changeset 49325:bf66f7a1e3f8

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 17 May 2022 16:36:32 +0100
parents 61ba04693d65
children 3840d16595cf
files mercurial/bundlecaches.py mercurial/commands.py
diffstat 2 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlecaches.py	Wed May 25 03:16:53 2022 +0200
+++ b/mercurial/bundlecaches.py	Tue May 17 16:36:32 2022 +0100
@@ -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 @@
     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.
--- a/mercurial/commands.py	Wed May 25 03:16:53 2022 +0200
+++ b/mercurial/commands.py	Tue May 17 16:36:32 2022 +0100
@@ -1570,7 +1570,7 @@
             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 @@
     # 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 @@
         fname,
         bversion,
         outgoing,
-        bundlespec.contentopts,
+        bundlespec.params,
         compression=bcompression,
         compopts=compopts,
     )