Mercurial > hg
comparison mercurial/graphmod.py @ 38150:24e517600b29
graph: add outputgraph() function, called by ascii() to print
the graph to the ui.
This allows a cleaner entrypoint for extensions to tweak the
graph output without needing to rewrite all of ascii(), or needing
to manually guess where the graph nodes/edges end and the rev
note portion begins.
This patch does not affect graph output or behavior in any way.
Differential Revision: https://phab.mercurial-scm.org/D3655
author | John Stiles <johnstiles@gmail.com> |
---|---|
date | Thu, 24 May 2018 23:05:12 -0700 |
parents | 34e850440271 |
children | e7aa113b14f7 |
comparison
equal
deleted
inserted
replaced
38149:d1690a64268e | 38150:24e517600b29 |
---|---|
339 'lastindex': 0, | 339 'lastindex': 0, |
340 'styles': EDGES.copy(), | 340 'styles': EDGES.copy(), |
341 'graphshorten': False, | 341 'graphshorten': False, |
342 } | 342 } |
343 | 343 |
344 def outputgraph(ui, graph): | |
345 """outputs an ASCII graph of a DAG | |
346 | |
347 this is a helper function for 'ascii' below. | |
348 | |
349 takes the following arguments: | |
350 | |
351 - ui to write to | |
352 - graph data: list of { graph nodes/edges, text } | |
353 | |
354 this function can be monkey-patched by extensions to alter graph display | |
355 without needing to mimic all of the edge-fixup logic in ascii() | |
356 """ | |
357 for (ln, logstr) in graph: | |
358 ui.write((ln + logstr).rstrip() + "\n") | |
359 | |
344 def ascii(ui, state, type, char, text, coldata): | 360 def ascii(ui, state, type, char, text, coldata): |
345 """prints an ASCII graph of the DAG | 361 """prints an ASCII graph of the DAG |
346 | 362 |
347 takes the following arguments (one call per node in the graph): | 363 takes the following arguments (one call per node in the graph): |
348 | 364 |
467 edgemap.update( | 483 edgemap.update( |
468 (e, (c if len(c) < 2 else parent)) for e, c in edgemap.items()) | 484 (e, (c if len(c) < 2 else parent)) for e, c in edgemap.items()) |
469 | 485 |
470 # print lines | 486 # print lines |
471 indentation_level = max(ncols, ncols + coldiff) | 487 indentation_level = max(ncols, ncols + coldiff) |
472 for (line, logstr) in zip(lines, text): | 488 lines = ["%-*s " % (2 * indentation_level, "".join(line)) for line in lines] |
473 ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) | 489 outputgraph(ui, zip(lines, text)) |
474 ui.write(ln.rstrip() + '\n') | |
475 | 490 |
476 # ... and start over | 491 # ... and start over |
477 state['lastcoldiff'] = coldiff | 492 state['lastcoldiff'] = coldiff |
478 state['lastindex'] = idx | 493 state['lastindex'] = idx |