commit: 4603c61f1eb9774d91a6f355a6a0c9e6a6f0fa08
Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu May 30 03:33:34 2024 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Jun 7 15:02:43 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=4603c61f
merge_driver-ekeyword: split out merge_keywords function
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
.../merge_driver_ekeyword/merge_driver_ekeyword.py | 34 ++++++++++++----------
1 file 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__":