Patchwork [6,of,9] bundle2-push: move changegroup push validation inside _pushb2ctx

login
register
mail settings
Submitter Pierre-Yves David
Date July 7, 2014, 11:02 a.m.
Message ID <344c10f0668ffb06c78e.1404730924@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5126/
State Accepted
Commit 48f61cfb75764d6ec7b5caef5ccf4d85f2153910
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 1404298509 -7200
#      Wed Jul 02 12:55:09 2014 +0200
# Node ID 344c10f0668ffb06c78ee8125c40cd5159a7a536
# Parent  92fa0cfd1a2d15f0e637ef33c4cf42e16f80c483
bundle2-push: move changegroup push validation inside _pushb2ctx

When bundle2 push includes more than just changesets, we may have no
changegroup to push yet still have other data to push.

So we now try to performs a bundle2 push in all cases. The check for changegroup
inclusion is moved into the ``_pushb2ctx`` function in charge of creating the
changegroup part.

The bundle2 part is aborted if no actual payload part have been added to the
bundle2.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -129,19 +129,15 @@  def push(repo, remote, force=False, revs
         unbundle = pushop.remote.capable('unbundle')
         if not unbundle:
             lock = pushop.remote.lock()
         try:
             _pushdiscovery(pushop)
-            if _pushcheckoutgoing(pushop):
-                pushop.repo.prepushoutgoinghooks(pushop.repo,
-                                                 pushop.remote,
-                                                 pushop.outgoing)
-                if (pushop.repo.ui.configbool('experimental', 'bundle2-exp',
-                                              False)
-                    and pushop.remote.capable('bundle2-exp')):
-                    _pushbundle2(pushop)
-                _pushchangeset(pushop)
+            if (pushop.repo.ui.configbool('experimental', 'bundle2-exp',
+                                          False)
+                and pushop.remote.capable('bundle2-exp')):
+                _pushbundle2(pushop)
+            _pushchangeset(pushop)
             _pushcomputecommonheads(pushop)
             _pushsyncphase(pushop)
             _pushobsolete(pushop)
         finally:
             if lock is not None:
@@ -212,10 +208,16 @@  def _pushb2ctx(pushop, bundler):
     """
     if 'changesets' in pushop.stepsdone:
         return
     pushop.stepsdone.add('changesets')
     # Send known heads to the server for race detection.
+    pushop.stepsdone.add('changesets')
+    if not _pushcheckoutgoing(pushop):
+        return
+    pushop.repo.prepushoutgoinghooks(pushop.repo,
+                                     pushop.remote,
+                                     pushop.outgoing)
     if not pushop.force:
         bundler.newpart('B2X:CHECK:HEADS', data=iter(pushop.remoteheads))
     cg = changegroup.getlocalbundle(pushop.repo, 'push', pushop.outgoing)
     cgpart = bundler.newpart('B2X:CHANGEGROUP', data=cg.getchunks())
     def handlereply(op):
@@ -235,10 +237,13 @@  def _pushbundle2(pushop):
     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
+    if bundler.nbparts <= 1:
+        return
     stream = util.chunkbuffer(bundler.getchunks())
     try:
         reply = pushop.remote.unbundle(stream, ['force'], 'push')
     except error.BundleValueError, exc:
         raise util.Abort('missing support for %s' % exc)
@@ -266,10 +271,15 @@  def _pushbundle2extrareply(pushop, op, e
 def _pushchangeset(pushop):
     """Make the actual push of changeset bundle to remote repo"""
     if 'changesets' in pushop.stepsdone:
         return
     pushop.stepsdone.add('changesets')
+    if not _pushcheckoutgoing(pushop):
+        return
+    pushop.repo.prepushoutgoinghooks(pushop.repo,
+                                     pushop.remote,
+                                     pushop.outgoing)
     outgoing = pushop.outgoing
     unbundle = pushop.remote.capable('unbundle')
     # TODO: get bundlecaps from remote
     bundlecaps = None
     # create a changegroup from local