changeset 40657:13d4ad8d7801

py3: fix keyword arguments handling in hgext/remotefilelog/ Keys of kwargs on Python 3 should be strings. This patch fixes them by appending r'' prefixes, and using pycompat.byteskwargs() and pycompat.strkwargs(). Differential Revision: https://phab.mercurial-scm.org/D5259
author Pulkit Goyal <pulkit@yandex-team.ru>
date Tue, 13 Nov 2018 17:41:26 +0300
parents ee9981bc8b44
children 5e3b3f88c2e4
files hgext/remotefilelog/__init__.py hgext/remotefilelog/basestore.py hgext/remotefilelog/contentstore.py hgext/remotefilelog/debugcommands.py hgext/remotefilelog/fileserverclient.py hgext/remotefilelog/metadatastore.py hgext/remotefilelog/remotefilectx.py hgext/remotefilelog/shallowbundle.py hgext/remotefilelog/shallowutil.py
diffstat 9 files changed, 42 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/remotefilelog/__init__.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/__init__.py	Tue Nov 13 17:41:26 2018 +0300
@@ -151,6 +151,7 @@
     merge,
     node as nodemod,
     patch,
+    pycompat,
     registrar,
     repair,
     repoview,
@@ -272,7 +273,7 @@
 
     # Prevent 'hg manifest --all'
     def _manifest(orig, ui, repo, *args, **opts):
-        if (isenabled(repo) and opts.get('all')):
+        if (isenabled(repo) and opts.get(r'all')):
             raise error.Abort(_("--all is not supported in a shallow repo"))
 
         return orig(ui, repo, *args, **opts)
@@ -294,7 +295,7 @@
     extensions.wrapcommand(commands.table, 'debugdata', debugdatashallow)
 
 def cloneshallow(orig, ui, repo, *args, **opts):
-    if opts.get('shallow'):
+    if opts.get(r'shallow'):
         repos = []
         def pull_shallow(orig, self, *args, **kwargs):
             if not isenabled(self):
@@ -327,9 +328,9 @@
                 if constants.NETWORK_CAP_LEGACY_SSH_GETFILES in caps:
                     opts = {}
                     if repo.includepattern:
-                        opts['includepattern'] = '\0'.join(repo.includepattern)
+                        opts[r'includepattern'] = '\0'.join(repo.includepattern)
                     if repo.excludepattern:
-                        opts['excludepattern'] = '\0'.join(repo.excludepattern)
+                        opts[r'excludepattern'] = '\0'.join(repo.excludepattern)
                     return remote._callstream('stream_out_shallow', **opts)
                 else:
                     return orig()
@@ -360,7 +361,7 @@
     try:
         orig(ui, repo, *args, **opts)
     finally:
-        if opts.get('shallow'):
+        if opts.get(r'shallow'):
             for r in repos:
                 if util.safehasattr(r, 'fileservice'):
                     r.fileservice.close()
@@ -888,19 +889,20 @@
     if not isenabled(repo):
         return orig(ui, repo, *pats, **opts)
 
-    follow = opts.get('follow')
-    revs = opts.get('rev')
+    follow = opts.get(r'follow')
+    revs = opts.get(r'rev')
     if pats:
         # Force slowpath for non-follow patterns and follows that start from
         # non-working-copy-parent revs.
         if not follow or revs:
             # This forces the slowpath
-            opts['removed'] = True
+            opts[r'removed'] = True
 
         # If this is a non-follow log without any revs specified, recommend that
         # the user add -f to speed it up.
         if not follow and not revs:
-            match, pats = scmutil.matchandpats(repo['.'], pats, opts)
+            match, pats = scmutil.matchandpats(repo['.'], pats,
+                                               pycompat.byteskwargs(opts))
             isfile = not match.anypats()
             if isfile:
                 for file in match.files():
@@ -1104,6 +1106,7 @@
 
     Return 0 on success.
     """
+    opts = pycompat.byteskwargs(opts)
     if not isenabled(repo):
         raise error.Abort(_("repo is not shallow"))
 
@@ -1121,15 +1124,15 @@
      ('', 'packsonly', None, _('only repack packs (skip loose objects)'), None),
     ], _('hg repack [OPTIONS]'))
 def repack_(ui, repo, *pats, **opts):
-    if opts.get('background'):
-        repackmod.backgroundrepack(repo, incremental=opts.get('incremental'),
-                                   packsonly=opts.get('packsonly', False))
+    if opts.get(r'background'):
+        repackmod.backgroundrepack(repo, incremental=opts.get(r'incremental'),
+                                   packsonly=opts.get(r'packsonly', False))
         return
 
-    options = {'packsonly': opts.get('packsonly')}
+    options = {'packsonly': opts.get(r'packsonly')}
 
     try:
-        if opts.get('incremental'):
+        if opts.get(r'incremental'):
             repackmod.incrementalrepack(repo, options=options)
         else:
             repackmod.fullrepack(repo, options=options)
--- a/hgext/remotefilelog/basestore.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/basestore.py	Tue Nov 13 17:41:26 2018 +0300
@@ -392,10 +392,10 @@
         # throw a KeyError, try this many times with a full refresh between
         # attempts. A repack operation may have moved data from one store to
         # another while we were running.
-        self.numattempts = kwargs.get('numretries', 0) + 1
+        self.numattempts = kwargs.get(r'numretries', 0) + 1
         # If not-None, call this function on every retry and if the attempts are
         # exhausted.
-        self.retrylog = kwargs.get('retrylog', None)
+        self.retrylog = kwargs.get(r'retrylog', None)
 
     def markforrefresh(self):
         for store in self.stores:
--- a/hgext/remotefilelog/contentstore.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/contentstore.py	Tue Nov 13 17:41:26 2018 +0300
@@ -36,12 +36,12 @@
         super(unioncontentstore, self).__init__(*args, **kwargs)
 
         self.stores = args
-        self.writestore = kwargs.get('writestore')
+        self.writestore = kwargs.get(r'writestore')
 
         # If allowincomplete==True then the union store can return partial
         # delta chains, otherwise it will throw a KeyError if a full
         # deltachain can't be found.
-        self.allowincomplete = kwargs.get('allowincomplete', False)
+        self.allowincomplete = kwargs.get(r'allowincomplete', False)
 
     def get(self, name, node):
         """Fetches the full text revision contents of the given name+node pair.
--- a/hgext/remotefilelog/debugcommands.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/debugcommands.py	Tue Nov 13 17:41:26 2018 +0300
@@ -28,7 +28,7 @@
 )
 
 def debugremotefilelog(ui, path, **opts):
-    decompress = opts.get('decompress')
+    decompress = opts.get(r'decompress')
 
     size, firstnode, mapping = parsefileblob(path, decompress)
 
@@ -89,9 +89,9 @@
 
 def debugindex(orig, ui, repo, file_=None, **opts):
     """dump the contents of an index file"""
-    if (opts.get('changelog') or
-        opts.get('manifest') or
-        opts.get('dir') or
+    if (opts.get(r'changelog') or
+        opts.get(r'manifest') or
+        opts.get(r'dir') or
         not shallowutil.isenabled(repo) or
         not repo.shallowmatch(file_)):
         return orig(ui, repo, file_, **opts)
@@ -154,7 +154,7 @@
     ui.write("}\n")
 
 def verifyremotefilelog(ui, path, **opts):
-    decompress = opts.get('decompress')
+    decompress = opts.get(r'decompress')
 
     for root, dirs, files in os.walk(path):
         for file in files:
@@ -213,13 +213,13 @@
             path = path[:path.index('.data')]
         ui.write("%s:\n" % path)
         dpack = datapack.datapack(path)
-        node = opts.get('node')
+        node = opts.get(r'node')
         if node:
             deltachain = dpack.getdeltachain('', bin(node))
             dumpdeltachain(ui, deltachain, **opts)
             return
 
-        if opts.get('long'):
+        if opts.get(r'long'):
             hashformatter = hex
             hashlen = 42
         else:
--- a/hgext/remotefilelog/fileserverclient.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/fileserverclient.py	Tue Nov 13 17:41:26 2018 +0300
@@ -18,6 +18,7 @@
 from mercurial.node import bin, hex, nullid
 from mercurial import (
     error,
+    pycompat,
     revlog,
     sshpeer,
     util,
@@ -119,7 +120,7 @@
         def _callstream(self, command, **opts):
             supertype = super(remotefilepeer, self)
             if not util.safehasattr(supertype, '_sendrequest'):
-                self._updatecallstreamopts(command, opts)
+                self._updatecallstreamopts(command, pycompat.byteskwargs(opts))
             return super(remotefilepeer, self)._callstream(command, **opts)
 
     peer.__class__ = remotefilepeer
--- a/hgext/remotefilelog/metadatastore.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/metadatastore.py	Tue Nov 13 17:41:26 2018 +0300
@@ -11,12 +11,12 @@
         super(unionmetadatastore, self).__init__(*args, **kwargs)
 
         self.stores = args
-        self.writestore = kwargs.get('writestore')
+        self.writestore = kwargs.get(r'writestore')
 
         # If allowincomplete==True then the union store can return partial
         # ancestor lists, otherwise it will throw a KeyError if a full
         # history can't be found.
-        self.allowincomplete = kwargs.get('allowincomplete', False)
+        self.allowincomplete = kwargs.get(r'allowincomplete', False)
 
     def getancestors(self, name, node, known=None):
         """Returns as many ancestors as we're aware of.
--- a/hgext/remotefilelog/remotefilectx.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/remotefilectx.py	Tue Nov 13 17:41:26 2018 +0300
@@ -15,6 +15,7 @@
     context,
     error,
     phases,
+    pycompat,
     util,
 )
 from . import shallowutil
@@ -218,11 +219,11 @@
             return linknode
 
         commonlogkwargs = {
-            'revs': ' '.join([hex(cl.node(rev)) for rev in revs]),
-            'fnode': hex(fnode),
-            'filepath': path,
-            'user': shallowutil.getusername(repo.ui),
-            'reponame': shallowutil.getreponame(repo.ui),
+            r'revs': ' '.join([hex(cl.node(rev)) for rev in revs]),
+            r'fnode': hex(fnode),
+            r'filepath': path,
+            r'user': shallowutil.getusername(repo.ui),
+            r'reponame': shallowutil.getreponame(repo.ui),
         }
 
         repo.ui.log('linkrevfixup', 'adjusting linknode', **commonlogkwargs)
@@ -315,7 +316,7 @@
         finally:
             elapsed = time.time() - start
             repo.ui.log('linkrevfixup', logmsg, elapsed=elapsed * 1000,
-                        **commonlogkwargs)
+                        **pycompat.strkwargs(commonlogkwargs))
 
     def _verifylinknode(self, revs, linknode):
         """
@@ -408,7 +409,7 @@
 
     def annotate(self, *args, **kwargs):
         introctx = self
-        prefetchskip = kwargs.pop('prefetchskip', None)
+        prefetchskip = kwargs.pop(r'prefetchskip', None)
         if prefetchskip:
             # use introrev so prefetchskip can be accurately tested
             introrev = self.introrev()
--- a/hgext/remotefilelog/shallowbundle.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/shallowbundle.py	Tue Nov 13 17:41:26 2018 +0300
@@ -146,7 +146,7 @@
     try:
         # if serving, only send files the clients has patterns for
         if source == 'serve':
-            bundlecaps = kwargs.get('bundlecaps')
+            bundlecaps = kwargs.get(r'bundlecaps')
             includepattern = None
             excludepattern = None
             for cap in (bundlecaps or []):
--- a/hgext/remotefilelog/shallowutil.py	Sat Oct 13 05:09:18 2018 +0300
+++ b/hgext/remotefilelog/shallowutil.py	Tue Nov 13 17:41:26 2018 +0300
@@ -105,7 +105,7 @@
 def reportpackmetrics(ui, prefix, *stores):
     dicts = [s.getmetrics() for s in stores]
     dict = prefixkeys(sumdicts(*dicts), prefix + '_')
-    ui.log(prefix + "_packsizes", "", **dict)
+    ui.log(prefix + "_packsizes", "", **pycompat.strkwargs(dict))
 
 def _parsepackmeta(metabuf):
     """parse datapack meta, bytes (<metadata-list>) -> dict