author | Martin Geisler <mg@lazybytes.net> |
Sun, 31 May 2009 14:51:37 +0200 | |
changeset 8665 | e4ad46f9a004 |
parent 8228 | eee2319c5895 |
child 8667 | 594507755800 |
permissions | -rw-r--r-- |
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 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
11 |
commands. When this options is given, an ascii representation of the |
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 |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7763
diff
changeset
|
21 |
from mercurial import hg, url, util |
4344 | 22 |
|
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
23 |
def revisions(repo, start, stop): |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
24 |
"""cset DAG generator yielding (rev, node, [parents]) tuples |
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 |
This generator function walks through the revision history from revision |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
27 |
start to revision stop (which must be less than or equal to start). |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
28 |
""" |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
29 |
assert start >= stop |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
30 |
cur = start |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
31 |
while cur >= stop: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
32 |
ctx = repo[cur] |
7379
ef22cb8896d6
graphlog: fix python2.3 incompatibility (used genexp, sorted())
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7374
diff
changeset
|
33 |
parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev] |
ef22cb8896d6
graphlog: fix python2.3 incompatibility (used genexp, sorted())
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7374
diff
changeset
|
34 |
parents.sort() |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
35 |
yield (ctx, parents) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
36 |
cur -= 1 |
4344 | 37 |
|
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
38 |
def filerevs(repo, path, start, stop): |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
39 |
"""file cset DAG generator yielding (rev, node, [parents]) tuples |
7374
ccec5ae82282
graphlog: kill whitespace from earlier refactoring
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7371
diff
changeset
|
40 |
|
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
41 |
This generator function walks through the revision history of a single |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
42 |
file from revision start to revision stop (which must be less than or |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
43 |
equal to start). |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
44 |
""" |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
45 |
assert start >= stop |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6666
diff
changeset
|
46 |
filerev = len(repo.file(path)) - 1 |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
47 |
while filerev >= 0: |
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
48 |
fctx = repo.filectx(path, fileid=filerev) |
7383
b501c7f3c2ad
graphlog: fix regression with filelogs introduced by 7bc62ebe7693
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7379
diff
changeset
|
49 |
parents = [f.linkrev() for f in fctx.parents() if f.path() == path] |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
50 |
parents.sort() |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
51 |
if fctx.rev() <= start: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
52 |
yield (fctx, parents) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
53 |
if fctx.rev() <= stop: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
54 |
break |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
55 |
filerev -= 1 |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
56 |
|
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
57 |
def grapher(nodes): |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
58 |
"""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
|
59 |
|
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
60 |
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
|
61 |
- 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
|
62 |
and max length 2, |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
63 |
- 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
|
64 |
- 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
|
65 |
""" |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
66 |
seen = [] |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
67 |
for node, parents, char, lines in nodes: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
68 |
if node not in seen: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
69 |
seen.append(node) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
70 |
nodeidx = seen.index(node) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
71 |
|
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
72 |
knownparents = [] |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
73 |
newparents = [] |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
74 |
for parent in parents: |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
75 |
if parent in seen: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
76 |
knownparents.append(parent) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
77 |
else: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
78 |
newparents.append(parent) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
79 |
|
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
80 |
ncols = len(seen) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
81 |
nextseen = seen[:] |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
82 |
nextseen[nodeidx:nodeidx + 1] = newparents |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
83 |
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
|
84 |
|
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
85 |
if len(newparents) > 0: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
86 |
edges.append((nodeidx, nodeidx)) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
87 |
if len(newparents) > 1: |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
88 |
edges.append((nodeidx, nodeidx + 1)) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
89 |
nmorecols = len(nextseen) - ncols |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
90 |
seen = nextseen |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
91 |
yield (char, lines, nodeidx, edges, ncols, nmorecols) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
92 |
|
4344 | 93 |
def fix_long_right_edges(edges): |
94 |
for (i, (start, end)) in enumerate(edges): |
|
95 |
if end > start: |
|
96 |
edges[i] = (start, end + 1) |
|
97 |
||
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
98 |
def get_nodeline_edges_tail( |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
99 |
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
|
100 |
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
|
101 |
# 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
|
102 |
if n_columns_diff == -1: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
103 |
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
|
104 |
tail = ["|", " "] * (start - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
105 |
tail.extend(["/", " "] * (n_columns - start)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
106 |
return tail |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
107 |
else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
108 |
return ["\\", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
109 |
else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
110 |
return ["|", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
111 |
|
4344 | 112 |
def draw_edges(edges, nodeline, interline): |
113 |
for (start, end) in edges: |
|
114 |
if start == end + 1: |
|
115 |
interline[2 * end + 1] = "/" |
|
116 |
elif start == end - 1: |
|
117 |
interline[2 * start + 1] = "\\" |
|
118 |
elif start == end: |
|
119 |
interline[2 * start] = "|" |
|
120 |
else: |
|
121 |
nodeline[2 * end] = "+" |
|
122 |
if start > end: |
|
123 |
(start, end) = (end,start) |
|
124 |
for i in range(2 * start + 1, 2 * end): |
|
125 |
if nodeline[i] != "+": |
|
126 |
nodeline[i] = "-" |
|
127 |
||
128 |
def get_padding_line(ni, n_columns, edges): |
|
129 |
line = [] |
|
130 |
line.extend(["|", " "] * ni) |
|
131 |
if (ni, ni - 1) in edges or (ni, ni) in edges: |
|
132 |
# (ni, ni - 1) (ni, ni) |
|
133 |
# | | | | | | | | |
|
134 |
# +---o | | o---+ |
|
135 |
# | | c | | c | | |
|
136 |
# | |/ / | |/ / |
|
137 |
# | | | | | | |
|
138 |
c = "|" |
|
139 |
else: |
|
140 |
c = " " |
|
141 |
line.extend([c, " "]) |
|
142 |
line.extend(["|", " "] * (n_columns - ni - 1)) |
|
143 |
return line |
|
144 |
||
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
145 |
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
|
146 |
"""prints an ASCII graph of the DAG returned by the grapher |
4344 | 147 |
|
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
148 |
grapher is a generator that emits tuples with the following elements: |
4344 | 149 |
|
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
150 |
- 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
|
151 |
- 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
|
152 |
- 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
|
153 |
- 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
|
154 |
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
|
155 |
- 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
|
156 |
- 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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
""" |
4344 | 161 |
prev_n_columns_diff = 0 |
162 |
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
|
163 |
for (node_ch, node_lines, node_index, edges, n_columns, n_columns_diff) in grapher: |
4344 | 164 |
|
7356
eee5b7b9c5d2
graphlog: add assertion for allowed n_column_diff range
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7355
diff
changeset
|
165 |
assert -2 < n_columns_diff < 2 |
4344 | 166 |
if n_columns_diff == -1: |
167 |
# Transform |
|
168 |
# |
|
169 |
# | | | | | | |
|
170 |
# o | | into o---+ |
|
171 |
# |X / |/ / |
|
172 |
# | | | | |
|
173 |
fix_long_right_edges(edges) |
|
174 |
||
175 |
# add_padding_line says whether to rewrite |
|
176 |
# |
|
177 |
# | | | | | | | | |
|
178 |
# | o---+ into | o---+ |
|
179 |
# | / / | | | # <--- padding line |
|
180 |
# o | | | / / |
|
181 |
# o | | |
|
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
182 |
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
|
183 |
n_columns_diff == -1 and |
ff7253a0d1da
Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4583
diff
changeset
|
184 |
[x for (x, y) in edges if x + 1 < y]) |
4344 | 185 |
|
186 |
# fix_nodeline_tail says whether to rewrite |
|
187 |
# |
|
188 |
# | | o | | | | o | | |
|
189 |
# | | |/ / | | |/ / |
|
190 |
# | o | | into | o / / # <--- fixed nodeline tail |
|
191 |
# | |/ / | |/ / |
|
192 |
# o | | o | | |
|
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
193 |
fix_nodeline_tail = len(node_lines) <= 2 and not add_padding_line |
4344 | 194 |
|
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
195 |
# nodeline is the line containing the node character (typically o) |
4344 | 196 |
nodeline = ["|", " "] * node_index |
197 |
nodeline.extend([node_ch, " "]) |
|
198 |
||
199 |
nodeline.extend( |
|
200 |
get_nodeline_edges_tail( |
|
201 |
node_index, prev_node_index, n_columns, n_columns_diff, |
|
202 |
prev_n_columns_diff, fix_nodeline_tail)) |
|
203 |
||
204 |
# 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
|
205 |
# edges between this entry and the next |
4344 | 206 |
shift_interline = ["|", " "] * node_index |
207 |
if n_columns_diff == -1: |
|
208 |
n_spaces = 1 |
|
209 |
edge_ch = "/" |
|
210 |
elif n_columns_diff == 0: |
|
211 |
n_spaces = 2 |
|
212 |
edge_ch = "|" |
|
213 |
else: |
|
214 |
n_spaces = 3 |
|
215 |
edge_ch = "\\" |
|
216 |
shift_interline.extend(n_spaces * [" "]) |
|
217 |
shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1)) |
|
218 |
||
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
219 |
# draw edges from the current node to its parents |
4344 | 220 |
draw_edges(edges, nodeline, shift_interline) |
221 |
||
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
222 |
# lines is the list of all graph lines to print |
4344 | 223 |
lines = [nodeline] |
224 |
if add_padding_line: |
|
225 |
lines.append(get_padding_line(node_index, n_columns, edges)) |
|
226 |
lines.append(shift_interline) |
|
227 |
||
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
228 |
# 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
|
229 |
# log strings |
7324
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
230 |
while len(node_lines) < len(lines): |
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
231 |
node_lines.append("") |
3a2cbf68e2f1
graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7323
diff
changeset
|
232 |
if len(lines) < len(node_lines): |
4344 | 233 |
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
|
234 |
while len(lines) < len(node_lines): |
4344 | 235 |
lines.append(extra_interline) |
236 |
||
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
237 |
# print lines |
4344 | 238 |
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
|
239 |
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
|
240 |
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
|
241 |
ui.write(ln.rstrip() + '\n') |
4344 | 242 |
|
7323
1c9f7aa7c8a5
graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7280
diff
changeset
|
243 |
# ... and start over |
4344 | 244 |
prev_node_index = node_index |
245 |
prev_n_columns_diff = n_columns_diff |
|
246 |
||
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
247 |
def get_revs(repo, rev_opt): |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
248 |
if rev_opt: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
249 |
revs = revrange(repo, rev_opt) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
250 |
return (max(revs), min(revs)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
251 |
else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
252 |
return (len(repo) - 1, 0) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
253 |
|
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
"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
|
257 |
"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
|
258 |
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
|
259 |
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
|
260 |
|
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
261 |
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
|
262 |
"""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
|
263 |
|
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
264 |
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
|
265 |
ASCII characters. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
266 |
|
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
267 |
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
|
268 |
directory. |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
269 |
""" |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
270 |
|
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
271 |
check_unsupported_flags(opts) |
7715
fd3266287b40
graphlog: reuse cmdutil.loglimit() instead of redefining
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7713
diff
changeset
|
272 |
limit = cmdutil.loglimit(opts) |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
273 |
start, stop = get_revs(repo, opts["rev"]) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
274 |
stop = max(stop, start - limit + 1) |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
275 |
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
|
276 |
return |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
277 |
|
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
278 |
if path: |
7713
b8c4ba0fd7c4
graphlog: import util module rather than selected functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7435
diff
changeset
|
279 |
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
|
280 |
if path: # could be reset in canonpath |
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
281 |
revdag = 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
|
282 |
else: |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
283 |
revdag = 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
|
284 |
|
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
285 |
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
|
286 |
ascii(ui, grapher(graphdag)) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
287 |
|
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
288 |
def graphrevs(repo, nodes, opts): |
8150
bbc24c0753a0
util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents:
7875
diff
changeset
|
289 |
include = set(nodes) |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
290 |
limit = cmdutil.loglimit(opts) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
291 |
count = 0 |
8210
344751cd8cb8
replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents:
8188
diff
changeset
|
292 |
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
|
293 |
if count >= limit: |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
294 |
break |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
295 |
ctx = repo[node] |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
296 |
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
|
297 |
parents.sort() |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
298 |
yield (ctx, parents) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
299 |
count += 1 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
300 |
|
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
displayer.show(ctx) |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
|
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
310 |
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
|
311 |
"""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
|
312 |
|
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
313 |
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
|
314 |
ASCII characters. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
315 |
|
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
316 |
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
|
317 |
directory. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
318 |
""" |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
319 |
|
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
320 |
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
|
321 |
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
|
322 |
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
|
323 |
opts.get('rev')) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
324 |
if revs: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
325 |
revs = [repo.lookup(rev) for rev in revs] |
8188 | 326 |
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
|
327 |
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
|
328 |
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
|
329 |
if not o: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
330 |
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
|
331 |
return |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
332 |
|
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
333 |
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
|
334 |
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
|
335 |
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
|
336 |
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
|
337 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
338 |
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
|
339 |
"""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
|
340 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
341 |
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
|
342 |
ASCII characters. |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
343 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
344 |
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
|
345 |
directory. |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
346 |
""" |
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 |
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
|
349 |
source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev')) |
8188 | 350 |
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
|
351 |
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
|
352 |
if revs: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
if not incoming: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
356 |
try: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
357 |
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
|
358 |
except: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
359 |
pass |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
360 |
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
|
361 |
return |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
362 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
363 |
cleanup = None |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
364 |
try: |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
365 |
|
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
366 |
fname = opts["bundle"] |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
367 |
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
|
368 |
# 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
|
369 |
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
|
370 |
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
|
371 |
else: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
# keep written bundle? |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
376 |
if opts["bundle"]: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
377 |
cleanup = None |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
378 |
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
|
379 |
# 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
|
380 |
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
|
381 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
387 |
finally: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
388 |
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
|
389 |
other.close() |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
390 |
if cleanup: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
391 |
os.unlink(cleanup) |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
392 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
393 |
def uisetup(ui): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
394 |
'''Initialize the extension.''' |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
395 |
_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
|
396 |
_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
|
397 |
_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
|
398 |
|
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
399 |
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
|
400 |
'''wrap the command''' |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
401 |
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
|
402 |
if kwargs['graph']: |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
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
|
407 |
|
4344 | 408 |
cmdtable = { |
409 |
"glog": |
|
4730
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
410 |
(graphlog, |
eadfaa9ec487
Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4633
diff
changeset
|
411 |
[('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
|
412 |
('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
|
413 |
('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
|
414 |
] + templateopts, |
5942
b75105de8573
glog shows at most one file: correct synopsis
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5940
diff
changeset
|
415 |
_('hg glog [OPTION]... [FILE]')), |
4344 | 416 |
} |