Mercurial > hg-stable
annotate hgext/graphlog.py @ 8836:11ff34956ee7
graphmod/graphlog: move log walks to graphmod
author | Peter Arrenbrecht <peter.arrenbrecht@gmail.com> |
---|---|
date | Fri, 19 Jun 2009 13:14:01 +0200 |
parents | 594507755800 |
children | d8e3a98018cb |
rev | line source |
---|---|
4344 | 1 # ASCII graph log extension for Mercurial |
2 # | |
3 # Copyright 2007 Joel Rosdahl <joel@rosdahl.net> | |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4509
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
6 # GNU General Public License version 2, incorporated herein by reference. |
8228
eee2319c5895
add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
7 |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
8 '''show revision graphs in terminal windows |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
9 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
10 This extension adds a --graph option to the incoming, outgoing and log |
8667
594507755800
graphlog, win32mbcs: capitalize ASCII
Martin Geisler <mg@lazybytes.net>
parents:
8228
diff
changeset
|
11 commands. When this options is given, an ASCII representation of the |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
12 revision graph is also shown. |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
13 ''' |
4344 | 14 |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
15 import os |
4344 | 16 from mercurial.cmdutil import revrange, show_changeset |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7763
diff
changeset
|
17 from mercurial.commands import templateopts |
4344 | 18 from mercurial.i18n import _ |
6212 | 19 from mercurial.node import nullrev |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
20 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions |
8836
11ff34956ee7
graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8667
diff
changeset
|
21 from mercurial import hg, url, util, graphmod |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
22 |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
23 def grapher(nodes): |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
24 """grapher for asciigraph on a list of nodes and their parents |
7374
ccec5ae82282
graphlog: kill whitespace from earlier refactoring
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7371
diff
changeset
|
25 |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
26 nodes must generate tuples (node, parents, char, lines) where |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
27 - parents must generate the parents of node, in sorted order, |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
28 and max length 2, |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
29 - char is the char to print as the node symbol, and |
7374
ccec5ae82282
graphlog: kill whitespace from earlier refactoring
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7371
diff
changeset
|
30 - lines are the lines to display next to the node. |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
31 """ |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
32 seen = [] |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
33 for node, parents, char, lines in nodes: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
34 if node not in seen: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
35 seen.append(node) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
36 nodeidx = seen.index(node) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
37 |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
38 knownparents = [] |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
39 newparents = [] |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
40 for parent in parents: |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
41 if parent in seen: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
42 knownparents.append(parent) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
43 else: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
44 newparents.append(parent) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
45 |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
46 ncols = len(seen) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
47 nextseen = seen[:] |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
48 nextseen[nodeidx:nodeidx + 1] = newparents |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
49 edges = [(nodeidx, nextseen.index(p)) for p in knownparents] |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
50 |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
51 if len(newparents) > 0: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
52 edges.append((nodeidx, nodeidx)) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
53 if len(newparents) > 1: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
54 edges.append((nodeidx, nodeidx + 1)) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
55 nmorecols = len(nextseen) - ncols |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
56 seen = nextseen |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
57 yield (char, lines, nodeidx, edges, ncols, nmorecols) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
58 |
4344 | 59 def fix_long_right_edges(edges): |
60 for (i, (start, end)) in enumerate(edges): | |
61 if end > start: | |
62 edges[i] = (start, end + 1) | |
63 | |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
64 def get_nodeline_edges_tail( |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
65 node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
66 if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
67 # Still going in the same non-vertical direction. |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
68 if n_columns_diff == -1: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
69 start = max(node_index + 1, p_node_index) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
70 tail = ["|", " "] * (start - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
71 tail.extend(["/", " "] * (n_columns - start)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
72 return tail |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
73 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
74 return ["\\", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
75 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
76 return ["|", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
77 |
4344 | 78 def draw_edges(edges, nodeline, interline): |
79 for (start, end) in edges: | |
80 if start == end + 1: | |
81 interline[2 * end + 1] = "/" | |
82 elif start == end - 1: | |
83 interline[2 * start + 1] = "\\" | |
84 elif start == end: | |
85 interline[2 * start] = "|" | |
86 else: | |
87 nodeline[2 * end] = "+" | |
88 if start > end: | |
89 (start, end) = (end,start) | |
90 for i in range(2 * start + 1, 2 * end): | |
91 if nodeline[i] != "+": | |
92 nodeline[i] = "-" | |
93 | |
94 def get_padding_line(ni, n_columns, edges): | |
95 line = [] | |
96 line.extend(["|", " "] * ni) | |
97 if (ni, ni - 1) in edges or (ni, ni) in edges: | |
98 # (ni, ni - 1) (ni, ni) | |
99 # | | | | | | | | | |
100 # +---o | | o---+ | |
101 # | | c | | c | | | |
102 # | |/ / | |/ / | |
103 # | | | | | | | |
104 c = "|" | |
105 else: | |
106 c = " " | |
107 line.extend([c, " "]) | |
108 line.extend(["|", " "] * (n_columns - ni - 1)) | |
109 return line | |
110 | |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
111 def ascii(ui, grapher): |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
112 """prints an ASCII graph of the DAG returned by the grapher |
4344 | 113 |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
114 grapher is a generator that emits tuples with the following elements: |
4344 | 115 |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
116 - Character to use as node's symbol. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
117 - List of lines to display as the node's text. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
118 - Column of the current node in the set of ongoing edges. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
119 - Edges; a list of (col, next_col) indicating the edges between |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
120 the current node and its parents. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
121 - Number of columns (ongoing edges) in the current revision. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
122 - The difference between the number of columns (ongoing edges) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
123 in the next revision and the number of columns (ongoing edges) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
124 in the current revision. That is: -1 means one column removed; |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
125 0 means no columns added or removed; 1 means one column added. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
126 """ |
4344 | 127 prev_n_columns_diff = 0 |
128 prev_node_index = 0 | |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
129 for (node_ch, node_lines, node_index, edges, n_columns, n_columns_diff) in grapher: |
4344 | 130 |
7356
eee5b7b9c5d2
graphlog: add assertion for allowed n_column_diff range
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7355
diff
changeset
|
131 assert -2 < n_columns_diff < 2 |
4344 | 132 if n_columns_diff == -1: |
133 # Transform | |
134 # | |
135 # | | | | | | | |
136 # o | | into o---+ | |
137 # |X / |/ / | |
138 # | | | | | |
139 fix_long_right_edges(edges) | |
140 | |
141 # add_padding_line says whether to rewrite | |
142 # | |
143 # | | | | | | | | | |
144 # | o---+ into | o---+ | |
145 # | / / | | | # <--- padding line | |
146 # o | | | / / | |
147 # o | | | |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
148 add_padding_line = (len(node_lines) > 2 and |
4633
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4583
diff
changeset
|
149 n_columns_diff == -1 and |
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4583
diff
changeset
|
150 [x for (x, y) in edges if x + 1 < y]) |
4344 | 151 |
152 # fix_nodeline_tail says whether to rewrite | |
153 # | |
154 # | | o | | | | o | | | |
155 # | | |/ / | | |/ / | |
156 # | o | | into | o / / # <--- fixed nodeline tail | |
157 # | |/ / | |/ / | |
158 # o | | o | | | |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
159 fix_nodeline_tail = len(node_lines) <= 2 and not add_padding_line |
4344 | 160 |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
161 # nodeline is the line containing the node character (typically o) |
4344 | 162 nodeline = ["|", " "] * node_index |
163 nodeline.extend([node_ch, " "]) | |
164 | |
165 nodeline.extend( | |
166 get_nodeline_edges_tail( | |
167 node_index, prev_node_index, n_columns, n_columns_diff, | |
168 prev_n_columns_diff, fix_nodeline_tail)) | |
169 | |
170 # shift_interline is the line containing the non-vertical | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
171 # edges between this entry and the next |
4344 | 172 shift_interline = ["|", " "] * node_index |
173 if n_columns_diff == -1: | |
174 n_spaces = 1 | |
175 edge_ch = "/" | |
176 elif n_columns_diff == 0: | |
177 n_spaces = 2 | |
178 edge_ch = "|" | |
179 else: | |
180 n_spaces = 3 | |
181 edge_ch = "\\" | |
182 shift_interline.extend(n_spaces * [" "]) | |
183 shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1)) | |
184 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
185 # draw edges from the current node to its parents |
4344 | 186 draw_edges(edges, nodeline, shift_interline) |
187 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
188 # lines is the list of all graph lines to print |
4344 | 189 lines = [nodeline] |
190 if add_padding_line: | |
191 lines.append(get_padding_line(node_index, n_columns, edges)) | |
192 lines.append(shift_interline) | |
193 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
194 # make sure that there are as many graph lines as there are |
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
195 # log strings |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
196 while len(node_lines) < len(lines): |
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
197 node_lines.append("") |
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
198 if len(lines) < len(node_lines): |
4344 | 199 extra_interline = ["|", " "] * (n_columns + n_columns_diff) |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
200 while len(lines) < len(node_lines): |
4344 | 201 lines.append(extra_interline) |
202 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
203 # print lines |
4344 | 204 indentation_level = max(n_columns, n_columns + n_columns_diff) |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
205 for (line, logstr) in zip(lines, node_lines): |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
206 ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
207 ui.write(ln.rstrip() + '\n') |
4344 | 208 |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
209 # ... and start over |
4344 | 210 prev_node_index = node_index |
211 prev_n_columns_diff = n_columns_diff | |
212 | |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
213 def get_revs(repo, rev_opt): |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
214 if rev_opt: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
215 revs = revrange(repo, rev_opt) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
216 return (max(revs), min(revs)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
217 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
218 return (len(repo) - 1, 0) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
219 |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
220 def check_unsupported_flags(opts): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
221 for op in ["follow", "follow_first", "date", "copies", "keyword", "remove", |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
222 "only_merges", "user", "only_branch", "prune", "newest_first", |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
223 "no_merges", "include", "exclude"]: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
224 if op in opts and opts[op]: |
7713
b8c4ba0fd7c4
graphlog: import util module rather than selected functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7435
diff
changeset
|
225 raise util.Abort(_("--graph option is incompatible with --%s") % op) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
226 |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
227 def graphlog(ui, repo, path=None, **opts): |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
228 """show revision history alongside an ASCII revision graph |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
229 |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
230 Print a revision history alongside a revision graph drawn with |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
231 ASCII characters. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
232 |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
233 Nodes printed as an @ character are parents of the working |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
234 directory. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
235 """ |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
236 |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
237 check_unsupported_flags(opts) |
7715
fd3266287b40
graphlog: reuse cmdutil.loglimit() instead of redefining
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7713
diff
changeset
|
238 limit = cmdutil.loglimit(opts) |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
239 start, stop = get_revs(repo, opts["rev"]) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
240 stop = max(stop, start - limit + 1) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
241 if start == nullrev: |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
242 return |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
243 |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
244 if path: |
7713
b8c4ba0fd7c4
graphlog: import util module rather than selected functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7435
diff
changeset
|
245 path = util.canonpath(repo.root, os.getcwd(), path) |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
246 if path: # could be reset in canonpath |
8836
11ff34956ee7
graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8667
diff
changeset
|
247 revdag = graphmod.filerevs(repo, path, start, stop) |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
248 else: |
8836
11ff34956ee7
graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8667
diff
changeset
|
249 revdag = graphmod.revisions(repo, start, stop) |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
250 |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
251 graphdag = graphabledag(ui, repo, revdag, opts) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
252 ascii(ui, grapher(graphdag)) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
253 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
254 def graphrevs(repo, nodes, opts): |
8150
bbc24c0753a0
util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents:
7875
diff
changeset
|
255 include = set(nodes) |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
256 limit = cmdutil.loglimit(opts) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
257 count = 0 |
8210
344751cd8cb8
replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents:
8188
diff
changeset
|
258 for node in reversed(nodes): |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
259 if count >= limit: |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
260 break |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
261 ctx = repo[node] |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
262 parents = [p.rev() for p in ctx.parents() if p.node() in include] |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
263 parents.sort() |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
264 yield (ctx, parents) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
265 count += 1 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
266 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
267 def graphabledag(ui, repo, revdag, opts): |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
268 showparents = [ctx.node() for ctx in repo[None].parents()] |
7371
6ad2b914acbd
graphlog: use built-in log output buffering
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7370
diff
changeset
|
269 displayer = show_changeset(ui, repo, opts, buffered=True) |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
270 for (ctx, parents) in revdag: |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
271 displayer.show(ctx) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
272 lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1] |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
273 char = ctx.node() in showparents and '@' or 'o' |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
274 yield (ctx.rev(), parents, char, lines) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
275 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
276 def goutgoing(ui, repo, dest=None, **opts): |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
277 """show the outgoing changesets alongside an ASCII revision graph |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
278 |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
279 Print the outgoing changesets alongside a revision graph drawn with |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
280 ASCII characters. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
281 |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
282 Nodes printed as an @ character are parents of the working |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
283 directory. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
284 """ |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
285 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
286 check_unsupported_flags(opts) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
287 dest, revs, checkout = hg.parseurl( |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
288 ui.expandpath(dest or 'default-push', dest or 'default'), |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
289 opts.get('rev')) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
290 if revs: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
291 revs = [repo.lookup(rev) for rev in revs] |
8188 | 292 other = hg.repository(cmdutil.remoteui(ui, opts), dest) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
293 ui.status(_('comparing with %s\n') % url.hidepassword(dest)) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
294 o = repo.findoutgoing(other, force=opts.get('force')) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
295 if not o: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
296 ui.status(_("no changes found\n")) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
297 return |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
298 |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
299 o = repo.changelog.nodesbetween(o, revs)[0] |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
300 revdag = graphrevs(repo, o, opts) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
301 graphdag = graphabledag(ui, repo, revdag, opts) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
302 ascii(ui, grapher(graphdag)) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
303 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
304 def gincoming(ui, repo, source="default", **opts): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
305 """show the incoming changesets alongside an ASCII revision graph |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
306 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
307 Print the incoming changesets alongside a revision graph drawn with |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
308 ASCII characters. |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
309 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
310 Nodes printed as an @ character are parents of the working |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
311 directory. |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
312 """ |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
313 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
314 check_unsupported_flags(opts) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
315 source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev')) |
8188 | 316 other = hg.repository(cmdutil.remoteui(repo, opts), source) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
317 ui.status(_('comparing with %s\n') % url.hidepassword(source)) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
318 if revs: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
319 revs = [other.lookup(rev) for rev in revs] |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
320 incoming = repo.findincoming(other, heads=revs, force=opts["force"]) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
321 if not incoming: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
322 try: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
323 os.unlink(opts["bundle"]) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
324 except: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
325 pass |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
326 ui.status(_("no changes found\n")) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
327 return |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
328 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
329 cleanup = None |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
330 try: |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
331 |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
332 fname = opts["bundle"] |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
333 if fname or not other.local(): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
334 # create a bundle (uncompressed if other repo is not local) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
335 if revs is None: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
336 cg = other.changegroup(incoming, "incoming") |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
337 else: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
338 cg = other.changegroupsubset(incoming, revs, 'incoming') |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
339 bundletype = other.local() and "HG10BZ" or "HG10UN" |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
340 fname = cleanup = changegroup.writebundle(cg, fname, bundletype) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
341 # keep written bundle? |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
342 if opts["bundle"]: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
343 cleanup = None |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
344 if not other.local(): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
345 # use the created uncompressed bundlerepo |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
346 other = bundlerepo.bundlerepository(ui, repo.root, fname) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
347 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
348 chlist = other.changelog.nodesbetween(incoming, revs)[0] |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
349 revdag = graphrevs(other, chlist, opts) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
350 graphdag = graphabledag(ui, repo, revdag, opts) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
351 ascii(ui, grapher(graphdag)) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
352 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
353 finally: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
354 if hasattr(other, 'close'): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
355 other.close() |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
356 if cleanup: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
357 os.unlink(cleanup) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
358 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
359 def uisetup(ui): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
360 '''Initialize the extension.''' |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
361 _wrapcmd(ui, 'log', commands.table, graphlog) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
362 _wrapcmd(ui, 'incoming', commands.table, gincoming) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
363 _wrapcmd(ui, 'outgoing', commands.table, goutgoing) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
364 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
365 def _wrapcmd(ui, cmd, table, wrapfn): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
366 '''wrap the command''' |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
367 def graph(orig, *args, **kwargs): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
368 if kwargs['graph']: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
369 return wrapfn(*args, **kwargs) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
370 return orig(*args, **kwargs) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
371 entry = extensions.wrapcommand(table, cmd, graph) |
7763
cdc913e7fc5f
log-like commands now use -G for --graph, -g for --git
Jim Correia <jim.correia@pobox.com>
parents:
7716
diff
changeset
|
372 entry[1].append(('G', 'graph', None, _("show the revision DAG"))) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
373 |
4344 | 374 cmdtable = { |
375 "glog": | |
4730
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
376 (graphlog, |
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
377 [('l', 'limit', '', _('limit number of changes displayed')), |
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
378 ('p', 'patch', False, _('show patch')), |
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
379 ('r', 'rev', [], _('show the specified revision or range')), |
6192
cd65a67aff31
Introduce templateopts and logopts to reduce duplicate option definitions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5968
diff
changeset
|
380 ] + templateopts, |
5942
b75105de8573
glog shows at most one file: correct synopsis
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5940
diff
changeset
|
381 _('hg glog [OPTION]... [FILE]')), |
4344 | 382 } |