summaryrefslogtreecommitdiff
path: root/migrate_series.py
diff options
context:
space:
mode:
Diffstat (limited to 'migrate_series.py')
-rw-r--r--migrate_series.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/migrate_series.py b/migrate_series.py
new file mode 100644
index 0000000..c09dea1
--- /dev/null
+++ b/migrate_series.py
@@ -0,0 +1,47 @@
+import patchstate as ps
+import io, os, sys
+
+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())
+
+ idmap = {}
+ for i,pi in enumerate(pcur.info):
+ h = pi.patch_hash
+ try:
+ h = repo.aliases[h]
+ except KeyError:
+ pass
+ p = repo.patches[h]
+ if pi.patch_id in idmap:
+ raise RuntimeError(f'duplicate patch id: {pi.patch_id!r}')
+ idmap[pi.patch_id] = p.id
+ pcur.info[i] = pi.update(patch=p)
+
+ print(idmap)
+
+ for i,pi in enumerate(pcur.info):
+ m = pi.mode
+ if m.startswith('reverts '):
+ m = f'reverts {idmap[m[8:]]}'
+ pcur.info[i] = pi.update(mode=m)
+
+ pcur = pcur.fmt()
+ with io.open(os.path.join(repo.path, 'series'), 'w') as f:
+ f.write(pcur)
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))