Page MenuHomePhabricator
Paste P9435

compare-meta-refs.py
ActivePublic

Authored by hashar on Oct 22 2019, 1:16 PM.
#!/usr/bin/env python3
import re
import unittest
from collections import defaultdict
def parse_path(path):
# Example:
# ./eventlogging.git/refs/changes/44/544144/meta:b6950bfe08fd59a63dfbcc4ff3b5ecfa5da43dcd
m = re.match('^./(.*)\.git/(.+/meta)$', path)
# (repo, ref)
return (m[1], m[2])
def parse_file(fname):
stuff = defaultdict(dict)
with open(fname) as f:
print("Reading %s" % fname)
for line in f.readlines():
(path, sha1) = line.rstrip().split(':')
(repo, ref) = parse_path(path)
stuff[repo][ref] = sha1
return stuff
refs = {}
repos = set()
for host in ('cobalt', 'gerrit1001'):
refs[host] = parse_file('%s-meta-files.txt' % host)
repos = repos.union(set(refs[host].keys()))
print('Found %s repositories.' % len(repos))
for repo in sorted(repos):
testcase = unittest.TestCase()
testcase.maxDiff = None
try:
testcase.assertDictEqual(refs['cobalt'][repo], refs['gerrit1001'][repo])
except AssertionError as e:
print("FAIL %s: %s" % (repo, e))
pass
else:
print("OK %s" % repo)