diff --git a/mercurial/bundlecaches.py b/mercurial/bundlecaches.py --- a/mercurial/bundlecaches.py +++ b/mercurial/bundlecaches.py @@ -3,6 +3,8 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. +import collections + from .i18n import _ from .thirdparty import attr @@ -26,8 +28,25 @@ class bundlespec: wirecompression = attr.ib() version = attr.ib() wireversion = attr.ib() - params = attr.ib() - contentopts = attr.ib() + # parameters explicitly overwritten by the config or the specification + _explicit_params = attr.ib() + # default parameter for the version + # + # Keeping it separated is useful to check what was actually overwritten. + _default_opts = attr.ib() + + @property + def params(self): + return collections.ChainMap(self._explicit_params, self._default_opts) + + @property + def contentopts(self): + # kept for Backward Compatibility concerns. + return self.params + + def set_param(self, key, value): + """overwrite a parameter value""" + self._explicit_params[key] = value # Maps bundle version human names to changegroup versions. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1570,7 +1570,7 @@ def bundle(ui, repo, fname, *dests, **op pycompat.bytestr(e), hint=_(b"see 'hg help bundlespec' for supported values for --type"), ) - cgversion = bundlespec.contentopts[b"cg.version"] + cgversion = bundlespec.params[b"cg.version"] # Packed bundles are a pseudo bundle format for now. if cgversion == b's1': @@ -1680,14 +1680,12 @@ def bundle(ui, repo, fname, *dests, **op # Bundling of obsmarker and phases is optional as not all clients # support the necessary features. cfg = ui.configbool - contentopts = { - b'obsolescence': cfg(b'experimental', b'evolution.bundle-obsmarker'), - b'obsolescence-mandatory': cfg( - b'experimental', b'evolution.bundle-obsmarker:mandatory' - ), - b'phases': cfg(b'experimental', b'bundle-phases'), - } - bundlespec.contentopts.update(contentopts) + obsolescence_cfg = cfg(b'experimental', b'evolution.bundle-obsmarker') + bundlespec.set_param(b'obsolescence', obsolescence_cfg) + obs_mand_cfg = cfg(b'experimental', b'evolution.bundle-obsmarker:mandatory') + bundlespec.set_param(b'obsolescence-mandatory', obs_mand_cfg) + phases_cfg = cfg(b'experimental', b'bundle-phases') + bundlespec.set_param(b'phases', phases_cfg) bundle2.writenewbundle( ui, @@ -1696,7 +1694,7 @@ def bundle(ui, repo, fname, *dests, **op fname, bversion, outgoing, - bundlespec.contentopts, + bundlespec.params, compression=bcompression, compopts=compopts, )