# HG changeset patch # User Yuya Nishihara # Date 2018-02-17 09:09:56 # Node ID b44fac3a49fbfcb53c562edc352bc46258bd5bb4 # Parent 18e29c65bc5c1bf42529286c871b4a14c4fff0bf py3: factor out byterepr() which returns an asciified value on py3 diff --git a/mercurial/formatter.py b/mercurial/formatter.py --- a/mercurial/formatter.py +++ b/mercurial/formatter.py @@ -291,7 +291,7 @@ class debugformatter(baseformatter): self._out = out self._out.write("%s = [\n" % self._topic) def _showitem(self): - self._out.write(' %s,\n' % pycompat.sysbytes(repr(self._item))) + self._out.write(' %s,\n' % pycompat.byterepr(self._item)) def end(self): baseformatter.end(self) self._out.write("]\n") diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -85,6 +85,7 @@ if ispy3: sysargv = list(map(os.fsencode, sys.argv)) bytechr = struct.Struct('>B').pack + byterepr = b'%r'.__mod__ class bytestr(bytes): """A bytes which mostly acts as a Python 2 str @@ -277,6 +278,7 @@ else: import cStringIO bytechr = chr + byterepr = repr bytestr = str iterbytestr = iter maybebytestr = identity diff --git a/mercurial/smartset.py b/mercurial/smartset.py --- a/mercurial/smartset.py +++ b/mercurial/smartset.py @@ -35,7 +35,7 @@ def _formatsetrepr(r): elif callable(r): return r() else: - return pycompat.sysbytes(repr(r)) + return pycompat.byterepr(r) def _typename(o): return pycompat.sysbytes(type(o).__name__).lstrip('_') @@ -400,7 +400,7 @@ class baseset(abstractsmartset): # We fallback to the sorted version for a stable output. if self._ascending is not None: l = self._asclist - s = pycompat.sysbytes(repr(l)) + s = pycompat.byterepr(l) return '<%s%s %s>' % (_typename(self), d, s) class filteredset(abstractsmartset): @@ -513,7 +513,7 @@ class filteredset(abstractsmartset): @encoding.strmethod def __repr__(self): - xs = [pycompat.sysbytes(repr(self._subset))] + xs = [pycompat.byterepr(self._subset)] s = _formatsetrepr(self._condrepr) if s: xs.append(s) @@ -1132,7 +1132,7 @@ class fullreposet(_spanset): def prettyformat(revs): lines = [] - rs = pycompat.sysbytes(repr(revs)) + rs = pycompat.byterepr(revs) p = 0 while p < len(rs): q = rs.find('<', p + 1)