diff 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
line wrap: on
line diff
--- a/hgext3rd/topic/flow.py	Tue Aug 06 15:06:27 2019 +0200
+++ b/hgext3rd/topic/flow.py	Tue Aug 06 15:06:38 2019 +0200
@@ -16,19 +16,19 @@
 )
 
 def enforcesinglehead(repo, tr):
-    branchmap = repo.filtered('visible').branchmap()
+    branchmap = repo.filtered(b'visible').branchmap()
     for name, heads in compat.branchmapitems(branchmap):
         if len(heads) > 1:
             hexs = [node.short(n) for n in heads]
-            raise error.Abort(_('%d heads on "%s"') % (len(heads), name),
-                              hint=(', '.join(hexs)))
+            raise error.Abort(_(b'%d heads on "%s"') % (len(heads), name),
+                              hint=(b', '.join(hexs)))
 
 def publishbarebranch(repo, tr):
     """Publish changeset without topic"""
-    if 'node' not in tr.hookargs: # no new node
+    if b'node' not in tr.hookargs: # no new node
         return
-    startnode = node.bin(tr.hookargs['node'])
-    topublish = repo.revs('not public() and (%n:) - hidden() - topic()', startnode)
+    startnode = node.bin(tr.hookargs[b'node'])
+    topublish = repo.revs(b'not public() and (%n:) - hidden() - topic()', startnode)
     if topublish:
         cl = repo.changelog
         nodes = [cl.node(r) for r in topublish]
@@ -36,41 +36,41 @@
 
 def rejectuntopicedchangeset(repo, tr):
     """Reject the push if there are changeset without topic"""
-    if 'node' not in tr.hookargs: # no new revs
+    if b'node' not in tr.hookargs: # no new revs
         return
 
-    startnode = node.bin(tr.hookargs['node'])
+    startnode = node.bin(tr.hookargs[b'node'])
 
-    mode = repo.ui.config('experimental', 'topic-mode.server', 'ignore')
+    mode = repo.ui.config(b'experimental', b'topic-mode.server', b'ignore')
 
-    untopiced = repo.revs('not public() and (%n:) - hidden() - topic()', startnode)
+    untopiced = repo.revs(b'not public() and (%n:) - hidden() - topic()', startnode)
     if untopiced:
         num = len(untopiced)
         fnode = repo[untopiced.first()].hex()[:10]
         if num == 1:
-            msg = _("%s") % fnode
+            msg = _(b"%s") % fnode
         else:
-            msg = _("%s and %d more") % (fnode, num - 1)
-        if mode == 'warning':
-            fullmsg = _("pushed draft changeset without topic: %s\n")
+            msg = _(b"%s and %d more") % (fnode, num - 1)
+        if mode == b'warning':
+            fullmsg = _(b"pushed draft changeset without topic: %s\n")
             repo.ui.warn(fullmsg % msg)
-        elif mode == 'enforce':
-            fullmsg = _("rejecting draft changesets: %s")
+        elif mode == b'enforce':
+            fullmsg = _(b"rejecting draft changesets: %s")
             raise error.Abort(fullmsg % msg)
         else:
-            repo.ui.warn(_("unknown 'topic-mode.server': %s\n" % mode))
+            repo.ui.warn(_(b"unknown 'topic-mode.server': %s\n" % mode))
 
 def reject_publish(repo, tr):
     """prevent a transaction to be publish anything"""
     published = set()
-    for r, (o, n) in tr.changes['phases'].items():
+    for r, (o, n) in tr.changes[b'phases'].items():
         if n == phases.public:
             published.add(r)
     if published:
         r = min(published)
-        msg = "rejecting publishing of changeset %s" % repo[r]
+        msg = b"rejecting publishing of changeset %s" % repo[r]
         if len(published) > 1:
-            msg += ' and %d others' % (len(published) - 1)
+            msg += b' and %d others' % (len(published) - 1)
         raise error.Abort(msg)
 
 def wrappush(orig, repo, remote, *args, **kwargs):
@@ -81,7 +81,7 @@
         if opargs is None:
             opargs = {}
         newargs[r'opargs'] = opargs.copy()
-        newargs[r'opargs']['publish'] = True
+        newargs[r'opargs'][b'publish'] = True
     return orig(repo, remote, *args, **newargs)
 
 def extendpushoperation(orig, self, *args, **kwargs):
@@ -95,16 +95,16 @@
         if not pushop.remotephases.publishing:
             unfi = pushop.repo.unfiltered()
             droots = pushop.remotephases.draftroots
-            revset = '%ln and (not public() or %ln::)'
+            revset = b'%ln and (not public() or %ln::)'
             future = list(unfi.set(revset, pushop.futureheads, droots))
             pushop.outdatedphases = future
 
 def installpushflag(ui):
-    entry = extensions.wrapcommand(commands.table, 'push', wrappush)
-    if not any(opt for opt in entry[1] if opt[1] == 'publish'): # hg <= 4.9
-        entry[1].append(('', 'publish', False,
-                         _('push the changeset as public')))
+    entry = extensions.wrapcommand(commands.table, b'push', wrappush)
+    if not any(opt for opt in entry[1] if opt[1] == b'publish'): # hg <= 4.9
+        entry[1].append((b'', b'publish', False,
+                         _(b'push the changeset as public')))
     extensions.wrapfunction(exchange.pushoperation, '__init__',
                             extendpushoperation)
     extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery)
-    exchange.pushdiscoverymapping['phase'] = exchange._pushdiscoveryphase
+    exchange.pushdiscoverymapping[b'phase'] = exchange._pushdiscoveryphase