okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-1402-y' into f-14025af104b51

main
2.4 KiB37 linesraw
1# merge_sel.py BASE_OUT NEW_OUT OLD_REV NEW_REV: 3-way merge into sycl/ of the files upstream changed OLD_REV..NEW_REV
2import re, subprocess, sys, os, shutil
3B, N, old, new = sys.argv[1:5]
4pat = re.compile(r"\b([A-Za-z0-9_]+)_([0-9a-f]{6})\b")
5H = lambda t: pat.sub(lambda m: m.group(1) + "_HASH", t)
6def hashes(t):
7    m = {}
8    for a, h in pat.findall(t): m.setdefault(a, set()).add(h)
9    return {a: next(iter(v)) for a, v in m.items() if len(v) == 1}
10changed = subprocess.check_output(["git", "diff", "--name-only", old, new, "--", "src", "include"], text=True).split()
11HAND = {"src/core/mtp.cpp", "src/core/verify.cpp", "src/ngram/ple_reader.cpp", "src/kernels/native_expert_parity.cpp"}
12for f in changed:
13    rel = f[:-3] + ".dp.cpp" if f.endswith(".cu") else f
14    pf = "sycl/" + rel
15    if f in HAND:
16        if not os.path.exists(pf): print("HAND-MISSING", f); continue
17        open("/tmp/_b", "w").write(subprocess.check_output(["git", "show", f"{old}:{f}"], text=True))
18        open("/tmp/_n", "w").write(subprocess.check_output(["git", "show", f"{new}:{f}"], text=True))
19        r = subprocess.run(["git", "merge-file", "-L", "port", "-L", "base", "-L", "new", pf, "/tmp/_b", "/tmp/_n"]).returncode
20        print("HAND", "MERGED" if r == 0 else f"CONFLICT {r}", rel); continue
21    bf, nf = f"{B}/{rel}", f"{N}/{rel}"
22    if not os.path.exists(nf):
23        print("NOT-MIGRATED (original used)" if not os.path.exists(pf) else "PORT-HAS-NO-DPCT?", rel); continue
24    nt = open(nf).read()
25    if not os.path.exists(pf):
26        os.makedirs(os.path.dirname(pf), exist_ok=True); os.makedirs(os.path.dirname(pf), exist_ok=True); shutil.copy(nf, pf); print("NEWCOPY", rel); continue
27    if not os.path.exists(bf):
28        print("NO-BASE (new to dpct output)", rel); continue
29    bt = open(bf).read()
30    if H(bt) == H(nt): print("NOCHANGE-after-dpct", rel); continue
31    pt = open(pf).read(); ph = hashes(pt); bh = hashes(bt)
32    nt = pat.sub(lambda m: f"{m.group(1)}_{bh[m.group(1)]}" if m.group(1) in bh else m.group(0), nt)
33    canon = lambda t: pat.sub(lambda m: f"{m.group(1)}_{ph[m.group(1)]}" if m.group(1) in ph else m.group(0), t)
34    bt, nt = canon(bt), canon(nt)
35    open("/tmp/_b", "w").write(bt); open("/tmp/_n", "w").write(nt)
36    r = subprocess.run(["git", "merge-file", "-L", "port", "-L", "base", "-L", "new", pf, "/tmp/_b", "/tmp/_n"]).returncode
37    print("MERGED" if r == 0 else f"CONFLICT {r}", rel)