diff hgext/evolve.py @ 957:2cde59f3cb5d

evolve: add a push pass using bundle2 Instead of using a dedicated wireprotocol commands, we use bundle2 to transmit an obs marker parts. This aims at both testing bundle2 more and to limit the amount of special code we needs to put in simple for server to fit our needs. The massive test changes comes from the fact we can use this fast path for both remote and local push.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 20 May 2014 13:41:27 -0700
parents b107f3549ec2
children 6d18a1ab496c
line wrap: on
line diff
--- a/hgext/evolve.py	Mon Jun 02 14:44:13 2014 -0700
+++ b/hgext/evolve.py	Tue May 20 13:41:27 2014 -0700
@@ -66,6 +66,7 @@
 from mercurial import wireproto
 from mercurial import localrepo
 from mercurial.hgweb import hgweb_mod
+from mercurial import bundle2
 
 _pack = struct.pack
 
@@ -2275,6 +2276,26 @@
             markers = []
         if not markers:
             repo.ui.status("OBSEXC: no marker to push\n")
+        elif remote.capable('_evoext_b2x_obsmarkers_0_pushonly'):
+            obsdata = StringIO()
+            _encodemarkersstream(obsdata, markers)
+            obsdata.seek(0)
+            repo.ui.status("OBSEXC: pushing %i markers (%i bytes)\n"
+                           % (len(markers), len(obsdata.getvalue())))
+            bundler = bundle2.bundle20(pushop.ui, {})
+            capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
+            bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsblob))
+            cgpart = bundle2.bundlepart('EVOLVE:B2X:OBSMARKERV1', data=obsdata.getvalue())
+            bundler.addpart(cgpart)
+            stream = util.chunkbuffer(bundler.getchunks())
+            try:
+                reply = pushop.remote.unbundle(stream, ['force'], 'push')
+            except bundle2.UnknownPartError, exc:
+                raise util.Abort('missing support for %s' % exc)
+            try:
+                op = bundle2.processbundle(pushop.repo, reply)
+            except bundle2.UnknownPartError, exc:
+                raise util.Abort('missing support for %s' % exc)
         elif remote.capable('_evoext_pushobsmarkers_0'):
             obsdata = pushobsmarkerStringIO()
             _encodemarkersstream(obsdata, markers)
@@ -2348,6 +2369,12 @@
     repo.hook('evolve_pushobsmarkers')
     return wireproto.pushres(0)
 
+@bundle2.parthandler('evolve:b2x:obsmarkerv1')
+def handleobsmarkerv1(op, inpart):
+    """add a stream of obsmarker to the repo"""
+    tr = op.gettransaction()
+    op.repo.obsstore.mergemarkers(tr, inpart.read())
+
 def _buildpullobsmerkersboundaries(pullop):
     """small funtion returning the argument for pull markers call
     may to contains 'heads' and 'common'. skip the key for None.
@@ -2582,12 +2609,14 @@
         caps += ' _evoext_pushobsmarkers_0'
         caps += ' _evoext_pullobsmarkers_0'
         caps += ' _evoext_obshash_0'
+        caps += ' _evoext_b2x_obsmarkers_0_pushonly'
     return caps
 
 
 @eh.extsetup
 def _installwireprotocol(ui):
     localrepo.moderncaps.add('_evoext_pullobsmarkers_0')
+    localrepo.moderncaps.add('_evoext_b2x_obsmarkers_0_pushonly')
     hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
     hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
     hgweb_mod.perms['evoext_obshash'] = 'pull'