# HG changeset patch # User Pierre-Yves David # Date 1395785111 25200 # Node ID 93a3c5b5863572abee76e248a054b7072a1b682c # Parent d7df4b7378ae194106ade2e14c6bafa334334fc4 bundle2: use reply part to return result of addchangegroup We now have an official way to return the result of addchangegroup. The tests are updated to check that the return bundle is properly created. It will be used when push is bundle2 enabled. diff -r d7df4b7378ae -r 93a3c5b58635 mercurial/bundle2.py --- a/mercurial/bundle2.py Fri Apr 04 14:24:11 2014 -0700 +++ b/mercurial/bundle2.py Tue Mar 25 15:05:11 2014 -0700 @@ -558,7 +558,7 @@ yield _pack(_fpayloadsize, 0) @parthandler('changegroup') -def handlechangegroup(op, part): +def handlechangegroup(op, inpart): """apply a changegroup part on the repo This is a very early implementation that will massive rework before being @@ -570,10 +570,21 @@ # we need to make sure we trigger the creation of a transaction object used # for the whole processing scope. op.gettransaction() - data = StringIO.StringIO(part.data) + data = StringIO.StringIO(inpart.data) data.seek(0) cg = changegroup.readbundle(data, 'bundle2part') ret = changegroup.addchangegroup(op.repo, cg, 'bundle2', 'bundle2') op.records.add('changegroup', {'return': ret}) + if op.reply is not None: + # This is definitly not the final form of this + # return. But one need to start somewhere. + op.reply.addpart(part('reply:changegroup', (), + [('in-reply-to', str(inpart.id)), + ('return', '%i' % ret)])) +@parthandler('reply:changegroup') +def handlechangegroup(op, inpart): + p = dict(inpart.advisoryparams) + ret = int(p['return']) + op.records.add('changegroup', {'return': ret}, int(p['in-reply-to'])) diff -r d7df4b7378ae -r 93a3c5b58635 tests/test-bundle2.t --- a/tests/test-bundle2.t Fri Apr 04 14:24:11 2014 -0700 +++ b/tests/test-bundle2.t Tue Mar 25 15:05:11 2014 -0700 @@ -626,7 +626,7 @@ \x87\xcd\xc9n\x8e\xaa\xb6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02H (esc) \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 (no-eol) (esc) - $ hg unbundle2 < ../rev.hg2 + $ hg unbundle2 ../rev-replay.hg2 < ../rev.hg2 adding changesets adding manifests adding file changes @@ -634,6 +634,9 @@ 0 unread bytes addchangegroup return: 1 + $ cat ../rev-replay.hg2 + HG20\x00\x00\x00/\x11reply:changegroup\x00\x00\x00\x00\x00\x02\x0b\x01\x06\x01in-reply-to0return1\x00\x00\x00\x00\x00\x00 (no-eol) (esc) + Real world exchange =====================