Mercurial > hg
annotate tests/drawdag.py @ 31454:a5bad127128d
branchmap: handle nullrev in setcachedata
906be86990 recently changed to switch from:
self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec
to
pack_into(_rbcrecfmt, self._rbcrevs, rbcrevidx, node, branchidx)
This causes an exception if rbcrevidx is -1 (i.e. the nullrev). The old code
handled this because python handles out of bound sets to arrays gracefully. The
new code throws because the self._rbcrevs buffer isn't long enough to write 8
bytes to. Normally it would've been resized by the immediately preceding line,
but because the 0 length buffer is greater than the idx (-1) times the size, no
resize happens.
Setting the branch for the nullrev doesn't make sense anyway, so let's skip it.
This was caught by external tests in the Facebook extensions repo, but I've
added a test here that catches the issue.
author | Durham Goode <durham@fb.com> |
---|---|
date | Wed, 15 Mar 2017 15:48:57 -0700 |
parents | a31634336471 |
children | d761ef24d6e1 |
rev | line source |
---|---|
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
1 # drawdag.py - convert ASCII revision DAG to actual changesets |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
2 # |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
3 # Copyright 2016 Facebook, Inc. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
4 # |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
7 """ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
8 create changesets from an ASCII graph for testing purpose. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
9 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
10 For example, given the following input:: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
11 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
12 c d |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
13 |/ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
14 b |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
15 | |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
16 a |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
17 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
18 4 changesets and 4 local tags will be created. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
19 `hg log -G -T "{rev} {desc} (tag: {tags})"` will output:: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
20 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
21 o 3 d (tag: d tip) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
22 | |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
23 | o 2 c (tag: c) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
24 |/ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
25 o 1 b (tag: b) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
26 | |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
27 o 0 a (tag: a) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
28 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
29 For root nodes (nodes without parents) in the graph, they can be revsets |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
30 pointing to existing nodes. The ASCII graph could also have disconnected |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
31 components with same names referring to the same changeset. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
32 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
33 Therefore, given the repo having the 4 changesets (and tags) above, with the |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
34 following ASCII graph as input:: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
35 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
36 foo bar bar foo |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
37 | / | | |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
38 ancestor(c,d) a baz |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
39 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
40 The result (`hg log -G -T "{desc}"`) will look like:: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
41 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
42 o foo |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
43 |\ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
44 +---o bar |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
45 | | | |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
46 | o | baz |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
47 | / |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
48 +---o d |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
49 | | |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
50 +---o c |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
51 | | |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
52 o | b |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
53 |/ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
54 o a |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
55 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
56 Note that if you take the above `hg log` output directly as input. It will work |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
57 as expected - the result would be an isomorphic graph:: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
58 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
59 o foo |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
60 |\ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
61 | | o d |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
62 | |/ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
63 | | o c |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
64 | |/ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
65 | | o bar |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
66 | |/| |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
67 | o | b |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
68 | |/ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
69 o / baz |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
70 / |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
71 o a |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
72 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
73 This is because 'o' is specially handled in the input: instead of using 'o' as |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
74 the node name, the word to the right will be used. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
75 """ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
76 from __future__ import absolute_import, print_function |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
77 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
78 import collections |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
79 import itertools |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
80 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
81 from mercurial.i18n import _ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
82 from mercurial import ( |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
83 cmdutil, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
84 context, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
85 error, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
86 node, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
87 scmutil, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
88 ) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
89 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
90 cmdtable = {} |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
91 command = cmdutil.command(cmdtable) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
92 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
93 _pipechars = '\\/+-|' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
94 _nonpipechars = ''.join(chr(i) for i in xrange(33, 127) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
95 if chr(i) not in _pipechars) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
96 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
97 def _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
98 """char -> bool. return True if ch looks like part of a name, False |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
99 otherwise""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
100 return ch in _nonpipechars |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
101 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
102 def _parseasciigraph(text): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
103 """str -> {str : [str]}. convert the ASCII graph to edges""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
104 lines = text.splitlines() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
105 edges = collections.defaultdict(list) # {node: []} |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
106 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
107 def get(y, x): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
108 """(int, int) -> char. give a coordinate, return the char. return a |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
109 space for anything out of range""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
110 if x < 0 or y < 0: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
111 return ' ' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
112 try: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
113 return lines[y][x] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
114 except IndexError: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
115 return ' ' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
116 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
117 def getname(y, x): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
118 """(int, int) -> str. like get(y, x) but concatenate left and right |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
119 parts. if name is an 'o', try to replace it to the right""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
120 result = '' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
121 for i in itertools.count(0): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
122 ch = get(y, x - i) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
123 if not _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
124 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
125 result = ch + result |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
126 for i in itertools.count(1): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
127 ch = get(y, x + i) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
128 if not _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
129 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
130 result += ch |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
131 if result == 'o': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
132 # special handling, find the name to the right |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
133 result = '' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
134 for i in itertools.count(2): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
135 ch = get(y, x + i) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
136 if ch == ' ' or ch in _pipechars: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
137 if result or x + i >= len(lines[y]): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
138 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
139 else: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
140 result += ch |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
141 return result or 'o' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
142 return result |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
143 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
144 def parents(y, x): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
145 """(int, int) -> [str]. follow the ASCII edges at given position, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
146 return a list of parents""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
147 visited = set([(y, x)]) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
148 visit = [] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
149 result = [] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
150 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
151 def follow(y, x, expected): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
152 """conditionally append (y, x) to visit array, if it's a char |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
153 in excepted. 'o' in expected means an '_isname' test. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
154 if '-' (or '+') is not in excepted, and get(y, x) is '-' (or '+'), |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
155 the next line (y + 1, x) will be checked instead.""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
156 ch = get(y, x) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
157 if any(ch == c and c not in expected for c in '-+'): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
158 y += 1 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
159 return follow(y + 1, x, expected) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
160 if ch in expected or ('o' in expected and _isname(ch)): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
161 visit.append((y, x)) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
162 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
163 # -o- # starting point: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
164 # /|\ # follow '-' (horizontally), and '/|\' (to the bottom) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
165 follow(y + 1, x, '|') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
166 follow(y + 1, x - 1, '/') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
167 follow(y + 1, x + 1, '\\') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
168 follow(y, x - 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
169 follow(y, x + 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
170 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
171 while visit: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
172 y, x = visit.pop() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
173 if (y, x) in visited: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
174 continue |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
175 visited.add((y, x)) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
176 ch = get(y, x) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
177 if _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
178 result.append(getname(y, x)) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
179 continue |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
180 elif ch == '|': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
181 follow(y + 1, x, '/|o') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
182 follow(y + 1, x - 1, '/') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
183 follow(y + 1, x + 1, '\\') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
184 elif ch == '+': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
185 follow(y, x - 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
186 follow(y, x + 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
187 follow(y + 1, x - 1, '/') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
188 follow(y + 1, x + 1, '\\') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
189 follow(y + 1, x, '|') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
190 elif ch == '\\': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
191 follow(y + 1, x + 1, '\\|o') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
192 elif ch == '/': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
193 follow(y + 1, x - 1, '/|o') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
194 elif ch == '-': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
195 follow(y, x - 1, '-+o') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
196 follow(y, x + 1, '-+o') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
197 return result |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
198 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
199 for y, line in enumerate(lines): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
200 for x, ch in enumerate(line): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
201 if ch == '#': # comment |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
202 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
203 if _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
204 edges[getname(y, x)] += parents(y, x) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
205 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
206 return dict(edges) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
207 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
208 class simplefilectx(object): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
209 def __init__(self, path, data): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
210 self._data = data |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
211 self._path = path |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
212 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
213 def data(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
214 return self._data |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
215 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
216 def path(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
217 return self._path |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
218 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
219 def renamed(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
220 return None |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
221 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
222 def flags(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
223 return '' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
224 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
225 class simplecommitctx(context.committablectx): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
226 def __init__(self, repo, name, parentctxs, added=None): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
227 opts = { |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
228 'changes': scmutil.status([], added or [], [], [], [], [], []), |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
229 'date': '0 0', |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
230 'extra': {'branch': 'default'}, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
231 } |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
232 super(simplecommitctx, self).__init__(self, name, **opts) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
233 self._repo = repo |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
234 self._name = name |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
235 self._parents = parentctxs |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
236 self._parents.sort(key=lambda c: c.node()) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
237 while len(self._parents) < 2: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
238 self._parents.append(repo[node.nullid]) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
239 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
240 def filectx(self, key): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
241 return simplefilectx(key, self._name) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
242 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
243 def commit(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
244 return self._repo.commitctx(self) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
245 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
246 def _walkgraph(edges): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
247 """yield node, parents in topologically order""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
248 visible = set(edges.keys()) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
249 remaining = {} # {str: [str]} |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
250 for k, vs in edges.iteritems(): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
251 for v in vs: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
252 if v not in remaining: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
253 remaining[v] = [] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
254 remaining[k] = vs[:] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
255 while remaining: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
256 leafs = [k for k, v in remaining.items() if not v] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
257 if not leafs: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
258 raise error.Abort(_('the graph has cycles')) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
259 for leaf in sorted(leafs): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
260 if leaf in visible: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
261 yield leaf, edges[leaf] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
262 del remaining[leaf] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
263 for k, v in remaining.iteritems(): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
264 if leaf in v: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
265 v.remove(leaf) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
266 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
267 @command('debugdrawdag', []) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
268 def debugdrawdag(ui, repo, **opts): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
269 """read an ASCII graph from stdin and create changesets |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
270 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
271 The ASCII graph is like what :hg:`log -G` outputs, with each `o` replaced |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
272 to the name of the node. The command will create dummy changesets and local |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
273 tags with those names to make the dummy changesets easier to be referred |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
274 to. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
275 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
276 If the name of a node is a single character 'o', It will be replaced by the |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
277 word to the right. This makes it easier to reuse |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
278 :hg:`log -G -T '{desc}'` outputs. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
279 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
280 For root (no parents) nodes, revset can be used to query existing repo. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
281 Note that the revset cannot have confusing characters which can be seen as |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
282 the part of the graph edges, like `|/+-\`. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
283 """ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
284 text = ui.fin.read() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
285 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
286 # parse the graph and make sure len(parents) <= 2 for each node |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
287 edges = _parseasciigraph(text) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
288 for k, v in edges.iteritems(): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
289 if len(v) > 2: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
290 raise error.Abort(_('%s: too many parents: %s') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
291 % (k, ' '.join(v))) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
292 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
293 committed = {None: node.nullid} # {name: node} |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
294 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
295 # for leaf nodes, try to find existing nodes in repo |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
296 for name, parents in edges.iteritems(): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
297 if len(parents) == 0: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
298 try: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
299 committed[name] = scmutil.revsingle(repo, name) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
300 except error.RepoLookupError: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
301 pass |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
302 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
303 # commit in topological order |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
304 for name, parents in _walkgraph(edges): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
305 if name in committed: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
306 continue |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
307 pctxs = [repo[committed[n]] for n in parents] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
308 ctx = simplecommitctx(repo, name, pctxs, [name]) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
309 n = ctx.commit() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
310 committed[name] = n |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
311 repo.tag(name, n, message=None, user=None, date=None, local=True) |