104 lines
4.0 KiB
Python
104 lines
4.0 KiB
Python
"Acquire necessary pinned text only; no upstream imports or execution."
|
|
|
|
import datetime
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
OUT = Path(__file__).resolve().parent
|
|
REF = OUT.parent / "zimage-reverse-reference"
|
|
|
|
|
|
def main():
|
|
REF.mkdir(parents=True, exist_ok=True)
|
|
rows = []
|
|
specs = [("core19", "Comfy-Org/ComfyUI", "v0.19.0", ["nodes.py", "folder_paths.py", "LICENSE"])]
|
|
for key, repo, tag, files in specs:
|
|
cache = ROOT / ".local-evidence" / ("zimage-reverse-" + key + "-git")
|
|
cache.mkdir(parents=True, exist_ok=True)
|
|
subprocess.run(["git", "init", "--bare", str(cache)], check=True, stdout=subprocess.DEVNULL)
|
|
subprocess.run(
|
|
[
|
|
"git",
|
|
"-C",
|
|
str(cache),
|
|
"fetch",
|
|
"--filter=blob:none",
|
|
"--depth=1",
|
|
"https://github.com/" + repo + ".git",
|
|
("refs/tags/" + tag) if tag.startswith("v") else tag,
|
|
],
|
|
check=True,
|
|
)
|
|
|
|
def git(*args):
|
|
return subprocess.check_output(["git", "-C", str(cache), *args])
|
|
|
|
rev = git("rev-parse", "FETCH_HEAD^{commit}").decode().strip()
|
|
tree = git("rev-parse", rev + "^{tree}").decode().strip()
|
|
(REF / (key + "-commit.txt")).write_bytes(git("cat-file", "commit", rev))
|
|
(REF / (key + "-tag.txt")).write_bytes(git("cat-file", "-p", "FETCH_HEAD"))
|
|
(REF / (key + "-tag.json")).write_text(
|
|
json.dumps(
|
|
dict(
|
|
ref=("refs/tags/" + tag) if tag.startswith("v") else tag,
|
|
commit=rev,
|
|
object=git("rev-parse", "FETCH_HEAD").decode().strip(),
|
|
),
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
entries = []
|
|
for line in git("ls-tree", "-r", rev).decode().splitlines():
|
|
head, path = line.split("\t", 1)
|
|
mode, kind, sha = head.split()
|
|
entries.append(dict(path=path, mode=mode, type=kind, sha=sha))
|
|
(REF / (key + "-tree.json")).write_text(
|
|
json.dumps(dict(sha=tree, truncated=False, tree=entries), indent=2) + "\n"
|
|
)
|
|
missing = []
|
|
for f in files:
|
|
ent = next((x for x in entries if x["path"] == f), None)
|
|
if ent is None:
|
|
missing.append(f)
|
|
continue
|
|
raw = git("show", rev + ":" + f)
|
|
name = key + "__" + f.replace("/", "__")
|
|
(REF / name).write_bytes(raw)
|
|
rows.append(
|
|
dict(
|
|
id=key,
|
|
repo=repo,
|
|
file=f,
|
|
local_file=name,
|
|
commit=rev,
|
|
tree=tree,
|
|
tag=tag,
|
|
url=f"https://raw.githubusercontent.com/{repo}/{rev}/{f}",
|
|
sha256=hashlib.sha256(raw).hexdigest(),
|
|
git_blob_sha1=ent["sha"],
|
|
acquisition_time=datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
license_file=key + ("__LICENSE.txt" if key == "dw" else "__LICENSE"),
|
|
transport="filtered git; selected text blobs only",
|
|
applicability="准确声明版本或显式参考假设;身份适用按本批定义分列,UE恢复未知",
|
|
)
|
|
)
|
|
(REF / (key + "-absent.json")).write_text(json.dumps(missing, indent=2) + "\n")
|
|
for e in rows:
|
|
e.update(identity_root=".", identity_key=e["id"])
|
|
if e["id"] == "literals":
|
|
e["license_file"] = "未知:准确完整树无LICENSE文本"
|
|
(REF / "sources.json").write_text(
|
|
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
(REF / "new-sources.json").write_text(
|
|
json.dumps(dict(sources=rows), ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|