changeset 24649:2d15c59a001b

bundle2: detect bundle2 stream/request on /HG2./ instead of /HG2Y/ To support more bundle2 formats, we need a wider detection of bundle2-family streams. The various places what were explicitly detecting the full magic string are now matching on the first three characters of it.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 07 Apr 2015 16:01:32 -0700
parents 5cac3accdaa1
children b83a8f512a80
files mercurial/exchange.py mercurial/wireproto.py
diffstat 2 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/exchange.py	Mon Apr 06 17:23:11 2015 -0700
+++ b/mercurial/exchange.py	Tue Apr 07 16:01:32 2015 -0700
@@ -32,7 +32,7 @@
         if alg is None:
             alg = changegroup.readexactly(fh, 2)
         return changegroup.cg1unpacker(fh, alg)
-    elif version == '2Y':
+    elif version.startswith('2'):
         return bundle2.getunbundler(ui, fh, header=magic + version)
     else:
         raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
@@ -1168,7 +1168,10 @@
     when the API of bundle is refined.
     """
     # bundle10 case
-    if bundlecaps is None or 'HG2Y' not in bundlecaps:
+    usebundle2 = False
+    if bundlecaps is not None:
+        usebundle2 = util.any((cap.startswith('HG2') for cap in bundlecaps))
+    if not usebundle2:
         if bundlecaps and not kwargs.get('cg', True):
             raise ValueError(_('request for bundle10 must include changegroup'))
 
--- a/mercurial/wireproto.py	Mon Apr 06 17:23:11 2015 -0700
+++ b/mercurial/wireproto.py	Tue Apr 07 16:01:32 2015 -0700
@@ -363,7 +363,9 @@
             opts[key] = value
         f = self._callcompressable("getbundle", **opts)
         bundlecaps = kwargs.get('bundlecaps')
-        if bundlecaps is not None and 'HG2Y' in bundlecaps:
+        if bundlecaps is None:
+            bundlecaps = () # kwargs could have it to None
+        if util.any((cap.startswith('HG2') for cap in bundlecaps)):
             return bundle2.getunbundler(self.ui, f)
         else:
             return changegroupmod.cg1unpacker(f, 'UN')