aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gentoo.org>2024-05-29 23:33:34 -0400
committerMatt Turner <mattst88@gentoo.org>2024-06-07 11:02:43 -0400
commit4603c61f1eb9774d91a6f355a6a0c9e6a6f0fa08 (patch)
tree3b20ed2cc6556fd82aac0ecf75e91d31976f5b35
parentbin/merge-driver-ekeyword: Move logic to a separate module (diff)
downloadgentoolkit-4603c61f1eb9774d91a6f355a6a0c9e6a6f0fa08.tar.gz
gentoolkit-4603c61f1eb9774d91a6f355a6a0c9e6a6f0fa08.tar.bz2
gentoolkit-4603c61f1eb9774d91a6f355a6a0c9e6a6f0fa08.zip
merge_driver-ekeyword: split out merge_keywords function
Signed-off-by: Matt Turner <mattst88@gentoo.org>
-rwxr-xr-xpym/gentoolkit/merge_driver_ekeyword/merge_driver_ekeyword.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/pym/gentoolkit/merge_driver_ekeyword/merge_driver_ekeyword.py b/pym/gentoolkit/merge_driver_ekeyword/merge_driver_ekeyword.py
index 59527bb..d252bc4 100755
--- a/pym/gentoolkit/merge_driver_ekeyword/merge_driver_ekeyword.py
+++ b/pym/gentoolkit/merge_driver_ekeyword/merge_driver_ekeyword.py
@@ -111,6 +111,14 @@ def apply_keyword_changes(ebuild: str, pathname: str,
return result
+def merge_keywords(O, A, B, P) -> int:
+ # Get changes to KEYWORDS= from %O to %B
+ if changes := keyword_changes(O, B):
+ # Apply %O -> %B changes to %A
+ return apply_keyword_changes(A, P, changes)
+ return -1
+
+
def main(argv: Sequence[str]) -> int:
if len(argv) != 4:
return -1
@@ -120,23 +128,19 @@ def main(argv: Sequence[str]) -> int:
B = argv[2] # %B - filename of the other branch's version
P = argv[3] # %P - original path of the file
- # Get changes to KEYWORDS= from %O to %B
- if changes := keyword_changes(O, B):
- # Apply %O -> %B changes to %A
- result = apply_keyword_changes(A, P, changes)
- return result
- # Get changes to KEYWORDS= from %O to %A
- elif changes := keyword_changes(O, A):
- # Apply %O -> %A changes to %B
- result = apply_keyword_changes(B, P, changes)
+ if merge_keywords(O, A, B, P) == 0:
+ return 0
+
+ # Try in reverse
+ if merge_keywords(O, B, A, P) == 0:
# Merged file should be left in %A
shutil.move(B, A)
- return result
- else:
- try:
- os.execlp("git", "git", "merge-file", "-L", "HEAD", "-L", "base", "-L", "ours", A, O, B)
- except OSError:
- return -1
+ return 0
+
+ try:
+ os.execlp("git", "git", "merge-file", "-L", "HEAD", "-L", "base", "-L", "ours", A, O, B)
+ except OSError:
+ return -1
if __name__ == "__main__":