[PATCH 03 of 10] graphmod/graphlog: extract nodelistwalk

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Sat May 16 00:16:42 CDT 2009


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1242391975 -7200
graphmod/graphlog: extract nodelistwalk

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -12,7 +12,7 @@
 revision graph is also shown.
 '''
 
-import os
+import os, sys
 from mercurial.cmdutil import revrange, show_changeset
 from mercurial.commands import templateopts
 from mercurial.i18n import _
@@ -252,17 +252,11 @@
     ascii(ui, grapher(graphdag))
 
 def graphrevs(repo, nodes, opts):
-    include = set(nodes)
     limit = cmdutil.loglimit(opts)
-    count = 0
-    for node in reversed(nodes):
-        if count >= limit:
-            break
-        ctx = repo[node]
-        parents = [p.rev() for p in ctx.parents() if p.node() in include]
-        parents.sort()
-        yield (ctx, parents)
-        count += 1
+    nodes.reverse()
+    if limit < sys.maxint:
+        nodes = nodes[:limit]
+    return graphmod.nodelistwalk(repo, nodes)
 
 def graphabledag(ui, repo, revdag, opts):
     showparents = [ctx.node() for ctx in repo[None].parents()]
diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -42,6 +42,14 @@
             break
         filerev -= 1
 
+def nodelistwalk(repo, nodes):
+    include = set(nodes)
+    for node in nodes:
+        ctx = repo[node]
+        parents = [p.rev() for p in ctx.parents() if p.node() in include]
+        parents.sort()
+        yield (ctx, parents)
+
 def graph(repo, start_rev, stop_rev):
     """incremental revision grapher
 


More information about the Mercurial-devel mailing list