comparison hgext3rd/topic/flow.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 14c12df16ab5
children a4d081923c81 af9f40236037
comparison
equal deleted inserted replaced
4812:67567d7f1174 4814:48b30ff742cb
14 from . import ( 14 from . import (
15 compat, 15 compat,
16 ) 16 )
17 17
18 def enforcesinglehead(repo, tr): 18 def enforcesinglehead(repo, tr):
19 branchmap = repo.filtered('visible').branchmap() 19 branchmap = repo.filtered(b'visible').branchmap()
20 for name, heads in compat.branchmapitems(branchmap): 20 for name, heads in compat.branchmapitems(branchmap):
21 if len(heads) > 1: 21 if len(heads) > 1:
22 hexs = [node.short(n) for n in heads] 22 hexs = [node.short(n) for n in heads]
23 raise error.Abort(_('%d heads on "%s"') % (len(heads), name), 23 raise error.Abort(_(b'%d heads on "%s"') % (len(heads), name),
24 hint=(', '.join(hexs))) 24 hint=(b', '.join(hexs)))
25 25
26 def publishbarebranch(repo, tr): 26 def publishbarebranch(repo, tr):
27 """Publish changeset without topic""" 27 """Publish changeset without topic"""
28 if 'node' not in tr.hookargs: # no new node 28 if b'node' not in tr.hookargs: # no new node
29 return 29 return
30 startnode = node.bin(tr.hookargs['node']) 30 startnode = node.bin(tr.hookargs[b'node'])
31 topublish = repo.revs('not public() and (%n:) - hidden() - topic()', startnode) 31 topublish = repo.revs(b'not public() and (%n:) - hidden() - topic()', startnode)
32 if topublish: 32 if topublish:
33 cl = repo.changelog 33 cl = repo.changelog
34 nodes = [cl.node(r) for r in topublish] 34 nodes = [cl.node(r) for r in topublish]
35 repo._phasecache.advanceboundary(repo, tr, phases.public, nodes) 35 repo._phasecache.advanceboundary(repo, tr, phases.public, nodes)
36 36
37 def rejectuntopicedchangeset(repo, tr): 37 def rejectuntopicedchangeset(repo, tr):
38 """Reject the push if there are changeset without topic""" 38 """Reject the push if there are changeset without topic"""
39 if 'node' not in tr.hookargs: # no new revs 39 if b'node' not in tr.hookargs: # no new revs
40 return 40 return
41 41
42 startnode = node.bin(tr.hookargs['node']) 42 startnode = node.bin(tr.hookargs[b'node'])
43 43
44 mode = repo.ui.config('experimental', 'topic-mode.server', 'ignore') 44 mode = repo.ui.config(b'experimental', b'topic-mode.server', b'ignore')
45 45
46 untopiced = repo.revs('not public() and (%n:) - hidden() - topic()', startnode) 46 untopiced = repo.revs(b'not public() and (%n:) - hidden() - topic()', startnode)
47 if untopiced: 47 if untopiced:
48 num = len(untopiced) 48 num = len(untopiced)
49 fnode = repo[untopiced.first()].hex()[:10] 49 fnode = repo[untopiced.first()].hex()[:10]
50 if num == 1: 50 if num == 1:
51 msg = _("%s") % fnode 51 msg = _(b"%s") % fnode
52 else: 52 else:
53 msg = _("%s and %d more") % (fnode, num - 1) 53 msg = _(b"%s and %d more") % (fnode, num - 1)
54 if mode == 'warning': 54 if mode == b'warning':
55 fullmsg = _("pushed draft changeset without topic: %s\n") 55 fullmsg = _(b"pushed draft changeset without topic: %s\n")
56 repo.ui.warn(fullmsg % msg) 56 repo.ui.warn(fullmsg % msg)
57 elif mode == 'enforce': 57 elif mode == b'enforce':
58 fullmsg = _("rejecting draft changesets: %s") 58 fullmsg = _(b"rejecting draft changesets: %s")
59 raise error.Abort(fullmsg % msg) 59 raise error.Abort(fullmsg % msg)
60 else: 60 else:
61 repo.ui.warn(_("unknown 'topic-mode.server': %s\n" % mode)) 61 repo.ui.warn(_(b"unknown 'topic-mode.server': %s\n" % mode))
62 62
63 def reject_publish(repo, tr): 63 def reject_publish(repo, tr):
64 """prevent a transaction to be publish anything""" 64 """prevent a transaction to be publish anything"""
65 published = set() 65 published = set()
66 for r, (o, n) in tr.changes['phases'].items(): 66 for r, (o, n) in tr.changes[b'phases'].items():
67 if n == phases.public: 67 if n == phases.public:
68 published.add(r) 68 published.add(r)
69 if published: 69 if published:
70 r = min(published) 70 r = min(published)
71 msg = "rejecting publishing of changeset %s" % repo[r] 71 msg = b"rejecting publishing of changeset %s" % repo[r]
72 if len(published) > 1: 72 if len(published) > 1:
73 msg += ' and %d others' % (len(published) - 1) 73 msg += b' and %d others' % (len(published) - 1)
74 raise error.Abort(msg) 74 raise error.Abort(msg)
75 75
76 def wrappush(orig, repo, remote, *args, **kwargs): 76 def wrappush(orig, repo, remote, *args, **kwargs):
77 """interpret the --publish flag and pass it to the push operation""" 77 """interpret the --publish flag and pass it to the push operation"""
78 newargs = kwargs.copy() 78 newargs = kwargs.copy()
79 if kwargs.pop('publish', False): 79 if kwargs.pop('publish', False):
80 opargs = kwargs.get('opargs') 80 opargs = kwargs.get('opargs')
81 if opargs is None: 81 if opargs is None:
82 opargs = {} 82 opargs = {}
83 newargs[r'opargs'] = opargs.copy() 83 newargs[r'opargs'] = opargs.copy()
84 newargs[r'opargs']['publish'] = True 84 newargs[r'opargs'][b'publish'] = True
85 return orig(repo, remote, *args, **newargs) 85 return orig(repo, remote, *args, **newargs)
86 86
87 def extendpushoperation(orig, self, *args, **kwargs): 87 def extendpushoperation(orig, self, *args, **kwargs):
88 publish = kwargs.pop('publish', False) 88 publish = kwargs.pop('publish', False)
89 orig(self, *args, **kwargs) 89 orig(self, *args, **kwargs)
93 orig(pushop) 93 orig(pushop)
94 if getattr(pushop, 'publish', False): 94 if getattr(pushop, 'publish', False):
95 if not pushop.remotephases.publishing: 95 if not pushop.remotephases.publishing:
96 unfi = pushop.repo.unfiltered() 96 unfi = pushop.repo.unfiltered()
97 droots = pushop.remotephases.draftroots 97 droots = pushop.remotephases.draftroots
98 revset = '%ln and (not public() or %ln::)' 98 revset = b'%ln and (not public() or %ln::)'
99 future = list(unfi.set(revset, pushop.futureheads, droots)) 99 future = list(unfi.set(revset, pushop.futureheads, droots))
100 pushop.outdatedphases = future 100 pushop.outdatedphases = future
101 101
102 def installpushflag(ui): 102 def installpushflag(ui):
103 entry = extensions.wrapcommand(commands.table, 'push', wrappush) 103 entry = extensions.wrapcommand(commands.table, b'push', wrappush)
104 if not any(opt for opt in entry[1] if opt[1] == 'publish'): # hg <= 4.9 104 if not any(opt for opt in entry[1] if opt[1] == b'publish'): # hg <= 4.9
105 entry[1].append(('', 'publish', False, 105 entry[1].append((b'', b'publish', False,
106 _('push the changeset as public'))) 106 _(b'push the changeset as public')))
107 extensions.wrapfunction(exchange.pushoperation, '__init__', 107 extensions.wrapfunction(exchange.pushoperation, '__init__',
108 extendpushoperation) 108 extendpushoperation)
109 extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery) 109 extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery)
110 exchange.pushdiscoverymapping['phase'] = exchange._pushdiscoveryphase 110 exchange.pushdiscoverymapping[b'phase'] = exchange._pushdiscoveryphase