30 > verses = 0 |
30 > verses = 0 |
31 > for line in part.data.split('\n'): |
31 > for line in part.data.split('\n'): |
32 > op.ui.write(' %s\n' % line) |
32 > op.ui.write(' %s\n' % line) |
33 > verses += 1 |
33 > verses += 1 |
34 > op.records.add('song', {'verses': verses}) |
34 > op.records.add('song', {'verses': verses}) |
|
35 > |
|
36 > @bundle2.parthandler('test:ping') |
|
37 > def pinghandler(op, part): |
|
38 > op.ui.write('received ping request (id %i)\n' % part.id) |
|
39 > if op.reply is not None: |
|
40 > op.reply.addpart(bundle2.part('test:pong', |
|
41 > [('in-reply-to', str(part.id))])) |
35 > |
42 > |
36 > @command('bundle2', |
43 > @command('bundle2', |
37 > [('', 'param', [], 'stream level parameter'), |
44 > [('', 'param', [], 'stream level parameter'), |
38 > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'), |
45 > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'), |
39 > ('', 'parts', False, 'include some arbitrary parts to the bundle'), |
46 > ('', 'parts', False, 'include some arbitrary parts to the bundle'), |
81 > bundler.addpart(part) |
88 > bundler.addpart(part) |
82 > if opts['unknown']: |
89 > if opts['unknown']: |
83 > part = bundle2.part('test:UNKNOWN', |
90 > part = bundle2.part('test:UNKNOWN', |
84 > data='some random content') |
91 > data='some random content') |
85 > bundler.addpart(part) |
92 > bundler.addpart(part) |
|
93 > if opts['parts']: |
|
94 > part = bundle2.part('test:ping') |
|
95 > bundler.addpart(part) |
86 > |
96 > |
87 > if path is None: |
97 > if path is None: |
88 > file = sys.stdout |
98 > file = sys.stdout |
89 > else: |
99 > else: |
90 > file = open(path, 'w') |
100 > file = open(path, 'w') |
91 > |
101 > |
92 > for chunk in bundler.getchunks(): |
102 > for chunk in bundler.getchunks(): |
93 > file.write(chunk) |
103 > file.write(chunk) |
94 > |
104 > |
95 > @command('unbundle2', [], '') |
105 > @command('unbundle2', [], '') |
96 > def cmdunbundle2(ui, repo): |
106 > def cmdunbundle2(ui, repo, replypath=None): |
97 > """process a bundle2 stream from stdin on the current repo""" |
107 > """process a bundle2 stream from stdin on the current repo""" |
98 > try: |
108 > try: |
99 > tr = None |
109 > tr = None |
100 > lock = repo.lock() |
110 > lock = repo.lock() |
101 > tr = repo.transaction('processbundle') |
111 > tr = repo.transaction('processbundle') |
114 > if op.records['song']: |
124 > if op.records['song']: |
115 > totalverses = sum(r['verses'] for r in op.records['song']) |
125 > totalverses = sum(r['verses'] for r in op.records['song']) |
116 > ui.write('%i total verses sung\n' % totalverses) |
126 > ui.write('%i total verses sung\n' % totalverses) |
117 > for rec in op.records['changegroup']: |
127 > for rec in op.records['changegroup']: |
118 > ui.write('addchangegroup return: %i\n' % rec['return']) |
128 > ui.write('addchangegroup return: %i\n' % rec['return']) |
|
129 > if op.reply is not None and replypath is not None: |
|
130 > file = open(replypath, 'w') |
|
131 > for chunk in op.reply.getchunks(): |
|
132 > file.write(chunk) |
119 > |
133 > |
120 > @command('statbundle2', [], '') |
134 > @command('statbundle2', [], '') |
121 > def cmdstatbundle2(ui, repo): |
135 > def cmdstatbundle2(ui, repo): |
122 > """print statistic on the bundle2 container read from stdin""" |
136 > """print statistic on the bundle2 container read from stdin""" |
123 > unbundler = bundle2.unbundle20(ui, sys.stdin) |
137 > unbundler = bundle2.unbundle20(ui, sys.stdin) |
316 start of parts |
330 start of parts |
317 bundle part: "test:empty" |
331 bundle part: "test:empty" |
318 bundle part: "test:empty" |
332 bundle part: "test:empty" |
319 bundle part: "test:song" |
333 bundle part: "test:song" |
320 bundle part: "test:math" |
334 bundle part: "test:math" |
|
335 bundle part: "test:ping" |
321 end of bundle |
336 end of bundle |
322 |
337 |
323 $ cat ../parts.hg2 |
338 $ cat ../parts.hg2 |
324 HG20\x00\x00\x00\x11 (esc) |
339 HG20\x00\x00\x00\x11 (esc) |
325 test:empty\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11 (esc) |
340 test:empty\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11 (esc) |
326 test:empty\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x10 test:song\x00\x00\x00\x02\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc) |
341 test:empty\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x10 test:song\x00\x00\x00\x02\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc) |
327 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko |
342 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko |
328 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00+ test:math\x00\x00\x00\x03\x02\x01\x02\x04\x01\x04\x07\x03pi3.14e2.72cookingraw\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x00 (no-eol) (esc) |
343 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00+ test:math\x00\x00\x00\x03\x02\x01\x02\x04\x01\x04\x07\x03pi3.14e2.72cookingraw\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x10 test:ping\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc) |
329 |
344 |
330 |
345 |
331 $ hg statbundle2 < ../parts.hg2 |
346 $ hg statbundle2 < ../parts.hg2 |
332 options count: 0 |
347 options count: 0 |
333 parts count: 4 |
348 parts count: 5 |
334 :test:empty: |
349 :test:empty: |
335 mandatory: 0 |
350 mandatory: 0 |
336 advisory: 0 |
351 advisory: 0 |
337 payload: 0 bytes |
352 payload: 0 bytes |
338 :test:empty: |
353 :test:empty: |
432 part id: "3" |
460 part id: "3" |
433 part parameters: 3 |
461 part parameters: 3 |
434 payload chunk size: 2 |
462 payload chunk size: 2 |
435 payload chunk size: 0 |
463 payload chunk size: 0 |
436 ignoring unknown advisory part 'test:math' |
464 ignoring unknown advisory part 'test:math' |
|
465 part header size: 16 |
|
466 part type: "test:ping" |
|
467 part id: "4" |
|
468 part parameters: 0 |
|
469 payload chunk size: 0 |
|
470 found a handler for part 'test:ping' |
|
471 received ping request (id 4) |
437 part header size: 0 |
472 part header size: 0 |
438 end of bundle2 stream |
473 end of bundle2 stream |
439 0 unread bytes |
474 0 unread bytes |
440 3 total verses sung |
475 3 total verses sung |
441 |
476 |
|
477 Unbundle with an unknown mandatory part |
|
478 (should abort) |
442 |
479 |
443 $ hg bundle2 --parts --unknown ../unknown.hg2 |
480 $ hg bundle2 --parts --unknown ../unknown.hg2 |
444 |
481 |
445 $ hg unbundle2 < ../unknown.hg2 |
482 $ hg unbundle2 < ../unknown.hg2 |
446 The choir starts singing: |
483 The choir starts singing: |
448 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko |
485 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko |
449 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko. |
486 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko. |
450 0 unread bytes |
487 0 unread bytes |
451 abort: missing support for 'test:unknown' |
488 abort: missing support for 'test:unknown' |
452 [255] |
489 [255] |
|
490 |
|
491 unbundle with a reply |
|
492 |
|
493 $ hg unbundle2 ../reply.hg2 < ../parts.hg2 |
|
494 The choir starts singing: |
|
495 Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko |
|
496 Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko |
|
497 Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko. |
|
498 received ping request (id 4) |
|
499 0 unread bytes |
|
500 3 total verses sung |
|
501 |
|
502 The reply is a bundle |
|
503 |
|
504 $ cat ../reply.hg2 |
|
505 HG20\x00\x00\x00\x1e test:pong\x00\x00\x00\x00\x01\x00\x0b\x01in-reply-to4\x00\x00\x00\x00\x00\x00 (no-eol) (esc) |
|
506 |
|
507 The reply is valid |
|
508 |
|
509 $ hg statbundle2 < ../reply.hg2 |
|
510 options count: 0 |
|
511 parts count: 1 |
|
512 :test:pong: |
|
513 mandatory: 1 |
|
514 advisory: 0 |
|
515 payload: 0 bytes |
453 |
516 |
454 Support for changegroup |
517 Support for changegroup |
455 =================================== |
518 =================================== |
456 |
519 |
457 $ hg unbundle $TESTDIR/bundles/rebase.hg |
520 $ hg unbundle $TESTDIR/bundles/rebase.hg |