"""Audit docs repo git history: .bru counts per commit + did the 6 missing files ever exist?""" import json import subprocess import sys if sys.stdout.encoding.lower() != "utf-8": sys.stdout.reconfigure(encoding="utf-8") REPO = r"E:\code\crm-api-docs" def git(*args): r = subprocess.run(["git", "-C", REPO, "-c", "core.quotepath=false"] + list(args), capture_output=True) if r.returncode != 0: raise RuntimeError(r.stderr.decode("utf-8", "replace")) return r.stdout.decode("utf-8", "replace") commits = [line.split("|")[0] for line in git("log", "--format=%h|%ci|%s|%d").splitlines()] print(f"commits on HEAD branch: {len(commits)}") target_frag = ("战略协议", "batch-update") for c in commits: files = git("ls-tree", "-r", c, "--name-only").splitlines() bru = [f for f in files if f.endswith(".bru")] hit = [f for f in bru if any(t in f for t in target_frag)] print(f"{c}: {len(bru)} .bru, agreement/batch-update hits: {len(hit)}") for h in hit: print(f" {h}") print("--- fsck dangling/unreachable (lost commits check) ---") fsck = subprocess.run(["git", "-C", REPO, "fsck", "--lost-found"], capture_output=True) out = fsck.stdout.decode("utf-8", "replace") + fsck.stderr.decode("utf-8", "replace") print(out[:2000] if out.strip() else "(no output)") print("--- all refs ---") print(git("for-each-ref", "--format=%(refname:short) %(objectname:short)").strip() or "(none)")