]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Simplify parse_new_includes()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 7 Jul 2024 13:35:27 +0000 (15:35 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 7 Jul 2024 15:23:13 +0000 (17:23 +0200)
We don't need to keep track of the current amount of includes since
those includes are already tracked in parsed_includes and will be
ignored. Slightly less efficient but this shouldn't matter here.

We also store the inode in parsed_includes before we parse the config
to make sure we don't try to parse it more than once.

mkosi/config.py

index 9716977a0b9db1cb13381aeca2a10b41a1089f00..68b553c3cddf52e4dc0ca237e578d018cf38ba8c 100644 (file)
@@ -3344,13 +3344,11 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
 
     @contextlib.contextmanager
     def parse_new_includes() -> Iterator[None]:
-        current_num_of_includes = len(getattr(namespace, "include", []))
-
         try:
             yield
         finally:
             # Parse any includes that were added after yielding.
-            for p in getattr(namespace, "include", [])[current_num_of_includes:]:
+            for p in getattr(namespace, "include", []):
                 for c in BUILTIN_CONFIGS:
                     if p == Path(c):
                         path = resources / c
@@ -3363,6 +3361,8 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
                 if (st.st_dev, st.st_ino) in parsed_includes:
                     continue
 
+                parsed_includes.add((st.st_dev, st.st_ino))
+
                 if any(p == Path(c) for c in BUILTIN_CONFIGS):
                     _, [config] = parse_config(["--directory", "", "--include", os.fspath(path)])
                     make_executable(
@@ -3378,7 +3378,6 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
 
                 with chdir(path if path.is_dir() else Path.cwd()):
                     parse_config_one(path if path.is_file() else Path("."))
-                parsed_includes.add((st.st_dev, st.st_ino))
 
     class ConfigAction(argparse.Action):
         def __call__(