Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#!/usr/bin/env python3"""Oracle: the system git's patches (git diff-tree -p) of the trees of themerge corpus, under each of its diff algorithms.
The merge corpus (../../merge/traces) holds, for each case, the base, oursand theirs trees and every object under them. For each case git diff-tree -p-r --full-index writes the patch of base into ours and of base into theirs,with --diff-algorithm=myers (git diff's default) and with--diff-algorithm=histogram (git merge's), the indent heuristic on asdiff.indentHeuristic leaves it by default. The traces are:
myers.patches one record per case and side: a line "<case name>\\t<ours|theirs>\\t<old tree>\\t<new tree>\\t<bytes>", then the patch, that many bytes; a patch is named by its trees, as two cases can share a name histogram.patches the records of the patches histogram writes otherwise than myers, in the same form; any other patch is myers' git-version the git that wrote them
Output goes to argv[1]."""import csvimport osimport shutilimport subprocessimport sysimport tempfile
HERE = os.path.dirname(os.path.abspath(__file__))CORPUS = os.path.join(HERE, "..", "..", "merge", "traces")ALGORITHMS = ("myers", "histogram")
def run(args, input=None): r = subprocess.run(args, input=input, capture_output=True) if r.returncode != 0: sys.exit("%s: exit %d\n%s" % (" ".join(args), r.returncode, r.stderr.decode())) return r.stdout
def main(out): with tempfile.TemporaryDirectory(prefix="diff-interop.") as work: repo = os.path.join(work, "corpus.git") run(["git", "init", "-q", "--bare", repo]) pack = os.path.join(repo, "objects", "pack") shutil.copy(os.path.join(CORPUS, "corpus.pack"), os.path.join(pack, "pack-corpus.pack")) shutil.copy(os.path.join(CORPUS, "corpus.idx"), os.path.join(pack, "pack-corpus.idx")) with open(os.path.join(CORPUS, "cases.csv"), newline="") as f: cases = list(csv.DictReader(f)) files = {a: open(os.path.join(out, "%s.patches" % a), "wb") for a in ALGORITHMS} try: for case in cases: for side in ("ours", "theirs"): patches = {a: run(["git", "-C", repo, "diff-tree", "-p", "-r", "--full-index", "--diff-algorithm=" + a, case["base"], case[side]]) for a in ALGORITHMS} for a in ALGORITHMS: if a != "myers" and patches[a] == patches["myers"]: continue files[a].write(("%s\t%s\t%s\t%s\t%d\n" % ( case["name"], side, case["base"], case[side], len(patches[a]))).encode()) files[a].write(patches[a]) finally: for f in files.values(): f.close() with open(os.path.join(out, "git-version"), "wb") as f: f.write(run(["git", "--version"]))
if __name__ == "__main__": main(os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else os.path.join(HERE, "..", "traces")))