summaryrefslogtreecommitdiff
path: root/rules
diff options
context:
space:
mode:
authorPierre Le Marre <dev@wismill.eu>2024-08-23 10:48:15 +0200
committerMarge Bot <emma+marge@anholt.net>2024-08-23 14:53:55 +0000
commitd68a1a23f9db06085c4b7f45406c59fb784d3133 (patch)
tree41aea61d33e0f4f4f56a9dadbbd4064a992dfb93 /rules
parent9fc70831ce3cb8d58bded60ab206288555213e53 (diff)
rules: Fix duplicates created by the merge script
The previous update c4f76b584fe10bc2037966a70efad9bc5b682a4a removed the initialization of a dictionary in the `merge` function, leading to duplicates, namely the files *not* starting with a rule header. While we introduced `defaultdict` previously to avoid initializing lists manually, we still need to initialize the `dict` in order to keep it in sync with `section_names`. Part-of: <https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/merge_requests/729>
Diffstat (limited to 'rules')
-rwxr-xr-xrules/merge.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/rules/merge.py b/rules/merge.py
index 868879f3..95e30f7d 100755
--- a/rules/merge.py
+++ b/rules/merge.py
@@ -58,14 +58,17 @@ def merge(dest: TextIO, files):
# sort the file list by basename
files.sort(key=sort_basename)
- # pre-populate with the empty header so it's the first one to be written
+ # Group files by their header
+ # Pre-populate with the empty header so it's the first one to be written
# out. We use section_names to keep the same order as we get the files
# passed in (superfluous with python 3.6+ since the dict keeps the
- # insertion order anyway).
- sections: dict[tuple[str, ...], list[Path]] = defaultdict(list)
+ # insertion order anyway) and the original header text.
section_names = [Header.empty()]
+ sections: dict[tuple[str, ...], list[Path]] = defaultdict(
+ list, ((h.key, []) for h in section_names)
+ )
for path in files:
- # files may exist in srcdir or builddir, depending whether they're
+ # Files may exist in srcdir or builddir, depending whether they're
# generated
header, path = handle_file(path)
if header.key not in sections: