]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mergetool: break setup_tool out into separate initialization function
authorSeth House <seth@eseth.com>
Tue, 9 Feb 2021 20:07:11 +0000 (13:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Feb 2021 22:09:16 +0000 (14:09 -0800)
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 <seth@eseth.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-mergetool--lib.txt
git-difftool--helper.sh
git-mergetool--lib.sh
git-mergetool.sh

index 4da9d240962f24da7daa7ebde7b4f0db4634cdd8..3e8f59ac0e46abc35b88723492fa2d411b2756ca 100644 (file)
@@ -38,6 +38,10 @@ get_merge_tool_cmd::
 get_merge_tool_path::
        returns the custom path for a merge tool.
 
+initialize_merge_tool::
+       bring merge tool specific functions into scope so they can be used or
+       overridden.
+
 run_merge_tool::
        launches a merge tool given the tool name and a true/false
        flag to indicate whether a merge base is present.
index 46af3e60b7185b2767accbee3420903edaf53d6f..992124cc67ce579e89ae86e4cca42ba2c80ea1ea 100755 (executable)
@@ -61,6 +61,9 @@ launch_merge_tool () {
                export BASE
                eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
        else
+               initialize_merge_tool "$merge_tool"
+               # ignore the error from the above --- run_merge_tool
+               # will diagnose unusable tool by itself
                run_merge_tool "$merge_tool"
        fi
 }
@@ -79,6 +82,9 @@ if test -n "$GIT_DIFFTOOL_DIRDIFF"
 then
        LOCAL="$1"
        REMOTE="$2"
+       initialize_merge_tool "$merge_tool"
+       # ignore the error from the above --- run_merge_tool
+       # will diagnose unusable tool by itself
        run_merge_tool "$merge_tool" false
 else
        # Launch the merge tool on each path provided by 'git diff'
index 7225abd81122e6bd798989d6e21fae1279cf3929..e059b3559e02dae35ff727e2d62a95521edad493 100644 (file)
@@ -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"
index 40a103443d9881353befe9baca8f1e574730b020..e5eac935f3fbcffeb1543bdd73cd6b6f3f82bc32 100755 (executable)
@@ -272,6 +272,8 @@ merge_file () {
                ext=
        esac
 
+       initialize_merge_tool "$merge_tool" || return
+
        mergetool_tmpdir_init
 
        if test "$MERGETOOL_TMPDIR" != "."