bundle2-push: move changegroup push validation inside _pushb2ctx
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 02 Jul 2014 12:55:09 +0200
changeset 21903 48f61cfb7576
parent 21902 7a7def851ba0
child 21904 5fbccbcc07ea
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.
mercurial/exchange.py
--- a/mercurial/exchange.py	Mon Jul 07 12:30:31 2014 +0200
+++ b/mercurial/exchange.py	Wed Jul 02 12:55:09 2014 +0200
@@ -131,15 +131,11 @@
             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)
@@ -214,6 +210,12 @@
         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)
@@ -237,6 +239,9 @@
     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')
@@ -268,6 +273,11 @@
     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