Show More
@@ -148,6 +148,48 b' def _makefpartparamsizes(nbparams):' | |||||
148 | """ |
|
148 | """ | |
149 | return '>'+('BB'*nbparams) |
|
149 | return '>'+('BB'*nbparams) | |
150 |
|
150 | |||
|
151 | ||||
|
152 | parthandlermapping = {} | |||
|
153 | ||||
|
154 | def processbundle(repo, stream): | |||
|
155 | """This function process a bundle, apply effect to/from a repo | |||
|
156 | ||||
|
157 | Currently it: | |||
|
158 | - parse a stream into an unbundle20 object | |||
|
159 | - iterate over each parts then search and use the proper handling code to | |||
|
160 | process the part. | |||
|
161 | ||||
|
162 | Parts are processes in order. | |||
|
163 | ||||
|
164 | This is very early version of this function that will be strongly reworked | |||
|
165 | before final usage. | |||
|
166 | ||||
|
167 | All unknown parts are currently ignored (Mandatory parts logic will comes | |||
|
168 | later). | |||
|
169 | """ | |||
|
170 | ui = repo.ui | |||
|
171 | # Extraction of the unbundler object will most likely change. It may be | |||
|
172 | # done outside of this function, the unbundler would be passed as argument. | |||
|
173 | # in all case the unbundler will eventually be created by a | |||
|
174 | # `changegroup.readbundle` style function. | |||
|
175 | unbundler = unbundle20(ui, stream) | |||
|
176 | # todo: | |||
|
177 | # - replace this is a init function soon. | |||
|
178 | # - exception catching | |||
|
179 | unbundler.params | |||
|
180 | for part in unbundler: | |||
|
181 | parttype = part.type | |||
|
182 | # part key are matched lower case | |||
|
183 | key = parttype.lower() | |||
|
184 | try: | |||
|
185 | handler = parthandlermapping[key] | |||
|
186 | ui.debug('found an handler for part %r\n' % parttype) | |||
|
187 | except KeyError: | |||
|
188 | ui.debug('ignoring unknown advisory part %r\n' % key) | |||
|
189 | # todo: consume the part (once we use streamed parts) | |||
|
190 | continue | |||
|
191 | handler(repo, part) | |||
|
192 | ||||
151 | class bundle20(object): |
|
193 | class bundle20(object): | |
152 | """represent an outgoing bundle2 container |
|
194 | """represent an outgoing bundle2 container | |
153 |
|
195 |
@@ -20,6 +20,14 b' Create an extension to test bundle2 API' | |||||
20 | > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.""" |
|
20 | > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.""" | |
21 | > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it. |
|
21 | > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it. | |
22 | > |
|
22 | > | |
|
23 | > def songhandler(repo, part): | |||
|
24 | > """handle a "test:song" bundle2 part, printing the lyrics on stdin""" | |||
|
25 | > repo.ui.write('The choir start singing:\n') | |||
|
26 | > for line in part.data.split('\n'): | |||
|
27 | > repo.ui.write(' %s\n' % line) | |||
|
28 | > | |||
|
29 | > bundle2.parthandlermapping['test:song'] = songhandler | |||
|
30 | > | |||
23 | > @command('bundle2', |
|
31 | > @command('bundle2', | |
24 | > [('', 'param', [], 'stream level parameter'), |
|
32 | > [('', 'param', [], 'stream level parameter'), | |
25 | > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], |
|
33 | > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], | |
@@ -56,6 +64,11 b' Create an extension to test bundle2 API' | |||||
56 | > for chunk in bundler.getchunks(): |
|
64 | > for chunk in bundler.getchunks(): | |
57 | > file.write(chunk) |
|
65 | > file.write(chunk) | |
58 | > |
|
66 | > | |
|
67 | > @command('unbundle2', [], '') | |||
|
68 | > def cmdunbundle2(ui, repo): | |||
|
69 | > """process a bundle2 stream from stdin on the current repo""" | |||
|
70 | > bundle2.processbundle(repo, sys.stdin) | |||
|
71 | > | |||
59 | > @command('statbundle2', [], '') |
|
72 | > @command('statbundle2', [], '') | |
60 | > def cmdstatbundle2(ui, repo): |
|
73 | > def cmdstatbundle2(ui, repo): | |
61 | > """print statistic on the bundle2 container read from stdin""" |
|
74 | > """print statistic on the bundle2 container read from stdin""" | |
@@ -327,3 +340,41 b' Test part' | |||||
327 | mandatory: 2 |
|
340 | mandatory: 2 | |
328 | advisory: 1 |
|
341 | advisory: 1 | |
329 | payload: 2 bytes |
|
342 | payload: 2 bytes | |
|
343 | ||||
|
344 | Test actual unbundling | |||
|
345 | ======================== | |||
|
346 | ||||
|
347 | Process the bundle | |||
|
348 | ||||
|
349 | $ hg unbundle2 --debug < ../parts.hg2 | |||
|
350 | start processing of HG20 stream | |||
|
351 | reading bundle2 stream parameters | |||
|
352 | start extraction of bundle2 parts | |||
|
353 | part header size: 13 | |||
|
354 | part type: "test:empty" | |||
|
355 | part parameters: 0 | |||
|
356 | payload chunk size: 0 | |||
|
357 | ignoring unknown advisory part 'test:empty' | |||
|
358 | part header size: 13 | |||
|
359 | part type: "test:empty" | |||
|
360 | part parameters: 0 | |||
|
361 | payload chunk size: 0 | |||
|
362 | ignoring unknown advisory part 'test:empty' | |||
|
363 | part header size: 12 | |||
|
364 | part type: "test:song" | |||
|
365 | part parameters: 0 | |||
|
366 | payload chunk size: 178 | |||
|
367 | payload chunk size: 0 | |||
|
368 | found an handler for part 'test:song' | |||
|
369 | The choir start singing: | |||
|
370 | Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko | |||
|
371 | Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | |||
|
372 | Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko. | |||
|
373 | part header size: 39 | |||
|
374 | part type: "test:math" | |||
|
375 | part parameters: 3 | |||
|
376 | payload chunk size: 2 | |||
|
377 | payload chunk size: 0 | |||
|
378 | ignoring unknown advisory part 'test:math' | |||
|
379 | part header size: 0 | |||
|
380 | end of bundle2 stream |
General Comments 0
You need to be logged in to leave comments.
Login now