add -l,--limit to log command.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Mon, 20 Feb 2006 11:06:41 -0800
changeset 1756 f29857aaa053
parent 1747 91c56c427171
child 1757 23012d48ae91
add -l,--limit to log command.
doc/hg.1.txt
mercurial/commands.py
--- a/doc/hg.1.txt	Sat Feb 18 07:37:59 2006 -0800
+++ b/doc/hg.1.txt	Mon Feb 20 11:06:41 2006 -0800
@@ -376,6 +376,7 @@
     options:
     -I, --include <pat>   include names matching the given patterns
     -X, --exclude <pat>   exclude names matching the given patterns
+    -l, --limit <num>     print no more than this many changes
     -r, --rev <A>         show the specified revision or range
     -p, --patch           show patch
 
--- a/mercurial/commands.py	Sat Feb 18 07:37:59 2006 -0800
+++ b/mercurial/commands.py	Mon Feb 20 11:06:41 2006 -0800
@@ -1599,7 +1599,19 @@
                 self.write(*args)
         def __getattr__(self, key):
             return getattr(self.ui, key)
+
     changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts)
+
+    if opts['limit']:
+        try:
+            limit = int(opts['limit'])
+        except ValueError:
+            raise util.Abort(_('limit must be a positive integer'))
+        if limit <= 0: raise util.Abort(_('limit must be positive'))
+    else:
+        limit = sys.maxint
+    count = 0
+
     for st, rev, fns in changeiter:
         if st == 'window':
             du = dui(ui)
@@ -1635,6 +1647,8 @@
                 dodiff(du, du, repo, prev, changenode, match=matchfn)
                 du.write("\n\n")
         elif st == 'iter':
+            if count == limit: break
+            count += 1
             for args in du.hunk[rev]:
                 ui.write(*args)
 
@@ -2446,6 +2460,7 @@
           ('X', 'exclude', [], _('exclude names matching the given patterns')),
           ('b', 'branch', None, _('show branches')),
           ('k', 'keyword', [], _('search for a keyword')),
+          ('l', 'limit', '', _('limit number of changes displayed')),
           ('r', 'rev', [], _('show the specified revision or range')),
           ('M', 'no-merges', None, _('do not show merges')),
           ('m', 'only-merges', None, _('show only merges')),