Mercurial > hg
annotate mercurial/graphmod.py @ 23420:902554884335 stable 3.2.2
merge: before cd/dc prompt, check that changed side really changed
Before, merging would in some cases ask "wrong" questions about
"changed/deleted" conflicts ... and even do it before the resolve phase where
they can be postponed, re"resolved" or answered in bulk operations.
Instead, check that the content of the changed file really did change.
Reading and comparing file content is expensive and should be avoided before
the resolve phase. Prompting the user is however even more expensive. Checking
the content here is thus better.
The 'f in ancestors[0]' should not be necessary but is included to be extra
safe.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 01 Dec 2014 02:30:21 +0100 |
parents | bb1bd9ee323d |
children | f7ce0837eefd |
rev | line source |
---|---|
6691 | 1 # Revision graph generator for Mercurial |
2 # | |
3 # Copyright 2008 Dirkjan Ochtman <dirkjan@ochtman.nl> | |
4 # Copyright 2007 Joel Rosdahl <joel@rosdahl.net> | |
5 # | |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7873
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # GNU General Public License version 2 or any later version. |
6691 | 8 |
8840
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
9 """supports walking the history as DAGs suitable for graphical output |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
10 |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
11 The most basic format we use is that of:: |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
12 |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
13 (id, type, data, [parentids]) |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
14 |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
15 The node and parent ids are arbitrary integers which identify a node in the |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
16 context of the graph returned. Type is a constant specifying the node type. |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
17 Data depends on type. |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
18 """ |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
19 |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
20 from mercurial.node import nullrev |
16132
41fc1e078d68
graphmod: add config cache
Matt Mackall <mpm@selenic.com>
parents:
16131
diff
changeset
|
21 import util |
8840
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
22 |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
23 CHANGESET = 'C' |
6691 | 24 |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
25 def dagwalker(repo, revs): |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
26 """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
27 |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
28 This generator function walks through revisions (which should be ordered |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
29 from bigger to lower). It returns a tuple for each node. The node and parent |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
30 ids are arbitrary integers which identify a node in the context of the graph |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
31 returned. |
8836
11ff34956ee7
graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8835
diff
changeset
|
32 """ |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
33 if not revs: |
14087
f3d585c9b042
graphmod: restore generator nature of dagwalker
Idan Kamara <idankk86@gmail.com>
parents:
14064
diff
changeset
|
34 return |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
35 |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
36 cl = repo.changelog |
20762
e87bd3485a07
graphmod: changed code in dagwalker to use lazy implementations
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
18467
diff
changeset
|
37 lowestrev = revs.min() |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
38 gpcache = {} |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
39 |
14087
f3d585c9b042
graphmod: restore generator nature of dagwalker
Idan Kamara <idankk86@gmail.com>
parents:
14064
diff
changeset
|
40 for rev in revs: |
f3d585c9b042
graphmod: restore generator nature of dagwalker
Idan Kamara <idankk86@gmail.com>
parents:
14064
diff
changeset
|
41 ctx = repo[rev] |
14088
e83ced8b6464
graphlog: use a set for inclusion test
Patrick Mezard <pmezard@gmail.com>
parents:
14087
diff
changeset
|
42 parents = sorted(set([p.rev() for p in ctx.parents() |
23006
bb1bd9ee323d
dagwalker: drop a useless intermediate variable
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22878
diff
changeset
|
43 if p.rev() in revs])) |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
44 mpars = [p.rev() for p in ctx.parents() if |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
45 p.rev() != nullrev and p.rev() not in parents] |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
46 |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
47 for mpar in mpars: |
14131
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
48 gp = gpcache.get(mpar) |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
49 if gp is None: |
14131
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
50 gp = gpcache[mpar] = grandparent(cl, lowestrev, revs, mpar) |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
51 if not gp: |
14087
f3d585c9b042
graphmod: restore generator nature of dagwalker
Idan Kamara <idankk86@gmail.com>
parents:
14064
diff
changeset
|
52 parents.append(mpar) |
14131
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
53 else: |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
54 parents.extend(g for g in gp if g not in parents) |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
55 |
14087
f3d585c9b042
graphmod: restore generator nature of dagwalker
Idan Kamara <idankk86@gmail.com>
parents:
14064
diff
changeset
|
56 yield (ctx.rev(), CHANGESET, ctx, parents) |
8836
11ff34956ee7
graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8835
diff
changeset
|
57 |
8837
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
58 def nodes(repo, nodes): |
8840
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
59 """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
60 |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
61 This generator function walks the given nodes. It only returns parents |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
62 that are in nodes, too. |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
63 """ |
8837
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
64 include = set(nodes) |
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
65 for node in nodes: |
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
66 ctx = repo[node] |
12951
101366ad816c
graphmod: safer code when a changeset has two identical parents
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10602
diff
changeset
|
67 parents = set([p.rev() for p in ctx.parents() if p.node() in include]) |
8840
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8837
diff
changeset
|
68 yield (ctx.rev(), CHANGESET, ctx, sorted(parents)) |
8837
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
69 |
16129
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
70 def colored(dag, repo): |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
71 """annotates a DAG with colored edge information |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
72 |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
73 For each DAG node this function emits tuples:: |
6691 | 74 |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
75 (id, type, data, (col, color), [(col, nextcol, color)]) |
6691 | 76 |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
77 with the following new elements: |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
78 |
8835
ec5483efc31f
graphmod: code cleanup and doc fix
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8225
diff
changeset
|
79 - Tuple (col, color) with column and color index for the current node |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
80 - A list of tuples indicating the edges between the current node and its |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
81 parents. |
6691 | 82 """ |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
83 seen = [] |
6691 | 84 colors = {} |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
85 newcolor = 1 |
16129
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
86 config = {} |
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
87 |
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
88 for key, val in repo.ui.configitems('graph'): |
16131
6f236c8bdc01
graphmod: rewrite graph config validation
Matt Mackall <mpm@selenic.com>
parents:
16130
diff
changeset
|
89 if '.' in key: |
6f236c8bdc01
graphmod: rewrite graph config validation
Matt Mackall <mpm@selenic.com>
parents:
16130
diff
changeset
|
90 branch, setting = key.rsplit('.', 1) |
6f236c8bdc01
graphmod: rewrite graph config validation
Matt Mackall <mpm@selenic.com>
parents:
16130
diff
changeset
|
91 # Validation |
6f236c8bdc01
graphmod: rewrite graph config validation
Matt Mackall <mpm@selenic.com>
parents:
16130
diff
changeset
|
92 if setting == "width" and val.isdigit(): |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
93 config.setdefault(branch, {})[setting] = int(val) |
16131
6f236c8bdc01
graphmod: rewrite graph config validation
Matt Mackall <mpm@selenic.com>
parents:
16130
diff
changeset
|
94 elif setting == "color" and val.isalnum(): |
6f236c8bdc01
graphmod: rewrite graph config validation
Matt Mackall <mpm@selenic.com>
parents:
16130
diff
changeset
|
95 config.setdefault(branch, {})[setting] = val |
16129
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
96 |
16132
41fc1e078d68
graphmod: add config cache
Matt Mackall <mpm@selenic.com>
parents:
16131
diff
changeset
|
97 if config: |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
98 getconf = util.lrucachefunc( |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
99 lambda rev: config.get(repo[rev].branch(), {})) |
16132
41fc1e078d68
graphmod: add config cache
Matt Mackall <mpm@selenic.com>
parents:
16131
diff
changeset
|
100 else: |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
101 getconf = lambda rev: {} |
16129
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
102 |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
103 for (cur, type, data, parents) in dag: |
6691 | 104 |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
105 # Compute seen and next |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
106 if cur not in seen: |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
107 seen.append(cur) # new head |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
108 colors[cur] = newcolor |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
109 newcolor += 1 |
6691 | 110 |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
111 col = seen.index(cur) |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
112 color = colors.pop(cur) |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
113 next = seen[:] |
6691 | 114 |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
115 # Add parents to next |
6691 | 116 addparents = [p for p in parents if p not in next] |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
117 next[col:col + 1] = addparents |
6691 | 118 |
119 # Set colors for the parents | |
120 for i, p in enumerate(addparents): | |
121 if not i: | |
122 colors[p] = color | |
123 else: | |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
124 colors[p] = newcolor |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
125 newcolor += 1 |
6691 | 126 |
127 # Add edges to the graph | |
128 edges = [] | |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
129 for ecol, eid in enumerate(seen): |
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
130 if eid in next: |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
131 bconf = getconf(eid) |
16129
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
132 edges.append(( |
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
133 ecol, next.index(eid), colors[eid], |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
134 bconf.get('width', -1), |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
135 bconf.get('color', ''))) |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
136 elif eid == cur: |
6691 | 137 for p in parents: |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
138 bconf = getconf(p) |
16129
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
139 edges.append(( |
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
14131
diff
changeset
|
140 ecol, next.index(p), color, |
16138
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
141 bconf.get('width', -1), |
6e4de55a41a4
hgweb: refactor graph customization javascript
Patrick Mezard <patrick@mezard.eu>
parents:
16132
diff
changeset
|
142 bconf.get('color', ''))) |
6691 | 143 |
144 # Yield and move on | |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8841
diff
changeset
|
145 yield (cur, type, data, (col, color), edges) |
8841
94ac080e7af9
graphmod: rename a bunch of vars in graph()
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8840
diff
changeset
|
146 seen = next |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
147 |
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
148 def grandparent(cl, lowestrev, roots, head): |
14131
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
149 """Return all ancestors of head in roots which revision is |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
150 greater or equal to lowestrev. |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
151 """ |
14131
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
152 pending = set([head]) |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
153 seen = set() |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
154 kept = set() |
14042
9966c95b8c4f
graphmod: use revsets internally
Alexander Solovyov <alexander@solovyov.net>
parents:
12951
diff
changeset
|
155 llowestrev = max(nullrev, lowestrev) |
14131
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
156 while pending: |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
157 r = pending.pop() |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
158 if r >= llowestrev and r not in seen: |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
159 if r in roots: |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
160 kept.add(r) |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
161 else: |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
162 pending.update([p for p in cl.parentrevs(r)]) |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
163 seen.add(r) |
03e1c2d35c6a
graphmod: correctly emit nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14088
diff
changeset
|
164 return sorted(kept) |
17179
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
165 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
166 def asciiedges(type, char, lines, seen, rev, parents): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
167 """adds edge info to changelog DAG walk suitable for ascii()""" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
168 if rev not in seen: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
169 seen.append(rev) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
170 nodeidx = seen.index(rev) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
171 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
172 knownparents = [] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
173 newparents = [] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
174 for parent in parents: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
175 if parent in seen: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
176 knownparents.append(parent) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
177 else: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
178 newparents.append(parent) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
179 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
180 ncols = len(seen) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
181 nextseen = seen[:] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
182 nextseen[nodeidx:nodeidx + 1] = newparents |
18467
e441657b372b
graphmod: don't try to visit nullrev (issue3772)
Bryan O'Sullivan <bryano@fb.com>
parents:
17179
diff
changeset
|
183 edges = [(nodeidx, nextseen.index(p)) for p in knownparents if p != nullrev] |
17179
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
184 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
185 while len(newparents) > 2: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
186 # ascii() only knows how to add or remove a single column between two |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
187 # calls. Nodes with more than two parents break this constraint so we |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
188 # introduce intermediate expansion lines to grow the active node list |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
189 # slowly. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
190 edges.append((nodeidx, nodeidx)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
191 edges.append((nodeidx, nodeidx + 1)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
192 nmorecols = 1 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
193 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
194 char = '\\' |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
195 lines = [] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
196 nodeidx += 1 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
197 ncols += 1 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
198 edges = [] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
199 del newparents[0] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
200 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
201 if len(newparents) > 0: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
202 edges.append((nodeidx, nodeidx)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
203 if len(newparents) > 1: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
204 edges.append((nodeidx, nodeidx + 1)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
205 nmorecols = len(nextseen) - ncols |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
206 seen[:] = nextseen |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
207 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
208 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
209 def _fixlongrightedges(edges): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
210 for (i, (start, end)) in enumerate(edges): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
211 if end > start: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
212 edges[i] = (start, end + 1) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
213 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
214 def _getnodelineedgestail( |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
215 node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
216 if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
217 # Still going in the same non-vertical direction. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
218 if n_columns_diff == -1: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
219 start = max(node_index + 1, p_node_index) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
220 tail = ["|", " "] * (start - node_index - 1) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
221 tail.extend(["/", " "] * (n_columns - start)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
222 return tail |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
223 else: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
224 return ["\\", " "] * (n_columns - node_index - 1) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
225 else: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
226 return ["|", " "] * (n_columns - node_index - 1) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
227 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
228 def _drawedges(edges, nodeline, interline): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
229 for (start, end) in edges: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
230 if start == end + 1: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
231 interline[2 * end + 1] = "/" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
232 elif start == end - 1: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
233 interline[2 * start + 1] = "\\" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
234 elif start == end: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
235 interline[2 * start] = "|" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
236 else: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
237 if 2 * end >= len(nodeline): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
238 continue |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
239 nodeline[2 * end] = "+" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
240 if start > end: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
241 (start, end) = (end, start) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
242 for i in range(2 * start + 1, 2 * end): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
243 if nodeline[i] != "+": |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
244 nodeline[i] = "-" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
245 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
246 def _getpaddingline(ni, n_columns, edges): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
247 line = [] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
248 line.extend(["|", " "] * ni) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
249 if (ni, ni - 1) in edges or (ni, ni) in edges: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
250 # (ni, ni - 1) (ni, ni) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
251 # | | | | | | | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
252 # +---o | | o---+ |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
253 # | | c | | c | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
254 # | |/ / | |/ / |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
255 # | | | | | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
256 c = "|" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
257 else: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
258 c = " " |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
259 line.extend([c, " "]) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
260 line.extend(["|", " "] * (n_columns - ni - 1)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
261 return line |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
262 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
263 def asciistate(): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
264 """returns the initial value for the "state" argument to ascii()""" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
265 return [0, 0] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
266 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
267 def ascii(ui, state, type, char, text, coldata): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
268 """prints an ASCII graph of the DAG |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
269 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
270 takes the following arguments (one call per node in the graph): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
271 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
272 - ui to write to |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
273 - Somewhere to keep the needed state in (init to asciistate()) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
274 - Column of the current node in the set of ongoing edges. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
275 - Type indicator of node data, usually 'C' for changesets. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
276 - Payload: (char, lines): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
277 - Character to use as node's symbol. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
278 - List of lines to display as the node's text. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
279 - Edges; a list of (col, next_col) indicating the edges between |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
280 the current node and its parents. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
281 - Number of columns (ongoing edges) in the current revision. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
282 - The difference between the number of columns (ongoing edges) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
283 in the next revision and the number of columns (ongoing edges) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
284 in the current revision. That is: -1 means one column removed; |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
285 0 means no columns added or removed; 1 means one column added. |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
286 """ |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
287 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
288 idx, edges, ncols, coldiff = coldata |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
289 assert -2 < coldiff < 2 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
290 if coldiff == -1: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
291 # Transform |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
292 # |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
293 # | | | | | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
294 # o | | into o---+ |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
295 # |X / |/ / |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
296 # | | | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
297 _fixlongrightedges(edges) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
298 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
299 # add_padding_line says whether to rewrite |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
300 # |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
301 # | | | | | | | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
302 # | o---+ into | o---+ |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
303 # | / / | | | # <--- padding line |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
304 # o | | | / / |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
305 # o | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
306 add_padding_line = (len(text) > 2 and coldiff == -1 and |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
307 [x for (x, y) in edges if x + 1 < y]) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
308 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
309 # fix_nodeline_tail says whether to rewrite |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
310 # |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
311 # | | o | | | | o | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
312 # | | |/ / | | |/ / |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
313 # | o | | into | o / / # <--- fixed nodeline tail |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
314 # | |/ / | |/ / |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
315 # o | | o | | |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
316 fix_nodeline_tail = len(text) <= 2 and not add_padding_line |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
317 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
318 # nodeline is the line containing the node character (typically o) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
319 nodeline = ["|", " "] * idx |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
320 nodeline.extend([char, " "]) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
321 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
322 nodeline.extend( |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
323 _getnodelineedgestail(idx, state[1], ncols, coldiff, |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
324 state[0], fix_nodeline_tail)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
325 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
326 # shift_interline is the line containing the non-vertical |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
327 # edges between this entry and the next |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
328 shift_interline = ["|", " "] * idx |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
329 if coldiff == -1: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
330 n_spaces = 1 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
331 edge_ch = "/" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
332 elif coldiff == 0: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
333 n_spaces = 2 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
334 edge_ch = "|" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
335 else: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
336 n_spaces = 3 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
337 edge_ch = "\\" |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
338 shift_interline.extend(n_spaces * [" "]) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
339 shift_interline.extend([edge_ch, " "] * (ncols - idx - 1)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
340 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
341 # draw edges from the current node to its parents |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
342 _drawedges(edges, nodeline, shift_interline) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
343 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
344 # lines is the list of all graph lines to print |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
345 lines = [nodeline] |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
346 if add_padding_line: |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
347 lines.append(_getpaddingline(idx, ncols, edges)) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
348 lines.append(shift_interline) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
349 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
350 # make sure that there are as many graph lines as there are |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
351 # log strings |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
352 while len(text) < len(lines): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
353 text.append("") |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
354 if len(lines) < len(text): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
355 extra_interline = ["|", " "] * (ncols + coldiff) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
356 while len(lines) < len(text): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
357 lines.append(extra_interline) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
358 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
359 # print lines |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
360 indentation_level = max(ncols, ncols + coldiff) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
361 for (line, logstr) in zip(lines, text): |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
362 ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
363 ui.write(ln.rstrip() + '\n') |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
364 |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
365 # ... and start over |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
366 state[0] = coldiff |
0849d725e2f9
graphlog: extract ascii drawing code into graphmod
Patrick Mezard <patrick@mezard.eu>
parents:
16138
diff
changeset
|
367 state[1] = idx |