Patchwork [1,of,5] py3: factor out byterepr() which returns an asciified value on py3

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 17, 2018, 10:07 a.m.
Message ID <d5e06baf9e6bc6705fb4.1518862056@mimosa>
Download mbox | patch
Permalink /patch/28021/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 17, 2018, 10:07 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1518858596 -32400
#      Sat Feb 17 18:09:56 2018 +0900
# Node ID d5e06baf9e6bc6705fb4c7e7ab1926bca0a2bae3
# Parent  c57892ccbb414bb79784dcbaba3ff958ca8915f0
py3: factor out byterepr() which returns an asciified value on py3

Patch

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)