[PATCH] graphlog: hide internal state of ascii() from users

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Fri Oct 2 03:00:09 CDT 2009


# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1254470313 -7200
graphlog: hide internal state of ascii() from users

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -100,13 +100,17 @@
     line.extend(["|", " "] * (n_columns - ni - 1))
     return line
 
-def ascii(ui, base, type, char, text, coldata):
+def asciictx():
+    """returns the initial value for the "ctx" argument to ascii()"""
+    return [0, 0]
+
+def ascii(ui, ctx, 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
+      - A context we can keep the needed state in (init to asciictx())
       - 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, ctx[1], ncols, coldiff,
+                                ctx[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
+    ctx[0] = coldiff
+    ctx[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, ctx = [], asciictx()
     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, ctx, type, char, lines, edgefn(seen, rev, parents))
 
 def graphlog(ui, repo, path=None, **opts):
     """show revision history alongside an ASCII revision graph


More information about the Mercurial-devel mailing list