]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Replace `!` operator for lists with empty string assignment
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Sep 2023 08:57:34 +0000 (10:57 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Sep 2023 08:57:34 +0000 (10:57 +0200)
Let's behave more like systemd and replace the `!` operator for
removing values from lists with assigning the empty string to remove
all values instead.

NEWS.md
mkosi/config.py
mkosi/resources/mkosi.md

diff --git a/NEWS.md b/NEWS.md
index e2f7bc0a61983d081ec1c394074a61de56a4fbba..a371a37e91dde0a381acfa5141716ac777df824f 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -4,11 +4,11 @@
 
 - `mkosi.version` is now picked up from preset and dropin directories as
   well following the usual config precedence logic
-- The "first assignment wins" logic was dropped from configuration
-  parsing. Settings parsed later will now override earlier values and
-  the `!` operator for lists will now remove values already in the list
-  instead of preventing specific values from being added.
-- Add support for configuring custom default values for settings by
+- Removed the "first assignment wins" logic from configuration parsing.
+  Settings parsed later will now override earlier values
+- Removed the `!` operator for lists. Instead, assign the empty string
+  to the list to remove all previous values.
+- Added support for configuring custom default values for settings by
   prefixing their name in the configuration file with `@`.
 
 ## v15.1
index 5a307c35ea3f13195d79ed269d5f41cd3d7f2d0d..4fb7ae9086ac089a3dc1ccb79388f345905b62f3 100644 (file)
@@ -360,7 +360,6 @@ def config_make_list_parser(delimiter: str,
     def config_parse_list(value: Optional[str], old: Optional[list[Any]]) -> list[Any]:
         new = old.copy() if old else []
 
-        # Empty strings reset the list.
         if value is None:
             return []
 
@@ -373,17 +372,11 @@ def config_make_list_parser(delimiter: str,
         else:
             values = value.replace(delimiter, "\n").split("\n")
 
-        for v in values:
-            if not v:
-                continue
-
-            if v.startswith("!"):
-                v = v[1:]
-                new = [n for n in new if not fnmatch.fnmatchcase(str(n), v)]
-            else:
-                new.append(parse(v))
+        # Empty strings reset the list.
+        if len(values) == 1 and values[0] == "":
+            return []
 
-        return new
+        return new + [parse(v) for v in values if v]
 
     return config_parse_list
 
index 58caa75877c6c7bb586aabdb72dfb71cdff71284..5670c85c9b89000720fba20039f1bad09d5f77ff 100644 (file)
@@ -269,10 +269,8 @@ setting. Also note that before v16, we used to do the opposite, where
 the earlier assignment would be used instead of later assignments.
 
 Settings that take a list of values are merged by appending the new
-values to the previously configured values. If a value of a list setting
-is prefixed with `!`, all existing instances of that value in the list
-are removed. Values prefixed with `!` can be globs to remove more than
-one value.
+values to the previously configured values. Assigning the empty string
+to such a setting removes all previously assigned values.
 
 If a setting's name in the configuration file is prefixed with `@`, it
 configures the default value used for that setting if no explicit