Mercurial > hg
comparison tests/test-bundle2.t @ 20949:571f2903ff1e
bundle2: record processing results in the bundleoperation object
Part handlers can now add records to the `bundleoperation` object. This can be
used to help other parts or to let the caller of the unbundling process react
to the results.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 02 Apr 2014 22:37:50 -0700 |
parents | 329cd74b52bd |
children | c7ceae0faf69 |
comparison
equal
deleted
inserted
replaced
20948:329cd74b52bd | 20949:571f2903ff1e |
---|---|
22 > | 22 > |
23 > @bundle2.parthandler('test:song') | 23 > @bundle2.parthandler('test:song') |
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'), |
32 > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'), | 35 > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'), |
33 > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], | 36 > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], |
73 > """process a bundle2 stream from stdin on the current repo""" | 76 > """process a bundle2 stream from stdin on the current repo""" |
74 > try: | 77 > try: |
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): |
88 > """print statistic on the bundle2 container read from stdin""" | 94 > """print statistic on the bundle2 container read from stdin""" |
89 > unbundler = bundle2.unbundle20(ui, sys.stdin) | 95 > unbundler = bundle2.unbundle20(ui, sys.stdin) |
391 payload chunk size: 0 | 397 payload chunk size: 0 |
392 ignoring unknown advisory part 'test:math' | 398 ignoring unknown advisory part 'test:math' |
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 |
399 | 406 |
400 $ hg unbundle2 < ../unknown.hg2 | 407 $ hg unbundle2 < ../unknown.hg2 |