[PATCH 2 of 3] bundle2: detect bundle2 stream/request on /HG2./ instead of /HG20/

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Apr 7 16:09:41 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1428367164 25200
#      Mon Apr 06 17:39:24 2015 -0700
# Node ID 877b5ed6bd636447ef8701b36e73d5e2b356e9b2
# Parent  e176f57dbf891662f7e63773d7f186772162ad80
bundle2: detect bundle2 stream/request on /HG2./ instead of /HG20/

To support more bundle2 formats, we need a wider detection of bundle2-family
stream. The various place what were explicitly detecting the full magic string
are now matching on the first three characters of it.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -30,11 +30,11 @@ def readbundle(ui, fh, fname, vfs=None):
         raise util.Abort(_('%s: not a Mercurial bundle') % fname)
     if version == '10':
         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))
 
 def buildobsmarkerspart(bundler, markers):
@@ -1166,11 +1166,17 @@ def getbundle(repo, source, heads=None, 
 
     The implementation is at a very early stage and will get massive rework
     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:
+        for cap in bundlecaps:
+            if cap.startswith('HG2'):
+                usebundle2 = True
+                break
+    if not usebundle2:
         if bundlecaps and not kwargs.get('cg', True):
             raise ValueError(_('request for bundle10 must include changegroup'))
 
         if kwargs:
             raise ValueError(_('unsupported getbundle arguments: %s')
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -361,12 +361,15 @@ class wirepeer(peer.peerrepository):
                 raise KeyError('unknown getbundle option type %s'
                                % keytype)
             opts[key] = value
         f = self._callcompressable("getbundle", **opts)
         bundlecaps = kwargs.get('bundlecaps')
-        if bundlecaps is not None and 'HG2Y' in bundlecaps:
-            return bundle2.getunbundler(self.ui, f)
+        if bundlecaps is None:
+            bundlecaps = () # kwargs could have it to None
+        for cap in bundlecaps:
+            if cap.startswith('HG2'):
+                return bundle2.getunbundler(self.ui, f)
         else:
             return changegroupmod.cg1unpacker(f, 'UN')
 
     def unbundle(self, cg, heads, source):
         '''Send cg (a readable file-like object representing the


More information about the Mercurial-devel mailing list