mercurial/graphmod.py
branchstable
changeset 10084 4c844f16bf39
parent 9727 d00cee04a746
child 10111 27457d31ae3f
child 10263 25e572394f5c
--- a/mercurial/graphmod.py	Wed Dec 16 12:10:21 2009 +0100
+++ b/mercurial/graphmod.py	Fri Dec 11 15:25:33 2009 +0900
@@ -17,6 +17,7 @@
 Data depends on type.
 """
 
+import sys
 from mercurial.node import nullrev
 
 CHANGESET = 'C'
@@ -36,21 +37,24 @@
         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:
+    rev = stop + 1
+    count = 0
+    while filerev >= 0 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
+            count += 1
+            if count == limit:
+                break
         filerev -= 1
 
 def nodes(repo, nodes):