File size: 1,837 Bytes
15c46ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """Regenerate source checksums and the small vendor patch from the pinned checkout."""
import difflib
import hashlib
import json
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from settings import UPSTREAM_COMMIT
def git(*args):
return subprocess.check_output(["git", "-C", str(ROOT / "upstream"), *args])
if __name__ == "__main__":
if git("rev-parse", "HEAD").decode().strip() != UPSTREAM_COMMIT:
raise SystemExit("Unexpected upstream checkout revision.")
prefix = "NExT-GPT-Lagacy/"
paths = git("ls-tree", "-r", "--name-only", "HEAD", prefix).decode().splitlines()
hashes, changes = {}, []
for path in paths:
relative = path[len(prefix):]
original = git("show", "HEAD:" + path)
hashes[relative] = hashlib.sha256(original).hexdigest()
local = (ROOT / "vendor" / "nextgpt" / relative).read_bytes()
if relative.endswith(".py"):
before = original.decode("utf-8").replace("\r\n", "\n")
after = local.decode("utf-8").replace("\r\n", "\n")
changes.extend(difflib.unified_diff(before.splitlines(True), after.splitlines(True),
fromfile="a/vendor/nextgpt/"+relative,
tofile="b/vendor/nextgpt/"+relative))
manifest = dict(project="nextgpt-chapter6-reproduction", upstream="https://github.com/NExT-GPT/NExT-GPT",
commit=UPSTREAM_COMMIT, directory=prefix.rstrip("/"), original_sha256=hashes)
(ROOT / "provenance.json").write_bytes((json.dumps(manifest, indent=2)+"\n").encode())
(ROOT / "vendor-patches.diff").write_bytes("".join(changes).encode())
print(f"Recorded {len(paths)} upstream files; {len(changes)} patch lines.")
|