D1624: py3: handle keyword arguments correctly in hgext/largefiles/

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Sun Dec 10 01:08:18 UTC 2017


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Keys of keyword arguments must be str(unicode) on Python 3. The transformer
  which we use on Python 3, appends b'' in front of each string literal, so this
  may lead in KeyError or None return even when the key is present by we are using
  bytes value and it's stored in unicodes. This patch and all the similar patches
  handle this by either converting the keys of kwargs to bytes using
  'pycompat.byteskwargs()' or adding r'' so that the transformer won't append
  b''.
  
  This next 23 patches follows the above mentioned way to handle keyword
  arguments.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1624

AFFECTED FILES
  hgext/largefiles/lfcommands.py
  hgext/largefiles/overrides.py
  hgext/largefiles/proto.py

CHANGE DETAILS

diff --git a/hgext/largefiles/proto.py b/hgext/largefiles/proto.py
--- a/hgext/largefiles/proto.py
+++ b/hgext/largefiles/proto.py
@@ -176,14 +176,14 @@
     if cmd == 'heads' and self.capable('largefiles'):
         cmd = 'lheads'
     if cmd == 'batch' and self.capable('largefiles'):
-        args['cmds'] = args['cmds'].replace('heads ', 'lheads ')
+        args[r'cmds'] = args[r'cmds'].replace('heads ', 'lheads ')
     return ssholdcallstream(self, cmd, **args)
 
 headsre = re.compile(r'(^|;)heads\b')
 
 def httprepocallstream(self, cmd, **args):
     if cmd == 'heads' and self.capable('largefiles'):
         cmd = 'lheads'
     if cmd == 'batch' and self.capable('largefiles'):
-        args['cmds'] = headsre.sub('lheads', args['cmds'])
+        args[r'cmds'] = headsre.sub('lheads', args[r'cmds'])
     return httpoldcallstream(self, cmd, **args)
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -21,6 +21,7 @@
     hg,
     match as matchmod,
     pathutil,
+    pycompat,
     registrar,
     scmutil,
     smartset,
@@ -156,7 +157,7 @@
     # Need to lock, otherwise there could be a race condition between
     # when standins are created and added to the repo.
     with repo.wlock():
-        if not opts.get('dry_run'):
+        if not opts.get(r'dry_run'):
             standins = []
             lfdirstate = lfutil.openlfdirstate(ui, repo)
             for f in lfnames:
@@ -177,7 +178,7 @@
     return added, bad
 
 def removelargefiles(ui, repo, isaddremove, matcher, **opts):
-    after = opts.get('after')
+    after = opts.get(r'after')
     m = composelargefilematcher(matcher, repo[None].manifest())
     try:
         repo.lfstatus = True
@@ -221,11 +222,11 @@
                     name = m.rel(f)
                 ui.status(_('removing %s\n') % name)
 
-            if not opts.get('dry_run'):
+            if not opts.get(r'dry_run'):
                 if not after:
                     repo.wvfs.unlinkpath(f, ignoremissing=True)
 
-        if opts.get('dry_run'):
+        if opts.get(r'dry_run'):
             return result
 
         remove = [lfutil.standin(f) for f in remove]
@@ -252,7 +253,7 @@
 # -- Wrappers: modify existing commands --------------------------------
 
 def overrideadd(orig, ui, repo, *pats, **opts):
-    if opts.get('normal') and opts.get('large'):
+    if opts.get(r'normal') and opts.get(r'large'):
         raise error.Abort(_('--normal cannot be used with --large'))
     return orig(ui, repo, *pats, **opts)
 
@@ -403,17 +404,17 @@
         setattr(cmdutil, '_makenofollowlogfilematcher', oldmakelogfilematcher)
 
 def overrideverify(orig, ui, repo, *pats, **opts):
-    large = opts.pop('large', False)
-    all = opts.pop('lfa', False)
-    contents = opts.pop('lfc', False)
+    large = opts.pop(r'large', False)
+    all = opts.pop(r'lfa', False)
+    contents = opts.pop(r'lfc', False)
 
     result = orig(ui, repo, *pats, **opts)
     if large or all or contents:
         result = result or lfcommands.verifylfiles(ui, repo, all, contents)
     return result
 
 def overridedebugstate(orig, ui, repo, *pats, **opts):
-    large = opts.pop('large', False)
+    large = opts.pop(r'large', False)
     if large:
         class fakerepo(object):
             dirstate = lfutil.openlfdirstate(ui, repo)
@@ -802,8 +803,8 @@
     repo.lfpullsource = source
     result = orig(ui, repo, source, **opts)
     revspostpull = len(repo)
-    lfrevs = opts.get('lfrev', [])
-    if opts.get('all_largefiles'):
+    lfrevs = opts.get(r'lfrev', [])
+    if opts.get(r'all_largefiles'):
         lfrevs.append('pulled()')
     if lfrevs and revspostpull > revsprepull:
         numcached = 0
@@ -820,15 +821,15 @@
 
 def overridepush(orig, ui, repo, *args, **kwargs):
     """Override push command and store --lfrev parameters in opargs"""
-    lfrevs = kwargs.pop('lfrev', None)
+    lfrevs = kwargs.pop(r'lfrev', None)
     if lfrevs:
         opargs = kwargs.setdefault('opargs', {})
         opargs['lfrevs'] = scmutil.revrange(repo, lfrevs)
     return orig(ui, repo, *args, **kwargs)
 
 def exchangepushoperation(orig, *args, **kwargs):
     """Override pushoperation constructor and store lfrevs parameter"""
-    lfrevs = kwargs.pop('lfrevs', None)
+    lfrevs = kwargs.pop(r'lfrevs', None)
     pushop = orig(*args, **kwargs)
     pushop.lfrevs = lfrevs
     return pushop
@@ -865,7 +866,7 @@
     d = dest
     if d is None:
         d = hg.defaultdest(source)
-    if opts.get('all_largefiles') and not hg.islocal(d):
+    if opts.get(r'all_largefiles') and not hg.islocal(d):
             raise error.Abort(_(
             '--all-largefiles is incompatible with non-local destination %s') %
             d)
@@ -893,7 +894,7 @@
         # Caching is implicitly limited to 'rev' option, since the dest repo was
         # truncated at that point.  The user may expect a download count with
         # this option, so attempt whether or not this is a largefile repo.
-        if opts.get('all_largefiles'):
+        if opts.get(r'all_largefiles'):
             success, missing = lfcommands.downloadlfiles(ui, repo, None)
 
             if missing != 0:
@@ -913,7 +914,7 @@
     if not util.safehasattr(repo, '_largefilesenabled'):
         return orig(ui, repo, **opts)
 
-    resuming = opts.get('continue')
+    resuming = opts.get(r'continue')
     repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
     repo._lfstatuswriters.append(lambda *msg, **opts: None)
     try:
@@ -1272,6 +1273,7 @@
     repo.status = overridestatus
     orig(ui, repo, *dirs, **opts)
     repo.status = oldstatus
+
 def overriderollback(orig, ui, repo, **opts):
     with repo.wlock():
         before = repo.dirstate.parents()
@@ -1310,7 +1312,7 @@
     return result
 
 def overridetransplant(orig, ui, repo, *revs, **opts):
-    resuming = opts.get('continue')
+    resuming = opts.get(r'continue')
     repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
     repo._lfstatuswriters.append(lambda *msg, **opts: None)
     try:
@@ -1321,6 +1323,7 @@
     return result
 
 def overridecat(orig, ui, repo, file1, *pats, **opts):
+    opts = pycompat.byteskwargs(opts)
     ctx = scmutil.revsingle(repo, opts.get('rev'))
     err = 1
     notbad = set()
@@ -1382,7 +1385,7 @@
 
 def mergeupdate(orig, repo, node, branchmerge, force,
                 *args, **kwargs):
-    matcher = kwargs.get('matcher', None)
+    matcher = kwargs.get(r'matcher', None)
     # note if this is a partial update
     partial = matcher and not matcher.always()
     with repo.wlock():
@@ -1437,7 +1440,7 @@
         # Make sure the merge runs on disk, not in-memory. largefiles is not a
         # good candidate for in-memory merge (large files, custom dirstate,
         # matcher usage).
-        kwargs['wc'] = repo[None]
+        kwargs[r'wc'] = repo[None]
         result = orig(repo, node, branchmerge, force, *args, **kwargs)
 
         newstandins = lfutil.getstandinsstate(repo)
diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -24,6 +24,7 @@
     lock,
     match as matchmod,
     node,
+    pycompat,
     registrar,
     scmutil,
     util,
@@ -74,6 +75,7 @@
     Use --to-normal to convert largefiles back to normal files; after
     this, the DEST repository can be used without largefiles at all.'''
 
+    opts = pycompat.byteskwargs(opts)
     if opts['to_normal']:
         tolfile = False
     else:
@@ -579,7 +581,7 @@
     """
     repo.lfpullsource = source
 
-    revs = opts.get('rev', [])
+    revs = opts.get(r'rev', [])
     if not revs:
         raise error.Abort(_('no revisions specified'))
     revs = scmutil.revrange(repo, revs)



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list