"""Compare a clean upstream source directory and a tracked Resatoshi export. Usage: python3 compare_whitepaper_fork.py /path/to/bitcoin-32.1 /path/to/fork-export Requires Git. Counts line changes with no rename detection; binary changes count as changed files with zero text lines. Directory inputs must be clean exports. """ import json from pathlib import Path import subprocess import sys EXCLUDED = ('src/crc32c/', 'src/crypto/ctaes/', 'src/ipc/libmultiprocess/', 'src/leveldb/', 'src/minisketch/', 'src/secp256k1/', 'src/univalue/') SELECTED = {'src/consensus/params.h', 'src/consensus/amount.h', 'src/kernel/chainparams.cpp', 'src/pow.cpp', 'src/pow/asert.cpp', 'src/pow/asert.h', 'src/node/recycle.cpp', 'src/node/recycle.h', 'src/validation.cpp', 'src/undo.h'} def compare(upstream, fork): paths = sorted({str(p.relative_to(root)) for root in (upstream, fork) for p in root.rglob('*') if p.is_file()}) totals = {name: {'changed_files': 0, 'added_lines': 0, 'removed_lines': 0} for name in ('all_nonvendor', 'selected_consensus_related_files')} selected_changes = [] for name in paths: if name.startswith(EXCLUDED): continue a, b = upstream / name, fork / name if a.exists() and b.exists() and a.read_bytes() == b.read_bytes(): continue r = subprocess.run(['git', 'diff', '--no-index', '--numstat', '--no-renames', str(a) if a.exists() else '/dev/null', str(b) if b.exists() else '/dev/null'], capture_output=True, text=True) if r.returncode not in (0, 1): raise RuntimeError(r.stderr) if not r.stdout: continue add, remove, _ = r.stdout.split('\t', 2) add, remove = (int(v) if v != '-' else 0 for v in (add, remove)) scopes = ['all_nonvendor'] if name in SELECTED: scopes.append('selected_consensus_related_files') selected_changes.append({'path': name, 'added_lines': add, 'removed_lines': remove}) for scope in scopes: t = totals[scope] t['changed_files'] += 1 t['added_lines'] += add t['removed_lines'] += remove return {'totals': totals, 'selected_paths': sorted(SELECTED), 'selected_changes': selected_changes, 'excluded': list(EXCLUDED)} if __name__ == '__main__': print(json.dumps(compare(Path(sys.argv[1]).resolve(), Path(sys.argv[2]).resolve()), indent=2))