comparison hgext3rd/topic/revset.py @ 4814:48b30ff742cb

python3: use format-source to run byteify-strings in .py files Using the format-source extension smooth out the pain of merging after auto-formatting. This change makes all of the Evolve test suite pass under python3 and has added benefit of being 100% automated using mercurial's `byteify-strings` script version 1.0 (revision 11498aa91c036c6d70f7ac5ee5af2664a84a1130). How to benefit from the help of format-source is explained in the README.
author Raphaël Gomès <rgomes@octobus.net>
date Tue, 06 Aug 2019 15:06:38 +0200
parents 7b36f9728351
children a4d081923c81 a828c7a7ace1
comparison
equal deleted inserted replaced
4812:67567d7f1174 4814:48b30ff742cb
22 mkmatcher = util.stringmatcher 22 mkmatcher = util.stringmatcher
23 23
24 revsetpredicate = registrar.revsetpredicate() 24 revsetpredicate = registrar.revsetpredicate()
25 25
26 def getstringstrict(x, err): 26 def getstringstrict(x, err):
27 if x and x[0] == 'string': 27 if x and x[0] == b'string':
28 return x[1] 28 return x[1]
29 raise error.ParseError(err) 29 raise error.ParseError(err)
30 30
31 @revsetpredicate(b'topic([string or set])') 31 @revsetpredicate(b'topic([string or set])')
32 def topicset(repo, subset, x): 32 def topicset(repo, subset, x):
34 changesets. Without the argument, all changesets with any topic specified. 34 changesets. Without the argument, all changesets with any topic specified.
35 35
36 If `string` starts with `re:` the remainder of the name is treated 36 If `string` starts with `re:` the remainder of the name is treated
37 as a regular expression. 37 as a regular expression.
38 """ 38 """
39 args = revset.getargs(x, 0, 1, 'topic takes one or no arguments') 39 args = revset.getargs(x, 0, 1, b'topic takes one or no arguments')
40 40
41 mutable = revset._notpublic(repo, revset.fullreposet(repo), ()) 41 mutable = revset._notpublic(repo, revset.fullreposet(repo), ())
42 42
43 if not args: 43 if not args:
44 return (subset & mutable).filter(lambda r: bool(repo[r].topic())) 44 return (subset & mutable).filter(lambda r: bool(repo[r].topic()))
45 45
46 try: 46 try:
47 topic = getstringstrict(args[0], '') 47 topic = getstringstrict(args[0], b'')
48 except error.ParseError: 48 except error.ParseError:
49 # not a string, but another revset 49 # not a string, but another revset
50 pass 50 pass
51 else: 51 else:
52 kind, pattern, matcher = mkmatcher(topic) 52 kind, pattern, matcher = mkmatcher(topic)
53 53
54 if topic.startswith('literal:') and pattern not in repo.topics: 54 if topic.startswith(b'literal:') and pattern not in repo.topics:
55 raise error.RepoLookupError("topic '%s' does not exist" % pattern) 55 raise error.RepoLookupError(b"topic '%s' does not exist" % pattern)
56 56
57 def matches(r): 57 def matches(r):
58 topic = repo[r].topic() 58 topic = repo[r].topic()
59 if not topic: 59 if not topic:
60 return False 60 return False
62 62
63 return (subset & mutable).filter(matches) 63 return (subset & mutable).filter(matches)
64 64
65 s = revset.getset(repo, revset.fullreposet(repo), x) 65 s = revset.getset(repo, revset.fullreposet(repo), x)
66 topics = {repo[r].topic() for r in s} 66 topics = {repo[r].topic() for r in s}
67 topics.discard('') 67 topics.discard(b'')
68 68
69 def matches(r): 69 def matches(r):
70 if r in s: 70 if r in s:
71 return True 71 return True
72 topic = repo[r].topic() 72 topic = repo[r].topic()
80 def ngtipset(repo, subset, x): 80 def ngtipset(repo, subset, x):
81 """The untopiced tip. 81 """The untopiced tip.
82 82
83 Name is horrible so that people change it. 83 Name is horrible so that people change it.
84 """ 84 """
85 args = revset.getargs(x, 1, 1, 'ngtip takes one argument') 85 args = revset.getargs(x, 1, 1, b'ngtip takes one argument')
86 # match a specific topic 86 # match a specific topic
87 branch = revset.getstring(args[0], 'ngtip requires a string') 87 branch = revset.getstring(args[0], b'ngtip requires a string')
88 if branch == '.': 88 if branch == b'.':
89 branch = repo['.'].branch() 89 branch = repo[b'.'].branch()
90 return subset & revset.baseset(destination.ngtip(repo, branch)) 90 return subset & revset.baseset(destination.ngtip(repo, branch))
91 91
92 @revsetpredicate(b'stack()') 92 @revsetpredicate(b'stack()')
93 def stackset(repo, subset, x): 93 def stackset(repo, subset, x):
94 """All relevant changes in the current topic, 94 """All relevant changes in the current topic,
95 95
96 This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving 96 This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving
97 unstable changeset after there future parent (as if evolve where already 97 unstable changeset after there future parent (as if evolve where already
98 run). 98 run).
99 """ 99 """
100 err = 'stack takes no arguments, it works on current topic' 100 err = b'stack takes no arguments, it works on current topic'
101 revset.getargs(x, 0, 0, err) 101 revset.getargs(x, 0, 0, err)
102 topic = None 102 topic = None
103 branch = None 103 branch = None
104 if repo.currenttopic: 104 if repo.currenttopic:
105 topic = repo.currenttopic 105 topic = repo.currenttopic
118 """ 118 """
119 # hg 4.9 provides a number or None, hg 5.0 provides a tuple of tokens 119 # hg 4.9 provides a number or None, hg 5.0 provides a tuple of tokens
120 if isinstance(z, tuple): 120 if isinstance(z, tuple):
121 a, b = revset.getintrange( 121 a, b = revset.getintrange(
122 z, 122 z,
123 'relation subscript must be an integer or a range', 123 b'relation subscript must be an integer or a range',
124 'relation subscript bounds must be integers', 124 b'relation subscript bounds must be integers',
125 None, None) 125 None, None)
126 else: 126 else:
127 a = b = z 127 a = b = z
128 128
129 s = revset.getset(repo, revset.fullreposet(repo), x) 129 s = revset.getset(repo, revset.fullreposet(repo), x)
157 if rev not in revs: 157 if rev not in revs:
158 revs.append(rev) 158 revs.append(rev)
159 159
160 return subset & revset.baseset(revs) 160 return subset & revset.baseset(revs)
161 161
162 revset.subscriptrelations['stack'] = stackrel 162 revset.subscriptrelations[b'stack'] = stackrel
163 revset.subscriptrelations['s'] = stackrel 163 revset.subscriptrelations[b's'] = stackrel
164 164
165 def topicrel(repo, subset, x, *args): 165 def topicrel(repo, subset, x, *args):
166 subset &= topicset(repo, subset, x) 166 subset &= topicset(repo, subset, x)
167 return revset.generationsrel(repo, subset, x, *args) 167 return revset.generationsrel(repo, subset, x, *args)
168 168
169 revset.subscriptrelations['topic'] = topicrel 169 revset.subscriptrelations[b'topic'] = topicrel
170 revset.subscriptrelations['t'] = topicrel 170 revset.subscriptrelations[b't'] = topicrel