Patchwork [3,of,5] getbundle: send highest changegroup format supported by both side

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 4, 2014, 2:20 p.m.
Message ID <514f8b2f466377bca8ee.1415110846@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6559/
State Accepted
Headers show

Comments

Pierre-Yves David - Nov. 4, 2014, 2:20 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1413550750 -7200
#      Fri Oct 17 14:59:10 2014 +0200
# Node ID 514f8b2f466377bca8eea987c67e33eb415586e9
# Parent  4704aafc725bb0eb2f4f6bed459760f54e2c3f65
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.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1184,15 +1184,30 @@  def _getbundlechangegrouppart(bundler, r
                               b2caps=None, heads=None, common=None, **kwargs):
     """add a changegroup part to the requested bundle"""
     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,
                             b2caps=None, **kwargs):
     """add parts containing listkeys namespaces to the requested bundle"""