Last active
June 30, 2020 18:21
-
-
Save stantonk/6709967 to your computer and use it in GitHub Desktop.
Diff two repositories, file by file, to verify they're the same. Output all diffs if there are any. Written out of our mutual distrust of destructive, history-modifying mercurial extensions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# authors: @stantonk, @salubriousdave | |
import os | |
import sys | |
import subprocess | |
def is_hg_repo(path): | |
hgchkpath = os.path.join(path, '.hg') | |
return os.path.exists(hgchkpath) | |
def in_ignore_list(filename): | |
ignorelist = ('.pyc', '.txt', 'Makefile', 'settings_local.py', '.venv') | |
for i in ignorelist: | |
if i in filename: | |
return True | |
return False | |
def get_rel_paths(repo_root): | |
cwd = os.getcwd() | |
os.chdir(repo_root) | |
inner_path = '.' | |
if not is_hg_repo(inner_path): | |
print 'not hg repo' | |
sys.exit(1) | |
filebag = set() | |
for dirname, _, files in os.walk(inner_path): | |
if '/.hg' in dirname: | |
continue | |
for f in files: | |
if in_ignore_list(f): | |
continue | |
filebag.add(os.path.join(dirname, f)) | |
os.chdir(cwd) | |
return filebag | |
def mash_paths(root, fpath): | |
return root + fpath | |
def files_same(a, b): | |
args = ['diff', a, b] | |
rc = subprocess.call(args, stderr=subprocess.STDOUT) | |
return not bool(rc) | |
if __name__ == '__main__': | |
repo_a_root, repo_b_root = sys.argv[1:3] | |
repo_a_files = get_rel_paths(repo_a_root) | |
repo_b_files = get_rel_paths(repo_b_root) | |
if repo_a_files != repo_b_files: | |
print 'omergerddd ddiediedie' | |
diff = repo_a_files - repo_b_files | |
if diff: | |
print 'a vs b:' | |
for d in diff: | |
print d | |
diff = repo_b_files - repo_a_files | |
if diff: | |
print 'b vs a:' | |
for d in diff: | |
print d | |
print 'error: differences!' | |
sys.exit(1) | |
failures = [] | |
for f in repo_a_files: | |
if not files_same(mash_paths(repo_a_root, f), mash_paths(repo_b_root, f)): | |
failures.append(f) | |
if not failures: | |
print 'repositories are exactly the same' | |
else: | |
for f in failures: | |
print 'not same: %s' % f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment