Mercurial > hg
annotate hgext/graphlog.py @ 7326:ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Makes it easier to read all of the code.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 07 Nov 2008 11:44:37 +0100 |
parents | f9985108d4e4 |
children | fac7e9070a19 |
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 # |
4344 | 5 # This software may be used and distributed according to the terms of |
6 # the GNU General Public License, incorporated herein by reference. | |
6666
53465a7464e2
convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6212
diff
changeset
|
7 '''show revision graphs in terminal windows''' |
4344 | 8 |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
9 import os |
4344 | 10 import sys |
11 from mercurial.cmdutil import revrange, show_changeset | |
6192
cd65a67aff31
Introduce templateopts and logopts to reduce duplicate option definitions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5968
diff
changeset
|
12 from mercurial.commands import templateopts |
4344 | 13 from mercurial.i18n import _ |
6212 | 14 from mercurial.node import nullrev |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
15 from mercurial.util import Abort, canonpath |
6762 | 16 from mercurial import util |
4344 | 17 |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
18 def get_rev_parents(repo, rev): |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
19 return [x for x in repo.changelog.parentrevs(rev) if x != nullrev] |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
20 |
4344 | 21 def revision_grapher(repo, start_rev, stop_rev): |
22 """incremental revision grapher | |
23 | |
24 This generator function walks through the revision history from | |
25 revision start_rev to revision stop_rev (which must be less than | |
26 or equal to start_rev) and for each revision emits tuples with the | |
27 following elements: | |
28 | |
29 - Current revision. | |
30 - Current node. | |
31 - Column of the current node in the set of ongoing edges. | |
32 - Edges; a list of (col, next_col) indicating the edges between | |
33 the current node and its parents. | |
34 - Number of columns (ongoing edges) in the current revision. | |
35 - The difference between the number of columns (ongoing edges) | |
36 in the next revision and the number of columns (ongoing edges) | |
37 in the current revision. That is: -1 means one column removed; | |
38 0 means no columns added or removed; 1 means one column added. | |
39 """ | |
40 | |
41 assert start_rev >= stop_rev | |
42 curr_rev = start_rev | |
43 revs = [] | |
44 while curr_rev >= stop_rev: | |
45 node = repo.changelog.node(curr_rev) | |
46 | |
47 # Compute revs and next_revs. | |
48 if curr_rev not in revs: | |
49 # New head. | |
50 revs.append(curr_rev) | |
51 rev_index = revs.index(curr_rev) | |
52 next_revs = revs[:] | |
53 | |
54 # Add parents to next_revs. | |
55 parents = get_rev_parents(repo, curr_rev) | |
56 parents_to_add = [] | |
57 for parent in parents: | |
58 if parent not in next_revs: | |
59 parents_to_add.append(parent) | |
6762 | 60 next_revs[rev_index:rev_index + 1] = util.sort(parents_to_add) |
4344 | 61 |
62 edges = [] | |
63 for parent in parents: | |
64 edges.append((rev_index, next_revs.index(parent))) | |
65 | |
66 n_columns_diff = len(next_revs) - len(revs) | |
67 yield (curr_rev, node, rev_index, edges, len(revs), n_columns_diff) | |
68 | |
69 revs = next_revs | |
70 curr_rev -= 1 | |
71 | |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
72 def filelog_grapher(repo, path, start_rev, stop_rev): |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
73 """incremental file log grapher |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
74 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
75 This generator function walks through the revision history of a |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
76 single file from revision start_rev to revision stop_rev (which must |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
77 be less than or equal to start_rev) and for each revision emits |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
78 tuples with the following elements: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
79 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
80 - Current revision. |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
81 - Current node. |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
82 - Column of the current node in the set of ongoing edges. |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
83 - Edges; a list of (col, next_col) indicating the edges between |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
84 the current node and its parents. |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
85 - Number of columns (ongoing edges) in the current revision. |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
86 - The difference between the number of columns (ongoing edges) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
87 in the next revision and the number of columns (ongoing edges) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
88 in the current revision. That is: -1 means one column removed; |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
89 0 means no columns added or removed; 1 means one column added. |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
90 """ |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
91 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
92 assert start_rev >= stop_rev |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
93 revs = [] |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6666
diff
changeset
|
94 filerev = len(repo.file(path)) - 1 |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
95 while filerev >= 0: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
96 fctx = repo.filectx(path, fileid=filerev) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
97 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
98 # Compute revs and next_revs. |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
99 if filerev not in revs: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
100 revs.append(filerev) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
101 rev_index = revs.index(filerev) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
102 next_revs = revs[:] |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
103 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
104 # Add parents to next_revs. |
5968
6dcc190ffc36
graphlog: skip filectx parents in other filelogs
Steve Borho <steve@borho.org>
parents:
5942
diff
changeset
|
105 parents = [f.filerev() for f in fctx.parents() if f.path() == path] |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
106 parents_to_add = [] |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
107 for parent in parents: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
108 if parent not in next_revs: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
109 parents_to_add.append(parent) |
6762 | 110 next_revs[rev_index:rev_index + 1] = util.sort(parents_to_add) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
111 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
112 edges = [] |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
113 for parent in parents: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
114 edges.append((rev_index, next_revs.index(parent))) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
115 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
116 changerev = fctx.linkrev() |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
117 if changerev <= start_rev: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
118 node = repo.changelog.node(changerev) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
119 n_columns_diff = len(next_revs) - len(revs) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
120 yield (changerev, node, rev_index, edges, len(revs), n_columns_diff) |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
121 if changerev <= stop_rev: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
122 break |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
123 revs = next_revs |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
124 filerev -= 1 |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
125 |
4344 | 126 def fix_long_right_edges(edges): |
127 for (i, (start, end)) in enumerate(edges): | |
128 if end > start: | |
129 edges[i] = (start, end + 1) | |
130 | |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
131 def get_nodeline_edges_tail( |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
132 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
|
133 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
|
134 # 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
|
135 if n_columns_diff == -1: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
136 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
|
137 tail = ["|", " "] * (start - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
138 tail.extend(["/", " "] * (n_columns - start)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
139 return tail |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
140 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
141 return ["\\", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
142 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
143 return ["|", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
144 |
4344 | 145 def draw_edges(edges, nodeline, interline): |
146 for (start, end) in edges: | |
147 if start == end + 1: | |
148 interline[2 * end + 1] = "/" | |
149 elif start == end - 1: | |
150 interline[2 * start + 1] = "\\" | |
151 elif start == end: | |
152 interline[2 * start] = "|" | |
153 else: | |
154 nodeline[2 * end] = "+" | |
155 if start > end: | |
156 (start, end) = (end,start) | |
157 for i in range(2 * start + 1, 2 * end): | |
158 if nodeline[i] != "+": | |
159 nodeline[i] = "-" | |
160 | |
161 def get_padding_line(ni, n_columns, edges): | |
162 line = [] | |
163 line.extend(["|", " "] * ni) | |
164 if (ni, ni - 1) in edges or (ni, ni) in edges: | |
165 # (ni, ni - 1) (ni, ni) | |
166 # | | | | | | | | | |
167 # +---o | | o---+ | |
168 # | | c | | c | | | |
169 # | |/ / | |/ / | |
170 # | | | | | | | |
171 c = "|" | |
172 else: | |
173 c = " " | |
174 line.extend([c, " "]) | |
175 line.extend(["|", " "] * (n_columns - ni - 1)) | |
176 return line | |
177 | |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
178 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
|
179 """prints an ASCII graph of the DAG returned by the grapher |
4344 | 180 |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
181 grapher is a generator that emits tuples with the following elements: |
4344 | 182 |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
183 - 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
|
184 - 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
|
185 - 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
|
186 - 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
|
187 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
|
188 - 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
|
189 - 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
|
190 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
|
191 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
|
192 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
|
193 """ |
4344 | 194 prev_n_columns_diff = 0 |
195 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
|
196 for (node_ch, node_lines, node_index, edges, n_columns, n_columns_diff) in grapher: |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
197 # node_lines is the list of all text lines to draw alongside the graph |
4344 | 198 |
199 if n_columns_diff == -1: | |
200 # Transform | |
201 # | |
202 # | | | | | | | |
203 # o | | into o---+ | |
204 # |X / |/ / | |
205 # | | | | | |
206 fix_long_right_edges(edges) | |
207 | |
208 # add_padding_line says whether to rewrite | |
209 # | |
210 # | | | | | | | | | |
211 # | o---+ into | o---+ | |
212 # | / / | | | # <--- padding line | |
213 # o | | | / / | |
214 # o | | | |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
215 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
|
216 n_columns_diff == -1 and |
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4583
diff
changeset
|
217 [x for (x, y) in edges if x + 1 < y]) |
4344 | 218 |
219 # fix_nodeline_tail says whether to rewrite | |
220 # | |
221 # | | o | | | | o | | | |
222 # | | |/ / | | |/ / | |
223 # | o | | into | o / / # <--- fixed nodeline tail | |
224 # | |/ / | |/ / | |
225 # o | | o | | | |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
226 fix_nodeline_tail = len(node_lines) <= 2 and not add_padding_line |
4344 | 227 |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
228 # nodeline is the line containing the node character (typically o) |
4344 | 229 nodeline = ["|", " "] * node_index |
230 nodeline.extend([node_ch, " "]) | |
231 | |
232 nodeline.extend( | |
233 get_nodeline_edges_tail( | |
234 node_index, prev_node_index, n_columns, n_columns_diff, | |
235 prev_n_columns_diff, fix_nodeline_tail)) | |
236 | |
237 # 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
|
238 # edges between this entry and the next |
4344 | 239 shift_interline = ["|", " "] * node_index |
240 if n_columns_diff == -1: | |
241 n_spaces = 1 | |
242 edge_ch = "/" | |
243 elif n_columns_diff == 0: | |
244 n_spaces = 2 | |
245 edge_ch = "|" | |
246 else: | |
247 n_spaces = 3 | |
248 edge_ch = "\\" | |
249 shift_interline.extend(n_spaces * [" "]) | |
250 shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1)) | |
251 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
252 # draw edges from the current node to its parents |
4344 | 253 draw_edges(edges, nodeline, shift_interline) |
254 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
255 # lines is the list of all graph lines to print |
4344 | 256 lines = [nodeline] |
257 if add_padding_line: | |
258 lines.append(get_padding_line(node_index, n_columns, edges)) | |
259 lines.append(shift_interline) | |
260 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
261 # 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
|
262 # log strings |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
263 while len(node_lines) < len(lines): |
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
264 node_lines.append("") |
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
265 if len(lines) < len(node_lines): |
4344 | 266 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
|
267 while len(lines) < len(node_lines): |
4344 | 268 lines.append(extra_interline) |
269 | |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
270 # print lines |
4344 | 271 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
|
272 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
|
273 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
|
274 ui.write(ln.rstrip() + '\n') |
4344 | 275 |
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
276 # ... and start over |
4344 | 277 prev_node_index = node_index |
278 prev_n_columns_diff = n_columns_diff | |
279 | |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
280 def get_limit(limit_opt): |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
281 if limit_opt: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
282 try: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
283 limit = int(limit_opt) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
284 except ValueError: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
285 raise Abort(_("limit must be a positive integer")) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
286 if limit <= 0: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
287 raise Abort(_("limit must be positive")) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
288 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
289 limit = sys.maxint |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
290 return limit |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
291 |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
292 def get_revs(repo, rev_opt): |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
293 if rev_opt: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
294 revs = revrange(repo, rev_opt) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
295 return (max(revs), min(revs)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
296 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
297 return (len(repo) - 1, 0) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
298 |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
299 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
|
300 """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
|
301 |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
302 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
|
303 ASCII characters. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
304 |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
305 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
|
306 directory. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
307 """ |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
308 |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
309 limit = get_limit(opts["limit"]) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
310 (start_rev, stop_rev) = get_revs(repo, opts["rev"]) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
311 stop_rev = max(stop_rev, start_rev - limit + 1) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
312 if start_rev == nullrev: |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
313 return |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
314 if path: |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
315 path = canonpath(repo.root, os.getcwd(), path) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
316 if path: |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
317 revgrapher = filelog_grapher(repo, path, start_rev, stop_rev) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
318 else: |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
319 revgrapher = revision_grapher(repo, start_rev, stop_rev) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
320 |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
321 repo_parents = repo.dirstate.parents() |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
322 cs_printer = show_changeset(ui, repo, opts) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
323 def grapher(): |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
324 for (rev, node, node_index, edges, n_columns, n_columns_diff) in revgrapher: |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
325 # log_strings is the list of all log strings to draw alongside |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
326 # the graph. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
327 ui.pushbuffer() |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
328 cs_printer.show(rev, node) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
329 log_strings = ui.popbuffer().split("\n")[:-1] |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
330 if node in repo_parents: |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
331 node_ch = "@" |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
332 else: |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
333 node_ch = "o" |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
334 yield (node_ch, log_strings, node_index, edges, n_columns, n_columns_diff) |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
335 |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
336 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
|
337 |
4344 | 338 cmdtable = { |
339 "glog": | |
4730
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
340 (graphlog, |
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
341 [('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
|
342 ('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
|
343 ('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
|
344 ] + templateopts, |
5942
b75105de8573
glog shows at most one file: correct synopsis
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5940
diff
changeset
|
345 _('hg glog [OPTION]... [FILE]')), |
4344 | 346 } |