changeset 49331:1b04d5213d0f

bundlespec: add processing of some parameter value The boolean option needs to be turned into boolean.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 18 May 2022 10:38:11 +0100
parents 5d17dd74177d
children d89bfc075289
files mercurial/bundlecaches.py tests/test-obsolete-bundle-strip.t
diffstat 2 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlecaches.py	Wed May 18 10:06:43 2022 +0100
+++ b/mercurial/bundlecaches.py	Wed May 18 10:38:11 2022 +0100
@@ -102,6 +102,24 @@
 _bundlespecv1compengines = {b'gzip', b'bzip2', b'none'}
 
 
+def param_bool(key, value):
+    """make a boolean out of a parameter value"""
+    b = stringutil.parsebool(value)
+    if b is None:
+        msg = _(b"parameter %s should be a boolean ('%s')")
+        msg %= (key, value)
+        raise error.InvalidBundleSpecification(msg)
+    return b
+
+
+# mapping of known parameter name need their value processed
+bundle_spec_param_processing = {
+    b"obsolescence": param_bool,
+    b"obsolescence-mandatory": param_bool,
+    b"phases": param_bool,
+}
+
+
 def _parseparams(s):
     """parse bundlespec parameter section
 
@@ -124,6 +142,9 @@
         key, value = p.split(b'=', 1)
         key = urlreq.unquote(key)
         value = urlreq.unquote(value)
+        process = bundle_spec_param_processing.get(key)
+        if process is not None:
+            value = process(key, value)
         params[key] = value
 
     return version, params
--- a/tests/test-obsolete-bundle-strip.t	Wed May 18 10:06:43 2022 +0100
+++ b/tests/test-obsolete-bundle-strip.t	Wed May 18 10:38:11 2022 +0100
@@ -1498,9 +1498,6 @@
   1 changesets found
   $ hg debugbundle bundle-type-without-obs --part-type obsmarkers
   Stream params: {Compression: BZ}
-  obsmarkers -- {} (mandatory: True) (known-bad-output !)
-      version: 1 (50 bytes) (known-bad-output !)
-      1ea73414a91b0920940797d8fc6a11e447f8ea1e 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} (known-bad-output !)
 
 Test bundlespec overwrite local config
 --------------------------------------
@@ -1516,6 +1513,3 @@
   1 changesets found
   $ hg debugbundle bundle-type-without-obs2 --part-type obsmarkers
   Stream params: {Compression: BZ}
-  obsmarkers -- {} (mandatory: True) (known-bad-output !)
-      version: 1 (50 bytes) (known-bad-output !)
-      1ea73414a91b0920940797d8fc6a11e447f8ea1e 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} (known-bad-output !)