Commit 13a17b06 authored by Julien Muchembled's avatar Julien Muchembled Committed by Xavier Thompson

[feat] Enable partial support for += / -= with <=

Before this, += and -= worked well when applied to keys defined in the
current section or in a section of the same name inherited from a file
extended by the current file, but not to keys inherited from another
section using macro extension <=, because <= substitution happens later
and all the += and -= are already resolved.

e.g.:

```
[macro]
a = 1

[part]
<= macro
a += 2
```

was equivalent to

```
[part]
a = 1
a = 2
```

instead of

```
[part]
a = 1
a += 2
```

Now a partial and brittle support for this is enabled by postponing
+= and -= resolution until <= substitution happens when the current
section contains a <= extension. But this is not guaranteed: if the
current section is overloaded in another file extending the current
one, then += and -= resolution will happend then, before <=.

A consistent solution would be to unify the implementation of
extends= and <= and update sections by taking both into account,
instead of updating based only on extends and computing <= later,
leading to inconsistencies. This could be achieved e.g. by computing
section updates on demand during substitution.
Co-authored-by: Xavier Thompson's avatarXavier Thompson <xavier.thompson@nexedi.com>
parent da9476d3
...@@ -2047,10 +2047,17 @@ def _update(d1, d2): ...@@ -2047,10 +2047,17 @@ def _update(d1, d2):
if section in d1: if section in d1:
_update_section(d1[section], d2[section]) _update_section(d1[section], d2[section])
else: else:
# In order to process += (and -=) correctly when # XXX: In order to process += (and -=) correctly when
# <key> = <value> and <key> += <value> are in the same section # <key> = <value> and <key> += <value> are in the same section
# _update_section must be called even when section is not in d1 # _update_section should be called even when section is not in d1
d1[section] = _update_section({}, d2[section]) # Hack: When <= is used in the section, _update_section will be
# called later anyway, so we can avoid calling it now which will
# enable brittle and partial support for += (or -=) with keys that
# come from the <= sections.
# TODO: Either implement += and -= support with <= fully or call
# _update_section systematically and give up <= compatibility.
s2 = d2[section]
d1[section] = s2 if '<' in s2 else _update_section({}, s2)
return d1 return d1
def _recipe(options): def _recipe(options):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment