# HG changeset patch # User Yuya Nishihara # Date 1517042797 -32400 # Node ID fc44c2657dc54b680583242916608c858026df19 # Parent 1a31111e6239a2eb841a5dce5e1cf8212c54bf33 py3: drop b'' from repr() of smartset cmdutil._maybebytestr() is moved to pycompat. diff -r 1a31111e6239 -r fc44c2657dc5 mercurial/cmdutil.py --- 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') diff -r 1a31111e6239 -r fc44c2657dc5 mercurial/pycompat.py --- 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 diff -r 1a31111e6239 -r fc44c2657dc5 mercurial/revset.py --- 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: '' % sorted(b)) + condrepr=lambda: '' % _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: '' % sorted(dests)) + condrepr=lambda: '' % _sortedb(dests)) @predicate('contentdivergent()', safe=True) def contentdivergent(repo, subset, x): diff -r 1a31111e6239 -r fc44c2657dc5 mercurial/smartset.py --- 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):