[PATCH 4 of 8] bundle2: use reply part to returns result of addchangregroup

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Fri Apr 11 17:06:01 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1395785111 25200
#      Tue Mar 25 15:05:11 2014 -0700
# Node ID f38dec61a78b9f38490bcb1667af0a66c834b59f
# Parent  2d021d13b34bb12a7a88962511515ce99e15fe6a
bundle2: use reply part to returns result of addchangregroup

We now have an official way to return the result of addchangegroup. The test are
updated to check that the return bundle is properly created. It will be used
when push are bundle2 enabled.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -556,11 +556,11 @@ class part(object):
             yield self.data
         # end of payload
         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
     inflicted to any end-user.
     """
@@ -568,12 +568,23 @@ def handlechangegroup(op, part):
     #
     # The addchangegroup function will get a transaction object by itself, but
     # 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)]))
 
+ at 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 --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -624,18 +624,21 @@ Support for changegroup
   \x0cI\xd4\xa9\xc5\x01|\xf0pC\xf5NX\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x95 \xee\xa7\x81\xbc\xca\x16\xc1\xe1Z\xcc\x0b\xa1C5\xa0\xe8\xe5\xba\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02E (esc)
   \x00\x00\x00\x00\x00\x00\x00\x05H\x00\x00\x00b\x85\x00\x18\x9et\xa9\xe0G^\x82 \x93\xbc}\xb0\xd61\xae\xb0\xb4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xdeB\x19n\xbe\xe4.\xf2\x84\xb6x (esc)
   \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
   added 0 changesets with 0 changes to 3 files
   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
 =====================
 
 
 clone --pull


More information about the Mercurial-devel mailing list