hgext/remotenames.py
changeset 43077 687b865b95ad
parent 43076 2372284d9457
child 43105 649d3ac37a12
--- a/hgext/remotenames.py	Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/remotenames.py	Sun Oct 06 09:48:39 2019 -0400
@@ -58,7 +58,7 @@
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
 # leave the attribute unspecified.
-testedwith = 'ships-with-hg-core'
+testedwith = b'ships-with-hg-core'
 
 configtable = {}
 configitem = registrar.configitem(configtable)
@@ -66,13 +66,13 @@
 revsetpredicate = registrar.revsetpredicate()
 
 configitem(
-    'remotenames', 'bookmarks', default=True,
+    b'remotenames', b'bookmarks', default=True,
 )
 configitem(
-    'remotenames', 'branches', default=True,
+    b'remotenames', b'branches', default=True,
 )
 configitem(
-    'remotenames', 'hoistedpeer', default='default',
+    b'remotenames', b'hoistedpeer', default=b'default',
 )
 
 
@@ -102,7 +102,7 @@
         for node, rpath, rname in logexchange.readremotenamefile(
             repo, self._kind
         ):
-            name = rpath + '/' + rname
+            name = rpath + b'/' + rname
             self.potentialentries[name] = (node, rpath, name)
 
     def _resolvedata(self, potentialentry):
@@ -118,7 +118,7 @@
         except LookupError:
             return None
         # Skip closed branches
-        if self._kind == 'branches' and repo[binnode].closesbranch():
+        if self._kind == b'branches' and repo[binnode].closesbranch():
             return None
         return [binnode]
 
@@ -185,8 +185,8 @@
 
     def clearnames(self):
         """ Clear all remote names state """
-        self.bookmarks = lazyremotenamedict("bookmarks", self._repo)
-        self.branches = lazyremotenamedict("branches", self._repo)
+        self.bookmarks = lazyremotenamedict(b"bookmarks", self._repo)
+        self.branches = lazyremotenamedict(b"branches", self._repo)
         self._invalidatecache()
 
     def _invalidatecache(self):
@@ -222,7 +222,7 @@
         if not self._hoisttonodes:
             marktonodes = self.bmarktonodes()
             self._hoisttonodes = {}
-            hoist += '/'
+            hoist += b'/'
             for name, node in marktonodes.iteritems():
                 if name.startswith(hoist):
                     name = name[len(hoist) :]
@@ -233,7 +233,7 @@
         if not self._nodetohoists:
             marktonodes = self.bmarktonodes()
             self._nodetohoists = {}
-            hoist += '/'
+            hoist += b'/'
             for name, node in marktonodes.iteritems():
                 if name.startswith(hoist):
                     name = name[len(hoist) :]
@@ -242,9 +242,9 @@
 
 
 def wrapprintbookmarks(orig, ui, repo, fm, bmarks):
-    if 'remotebookmarks' not in repo.names:
+    if b'remotebookmarks' not in repo.names:
         return
-    ns = repo.names['remotebookmarks']
+    ns = repo.names[b'remotebookmarks']
 
     for name in ns.listnames(repo):
         nodes = ns.nodes(repo, name)
@@ -252,19 +252,19 @@
             continue
         node = nodes[0]
 
-        bmarks[name] = (node, ' ', '')
+        bmarks[name] = (node, b' ', b'')
 
     return orig(ui, repo, fm, bmarks)
 
 
 def extsetup(ui):
-    extensions.wrapfunction(bookmarks, '_printbookmarks', wrapprintbookmarks)
+    extensions.wrapfunction(bookmarks, b'_printbookmarks', wrapprintbookmarks)
 
 
 def reposetup(ui, repo):
 
     # set the config option to store remotenames
-    repo.ui.setconfig('experimental', 'remotenames', True, 'remotenames-ext')
+    repo.ui.setconfig(b'experimental', b'remotenames', True, b'remotenames-ext')
 
     if not repo.local():
         return
@@ -272,12 +272,12 @@
     repo._remotenames = remotenames(repo)
     ns = namespaces.namespace
 
-    if ui.configbool('remotenames', 'bookmarks'):
+    if ui.configbool(b'remotenames', b'bookmarks'):
         remotebookmarkns = ns(
-            'remotebookmarks',
-            templatename='remotebookmarks',
-            colorname='remotebookmark',
-            logfmt='remote bookmark:  %s\n',
+            b'remotebookmarks',
+            templatename=b'remotebookmarks',
+            colorname=b'remotebookmark',
+            logfmt=b'remote bookmark:  %s\n',
             listnames=lambda repo: repo._remotenames.bmarktonodes().keys(),
             namemap=lambda repo, name: repo._remotenames.bmarktonodes().get(
                 name, []
@@ -289,13 +289,13 @@
         repo.names.addnamespace(remotebookmarkns)
 
         # hoisting only works if there are remote bookmarks
-        hoist = ui.config('remotenames', 'hoistedpeer')
+        hoist = ui.config(b'remotenames', b'hoistedpeer')
         if hoist:
             hoistednamens = ns(
-                'hoistednames',
-                templatename='hoistednames',
-                colorname='hoistedname',
-                logfmt='hoisted name:  %s\n',
+                b'hoistednames',
+                templatename=b'hoistednames',
+                colorname=b'hoistedname',
+                logfmt=b'hoisted name:  %s\n',
                 listnames=lambda repo: repo._remotenames.hoisttonodes(
                     hoist
                 ).keys(),
@@ -308,12 +308,12 @@
             )
             repo.names.addnamespace(hoistednamens)
 
-    if ui.configbool('remotenames', 'branches'):
+    if ui.configbool(b'remotenames', b'branches'):
         remotebranchns = ns(
-            'remotebranches',
-            templatename='remotebranches',
-            colorname='remotebranch',
-            logfmt='remote branch:  %s\n',
+            b'remotebranches',
+            templatename=b'remotebranches',
+            colorname=b'remotebranch',
+            logfmt=b'remote branch:  %s\n',
             listnames=lambda repo: repo._remotenames.branchtonodes().keys(),
             namemap=lambda repo, name: repo._remotenames.branchtonodes().get(
                 name, []
@@ -325,68 +325,68 @@
         repo.names.addnamespace(remotebranchns)
 
 
-@templatekeyword('remotenames', requires={'repo', 'ctx'})
+@templatekeyword(b'remotenames', requires={b'repo', b'ctx'})
 def remotenameskw(context, mapping):
     """List of strings. Remote names associated with the changeset."""
-    repo = context.resource(mapping, 'repo')
-    ctx = context.resource(mapping, 'ctx')
+    repo = context.resource(mapping, b'repo')
+    ctx = context.resource(mapping, b'ctx')
 
     remotenames = []
-    if 'remotebookmarks' in repo.names:
-        remotenames = repo.names['remotebookmarks'].names(repo, ctx.node())
+    if b'remotebookmarks' in repo.names:
+        remotenames = repo.names[b'remotebookmarks'].names(repo, ctx.node())
 
-    if 'remotebranches' in repo.names:
-        remotenames += repo.names['remotebranches'].names(repo, ctx.node())
+    if b'remotebranches' in repo.names:
+        remotenames += repo.names[b'remotebranches'].names(repo, ctx.node())
 
     return templateutil.compatlist(
-        context, mapping, 'remotename', remotenames, plural='remotenames'
+        context, mapping, b'remotename', remotenames, plural=b'remotenames'
     )
 
 
-@templatekeyword('remotebookmarks', requires={'repo', 'ctx'})
+@templatekeyword(b'remotebookmarks', requires={b'repo', b'ctx'})
 def remotebookmarkskw(context, mapping):
     """List of strings. Remote bookmarks associated with the changeset."""
-    repo = context.resource(mapping, 'repo')
-    ctx = context.resource(mapping, 'ctx')
+    repo = context.resource(mapping, b'repo')
+    ctx = context.resource(mapping, b'ctx')
 
     remotebmarks = []
-    if 'remotebookmarks' in repo.names:
-        remotebmarks = repo.names['remotebookmarks'].names(repo, ctx.node())
+    if b'remotebookmarks' in repo.names:
+        remotebmarks = repo.names[b'remotebookmarks'].names(repo, ctx.node())
 
     return templateutil.compatlist(
         context,
         mapping,
-        'remotebookmark',
+        b'remotebookmark',
         remotebmarks,
-        plural='remotebookmarks',
+        plural=b'remotebookmarks',
     )
 
 
-@templatekeyword('remotebranches', requires={'repo', 'ctx'})
+@templatekeyword(b'remotebranches', requires={b'repo', b'ctx'})
 def remotebrancheskw(context, mapping):
     """List of strings. Remote branches associated with the changeset."""
-    repo = context.resource(mapping, 'repo')
-    ctx = context.resource(mapping, 'ctx')
+    repo = context.resource(mapping, b'repo')
+    ctx = context.resource(mapping, b'ctx')
 
     remotebranches = []
-    if 'remotebranches' in repo.names:
-        remotebranches = repo.names['remotebranches'].names(repo, ctx.node())
+    if b'remotebranches' in repo.names:
+        remotebranches = repo.names[b'remotebranches'].names(repo, ctx.node())
 
     return templateutil.compatlist(
         context,
         mapping,
-        'remotebranch',
+        b'remotebranch',
         remotebranches,
-        plural='remotebranches',
+        plural=b'remotebranches',
     )
 
 
 def _revsetutil(repo, subset, x, rtypes):
     """utility function to return a set of revs based on the rtypes"""
-    args = revsetlang.getargs(x, 0, 1, _('only one argument accepted'))
+    args = revsetlang.getargs(x, 0, 1, _(b'only one argument accepted'))
     if args:
         kind, pattern, matcher = stringutil.stringmatcher(
-            revsetlang.getstring(args[0], _('argument must be a string'))
+            revsetlang.getstring(args[0], _(b'argument must be a string'))
         )
     else:
         kind = pattern = None
@@ -401,40 +401,40 @@
                 if not matcher(name):
                     continue
                 nodes.update(ns.nodes(repo, name))
-    if kind == 'literal' and not nodes:
+    if kind == b'literal' and not nodes:
         raise error.RepoLookupError(
-            _("remote name '%s' does not exist") % pattern
+            _(b"remote name '%s' does not exist") % pattern
         )
 
     revs = (cl.rev(n) for n in nodes if cl.hasnode(n))
     return subset & smartset.baseset(revs)
 
 
-@revsetpredicate('remotenames([name])')
+@revsetpredicate(b'remotenames([name])')
 def remotenamesrevset(repo, subset, x):
     """All changesets which have a remotename on them. If `name` is
     specified, only remotenames of matching remote paths are considered.
 
     Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
     """
-    return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches'))
+    return _revsetutil(repo, subset, x, (b'remotebookmarks', b'remotebranches'))
 
 
-@revsetpredicate('remotebranches([name])')
+@revsetpredicate(b'remotebranches([name])')
 def remotebranchesrevset(repo, subset, x):
     """All changesets which are branch heads on remotes. If `name` is
     specified, only remotenames of matching remote paths are considered.
 
     Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
     """
-    return _revsetutil(repo, subset, x, ('remotebranches',))
+    return _revsetutil(repo, subset, x, (b'remotebranches',))
 
 
-@revsetpredicate('remotebookmarks([name])')
+@revsetpredicate(b'remotebookmarks([name])')
 def remotebmarksrevset(repo, subset, x):
     """All changesets which have bookmarks on remotes. If `name` is
     specified, only remotenames of matching remote paths are considered.
 
     Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
     """
-    return _revsetutil(repo, subset, x, ('remotebookmarks',))
+    return _revsetutil(repo, subset, x, (b'remotebookmarks',))