Mercurial > hg
comparison hgext/graphlog.py @ 8840:d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
author | Peter Arrenbrecht <peter.arrenbrecht@gmail.com> |
---|---|
date | Fri, 19 Jun 2009 13:22:32 +0200 |
parents | bbfa21b6f18a |
children | 868670dbc237 |
comparison
equal
deleted
inserted
replaced
8839:bbfa21b6f18a | 8840:d9acbe7b0049 |
---|---|
18 from mercurial.i18n import _ | 18 from mercurial.i18n import _ |
19 from mercurial.node import nullrev | 19 from mercurial.node import nullrev |
20 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions | 20 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions |
21 from mercurial import hg, url, util, graphmod | 21 from mercurial import hg, url, util, graphmod |
22 | 22 |
23 ASCIIDATA = 'ASC' | |
24 | |
23 def asciiformat(ui, repo, revdag, opts): | 25 def asciiformat(ui, repo, revdag, opts): |
24 """formats a changelog DAG walk for ASCII output""" | 26 """formats a changelog DAG walk for ASCII output""" |
25 showparents = [ctx.node() for ctx in repo[None].parents()] | 27 showparents = [ctx.node() for ctx in repo[None].parents()] |
26 displayer = show_changeset(ui, repo, opts, buffered=True) | 28 displayer = show_changeset(ui, repo, opts, buffered=True) |
27 for (ctx, parents) in revdag: | 29 for (id, type, ctx, parentids) in revdag: |
30 if type != graphmod.CHANGESET: | |
31 continue | |
28 displayer.show(ctx) | 32 displayer.show(ctx) |
29 lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1] | 33 lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1] |
30 char = ctx.node() in showparents and '@' or 'o' | 34 char = ctx.node() in showparents and '@' or 'o' |
31 yield (ctx.rev(), parents, char, lines) | 35 yield (id, ASCIIDATA, (char, lines), parentids) |
32 | 36 |
33 def asciiedges(nodes): | 37 def asciiedges(nodes): |
34 """adds edge info to ascii formatted changelog DAG walk suitable for ascii() | 38 """adds edge info to changelog DAG walk suitable for ascii()""" |
35 | |
36 nodes must generate tuples (node, parents, char, lines) where | |
37 - parents must generate the parents of node, in sorted order, | |
38 and max length 2, | |
39 - char is the char to print as the node symbol, and | |
40 - lines are the lines to display next to the node. | |
41 """ | |
42 seen = [] | 39 seen = [] |
43 for node, parents, char, lines in nodes: | 40 for node, type, data, parents in nodes: |
44 if node not in seen: | 41 if node not in seen: |
45 seen.append(node) | 42 seen.append(node) |
46 nodeidx = seen.index(node) | 43 nodeidx = seen.index(node) |
47 | 44 |
48 knownparents = [] | 45 knownparents = [] |
62 edges.append((nodeidx, nodeidx)) | 59 edges.append((nodeidx, nodeidx)) |
63 if len(newparents) > 1: | 60 if len(newparents) > 1: |
64 edges.append((nodeidx, nodeidx + 1)) | 61 edges.append((nodeidx, nodeidx + 1)) |
65 nmorecols = len(nextseen) - ncols | 62 nmorecols = len(nextseen) - ncols |
66 seen = nextseen | 63 seen = nextseen |
67 yield (char, lines, nodeidx, edges, ncols, nmorecols) | 64 yield (nodeidx, type, data, edges, ncols, nmorecols) |
68 | 65 |
69 def fix_long_right_edges(edges): | 66 def fix_long_right_edges(edges): |
70 for (i, (start, end)) in enumerate(edges): | 67 for (i, (start, end)) in enumerate(edges): |
71 if end > start: | 68 if end > start: |
72 edges[i] = (start, end + 1) | 69 edges[i] = (start, end + 1) |
121 def ascii(ui, dag): | 118 def ascii(ui, dag): |
122 """prints an ASCII graph of the DAG | 119 """prints an ASCII graph of the DAG |
123 | 120 |
124 dag is a generator that emits tuples with the following elements: | 121 dag is a generator that emits tuples with the following elements: |
125 | 122 |
126 - Character to use as node's symbol. | |
127 - List of lines to display as the node's text. | |
128 - Column of the current node in the set of ongoing edges. | 123 - Column of the current node in the set of ongoing edges. |
124 - Type indicator of node data == ASCIIDATA. | |
125 - Payload: (char, lines): | |
126 - Character to use as node's symbol. | |
127 - List of lines to display as the node's text. | |
129 - Edges; a list of (col, next_col) indicating the edges between | 128 - Edges; a list of (col, next_col) indicating the edges between |
130 the current node and its parents. | 129 the current node and its parents. |
131 - Number of columns (ongoing edges) in the current revision. | 130 - Number of columns (ongoing edges) in the current revision. |
132 - The difference between the number of columns (ongoing edges) | 131 - The difference between the number of columns (ongoing edges) |
133 in the next revision and the number of columns (ongoing edges) | 132 in the next revision and the number of columns (ongoing edges) |
134 in the current revision. That is: -1 means one column removed; | 133 in the current revision. That is: -1 means one column removed; |
135 0 means no columns added or removed; 1 means one column added. | 134 0 means no columns added or removed; 1 means one column added. |
136 """ | 135 """ |
137 prev_n_columns_diff = 0 | 136 prev_n_columns_diff = 0 |
138 prev_node_index = 0 | 137 prev_node_index = 0 |
139 for (node_ch, node_lines, node_index, edges, n_columns, n_columns_diff) in dag: | 138 for (node_index, type, (node_ch, node_lines), edges, n_columns, n_columns_diff) in dag: |
140 | 139 |
141 assert -2 < n_columns_diff < 2 | 140 assert -2 < n_columns_diff < 2 |
142 if n_columns_diff == -1: | 141 if n_columns_diff == -1: |
143 # Transform | 142 # Transform |
144 # | 143 # |