annotate tests/drawdag.py @ 53036:fcd7cb10623d stable

drawdag: add documentation about special comment around files The feature was not documented, so we start with documenting it before extending it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 11 Mar 2025 11:38:12 +0100
parents 5cc8deb96b48
children 25079cc2016f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30458
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.
33159
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
75
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
76 Some special comments could have side effects:
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
77
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
78 - Create obsmarkers
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
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: 32376
diff changeset
80 # split: A -> B, C # 1 to many
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
81 # prune: A, B, C # many to nothing
53036
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
82
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
83 Special comment can also be used to control file content for some revision.
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
84
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
85 The example below create two extra files in A, update on in B.
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
86
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
87 In all case the file matching the node name is created for all non-merge
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
88 commit.
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
89
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
90 C # A/file/path=content in A
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
91 | # A/other/file/path=content for another file
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
92 B # B/file/path=updated content in B
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
93 |
fcd7cb10623d drawdag: add documentation about special comment around files
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52668
diff changeset
94 A
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
95 """
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 import collections
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
98 import itertools
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
99 import re
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
100
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
101 from mercurial.i18n import _
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
102 from mercurial import (
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
103 context,
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
104 error,
33159
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
105 obsolete,
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
106 pycompat,
32376
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32345
diff changeset
107 registrar,
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
108 scmutil,
31676
d761ef24d6e1 drawdag: use 'tagsmod.tag' instead of 'repo.tag'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30458
diff changeset
109 tags as tagsmod,
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
110 )
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 cmdtable = {}
32376
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32345
diff changeset
113 command = registrar.command(cmdtable)
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
114
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
115 _pipechars = b'\\/+-|'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
116 _nonpipechars = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
117 pycompat.bytechr(i)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
118 for i in range(33, 127)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
119 if pycompat.bytechr(i) not in _pipechars
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
120 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
121
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
122
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
123 def _isname(ch):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
124 """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
125 otherwise"""
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
126 return ch in _nonpipechars
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
127
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
128
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
129 def _parseasciigraph(text):
34213
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
130 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: 34212
diff changeset
131
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
132 >>> import pprint
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
133 >>> pprint.pprint({pycompat.sysstr(k): [pycompat.sysstr(vv) for vv in v]
34213
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
134 ... for k, v in _parseasciigraph(br'''
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
135 ... G
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
136 ... |
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
137 ... 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: 34212
diff changeset
138 ... \ \| | # replace: C -> D -> H
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
139 ... H B E # prune: F, I
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
140 ... \|/
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
141 ... A
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
142 ... ''').items()})
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
143 {'A': [],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
144 'B': ['A'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
145 'C': ['B'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
146 'D': ['B'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
147 'E': ['A'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
148 'F': ['E'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
149 'G': ['F'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
150 'H': ['A'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
151 'I': ['H']}
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
152 >>> pprint.pprint({pycompat.sysstr(k): [pycompat.sysstr(vv) for vv in v]
34213
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
153 ... for k, v in _parseasciigraph(br'''
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
154 ... o foo
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
155 ... |\
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
156 ... +---o bar
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
157 ... | | |
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
158 ... | o | baz
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
159 ... | /
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
160 ... +---o d
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
161 ... | |
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
162 ... +---o c
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
163 ... | |
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
164 ... o | b
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
165 ... |/
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
166 ... o a
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
167 ... ''').items()})
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
168 {'a': [],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
169 'b': ['a'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
170 'bar': ['b', 'a'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
171 'baz': [],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
172 'c': ['b'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
173 'd': ['b'],
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
174 'foo': ['baz', 'b']}
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
175 """
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
176 lines = text.splitlines()
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
177 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
178
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
179 def get(y, x):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
180 """(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
181 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
182 if x < 0 or y < 0:
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
183 return b' '
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
184 try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
185 return lines[y][x : x + 1] or b' '
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
186 except IndexError:
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
187 return b' '
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
188
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
189 def getname(y, x):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
190 """(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
191 parts. if name is an 'o', try to replace it to the right"""
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
192 result = b''
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
193 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
194 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
195 if not _isname(ch):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
196 break
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
197 result = ch + result
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
198 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
199 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
200 if not _isname(ch):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
201 break
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
202 result += ch
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
203 if result == b'o':
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
204 # special handling, find the name to the right
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
205 result = b''
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
206 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
207 ch = get(y, x + i)
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
208 if ch == b' ' or ch in _pipechars:
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
209 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
210 break
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
211 else:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
212 result += ch
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
213 return result or b'o'
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
214 return result
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 parents(y, x):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
217 """(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
218 return a list of parents"""
32331
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 31676
diff changeset
219 visited = {(y, x)}
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
220 visit = []
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
221 result = []
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
222
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
223 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
224 """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
225 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
226 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
227 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
228 ch = get(y, x)
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
229 if any(ch == c and c not in expected for c in (b'-', b'+')):
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
230 y += 1
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
231 return follow(y + 1, x, expected)
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
232 if ch in expected or (b'o' in expected and _isname(ch)):
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
233 visit.append((y, x))
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
234
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
235 # -o- # starting point:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
236 # /|\ # follow '-' (horizontally), and '/|\' (to the bottom)
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
237 follow(y + 1, x, b'|')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
238 follow(y + 1, x - 1, b'/')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
239 follow(y + 1, x + 1, b'\\')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
240 follow(y, x - 1, b'-')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
241 follow(y, x + 1, b'-')
30458
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 while visit:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
244 y, x = visit.pop()
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
245 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
246 continue
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
247 visited.add((y, x))
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
248 ch = get(y, x)
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
249 if _isname(ch):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
250 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
251 continue
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
252 elif ch == b'|':
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
253 follow(y + 1, x, b'/|o')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
254 follow(y + 1, x - 1, b'/')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
255 follow(y + 1, x + 1, b'\\')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
256 elif ch == b'+':
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
257 follow(y, x - 1, b'-')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
258 follow(y, x + 1, b'-')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
259 follow(y + 1, x - 1, b'/')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
260 follow(y + 1, x + 1, b'\\')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
261 follow(y + 1, x, b'|')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
262 elif ch == b'\\':
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
263 follow(y + 1, x + 1, b'\\|o')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
264 elif ch == b'/':
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
265 follow(y + 1, x - 1, b'/|o')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
266 elif ch == b'-':
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
267 follow(y, x - 1, b'-+o')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
268 follow(y, x + 1, b'-+o')
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
269 return result
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 for y, line in enumerate(lines):
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
272 for x, ch in enumerate(pycompat.bytestr(line)):
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
273 if ch == b'#': # comment
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
274 break
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
275 if _isname(ch):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
276 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
277
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
278 return dict(edges)
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
279
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
280
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
281 class simplefilectx:
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
282 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
283 self._data = data
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
284 self._path = path
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 def data(self):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
287 return self._data
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
288
32345
911057981ba4 drawdag: provide filenode for its dummy filectx
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
289 def filenode(self):
911057981ba4 drawdag: provide filenode for its dummy filectx
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
290 return None
911057981ba4 drawdag: provide filenode for its dummy filectx
Jun Wu <quark@fb.com>
parents: 32331
diff changeset
291
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
292 def path(self):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
293 return self._path
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
294
41783
2e2076c8c25f commit: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41556
diff changeset
295 def copysource(self):
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
296 return None
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
297
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
298 def flags(self):
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
299 return b''
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
300
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
301
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
302 class simplecommitctx(context.committablectx):
33558
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
303 def __init__(self, repo, name, parentctxs, added):
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
304 opts = {
33558
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
305 'changes': scmutil.status([], list(added), [], [], [], [], []),
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
306 'date': b'0 0',
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
307 'extra': {b'branch': b'default'},
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
308 }
52668
5cc8deb96b48 pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents: 49037
diff changeset
309 super().__init__(repo, name, **opts)
33558
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
310 self._added = added
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
311 self._parents = parentctxs
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
312 while len(self._parents) < 2:
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
313 self._parents.append(repo[repo.nullid])
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
314
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
315 def filectx(self, key):
33558
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
316 return simplefilectx(key, self._added[key])
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
317
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
318 def commit(self):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
319 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
320
42521
15f04d652b62 drawdag: don't crash when writing copy info to changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 41783
diff changeset
321 def p1copies(self):
15f04d652b62 drawdag: don't crash when writing copy info to changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 41783
diff changeset
322 return {}
15f04d652b62 drawdag: don't crash when writing copy info to changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 41783
diff changeset
323
15f04d652b62 drawdag: don't crash when writing copy info to changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 41783
diff changeset
324 def p2copies(self):
15f04d652b62 drawdag: don't crash when writing copy info to changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 41783
diff changeset
325 return {}
15f04d652b62 drawdag: don't crash when writing copy info to changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 41783
diff changeset
326
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
327
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
328 def _walkgraph(edges):
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
329 """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
330 visible = set(edges.keys())
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
331 remaining = {} # {str: [str]}
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
332 for k, vs in edges.items():
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
333 for v in vs:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
334 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
335 remaining[v] = []
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
336 remaining[k] = vs[:]
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
337 while remaining:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
338 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
339 if not leafs:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
340 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
341 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
342 if leaf in visible:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
343 yield leaf, edges[leaf]
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
344 del remaining[leaf]
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
345 for k, v in remaining.items():
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
346 if leaf in v:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
347 v.remove(leaf)
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
348
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
349
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
350 def _getcomments(text):
41556
8d4ee2d9ffb8 drawdag: use raw strings for docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39461
diff changeset
351 r"""
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
352 >>> [pycompat.sysstr(s) for s in _getcomments(br'''
34213
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
353 ... G
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
354 ... |
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
355 ... 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: 34212
diff changeset
356 ... \ \| | # replace: C -> D -> H
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
357 ... H B E # prune: F, I
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
358 ... \|/
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
359 ... A
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
360 ... ''')]
1e71dddc10a2 drawdag: add a couple of doctests to help with python3 porting
Augie Fackler <raf@durin42.com>
parents: 34212
diff changeset
361 ['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: 34212
diff changeset
362 """
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
363 for line in text.splitlines():
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
364 if b' # ' not in line:
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
365 continue
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
366 yield line.split(b' # ', 1)[1].split(b' # ')[0].strip()
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
367
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
368
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
369 @command(b'debugdrawdag', [])
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
370 def debugdrawdag(ui, repo, **opts):
41556
8d4ee2d9ffb8 drawdag: use raw strings for docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39461
diff changeset
371 r"""read an ASCII graph from stdin and create changesets
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
372
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
373 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
374 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
375 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
376 to.
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
377
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
378 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
379 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
380 :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
381
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
382 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
383 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
384 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
385 """
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
386 text = ui.fin.read()
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
387
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
388 # 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
389 edges = _parseasciigraph(text)
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
390 for k, v in edges.items():
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
391 if len(v) > 2:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
392 raise error.Abort(_('%s: too many parents: %s') % (k, b' '.join(v)))
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
393
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
394 # parse comments to get extra file content instructions
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
395 files = collections.defaultdict(dict) # {(name, path): content}
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
396 comments = list(_getcomments(text))
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
397 filere = re.compile(br'^(\w+)/([\w/]+)\s*=\s*(.*)$', re.M)
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
398 for name, path, content in filere.findall(b'\n'.join(comments)):
35838
4e41b59633fa lfs: add a test showing bundle application could be broken
Jun Wu <quark@fb.com>
parents: 34214
diff changeset
399 content = content.replace(br'\n', b'\n').replace(br'\1', b'\1')
4e41b59633fa lfs: add a test showing bundle application could be broken
Jun Wu <quark@fb.com>
parents: 34214
diff changeset
400 files[name][path] = content
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
401
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
402 committed = {None: repo.nullid} # {name: node}
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
403
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
404 # for leaf nodes, try to find existing nodes in repo
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
405 for name, parents in edges.items():
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
406 if len(parents) == 0:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
407 try:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
408 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
409 except error.RepoLookupError:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
410 pass
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
411
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
412 # commit in topological order
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
413 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
414 if name in committed:
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
415 continue
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
416 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: 33174
diff changeset
417 pctxs.sort(key=lambda c: c.node())
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
418 added = {}
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
419 if len(parents) > 1:
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
420 # 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: 33174
diff changeset
421 for f in pctxs[1].manifest():
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
422 if f not in pctxs[0].manifest():
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
423 added[f] = pctxs[1][f].data()
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
424 else:
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
425 # 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: 33174
diff changeset
426 added[name] = name
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
427 # add extra file contents in comments
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
428 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
429 added[path] = content
33558
0103e7187237 drawdag: include files from both parents in merge commits
Martin von Zweigbergk <martinvonz@google.com>
parents: 33174
diff changeset
430 ctx = simplecommitctx(repo, name, pctxs, added)
30458
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
431 n = ctx.commit()
a31634336471 drawdag: update test repos by drawing the changelog DAG in ASCII
Jun Wu <quark@fb.com>
parents:
diff changeset
432 committed[name] = n
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
433 tagsmod.tag(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
434 repo, [name], n, message=None, user=None, date=None, local=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
435 )
33159
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
436
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
437 # handle special comments
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
438 with repo.wlock(), repo.lock(), repo.transaction(b'drawdag'):
33159
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
439 getctx = lambda x: repo.unfiltered()[committed[x.strip()]]
33809
0531ffd59a98 drawdag: allow override file contents via comments
Jun Wu <quark@fb.com>
parents: 33558
diff changeset
440 for comment in comments:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42521
diff changeset
441 rels = [] # obsolete relationships
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
442 args = comment.split(b':', 1)
33159
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
443 if len(args) <= 1:
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
444 continue
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
445
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
446 cmd = args[0].strip()
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
447 arg = args[1].strip()
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
448
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
449 if cmd in (b'replace', b'rebase', b'amend'):
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
450 nodes = [getctx(m) for m in arg.split(b'->')]
33159
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
451 for i in range(len(nodes) - 1):
44411
dda2341d6664 drawdag: abide by new createmarkers() API
Martin von Zweigbergk <martinvonz@google.com>
parents: 43076
diff changeset
452 rels.append(((nodes[i],), (nodes[i + 1],)))
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
453 elif cmd in (b'split',):
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
454 pre, succs = arg.split(b'->')
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
455 succs = succs.split(b',')
44411
dda2341d6664 drawdag: abide by new createmarkers() API
Martin von Zweigbergk <martinvonz@google.com>
parents: 43076
diff changeset
456 rels.append(((getctx(pre),), (getctx(s) for s in succs)))
34214
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
457 elif cmd in (b'prune',):
5a1b41268b7c drawdag: port to python 3
Augie Fackler <raf@durin42.com>
parents: 34213
diff changeset
458 for n in arg.split(b','):
44411
dda2341d6664 drawdag: abide by new createmarkers() API
Martin von Zweigbergk <martinvonz@google.com>
parents: 43076
diff changeset
459 rels.append(((getctx(n),), ()))
33159
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
460 if rels:
4d780d510b44 drawdag: support obsmarker creation in comments
Jun Wu <quark@fb.com>
parents: 32376
diff changeset
461 obsolete.createmarkers(repo, rels, date=(0, 0), operation=cmd)