Mercurial > hg
comparison hgext/graphlog.py @ 14130:5e4ec4119485
graphlog: display nodes with more than 2 predecessors
While nodes with more than 2 parents do not exist in revision graphs, they do
appear when you transform them by removing subgraphs while trying to preserve
ancestry links.
This code was borrowed from Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
pbranch extension.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 01 May 2011 15:51:20 +0200 |
parents | 2d7cb340a53f |
children | 7d3bd0640262 |
comparison
equal
deleted
inserted
replaced
14129:81e6d42b3228 | 14130:5e4ec4119485 |
---|---|
19 from mercurial import cmdutil, commands, extensions | 19 from mercurial import cmdutil, commands, extensions |
20 from mercurial import hg, scmutil, util, graphmod | 20 from mercurial import hg, scmutil, util, graphmod |
21 | 21 |
22 ASCIIDATA = 'ASC' | 22 ASCIIDATA = 'ASC' |
23 | 23 |
24 def asciiedges(seen, rev, parents): | 24 def asciiedges(type, char, lines, seen, rev, parents): |
25 """adds edge info to changelog DAG walk suitable for ascii()""" | 25 """adds edge info to changelog DAG walk suitable for ascii()""" |
26 if rev not in seen: | 26 if rev not in seen: |
27 seen.append(rev) | 27 seen.append(rev) |
28 nodeidx = seen.index(rev) | 28 nodeidx = seen.index(rev) |
29 | 29 |
34 knownparents.append(parent) | 34 knownparents.append(parent) |
35 else: | 35 else: |
36 newparents.append(parent) | 36 newparents.append(parent) |
37 | 37 |
38 ncols = len(seen) | 38 ncols = len(seen) |
39 seen[nodeidx:nodeidx + 1] = newparents | 39 nextseen = seen[:] |
40 edges = [(nodeidx, seen.index(p)) for p in knownparents] | 40 nextseen[nodeidx:nodeidx + 1] = newparents |
41 edges = [(nodeidx, nextseen.index(p)) for p in knownparents] | |
42 | |
43 while len(newparents) > 2: | |
44 # ascii() only knows how to add or remove a single column between two | |
45 # calls. Nodes with more than two parents break this constraint so we | |
46 # introduce intermediate expansion lines to grow the active node list | |
47 # slowly. | |
48 edges.append((nodeidx, nodeidx)) | |
49 edges.append((nodeidx, nodeidx + 1)) | |
50 nmorecols = 1 | |
51 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) | |
52 char = '\\' | |
53 lines = [] | |
54 nodeidx += 1 | |
55 ncols += 1 | |
56 edges = [] | |
57 del newparents[0] | |
41 | 58 |
42 if len(newparents) > 0: | 59 if len(newparents) > 0: |
43 edges.append((nodeidx, nodeidx)) | 60 edges.append((nodeidx, nodeidx)) |
44 if len(newparents) > 1: | 61 if len(newparents) > 1: |
45 edges.append((nodeidx, nodeidx + 1)) | 62 edges.append((nodeidx, nodeidx + 1)) |
46 | 63 nmorecols = len(nextseen) - ncols |
47 nmorecols = len(seen) - ncols | 64 seen[:] = nextseen |
48 return nodeidx, edges, ncols, nmorecols | 65 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) |
49 | 66 |
50 def fix_long_right_edges(edges): | 67 def fix_long_right_edges(edges): |
51 for (i, (start, end)) in enumerate(edges): | 68 for (i, (start, end)) in enumerate(edges): |
52 if end > start: | 69 if end > start: |
53 edges[i] = (start, end + 1) | 70 edges[i] = (start, end + 1) |
274 for rev, type, ctx, parents in dag: | 291 for rev, type, ctx, parents in dag: |
275 char = ctx.node() in showparents and '@' or 'o' | 292 char = ctx.node() in showparents and '@' or 'o' |
276 displayer.show(ctx) | 293 displayer.show(ctx) |
277 lines = displayer.hunk.pop(rev).split('\n')[:-1] | 294 lines = displayer.hunk.pop(rev).split('\n')[:-1] |
278 displayer.flush(rev) | 295 displayer.flush(rev) |
279 ascii(ui, state, type, char, lines, edgefn(seen, rev, parents)) | 296 edges = edgefn(type, char, lines, seen, rev, parents) |
297 for type, char, lines, coldata in edges: | |
298 ascii(ui, state, type, char, lines, coldata) | |
280 displayer.close() | 299 displayer.close() |
281 | 300 |
282 def graphlog(ui, repo, *pats, **opts): | 301 def graphlog(ui, repo, *pats, **opts): |
283 """show revision history alongside an ASCII revision graph | 302 """show revision history alongside an ASCII revision graph |
284 | 303 |