[PATCH 02 of 10] graphmod/graphlog: move log walks to graphmod

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Fri May 15 11:03:12 CDT 2009


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1242391652 -7200
graphmod/graphlog: move log walks to graphmod

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -18,41 +18,7 @@
 from mercurial.i18n import _
 from mercurial.node import nullrev
 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions
-from mercurial import hg, url, util
-
-def revisions(repo, start, stop):
-    """cset DAG generator yielding (rev, node, [parents]) tuples
-
-    This generator function walks through the revision history from revision
-    start to revision stop (which must be less than or equal to start).
-    """
-    assert start >= stop
-    cur = start
-    while cur >= stop:
-        ctx = repo[cur]
-        parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
-        parents.sort()
-        yield (ctx, parents)
-        cur -= 1
-
-def filerevs(repo, path, start, stop):
-    """file cset DAG generator yielding (rev, node, [parents]) tuples
-
-    This generator function walks through the revision history of a single
-    file from revision start to revision stop (which must be less than or
-    equal to start).
-    """
-    assert start >= stop
-    filerev = len(repo.file(path)) - 1
-    while filerev >= 0:
-        fctx = repo.filectx(path, fileid=filerev)
-        parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
-        parents.sort()
-        if fctx.rev() <= start:
-            yield (fctx, parents)
-        if fctx.rev() <= stop:
-            break
-        filerev -= 1
+from mercurial import hg, url, util, graphmod
 
 def grapher(nodes):
     """grapher for asciigraph on a list of nodes and their parents
@@ -278,9 +244,9 @@
     if path:
         path = util.canonpath(repo.root, os.getcwd(), path)
     if path: # could be reset in canonpath
-        revdag = filerevs(repo, path, start, stop)
+        revdag = graphmod.filelogwalk(repo, path, start, stop)
     else:
-        revdag = revisions(repo, start, stop)
+        revdag = graphmod.changelogwalk(repo, start, stop)
 
     graphdag = graphabledag(ui, repo, revdag, opts)
     ascii(ui, grapher(graphdag))
diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -8,6 +8,40 @@
 
 from node import nullrev
 
+def changelogwalk(repo, start, stop):
+    """cset DAG generator yielding (rev, node, [parents]) tuples
+
+    This generator function walks through the revision history from revision
+    start to revision stop (which must be less than or equal to start).
+    """
+    assert start >= stop
+    cur = start
+    while cur >= stop:
+        ctx = repo[cur]
+        parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
+        parents.sort()
+        yield (ctx, parents)
+        cur -= 1
+
+def filelogwalk(repo, path, start, stop):
+    """file cset DAG generator yielding (rev, node, [parents]) tuples
+
+    This generator function walks through the revision history of a single
+    file from revision start to revision stop (which must be less than or
+    equal to start).
+    """
+    assert start >= stop
+    filerev = len(repo.file(path)) - 1
+    while filerev >= 0:
+        fctx = repo.filectx(path, fileid=filerev)
+        parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
+        parents.sort()
+        if fctx.rev() <= start:
+            yield (fctx, parents)
+        if fctx.rev() <= stop:
+            break
+        filerev -= 1
+
 def graph(repo, start_rev, stop_rev):
     """incremental revision grapher
 


More information about the Mercurial-devel mailing list