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>
David Aguilar committed
Jan 26, 2013 at 16:46 UTC
073678b8e6324a155fa99f40eee0637941a70a34
6 files changed
+34
-52
git-mergetool--lib.sh
+31
-30
@@ -1,5 +1,7 @@
1
#!/bin/sh
2
# git-mergetool--lib is a library for common merge tool functions
3
+MERGE_TOOLS_DIR=$(git --exec-path)/mergetools
4
+
5
diff_mode() {
6
test "$TOOL_MODE" = diff
7
}
@@ -44,19 +46,32 @@ valid_tool () {
46
}
47
48
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
+ }
69
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"
75
then
76
# Use a special return code for this case since we want to
77
# source "defaults" even when an explicit tool path is
@@ -66,7 +81,7 @@ setup_tool () {
81
fi
82
83
# Load the redefined functions
69
- . "$mergetools/$tool"
84
+ . "$MERGE_TOOLS_DIR/$tool"
85
86
if merge_mode && ! can_merge
87
then
@@ -194,24 +209,10 @@ list_merge_tool_candidates () {
209
show_tool_help () {
210
unavailable= available= LF='
211
'
197
-
198
- scriptlets="$(git --exec-path)"/mergetools
199
- for i in "$scriptlets"/*
212
+ for i in "$MERGE_TOOLS_DIR"/*
213
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
216
217
merge_tool_path=$(translate_merge_tool_path "$tool")
218
if type "$merge_tool_path" >/dev/null 2>&1
mergetools/defaults
deleted
-22
@@ -1,22 +0,0 @@
1
-# Redefined by builtin tools
2
-can_merge () {
3
- return 0
4
-}
5
-
6
-can_diff () {
7
- return 0
8
-}
9
-
10
-diff_cmd () {
11
- status=1
12
- return $status
13
-}
14
-
15
-merge_cmd () {
16
- status=1
17
- return $status
18
-}
19
-
20
-translate_merge_tool_path () {
21
- echo "$1"
22
-}
mergetools/gvimdiff
new
+1
@@ -0,0 +1 @@
1
+. "$MERGE_TOOLS_DIR/vimdiff"
mergetools/gvimdiff2
new
+1
@@ -0,0 +1 @@
1
+. "$MERGE_TOOLS_DIR/vimdiff"
mergetools/vimdiff
renamed
mergetools/vimdiff2
new
+1
@@ -0,0 +1 @@
1
+. "$MERGE_TOOLS_DIR/vimdiff"