# HG changeset patch # User Pierre-Yves David # Date 2022-05-17 15:36:32 # Node ID bf66f7a1e3f88b16666d1d2ded8a27136e0b50b5 # Parent 61ba04693d651fb6f2730dcc9d936c85f8776af2 bundlespec: merge the contentopts and params dictionnary They are content using the same keys. Using differents object for access open the gates for confusion in the code using them (this is already the case). So we start fusing their usages to make the parameters more useful. More work will be needed to make them really useful, but the first step is here: not throwing the value away. However this is still not making the previously introduced test useful because currently, the default config value overwrite the one from the bundlespec. We will fix this in the coming changesets. 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, )