mergetool--lib: improve support for vimdiff-style tool variants
The merge tools vimdiff2, vimdiff3, gvimdiff2, gvimdiff3 and bc3 are all variants of the main tools vimdiff and bc. They are implemented in the main and a one-liner script that just sources it exist for each. Allow variants ending in [0-9] to be correctly wired without the need for such one-liners, so instead of 5 scripts, only 1 (gvimdiff) is needed. Signed-off-by: pudinha <rogi@skylittlesystem.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
pudinha committed
Jul 29, 2020 at 22:31 UTC
83bbf9b92ea8a10a60f44369a200b39ce5db78cd
8 files changed
+36
-10
git-mergetool--lib.sh
+23
-5
@@ -43,7 +43,14 @@ show_tool_names () {
43
44
shown_any=
45
( cd "$MERGE_TOOLS_DIR" && ls ) | {
46
- while read toolname
46
+ while read scriptname
47
+ do
48
+ setup_tool "$scriptname" 2>/dev/null
49
+ variants="$variants$(list_tool_variants)\n"
50
+ done
51
+ variants="$(echo "$variants" | sort | uniq)"
52
+
53
+ for toolname in $variants
54
do
55
if setup_tool "$toolname" 2>/dev/null &&
56
(eval "$condition" "$toolname")
@@ -157,6 +164,10 @@ setup_tool () {
164
echo "$1"
165
}
166
167
+ list_tool_variants () {
168
+ echo "$tool"
169
+ }
170
+
171
# Most tools' exit codes cannot be trusted, so By default we ignore
172
# their exit code and check the merged file's modification time in
173
# check_unchanged() to determine whether or not the merge was
@@ -178,19 +189,26 @@ setup_tool () {
189
false
190
}
191
181
-
182
- if ! test -f "$MERGE_TOOLS_DIR/$tool"
192
+ if test -f "$MERGE_TOOLS_DIR/$tool"
193
then
194
+ . "$MERGE_TOOLS_DIR/$tool"
195
+ elif test -f "$MERGE_TOOLS_DIR/${tool%[0-9]}"
196
+ then
197
+ . "$MERGE_TOOLS_DIR/${tool%[0-9]}"
198
+ else
199
setup_user_tool
200
return $?
201
fi
202
188
- # Load the redefined functions
189
- . "$MERGE_TOOLS_DIR/$tool"
203
# Now let the user override the default command for the tool. If
204
# they have not done so then this will return 1 which we ignore.
205
setup_user_tool
206
207
+ if ! list_tool_variants | grep -q "^$tool$"
208
+ then
209
+ return 1
210
+ fi
211
+
212
if merge_mode && ! can_merge
213
then
214
echo "error: '$tool' can not be used to resolve merges" >&2
mergetools/bc
+5
@@ -21,3 +21,8 @@ translate_merge_tool_path() {
21
echo bcompare
22
fi
23
}
24
+
25
+list_tool_variants () {
26
+ echo bc
27
+ echo bc3
28
+}
mergetools/bc3
deleted
-1
@@ -1 +0,0 @@
1
-. "$MERGE_TOOLS_DIR/bc"
mergetools/gvimdiff2
deleted
-1
@@ -1 +0,0 @@
1
-. "$MERGE_TOOLS_DIR/vimdiff"
mergetools/gvimdiff3
deleted
-1
@@ -1 +0,0 @@
1
-. "$MERGE_TOOLS_DIR/vimdiff"
mergetools/vimdiff
+8
@@ -46,3 +46,11 @@ translate_merge_tool_path() {
46
exit_code_trustable () {
47
true
48
}
49
+
50
+list_tool_variants () {
51
+ for prefix in '' g; do
52
+ for suffix in '' 2 3; do
53
+ echo "${prefix}vimdiff${suffix}"
54
+ done
55
+ done
56
+}
mergetools/vimdiff2
deleted
-1
@@ -1 +0,0 @@
1
-. "$MERGE_TOOLS_DIR/vimdiff"
mergetools/vimdiff3
deleted
-1
@@ -1 +0,0 @@
1
-. "$MERGE_TOOLS_DIR/vimdiff"