Patchwork [2,of,2] stringutil: flip the default of pprint() to bprefix=False

login
register
mail settings
Submitter Yuya Nishihara
Date May 10, 2018, 2:10 p.m.
Message ID <1943cc2fad78346bac40.1525961446@mimosa>
Download mbox | patch
Permalink /patch/31457/
State Accepted
Headers show

Comments

Yuya Nishihara - May 10, 2018, 2:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1525954112 -32400
#      Thu May 10 21:08:32 2018 +0900
# Node ID 1943cc2fad78346bac406fa390fe2634e426338c
# Parent  ac6531a127cbc6f4bb2479b7f7805ee70dd45af5
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.

Patch

diff --git a/hgext/lfs/pointer.py b/hgext/lfs/pointer.py
--- a/hgext/lfs/pointer.py
+++ b/hgext/lfs/pointer.py
@@ -35,9 +35,8 @@  class gitlfspointer(dict):
         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 @@  class gitlfspointer(dict):
         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))
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -3017,10 +3017,12 @@  def debugwireproto(ui, repo, path=None, 
 
                 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 @@  def debugwireproto(ui, repo, path=None, 
                 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()
diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -138,7 +138,7 @@  def _exthook(ui, repo, htype, name, cmd,
         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:
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -106,8 +106,7 @@  class status(tuple):
     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"""
diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py
--- a/mercurial/utils/stringutil.py
+++ b/mercurial/utils/stringutil.py
@@ -23,7 +23,7 @@  from .. import (
     pycompat,
 )
 
-def pprint(o, bprefix=True):
+def pprint(o, bprefix=False):
     """Pretty print an object."""
     if isinstance(o, bytes):
         if bprefix:
diff --git a/tests/test-minirst.py b/tests/test-minirst.py
--- a/tests/test-minirst.py
+++ b/tests/test-minirst.py
@@ -18,7 +18,7 @@  def debugformat(text, form, **kwargs):
     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)
diff --git a/tests/test-ui-color.py b/tests/test-ui-color.py
--- a/tests/test-ui-color.py
+++ b/tests/test-ui-color.py
@@ -15,7 +15,7 @@  testui.pushbuffer()
 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')
diff --git a/tests/test-wireproto.py b/tests/test-wireproto.py
--- a/tests/test-wireproto.py
+++ b/tests/test-wireproto.py
@@ -108,4 +108,5 @@  with clt.commandexecutor() as e:
     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))