Skip to content

Commit 073678b

Browse files
davvidgitster
authored andcommitted
mergetools: simplify how we handle "vim" and "defaults"
Remove the exceptions for "vim" and "defaults" in the mergetool library so that every filename in mergetools/ matches 1:1 with the name of a valid built-in tool. Define the trivial fallback definition of shell functions in-line in git-mergetool-lib script, instead of dot-sourcing them from another file. The result is much easier to follow. [jc: squashed in an update from John Keeping as well] Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 62957be commit 073678b

File tree

6 files changed

+34
-52
lines changed

6 files changed

+34
-52
lines changed

git-mergetool--lib.sh

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22
# git-mergetool--lib is a library for common merge tool functions
3+
MERGE_TOOLS_DIR=$(git --exec-path)/mergetools
4+
35
diff_mode() {
46
test "$TOOL_MODE" = diff
57
}
@@ -44,19 +46,32 @@ valid_tool () {
4446
}
4547

4648
setup_tool () {
47-
case "$1" in
48-
vim*|gvim*)
49-
tool=vim
50-
;;
51-
*)
52-
tool="$1"
53-
;;
54-
esac
55-
mergetools="$(git --exec-path)/mergetools"
49+
tool="$1"
50+
51+
# Fallback definitions, to be overriden by tools.
52+
can_merge () {
53+
return 0
54+
}
55+
56+
can_diff () {
57+
return 0
58+
}
59+
60+
diff_cmd () {
61+
status=1
62+
return $status
63+
}
64+
65+
merge_cmd () {
66+
status=1
67+
return $status
68+
}
5669

57-
# Load the default definitions
58-
. "$mergetools/defaults"
59-
if ! test -f "$mergetools/$tool"
70+
translate_merge_tool_path () {
71+
echo "$1"
72+
}
73+
74+
if ! test -f "$MERGE_TOOLS_DIR/$tool"
6075
then
6176
# Use a special return code for this case since we want to
6277
# source "defaults" even when an explicit tool path is
@@ -66,7 +81,7 @@ setup_tool () {
6681
fi
6782

6883
# Load the redefined functions
69-
. "$mergetools/$tool"
84+
. "$MERGE_TOOLS_DIR/$tool"
7085

7186
if merge_mode && ! can_merge
7287
then
@@ -194,24 +209,10 @@ list_merge_tool_candidates () {
194209
show_tool_help () {
195210
unavailable= available= LF='
196211
'
197-
198-
scriptlets="$(git --exec-path)"/mergetools
199-
for i in "$scriptlets"/*
212+
for i in "$MERGE_TOOLS_DIR"/*
200213
do
201-
. "$scriptlets"/defaults
202-
. "$i"
203-
204-
tool="$(basename "$i")"
205-
if test "$tool" = "defaults"
206-
then
207-
continue
208-
elif merge_mode && ! can_merge
209-
then
210-
continue
211-
elif diff_mode && ! can_diff
212-
then
213-
continue
214-
fi
214+
tool=$(basename "$i")
215+
setup_tool "$tool" 2>/dev/null || continue
215216

216217
merge_tool_path=$(translate_merge_tool_path "$tool")
217218
if type "$merge_tool_path" >/dev/null 2>&1

mergetools/defaults

Lines changed: 0 additions & 22 deletions
This file was deleted.

mergetools/gvimdiff

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
. "$MERGE_TOOLS_DIR/vimdiff"

mergetools/gvimdiff2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
. "$MERGE_TOOLS_DIR/vimdiff"
File renamed without changes.

mergetools/vimdiff2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
. "$MERGE_TOOLS_DIR/vimdiff"

0 commit comments

Comments
 (0)