py3: drop b'' from repr() of smartset
authorYuya Nishihara <yuya@tcha.org>
Sat, 27 Jan 2018 17:46:37 +0900
changeset 42016 fc44c2657dc54b680583242916608c858026df19
parent 42015 1a31111e6239a2eb841a5dce5e1cf8212c54bf33
child 42017 887bbce7f491afc07c5cdd87f87823047b9e5897
push id667
push usergszorc@mozilla.com
push dateSun, 04 Feb 2018 23:07:21 +0000
py3: drop b'' from repr() of smartset cmdutil._maybebytestr() is moved to pycompat.
mercurial/cmdutil.py
mercurial/pycompat.py
mercurial/revset.py
mercurial/smartset.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1558,21 +1558,16 @@ def export(repo, revs, fntemplate='hg-%h
                 fo.write(s)
         if not dest.startswith('<'):
             repo.ui.note("%s\n" % dest)
         _exportsingle(
             repo, ctx, match, switch_parent, rev, seqno, write, opts)
         if fo is not None:
             fo.close()
 
-def _maybebytestr(v):
-    if isinstance(v, bytes):
-        return pycompat.bytestr(v)
-    return v
-
 def showmarker(fm, marker, index=None):
     """utility function to display obsolescence marker in a readable way
 
     To be used by debug function."""
     if index is not None:
         fm.write('index', '%i ', index)
     fm.write('prednode', '%s ', hex(marker.prednode()))
     succs = marker.succnodes()
@@ -1581,17 +1576,17 @@ def showmarker(fm, marker, index=None):
     fm.write('flag', '%X ', marker.flags())
     parents = marker.parentnodes()
     if parents is not None:
         fm.write('parentnodes', '{%s} ',
                  fm.formatlist(map(hex, parents), name='node', sep=', '))
     fm.write('date', '(%s) ', fm.formatdate(marker.date()))
     meta = marker.metadata().copy()
     meta.pop('date', None)
-    smeta = util.rapply(_maybebytestr, meta)
+    smeta = util.rapply(pycompat.maybebytestr, meta)
     fm.write('metadata', '{%s}', fm.formatdict(smeta, fmt='%r: %r', sep=', '))
     fm.plain('\n')
 
 def finddate(ui, repo, date):
     """Find the tipmost changeset that matches the given date spec"""
 
     df = util.matchdate(date)
     m = scmutil.matchall(repo)
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -156,16 +156,22 @@ if ispy3:
 
         def __repr__(self):
             return bytes.__repr__(self)[1:]  # drop b''
 
     def iterbytestr(s):
         """Iterate bytes as if it were a str object of Python 2"""
         return map(bytechr, s)
 
+    def maybebytestr(s):
+        """Promote bytes to bytestr"""
+        if isinstance(s, bytes):
+            return bytestr(s)
+        return s
+
     def sysbytes(s):
         """Convert an internal str (e.g. keyword, __doc__) back to bytes
 
         This never raises UnicodeEncodeError, but only ASCII characters
         can be round-trip by sysstr(sysbytes(s)).
         """
         return s.encode(u'utf-8')
 
@@ -262,16 +268,17 @@ if ispy3:
         return [a.encode('latin-1') for a in ret]
 
 else:
     import cStringIO
 
     bytechr = chr
     bytestr = str
     iterbytestr = iter
+    maybebytestr = identity
     sysbytes = identity
     sysstr = identity
     strurl = identity
     bytesurl = identity
 
     # this can't be parsed on Python 3
     exec('def raisewithtb(exc, tb):\n'
          '    raise exc, None, tb\n')
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -100,16 +100,19 @@ def _getrevsource(repo, r):
     for label in ('source', 'transplant_source', 'rebase_source'):
         if label in extra:
             try:
                 return repo[extra[label]].rev()
             except error.RepoLookupError:
                 pass
     return None
 
+def _sortedb(xs):
+    return sorted(util.rapply(pycompat.maybebytestr, xs))
+
 # operator methods
 
 def stringset(repo, subset, x, order):
     x = scmutil.intrev(repo[x])
     if (x in subset
         or x == node.nullrev and isinstance(subset, fullreposet)):
         return baseset([x])
     return baseset()
@@ -502,17 +505,17 @@ def branch(repo, subset, x):
                                  condrepr=('<branch %r>', b))
 
     s = getset(repo, fullreposet(repo), x)
     b = set()
     for r in s:
         b.add(getbranch(r))
     c = s.__contains__
     return subset.filter(lambda r: c(r) or getbranch(r) in b,
-                         condrepr=lambda: '<branch %r>' % sorted(b))
+                         condrepr=lambda: '<branch %r>' % _sortedb(b))
 
 @predicate('phasedivergent()', safe=True)
 def phasedivergent(repo, subset, x):
     """Mutable changesets marked as successors of public changesets.
 
     Only non-public and non-obsolete changesets can be `phasedivergent`.
     (EXPERIMENTAL)
     """
@@ -755,17 +758,17 @@ def destination(repo, subset, x):
             if src in sources or src in dests:
                 dests.update(lineage)
                 break
 
             r = src
             src = _getrevsource(repo, r)
 
     return subset.filter(dests.__contains__,
-                         condrepr=lambda: '<destination %r>' % sorted(dests))
+                         condrepr=lambda: '<destination %r>' % _sortedb(dests))
 
 @predicate('contentdivergent()', safe=True)
 def contentdivergent(repo, subset, x):
     """
     Final successors of changesets with an alternative set of final
     successors. (EXPERIMENTAL)
     """
     # i18n: "contentdivergent" is a keyword
--- a/mercurial/smartset.py
+++ b/mercurial/smartset.py
@@ -24,17 +24,17 @@ def _formatsetrepr(r):
     bytes     '<branch closed>'
     callable  lambda: '<branch %r>' % sorted(b)
     object    other
     ========  =================================
     """
     if r is None:
         return ''
     elif isinstance(r, tuple):
-        return r[0] % r[1:]
+        return r[0] % util.rapply(pycompat.maybebytestr, r[1:])
     elif isinstance(r, bytes):
         return r
     elif callable(r):
         return r()
     else:
         return pycompat.sysbytes(repr(r))
 
 def _typename(o):