Patchwork [1,of,8] py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes

login
register
mail settings
Submitter Pulkit Goyal
Date June 26, 2017, 7:55 p.m.
Message ID <9fa49669fdd13c7e15ae.1498506922@workspace>
Download mbox | patch
Permalink /patch/21742/
State Accepted
Headers show

Comments

Pulkit Goyal - June 26, 2017, 7:55 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1498503055 -19800
#      Tue Jun 27 00:20:55 2017 +0530
# Node ID 9fa49669fdd13c7e15aec3bfc1039cf612f4ab52
# Parent  bb46f1aba2c07467171472188efa8ce43ef081c9
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes

This is used where ever required like where kwargs are passed into
ui.formatter(), scmutil.match() or cmdutil.openrevlog() which expects bytes.
Yuya Nishihara - June 27, 2017, 1:05 p.m.
On Tue, 27 Jun 2017 01:25:22 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1498503055 -19800
> #      Tue Jun 27 00:20:55 2017 +0530
> # Node ID 9fa49669fdd13c7e15aec3bfc1039cf612f4ab52
> # Parent  bb46f1aba2c07467171472188efa8ce43ef081c9
> py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes

Queued, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1332,6 +1332,7 @@ 
             self.ui.write(self.footer)
 
     def show(self, ctx, copies=None, matchfn=None, **props):
+        props = pycompat.byteskwargs(props)
         if self.buffered:
             self.ui.pushbuffer(labeled=True)
             self._show(ctx, copies, matchfn, props)
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -291,6 +291,7 @@ 
 
 def _debugobsmarkers(ui, part, indent=0, **opts):
     """display version and markers contained in 'data'"""
+    opts = pycompat.byteskwargs(opts)
     data = part.read()
     indent_string = ' ' * indent
     try:
@@ -511,6 +512,7 @@ 
 @command('debugdata', cmdutil.debugrevlogopts, _('-c|-m|FILE REV'))
 def debugdata(ui, repo, file_, rev=None, **opts):
     """dump the contents of a data file revision"""
+    opts = pycompat.byteskwargs(opts)
     if opts.get('changelog') or opts.get('manifest') or opts.get('dir'):
         if rev is not None:
             raise error.CommandError('debugdata', _('invalid arguments'))
@@ -567,6 +569,7 @@ 
     :``extraratio``: extradist divided by chainsize; another representation of
                     how much unrelated data is needed to load this delta chain
     """
+    opts = pycompat.byteskwargs(opts)
     r = cmdutil.openrevlog(repo, 'debugdeltachain', file_, opts)
     index = r.index
     generaldelta = r.version & revlog.FLAG_GENERALDELTA
@@ -679,6 +682,7 @@ 
     _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]'))
 def debugdiscovery(ui, repo, remoteurl="default", **opts):
     """runs the changeset discovery protocol in isolation"""
+    opts = pycompat.byteskwargs(opts)
     remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl),
                                       opts.get('branch'))
     remote = hg.peer(repo, opts, remoteurl)
@@ -740,6 +744,7 @@ 
 @command('debugextensions', cmdutil.formatteropts, [], norepo=True)
 def debugextensions(ui, **opts):
     '''show information about active extensions'''
+    opts = pycompat.byteskwargs(opts)
     exts = extensions.extensions(ui)
     hgver = util.version()
     fm = ui.formatter('debugextensions', opts)
@@ -822,6 +827,7 @@ 
     Every ID must be a full-length hex node id string. Saves the bundle to the
     given file.
     """
+    opts = pycompat.byteskwargs(opts)
     repo = hg.peer(ui, opts, repopath)
     if not repo.capable('getbundle'):
         raise error.Abort("getbundle() not supported by target repository")
@@ -891,6 +897,7 @@ 
     optionalrepo=True)
 def debugindex(ui, repo, file_=None, **opts):
     """dump the contents of an index file"""
+    opts = pycompat.byteskwargs(opts)
     r = cmdutil.openrevlog(repo, 'debugindex', file_, opts)
     format = opts.get('format', 0)
     if format not in (0, 1):
@@ -945,6 +952,7 @@ 
     _('-c|-m|FILE'), optionalrepo=True)
 def debugindexdot(ui, repo, file_=None, **opts):
     """dump an index DAG as a graphviz dot file"""
+    opts = pycompat.byteskwargs(opts)
     r = cmdutil.openrevlog(repo, 'debugindexdot', file_, opts)
     ui.write(("digraph G {\n"))
     for i in r:
@@ -961,6 +969,7 @@ 
 
     Returns 0 on success.
     '''
+    opts = pycompat.byteskwargs(opts)
 
     def writetemp(contents):
         (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
@@ -1129,6 +1138,7 @@ 
     Every ID must be a full-length hex node id string. Returns a list of 0s
     and 1s indicating unknown/known.
     """
+    opts = pycompat.byteskwargs(opts)
     repo = hg.peer(ui, opts, repopath)
     if not repo.capable('known'):
         raise error.Abort("known() not supported by target repository")
@@ -1347,6 +1357,8 @@ 
 
     With no arguments, displays the list of obsolescence markers."""
 
+    opts = pycompat.byteskwargs(opts)
+
     def parsenodeid(s):
         try:
             # We do not use revsingle/revrange functions here to accept
@@ -1558,6 +1570,7 @@ 
     information, even with --debug. In such case, information above is
     useful to know why a merge tool is chosen.
     """
+    opts = pycompat.byteskwargs(opts)
     overrides = {}
     if opts['tool']:
         overrides[('ui', 'forcemerge')] = opts['tool']
@@ -1679,6 +1692,7 @@ 
 def debugrename(ui, repo, file1, *pats, **opts):
     """dump rename information"""
 
+    opts = pycompat.byteskwargs(opts)
     ctx = scmutil.revsingle(repo, opts.get('rev'))
     m = scmutil.match(ctx, (file1,) + pats, opts)
     for abs in ctx.walk(m):
@@ -1696,6 +1710,7 @@ 
     optionalrepo=True)
 def debugrevlog(ui, repo, file_=None, **opts):
     """show data and statistics about a revlog"""
+    opts = pycompat.byteskwargs(opts)
     r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts)
 
     if opts.get("dump"):
@@ -1943,6 +1958,7 @@ 
     Use --verify-optimized to compare the optimized result with the unoptimized
     one. Returns 1 if the optimized result differs.
     """
+    opts = pycompat.byteskwargs(opts)
     stages = [
         ('parsed', lambda tree: tree),
         ('expanded', lambda tree: revsetlang.expandaliases(ui, tree)),
@@ -2188,6 +2204,7 @@ 
          inferrepo=True)
 def debugwalk(ui, repo, *pats, **opts):
     """show how files match on given patterns"""
+    opts = pycompat.byteskwargs(opts)
     m = scmutil.match(repo[None], pats, opts)
     ui.write(('matcher: %r\n' % m))
     items = list(repo[None].walk(m))
@@ -2211,6 +2228,7 @@ 
     _('REPO [OPTIONS]... [ONE [TWO]]'),
     norepo=True)
 def debugwireargs(ui, repopath, *vals, **opts):
+    opts = pycompat.byteskwargs(opts)
     repo = hg.peer(ui, opts, repopath)
     for opt in cmdutil.remoteopts:
         del opts[opt[1]]
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -12,6 +12,7 @@ 
 from .i18n import _
 from . import (
     error,
+    pycompat,
     util,
     wireproto,
 )
@@ -259,6 +260,7 @@ 
         yield wireproto.unescapearg(work)
 
     def _callstream(self, cmd, **args):
+        args = pycompat.byteskwargs(args)
         self.ui.debug("sending %s command\n" % cmd)
         self.pipeo.write("%s\n" % cmd)
         _func, names = wireproto.commands[cmd]