mercurial/graphmod.py
changeset 38150 24e517600b29
parent 36180 34e850440271
child 38783 e7aa113b14f7
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