diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -80,6 +80,14 @@ def readbundle(ui, fh, fname, vfs=None): ) +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 @@ def getbundlespec(ui, fh): except KeyError: return None + params = {} + b = readbundle(ui, fh, None) if isinstance(b, changegroup.cg1unpacker): alg = b._type @@ -115,9 +125,12 @@ def getbundlespec(ui, fh): 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 @@ def getbundlespec(ui, fh): 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) diff --git a/tests/test-bundle-type.t b/tests/test-bundle-type.t --- a/tests/test-bundle-type.t +++ b/tests/test-bundle-type.t @@ -265,6 +265,4 @@ Test controlling the changegroup version changegroup -- {nbchanges: 1, version: 03} (mandatory: True) c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf $ hg debugbundle ./v2-cg-03.hg --spec - abort: changegroup version 03 does not have a known bundlespec (known-bad-output !) - (try upgrading your Mercurial client) (known-bad-output !) - [255] + bzip2-v2;cg.version=03