[PATCH] graphlog: fix output when both a limit and a path are provided

Nicolas Dumazet nicdumz at gmail.com
Fri Dec 11 00:29:58 CST 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1260512733 -32400
# Node ID c0daabf498092b64cf93f4a291eae870ca6e4f96
# Parent  2b630e4c8f2f626f1e5d0f88646463968860f8ac
graphlog: fix output when both a limit and a path are provided

Limit was interpreted as absolute, from the topmost revision, without
counting the number of revisions matching a given file.
Which caused "glog -lN file" to show sometimes less than N csets if
the file was not modified in all of the N previous csets.

glog will now match the behavior of log.

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -248,7 +248,7 @@
     if path:
         path = util.canonpath(repo.root, os.getcwd(), path)
     if path: # could be reset in canonpath
-        revdag = graphmod.filerevs(repo, path, start, stop)
+        revdag = graphmod.filerevs(repo, path, start, stop, limit)
     else:
         revdag = graphmod.revisions(repo, start, stop)
 
diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -18,6 +18,7 @@
 """
 
 from mercurial.node import nullrev
+import sys
 
 CHANGESET = 'C'
 
@@ -36,20 +37,25 @@
         yield (cur, CHANGESET, ctx, sorted(parents))
         cur -= 1
 
-def filerevs(repo, path, start, stop):
+def filerevs(repo, path, start, stop, limit=sys.maxint):
     """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
 
     This generator function walks through the revision history of a single
     file from revision start down to revision stop.
     """
     filerev = len(repo.file(path)) - 1
+    count = 0
     while filerev >= 0:
         fctx = repo.filectx(path, fileid=filerev)
         parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
         rev = fctx.rev()
         if rev <= start:
             yield (rev, CHANGESET, fctx.changectx(), sorted(parents))
-        if rev <= stop:
+        if limit < sys.maxint:
+            count += 1
+            if count == limit:
+                break
+        elif rev <= stop:
             break
         filerev -= 1
 
diff --git a/tests/test-glog b/tests/test-glog
--- a/tests/test-glog
+++ b/tests/test-glog
@@ -175,3 +175,10 @@
 hg incoming --graph ../repo
 cd ..
 hg -R repo outgoing --graph repo2
+
+cd repo
+echo % file + limit
+touch b
+hg ci -Aqm0
+# this used to show only one cset
+hg glog -l2 a
diff --git a/tests/test-glog.out b/tests/test-glog.out
--- a/tests/test-glog.out
+++ b/tests/test-glog.out
@@ -643,3 +643,16 @@
    date:        Thu Jan 01 00:00:27 1970 +0000
    summary:     (27) collapse
 
+% file + limit
+o  changeset:   34:fea3ac5810e0
+|  parent:      32:d06dffa21a31
+|  user:        test
+|  date:        Thu Jan 01 00:00:34 1970 +0000
+|  summary:     (34) head
+|
+| o  changeset:   33:68608f5145f9
+| |  parent:      18:1aa84d96232a
+| |  user:        test
+| |  date:        Thu Jan 01 00:00:33 1970 +0000
+| |  summary:     (33) head
+| |


More information about the Mercurial-devel mailing list