##// END OF EJS Templates
bundle2: implement the mandatory/advisory logic for parameter...
Pierre-Yves David -
r20844:2631204d default
parent child Browse files
Show More
@@ -47,9 +47,10 b' Binary format is as follow'
47
47
48 Empty name are obviously forbidden.
48 Empty name are obviously forbidden.
49
49
50 Name MUST start with a letter. This first character has to be capitalizable.
50 Name MUST start with a letter. If this first letter is lower case, the
51 The capitalisation of the first letter will be used to know if an option is
51 parameter is advisory and can be safefly ignored. However when the first
52 advisory or mandatory. This is not implemented yet.
52 letter is capital, the parameter is mandatory and the bundling process MUST
53 stop if he is not able to proceed it.
53
54
54 Stream parameters use a simple textual format for two main reasons:
55 Stream parameters use a simple textual format for two main reasons:
55
56
@@ -173,9 +174,32 b' class unbundle20(object):'
173 p = [urllib.unquote(i) for i in p]
174 p = [urllib.unquote(i) for i in p]
174 if len(p) < 2:
175 if len(p) < 2:
175 p.append(None)
176 p.append(None)
177 self._processparam(*p)
176 params[p[0]] = p[1]
178 params[p[0]] = p[1]
177 return params
179 return params
178
180
181 def _processparam(self, name, value):
182 """process a parameter, applying its effect if needed
183
184 Parameter starting with a lower case letter are advisory and will be
185 ignored when unknown. Those starting with an upper case letter are
186 mandatory and will this function will raise a KeyError when unknown.
187
188 Note: no option are currently supported. Any input will be either
189 ignored or failing.
190 """
191 if not name:
192 raise ValueError('empty parameter name')
193 if name[0] not in string.letters:
194 raise ValueError('non letter first character: %r' % name)
195 # Some logic will be later added here to try to process the option for
196 # a dict of known parameter.
197 if name[0].islower():
198 self.ui.debug("ignoring unknown parameter %r\n" % name)
199 else:
200 raise KeyError(name)
201
202
179 def __iter__(self):
203 def __iter__(self):
180 """yield all parts contained in the stream"""
204 """yield all parts contained in the stream"""
181 # make sure param have been loaded
205 # make sure param have been loaded
@@ -40,10 +40,14 b' Create an extension to test bundle2 API'
40 > def cmdunbundle2(ui, repo):
40 > def cmdunbundle2(ui, repo):
41 > """read a bundle2 container from standard input"""
41 > """read a bundle2 container from standard input"""
42 > unbundler = bundle2.unbundle20(ui, sys.stdin)
42 > unbundler = bundle2.unbundle20(ui, sys.stdin)
43 > ui.write('options count: %i\n' % len(unbundler.params))
43 > try:
44 > for key in sorted(unbundler.params):
44 > params = unbundler.params
45 > except KeyError, exc:
46 > raise util.Abort('unknown parameters: %s' % exc)
47 > ui.write('options count: %i\n' % len(params))
48 > for key in sorted(params):
45 > ui.write('- %s\n' % key)
49 > ui.write('- %s\n' % key)
46 > value = unbundler.params[key]
50 > value = params[key]
47 > if value is not None:
51 > if value is not None:
48 > ui.write(' %s\n' % value)
52 > ui.write(' %s\n' % value)
49 > parts = list(unbundler)
53 > parts = list(unbundler)
@@ -159,6 +163,13 b' Test unbundling'
159 - simple
163 - simple
160 parts count: 0
164 parts count: 0
161
165
166 Test unknown mandatory option
167 ---------------------------------------------------
168
169 $ hg bundle2 --param 'Gravity' | hg unbundle2
170 abort: unknown parameters: 'Gravity'
171 [255]
172
162 Test debug output
173 Test debug output
163 ---------------------------------------------------
174 ---------------------------------------------------
164
175
@@ -179,6 +190,8 b' unbundling debug'
179 $ hg unbundle2 --debug < ../out.hg2
190 $ hg unbundle2 --debug < ../out.hg2
180 start processing of HG20 stream
191 start processing of HG20 stream
181 reading bundle2 stream parameters
192 reading bundle2 stream parameters
193 ignoring unknown parameter 'e|! 7/'
194 ignoring unknown parameter 'simple'
182 options count: 2
195 options count: 2
183 - e|! 7/
196 - e|! 7/
184 babar%#==tutu
197 babar%#==tutu
General Comments 0
You need to be logged in to leave comments. Login now