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 <seth@eseth.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Seth House committed Feb 9, 2021 at 13:07 UTC de8dafbada811bc1bc8e1288541931f3c5406231
4 files changed +16 -3
Documentation/git-mergetool--lib.txt
+4
@@ -38,6 +38,10 @@ get_merge_tool_cmd::
38 get_merge_tool_path::
39 returns the custom path for a merge tool.
40
41 +initialize_merge_tool::
42 + bring merge tool specific functions into scope so they can be used or
43 + overridden.
44 +
45 run_merge_tool::
46 launches a merge tool given the tool name and a true/false
47 flag to indicate whether a merge base is present.
git-difftool--helper.sh
+6
@@ -61,6 +61,9 @@ launch_merge_tool () {
61 export BASE
62 eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
63 else
64 + initialize_merge_tool "$merge_tool"
65 + # ignore the error from the above --- run_merge_tool
66 + # will diagnose unusable tool by itself
67 run_merge_tool "$merge_tool"
68 fi
69 }
@@ -79,6 +82,9 @@ if test -n "$GIT_DIFFTOOL_DIRDIFF"
82 then
83 LOCAL="$1"
84 REMOTE="$2"
85 + initialize_merge_tool "$merge_tool"
86 + # ignore the error from the above --- run_merge_tool
87 + # will diagnose unusable tool by itself
88 run_merge_tool "$merge_tool" false
89 else
90 # Launch the merge tool on each path provided by 'git diff'
git-mergetool--lib.sh
+4 -3
@@ -248,6 +248,10 @@ trust_exit_code () {
248 fi
249 }
250
251 +initialize_merge_tool () {
252 + # Bring tool-specific functions into scope
253 + setup_tool "$1" || return 1
254 +}
255
256 # Entry point for running tools
257 run_merge_tool () {
@@ -259,9 +263,6 @@ run_merge_tool () {
263 merge_tool_path=$(get_merge_tool_path "$1") || exit
264 base_present="$2"
265
262 - # Bring tool-specific functions into scope
263 - setup_tool "$1" || return 1
264 -
266 if merge_mode
267 then
268 run_merge_cmd "$1"
git-mergetool.sh
+2
@@ -272,6 +272,8 @@ merge_file () {
272 ext=
273 esac
274
275 + initialize_merge_tool "$merge_tool" || return
276 +
277 mergetool_tmpdir_init
278
279 if test "$MERGETOOL_TMPDIR" != "."