[PATCH 2 of 8] py3: use r'' to prevent the addition of b'' by transformer

Pulkit Goyal 7895pulkit at gmail.com
Mon Jun 26 15:55:23 EDT 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1498502756 -19800
#      Tue Jun 27 00:15:56 2017 +0530
# Node ID bd2b8d7fb25b256e1e9fa03d43a7fb6712d3daa3
# Parent  9fa49669fdd13c7e15aec3bfc1039cf612f4ab52
py3: use r'' to prevent the addition of b'' by transformer

There are cases in opts handling in debugcommands.py where we don't need to
convert opts keys back to bytes as there are some handful cases and no other
function using opts value. Using r'', we prevent the transformer to add
a b'' which will keep the value str.

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -326,7 +326,7 @@
     if not isinstance(gen, bundle2.unbundle20):
         raise error.Abort(_('not a bundle2 file'))
     ui.write(('Stream params: %s\n' % repr(gen.params)))
-    parttypes = opts.get('part_type', [])
+    parttypes = opts.get(r'part_type', [])
     for part in gen.iterparts():
         if parttypes and part.type not in parttypes:
             continue
@@ -393,7 +393,7 @@
 def debugcolor(ui, repo, **opts):
     """show available color, effects or style"""
     ui.write(('color mode: %s\n') % ui._colormode)
-    if opts.get('style'):
+    if opts.get(r'style'):
         return _debugdisplaystyle(ui)
     else:
         return _debugdisplaycolor(ui)
@@ -461,8 +461,8 @@
 
     Otherwise, the changelog DAG of the current repo is emitted.
     """
-    spaces = opts.get('spaces')
-    dots = opts.get('dots')
+    spaces = opts.get(r'spaces')
+    dots = opts.get(r'dots')
     if file_:
         rlog = revlog.revlog(vfsmod.vfs(pycompat.getcwd(), audit=False),
                              file_)
@@ -475,8 +475,8 @@
                     yield 'l', (r, "r%i" % r)
     elif repo:
         cl = repo.changelog
-        tags = opts.get('tags')
-        branches = opts.get('branches')
+        tags = opts.get(r'tags')
+        branches = opts.get(r'branches')
         if tags:
             labels = {}
             for l, n in repo.tags().items():
@@ -531,7 +531,7 @@
     norepo=True, optionalrepo=True)
 def debugdate(ui, date, range=None, **opts):
     """parse and display a date"""
-    if opts["extended"]:
+    if opts[r"extended"]:
         d = util.parsedate(date, util.extendeddateformats)
     else:
         d = util.parsedate(date)
@@ -650,8 +650,8 @@
 def debugstate(ui, repo, **opts):
     """show the contents of the current dirstate"""
 
-    nodates = opts.get('nodates')
-    datesort = opts.get('datesort')
+    nodates = opts.get(r'nodates')
+    datesort = opts.get(r'datesort')
 
     timestr = ""
     if datesort:
@@ -792,7 +792,7 @@
     _('[-r REV] FILESPEC'))
 def debugfileset(ui, repo, expr, **opts):
     '''parse and apply a fileset specification'''
-    ctx = scmutil.revsingle(repo, opts.get('rev'), None)
+    ctx = scmutil.revsingle(repo, opts.get(r'rev'), None)
     if ui.verbose:
         tree = fileset.parse(expr)
         ui.note(fileset.prettyformat(tree), "\n")
@@ -833,11 +833,11 @@
         raise error.Abort("getbundle() not supported by target repository")
     args = {}
     if common:
-        args['common'] = [bin(s) for s in common]
+        args[r'common'] = [bin(s) for s in common]
     if head:
-        args['heads'] = [bin(s) for s in head]
+        args[r'heads'] = [bin(s) for s in head]
     # TODO: get desired bundlecaps from command line.
-    args['bundlecaps'] = None
+    args[r'bundlecaps'] = None
     bundle = repo.getbundle('debug', **args)
 
     bundletype = opts.get('type', 'bzip2').lower()
@@ -1176,11 +1176,11 @@
 
     """
 
-    if opts.get('force_lock'):
+    if opts.get(r'force_lock'):
         repo.svfs.unlink('lock')
-    if opts.get('force_wlock'):
+    if opts.get(r'force_wlock'):
         repo.vfs.unlink('wlock')
-    if opts.get('force_lock') or opts.get('force_lock'):
+    if opts.get(r'force_lock') or opts.get(r'force_lock'):
         return 0
 
     now = time.time()
@@ -1485,7 +1485,7 @@
         if fixpaths:
             spec = spec.replace(pycompat.ossep, '/')
         speclen = len(spec)
-        fullpaths = opts['full']
+        fullpaths = opts[r'full']
         files, dirs = set(), set()
         adddir, addfile = dirs.add, files.add
         for f, st in dirstate.iteritems():
@@ -1503,11 +1503,11 @@
         return files, dirs
 
     acceptable = ''
-    if opts['normal']:
+    if opts[r'normal']:
         acceptable += 'nm'
-    if opts['added']:
+    if opts[r'added']:
         acceptable += 'a'
-    if opts['removed']:
+    if opts[r'removed']:
         acceptable += 'r'
     cwd = repo.getcwd()
     if not specs:
@@ -1671,7 +1671,7 @@
         dirstate = repo.dirstate
         changedfiles = None
         # See command doc for what minimal does.
-        if opts.get('minimal'):
+        if opts.get(r'minimal'):
             manifestfiles = set(ctx.manifest().keys())
             dirstatefiles = set(dirstate)
             manifestonly = manifestfiles - dirstatefiles
@@ -2134,14 +2134,14 @@
     Use --verbose to print the parsed tree.
     """
     revs = None
-    if opts['rev']:
+    if opts[r'rev']:
         if repo is None:
             raise error.RepoError(_('there is no Mercurial repository here '
                                     '(.hg not found)'))
-        revs = scmutil.revrange(repo, opts['rev'])
+        revs = scmutil.revrange(repo, opts[r'rev'])
 
     props = {}
-    for d in opts['define']:
+    for d in opts[r'define']:
         try:
             k, v = (e.strip() for e in d.split('=', 1))
             if not k or k == 'ui':


More information about the Mercurial-devel mailing list