From de8dafbada811bc1bc8e1288541931f3c5406231 Mon Sep 17 00:00:00 2001 From: Seth House Date: Tue, 9 Feb 2021 13:07:11 -0700 Subject: mergetool: break setup_tool out into separate initialization function This is preparation for the following commit where we need to source the mergetool shell script to look for overrides before `run_merge_tool` is called. Previously `run_merge_tool` both sourced that script and invoked the mergetool. In the case of the following commit, we need the result of the `hide_resolved` override, if present, before we actually run `run_merge_tool`. The new `initialize_merge_tool` wrapper is exposed and documented as a public interface for consistency with the existing `run_merge_tool` which is also public. Although `setup_tool` could instead be exposed directly, the related `setup_user_tool` would probably also want to be elevated to match and this felt the cleanest to me. Signed-off-by: Seth House Signed-off-by: Junio C Hamano --- git-mergetool--lib.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'git-mergetool--lib.sh') diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index 7225abd811..e059b3559e 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -248,6 +248,10 @@ trust_exit_code () { fi } +initialize_merge_tool () { + # Bring tool-specific functions into scope + setup_tool "$1" || return 1 +} # Entry point for running tools run_merge_tool () { @@ -259,9 +263,6 @@ run_merge_tool () { merge_tool_path=$(get_merge_tool_path "$1") || exit base_present="$2" - # Bring tool-specific functions into scope - setup_tool "$1" || return 1 - if merge_mode then run_merge_cmd "$1" -- cgit v1.2.3 From 9d9cf230317f7fe7cb153f61b537e6e9bef22e3b Mon Sep 17 00:00:00 2001 From: Seth House Date: Tue, 9 Feb 2021 13:07:12 -0700 Subject: mergetool: add per-tool support and overrides for the hideResolved flag Add a per-tool override flag so that users may enable the flag for one tool and disable it for another by setting `mergetool..hideResolved` to `false`. In addition, the author or maintainer of a mergetool may optionally override the default `hideResolved` value for that mergetool. If the `mergetools/` shell script contains a `hide_resolved_enabled` function it will be called when the mergetool is invoked and the return value will be used as the default for the `hideResolved` flag. hide_resolved_enabled () { return 1 } Disabling may be desirable if the mergetool wants or needs access to the original, unmodified 'LOCAL' and 'REMOTE' versions of the conflicted file. For example: - A tool may use a custom conflict resolution algorithm and prefer to ignore the results of Git's conflict resolution. - A tool may want to visually compare/constrast the version of the file from before the merge (saved to 'LOCAL', 'REMOTE', and 'BASE') with Git's conflict resolution results (saved to 'MERGED'). Helped-by: Johannes Sixt Helped-by: Junio C Hamano Signed-off-by: Seth House Signed-off-by: Junio C Hamano --- git-mergetool--lib.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'git-mergetool--lib.sh') diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index e059b3559e..11f00dde41 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -164,6 +164,10 @@ setup_tool () { return 1 } + hide_resolved_enabled () { + return 0 + } + translate_merge_tool_path () { echo "$1" } -- cgit v1.2.3