]> thyrsus.com Git - src.git/commitdiff
Added -l option to list and log entries. Regression test passes.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 21 Nov 2014 03:11:29 +0000 (22:11 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 21 Nov 2014 03:11:29 +0000 (22:11 -0500)
NEWS
TODO
src

diff --git a/NEWS b/NEWS
index ca2b431013400b67aed65b0f3e14a351d7ac5756..328d51b757b8c7ba6fc1e118bfe36f1970f4ba4f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
                        src project news
 
+Repository head:
+   List and log command now have an -l option to play nice with Emacs VC
+
 0.11: 2014-11-19
    File-not-modified status character changed to '=' to match Mercurial.
    Fixed-width cutlines and list -f option support Emacs VC mode.
diff --git a/TODO b/TODO
index 02a760d7110c547cafe8eba5662fa77a356d84bc..e6e889e82aff9a81c1fe272c749bf0d1fb0e2a72 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,7 @@
                        SRC TODO list
 
+* Limit option for list and log.
+
 * Implement reverse ranges and remove automatic reversal in print and log.
 
 * Stop using rcsdiff, it leaks RCS version numbers onto the screen.
diff --git a/src b/src
index 55350f82afd289d759148c148582ab9f51f6c3bd..430e15e3603249a4c3fd6fd38c782376e5db4012 100755 (executable)
--- a/src
+++ b/src
@@ -452,7 +452,7 @@ src cat ['revision'] ['file'...]
 src status [-a] ['file'...]
    'A' = added, '=' = unmodified, 'M' = modified, '!' = missing, '?' = not
    tracked, 'I' = ignored, 'L' = locked (recover with src checkout).
-   Find more details under 'help status'. 'st' is a synonym fot status.
+   Find more details under 'help status'. 'st' is a synonym for status.
 
 src tag [list|-l|create|-c|delete|del|-d] ['name'] ['revision'] ['file'...] 
    List tags, create tags, or delete tags. Takes a singleton
@@ -466,14 +466,15 @@ src rename ['tag'|'branch'] ['oldname'] ['newname']  ['file'...]
    Rename a tag or branch. Refuses to step on an existing symbol or
    rename a nonexistent one.  'rn' is a synonym for 'rename'.
 
-src list [-f fmt] ['revision-range'] ['file'...]
+src list [-l n] [-f fmt] ['revision-range'] ['file'...]
    Sends summary information about the specified commits to standard output.
    The summary line tagged with '*' is the state that the file would
    return to on checkout without a revision-spec. See 'help list' for
-   information about custom formats.
+   information about custom formats. Use -l n to omit the listing length.
 
-src log ['revision-range'] ['file'...]
+src log [-l n] ['revision-range'] ['file'...]
    Sends log information about the specified commits to standard output.
+   Use -l n to omit the listing length.
    
 src diff ['revision-range'] ['file'...]
    Sends a diff listing to standard output. With no revision spec, diffs
@@ -657,16 +658,19 @@ creation will not step on an existing branch name, and a nonexistent branch
 cannot be deleted.
 """,
    "log" : """
-src log ['revision-range'] ['file'...]
+src log [-l n] ['revision-range'] ['file'...]
 
 Sends log information about the specified commits of each file
 to standard output.  The log information includes the revision
 number, the date, and the log comment.
 
 With no revision, dumps a log of the entire current branch.
+
+The -l option can be used to limit the listing length.  It is not
+primarily intended for use by humans, but rather for Emacs VC mode.
 """,   
    "list" : """
-src list [-f fmt] ['revision-range'] ['file'...]
+src list [-l n] [-f fmt] ['revision-range'] ['file'...]
 
 Sends summary information about the specified commits of each file
 to standard output.  The summary information includes the revision
@@ -686,6 +690,9 @@ substitutions are:
 {3}   The date in RFC3339 format
 {4}   The summary line
 
+The -l option can be used to limit the listing length.  It is not
+primarily intended for use by humans, but rather for Emacs VC mode.
+
 'li' is a synonym for 'list'.
 """,   
    "diff" : """
@@ -1112,6 +1119,7 @@ def list_method(*args):
     "Generate a summary listing of commits, one line per commit."
     args = list(args)
     custom = None
+    limit = None
     if args[0] == '--':
         args.pop(0)
     elif args[0] == "-f":
@@ -1124,6 +1132,16 @@ def list_method(*args):
     elif args[0].startswith("-f"):
         custom = args[0][2:]
         args.pop(0)
+    elif args[0] == "-l":
+        args.pop(0)
+        try:
+            limit = args[0]
+            args.pop(0)
+            limit = int(limit)
+        except IndexError:
+            croak("list -f requires a following string")
+        except ValueError:
+            croak("%s is not an integer" % limit)
     ctx = CommandContext("list", args, default_to="branch_reversed")
     for arg in ctx.args:
         if ignore(arg) or not registered(arg):
@@ -1143,9 +1161,27 @@ def list_method(*args):
                              % (item.revno, mark, item.date, summary))
             else:
                 sys.stdout.write(custom.format(arg, item.revno, mark, item.date, summary))
+            if limit is not None:
+                limit -= 1
+                if limit <= 0:
+                    break
 
 def log_method(*args):
     "Report revision logs"
+    limit = None
+    args = list(args)
+    if args[0] == '--':
+        args.pop(0)
+    elif args[0] == "-l":
+        args.pop(0)
+        try:
+            limit = args[0]
+            args.pop(0)
+            limit = int(limit)
+        except IndexError:
+            croak("list -f requires a following string")
+        except ValueError:
+            croak("%s is not an integer" % limit)
     ctx = CommandContext("log", args, default_to="branch_reversed")
     for arg in ctx.args:
         if ignore(arg) or not registered(arg):
@@ -1154,6 +1190,10 @@ def log_method(*args):
         for item in ctx.resolve(History(arg), backwards=True):
             sys.stdout.write("%-4d | %s\n%s" % (item.revno,item.date,item.log))
             sys.stdout.write(("-" * WIDTH) + "\n")
+            if limit is not None:
+                limit -= 1
+                if limit <= 0:
+                    break
 
 def checkout_method(*args):
     "Refresh the working copy from the history file."