stringutil: flip the default of pprint() to bprefix=False
authorYuya Nishihara <yuya@tcha.org>
Thu, 10 May 2018 21:08:32 +0900
changeset 37986 32bc3815efae
parent 37985 af83a0ed0afb
child 37987 45a669bad421
stringutil: flip the default of pprint() to bprefix=False If we use pprint() as a drop-in replacement for repr(), bprefix=False is more appropriate. Let's make it the default to remove bprefix=False noise.
hgext/lfs/pointer.py
mercurial/debugcommands.py
mercurial/hook.py
mercurial/scmutil.py
mercurial/utils/stringutil.py
tests/test-hgweb-auth.py
tests/test-minirst.py
tests/test-ui-color.py
tests/test-ui-config.py
tests/test-wireproto.py
--- a/hgext/lfs/pointer.py	Thu May 10 21:00:58 2018 +0900
+++ b/hgext/lfs/pointer.py	Thu May 10 21:08:32 2018 +0900
@@ -35,9 +35,8 @@
         try:
             return cls(l.split(' ', 1) for l in text.splitlines()).validate()
         except ValueError: # l.split returns 1 item instead of 2
-            raise InvalidPointer(
-                _('cannot parse git-lfs text: %s') % stringutil.pprint(
-                    text, bprefix=False))
+            raise InvalidPointer(_('cannot parse git-lfs text: %s')
+                                 % stringutil.pprint(text))
 
     def serialize(self):
         sortkeyfunc = lambda x: (x[0] != 'version', x)
@@ -66,14 +65,14 @@
         for k, v in self.iteritems():
             if k in self._requiredre:
                 if not self._requiredre[k].match(v):
-                    raise InvalidPointer(_('unexpected value: %s=%s') % (
-                        k, stringutil.pprint(v, bprefix=False)))
+                    raise InvalidPointer(_('unexpected value: %s=%s')
+                                         % (k, stringutil.pprint(v)))
                 requiredcount += 1
             elif not self._keyre.match(k):
                 raise InvalidPointer(_('unexpected key: %s') % k)
             if not self._valuere.match(v):
-                raise InvalidPointer(_('unexpected value: %s=%s') % (
-                    k, stringutil.pprint(v, bprefix=False)))
+                raise InvalidPointer(_('unexpected value: %s=%s')
+                                     % (k, stringutil.pprint(v)))
         if len(self._requiredre) != requiredcount:
             miss = sorted(set(self._requiredre.keys()).difference(self.keys()))
             raise InvalidPointer(_('missed keys: %s') % ', '.join(miss))
--- a/mercurial/debugcommands.py	Thu May 10 21:00:58 2018 +0900
+++ b/mercurial/debugcommands.py	Thu May 10 21:08:32 2018 +0900
@@ -3017,10 +3017,12 @@
 
                 if isinstance(res, wireprotov2peer.commandresponse):
                     val = list(res.cborobjects())
-                    ui.status(_('response: %s\n') % stringutil.pprint(val))
+                    ui.status(_('response: %s\n') %
+                              stringutil.pprint(val, bprefix=True))
 
                 else:
-                    ui.status(_('response: %s\n') % stringutil.pprint(res))
+                    ui.status(_('response: %s\n') %
+                              stringutil.pprint(res, bprefix=True))
 
         elif action == 'batchbegin':
             if batchedcommands is not None:
@@ -3092,7 +3094,8 @@
                 continue
 
             if res.headers.get('Content-Type') == 'application/mercurial-cbor':
-                ui.write(_('cbor> %s\n') % stringutil.pprint(cbor.loads(body)))
+                ui.write(_('cbor> %s\n') %
+                         stringutil.pprint(cbor.loads(body), bprefix=True))
 
         elif action == 'close':
             peer.close()
--- a/mercurial/hook.py	Thu May 10 21:00:58 2018 +0900
+++ b/mercurial/hook.py	Thu May 10 21:08:32 2018 +0900
@@ -138,7 +138,7 @@
         if callable(v):
             v = v()
         if isinstance(v, (dict, list)):
-            v = stringutil.pprint(v, bprefix=False)
+            v = stringutil.pprint(v)
         env['HG_' + k.upper()] = v
 
     if repo:
--- a/mercurial/scmutil.py	Thu May 10 21:00:58 2018 +0900
+++ b/mercurial/scmutil.py	Thu May 10 21:08:32 2018 +0900
@@ -106,8 +106,7 @@
     def __repr__(self, *args, **kwargs):
         return ((r'<status modified=%s, added=%s, removed=%s, deleted=%s, '
                  r'unknown=%s, ignored=%s, clean=%s>') %
-                tuple(pycompat.sysstr(stringutil.pprint(
-                    v, bprefix=False)) for v in self))
+                tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self))
 
 def itersubrepos(ctx1, ctx2):
     """find subrepos in ctx1 or ctx2"""
--- a/mercurial/utils/stringutil.py	Thu May 10 21:00:58 2018 +0900
+++ b/mercurial/utils/stringutil.py	Thu May 10 21:08:32 2018 +0900
@@ -23,7 +23,7 @@
     pycompat,
 )
 
-def pprint(o, bprefix=True):
+def pprint(o, bprefix=False):
     """Pretty print an object."""
     if isinstance(o, bytes):
         if bprefix:
--- a/tests/test-hgweb-auth.py	Thu May 10 21:00:58 2018 +0900
+++ b/tests/test-hgweb-auth.py	Thu May 10 21:08:32 2018 +0900
@@ -28,7 +28,7 @@
     return ui
 
 def test(auth, urls=None):
-    print('CFG:', pycompat.sysstr(stringutil.pprint(auth)))
+    print('CFG:', pycompat.sysstr(stringutil.pprint(auth, bprefix=True)))
     prefixes = set()
     for k in auth:
         prefixes.add(k.split('.', 1)[0])
--- a/tests/test-minirst.py	Thu May 10 21:00:58 2018 +0900
+++ b/tests/test-minirst.py	Thu May 10 21:08:32 2018 +0900
@@ -18,7 +18,7 @@
     if type(out) == tuple:
         print(out[0][:-1].decode('utf8'))
         print("-" * 70)
-        print(stringutil.pprint(out[1], bprefix=False).decode('utf8'))
+        print(stringutil.pprint(out[1]).decode('utf8'))
     else:
         print(out[:-1].decode('utf8'))
     print("-" * 70)
--- a/tests/test-ui-color.py	Thu May 10 21:00:58 2018 +0900
+++ b/tests/test-ui-color.py	Thu May 10 21:08:32 2018 +0900
@@ -15,7 +15,7 @@
 testui.write((b'buffered\n'))
 testui.warn((b'warning\n'))
 testui.write_err(b'error\n')
-print(stringutil.pprint(testui.popbuffer()).decode('ascii'))
+print(stringutil.pprint(testui.popbuffer(), bprefix=True).decode('ascii'))
 
 # test dispatch.dispatch with the same ui object
 hgrc = open(os.environ["HGRCPATH"], 'wb')
--- a/tests/test-ui-config.py	Thu May 10 21:00:58 2018 +0900
+++ b/tests/test-ui-config.py	Thu May 10 21:08:32 2018 +0900
@@ -51,7 +51,7 @@
     ])
 
 def pprint(obj):
-    return stringutil.pprint(obj, bprefix=False).decode('ascii')
+    return stringutil.pprint(obj).decode('ascii')
 
 print(pprint(testui.configitems(b'values')))
 print(pprint(testui.configitems(b'lists')))
--- a/tests/test-wireproto.py	Thu May 10 21:00:58 2018 +0900
+++ b/tests/test-wireproto.py	Thu May 10 21:08:32 2018 +0900
@@ -108,4 +108,5 @@
     fgreet1 = e.callcommand(b'greet', {b'name': b'Fo, =;:<o'})
     fgreet2 = e.callcommand(b'greet', {b'name': b'Bar'})
 
-printb(stringutil.pprint([f.result() for f in (fgreet1, fgreet2)]))
+printb(stringutil.pprint([f.result() for f in (fgreet1, fgreet2)],
+                         bprefix=True))