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

Nicolas Dumazet nicdumz at gmail.com
Sun Dec 13 18:08:41 CST 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1260512733 -32400
# Node ID 0f195e3ad08945e2bfc3c4f34be337612f946bc8
# Parent  dfc3ed37d58d921428a6a684001e4f708c445a52
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
@@ -241,15 +241,15 @@
     check_unsupported_flags(opts)
     limit = cmdutil.loglimit(opts)
     start, stop = get_revs(repo, opts["rev"])
-    stop = max(stop, start - limit + 1)
     if start == nullrev:
         return
 
     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:
+        stop = max(stop, start - limit + 1)
         revdag = graphmod.revisions(repo, start, stop)
 
     displayer = show_changeset(ui, repo, opts, buffered=True)
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,21 +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
-    while filerev >= 0:
+    if limit < sys.maxint:
+        lower = max(0, filerev - limit + 1)
+    else:
+        lower = 0
+    count = 0
+    rev = stop + 1
+    while filerev >= lower and rev > stop:
         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:
-            break
         filerev -= 1
 
 def nodes(repo, nodes):
diff --git a/tests/test-glog b/tests/test-glog
--- a/tests/test-glog
+++ b/tests/test-glog
@@ -175,3 +175,13 @@
 hg incoming --graph ../repo
 cd ..
 hg -R repo outgoing --graph repo2
+
+cd repo
+echo % file + limit with revs != cset revs
+touch b
+hg ci -Aqm0
+# this used to show only one cset
+hg glog -l2 a
+
+echo "% file + limit + -r, with len(revs) < limit"
+hg glog -l3000 -r32:tip 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,36 @@
    date:        Thu Jan 01 00:00:27 1970 +0000
    summary:     (27) collapse
 
+% file + limit with revs != cset revs
+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
+| |
+% file + limit + -r, with len(revs) < 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
+| |
+o |    changeset:   32:d06dffa21a31
+|\ \   parent:      27:886ed638191b
+| | |  parent:      31:621d83e11f67
+| | |  user:        test
+| | |  date:        Thu Jan 01 00:00:32 1970 +0000
+| | |  summary:     (32) expand
+| | |


More information about the Mercurial-devel mailing list