Mercurial > hg
annotate tests/drawdag.py @ 34206:1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 23 Aug 2017 10:51:26 -0400 |
parents | 6c408bfa2dab |
children | 5a1b41268b7c |
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. |
33153
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
75 |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
76 Some special comments could have side effects: |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
77 |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
78 - Create obsmarkers |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
79 # replace: A -> B -> C -> D # chained 1 to 1 replacements |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
80 # split: A -> B, C # 1 to many |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
81 # prune: A, B, C # many to nothing |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
82 """ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
83 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
|
84 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
85 import collections |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
86 import itertools |
33788
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
87 import re |
30449
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 from mercurial.i18n import _ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
90 from mercurial import ( |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
91 context, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
92 error, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
93 node, |
33153
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
94 obsolete, |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32305
diff
changeset
|
95 registrar, |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
96 scmutil, |
31671
d761ef24d6e1
drawdag: use 'tagsmod.tag' instead of 'repo.tag'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30449
diff
changeset
|
97 tags as tagsmod, |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
98 ) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
99 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
100 cmdtable = {} |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32305
diff
changeset
|
101 command = registrar.command(cmdtable) |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
102 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
103 _pipechars = '\\/+-|' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
104 _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
|
105 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
|
106 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
107 def _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
108 """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
|
109 otherwise""" |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
110 return ch in _nonpipechars |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
111 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
112 def _parseasciigraph(text): |
34206
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
113 r"""str -> {str : [str]}. convert the ASCII graph to edges |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
114 |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
115 >>> import pprint |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
116 >>> pprint.pprint({k: [vv for vv in v] |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
117 ... for k, v in _parseasciigraph(br''' |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
118 ... G |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
119 ... | |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
120 ... I D C F # split: B -> E, F, G |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
121 ... \ \| | # replace: C -> D -> H |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
122 ... H B E # prune: F, I |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
123 ... \|/ |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
124 ... A |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
125 ... ''').items()}) |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
126 {'A': [], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
127 'B': ['A'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
128 'C': ['B'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
129 'D': ['B'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
130 'E': ['A'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
131 'F': ['E'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
132 'G': ['F'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
133 'H': ['A'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
134 'I': ['H']} |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
135 >>> pprint.pprint({k: [vv for vv in v] |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
136 ... for k, v in _parseasciigraph(br''' |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
137 ... o foo |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
138 ... |\ |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
139 ... +---o bar |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
140 ... | | | |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
141 ... | o | baz |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
142 ... | / |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
143 ... +---o d |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
144 ... | | |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
145 ... +---o c |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
146 ... | | |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
147 ... o | b |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
148 ... |/ |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
149 ... o a |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
150 ... ''').items()}) |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
151 {'a': [], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
152 'b': ['a'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
153 'bar': ['b', 'a'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
154 'baz': [], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
155 'c': ['b'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
156 'd': ['b'], |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
157 'foo': ['baz', 'b']} |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
158 """ |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
159 lines = text.splitlines() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
160 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
|
161 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
162 def get(y, x): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
163 """(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
|
164 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
|
165 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
|
166 return ' ' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
167 try: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
168 return lines[y][x] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
169 except IndexError: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
170 return ' ' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
171 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
172 def getname(y, x): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
173 """(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
|
174 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
|
175 result = '' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
176 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
|
177 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
|
178 if not _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
179 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
180 result = ch + result |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
181 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
|
182 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
|
183 if not _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
184 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
185 result += ch |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
186 if result == 'o': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
187 # 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
|
188 result = '' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 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
|
193 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
194 else: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
195 result += ch |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
196 return result or '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 def parents(y, x): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
200 """(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
|
201 return a list of parents""" |
32291
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
31671
diff
changeset
|
202 visited = {(y, x)} |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
203 visit = [] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
204 result = [] |
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 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
|
207 """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
|
208 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
|
209 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
|
210 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
|
211 ch = get(y, x) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
212 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
|
213 y += 1 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
214 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
|
215 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
|
216 visit.append((y, x)) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
217 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
218 # -o- # starting point: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
219 # /|\ # 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
|
220 follow(y + 1, x, '|') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
221 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
|
222 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
|
223 follow(y, x - 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
224 follow(y, x + 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
225 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
226 while visit: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
227 y, x = visit.pop() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
228 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
|
229 continue |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
230 visited.add((y, x)) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
231 ch = get(y, x) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
232 if _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
233 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
|
234 continue |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
235 elif ch == '|': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 elif ch == '+': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
240 follow(y, x - 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
241 follow(y, x + 1, '-') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
242 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
|
243 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
|
244 follow(y + 1, x, '|') |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
245 elif ch == '\\': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
246 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
|
247 elif ch == '/': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
248 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
|
249 elif ch == '-': |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
250 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
|
251 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
|
252 return result |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
253 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
254 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
|
255 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
|
256 if ch == '#': # comment |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
257 break |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
258 if _isname(ch): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
259 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
|
260 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
261 return dict(edges) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
262 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
263 class simplefilectx(object): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
264 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
|
265 self._data = data |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
266 self._path = path |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
267 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
268 def data(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
269 return self._data |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
270 |
32305
911057981ba4
drawdag: provide filenode for its dummy filectx
Jun Wu <quark@fb.com>
parents:
32291
diff
changeset
|
271 def filenode(self): |
911057981ba4
drawdag: provide filenode for its dummy filectx
Jun Wu <quark@fb.com>
parents:
32291
diff
changeset
|
272 return None |
911057981ba4
drawdag: provide filenode for its dummy filectx
Jun Wu <quark@fb.com>
parents:
32291
diff
changeset
|
273 |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
274 def path(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
275 return self._path |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
276 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
277 def renamed(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
278 return None |
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 def flags(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
281 return '' |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
282 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
283 class simplecommitctx(context.committablectx): |
33558
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
284 def __init__(self, repo, name, parentctxs, added): |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
285 opts = { |
33558
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
286 'changes': scmutil.status([], list(added), [], [], [], [], []), |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
287 'date': '0 0', |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
288 'extra': {'branch': 'default'}, |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
289 } |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
290 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
|
291 self._repo = repo |
33558
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
292 self._added = added |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
293 self._parents = parentctxs |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
294 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
|
295 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
|
296 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
297 def filectx(self, key): |
33558
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
298 return simplefilectx(key, self._added[key]) |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
299 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
300 def commit(self): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
301 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
|
302 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
303 def _walkgraph(edges): |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
304 """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
|
305 visible = set(edges.keys()) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
306 remaining = {} # {str: [str]} |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
307 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
|
308 for v in vs: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
309 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
|
310 remaining[v] = [] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
311 remaining[k] = vs[:] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
312 while remaining: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
313 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
|
314 if not leafs: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
315 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
|
316 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
|
317 if leaf in visible: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
318 yield leaf, edges[leaf] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
319 del remaining[leaf] |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
320 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
|
321 if leaf in v: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
322 v.remove(leaf) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
323 |
33788
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
324 def _getcomments(text): |
34206
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
325 """ |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
326 >>> [s for s in _getcomments(br''' |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
327 ... G |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
328 ... | |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
329 ... I D C F # split: B -> E, F, G |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
330 ... \ \| | # replace: C -> D -> H |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
331 ... H B E # prune: F, I |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
332 ... \|/ |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
333 ... A |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
334 ... ''')] |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
335 ['split: B -> E, F, G', 'replace: C -> D -> H', 'prune: F, I'] |
1e71dddc10a2
drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents:
34205
diff
changeset
|
336 """ |
33788
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
337 for line in text.splitlines(): |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
338 if ' # ' not in line: |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
339 continue |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
340 yield line.split(' # ', 1)[1].split(' # ')[0].strip() |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
341 |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
342 @command('debugdrawdag', []) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
343 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
|
344 """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
|
345 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 to. |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
350 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
351 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
|
352 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
|
353 :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
|
354 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 """ |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
359 text = ui.fin.read() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
360 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
361 # 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
|
362 edges = _parseasciigraph(text) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
363 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
|
364 if len(v) > 2: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
365 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
|
366 % (k, ' '.join(v))) |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
367 |
33788
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
368 # parse comments to get extra file content instructions |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
369 files = collections.defaultdict(dict) # {(name, path): content} |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
370 comments = list(_getcomments(text)) |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
371 filere = re.compile(r'^(\w+)/([\w/]+)\s*=\s*(.*)$', re.M) |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
372 for name, path, content in filere.findall('\n'.join(comments)): |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
373 files[name][path] = content.replace(r'\n', '\n') |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
374 |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
375 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
|
376 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
377 # 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
|
378 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
|
379 if len(parents) == 0: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
380 try: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
381 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
|
382 except error.RepoLookupError: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
383 pass |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
384 |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
385 # commit in topological order |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
386 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
|
387 if name in committed: |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
388 continue |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
389 pctxs = [repo[committed[n]] for n in parents] |
33558
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
390 pctxs.sort(key=lambda c: c.node()) |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
391 added = {} |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
392 if len(parents) > 1: |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
393 # If it's a merge, take the files and contents from the parents |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
394 for f in pctxs[1].manifest(): |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
395 if f not in pctxs[0].manifest(): |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
396 added[f] = pctxs[1][f].data() |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
397 else: |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
398 # If it's not a merge, add a single file |
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
399 added[name] = name |
33788
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
400 # add extra file contents in comments |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
401 for path, content in files.get(name, {}).items(): |
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
402 added[path] = content |
33558
0103e7187237
drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents:
33172
diff
changeset
|
403 ctx = simplecommitctx(repo, name, pctxs, added) |
30449
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
404 n = ctx.commit() |
a31634336471
drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff
changeset
|
405 committed[name] = n |
34205
6c408bfa2dab
drawdag: tagsmod.tag() takes a list of names, not a single name
Augie Fackler <raf@durin42.com>
parents:
33788
diff
changeset
|
406 tagsmod.tag(repo, [name], n, message=None, user=None, date=None, |
31671
d761ef24d6e1
drawdag: use 'tagsmod.tag' instead of 'repo.tag'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30449
diff
changeset
|
407 local=True) |
33153
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
408 |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
409 # handle special comments |
33172
0830c841fc7f
drawdag: inline transaction() function
Martin von Zweigbergk <martinvonz@google.com>
parents:
33153
diff
changeset
|
410 with repo.wlock(), repo.lock(), repo.transaction('drawdag'): |
33153
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
411 getctx = lambda x: repo.unfiltered()[committed[x.strip()]] |
33788
0531ffd59a98
drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents:
33558
diff
changeset
|
412 for comment in comments: |
33153
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
413 rels = [] # obsolete relationships |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
414 args = comment.split(':', 1) |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
415 if len(args) <= 1: |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
416 continue |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
417 |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
418 cmd = args[0].strip() |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
419 arg = args[1].strip() |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
420 |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
421 if cmd in ('replace', 'rebase', 'amend'): |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
422 nodes = [getctx(m) for m in arg.split('->')] |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
423 for i in range(len(nodes) - 1): |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
424 rels.append((nodes[i], (nodes[i + 1],))) |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
425 elif cmd in ('split',): |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
426 pre, succs = arg.split('->') |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
427 succs = succs.split(',') |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
428 rels.append((getctx(pre), (getctx(s) for s in succs))) |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
429 elif cmd in ('prune',): |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
430 for n in arg.split(','): |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
431 rels.append((getctx(n), ())) |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
432 if rels: |
4d780d510b44
drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents:
32337
diff
changeset
|
433 obsolete.createmarkers(repo, rels, date=(0, 0), operation=cmd) |