Mercurial > hg
changeset 9369:20140c249e63
graphlog: move common code into function again, change function types
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Thu, 20 Aug 2009 08:35:35 +0200 |
parents | 8a4773bcbaec |
children | b360addfbe0e |
files | hgext/graphlog.py |
diffstat | 1 files changed, 36 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/graphlog.py Thu Aug 20 08:35:03 2009 +0200 +++ b/hgext/graphlog.py Thu Aug 20 08:35:35 2009 +0200 @@ -22,44 +22,31 @@ ASCIIDATA = 'ASC' -def asciiformat(revdag, displayer, parents): - """formats a changelog DAG walk for ASCII output""" - for (id, type, ctx, parentids) in revdag: - if type != graphmod.CHANGESET: - continue - displayer.show(ctx) - lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1] - char = ctx.node() in parents and '@' or 'o' - yield (id, ASCIIDATA, (char, lines), parentids) - -def asciiedges(nodes): +def asciiedges(seen, rev, parents): """adds edge info to changelog DAG walk suitable for ascii()""" - seen = [] - for node, type, data, parents in nodes: - if node not in seen: - seen.append(node) - nodeidx = seen.index(node) + if rev not in seen: + seen.append(rev) + nodeidx = seen.index(rev) - knownparents = [] - newparents = [] - for parent in parents: - if parent in seen: - knownparents.append(parent) - else: - newparents.append(parent) + knownparents = [] + newparents = [] + for parent in parents: + if parent in seen: + knownparents.append(parent) + else: + newparents.append(parent) - ncols = len(seen) - nextseen = seen[:] - nextseen[nodeidx:nodeidx + 1] = newparents - edges = [(nodeidx, nextseen.index(p)) for p in knownparents] + ncols = len(seen) + seen[nodeidx:nodeidx + 1] = newparents + edges = [(nodeidx, seen.index(p)) for p in knownparents] - if len(newparents) > 0: - edges.append((nodeidx, nodeidx)) - if len(newparents) > 1: - edges.append((nodeidx, nodeidx + 1)) - nmorecols = len(nextseen) - ncols - seen = nextseen - yield (nodeidx, type, data, edges, ncols, nmorecols) + if len(newparents) > 0: + edges.append((nodeidx, nodeidx)) + if len(newparents) > 1: + edges.append((nodeidx, nodeidx + 1)) + + nmorecols = len(seen) - ncols + return nodeidx, edges, ncols, nmorecols def fix_long_right_edges(edges): for (i, (start, end)) in enumerate(edges): @@ -231,6 +218,15 @@ if op in opts and opts[op]: raise util.Abort(_("--graph option is incompatible with --%s") % op) +def generate(dag, displayer, showparents, edgefn): + seen = [] + 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] + cols = edgefn(seen, rev, parents) + yield cols[0], type, (char, lines), cols[1], cols[2], cols[3] + def graphlog(ui, repo, path=None, **opts): """show revision history alongside an ASCII revision graph @@ -257,8 +253,8 @@ displayer = show_changeset(ui, repo, opts, buffered=True) showparents = [ctx.node() for ctx in repo[None].parents()] - fmtdag = asciiformat(revdag, displayer, showparents) - ascii(ui, asciiedges(fmtdag)) + gen = generate(revdag, displayer, showparents, asciiedges) + ascii(ui, gen) def graphrevs(repo, nodes, opts): limit = cmdutil.loglimit(opts) @@ -294,8 +290,8 @@ revdag = graphrevs(repo, o, opts) displayer = show_changeset(ui, repo, opts, buffered=True) showparents = [ctx.node() for ctx in repo[None].parents()] - fmtdag = asciiformat(revdag, displayer, showparents) - ascii(ui, asciiedges(fmtdag)) + gen = generate(revdag, displayer, showparents, asciiedges) + ascii(ui, gen) def gincoming(ui, repo, source="default", **opts): """show the incoming changesets alongside an ASCII revision graph @@ -345,8 +341,8 @@ revdag = graphrevs(other, chlist, opts) displayer = show_changeset(ui, other, opts, buffered=True) showparents = [ctx.node() for ctx in repo[None].parents()] - fmtdag = asciiformat(revdag, displayer, showparents) - ascii(ui, asciiedges(fmtdag)) + gen = generate(revdag, displayer, showparents, asciiedges) + ascii(ui, gen) finally: if hasattr(other, 'close'):