Mercurial > evolve
comparison hgext3rd/topic/stack.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 | 88472e743c64 |
children | 485a9f3490c9 |
comparison
equal
deleted
inserted
replaced
4812:67567d7f1174 | 4814:48b30ff742cb |
---|---|
24 """parses the ctx user and returns the username without email ID if | 24 """parses the ctx user and returns the username without email ID if |
25 possible, otherwise returns the mail address from that""" | 25 possible, otherwise returns the mail address from that""" |
26 username = None | 26 username = None |
27 if user: | 27 if user: |
28 # user is of form "abc <abc@xyz.com>" | 28 # user is of form "abc <abc@xyz.com>" |
29 username = user.split('<')[0] | 29 username = user.split(b'<')[0] |
30 if not username: | 30 if not username: |
31 # assuming user is of form "<abc@xyz.com>" | 31 # assuming user is of form "<abc@xyz.com>" |
32 if len(user) > 1: | 32 if len(user) > 1: |
33 username = user[1:-1] | 33 username = user[1:-1] |
34 else: | 34 else: |
43 The intend is to build something more efficient than what revsets do in | 43 The intend is to build something more efficient than what revsets do in |
44 this area. | 44 this area. |
45 """ | 45 """ |
46 phasesets = repo._phasecache._phasesets | 46 phasesets = repo._phasecache._phasesets |
47 if not phasesets or None in phasesets[phases.draft:]: | 47 if not phasesets or None in phasesets[phases.draft:]: |
48 return repo.revs('(not public()) - obsolete()') | 48 return repo.revs(b'(not public()) - obsolete()') |
49 | 49 |
50 result = set.union(*phasesets[phases.draft:]) | 50 result = set.union(*phasesets[phases.draft:]) |
51 result -= obsolete.getrevs(repo, 'obsolete') | 51 result -= obsolete.getrevs(repo, b'obsolete') |
52 return result | 52 return result |
53 | 53 |
54 class stack(object): | 54 class stack(object): |
55 """object represent a stack and common logic associated to it.""" | 55 """object represent a stack and common logic associated to it.""" |
56 | 56 |
61 self.behinderror = None | 61 self.behinderror = None |
62 | 62 |
63 subset = _stackcandidates(repo) | 63 subset = _stackcandidates(repo) |
64 | 64 |
65 if topic is not None and branch is not None: | 65 if topic is not None and branch is not None: |
66 raise error.ProgrammingError('both branch and topic specified (not defined yet)') | 66 raise error.ProgrammingError(b'both branch and topic specified (not defined yet)') |
67 elif topic is not None: | 67 elif topic is not None: |
68 trevs = repo.revs("%ld and topic(%s)", subset, topic) | 68 trevs = repo.revs(b"%ld and topic(%s)", subset, topic) |
69 elif branch is not None: | 69 elif branch is not None: |
70 trevs = repo.revs("%ld and branch(%s) - topic()", subset, branch) | 70 trevs = repo.revs(b"%ld and branch(%s) - topic()", subset, branch) |
71 else: | 71 else: |
72 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') | 72 raise error.ProgrammingError(b'neither branch and topic specified (not defined yet)') |
73 self._revs = trevs | 73 self._revs = trevs |
74 | 74 |
75 def __iter__(self): | 75 def __iter__(self): |
76 return iter(self.revs) | 76 return iter(self.revs) |
77 | 77 |
167 revs.extend(sorted(dependencies)) | 167 revs.extend(sorted(dependencies)) |
168 # step 3: add t0 | 168 # step 3: add t0 |
169 if revs: | 169 if revs: |
170 pt1 = self._repo[revs[0]].p1() | 170 pt1 = self._repo[revs[0]].p1() |
171 else: | 171 else: |
172 pt1 = self._repo['.'] | 172 pt1 = self._repo[b'.'] |
173 | 173 |
174 if pt1.obsolete(): | 174 if pt1.obsolete(): |
175 pt1 = self._repo[_singlesuccessor(self._repo, pt1)] | 175 pt1 = self._repo[_singlesuccessor(self._repo, pt1)] |
176 revs.insert(0, pt1.rev()) | 176 revs.insert(0, pt1.rev()) |
177 return revs | 177 return revs |
195 revs = self.revs[1:] | 195 revs = self.revs[1:] |
196 deps, rdeps = self._dependencies | 196 deps, rdeps = self._dependencies |
197 if revs: | 197 if revs: |
198 minroot = [min(r for r in revs if not deps[r])] | 198 minroot = [min(r for r in revs if not deps[r])] |
199 try: | 199 try: |
200 dest = destutil.destmerge(self._repo, action='rebase', | 200 dest = destutil.destmerge(self._repo, action=b'rebase', |
201 sourceset=minroot, | 201 sourceset=minroot, |
202 onheadcheck=False) | 202 onheadcheck=False) |
203 return len(self._repo.revs("only(%d, %ld)", dest, minroot)) | 203 return len(self._repo.revs(b"only(%d, %ld)", dest, minroot)) |
204 except error.NoMergeDestAbort: | 204 except error.NoMergeDestAbort: |
205 return 0 | 205 return 0 |
206 except error.ManyMergeDestAbort as exc: | 206 except error.ManyMergeDestAbort as exc: |
207 # XXX we should make it easier for upstream to provide the information | 207 # XXX we should make it easier for upstream to provide the information |
208 self.behinderror = pycompat.bytestr(exc).split('-', 1)[0].rstrip() | 208 self.behinderror = pycompat.bytestr(exc).split(b'-', 1)[0].rstrip() |
209 return -1 | 209 return -1 |
210 return 0 | 210 return 0 |
211 | 211 |
212 @util.propertycache | 212 @util.propertycache |
213 def branches(self): | 213 def branches(self): |
215 if not branches: | 215 if not branches: |
216 branches = set([self._repo[None].branch()]) | 216 branches = set([self._repo[None].branch()]) |
217 return branches | 217 return branches |
218 | 218 |
219 def labelsgen(prefix, parts): | 219 def labelsgen(prefix, parts): |
220 fmt = prefix + '.%s' | 220 fmt = prefix + b'.%s' |
221 return prefix + ' ' + ' '.join(fmt % p.replace(' ', '-') for p in parts) | 221 return prefix + b' ' + b' '.join(fmt % p.replace(b' ', b'-') for p in parts) |
222 | 222 |
223 def showstack(ui, repo, branch=None, topic=None, opts=None): | 223 def showstack(ui, repo, branch=None, topic=None, opts=None): |
224 if opts is None: | 224 if opts is None: |
225 opts = {} | 225 opts = {} |
226 | 226 |
227 if topic is not None and branch is not None: | 227 if topic is not None and branch is not None: |
228 msg = 'both branch and topic specified [%s]{%s}(not defined yet)' | 228 msg = b'both branch and topic specified [%s]{%s}(not defined yet)' |
229 msg %= (branch, topic) | 229 msg %= (branch, topic) |
230 raise error.ProgrammingError(msg) | 230 raise error.ProgrammingError(msg) |
231 elif topic is not None: | 231 elif topic is not None: |
232 prefix = 's' | 232 prefix = b's' |
233 if topic not in repo.topics: | 233 if topic not in repo.topics: |
234 raise error.Abort(_('cannot resolve "%s": no such topic found') % topic) | 234 raise error.Abort(_(b'cannot resolve "%s": no such topic found') % topic) |
235 elif branch is not None: | 235 elif branch is not None: |
236 prefix = 's' | 236 prefix = b's' |
237 else: | 237 else: |
238 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') | 238 raise error.ProgrammingError(b'neither branch and topic specified (not defined yet)') |
239 | 239 |
240 fm = ui.formatter('topicstack', opts) | 240 fm = ui.formatter(b'topicstack', opts) |
241 prev = None | 241 prev = None |
242 entries = [] | 242 entries = [] |
243 idxmap = {} | 243 idxmap = {} |
244 | 244 |
245 label = 'topic' | 245 label = b'topic' |
246 if topic == repo.currenttopic: | 246 if topic == repo.currenttopic: |
247 label = 'topic.active' | 247 label = b'topic.active' |
248 | 248 |
249 st = stack(repo, branch, topic) | 249 st = stack(repo, branch, topic) |
250 if topic is not None: | 250 if topic is not None: |
251 fm.plain(_('### topic: %s') | 251 fm.plain(_(b'### topic: %s') |
252 % ui.label(topic, label), | 252 % ui.label(topic, label), |
253 label='stack.summary.topic') | 253 label=b'stack.summary.topic') |
254 | 254 |
255 if 1 < len(st.heads): | 255 if 1 < len(st.heads): |
256 fm.plain(' (') | 256 fm.plain(b' (') |
257 fm.plain('%d heads' % len(st.heads), | 257 fm.plain(b'%d heads' % len(st.heads), |
258 label='stack.summary.headcount.multiple') | 258 label=b'stack.summary.headcount.multiple') |
259 fm.plain(')') | 259 fm.plain(b')') |
260 fm.plain('\n') | 260 fm.plain(b'\n') |
261 fm.plain(_('### target: %s (branch)') | 261 fm.plain(_(b'### target: %s (branch)') |
262 % '+'.join(st.branches), # XXX handle multi branches | 262 % b'+'.join(st.branches), # XXX handle multi branches |
263 label='stack.summary.branches') | 263 label=b'stack.summary.branches') |
264 if topic is None: | 264 if topic is None: |
265 if 1 < len(st.heads): | 265 if 1 < len(st.heads): |
266 fm.plain(' (') | 266 fm.plain(b' (') |
267 fm.plain('%d heads' % len(st.heads), | 267 fm.plain(b'%d heads' % len(st.heads), |
268 label='stack.summary.headcount.multiple') | 268 label=b'stack.summary.headcount.multiple') |
269 fm.plain(')') | 269 fm.plain(b')') |
270 else: | 270 else: |
271 if st.behindcount == -1: | 271 if st.behindcount == -1: |
272 fm.plain(', ') | 272 fm.plain(b', ') |
273 fm.plain('ambiguous rebase destination - %s' % st.behinderror, | 273 fm.plain(b'ambiguous rebase destination - %s' % st.behinderror, |
274 label='stack.summary.behinderror') | 274 label=b'stack.summary.behinderror') |
275 elif st.behindcount: | 275 elif st.behindcount: |
276 fm.plain(', ') | 276 fm.plain(b', ') |
277 fm.plain('%d behind' % st.behindcount, label='stack.summary.behindcount') | 277 fm.plain(b'%d behind' % st.behindcount, label=b'stack.summary.behindcount') |
278 fm.plain('\n') | 278 fm.plain(b'\n') |
279 | 279 |
280 if not st: | 280 if not st: |
281 fm.plain(_("(stack is empty)\n")) | 281 fm.plain(_(b"(stack is empty)\n")) |
282 | 282 |
283 st = stack(repo, branch=branch, topic=topic) | 283 st = stack(repo, branch=branch, topic=topic) |
284 for idx, r in enumerate(st, 0): | 284 for idx, r in enumerate(st, 0): |
285 ctx = repo[r] | 285 ctx = repo[r] |
286 # special case for t0, b0 as it's hard to plugin into rest of the logic | 286 # special case for t0, b0 as it's hard to plugin into rest of the logic |
316 for idx, isentry, ctx in entries[::-1]: | 316 for idx, isentry, ctx in entries[::-1]: |
317 | 317 |
318 symbol = None | 318 symbol = None |
319 states = [] | 319 states = [] |
320 if opts.get(b'children'): | 320 if opts.get(b'children'): |
321 expr = 'children(%d) and merge() - %ld' | 321 expr = b'children(%d) and merge() - %ld' |
322 revisions = repo.revs(expr, ctx.rev(), st._revs) | 322 revisions = repo.revs(expr, ctx.rev(), st._revs) |
323 if len(revisions) > 0: | 323 if len(revisions) > 0: |
324 states.append('external-children') | 324 states.append(b'external-children') |
325 | 325 |
326 if ctx.orphan(): | 326 if ctx.orphan(): |
327 symbol = '$' | 327 symbol = b'$' |
328 states.append('orphan') | 328 states.append(b'orphan') |
329 | 329 |
330 if ctx.contentdivergent(): | 330 if ctx.contentdivergent(): |
331 symbol = '$' | 331 symbol = b'$' |
332 states.append('content divergent') | 332 states.append(b'content divergent') |
333 | 333 |
334 if ctx.phasedivergent(): | 334 if ctx.phasedivergent(): |
335 symbol = '$' | 335 symbol = b'$' |
336 states.append('phase divergent') | 336 states.append(b'phase divergent') |
337 | 337 |
338 iscurrentrevision = repo.revs('%d and parents()', ctx.rev()) | 338 iscurrentrevision = repo.revs(b'%d and parents()', ctx.rev()) |
339 if iscurrentrevision: | 339 if iscurrentrevision: |
340 symbol = '@' | 340 symbol = b'@' |
341 states.append('current') | 341 states.append(b'current') |
342 | 342 |
343 if not isentry: | 343 if not isentry: |
344 symbol = '^' | 344 symbol = b'^' |
345 # "base" is kind of a "ghost" entry | 345 # "base" is kind of a "ghost" entry |
346 states.append('base') | 346 states.append(b'base') |
347 | 347 |
348 # none of the above if statments get executed | 348 # none of the above if statments get executed |
349 if not symbol: | 349 if not symbol: |
350 symbol = ':' | 350 symbol = b':' |
351 | 351 |
352 if not states: | 352 if not states: |
353 states.append('clean') | 353 states.append(b'clean') |
354 | 354 |
355 states.sort() | 355 states.sort() |
356 | 356 |
357 fm.startitem() | 357 fm.startitem() |
358 fm.context(ctx=ctx) | 358 fm.context(ctx=ctx) |
366 if ui.debugflag: | 366 if ui.debugflag: |
367 # parentheses plus full node hash | 367 # parentheses plus full node hash |
368 spacewidth = 2 + 40 | 368 spacewidth = 2 + 40 |
369 # s# alias width | 369 # s# alias width |
370 spacewidth += 2 | 370 spacewidth += 2 |
371 fm.plain(' ' * spacewidth) | 371 fm.plain(b' ' * spacewidth) |
372 else: | 372 else: |
373 fm.write('stack_index', '%s%%d' % prefix, idx, | 373 fm.write(b'stack_index', b'%s%%d' % prefix, idx, |
374 label=labelsgen('stack.index', states)) | 374 label=labelsgen(b'stack.index', states)) |
375 if ui.verbose: | 375 if ui.verbose: |
376 fm.write('node', '(%s)', fm.hexfunc(ctx.node()), | 376 fm.write(b'node', b'(%s)', fm.hexfunc(ctx.node()), |
377 label=labelsgen('stack.shortnode', states)) | 377 label=labelsgen(b'stack.shortnode', states)) |
378 else: | 378 else: |
379 fm.data(node=fm.hexfunc(ctx.node())) | 379 fm.data(node=fm.hexfunc(ctx.node())) |
380 fm.write('symbol', '%s', symbol, | 380 fm.write(b'symbol', b'%s', symbol, |
381 label=labelsgen('stack.state', states)) | 381 label=labelsgen(b'stack.state', states)) |
382 fm.plain(' ') | 382 fm.plain(b' ') |
383 fm.write('desc', '%s', ctx.description().splitlines()[0], | 383 fm.write(b'desc', b'%s', ctx.description().splitlines()[0], |
384 label=labelsgen('stack.desc', states)) | 384 label=labelsgen(b'stack.desc', states)) |
385 fm.condwrite(states != ['clean'] and idx is not None, 'state', | 385 fm.condwrite(states != [b'clean'] and idx is not None, b'state', |
386 ' (%s)', fm.formatlist(states, 'stack.state'), | 386 b' (%s)', fm.formatlist(states, b'stack.state'), |
387 label=labelsgen('stack.state', states)) | 387 label=labelsgen(b'stack.state', states)) |
388 fm.plain('\n') | 388 fm.plain(b'\n') |
389 fm.end() | 389 fm.end() |