Patchwork [7,of,9] bundle2-push: introduce a list of part generating functions

login
register
mail settings
Submitter Pierre-Yves David
Date July 7, 2014, 11:02 a.m.
Message ID <c633162a96e155faf17a.1404730925@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5124/
State Accepted
Commit 5fbccbcc07ea1ba94d5dad91bf48925b99bdc0ce
Headers show

Comments

Pierre-Yves David - July 7, 2014, 11:02 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1404307564 -7200
#      Wed Jul 02 15:26:04 2014 +0200
# Node ID c633162a96e155faf17a49d5c334a3fdf536027f
# Parent  344c10f0668ffb06c78ee8125c40cd5159a7a536
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.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -225,23 +225,28 @@  def _pushb2ctx(pushop, bundler):
         cgreplies = op.records.getreplies(cgpart.id)
         assert len(cgreplies['changegroup']) == 1
         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
 
     The only currently supported type of data is changegroup but this will
     evolve in the future."""
     bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
     # create reply capability
     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())
     try:
         reply = pushop.remote.unbundle(stream, ['force'], 'push')
@@ -249,11 +254,12 @@  def _pushbundle2(pushop):
         raise util.Abort('missing support for %s' % exc)
     try:
         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):
     """hook function to let extensions add parts