changeset 35944:fc44c2657dc5

py3: drop b'' from repr() of smartset cmdutil._maybebytestr() is moved to pycompat.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 27 Jan 2018 17:46:37 +0900
parents 1a31111e6239
children 887bbce7f491
files mercurial/cmdutil.py mercurial/pycompat.py mercurial/revset.py mercurial/smartset.py
diffstat 4 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sat Jan 27 17:31:25 2018 +0900
+++ b/mercurial/cmdutil.py	Sat Jan 27 17:46:37 2018 +0900
@@ -1563,11 +1563,6 @@
         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
 
@@ -1586,7 +1581,7 @@
     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')
 
--- a/mercurial/pycompat.py	Sat Jan 27 17:31:25 2018 +0900
+++ b/mercurial/pycompat.py	Sat Jan 27 17:46:37 2018 +0900
@@ -161,6 +161,12 @@
         """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
 
@@ -267,6 +273,7 @@
     bytechr = chr
     bytestr = str
     iterbytestr = iter
+    maybebytestr = identity
     sysbytes = identity
     sysstr = identity
     strurl = identity
--- a/mercurial/revset.py	Sat Jan 27 17:31:25 2018 +0900
+++ b/mercurial/revset.py	Sat Jan 27 17:46:37 2018 +0900
@@ -105,6 +105,9 @@
                 pass
     return None
 
+def _sortedb(xs):
+    return sorted(util.rapply(pycompat.maybebytestr, xs))
+
 # operator methods
 
 def stringset(repo, subset, x, order):
@@ -507,7 +510,7 @@
         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):
@@ -760,7 +763,7 @@
             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):
--- a/mercurial/smartset.py	Sat Jan 27 17:31:25 2018 +0900
+++ b/mercurial/smartset.py	Sat Jan 27 17:46:37 2018 +0900
@@ -29,7 +29,7 @@
     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):