bundle2-push: introduce a list of part generating functions
Instead of explicitly calling a few function to generate part in the bundle, we
now have a list of all part generators. This should make it easier for
extensions to adds new part in the bundle.
This new way to extend the push deprecates the old `_pushbundle2extraparts` way.
--- a/mercurial/exchange.py Wed Jul 02 12:55:09 2014 +0200
+++ b/mercurial/exchange.py Wed Jul 02 15:26:04 2014 +0200
@@ -227,6 +227,9 @@
pushop.ret = cgreplies['changegroup'][0]['return']
return handlereply
+# list of function that may decide to add parts to an outgoing bundle2
+bundle2partsgenerators = [_pushb2ctx]
+
def _pushbundle2(pushop):
"""push data to the remote using bundle2
@@ -237,9 +240,11 @@
capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
bundler.newpart('b2x:replycaps', data=capsblob)
extrainfo = _pushbundle2extraparts(pushop, bundler)
- # add the changegroup bundle
- cgreplyhandler = _pushb2ctx(pushop, bundler)
- # do not push if no other parts than the capability
+ replyhandlers = []
+ for partgen in bundle2partsgenerators:
+ ret = partgen(pushop, bundler)
+ replyhandlers.append(ret)
+ # do not push if nothing to push
if bundler.nbparts <= 1:
return
stream = util.chunkbuffer(bundler.getchunks())
@@ -251,7 +256,8 @@
op = bundle2.processbundle(pushop.repo, reply)
except error.BundleValueError, exc:
raise util.Abort('missing support for %s' % exc)
- cgreplyhandler(op)
+ for rephand in replyhandlers:
+ rephand(op)
_pushbundle2extrareply(pushop, op, extrainfo)
def _pushbundle2extraparts(pushop, bundler):