diff mercurial/exchange.py @ 37168:a2b350d9f6ae

bundlespec: add support for some variants This way the stream v2 bundle spec can disable the changegroup part while enabling the stream v2 part. Differential Revision: https://phab.mercurial-scm.org/D1955
author Boris Feld <boris.feld@octobus.net>
date Wed, 31 Jan 2018 11:10:55 +0100
parents 6f467adf9f05
children b837655c1509
line wrap: on
line diff
--- a/mercurial/exchange.py	Wed Jan 31 11:09:20 2018 +0100
+++ b/mercurial/exchange.py	Wed Jan 31 11:10:55 2018 +0100
@@ -76,6 +76,10 @@
 }
 _bundlespeccontentopts['bundle2'] = _bundlespeccontentopts['v2']
 
+_bundlespecvariants = {"streamv2": {"changegroup": False, "streamv2": True,
+                                    "tagsfnodescache": False,
+                                    "revbranchcache": False}}
+
 # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE.
 _bundlespecv1compengines = {'gzip', 'bzip2', 'none'}
 
@@ -206,6 +210,11 @@
     # Compute contentopts based on the version
     contentopts = _bundlespeccontentopts.get(version, {}).copy()
 
+    # Process the variants
+    if "stream" in params and params["stream"] == "v2":
+        variant = _bundlespecvariants["streamv2"]
+        contentopts.update(variant)
+
     if not externalnames:
         engine = util.compengines.forbundlename(compression)
         compression = engine.bundletype()[1]
@@ -281,6 +290,13 @@
                                         'a known bundlespec') % version,
                                       hint=_('try upgrading your Mercurial '
                                               'client'))
+            elif part.type == 'stream2' and version is None:
+                # A stream2 part requires to be part of a v2 bundle
+                version = "v2"
+                requirements = urlreq.unquote(part.params['requirements'])
+                splitted = requirements.split()
+                params = bundle2._formatrequirementsparams(splitted)
+                return 'none-v2;stream=v2;%s' % params
 
         if not version:
             raise error.Abort(_('could not identify changegroup version in '