Patchwork [4,of,6] py3: avoid using %r format on bytes

login
register
mail settings
Submitter Manuel Jacob
Date June 16, 2020, 12:49 p.m.
Message ID <a35a5c188094fec13155.1592311766@tmp>
Download mbox | patch
Permalink /patch/46518/
State Accepted
Headers show

Comments

Manuel Jacob - June 16, 2020, 12:49 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1592310730 -7200
#      Tue Jun 16 14:32:10 2020 +0200
# Branch stable
# Node ID a35a5c188094fec13155a44a8e2c659847af337c
# Parent  81301372ba9b5cc430888241bb03106459b6a280
# EXP-Topic convert-svn
py3: avoid using %r format on bytes

Before the patch, the 'b' prefix appeared in the formatted string. Wrapping the
bytes as pycompat.bytestr solves this problem.

Eventually, I think that we should move away from using %r (like 975e517451a6
and 4d6019c0e0ef did), but that would change output of non-ASCII bytes on
Python 2, so we can’t do it on the stable branch. Also, many places continue to
use %r, so it would be a good idea to do the change all at once.

Patch

diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -535,7 +535,9 @@ 
                         % (name, path)
                     )
                 return None
-            self.ui.note(_(b'found %s at %r\n') % (name, path))
+            self.ui.note(
+                _(b'found %s at %r\n') % (name, pycompat.bytestr(path))
+            )
             return path
 
         rev = optrev(self.last_changed)
@@ -1208,7 +1210,10 @@ 
                 return relative
 
         # The path is outside our tracked tree...
-        self.ui.debug(b'%r is not under %r, ignoring\n' % (path, module))
+        self.ui.debug(
+            b'%r is not under %r, ignoring\n'
+            % (pycompat.bytestr(path), pycompat.bytestr(module))
+        )
         return None
 
     def _checkpath(self, path, revnum, module=None):