Show More
@@ -183,6 +183,26 b' def parthandler(parttype):' | |||||
183 | return func |
|
183 | return func | |
184 | return _decorator |
|
184 | return _decorator | |
185 |
|
185 | |||
|
186 | class bundleoperation(object): | |||
|
187 | """an object that represents a single bundling process | |||
|
188 | ||||
|
189 | Its purpose is to carry unbundle-related objects and states. | |||
|
190 | ||||
|
191 | A new object should be created at the beginning of each bundle processing. | |||
|
192 | The object is to be returned by the processing function. | |||
|
193 | ||||
|
194 | The object has very little content now it will ultimately contain: | |||
|
195 | * an access to the repo the bundle is applied to, | |||
|
196 | * a ui object, | |||
|
197 | * a way to retrieve a transaction to add changes to the repo, | |||
|
198 | * a way to record the result of processing each part, | |||
|
199 | * a way to construct a bundle response when applicable. | |||
|
200 | """ | |||
|
201 | ||||
|
202 | def __init__(self, repo): | |||
|
203 | self.repo = repo | |||
|
204 | self.ui = repo.ui | |||
|
205 | ||||
186 | def processbundle(repo, unbundler): |
|
206 | def processbundle(repo, unbundler): | |
187 | """This function process a bundle, apply effect to/from a repo |
|
207 | """This function process a bundle, apply effect to/from a repo | |
188 |
|
208 | |||
@@ -194,7 +214,7 b' def processbundle(repo, unbundler):' | |||||
194 |
|
214 | |||
195 | Unknown Mandatory part will abort the process. |
|
215 | Unknown Mandatory part will abort the process. | |
196 | """ |
|
216 | """ | |
197 | ui = repo.ui |
|
217 | op = bundleoperation(repo) | |
198 | # todo: |
|
218 | # todo: | |
199 | # - replace this is a init function soon. |
|
219 | # - replace this is a init function soon. | |
200 | # - exception catching |
|
220 | # - exception catching | |
@@ -207,17 +227,17 b' def processbundle(repo, unbundler):' | |||||
207 | key = parttype.lower() |
|
227 | key = parttype.lower() | |
208 | try: |
|
228 | try: | |
209 | handler = parthandlermapping[key] |
|
229 | handler = parthandlermapping[key] | |
210 |
ui.debug('found a |
|
230 | op.ui.debug('found a handler for part %r\n' % parttype) | |
211 | except KeyError: |
|
231 | except KeyError: | |
212 | if key != parttype: # mandatory parts |
|
232 | if key != parttype: # mandatory parts | |
213 | # todo: |
|
233 | # todo: | |
214 | # - use a more precise exception |
|
234 | # - use a more precise exception | |
215 | raise |
|
235 | raise | |
216 | ui.debug('ignoring unknown advisory part %r\n' % key) |
|
236 | op.ui.debug('ignoring unknown advisory part %r\n' % key) | |
217 | # todo: |
|
237 | # todo: | |
218 | # - consume the part once we use streaming |
|
238 | # - consume the part once we use streaming | |
219 | continue |
|
239 | continue | |
220 |
handler( |
|
240 | handler(op, part) | |
221 | except Exception: |
|
241 | except Exception: | |
222 | for part in iterparts: |
|
242 | for part in iterparts: | |
223 | pass # consume the bundle content |
|
243 | pass # consume the bundle content |
@@ -21,11 +21,11 b' Create an extension to test bundle2 API' | |||||
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 | > @bundle2.parthandler('test:song') |
|
23 | > @bundle2.parthandler('test:song') | |
24 |
> def songhandler( |
|
24 | > def songhandler(op, part): | |
25 | > """handle a "test:song" bundle2 part, printing the lyrics on stdin""" |
|
25 | > """handle a "test:song" bundle2 part, printing the lyrics on stdin""" | |
26 |
> |
|
26 | > op.ui.write('The choir starts singing:\n') | |
27 | > for line in part.data.split('\n'): |
|
27 | > for line in part.data.split('\n'): | |
28 |
> |
|
28 | > op.ui.write(' %s\n' % line) | |
29 | > |
|
29 | > | |
30 | > @command('bundle2', |
|
30 | > @command('bundle2', | |
31 | > [('', 'param', [], 'stream level parameter'), |
|
31 | > [('', 'param', [], 'stream level parameter'), |
General Comments 0
You need to be logged in to leave comments.
Login now