Show More
@@ -1,397 +1,397 b'' | |||||
1 | # ASCII graph log extension for Mercurial |
|
1 | # ASCII graph log extension for Mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2007 Joel Rosdahl <joel@rosdahl.net> |
|
3 | # Copyright 2007 Joel Rosdahl <joel@rosdahl.net> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | '''command to view revision graphs from a shell |
|
8 | '''command to view revision graphs from a shell | |
9 |
|
9 | |||
10 | This extension adds a --graph option to the incoming, outgoing and log |
|
10 | This extension adds a --graph option to the incoming, outgoing and log | |
11 | commands. When this options is given, an ASCII representation of the |
|
11 | commands. When this options is given, an ASCII representation of the | |
12 | revision graph is also shown. |
|
12 | revision graph is also shown. | |
13 | ''' |
|
13 | ''' | |
14 |
|
14 | |||
15 | from mercurial.cmdutil import show_changeset |
|
15 | from mercurial.cmdutil import show_changeset | |
16 | from mercurial.commands import templateopts |
|
16 | from mercurial.commands import templateopts | |
17 | from mercurial.i18n import _ |
|
17 | from mercurial.i18n import _ | |
18 | from mercurial.node import nullrev |
|
18 | from mercurial.node import nullrev | |
19 | from mercurial import cmdutil, commands, extensions, scmutil |
|
19 | from mercurial import cmdutil, commands, extensions, scmutil | |
20 | from mercurial import hg, util, graphmod |
|
20 | from mercurial import hg, util, graphmod | |
21 |
|
21 | |||
22 | cmdtable = {} |
|
22 | cmdtable = {} | |
23 | command = cmdutil.command(cmdtable) |
|
23 | command = cmdutil.command(cmdtable) | |
24 |
|
24 | |||
25 | ASCIIDATA = 'ASC' |
|
25 | ASCIIDATA = 'ASC' | |
26 |
|
26 | |||
27 | def asciiedges(type, char, lines, seen, rev, parents): |
|
27 | def asciiedges(type, char, lines, seen, rev, parents): | |
28 | """adds edge info to changelog DAG walk suitable for ascii()""" |
|
28 | """adds edge info to changelog DAG walk suitable for ascii()""" | |
29 | if rev not in seen: |
|
29 | if rev not in seen: | |
30 | seen.append(rev) |
|
30 | seen.append(rev) | |
31 | nodeidx = seen.index(rev) |
|
31 | nodeidx = seen.index(rev) | |
32 |
|
32 | |||
33 | knownparents = [] |
|
33 | knownparents = [] | |
34 | newparents = [] |
|
34 | newparents = [] | |
35 | for parent in parents: |
|
35 | for parent in parents: | |
36 | if parent in seen: |
|
36 | if parent in seen: | |
37 | knownparents.append(parent) |
|
37 | knownparents.append(parent) | |
38 | else: |
|
38 | else: | |
39 | newparents.append(parent) |
|
39 | newparents.append(parent) | |
40 |
|
40 | |||
41 | ncols = len(seen) |
|
41 | ncols = len(seen) | |
42 | nextseen = seen[:] |
|
42 | nextseen = seen[:] | |
43 | nextseen[nodeidx:nodeidx + 1] = newparents |
|
43 | nextseen[nodeidx:nodeidx + 1] = newparents | |
44 | edges = [(nodeidx, nextseen.index(p)) for p in knownparents] |
|
44 | edges = [(nodeidx, nextseen.index(p)) for p in knownparents] | |
45 |
|
45 | |||
46 | while len(newparents) > 2: |
|
46 | while len(newparents) > 2: | |
47 | # ascii() only knows how to add or remove a single column between two |
|
47 | # ascii() only knows how to add or remove a single column between two | |
48 | # calls. Nodes with more than two parents break this constraint so we |
|
48 | # calls. Nodes with more than two parents break this constraint so we | |
49 | # introduce intermediate expansion lines to grow the active node list |
|
49 | # introduce intermediate expansion lines to grow the active node list | |
50 | # slowly. |
|
50 | # slowly. | |
51 | edges.append((nodeidx, nodeidx)) |
|
51 | edges.append((nodeidx, nodeidx)) | |
52 | edges.append((nodeidx, nodeidx + 1)) |
|
52 | edges.append((nodeidx, nodeidx + 1)) | |
53 | nmorecols = 1 |
|
53 | nmorecols = 1 | |
54 | yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) |
|
54 | yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) | |
55 | char = '\\' |
|
55 | char = '\\' | |
56 | lines = [] |
|
56 | lines = [] | |
57 | nodeidx += 1 |
|
57 | nodeidx += 1 | |
58 | ncols += 1 |
|
58 | ncols += 1 | |
59 | edges = [] |
|
59 | edges = [] | |
60 | del newparents[0] |
|
60 | del newparents[0] | |
61 |
|
61 | |||
62 | if len(newparents) > 0: |
|
62 | if len(newparents) > 0: | |
63 | edges.append((nodeidx, nodeidx)) |
|
63 | edges.append((nodeidx, nodeidx)) | |
64 | if len(newparents) > 1: |
|
64 | if len(newparents) > 1: | |
65 | edges.append((nodeidx, nodeidx + 1)) |
|
65 | edges.append((nodeidx, nodeidx + 1)) | |
66 | nmorecols = len(nextseen) - ncols |
|
66 | nmorecols = len(nextseen) - ncols | |
67 | seen[:] = nextseen |
|
67 | seen[:] = nextseen | |
68 | yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) |
|
68 | yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) | |
69 |
|
69 | |||
70 | def fix_long_right_edges(edges): |
|
70 | def fix_long_right_edges(edges): | |
71 | for (i, (start, end)) in enumerate(edges): |
|
71 | for (i, (start, end)) in enumerate(edges): | |
72 | if end > start: |
|
72 | if end > start: | |
73 | edges[i] = (start, end + 1) |
|
73 | edges[i] = (start, end + 1) | |
74 |
|
74 | |||
75 | def get_nodeline_edges_tail( |
|
75 | def get_nodeline_edges_tail( | |
76 | node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): |
|
76 | node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): | |
77 | if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: |
|
77 | if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: | |
78 | # Still going in the same non-vertical direction. |
|
78 | # Still going in the same non-vertical direction. | |
79 | if n_columns_diff == -1: |
|
79 | if n_columns_diff == -1: | |
80 | start = max(node_index + 1, p_node_index) |
|
80 | start = max(node_index + 1, p_node_index) | |
81 | tail = ["|", " "] * (start - node_index - 1) |
|
81 | tail = ["|", " "] * (start - node_index - 1) | |
82 | tail.extend(["/", " "] * (n_columns - start)) |
|
82 | tail.extend(["/", " "] * (n_columns - start)) | |
83 | return tail |
|
83 | return tail | |
84 | else: |
|
84 | else: | |
85 | return ["\\", " "] * (n_columns - node_index - 1) |
|
85 | return ["\\", " "] * (n_columns - node_index - 1) | |
86 | else: |
|
86 | else: | |
87 | return ["|", " "] * (n_columns - node_index - 1) |
|
87 | return ["|", " "] * (n_columns - node_index - 1) | |
88 |
|
88 | |||
89 | def draw_edges(edges, nodeline, interline): |
|
89 | def draw_edges(edges, nodeline, interline): | |
90 | for (start, end) in edges: |
|
90 | for (start, end) in edges: | |
91 | if start == end + 1: |
|
91 | if start == end + 1: | |
92 | interline[2 * end + 1] = "/" |
|
92 | interline[2 * end + 1] = "/" | |
93 | elif start == end - 1: |
|
93 | elif start == end - 1: | |
94 | interline[2 * start + 1] = "\\" |
|
94 | interline[2 * start + 1] = "\\" | |
95 | elif start == end: |
|
95 | elif start == end: | |
96 | interline[2 * start] = "|" |
|
96 | interline[2 * start] = "|" | |
97 | else: |
|
97 | else: | |
98 | nodeline[2 * end] = "+" |
|
98 | nodeline[2 * end] = "+" | |
99 | if start > end: |
|
99 | if start > end: | |
100 | (start, end) = (end, start) |
|
100 | (start, end) = (end, start) | |
101 | for i in range(2 * start + 1, 2 * end): |
|
101 | for i in range(2 * start + 1, 2 * end): | |
102 | if nodeline[i] != "+": |
|
102 | if nodeline[i] != "+": | |
103 | nodeline[i] = "-" |
|
103 | nodeline[i] = "-" | |
104 |
|
104 | |||
105 | def get_padding_line(ni, n_columns, edges): |
|
105 | def get_padding_line(ni, n_columns, edges): | |
106 | line = [] |
|
106 | line = [] | |
107 | line.extend(["|", " "] * ni) |
|
107 | line.extend(["|", " "] * ni) | |
108 | if (ni, ni - 1) in edges or (ni, ni) in edges: |
|
108 | if (ni, ni - 1) in edges or (ni, ni) in edges: | |
109 | # (ni, ni - 1) (ni, ni) |
|
109 | # (ni, ni - 1) (ni, ni) | |
110 | # | | | | | | | | |
|
110 | # | | | | | | | | | |
111 | # +---o | | o---+ |
|
111 | # +---o | | o---+ | |
112 | # | | c | | c | | |
|
112 | # | | c | | c | | | |
113 | # | |/ / | |/ / |
|
113 | # | |/ / | |/ / | |
114 | # | | | | | | |
|
114 | # | | | | | | | |
115 | c = "|" |
|
115 | c = "|" | |
116 | else: |
|
116 | else: | |
117 | c = " " |
|
117 | c = " " | |
118 | line.extend([c, " "]) |
|
118 | line.extend([c, " "]) | |
119 | line.extend(["|", " "] * (n_columns - ni - 1)) |
|
119 | line.extend(["|", " "] * (n_columns - ni - 1)) | |
120 | return line |
|
120 | return line | |
121 |
|
121 | |||
122 | def asciistate(): |
|
122 | def asciistate(): | |
123 | """returns the initial value for the "state" argument to ascii()""" |
|
123 | """returns the initial value for the "state" argument to ascii()""" | |
124 | return [0, 0] |
|
124 | return [0, 0] | |
125 |
|
125 | |||
126 | def ascii(ui, state, type, char, text, coldata): |
|
126 | def ascii(ui, state, type, char, text, coldata): | |
127 | """prints an ASCII graph of the DAG |
|
127 | """prints an ASCII graph of the DAG | |
128 |
|
128 | |||
129 | takes the following arguments (one call per node in the graph): |
|
129 | takes the following arguments (one call per node in the graph): | |
130 |
|
130 | |||
131 | - ui to write to |
|
131 | - ui to write to | |
132 | - Somewhere to keep the needed state in (init to asciistate()) |
|
132 | - Somewhere to keep the needed state in (init to asciistate()) | |
133 | - Column of the current node in the set of ongoing edges. |
|
133 | - Column of the current node in the set of ongoing edges. | |
134 | - Type indicator of node data == ASCIIDATA. |
|
134 | - Type indicator of node data == ASCIIDATA. | |
135 | - Payload: (char, lines): |
|
135 | - Payload: (char, lines): | |
136 | - Character to use as node's symbol. |
|
136 | - Character to use as node's symbol. | |
137 | - List of lines to display as the node's text. |
|
137 | - List of lines to display as the node's text. | |
138 | - Edges; a list of (col, next_col) indicating the edges between |
|
138 | - Edges; a list of (col, next_col) indicating the edges between | |
139 | the current node and its parents. |
|
139 | the current node and its parents. | |
140 | - Number of columns (ongoing edges) in the current revision. |
|
140 | - Number of columns (ongoing edges) in the current revision. | |
141 | - The difference between the number of columns (ongoing edges) |
|
141 | - The difference between the number of columns (ongoing edges) | |
142 | in the next revision and the number of columns (ongoing edges) |
|
142 | in the next revision and the number of columns (ongoing edges) | |
143 | in the current revision. That is: -1 means one column removed; |
|
143 | in the current revision. That is: -1 means one column removed; | |
144 | 0 means no columns added or removed; 1 means one column added. |
|
144 | 0 means no columns added or removed; 1 means one column added. | |
145 | """ |
|
145 | """ | |
146 |
|
146 | |||
147 | idx, edges, ncols, coldiff = coldata |
|
147 | idx, edges, ncols, coldiff = coldata | |
148 | assert -2 < coldiff < 2 |
|
148 | assert -2 < coldiff < 2 | |
149 | if coldiff == -1: |
|
149 | if coldiff == -1: | |
150 | # Transform |
|
150 | # Transform | |
151 | # |
|
151 | # | |
152 | # | | | | | | |
|
152 | # | | | | | | | |
153 | # o | | into o---+ |
|
153 | # o | | into o---+ | |
154 | # |X / |/ / |
|
154 | # |X / |/ / | |
155 | # | | | | |
|
155 | # | | | | | |
156 | fix_long_right_edges(edges) |
|
156 | fix_long_right_edges(edges) | |
157 |
|
157 | |||
158 | # add_padding_line says whether to rewrite |
|
158 | # add_padding_line says whether to rewrite | |
159 | # |
|
159 | # | |
160 | # | | | | | | | | |
|
160 | # | | | | | | | | | |
161 | # | o---+ into | o---+ |
|
161 | # | o---+ into | o---+ | |
162 | # | / / | | | # <--- padding line |
|
162 | # | / / | | | # <--- padding line | |
163 | # o | | | / / |
|
163 | # o | | | / / | |
164 | # o | | |
|
164 | # o | | | |
165 | add_padding_line = (len(text) > 2 and coldiff == -1 and |
|
165 | add_padding_line = (len(text) > 2 and coldiff == -1 and | |
166 | [x for (x, y) in edges if x + 1 < y]) |
|
166 | [x for (x, y) in edges if x + 1 < y]) | |
167 |
|
167 | |||
168 | # fix_nodeline_tail says whether to rewrite |
|
168 | # fix_nodeline_tail says whether to rewrite | |
169 | # |
|
169 | # | |
170 | # | | o | | | | o | | |
|
170 | # | | o | | | | o | | | |
171 | # | | |/ / | | |/ / |
|
171 | # | | |/ / | | |/ / | |
172 | # | o | | into | o / / # <--- fixed nodeline tail |
|
172 | # | o | | into | o / / # <--- fixed nodeline tail | |
173 | # | |/ / | |/ / |
|
173 | # | |/ / | |/ / | |
174 | # o | | o | | |
|
174 | # o | | o | | | |
175 | fix_nodeline_tail = len(text) <= 2 and not add_padding_line |
|
175 | fix_nodeline_tail = len(text) <= 2 and not add_padding_line | |
176 |
|
176 | |||
177 | # nodeline is the line containing the node character (typically o) |
|
177 | # nodeline is the line containing the node character (typically o) | |
178 | nodeline = ["|", " "] * idx |
|
178 | nodeline = ["|", " "] * idx | |
179 | nodeline.extend([char, " "]) |
|
179 | nodeline.extend([char, " "]) | |
180 |
|
180 | |||
181 | nodeline.extend( |
|
181 | nodeline.extend( | |
182 | get_nodeline_edges_tail(idx, state[1], ncols, coldiff, |
|
182 | get_nodeline_edges_tail(idx, state[1], ncols, coldiff, | |
183 | state[0], fix_nodeline_tail)) |
|
183 | state[0], fix_nodeline_tail)) | |
184 |
|
184 | |||
185 | # shift_interline is the line containing the non-vertical |
|
185 | # shift_interline is the line containing the non-vertical | |
186 | # edges between this entry and the next |
|
186 | # edges between this entry and the next | |
187 | shift_interline = ["|", " "] * idx |
|
187 | shift_interline = ["|", " "] * idx | |
188 | if coldiff == -1: |
|
188 | if coldiff == -1: | |
189 | n_spaces = 1 |
|
189 | n_spaces = 1 | |
190 | edge_ch = "/" |
|
190 | edge_ch = "/" | |
191 | elif coldiff == 0: |
|
191 | elif coldiff == 0: | |
192 | n_spaces = 2 |
|
192 | n_spaces = 2 | |
193 | edge_ch = "|" |
|
193 | edge_ch = "|" | |
194 | else: |
|
194 | else: | |
195 | n_spaces = 3 |
|
195 | n_spaces = 3 | |
196 | edge_ch = "\\" |
|
196 | edge_ch = "\\" | |
197 | shift_interline.extend(n_spaces * [" "]) |
|
197 | shift_interline.extend(n_spaces * [" "]) | |
198 | shift_interline.extend([edge_ch, " "] * (ncols - idx - 1)) |
|
198 | shift_interline.extend([edge_ch, " "] * (ncols - idx - 1)) | |
199 |
|
199 | |||
200 | # draw edges from the current node to its parents |
|
200 | # draw edges from the current node to its parents | |
201 | draw_edges(edges, nodeline, shift_interline) |
|
201 | draw_edges(edges, nodeline, shift_interline) | |
202 |
|
202 | |||
203 | # lines is the list of all graph lines to print |
|
203 | # lines is the list of all graph lines to print | |
204 | lines = [nodeline] |
|
204 | lines = [nodeline] | |
205 | if add_padding_line: |
|
205 | if add_padding_line: | |
206 | lines.append(get_padding_line(idx, ncols, edges)) |
|
206 | lines.append(get_padding_line(idx, ncols, edges)) | |
207 | lines.append(shift_interline) |
|
207 | lines.append(shift_interline) | |
208 |
|
208 | |||
209 | # make sure that there are as many graph lines as there are |
|
209 | # make sure that there are as many graph lines as there are | |
210 | # log strings |
|
210 | # log strings | |
211 | while len(text) < len(lines): |
|
211 | while len(text) < len(lines): | |
212 | text.append("") |
|
212 | text.append("") | |
213 | if len(lines) < len(text): |
|
213 | if len(lines) < len(text): | |
214 | extra_interline = ["|", " "] * (ncols + coldiff) |
|
214 | extra_interline = ["|", " "] * (ncols + coldiff) | |
215 | while len(lines) < len(text): |
|
215 | while len(lines) < len(text): | |
216 | lines.append(extra_interline) |
|
216 | lines.append(extra_interline) | |
217 |
|
217 | |||
218 | # print lines |
|
218 | # print lines | |
219 | indentation_level = max(ncols, ncols + coldiff) |
|
219 | indentation_level = max(ncols, ncols + coldiff) | |
220 | for (line, logstr) in zip(lines, text): |
|
220 | for (line, logstr) in zip(lines, text): | |
221 | ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) |
|
221 | ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) | |
222 | ui.write(ln.rstrip() + '\n') |
|
222 | ui.write(ln.rstrip() + '\n') | |
223 |
|
223 | |||
224 | # ... and start over |
|
224 | # ... and start over | |
225 | state[0] = coldiff |
|
225 | state[0] = coldiff | |
226 | state[1] = idx |
|
226 | state[1] = idx | |
227 |
|
227 | |||
228 | def get_revs(repo, rev_opt): |
|
228 | def get_revs(repo, rev_opt): | |
229 | if rev_opt: |
|
229 | if rev_opt: | |
230 | revs = scmutil.revrange(repo, rev_opt) |
|
230 | revs = scmutil.revrange(repo, rev_opt) | |
231 | if len(revs) == 0: |
|
231 | if len(revs) == 0: | |
232 | return (nullrev, nullrev) |
|
232 | return (nullrev, nullrev) | |
233 | return (max(revs), min(revs)) |
|
233 | return (max(revs), min(revs)) | |
234 | else: |
|
234 | else: | |
235 | return (len(repo) - 1, 0) |
|
235 | return (len(repo) - 1, 0) | |
236 |
|
236 | |||
237 | def check_unsupported_flags(pats, opts): |
|
237 | def check_unsupported_flags(pats, opts): | |
238 | for op in ["follow_first", "copies", "newest_first"]: |
|
238 | for op in ["follow_first", "copies", "newest_first"]: | |
239 | if op in opts and opts[op]: |
|
239 | if op in opts and opts[op]: | |
240 | raise util.Abort(_("-G/--graph option is incompatible with --%s") |
|
240 | raise util.Abort(_("-G/--graph option is incompatible with --%s") | |
241 | % op.replace("_", "-")) |
|
241 | % op.replace("_", "-")) | |
242 | if pats and opts.get('follow'): |
|
242 | if pats and opts.get('follow'): | |
243 | raise util.Abort(_("-G/--graph option is incompatible with --follow " |
|
243 | raise util.Abort(_("-G/--graph option is incompatible with --follow " | |
244 | "with file argument")) |
|
244 | "with file argument")) | |
245 |
|
245 | |||
246 | def revset(pats, opts): |
|
246 | def revset(pats, opts): | |
247 | """Return revset str built of revisions, log options and file patterns. |
|
247 | """Return revset str built of revisions, log options and file patterns. | |
248 | """ |
|
248 | """ | |
249 | opt2revset = { |
|
249 | opt2revset = { | |
250 | 'follow': (0, 'follow()'), |
|
250 | 'follow': (0, 'follow()'), | |
251 | 'no_merges': (0, 'not merge()'), |
|
251 | 'no_merges': (0, 'not merge()'), | |
252 | 'only_merges': (0, 'merge()'), |
|
252 | 'only_merges': (0, 'merge()'), | |
253 | 'removed': (0, 'removes("*")'), |
|
253 | 'removed': (0, 'removes("*")'), | |
254 | 'date': (1, 'date($)'), |
|
254 | 'date': (1, 'date($)'), | |
255 | 'branch': (2, 'branch($)'), |
|
255 | 'branch': (2, 'branch($)'), | |
256 | 'exclude': (2, 'not file($)'), |
|
256 | 'exclude': (2, 'not file($)'), | |
257 | 'include': (2, 'file($)'), |
|
257 | 'include': (2, 'file($)'), | |
258 | 'keyword': (2, 'keyword($)'), |
|
258 | 'keyword': (2, 'keyword($)'), | |
259 | 'only_branch': (2, 'branch($)'), |
|
259 | 'only_branch': (2, 'branch($)'), | |
260 | 'prune': (2, 'not ($ or ancestors($))'), |
|
260 | 'prune': (2, 'not ($ or ancestors($))'), | |
261 | 'user': (2, 'user($)'), |
|
261 | 'user': (2, 'user($)'), | |
262 | } |
|
262 | } | |
263 | optrevset = [] |
|
263 | optrevset = [] | |
264 | revset = [] |
|
264 | revset = [] | |
265 | for op, val in opts.iteritems(): |
|
265 | for op, val in opts.iteritems(): | |
266 | if not val: |
|
266 | if not val: | |
267 | continue |
|
267 | continue | |
268 | if op == 'rev': |
|
268 | if op == 'rev': | |
269 | # Already a revset |
|
269 | # Already a revset | |
270 | revset.extend(val) |
|
270 | revset.extend(val) | |
271 | if op not in opt2revset: |
|
271 | if op not in opt2revset: | |
272 | continue |
|
272 | continue | |
273 | arity, revop = opt2revset[op] |
|
273 | arity, revop = opt2revset[op] | |
274 | revop = revop.replace('$', '%(val)r') |
|
274 | revop = revop.replace('$', '%(val)r') | |
275 | if arity == 0: |
|
275 | if arity == 0: | |
276 | optrevset.append(revop) |
|
276 | optrevset.append(revop) | |
277 | elif arity == 1: |
|
277 | elif arity == 1: | |
278 | optrevset.append(revop % {'val': val}) |
|
278 | optrevset.append(revop % {'val': val}) | |
279 | else: |
|
279 | else: | |
280 | for f in val: |
|
280 | for f in val: | |
281 | optrevset.append(revop % {'val': f}) |
|
281 | optrevset.append(revop % {'val': f}) | |
282 |
|
282 | |||
283 | for path in pats: |
|
283 | for path in pats: | |
284 | optrevset.append('file(%r)' % path) |
|
284 | optrevset.append('file(%r)' % path) | |
285 |
|
285 | |||
286 | if revset or optrevset: |
|
286 | if revset or optrevset: | |
287 | if revset: |
|
287 | if revset: | |
288 | revset = ['(' + ' or '.join(revset) + ')'] |
|
288 | revset = ['(' + ' or '.join(revset) + ')'] | |
289 | if optrevset: |
|
289 | if optrevset: | |
290 | revset.append('(' + ' and '.join(optrevset) + ')') |
|
290 | revset.append('(' + ' and '.join(optrevset) + ')') | |
291 | revset = ' and '.join(revset) |
|
291 | revset = ' and '.join(revset) | |
292 | else: |
|
292 | else: | |
293 | revset = 'all()' |
|
293 | revset = 'all()' | |
294 | return revset |
|
294 | return revset | |
295 |
|
295 | |||
296 | def generate(ui, dag, displayer, showparents, edgefn): |
|
296 | def generate(ui, dag, displayer, showparents, edgefn): | |
297 | seen, state = [], asciistate() |
|
297 | seen, state = [], asciistate() | |
298 | for rev, type, ctx, parents in dag: |
|
298 | for rev, type, ctx, parents in dag: | |
299 | char = ctx.node() in showparents and '@' or 'o' |
|
299 | char = ctx.node() in showparents and '@' or 'o' | |
300 | displayer.show(ctx) |
|
300 | displayer.show(ctx) | |
301 | lines = displayer.hunk.pop(rev).split('\n')[:-1] |
|
301 | lines = displayer.hunk.pop(rev).split('\n')[:-1] | |
302 | displayer.flush(rev) |
|
302 | displayer.flush(rev) | |
303 | edges = edgefn(type, char, lines, seen, rev, parents) |
|
303 | edges = edgefn(type, char, lines, seen, rev, parents) | |
304 | for type, char, lines, coldata in edges: |
|
304 | for type, char, lines, coldata in edges: | |
305 | ascii(ui, state, type, char, lines, coldata) |
|
305 | ascii(ui, state, type, char, lines, coldata) | |
306 | displayer.close() |
|
306 | displayer.close() | |
307 |
|
307 | |||
308 | @command('glog', |
|
308 | @command('glog', | |
309 | [('l', 'limit', '', |
|
309 | [('l', 'limit', '', | |
310 | _('limit number of changes displayed'), _('NUM')), |
|
310 | _('limit number of changes displayed'), _('NUM')), | |
311 | ('p', 'patch', False, _('show patch')), |
|
311 | ('p', 'patch', False, _('show patch')), | |
312 | ('r', 'rev', [], _('show the specified revision or range'), _('REV')), |
|
312 | ('r', 'rev', [], _('show the specified revision or range'), _('REV')), | |
313 | ] + templateopts, |
|
313 | ] + templateopts, | |
314 | _('hg glog [OPTION]... [FILE]')) |
|
314 | _('hg glog [OPTION]... [FILE]')) | |
315 | def graphlog(ui, repo, *pats, **opts): |
|
315 | def graphlog(ui, repo, *pats, **opts): | |
316 | """show revision history alongside an ASCII revision graph |
|
316 | """show revision history alongside an ASCII revision graph | |
317 |
|
317 | |||
318 | Print a revision history alongside a revision graph drawn with |
|
318 | Print a revision history alongside a revision graph drawn with | |
319 | ASCII characters. |
|
319 | ASCII characters. | |
320 |
|
320 | |||
321 | Nodes printed as an @ character are parents of the working |
|
321 | Nodes printed as an @ character are parents of the working | |
322 | directory. |
|
322 | directory. | |
323 | """ |
|
323 | """ | |
324 |
|
324 | |||
325 | check_unsupported_flags(pats, opts) |
|
325 | check_unsupported_flags(pats, opts) | |
326 |
|
326 | |||
327 | revs = sorted(scmutil.revrange(repo, [revset(pats, opts)]), reverse=1) |
|
327 | revs = sorted(scmutil.revrange(repo, [revset(pats, opts)]), reverse=1) | |
328 | limit = cmdutil.loglimit(opts) |
|
328 | limit = cmdutil.loglimit(opts) | |
329 | if limit is not None: |
|
329 | if limit is not None: | |
330 | revs = revs[:limit] |
|
330 | revs = revs[:limit] | |
331 | revdag = graphmod.dagwalker(repo, revs) |
|
331 | revdag = graphmod.dagwalker(repo, revs) | |
332 |
|
332 | |||
333 | displayer = show_changeset(ui, repo, opts, buffered=True) |
|
333 | displayer = show_changeset(ui, repo, opts, buffered=True) | |
334 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
334 | showparents = [ctx.node() for ctx in repo[None].parents()] | |
335 | generate(ui, revdag, displayer, showparents, asciiedges) |
|
335 | generate(ui, revdag, displayer, showparents, asciiedges) | |
336 |
|
336 | |||
337 | def graphrevs(repo, nodes, opts): |
|
337 | def graphrevs(repo, nodes, opts): | |
338 | limit = cmdutil.loglimit(opts) |
|
338 | limit = cmdutil.loglimit(opts) | |
339 | nodes.reverse() |
|
339 | nodes.reverse() | |
340 | if limit is not None: |
|
340 | if limit is not None: | |
341 | nodes = nodes[:limit] |
|
341 | nodes = nodes[:limit] | |
342 | return graphmod.nodes(repo, nodes) |
|
342 | return graphmod.nodes(repo, nodes) | |
343 |
|
343 | |||
344 | def goutgoing(ui, repo, dest=None, **opts): |
|
344 | def goutgoing(ui, repo, dest=None, **opts): | |
345 | """show the outgoing changesets alongside an ASCII revision graph |
|
345 | """show the outgoing changesets alongside an ASCII revision graph | |
346 |
|
346 | |||
347 | Print the outgoing changesets alongside a revision graph drawn with |
|
347 | Print the outgoing changesets alongside a revision graph drawn with | |
348 | ASCII characters. |
|
348 | ASCII characters. | |
349 |
|
349 | |||
350 | Nodes printed as an @ character are parents of the working |
|
350 | Nodes printed as an @ character are parents of the working | |
351 | directory. |
|
351 | directory. | |
352 | """ |
|
352 | """ | |
353 |
|
353 | |||
354 | check_unsupported_flags([], opts) |
|
354 | check_unsupported_flags([], opts) | |
355 | o = hg._outgoing(ui, repo, dest, opts) |
|
355 | o = hg._outgoing(ui, repo, dest, opts) | |
356 | if o is None: |
|
356 | if o is None: | |
357 | return |
|
357 | return | |
358 |
|
358 | |||
359 | revdag = graphrevs(repo, o, opts) |
|
359 | revdag = graphrevs(repo, o, opts) | |
360 | displayer = show_changeset(ui, repo, opts, buffered=True) |
|
360 | displayer = show_changeset(ui, repo, opts, buffered=True) | |
361 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
361 | showparents = [ctx.node() for ctx in repo[None].parents()] | |
362 | generate(ui, revdag, displayer, showparents, asciiedges) |
|
362 | generate(ui, revdag, displayer, showparents, asciiedges) | |
363 |
|
363 | |||
364 | def gincoming(ui, repo, source="default", **opts): |
|
364 | def gincoming(ui, repo, source="default", **opts): | |
365 | """show the incoming changesets alongside an ASCII revision graph |
|
365 | """show the incoming changesets alongside an ASCII revision graph | |
366 |
|
366 | |||
367 | Print the incoming changesets alongside a revision graph drawn with |
|
367 | Print the incoming changesets alongside a revision graph drawn with | |
368 | ASCII characters. |
|
368 | ASCII characters. | |
369 |
|
369 | |||
370 | Nodes printed as an @ character are parents of the working |
|
370 | Nodes printed as an @ character are parents of the working | |
371 | directory. |
|
371 | directory. | |
372 | """ |
|
372 | """ | |
373 | def subreporecurse(): |
|
373 | def subreporecurse(): | |
374 | return 1 |
|
374 | return 1 | |
375 |
|
375 | |||
376 | check_unsupported_flags([], opts) |
|
376 | check_unsupported_flags([], opts) | |
377 | def display(other, chlist, displayer): |
|
377 | def display(other, chlist, displayer): | |
378 | revdag = graphrevs(other, chlist, opts) |
|
378 | revdag = graphrevs(other, chlist, opts) | |
379 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
379 | showparents = [ctx.node() for ctx in repo[None].parents()] | |
380 | generate(ui, revdag, displayer, showparents, asciiedges) |
|
380 | generate(ui, revdag, displayer, showparents, asciiedges) | |
381 |
|
381 | |||
382 | hg._incoming(display, subreporecurse, ui, repo, source, opts, buffered=True) |
|
382 | hg._incoming(display, subreporecurse, ui, repo, source, opts, buffered=True) | |
383 |
|
383 | |||
384 | def uisetup(ui): |
|
384 | def uisetup(ui): | |
385 | '''Initialize the extension.''' |
|
385 | '''Initialize the extension.''' | |
386 |
_wrapcmd( |
|
386 | _wrapcmd('log', commands.table, graphlog) | |
387 |
_wrapcmd( |
|
387 | _wrapcmd('incoming', commands.table, gincoming) | |
388 |
_wrapcmd( |
|
388 | _wrapcmd('outgoing', commands.table, goutgoing) | |
389 |
|
389 | |||
390 |
def _wrapcmd( |
|
390 | def _wrapcmd(cmd, table, wrapfn): | |
391 | '''wrap the command''' |
|
391 | '''wrap the command''' | |
392 | def graph(orig, *args, **kwargs): |
|
392 | def graph(orig, *args, **kwargs): | |
393 | if kwargs['graph']: |
|
393 | if kwargs['graph']: | |
394 | return wrapfn(*args, **kwargs) |
|
394 | return wrapfn(*args, **kwargs) | |
395 | return orig(*args, **kwargs) |
|
395 | return orig(*args, **kwargs) | |
396 | entry = extensions.wrapcommand(table, cmd, graph) |
|
396 | entry = extensions.wrapcommand(table, cmd, graph) | |
397 | entry[1].append(('G', 'graph', None, _("show the revision DAG"))) |
|
397 | entry[1].append(('G', 'graph', None, _("show the revision DAG"))) |
General Comments 0
You need to be logged in to leave comments.
Login now