[PATCH 05/10] difftool: use get_mergetool_path from git-mergetool-lib
This refactors git-difftool-helper to use get_mergetool_path().
Signed-off-by: David Aguilar <davvid@gmail.com>
---
git-difftool-helper.sh | 33 ++++++++++++---------------------
1 files changed, 12 insertions(+), 21 deletions(-)
diff --git a/git-difftool-helper.sh b/git-difftool-helper.sh
index 02bb135..d1bea18 100755
--- a/git-difftool-helper.sh
+++ b/git-difftool-helper.sh
@@ -7,6 +7,9 @@
#
# Copyright (c) 2009 David Aguilar
+# Load common functions from git-mergetool-lib
+. git-mergetool-lib
+
# difftool.prompt controls the default prompt/no-prompt behavior
# and is overridden with $GIT_DIFFTOOL*_PROMPT.
should_prompt () {
@@ -125,25 +128,6 @@ valid_tool() {
esac
}
-# Sets up the merge_tool_path variable.
-# This handles the difftool.<tool>.path configuration.
-# This also falls back to mergetool defaults.
-init_merge_tool_path() {
- merge_tool_path=$(git config difftool."$1".path)
- test -z "$merge_tool_path" &&
- merge_tool_path=$(git config mergetool."$1".path)
- if test -z "$merge_tool_path"; then
- case "$1" in
- emerge)
- merge_tool_path=emacs
- ;;
- *)
- merge_tool_path="$1"
- ;;
- esac
- fi
-}
-
# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values
test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL"
test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL"
@@ -187,7 +171,7 @@ if test -z "$merge_tool"; then
# Loop over each candidate and stop when a valid merge tool is found.
for i in $merge_tool_candidates
do
- init_merge_tool_path $i
+ merge_tool_path="$(get_merge_tool_path "$i")"
if type "$merge_tool_path" > /dev/null 2>&1; then
merge_tool=$i
break
@@ -206,7 +190,14 @@ else
exit 1
fi
- init_merge_tool_path "$merge_tool"
+ # Sets up the merge_tool_path variable.
+ # This handles the difftool.<tool>.path configuration variable
+ # and falls back to mergetool defaults.
+ merge_tool_path=$(git config difftool."$1".path)
+ test -z "$merge_tool_path" &&
+ merge_tool_path=$(git config mergetool."$1".path)
+ merge_tool_path="$(get_merge_tool_path "$merge_tool" \
+ "$merge_tool_path")"
if test -z "$merge_tool_cmd" && ! type "$merge_tool_path" > /dev/null 2>&1; then
echo "The merge tool $merge_tool is not available as '$merge_tool_path'"
--
1.6.1.3