[PATCH 8 of 9] py3: drop b'' from repr() of smartset
Yuya Nishihara
yuya at tcha.org
Sat Feb 3 03:36:19 EST 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1517042797 -32400
# Sat Jan 27 17:46:37 2018 +0900
# Node ID c1752bc1026f6388a83793b2fcf2eb6cddae53e1
# Parent d6dc55d17ec2df28f544701cb97dce4a7641a1ed
py3: drop b'' from repr() of smartset
cmdutil._maybebytestr() is moved to pycompat.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1563,11 +1563,6 @@ def export(repo, revs, fntemplate='hg-%h
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 @@ def showmarker(fm, marker, index=None):
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')
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -161,6 +161,12 @@ if ispy3:
"""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 @@ else:
bytechr = chr
bytestr = str
iterbytestr = iter
+ maybebytestr = identity
sysbytes = identity
sysstr = identity
strurl = identity
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -105,6 +105,9 @@ def _getrevsource(repo, r):
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 @@ def branch(repo, subset, x):
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('bumped()', safe=True)
def bumped(repo, subset, x):
@@ -768,7 +771,7 @@ def destination(repo, subset, x):
src = _getrevsource(repo, r)
return subset.filter(dests.__contains__,
- condrepr=lambda: '<destination %r>' % sorted(dests))
+ condrepr=lambda: '<destination %r>' % _sortedb(dests))
@predicate('divergent()', safe=True)
def divergent(repo, subset, x):
diff --git a/mercurial/smartset.py b/mercurial/smartset.py
--- a/mercurial/smartset.py
+++ b/mercurial/smartset.py
@@ -29,7 +29,7 @@ def _formatsetrepr(r):
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):
More information about the Mercurial-devel
mailing list