changeset 28375:97cb1aeaca78

graphmod: refactor state handling Move ASCII graph state to a dictionary, to clarify what is being tracked. Move the 'seen' state (tracking currently active edges) into this structure.
author Martijn Pieters <mjpieters@fb.com>
date Fri, 04 Mar 2016 14:44:32 +0000
parents af3bd9d1dbc1
children fa2cd0c9a567
files mercurial/cmdutil.py mercurial/graphmod.py
diffstat 2 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Jun 11 23:04:14 2015 +0900
+++ b/mercurial/cmdutil.py	Fri Mar 04 14:44:32 2016 +0000
@@ -2212,7 +2212,7 @@
 def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None,
                  filematcher=None):
     formatnode = _graphnodeformatter(ui, displayer)
-    seen, state = [], graphmod.asciistate()
+    state = graphmod.asciistate()
     for rev, type, ctx, parents in dag:
         char = formatnode(repo, ctx)
         copies = None
@@ -2230,7 +2230,7 @@
         if not lines[-1]:
             del lines[-1]
         displayer.flush(ctx)
-        edges = edgefn(type, char, lines, seen, rev, parents)
+        edges = edgefn(type, char, lines, state, rev, parents)
         for type, char, lines, coldata in edges:
             graphmod.ascii(ui, state, type, char, lines, coldata)
     displayer.close()
--- a/mercurial/graphmod.py	Thu Jun 11 23:04:14 2015 +0900
+++ b/mercurial/graphmod.py	Fri Mar 04 14:44:32 2016 +0000
@@ -362,8 +362,9 @@
         yield (cur, type, data, (col, color), edges)
         seen = next
 
-def asciiedges(type, char, lines, seen, rev, parents):
+def asciiedges(type, char, lines, state, rev, parents):
     """adds edge info to changelog DAG walk suitable for ascii()"""
+    seen = state['seen']
     if rev not in seen:
         seen.append(rev)
     nodeidx = seen.index(rev)
@@ -461,7 +462,7 @@
 
 def asciistate():
     """returns the initial value for the "state" argument to ascii()"""
-    return [0, 0]
+    return {'seen': [], 'lastcoldiff': 0, 'lastindex': 0}
 
 def ascii(ui, state, type, char, text, coldata):
     """prints an ASCII graph of the DAG
@@ -519,8 +520,8 @@
     nodeline.extend([char, " "])
 
     nodeline.extend(
-        _getnodelineedgestail(idx, state[1], ncols, coldiff,
-                              state[0], fix_nodeline_tail))
+        _getnodelineedgestail(idx, state['lastindex'], ncols, coldiff,
+                              state['lastcoldiff'], fix_nodeline_tail))
 
     # shift_interline is the line containing the non-vertical
     # edges between this entry and the next
@@ -562,5 +563,5 @@
         ui.write(ln.rstrip() + '\n')
 
     # ... and start over
-    state[0] = coldiff
-    state[1] = idx
+    state['lastcoldiff'] = coldiff
+    state['lastindex'] = idx