66 src = Path(argv[1]
if len(argv) > 1
else "src")
70 for path
in sorted((src /
"database").glob(
"*_repository.c")):
71 for name, body
in _functions(path.read_text(encoding=
"utf-8", errors=
"replace")):
72 if "g_list_prepend" in body
and "g_list_reverse" not in body:
73 unreversed[name] = path
76 print(
"OK: no unreversed prepend-built lists leave src/database.")
80 listing = subprocess.run(
81 [
"git",
"ls-files",
"--", f
"{src}/*.c", f
"{src}/*.cc"],
82 capture_output=
True, text=
True, cwd=src.parent
if src.name ==
"src" else None,
84 files = [Path(p)
for p
in listing.stdout.split()
if p
and "/external/" not in p]
86 files = [p
for p
in src.rglob(
"*.c")
if "external" not in p.parts]
87 files += [p
for p
in src.rglob(
"*.cc")
if "external" not in p.parts]
91 if "database" in path.parts:
94 text = path.read_text(encoding=
"utf-8", errors=
"replace")
97 if not any(name
in text
for name
in unreversed):
100 if "g_list_prepend" not in body:
102 for name
in unreversed:
103 if name +
"(" in body:
104 findings.append((name, unreversed[name], path, caller))
107 print(f
"OK: {len(unreversed)} unreversed list(s) leave src/database, none double-prepended.")
110 print(
"FAILED: a repository list is prepended twice -- its order is flipped vs the "
111 "single-loop original.\n")
112 for name, defined_in, path, caller
in findings:
113 print(f
" {name}() [{defined_in}]")
114 print(f
" prepended again by {path}:{caller}()")
115 print(
"\nExactly one of the two must reverse. Reverse in the REPOSITORY (return row order) "
116 "\nand say why in a comment beside the return.")