##// END OF EJS Templates
bundle2: produce a bundle2 reply...
Pierre-Yves David -
r20997:d7df4b73 default
parent child Browse files
Show More
@@ -254,6 +254,7 b' class bundleoperation(object):'
254 self.ui = repo.ui
254 self.ui = repo.ui
255 self.records = unbundlerecords()
255 self.records = unbundlerecords()
256 self.gettransaction = transactiongetter
256 self.gettransaction = transactiongetter
257 self.reply = None
257
258
258 class TransactionUnavailable(RuntimeError):
259 class TransactionUnavailable(RuntimeError):
259 pass
260 pass
@@ -278,6 +279,9 b' def processbundle(repo, unbundler, trans'
278 """
279 """
279 op = bundleoperation(repo, transactiongetter)
280 op = bundleoperation(repo, transactiongetter)
280 # todo:
281 # todo:
282 # - only create reply bundle if requested.
283 op.reply = bundle20(op.ui)
284 # todo:
281 # - replace this is a init function soon.
285 # - replace this is a init function soon.
282 # - exception catching
286 # - exception catching
283 unbundler.params
287 unbundler.params
@@ -33,6 +33,13 b' Create an extension to test bundle2 API'
33 > verses += 1
33 > verses += 1
34 > op.records.add('song', {'verses': verses})
34 > op.records.add('song', {'verses': verses})
35 >
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))]))
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'),
@@ -83,6 +90,9 b' Create an extension to test bundle2 API'
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
@@ -93,7 +103,7 b' Create an extension to test bundle2 API'
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
@@ -116,6 +126,10 b' Create an extension to test bundle2 API'
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):
@@ -318,6 +332,7 b' Test part'
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
@@ -325,12 +340,12 b' Test part'
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
@@ -347,6 +362,10 b' Test part'
347 mandatory: 2
362 mandatory: 2
348 advisory: 1
363 advisory: 1
349 payload: 2 bytes
364 payload: 2 bytes
365 :test:ping:
366 mandatory: 0
367 advisory: 0
368 payload: 0 bytes
350
369
351 $ hg statbundle2 --debug < ../parts.hg2
370 $ hg statbundle2 --debug < ../parts.hg2
352 start processing of HG20 stream
371 start processing of HG20 stream
@@ -375,9 +394,14 b' Test part'
375 part parameters: 3
394 part parameters: 3
376 payload chunk size: 2
395 payload chunk size: 2
377 payload chunk size: 0
396 payload chunk size: 0
397 part header size: 16
398 part type: "test:ping"
399 part id: "4"
400 part parameters: 0
401 payload chunk size: 0
378 part header size: 0
402 part header size: 0
379 end of bundle2 stream
403 end of bundle2 stream
380 parts count: 4
404 parts count: 5
381 :test:empty:
405 :test:empty:
382 mandatory: 0
406 mandatory: 0
383 advisory: 0
407 advisory: 0
@@ -394,6 +418,10 b' Test part'
394 mandatory: 2
418 mandatory: 2
395 advisory: 1
419 advisory: 1
396 payload: 2 bytes
420 payload: 2 bytes
421 :test:ping:
422 mandatory: 0
423 advisory: 0
424 payload: 0 bytes
397
425
398 Test actual unbundling of test part
426 Test actual unbundling of test part
399 =======================================
427 =======================================
@@ -434,11 +462,20 b' Process the bundle'
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
@@ -451,6 +488,32 b' Process the bundle'
451 abort: missing support for 'test:unknown'
488 abort: missing support for 'test:unknown'
452 [255]
489 [255]
453
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
516
454 Support for changegroup
517 Support for changegroup
455 ===================================
518 ===================================
456
519
General Comments 0
You need to be logged in to leave comments. Login now