[PATCH 4 of 4] graphlog: support >2 parents in nodegrapher()

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Fri Nov 7 09:53:11 CST 2008


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1226072930 -3600
graphlog: support >2 parents in nodegrapher()

Adds support for >2 parents per DAG node by inserting dummy lines
to make room for routing the ASCII graph lines.

This is needed for the upcoming pbranch extension, so I'd like to get
it into Hg 1.1.


diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -51,15 +51,17 @@
             break
         filerev -= 1
 
-def nodegrapher(nodes):
+def nodegrapher(nodes, joinchar='\\'):
     """grapher for asciigraph on a list of nodes and their parents
     
     nodes must generate tuples (node, parents, char, lines) where
     
      - parents must generate the parents of node, in sorted order,
-       and max length 2,
      - char is the char to print as the node symbol, and
      - lines are the lines to display next to the node.  
+    
+    Inserts artificial lines with joinchar as marker to make room
+    when a node has >2 parents. 
     """
     seen = []
     for node, parents, char, lines in nodes:
@@ -80,6 +82,19 @@
         nextseen[nodeidx:nodeidx + 1] = newparents
         edges = [(nodeidx, nextseen.index(p)) for p in knownparents]
 
+        while len(newparents) > 2:
+            edges.append((nodeidx, nodeidx))
+            edges.append((nodeidx, nodeidx + 1))
+            nmorecols = +1
+            yield (char, lines, nodeidx, edges, ncols, nmorecols)
+            char = joinchar
+            lines = []
+            seen = nextseen
+            nodeidx += 1
+            ncols += 1
+            edges = []
+            del newparents[0]
+
         if len(newparents) > 0:
             edges.append((nodeidx, nodeidx))
         if len(newparents) > 1:
@@ -88,6 +103,17 @@
         seen = nextseen
         yield (char, lines, nodeidx, edges, ncols, nmorecols)
 
+def debugnodegraph(ui, repo, **opts):
+    dag = [[0, [1, 2, 3, 4], 'o', ['0']],
+           [1, [5], 'o', ['1']],
+           [2, [5], 'o', ['2']],
+           [3, [5], 'o', ['3']],
+           [4, [5], 'o', ['4']],
+           [5, [], 'o', ['5']],
+          ]
+    grapher = nodegrapher(dag)
+    graphlog.asciigraph(ui, grapher)
+
 def fix_long_right_edges(edges):
     for (i, (start, end)) in enumerate(edges):
         if end > start:
@@ -308,4 +334,5 @@
           ('r', 'rev', [], _('show the specified revision or range')),
          ] + templateopts,
          _('hg glog [OPTION]... [FILE]')),
+    # "debuggraph": (debugnodegraph, [], ''),
 }


More information about the Mercurial-devel mailing list