[PATCH 1 of 6] bundle2: stop using %r to quote part names

Augie Fackler raf at durin42.com
Tue Sep 19 16:08:24 UTC 2017


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1505756143 14400
#      Mon Sep 18 13:35:43 2017 -0400
# Node ID d3ecff8a8e1e49438fb7027adb12b678f394ff11
# Parent  a254c669b47549ba9056a1a3180a918c4a4eae80
bundle2: stop using %r to quote part names

Valid part names are restricted to [a-zA-Z0-9_:-]+, so I'm not worried
about having quoting present in places where we should have
predominantly valid part names. This will significantly ease the
Python 3 transition, and simultaneously isn't a BC because this is
only in error messages that should never be shown.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -470,12 +470,12 @@ def _gethandler(op, part):
         if handler is None:
             status = 'unsupported-type'
             raise error.BundleUnknownFeatureError(parttype=part.type)
-        indebug(op.ui, 'found a handler for part %r' % part.type)
+        indebug(op.ui, 'found a handler for part %s' % part.type)
         unknownparams = part.mandatorykeys - handler.params
         if unknownparams:
             unknownparams = list(unknownparams)
             unknownparams.sort()
-            status = 'unsupported-params (%s)' % unknownparams
+            status = 'unsupported-params (%s)' % ', '.join(unknownparams)
             raise error.BundleUnknownFeatureError(parttype=part.type,
                                                   params=unknownparams)
         status = 'supported'
@@ -616,7 +616,7 @@ class bundle20(object):
         if not name:
             raise ValueError('empty parameter name')
         if name[0] not in pycompat.bytestr(string.ascii_letters):
-            raise ValueError('non letter first character: %r' % name)
+            raise ValueError('non letter first character: %s' % name)
         self._params.append((name, value))
 
     def addpart(self, part):
@@ -792,14 +792,14 @@ class unbundle20(unpackermixin):
               ignored or failing.
         """
         if not name:
-            raise ValueError('empty parameter name')
-        if name[0] not in pycompat.bytestr(string.ascii_letters):
-            raise ValueError('non letter first character: %r' % name)
+            raise ValueError(r'empty parameter name')
+        if name[0:1] not in pycompat.bytestr(string.ascii_letters):
+            raise ValueError(r'non letter first character: %s' % name)
         try:
             handler = b2streamparamsmap[name.lower()]
         except KeyError:
-            if name[0].islower():
-                indebug(self.ui, "ignoring unknown parameter %r" % name)
+            if name[0:1].islower():
+                indebug(self.ui, "ignoring unknown parameter %s" % name)
             else:
                 raise error.BundleUnknownFeatureError(params=(name,))
         else:
diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -410,8 +410,8 @@ unbundling debug
   $ hg statbundle2 --debug --config progress.debug=true --config devel.bundle2.debug=true < ../out.hg2
   bundle2-input: start processing of HG20 stream
   bundle2-input: reading bundle2 stream parameters
-  bundle2-input: ignoring unknown parameter 'e|! 7/'
-  bundle2-input: ignoring unknown parameter 'simple'
+  bundle2-input: ignoring unknown parameter e|! 7/
+  bundle2-input: ignoring unknown parameter simple
   options count: 2
   - e|! 7/
       babar%#==tutu
@@ -434,7 +434,7 @@ empty parameter name
 bad parameter name
 
   $ hg bundle2 --param 42babar
-  abort: non letter first character: '42babar'
+  abort: non letter first character: 42babar
   [255]
 
 
@@ -651,7 +651,7 @@ Process the bundle
   bundle2-input: part type: "test:song"
   bundle2-input: part id: "2"
   bundle2-input: part parameters: 0
-  bundle2-input: found a handler for part 'test:song'
+  bundle2-input: found a handler for part test:song
   bundle2-input-part: "test:song" (advisory) supported
   The choir starts singing:
   bundle2-input: payload chunk size: 178
@@ -664,7 +664,7 @@ Process the bundle
   bundle2-input: part type: "test:debugreply"
   bundle2-input: part id: "3"
   bundle2-input: part parameters: 0
-  bundle2-input: found a handler for part 'test:debugreply'
+  bundle2-input: found a handler for part test:debugreply
   bundle2-input-part: "test:debugreply" (advisory) supported
   debugreply: no reply
   bundle2-input: payload chunk size: 0
@@ -681,15 +681,15 @@ Process the bundle
   bundle2-input: part type: "test:song"
   bundle2-input: part id: "5"
   bundle2-input: part parameters: 1
-  bundle2-input: found a handler for part 'test:song'
+  bundle2-input: found a handler for part test:song
   bundle2-input: ignoring unsupported advisory part test:song - randomparam
-  bundle2-input-part: "test:song" (advisory) (params: 1 mandatory) unsupported-params (['randomparam'])
+  bundle2-input-part: "test:song" (advisory) (params: 1 mandatory) unsupported-params (randomparam)
   bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 16
   bundle2-input: part type: "test:ping"
   bundle2-input: part id: "6"
   bundle2-input: part parameters: 0
-  bundle2-input: found a handler for part 'test:ping'
+  bundle2-input: found a handler for part test:ping
   bundle2-input-part: "test:ping" (advisory) supported
   received ping request (id 6)
   bundle2-input: payload chunk size: 0


More information about the Mercurial-devel mailing list