"""Restore original comparison sources from the preserved upstream commit.""" import hashlib,json,subprocess from pathlib import Path ROOT=Path(__file__).resolve().parents[1] SNAPSHOT='8b8cf72d1fb4de1d05345de8d5b92ec2d500fcd2' def original_sources(name): if name!='coco3-mister':raise ValueError('This repository supports MiSTer only') out=ROOT/'build/source-snapshots'/name entries=subprocess.check_output(['git','ls-tree','-r','-z',SNAPSHOT],cwd=ROOT).split(b'\0') for entry in filter(None,entries): header,name=entry.split(b'\t',1);mode,kind,oid=header.decode().split();name=name.decode() if kind!='blob' or mode not in ('100644','100755'):raise RuntimeError('Unsupported upstream entry') data=subprocess.check_output(['git','show',SNAPSHOT+':'+name],cwd=ROOT) path=out/name if path.exists() and path.read_bytes()!=data:raise RuntimeError('Preserve changed reference cache: '+name) if not path.exists():path.parent.mkdir(parents=True,exist_ok=True);path.write_bytes(data) return out