Patchwork D3655: graph: add outputgraph() function, called by ascii() to printthe graph to the ui.

login
register
mail settings
Submitter phabricator
Date May 25, 2018, 7:47 p.m.
Message ID <5d490b202fa7db9e36f2437cb5027f2f@localhost.localdomain>
Download mbox | patch
Permalink /patch/31864/
State Not Applicable
Headers show

Comments

phabricator - May 25, 2018, 7:47 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG24e517600b29: graph: add outputgraph() function, called by ascii() to print (authored by johnstiles, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3655?vs=8888&id=8895

REVISION DETAIL
  https://phab.mercurial-scm.org/D3655

AFFECTED FILES
  mercurial/graphmod.py

CHANGE DETAILS




To: johnstiles, #hg-reviewers, spectral, pulkit
Cc: spectral, mercurial-devel

Patch

diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -341,6 +341,22 @@ 
         'graphshorten': False,
     }
 
+def outputgraph(ui, graph):
+    """outputs an ASCII graph of a DAG
+
+    this is a helper function for 'ascii' below.
+
+    takes the following arguments:
+
+    - ui to write to
+    - graph data: list of { graph nodes/edges, text }
+
+    this function can be monkey-patched by extensions to alter graph display
+    without needing to mimic all of the edge-fixup logic in ascii()
+    """
+    for (ln, logstr) in graph:
+        ui.write((ln + logstr).rstrip() + "\n")
+
 def ascii(ui, state, type, char, text, coldata):
     """prints an ASCII graph of the DAG
 
@@ -469,9 +485,8 @@ 
 
     # print lines
     indentation_level = max(ncols, ncols + coldiff)
-    for (line, logstr) in zip(lines, text):
-        ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr)
-        ui.write(ln.rstrip() + '\n')
+    lines = ["%-*s " % (2 * indentation_level, "".join(line)) for line in lines]
+    outputgraph(ui, zip(lines, text))
 
     # ... and start over
     state['lastcoldiff'] = coldiff