changeset 7716:4ad12930a459

graphlog: extract large parts of repeated code from incoming/outgoing
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Mon, 26 Jan 2009 16:50:27 +0100
parents fd3266287b40
children f9ba30cb7ee4
files hgext/graphlog.py
diffstat 1 files changed, 41 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/graphlog.py	Mon Jan 26 16:40:43 2009 +0100
+++ b/hgext/graphlog.py	Mon Jan 26 16:50:27 2009 +0100
@@ -282,26 +282,43 @@
     else:
         revdag = revisions(repo, start, stop)
 
-    repo_parents = repo.dirstate.parents()
+    graphdag = graphabledag(ui, repo, revdag, opts)
+    ascii(ui, grapher(graphdag))
+
+def graphrevs(repo, nodes, opts):
+    nodes.reverse()
+    include = util.set(nodes)
+    limit = cmdutil.loglimit(opts)
+    count = 0
+    for node in 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
+
+def graphabledag(ui, repo, revdag, opts):
+    showparents = [ctx.node() for ctx in repo[None].parents()]
     displayer = show_changeset(ui, repo, opts, buffered=True)
-    def graphabledag():
-        for (ctx, parents) in revdag:
-            # log_strings is the list of all log strings to draw alongside
-            # the graph.
-            displayer.show(ctx)
-            lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1]
-            char = ctx.node() in repo_parents and '@' or 'o'
-            yield (ctx.rev(), parents, char, lines)
+    for (ctx, parents) in revdag:
+        displayer.show(ctx)
+        lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1]
+        char = ctx.node() in showparents and '@' or 'o'
+        yield (ctx.rev(), parents, char, lines)
+
+def goutgoing(ui, repo, dest=None, **opts):
+    """show the outgoing changesets alongside an ASCII revision graph
 
-    ascii(ui, grapher(graphabledag()))
-
-def outgoing_revs(ui, repo, dest, opts):
-    """cset DAG generator yielding (node, [parents]) tuples
+    Print the outgoing changesets alongside a revision graph drawn with
+    ASCII characters.
 
-    This generator function walks through the revisions not found
-    in the destination
+    Nodes printed as an @ character are parents of the working
+    directory.
     """
-    limit = cmdutil.loglimit(opts)
+
+    check_unsupported_flags(opts)
     dest, revs, checkout = hg.parseurl(
         ui.expandpath(dest or 'default-push', dest or 'default'),
         opts.get('rev'))
@@ -314,65 +331,11 @@
     if not o:
         ui.status(_("no changes found\n"))
         return
+
     o = repo.changelog.nodesbetween(o, revs)[0]
-    o.reverse()
-    revdict = {}
-    for n in o:
-        revdict[repo.changectx(n).rev()]=True
-    count = 0
-    for n in o:
-        if count >= limit:
-            break
-        ctx = repo.changectx(n)
-        parents = [p.rev() for p in ctx.parents() if p.rev() in revdict]
-        parents.sort()
-        yield (ctx, parents)
-        count += 1
-
-def goutgoing(ui, repo, dest=None, **opts):
-    """show the outgoing changesets alongside an ASCII revision graph
-
-    Print the outgoing changesets alongside a revision graph drawn with
-    ASCII characters.
-
-    Nodes printed as an @ character are parents of the working
-    directory.
-    """
-    check_unsupported_flags(opts)
-    revdag = outgoing_revs(ui, repo, dest, opts)
-    repo_parents = repo.dirstate.parents()
-    displayer = show_changeset(ui, repo, opts, buffered=True)
-    def graphabledag():
-        for (ctx, parents) in revdag:
-            # log_strings is the list of all log strings to draw alongside
-            # the graph.
-            displayer.show(ctx)
-            lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1]
-            char = ctx.node() in repo_parents and '@' or 'o'
-            yield (ctx.rev(), parents, char, lines)
-
-    ascii(ui, grapher(graphabledag()))
-
-def incoming_revs(other, chlist, opts):
-    """cset DAG generator yielding (node, [parents]) tuples
-
-    This generator function walks through the revisions of the destination
-    not found in repo
-    """
-    limit = cmdutil.loglimit(opts)
-    chlist.reverse()
-    revdict = {}
-    for n in chlist:
-        revdict[other.changectx(n).rev()]=True
-    count = 0
-    for n in chlist:
-        if count >= limit:
-            break
-        ctx = other.changectx(n)
-        parents = [p.rev() for p in ctx.parents() if p.rev() in revdict]
-        parents.sort()
-        yield (ctx, parents)
-        count += 1
+    revdag = graphrevs(repo, o, opts)
+    graphdag = graphabledag(ui, repo, revdag, opts)
+    ascii(ui, grapher(graphdag))
 
 def gincoming(ui, repo, source="default", **opts):
     """show the incoming changesets alongside an ASCII revision graph
@@ -403,6 +366,7 @@
 
     cleanup = None
     try:
+
         fname = opts["bundle"]
         if fname or not other.local():
             # create a bundle (uncompressed if other repo is not local)
@@ -420,19 +384,12 @@
                 other = bundlerepo.bundlerepository(ui, repo.root, fname)
 
         chlist = other.changelog.nodesbetween(incoming, revs)[0]
-        revdag = incoming_revs(other, chlist, opts)
+        revdag = graphrevs(other, chlist, opts)
         other_parents = []
         displayer = show_changeset(ui, other, opts, buffered=True)
-        def graphabledag():
-            for (ctx, parents) in revdag:
-                # log_strings is the list of all log strings to draw alongside
-                # the graph.
-                displayer.show(ctx)
-                lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1]
-                char = ctx.node() in other_parents and '@' or 'o'
-                yield (ctx.rev(), parents, char, lines)
+        graphdag = graphabledag(ui, repo, revdag, opts)
+        ascii(ui, grapher(graphdag))
 
-        ascii(ui, grapher(graphabledag()))
     finally:
         if hasattr(other, 'close'):
             other.close()