Show More
@@ -183,6 +183,44 b' def parthandler(parttype):' | |||||
183 | return func |
|
183 | return func | |
184 | return _decorator |
|
184 | return _decorator | |
185 |
|
185 | |||
|
186 | class unbundlerecords(object): | |||
|
187 | """keep record of what happens during and unbundle | |||
|
188 | ||||
|
189 | New records are added using `records.add('cat', obj)`. Where 'cat' is a | |||
|
190 | category of record and obj is an arbitraty object. | |||
|
191 | ||||
|
192 | `records['cat']` will return all entries of this category 'cat'. | |||
|
193 | ||||
|
194 | Iterating on the object itself will yield `('category', obj)` tuples | |||
|
195 | for all entries. | |||
|
196 | ||||
|
197 | All iterations happens in chronological order. | |||
|
198 | """ | |||
|
199 | ||||
|
200 | def __init__(self): | |||
|
201 | self._categories = {} | |||
|
202 | self._sequences = [] | |||
|
203 | ||||
|
204 | def add(self, category, entry): | |||
|
205 | """add a new record of a given category. | |||
|
206 | ||||
|
207 | The entry can then be retrieved in the list returned by | |||
|
208 | self['category'].""" | |||
|
209 | self._categories.setdefault(category, []).append(entry) | |||
|
210 | self._sequences.append((category, entry)) | |||
|
211 | ||||
|
212 | def __getitem__(self, cat): | |||
|
213 | return tuple(self._categories.get(cat, ())) | |||
|
214 | ||||
|
215 | def __iter__(self): | |||
|
216 | return iter(self._sequences) | |||
|
217 | ||||
|
218 | def __len__(self): | |||
|
219 | return len(self._sequences) | |||
|
220 | ||||
|
221 | def __nonzero__(self): | |||
|
222 | return bool(self._sequences) | |||
|
223 | ||||
186 | class bundleoperation(object): |
|
224 | class bundleoperation(object): | |
187 | """an object that represents a single bundling process |
|
225 | """an object that represents a single bundling process | |
188 |
|
226 | |||
@@ -202,6 +240,7 b' class bundleoperation(object):' | |||||
202 | def __init__(self, repo): |
|
240 | def __init__(self, repo): | |
203 | self.repo = repo |
|
241 | self.repo = repo | |
204 | self.ui = repo.ui |
|
242 | self.ui = repo.ui | |
|
243 | self.records = unbundlerecords() | |||
205 |
|
244 | |||
206 | def processbundle(repo, unbundler): |
|
245 | def processbundle(repo, unbundler): | |
207 | """This function process a bundle, apply effect to/from a repo |
|
246 | """This function process a bundle, apply effect to/from a repo | |
@@ -242,6 +281,7 b' def processbundle(repo, unbundler):' | |||||
242 | for part in iterparts: |
|
281 | for part in iterparts: | |
243 | pass # consume the bundle content |
|
282 | pass # consume the bundle content | |
244 | raise |
|
283 | raise | |
|
284 | return op | |||
245 |
|
285 | |||
246 | class bundle20(object): |
|
286 | class bundle20(object): | |
247 | """represent an outgoing bundle2 container |
|
287 | """represent an outgoing bundle2 container |
@@ -24,8 +24,11 b' Create an extension to test bundle2 API' | |||||
24 | > def songhandler(op, part): |
|
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 | > op.ui.write('The choir starts singing:\n') |
|
26 | > op.ui.write('The choir starts singing:\n') | |
|
27 | > verses = 0 | |||
27 | > for line in part.data.split('\n'): |
|
28 | > for line in part.data.split('\n'): | |
28 | > op.ui.write(' %s\n' % line) |
|
29 | > op.ui.write(' %s\n' % line) | |
|
30 | > verses += 1 | |||
|
31 | > op.records.add('song', {'verses': verses}) | |||
29 | > |
|
32 | > | |
30 | > @command('bundle2', |
|
33 | > @command('bundle2', | |
31 | > [('', 'param', [], 'stream level parameter'), |
|
34 | > [('', 'param', [], 'stream level parameter'), | |
@@ -75,13 +78,16 b' Create an extension to test bundle2 API' | |||||
75 | > lock = repo.lock() |
|
78 | > lock = repo.lock() | |
76 | > try: |
|
79 | > try: | |
77 | > unbundler = bundle2.unbundle20(ui, sys.stdin) |
|
80 | > unbundler = bundle2.unbundle20(ui, sys.stdin) | |
78 | > bundle2.processbundle(repo, unbundler) |
|
81 | > op = bundle2.processbundle(repo, unbundler) | |
79 | > except KeyError, exc: |
|
82 | > except KeyError, exc: | |
80 | > raise util.Abort('missing support for %s' % exc) |
|
83 | > raise util.Abort('missing support for %s' % exc) | |
81 | > finally: |
|
84 | > finally: | |
82 | > lock.release() |
|
85 | > lock.release() | |
83 | > remains = sys.stdin.read() |
|
86 | > remains = sys.stdin.read() | |
84 | > ui.write('%i unread bytes\n' % len(remains)) |
|
87 | > ui.write('%i unread bytes\n' % len(remains)) | |
|
88 | > if op.records['song']: | |||
|
89 | > totalverses = sum(r['verses'] for r in op.records['song']) | |||
|
90 | > ui.write('%i total verses sung\n' % totalverses) | |||
85 | > |
|
91 | > | |
86 | > @command('statbundle2', [], '') |
|
92 | > @command('statbundle2', [], '') | |
87 | > def cmdstatbundle2(ui, repo): |
|
93 | > def cmdstatbundle2(ui, repo): | |
@@ -393,6 +399,7 b' Process the bundle' | |||||
393 | part header size: 0 |
|
399 | part header size: 0 | |
394 | end of bundle2 stream |
|
400 | end of bundle2 stream | |
395 | 0 unread bytes |
|
401 | 0 unread bytes | |
|
402 | 3 total verses sung | |||
396 |
|
403 | |||
397 |
|
404 | |||
398 | $ hg bundle2 --parts --unknown ../unknown.hg2 |
|
405 | $ hg bundle2 --parts --unknown ../unknown.hg2 |
General Comments 0
You need to be logged in to leave comments.
Login now