summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-04-03 23:20:11 +0200
committersfan5 <sfan5@live.de>2020-04-03 23:26:07 +0200
commitfe21aa1f4a92f54df2ed0f240472ce9a42fe473c (patch)
tree1c252f5fb34bebcafd0cc47389f70beb74fcb056 /util
parentb6d2c34a15f93c61a784696d895fc02a5d81d6de (diff)
downloadminetest-fe21aa1f4a92f54df2ed0f240472ce9a42fe473c.tar.gz
minetest-fe21aa1f4a92f54df2ed0f240472ce9a42fe473c.tar.bz2
minetest-fe21aa1f4a92f54df2ed0f240472ce9a42fe473c.zip
Utility script to help with Weblate commit import
Diffstat (limited to 'util')
-rwxr-xr-xutil/reorder_translation_commits.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/util/reorder_translation_commits.py b/util/reorder_translation_commits.py
new file mode 100755
index 000000000..465cf0b93
--- /dev/null
+++ b/util/reorder_translation_commits.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+import sys
+import subprocess
+
+ret = subprocess.run(["git", "config", "rebase.instructionFormat"], capture_output=True)
+if ret.returncode != 0 or ret.stdout.decode('ascii').strip() != "(%an <%ae>) %s":
+ print("Git is using the wrong rebase instruction format, reconfigure it.")
+ exit(1)
+
+try:
+ f = open(".git/rebase-merge/git-rebase-todo", "r")
+except:
+ print("Initiate the rebase first!")
+ exit(1)
+lines = list(s.strip("\r\n") for s in f.readlines())
+f.close()
+
+for i in range(len(lines)):
+ line = lines[i]
+ if line.startswith("#") or " Translated using Weblate " not in line: continue
+ pos = line.rfind("(")
+ lang = line[pos:]
+ author = line[line.find("("):line.rfind(")", 0, pos)+1]
+ # try to grab the next commit by the same author for the same language
+ for j in range(i+1, len(lines)):
+ if lines[j].startswith("#") or not lines[j].endswith(lang): continue
+ if author in lines[j]:
+ lines.insert(i+1, "f " + lines.pop(j)[5:])
+ break
+
+with open(".git/rebase-merge/git-rebase-todo", "w") as f:
+ f.write("\n".join(lines) + "\n")
+print("You can now continue with the rebase.")