Patchwork [7,of,7] bundle2: force the first char of parameter to be an letter

login
register
mail settings
Submitter Pierre-Yves David
Date March 21, 2014, 9:57 p.m.
Message ID <eec1f3d69dcd9f865677.1395439052@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4030/
State Accepted
Headers show

Comments

Pierre-Yves David - March 21, 2014, 9:57 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1395194168 25200
#      Tue Mar 18 18:56:08 2014 -0700
# Node ID eec1f3d69dcd9f8656776045e36f277ec5ebd8f9
# Parent  ca51ee1121790c891e1f98cd18d8b664f131ea31
bundle2: force the first char of parameter to be an letter.

We need a case sensitive character to convey mandatory/advisory parameter
semantic in a later patches.
Matt Mackall - March 21, 2014, 10:04 p.m.
On Fri, 2014-03-21 at 14:57 -0700, pierre-yves.david@ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1395194168 25200
> #      Tue Mar 18 18:56:08 2014 -0700
> # Node ID eec1f3d69dcd9f8656776045e36f277ec5ebd8f9
> # Parent  ca51ee1121790c891e1f98cd18d8b664f131ea31
> bundle2: force the first char of parameter to be an letter.

These are queued for default, thanks.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -45,10 +45,14 @@  Binary format is as follow
   The blob contains a space separated list of parameters. parameter with value
   are stored in the form `<name>=<value>`. Both name and value are urlquoted.
 
   Empty name are obviously forbidden.
 
+  Name MUST start with a letter. This first character has to be capitalizable.
+  The capitalisation of the first letter will be used to know if an option is
+  advisory or mandatory. This is not implemented yet.
+
   Stream parameters use a simple textual format for two main reasons:
 
   - Stream level parameters should remains simple and we want to discourage any
     crazy usage.
   - Textual data allow easy human inspection of a the bundle2 header in case of
@@ -70,10 +74,11 @@  Binary format is as follow
 """
 
 import util
 import struct
 import urllib
+import string
 
 import changegroup
 from i18n import _
 
 _pack = struct.pack
@@ -98,10 +103,12 @@  class bundle20(object):
 
     def addparam(self, name, value=None):
         """add a stream level parameter"""
         if not name:
             raise ValueError('empty parameter name')
+        if name[0] not in string.letters:
+            raise ValueError('non letter first character: %r' % name)
         self._params.append((name, value))
 
     def getchunks(self):
         yield _magicstring
         param = self._paramchunk()
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -160,5 +160,11 @@  Test buggy input
 empty parameter name
 
   $ hg bundle2 --param '' --quiet
   abort: empty parameter name
   [255]
+
+bad parameter name
+
+  $ hg bundle2 --param 42babar
+  abort: non letter first character: '42babar'
+  [255]