summaryrefslogtreecommitdiff
path: root/check_reverts.py
diff options
context:
space:
mode:
Diffstat (limited to 'check_reverts.py')
-rw-r--r--check_reverts.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/check_reverts.py b/check_reverts.py
new file mode 100644
index 0000000..f8598d3
--- /dev/null
+++ b/check_reverts.py
@@ -0,0 +1,58 @@
+import patchstate as ps
+import io, os, sys, subprocess, tempfile
+
+def main(args):
+ args = iter(args)
+ arg0 = next(args)
+
+ @ps.argparse_all(args)
+ def path(arg):
+ raise RuntimeError(f'Invalid argument: {arg!r}')
+
+ [repo_path] = path
+
+ repo = ps.Repository(repo_path)
+
+ with io.open(os.path.join(repo.path, 'series'), 'r') as f:
+ pcur = ps.Series.parse(f.read())
+
+ ok = True
+ reverted = {}
+ for pi in pcur.info:
+ mode = pi.mode
+ p = pi.get_patch(repo)
+ if mode == 'reverted':
+ pid = p.id
+ if pid in reverted:
+ raise RuntimeError(f'reverted twice: {pid!r}')
+ reverted[pid] = p
+ continue
+ if not mode.startswith('reverts '):
+ continue
+ pid = mode[8:]
+ revp = reverted.pop(pid)
+
+ d1 = ps.fmt_diff(revp.files, munge=True)
+ d2 = ps.fmt_diff(p.revert().files, munge=True)
+ if d1 != d2:
+ ok = False
+ print(f'Bad diff for {pid} {revp.title}:')
+ if 0:
+ with tempfile.NamedTemporaryFile('w+b') as t1, tempfile.NamedTemporaryFile('w+b') as t2:
+ t1.write(d1)
+ t1.flush()
+ t2.write(d2)
+ t2.flush()
+ diff = subprocess.run(['diff', t1.name, t2.name], capture_output=True, check=False)
+ diff = diff.stdout.decode('utf-8')
+ for line in diff.splitlines():
+ print(f'\t{line}')
+
+ for p in reverted.values():
+ print(f'Not reverted: {pid} {revp.title}')
+ ok = False
+
+ return 0 if ok else 1
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))