##// 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 254 self.ui = repo.ui
255 255 self.records = unbundlerecords()
256 256 self.gettransaction = transactiongetter
257 self.reply = None
257 258
258 259 class TransactionUnavailable(RuntimeError):
259 260 pass
@@ -278,6 +279,9 b' def processbundle(repo, unbundler, trans'
278 279 """
279 280 op = bundleoperation(repo, transactiongetter)
280 281 # todo:
282 # - only create reply bundle if requested.
283 op.reply = bundle20(op.ui)
284 # todo:
281 285 # - replace this is a init function soon.
282 286 # - exception catching
283 287 unbundler.params
@@ -33,6 +33,13 b' Create an extension to test bundle2 API'
33 33 > verses += 1
34 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 43 > @command('bundle2',
37 44 > [('', 'param', [], 'stream level parameter'),
38 45 > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
@@ -83,6 +90,9 b' Create an extension to test bundle2 API'
83 90 > part = bundle2.part('test:UNKNOWN',
84 91 > data='some random content')
85 92 > bundler.addpart(part)
93 > if opts['parts']:
94 > part = bundle2.part('test:ping')
95 > bundler.addpart(part)
86 96 >
87 97 > if path is None:
88 98 > file = sys.stdout
@@ -93,7 +103,7 b' Create an extension to test bundle2 API'
93 103 > file.write(chunk)
94 104 >
95 105 > @command('unbundle2', [], '')
96 > def cmdunbundle2(ui, repo):
106 > def cmdunbundle2(ui, repo, replypath=None):
97 107 > """process a bundle2 stream from stdin on the current repo"""
98 108 > try:
99 109 > tr = None
@@ -116,6 +126,10 b' Create an extension to test bundle2 API'
116 126 > ui.write('%i total verses sung\n' % totalverses)
117 127 > for rec in op.records['changegroup']:
118 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 134 > @command('statbundle2', [], '')
121 135 > def cmdstatbundle2(ui, repo):
@@ -318,6 +332,7 b' Test part'
318 332 bundle part: "test:empty"
319 333 bundle part: "test:song"
320 334 bundle part: "test:math"
335 bundle part: "test:ping"
321 336 end of bundle
322 337
323 338 $ cat ../parts.hg2
@@ -325,12 +340,12 b' Test part'
325 340 test:empty\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11 (esc)
326 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 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 346 $ hg statbundle2 < ../parts.hg2
332 347 options count: 0
333 parts count: 4
348 parts count: 5
334 349 :test:empty:
335 350 mandatory: 0
336 351 advisory: 0
@@ -347,6 +362,10 b' Test part'
347 362 mandatory: 2
348 363 advisory: 1
349 364 payload: 2 bytes
365 :test:ping:
366 mandatory: 0
367 advisory: 0
368 payload: 0 bytes
350 369
351 370 $ hg statbundle2 --debug < ../parts.hg2
352 371 start processing of HG20 stream
@@ -375,9 +394,14 b' Test part'
375 394 part parameters: 3
376 395 payload chunk size: 2
377 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 402 part header size: 0
379 403 end of bundle2 stream
380 parts count: 4
404 parts count: 5
381 405 :test:empty:
382 406 mandatory: 0
383 407 advisory: 0
@@ -394,6 +418,10 b' Test part'
394 418 mandatory: 2
395 419 advisory: 1
396 420 payload: 2 bytes
421 :test:ping:
422 mandatory: 0
423 advisory: 0
424 payload: 0 bytes
397 425
398 426 Test actual unbundling of test part
399 427 =======================================
@@ -434,11 +462,20 b' Process the bundle'
434 462 payload chunk size: 2
435 463 payload chunk size: 0
436 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 472 part header size: 0
438 473 end of bundle2 stream
439 474 0 unread bytes
440 475 3 total verses sung
441 476
477 Unbundle with an unknown mandatory part
478 (should abort)
442 479
443 480 $ hg bundle2 --parts --unknown ../unknown.hg2
444 481
@@ -451,6 +488,32 b' Process the bundle'
451 488 abort: missing support for 'test:unknown'
452 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 517 Support for changegroup
455 518 ===================================
456 519
General Comments 0
You need to be logged in to leave comments. Login now