Skip to content

Commit de8dafb

Browse files
whiteingegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98ea309 commit de8dafb

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

Documentation/git-mergetool--lib.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ get_merge_tool_cmd::
3838
get_merge_tool_path::
3939
returns the custom path for a merge tool.
4040

41+
initialize_merge_tool::
42+
bring merge tool specific functions into scope so they can be used or
43+
overridden.
44+
4145
run_merge_tool::
4246
launches a merge tool given the tool name and a true/false
4347
flag to indicate whether a merge base is present.

git-difftool--helper.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ launch_merge_tool () {
6161
export BASE
6262
eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
6363
else
64+
initialize_merge_tool "$merge_tool"
65+
# ignore the error from the above --- run_merge_tool
66+
# will diagnose unusable tool by itself
6467
run_merge_tool "$merge_tool"
6568
fi
6669
}
@@ -79,6 +82,9 @@ if test -n "$GIT_DIFFTOOL_DIRDIFF"
7982
then
8083
LOCAL="$1"
8184
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
8288
run_merge_tool "$merge_tool" false
8389
else
8490
# Launch the merge tool on each path provided by 'git diff'

git-mergetool--lib.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ trust_exit_code () {
248248
fi
249249
}
250250

251+
initialize_merge_tool () {
252+
# Bring tool-specific functions into scope
253+
setup_tool "$1" || return 1
254+
}
251255

252256
# Entry point for running tools
253257
run_merge_tool () {
@@ -259,9 +263,6 @@ run_merge_tool () {
259263
merge_tool_path=$(get_merge_tool_path "$1") || exit
260264
base_present="$2"
261265

262-
# Bring tool-specific functions into scope
263-
setup_tool "$1" || return 1
264-
265266
if merge_mode
266267
then
267268
run_merge_cmd "$1"

git-mergetool.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ merge_file () {
272272
ext=
273273
esac
274274

275+
initialize_merge_tool "$merge_tool" || return
276+
275277
mergetool_tmpdir_init
276278

277279
if test "$MERGETOOL_TMPDIR" != "."

0 commit comments

Comments
 (0)