12 from mercurial.commands import templateopts |
12 from mercurial.commands import templateopts |
13 from mercurial.i18n import _ |
13 from mercurial.i18n import _ |
14 from mercurial.node import nullrev |
14 from mercurial.node import nullrev |
15 from mercurial.util import Abort, canonpath |
15 from mercurial.util import Abort, canonpath |
16 from mercurial import util |
16 from mercurial import util |
|
17 |
|
18 def get_rev_parents(repo, rev): |
|
19 return [x for x in repo.changelog.parentrevs(rev) if x != nullrev] |
17 |
20 |
18 def revision_grapher(repo, start_rev, stop_rev): |
21 def revision_grapher(repo, start_rev, stop_rev): |
19 """incremental revision grapher |
22 """incremental revision grapher |
20 |
23 |
21 This generator function walks through the revision history from |
24 This generator function walks through the revision history from |
118 if changerev <= stop_rev: |
121 if changerev <= stop_rev: |
119 break |
122 break |
120 revs = next_revs |
123 revs = next_revs |
121 filerev -= 1 |
124 filerev -= 1 |
122 |
125 |
123 def get_rev_parents(repo, rev): |
|
124 return [x for x in repo.changelog.parentrevs(rev) if x != nullrev] |
|
125 |
|
126 def fix_long_right_edges(edges): |
126 def fix_long_right_edges(edges): |
127 for (i, (start, end)) in enumerate(edges): |
127 for (i, (start, end)) in enumerate(edges): |
128 if end > start: |
128 if end > start: |
129 edges[i] = (start, end + 1) |
129 edges[i] = (start, end + 1) |
|
130 |
|
131 def get_nodeline_edges_tail( |
|
132 node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): |
|
133 if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: |
|
134 # Still going in the same non-vertical direction. |
|
135 if n_columns_diff == -1: |
|
136 start = max(node_index + 1, p_node_index) |
|
137 tail = ["|", " "] * (start - node_index - 1) |
|
138 tail.extend(["/", " "] * (n_columns - start)) |
|
139 return tail |
|
140 else: |
|
141 return ["\\", " "] * (n_columns - node_index - 1) |
|
142 else: |
|
143 return ["|", " "] * (n_columns - node_index - 1) |
130 |
144 |
131 def draw_edges(edges, nodeline, interline): |
145 def draw_edges(edges, nodeline, interline): |
132 for (start, end) in edges: |
146 for (start, end) in edges: |
133 if start == end + 1: |
147 if start == end + 1: |
134 interline[2 * end + 1] = "/" |
148 interline[2 * end + 1] = "/" |
142 (start, end) = (end,start) |
156 (start, end) = (end,start) |
143 for i in range(2 * start + 1, 2 * end): |
157 for i in range(2 * start + 1, 2 * end): |
144 if nodeline[i] != "+": |
158 if nodeline[i] != "+": |
145 nodeline[i] = "-" |
159 nodeline[i] = "-" |
146 |
160 |
147 def format_line(line, level, logstr): |
|
148 text = "%-*s %s" % (2 * level, "".join(line), logstr) |
|
149 return "%s\n" % text.rstrip() |
|
150 |
|
151 def get_nodeline_edges_tail( |
|
152 node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): |
|
153 if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: |
|
154 # Still going in the same non-vertical direction. |
|
155 if n_columns_diff == -1: |
|
156 start = max(node_index + 1, p_node_index) |
|
157 tail = ["|", " "] * (start - node_index - 1) |
|
158 tail.extend(["/", " "] * (n_columns - start)) |
|
159 return tail |
|
160 else: |
|
161 return ["\\", " "] * (n_columns - node_index - 1) |
|
162 else: |
|
163 return ["|", " "] * (n_columns - node_index - 1) |
|
164 |
|
165 def get_padding_line(ni, n_columns, edges): |
161 def get_padding_line(ni, n_columns, edges): |
166 line = [] |
162 line = [] |
167 line.extend(["|", " "] * ni) |
163 line.extend(["|", " "] * ni) |
168 if (ni, ni - 1) in edges or (ni, ni) in edges: |
164 if (ni, ni - 1) in edges or (ni, ni) in edges: |
169 # (ni, ni - 1) (ni, ni) |
165 # (ni, ni - 1) (ni, ni) |
176 else: |
172 else: |
177 c = " " |
173 c = " " |
178 line.extend([c, " "]) |
174 line.extend([c, " "]) |
179 line.extend(["|", " "] * (n_columns - ni - 1)) |
175 line.extend(["|", " "] * (n_columns - ni - 1)) |
180 return line |
176 return line |
181 |
|
182 def get_limit(limit_opt): |
|
183 if limit_opt: |
|
184 try: |
|
185 limit = int(limit_opt) |
|
186 except ValueError: |
|
187 raise Abort(_("limit must be a positive integer")) |
|
188 if limit <= 0: |
|
189 raise Abort(_("limit must be positive")) |
|
190 else: |
|
191 limit = sys.maxint |
|
192 return limit |
|
193 |
|
194 def get_revs(repo, rev_opt): |
|
195 if rev_opt: |
|
196 revs = revrange(repo, rev_opt) |
|
197 return (max(revs), min(revs)) |
|
198 else: |
|
199 return (len(repo) - 1, 0) |
|
200 |
177 |
201 def ascii(ui, grapher): |
178 def ascii(ui, grapher): |
202 """prints an ASCII graph of the DAG returned by the grapher |
179 """prints an ASCII graph of the DAG returned by the grapher |
203 |
180 |
204 grapher is a generator that emits tuples with the following elements: |
181 grapher is a generator that emits tuples with the following elements: |
291 lines.append(extra_interline) |
268 lines.append(extra_interline) |
292 |
269 |
293 # print lines |
270 # print lines |
294 indentation_level = max(n_columns, n_columns + n_columns_diff) |
271 indentation_level = max(n_columns, n_columns + n_columns_diff) |
295 for (line, logstr) in zip(lines, node_lines): |
272 for (line, logstr) in zip(lines, node_lines): |
296 ui.write(format_line(line, indentation_level, logstr)) |
273 ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) |
|
274 ui.write(ln.rstrip() + '\n') |
297 |
275 |
298 # ... and start over |
276 # ... and start over |
299 prev_node_index = node_index |
277 prev_node_index = node_index |
300 prev_n_columns_diff = n_columns_diff |
278 prev_n_columns_diff = n_columns_diff |
|
279 |
|
280 def get_limit(limit_opt): |
|
281 if limit_opt: |
|
282 try: |
|
283 limit = int(limit_opt) |
|
284 except ValueError: |
|
285 raise Abort(_("limit must be a positive integer")) |
|
286 if limit <= 0: |
|
287 raise Abort(_("limit must be positive")) |
|
288 else: |
|
289 limit = sys.maxint |
|
290 return limit |
|
291 |
|
292 def get_revs(repo, rev_opt): |
|
293 if rev_opt: |
|
294 revs = revrange(repo, rev_opt) |
|
295 return (max(revs), min(revs)) |
|
296 else: |
|
297 return (len(repo) - 1, 0) |
301 |
298 |
302 def graphlog(ui, repo, path=None, **opts): |
299 def graphlog(ui, repo, path=None, **opts): |
303 """show revision history alongside an ASCII revision graph |
300 """show revision history alongside an ASCII revision graph |
304 |
301 |
305 Print a revision history alongside a revision graph drawn with |
302 Print a revision history alongside a revision graph drawn with |