mercurial/exchange.py
changeset 49334 6d15a8971e30
parent 48946 642e31cb55f0
child 49335 04cdb442a892
--- a/mercurial/exchange.py	Wed May 18 11:55:21 2022 +0100
+++ b/mercurial/exchange.py	Wed May 18 12:07:50 2022 +0100
@@ -80,6 +80,14 @@
         )
 
 
+def _format_params(params):
+    parts = []
+    for key, value in sorted(params.items()):
+        value = urlreq.quote(value)
+        parts.append(b"%s=%s" % (key, value))
+    return b';'.join(parts)
+
+
 def getbundlespec(ui, fh):
     """Infer the bundlespec from a bundle file handle.
 
@@ -93,6 +101,8 @@
         except KeyError:
             return None
 
+    params = {}
+
     b = readbundle(ui, fh, None)
     if isinstance(b, changegroup.cg1unpacker):
         alg = b._type
@@ -115,9 +125,12 @@
         version = None
         for part in b.iterparts():
             if part.type == b'changegroup':
-                version = part.params[b'version']
-                if version in (b'01', b'02'):
+                cgversion = part.params[b'version']
+                if cgversion in (b'01', b'02'):
                     version = b'v2'
+                elif cgversion in (b'03',):
+                    version = b'v2'
+                    params[b'cg.version'] = cgversion
                 else:
                     raise error.Abort(
                         _(
@@ -138,8 +151,12 @@
             raise error.Abort(
                 _(b'could not identify changegroup version in bundle')
             )
-
-        return b'%s-%s' % (comp, version)
+        spec = b'%s-%s' % (comp, version)
+        if params:
+            spec += b';'
+            spec += _format_params(params)
+        return spec
+
     elif isinstance(b, streamclone.streamcloneapplier):
         requirements = streamclone.readbundle1header(fh)[2]
         formatted = bundle2._formatrequirementsparams(requirements)