changeset 9631:1c34fca5d785

graphlog: hide internal state of ascii() from users
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
date Wed, 21 Oct 2009 14:16:37 +0200
parents 24dad078603b
children 16698d87ad20
files hgext/graphlog.py
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/graphlog.py	Thu Oct 22 00:46:54 2009 +0200
+++ b/hgext/graphlog.py	Wed Oct 21 14:16:37 2009 +0200
@@ -100,13 +100,17 @@
     line.extend(["|", " "] * (n_columns - ni - 1))
     return line
 
-def ascii(ui, base, type, char, text, coldata):
+def asciistate():
+    """returns the initial value for the "state" argument to ascii()"""
+    return [0, 0]
+
+def ascii(ui, state, type, char, text, coldata):
     """prints an ASCII graph of the DAG
 
     takes the following arguments (one call per node in the graph):
 
       - ui to write to
-      - A list we can keep the needed state in
+      - Somewhere to keep the needed state in (init to asciistate())
       - Column of the current node in the set of ongoing edges.
       - Type indicator of node data == ASCIIDATA.
       - Payload: (char, lines):
@@ -156,8 +160,8 @@
     nodeline.extend([char, " "])
 
     nodeline.extend(
-        get_nodeline_edges_tail(idx, base[1], ncols, coldiff,
-                                base[0], fix_nodeline_tail))
+        get_nodeline_edges_tail(idx, state[1], ncols, coldiff,
+                                state[0], fix_nodeline_tail))
 
     # shift_interline is the line containing the non-vertical
     # edges between this entry and the next
@@ -199,8 +203,8 @@
         ui.write(ln.rstrip() + '\n')
 
     # ... and start over
-    base[0] = coldiff
-    base[1] = idx
+    state[0] = coldiff
+    state[1] = idx
 
 def get_revs(repo, rev_opt):
     if rev_opt:
@@ -217,12 +221,12 @@
             raise util.Abort(_("--graph option is incompatible with --%s") % op)
 
 def generate(ui, dag, displayer, showparents, edgefn):
-    seen, base = [], [0, 0]
+    seen, state = [], asciistate()
     for rev, type, ctx, parents in dag:
         char = ctx.node() in showparents and '@' or 'o'
         displayer.show(ctx)
         lines = displayer.hunk.pop(rev).split('\n')[:-1]
-        ascii(ui, base, type, char, lines, edgefn(seen, rev, parents))
+        ascii(ui, state, type, char, lines, edgefn(seen, rev, parents))
 
 def graphlog(ui, repo, path=None, **opts):
     """show revision history alongside an ASCII revision graph