annotate mercurial/dagparser.py @ 46150:a132aa5979ec

copies: no longer cache the ChangedFiles during copy tracing Now that the copies information for both parents are processed all at once, we no longer needs to cache this information, so we simplify the code. The simpler code is also a (tiny) bit faster overall. Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000041 s, 0.000041 s, +0.000000 s, × 1.0000, 41 µs/rev mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 6 revs, 0.000102 s, 0.000096 s, -0.000006 s, × 0.9412, 16 µs/rev mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.004254 s, 0.004039 s, -0.000215 s, × 0.9495, 3 µs/rev pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 9 revs, 0.000282 s, 0.000189 s, -0.000093 s, × 0.6702, 21 µs/rev pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.000048 s, 0.000047 s, -0.000001 s, × 0.9792, 47 µs/rev pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 7 revs, 0.000211 s, 0.000103 s, -0.000108 s, × 0.4882, 14 µs/rev pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 1 revs, 0.000375 s, 0.000286 s, -0.000089 s, × 0.7627, 286 µs/rev pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 6 revs, 0.010574 s, 0.010436 s, -0.000138 s, × 0.9869, 1739 µs/rev pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 4785 revs, 0.049974 s, 0.047465 s, -0.002509 s, × 0.9498, 9 µs/rev pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.084300 s, 0.082351 s, -0.001949 s, × 0.9769, 12 µs/rev pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 5441 revs, 0.060128 s, 0.058757 s, -0.001371 s, × 0.9772, 10 µs/rev pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.686542 s, 0.674129 s, -0.012413 s, × 0.9819, 15 µs/rev pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 2 revs, 0.009277 s, 0.009434 s, +0.000157 s, × 1.0169, 4717 µs/rev pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 11316 revs, 0.114733 s, 0.111935 s, -0.002798 s, × 0.9756, 9 µs/rev netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.000081 s, 0.000078 s, -0.000003 s, × 0.9630, 39 µs/rev netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 2 revs, 0.000107 s, 0.000106 s, -0.000001 s, × 0.9907, 53 µs/rev netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.000173 s, 0.000162 s, -0.000011 s, × 0.9364, 54 µs/rev netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 9 revs, 0.000698 s, 0.000695 s, -0.000003 s, × 0.9957, 77 µs/rev netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.009248 s, 0.008901 s, -0.000347 s, × 0.9625, 6 µs/rev netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 1533 revs, 0.015446 s, 0.014333 s, -0.001113 s, × 0.9279, 9 µs/rev netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 5750 revs, 0.074373 s, 0.071998 s, -0.002375 s, × 0.9681, 12 µs/rev netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 66949 revs, 0.639870 s, 0.615346 s, -0.024524 s, × 0.9617, 9 µs/rev mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 2 revs, 0.000088 s, 0.000085 s, -0.000003 s, × 0.9659, 42 µs/rev mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 8 revs, 0.000199 s, 0.000199 s, +0.000000 s, × 1.0000, 24 µs/rev mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 9 revs, 0.000171 s, 0.000169 s, -0.000002 s, × 0.9883, 18 µs/rev mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 7 revs, 0.000592 s, 0.000590 s, -0.000002 s, × 0.9966, 84 µs/rev mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.003151 s, 0.003122 s, -0.000029 s, × 0.9908, 1040 µs/rev mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.061612 s, 0.061192 s, -0.000420 s, × 0.9932, 10198 µs/rev mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.005381 s, 0.005137 s, -0.000244 s, × 0.9547, 3 µs/rev mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.003742 s, 0.003585 s, -0.000157 s, × 0.9580, 87 µs/rev mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 7839 revs, 0.061983 s, 0.060592 s, -0.001391 s, × 0.9776, 7 µs/rev mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.019861 s, 0.019596 s, -0.000265 s, × 0.9867, 31 µs/rev mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 30263 revs, 0.188101 s, 0.183558 s, -0.004543 s, × 0.9758, 6 µs/rev mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 153721 revs, 1.806696 s, 1.758083 s, -0.048613 s, × 0.9731, 11 µs/rev mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 204976 revs, 2.682987 s, 2.592955 s, -0.090032 s, × 0.9664, 12 µs/rev mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 2 revs, 0.000852 s, 0.000844 s, -0.000008 s, × 0.9906, 422 µs/rev mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.000859 s, 0.000861 s, +0.000002 s, × 1.0023, 430 µs/rev mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 4 revs, 0.000150 s, 0.000150 s, +0.000000 s, × 1.0000, 37 µs/rev mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 2 revs, 0.001158 s, 0.001166 s, +0.000008 s, × 1.0069, 583 µs/rev mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1 revs, 0.027240 s, 0.027359 s, +0.000119 s, × 1.0044, 27359 µs/rev mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.062824 s, 0.061848 s, -0.000976 s, × 0.9845, 10308 µs/rev mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.005463 s, 0.005110 s, -0.000353 s, × 0.9354, 3 µs/rev mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.004238 s, 0.004168 s, -0.000070 s, × 0.9835, 101 µs/rev mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 6657 revs, 0.064113 s, 0.063414 s, -0.000699 s, × 0.9891, 9 µs/rev mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 40314 revs, 0.294063 s, 0.288301 s, -0.005762 s, × 0.9804, 7 µs/rev mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 38690 revs, 0.281493 s, 0.275798 s, -0.005695 s, × 0.9798, 7 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.076323 s, 0.074640 s, -0.001683 s, × 0.9779, 8 µs/rev mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.020390 s, 0.020327 s, -0.000063 s, × 0.9969, 33 µs/rev mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 3.023879 s, 2.970385 s, -0.053494 s, × 0.9823, 30 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 0.735549 s, 0.719432 s, -0.016117 s, × 0.9781, 13 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 18.568900 s, 18.165143 s, -0.403757 s, × 0.9783, 49 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.502584 s, 0.486769 s, -0.015815 s, × 0.9685, 14 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 18.356645 s, 17.913924 s, -0.442721 s, × 0.9759, 49 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 18.250393 s, 17.660113 s, -0.590280 s, × 0.9677, 49 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 2.792459 s, 2.709446 s, -0.083013 s, × 0.9703, 14 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 107.697264 s, 107.796891 s, +0.099627 s, × 1.0009, 470 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 63.961040 s, 63.575217 s, -0.385823 s, × 0.9940, 166 µs/rev Differential Revision: https://phab.mercurial-scm.org/D9423
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 20 Nov 2020 13:46:14 +0100
parents 89a2afe31e82
children 70f8c64812db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
1 # dagparser.py - parser and generator for concise description of DAGs
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
2 #
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
3 # Copyright 2010 Peter Arrenbrecht <peter@arrenbrecht.ch>
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
4 #
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
7
25941
a75cda2dfc19 dagparser: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25170
diff changeset
8 from __future__ import absolute_import
a75cda2dfc19 dagparser: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25170
diff changeset
9
a75cda2dfc19 dagparser: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25170
diff changeset
10 import re
a75cda2dfc19 dagparser: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25170
diff changeset
11 import string
a75cda2dfc19 dagparser: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25170
diff changeset
12
a75cda2dfc19 dagparser: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25170
diff changeset
13 from .i18n import _
34210
8927534cacbc py3: drop use of str() in dagparser.py
Yuya Nishihara <yuya@tcha.org>
parents: 34209
diff changeset
14 from . import (
8927534cacbc py3: drop use of str() in dagparser.py
Yuya Nishihara <yuya@tcha.org>
parents: 34209
diff changeset
15 error,
34211
a48ad118c558 py3: wrap string constants in dagparser.py with bytestr()
Yuya Nishihara <yuya@tcha.org>
parents: 34210
diff changeset
16 pycompat,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 34212
diff changeset
17 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
18 from .utils import stringutil
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
19
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
20
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
21 def parsedag(desc):
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
22 '''parses a DAG from a concise textual description; generates events
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
23
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
24 "+n" is a linear run of n nodes based on the current default parent
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
25 "." is a single node based on the current default parent
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
26 "$" resets the default parent to -1 (implied at the start);
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
27 otherwise the default parent is always the last node created
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
28 "<p" sets the default parent to the backref p
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
29 "*p" is a fork at parent p, where p is a backref
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
30 "*p1/p2/.../pn" is a merge of parents p1..pn, where the pi are backrefs
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
31 "/p2/.../pn" is a merge of the preceding node and p2..pn
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
32 ":name" defines a label for the preceding node; labels can be redefined
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
33 "@text" emits an annotation event for text
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
34 "!command" emits an action event for the current node
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
35 "!!my command\n" is like "!", but to the end of the line
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
36 "#...\n" is a comment up to the end of the line
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
37
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
38 Whitespace between the above elements is ignored.
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
39
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
40 A backref is either
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
41 * a number n, which references the node curr-n, where curr is the current
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
42 node, or
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
43 * the name of a label you placed earlier using ":name", or
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
44 * empty to denote the default parent.
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
45
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
46 All string valued-elements are either strictly alphanumeric, or must
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
47 be enclosed in double quotes ("..."), with "\" as escape character.
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
48
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
49 Generates sequence of
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
50
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
51 ('n', (id, [parentids])) for node creation
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
52 ('l', (id, labelname)) for labels on nodes
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
53 ('a', text) for annotations
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
54 ('c', command) for actions (!)
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
55 ('C', command) for line actions (!!)
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
56
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
57 Examples
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
58 --------
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
59
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
60 Example of a complex graph (output not shown for brevity):
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
61
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
62 >>> len(list(parsedag(b"""
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
63 ...
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
64 ... +3 # 3 nodes in linear run
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
65 ... :forkhere # a label for the last of the 3 nodes from above
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
66 ... +5 # 5 more nodes on one branch
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
67 ... :mergethis # label again
17500
8ac8db8dc346 en-us: labeled
timeless@mozdev.org
parents: 16683
diff changeset
68 ... <forkhere # set default parent to labeled fork node
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
69 ... +10 # 10 more nodes on a parallel branch
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
70 ... @stable # following nodes will be annotated as "stable"
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
71 ... +5 # 5 nodes in stable
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
72 ... !addfile # custom command; could trigger new file in next node
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
73 ... +2 # two more nodes
17500
8ac8db8dc346 en-us: labeled
timeless@mozdev.org
parents: 16683
diff changeset
74 ... /mergethis # merge last node with labeled node
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
75 ... +4 # 4 more nodes descending from merge node
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
76 ...
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
77 ... """)))
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
78 34
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
79
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
80 Empty list:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
81
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
82 >>> list(parsedag(b""))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
83 []
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
84
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
85 A simple linear run:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
86
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
87 >>> list(parsedag(b"+3"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
88 [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
89
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
90 Some non-standard ways to define such runs:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
91
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
92 >>> list(parsedag(b"+1+2"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
93 [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
94
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
95 >>> list(parsedag(b"+1*1*"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
96 [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
97
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
98 >>> list(parsedag(b"*"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
99 [('n', (0, [-1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
100
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
101 >>> list(parsedag(b"..."))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
102 [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
103
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
104 A fork and a join, using numeric back references:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
105
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
106 >>> list(parsedag(b"+2*2*/2"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
107 [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [0])), ('n', (3, [2, 1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
108
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
109 >>> list(parsedag(b"+2<2+1/2"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
110 [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [0])), ('n', (3, [2, 1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
111
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
112 Placing a label:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
113
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
114 >>> list(parsedag(b"+1 :mylabel +1"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
115 [('n', (0, [-1])), ('l', (0, 'mylabel')), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
116
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
117 An empty label (silly, really):
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
118
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
119 >>> list(parsedag(b"+1:+1"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
120 [('n', (0, [-1])), ('l', (0, '')), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
121
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
122 Fork and join, but with labels instead of numeric back references:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
123
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
124 >>> list(parsedag(b"+1:f +1:p2 *f */p2"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
125 [('n', (0, [-1])), ('l', (0, 'f')), ('n', (1, [0])), ('l', (1, 'p2')),
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
126 ('n', (2, [0])), ('n', (3, [2, 1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
127
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
128 >>> list(parsedag(b"+1:f +1:p2 <f +1 /p2"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
129 [('n', (0, [-1])), ('l', (0, 'f')), ('n', (1, [0])), ('l', (1, 'p2')),
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
130 ('n', (2, [0])), ('n', (3, [2, 1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
131
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
132 Restarting from the root:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
133
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
134 >>> list(parsedag(b"+1 $ +1"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
135 [('n', (0, [-1])), ('n', (1, [-1]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
136
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
137 Annotations, which are meant to introduce sticky state for subsequent nodes:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
138
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
139 >>> list(parsedag(b"+1 @ann +1"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
140 [('n', (0, [-1])), ('a', 'ann'), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
141
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
142 >>> list(parsedag(b'+1 @"my annotation" +1'))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
143 [('n', (0, [-1])), ('a', 'my annotation'), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
144
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
145 Commands, which are meant to operate on the most recently created node:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
146
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
147 >>> list(parsedag(b"+1 !cmd +1"))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
148 [('n', (0, [-1])), ('c', 'cmd'), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
149
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
150 >>> list(parsedag(b'+1 !"my command" +1'))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
151 [('n', (0, [-1])), ('c', 'my command'), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
152
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
153 >>> list(parsedag(b'+1 !!my command line\\n +1'))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
154 [('n', (0, [-1])), ('C', 'my command line'), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
155
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
156 Comments, which extend to the end of the line:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
157
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
158 >>> list(parsedag(b'+1 # comment\\n+1'))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
159 [('n', (0, [-1])), ('n', (1, [0]))]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
160
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
161 Error:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
162
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
163 >>> try: list(parsedag(b'+1 bad'))
34138
0f9936d80e01 doctest: upgrade old-style "except" clause
Yuya Nishihara <yuya@tcha.org>
parents: 34137
diff changeset
164 ... except Exception as e: print(pycompat.sysstr(bytes(e)))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
165 invalid character in dag description: bad...
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
166
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
167 '''
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
168 if not desc:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
169 return
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
170
43497
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
171 wordchars = pycompat.bytestr(
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
172 string.ascii_letters + string.digits
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
173 ) # pytype: disable=wrong-arg-types
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
174
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
175 labels = {}
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
176 p1 = -1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
177 r = 0
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
178
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
179 def resolve(ref):
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
180 if not ref:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
181 return p1
43497
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
182 elif ref[0] in pycompat.bytestr(
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
183 string.digits
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
184 ): # pytype: disable=wrong-arg-types
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
185 return r - int(ref)
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
186 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
187 return labels[ref]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
188
34212
dfd009e5f9f2 py3: iterate bytes as a byte string in dagparser.py
Yuya Nishihara <yuya@tcha.org>
parents: 34211
diff changeset
189 chiter = pycompat.iterbytestr(desc)
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
190
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
191 def nextch():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
192 return next(chiter, b'\0')
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
193
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
194 def nextrun(c, allow):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
195 s = b''
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
196 while c in allow:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
197 s += c
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
198 c = nextch()
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
199 return c, s
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
200
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
201 def nextdelimited(c, limit, escape):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
202 s = b''
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
203 while c != limit:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
204 if c == escape:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
205 c = nextch()
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
206 s += c
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
207 c = nextch()
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
208 return nextch(), s
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
209
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
210 def nextstring(c):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
211 if c == b'"':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
212 return nextdelimited(nextch(), b'"', b'\\')
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
213 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
214 return nextrun(c, wordchars)
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
215
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
216 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
217 while c != b'\0':
43497
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
218 while c in pycompat.bytestr(
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
219 string.whitespace
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
220 ): # pytype: disable=wrong-arg-types
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
221 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
222 if c == b'.':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
223 yield b'n', (r, [p1])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
224 p1 = r
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
225 r += 1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
226 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
227 elif c == b'+':
43497
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
228 c, digs = nextrun(
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
229 nextch(), pycompat.bytestr(string.digits)
6d001f452bcb dagparser: suppress some pytype errors around pycompat.bytestring
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
230 ) # pytype: disable=wrong-arg-types
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
231 n = int(digs)
38783
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37084
diff changeset
232 for i in pycompat.xrange(0, n):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
233 yield b'n', (r, [p1])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
234 p1 = r
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
235 r += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
236 elif c in b'*/':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
237 if c == b'*':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
238 c = nextch()
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
239 c, pref = nextstring(c)
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
240 prefs = [pref]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
241 while c == b'/':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
242 c, pref = nextstring(nextch())
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
243 prefs.append(pref)
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
244 ps = [resolve(ref) for ref in prefs]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
245 yield b'n', (r, ps)
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
246 p1 = r
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
247 r += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
248 elif c == b'<':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
249 c, ref = nextstring(nextch())
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
250 p1 = resolve(ref)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
251 elif c == b':':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
252 c, name = nextstring(nextch())
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
253 labels[name] = p1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
254 yield b'l', (p1, name)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
255 elif c == b'@':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
256 c, text = nextstring(nextch())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
257 yield b'a', text
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
258 elif c == b'!':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
259 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
260 if c == b'!':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
261 cmd = b''
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
262 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
263 while c not in b'\n\r\0':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
264 cmd += c
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
265 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
266 yield b'C', cmd
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
267 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
268 c, cmd = nextstring(c)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
269 yield b'c', cmd
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
270 elif c == b'#':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
271 while c not in b'\n\r\0':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
272 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
273 elif c == b'$':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
274 p1 = -1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
275 c = nextch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
276 elif c == b'\0':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
277 return # in case it was preceded by whitespace
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
278 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
279 s = b''
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
280 i = 0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
281 while c != b'\0' and i < 10:
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
282 s += c
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
283 i += 1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
284 c = nextch()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
285 raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
286 _(b'invalid character in dag description: %s...') % s
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
287 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
288
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
289
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
290 def dagtextlines(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
291 events,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
292 addspaces=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
293 wraplabels=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
294 wrapannotations=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
295 wrapcommands=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
296 wrapnonlinear=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
297 usedots=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
298 maxlinewidth=70,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
299 ):
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
300 '''generates single lines for dagtext()'''
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
301
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
302 def wrapstring(text):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
303 if re.match(b"^[0-9a-z]*$", text):
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
304 return text
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
305 return b'"' + text.replace(b'\\', b'\\\\').replace(b'"', b'\"') + b'"'
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
306
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
307 def gen():
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
308 labels = {}
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
309 run = 0
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
310 wantr = 0
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
311 needroot = False
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
312 for kind, data in events:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
313 if kind == b'n':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
314 r, ps = data
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
315
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
316 # sanity check
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
317 if r != wantr:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
318 raise error.Abort(_(b"expected id %i, got %i") % (wantr, r))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
319 if not ps:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
320 ps = [-1]
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
321 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
322 for p in ps:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
323 if p >= r:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
324 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
325 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
326 b"parent id %i is larger than "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
327 b"current id %i"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
328 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
329 % (p, r)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
330 )
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
331 wantr += 1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
332
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
333 # new root?
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
334 p1 = r - 1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
335 if len(ps) == 1 and ps[0] == -1:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
336 if needroot:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
337 if run:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
338 yield b'+%d' % run
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
339 run = 0
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
340 if wrapnonlinear:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
341 yield b'\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
342 yield b'$'
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
343 p1 = -1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
344 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
345 needroot = True
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
346 if len(ps) == 1 and ps[0] == p1:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
347 if usedots:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
348 yield b"."
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
349 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
350 run += 1
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
351 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
352 if run:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
353 yield b'+%d' % run
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
354 run = 0
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
355 if wrapnonlinear:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
356 yield b'\n'
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
357 prefs = []
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
358 for p in ps:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
359 if p == p1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
360 prefs.append(b'')
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
361 elif p in labels:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
362 prefs.append(labels[p])
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
363 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
364 prefs.append(b'%d' % (r - p))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
365 yield b'*' + b'/'.join(prefs)
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
366 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
367 if run:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
368 yield b'+%d' % run
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
369 run = 0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
370 if kind == b'l':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
371 rid, name = data
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
372 labels[rid] = name
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
373 yield b':' + name
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
374 if wraplabels:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
375 yield b'\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
376 elif kind == b'c':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
377 yield b'!' + wrapstring(data)
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
378 if wrapcommands:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
379 yield b'\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
380 elif kind == b'C':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
381 yield b'!!' + data
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
382 yield b'\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
383 elif kind == b'a':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
384 if wrapannotations:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
385 yield b'\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
386 yield b'@' + wrapstring(data)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
387 elif kind == b'#':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
388 yield b'#' + data
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
389 yield b'\n'
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
390 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
391 raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
392 _(b"invalid event type in dag: ('%s', '%s')")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
393 % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
394 stringutil.escapestr(kind),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
395 stringutil.escapestr(data),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
396 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
397 )
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
398 if run:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
399 yield b'+%d' % run
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
400
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
401 line = b''
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
402 for part in gen():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
403 if part == b'\n':
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
404 if line:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
405 yield line
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
406 line = b''
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
407 else:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
408 if len(line) + len(part) >= maxlinewidth:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
409 yield line
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
410 line = b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
411 elif addspaces and line and part != b'.':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
412 line += b' '
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
413 line += part
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
414 if line:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
415 yield line
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
416
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
417
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
418 def dagtext(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
419 dag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
420 addspaces=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
421 wraplabels=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
422 wrapannotations=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
423 wrapcommands=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
424 wrapnonlinear=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
425 usedots=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
426 maxlinewidth=70,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
427 ):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43497
diff changeset
428 """generates lines of a textual representation for a dag event stream
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
429
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
430 events should generate what parsedag() does, so:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
431
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
432 ('n', (id, [parentids])) for node creation
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
433 ('l', (id, labelname)) for labels on nodes
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
434 ('a', text) for annotations
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
435 ('c', text) for commands
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
436 ('C', text) for line commands ('!!')
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
437 ('#', text) for comment lines
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
438
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
439 Parent nodes must come before child nodes.
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
440
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
441 Examples
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
442 --------
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
443
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
444 Linear run:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
445
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
446 >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [0]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
447 '+2'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
448
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
449 Two roots:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
450
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
451 >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [-1]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
452 '+1 $ +1'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
453
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
454 Fork and join:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
455
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
456 >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [0])), (b'n', (2, [0])),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
457 ... (b'n', (3, [2, 1]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
458 '+2 *2 */2'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
459
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
460 Fork and join with labels:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
461
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
462 >>> dagtext([(b'n', (0, [-1])), (b'l', (0, b'f')), (b'n', (1, [0])),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
463 ... (b'l', (1, b'p2')), (b'n', (2, [0])), (b'n', (3, [2, 1]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
464 '+1 :f +1 :p2 *f */p2'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
465
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
466 Annotations:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
467
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
468 >>> dagtext([(b'n', (0, [-1])), (b'a', b'ann'), (b'n', (1, [0]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
469 '+1 @ann +1'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
470
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
471 >>> dagtext([(b'n', (0, [-1])),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
472 ... (b'a', b'my annotation'),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
473 ... (b'n', (1, [0]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
474 '+1 @"my annotation" +1'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
475
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
476 Commands:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
477
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
478 >>> dagtext([(b'n', (0, [-1])), (b'c', b'cmd'), (b'n', (1, [0]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
479 '+1 !cmd +1'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
480
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
481 >>> dagtext([(b'n', (0, [-1])),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
482 ... (b'c', b'my command'),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
483 ... (b'n', (1, [0]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
484 '+1 !"my command" +1'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
485
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
486 >>> dagtext([(b'n', (0, [-1])),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
487 ... (b'C', b'my command line'),
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
488 ... (b'n', (1, [0]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
489 '+1 !!my command line\\n+1'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
490
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
491 Comments:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
492
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
493 >>> dagtext([(b'n', (0, [-1])), (b'#', b' comment'), (b'n', (1, [0]))])
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
494 '+1 # comment\\n+1'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
495
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
496 >>> dagtext([])
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
497 ''
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
498
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
499 Combining parsedag and dagtext:
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
500
34131
0fa781320203 doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 33716
diff changeset
501 >>> dagtext(parsedag(b'+1 :f +1 :p2 *f */p2'))
11335
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
502 '+1 :f +1 :p2 *f */p2'
3201ff1459dd dagparser: parses and formats DAGs as concise text
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
diff changeset
503
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43497
diff changeset
504 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
505 return b"\n".join(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
506 dagtextlines(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
507 dag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
508 addspaces,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
509 wraplabels,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
510 wrapannotations,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
511 wrapcommands,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
512 wrapnonlinear,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
513 usedots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
514 maxlinewidth,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
515 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38783
diff changeset
516 )