Show More
@@ -148,8 +148,23 b' def _makefpartparamsizes(nbparams):' | |||
|
148 | 148 | """ |
|
149 | 149 | return '>'+('BB'*nbparams) |
|
150 | 150 | |
|
151 | parthandlermapping = {} | |
|
151 | 152 | |
|
152 | parthandlermapping = {} | |
|
153 | def parthandler(parttype): | |
|
154 | """decorator that register a function as a bundle2 part handler | |
|
155 | ||
|
156 | eg:: | |
|
157 | ||
|
158 | @parthandler('myparttype') | |
|
159 | def myparttypehandler(...): | |
|
160 | '''process a part of type "my part".''' | |
|
161 | ... | |
|
162 | """ | |
|
163 | def _decorator(func): | |
|
164 | assert parttype not in parthandlermapping | |
|
165 | parthandlermapping[parttype] = func | |
|
166 | return func | |
|
167 | return _decorator | |
|
153 | 168 | |
|
154 | 169 | def processbundle(repo, stream): |
|
155 | 170 | """This function process a bundle, apply effect to/from a repo |
@@ -20,14 +20,13 b' Create an extension to test bundle2 API' | |||
|
20 | 20 | > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.""" |
|
21 | 21 | > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it. |
|
22 | 22 | > |
|
23 | > @bundle2.parthandler('test:song') | |
|
23 | 24 | > def songhandler(repo, part): |
|
24 | 25 | > """handle a "test:song" bundle2 part, printing the lyrics on stdin""" |
|
25 | 26 | > repo.ui.write('The choir start singing:\n') |
|
26 | 27 | > for line in part.data.split('\n'): |
|
27 | 28 | > repo.ui.write(' %s\n' % line) |
|
28 | 29 | > |
|
29 | > bundle2.parthandlermapping['test:song'] = songhandler | |
|
30 | > | |
|
31 | 30 | > @command('bundle2', |
|
32 | 31 | > [('', 'param', [], 'stream level parameter'), |
|
33 | 32 | > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], |
General Comments 0
You need to be logged in to leave comments.
Login now