getbundle: send highest changegroup format supported by both side
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 17 Oct 2014 14:59:10 +0200
changeset 23179 6bb9533fa8fa
parent 23178 5e895ed5e955
child 23180 116b80d63815
getbundle: send highest changegroup format supported by both side When using bundle2, we find the common subset of supported changegroup-packers and we pick the max of them. This allow to use generaldelta aware changegroup through bundle2.
mercurial/exchange.py
--- a/mercurial/exchange.py	Fri Oct 17 14:41:21 2014 +0200
+++ b/mercurial/exchange.py	Fri Oct 17 14:59:10 2014 +0200
@@ -1186,11 +1186,26 @@
     cg = None
     if kwargs.get('cg', True):
         # build changegroup bundle here.
-        cg = changegroup.getchangegroupraw(repo, source, heads=heads,
-                                           common=common, bundlecaps=bundlecaps)
+        version = None
+        cgversions = b2caps.get('b2x:changegroup')
+        if cgversions is None:
+            cg = changegroup.getchangegroupraw(repo, source, heads=heads,
+                                               common=common,
+                                               bundlecaps=bundlecaps)
+        else:
+            cgversions = [v for v in cgversions if v in changegroup.packermap]
+            if not cgversions:
+                raise ValueError(_('no common changegroup version'))
+            version = max(cgversions)
+            cg = changegroup.getchangegroupraw(repo, source, heads=heads,
+                                               common=common,
+                                               bundlecaps=bundlecaps,
+                                               version=version)
 
     if cg:
-        bundler.newpart('b2x:changegroup', data=cg)
+        part = bundler.newpart('b2x:changegroup', data=cg)
+        if version is not None:
+            part.addparam('version', version)
 
 @getbundle2partsgenerator('listkeys')
 def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,