Skip to content

Commit 83bbf9b

Browse files
pudivagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47ae905 commit 83bbf9b

File tree

8 files changed

+36
-10
lines changed

8 files changed

+36
-10
lines changed

git-mergetool--lib.sh

+23-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ show_tool_names () {
4343

4444
shown_any=
4545
( 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
4754
do
4855
if setup_tool "$toolname" 2>/dev/null &&
4956
(eval "$condition" "$toolname")
@@ -157,6 +164,10 @@ setup_tool () {
157164
echo "$1"
158165
}
159166

167+
list_tool_variants () {
168+
echo "$tool"
169+
}
170+
160171
# Most tools' exit codes cannot be trusted, so By default we ignore
161172
# their exit code and check the merged file's modification time in
162173
# check_unchanged() to determine whether or not the merge was
@@ -178,19 +189,26 @@ setup_tool () {
178189
false
179190
}
180191

181-
182-
if ! test -f "$MERGE_TOOLS_DIR/$tool"
192+
if test -f "$MERGE_TOOLS_DIR/$tool"
183193
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
184199
setup_user_tool
185200
return $?
186201
fi
187202

188-
# Load the redefined functions
189-
. "$MERGE_TOOLS_DIR/$tool"
190203
# Now let the user override the default command for the tool. If
191204
# they have not done so then this will return 1 which we ignore.
192205
setup_user_tool
193206

207+
if ! list_tool_variants | grep -q "^$tool$"
208+
then
209+
return 1
210+
fi
211+
194212
if merge_mode && ! can_merge
195213
then
196214
echo "error: '$tool' can not be used to resolve merges" >&2

mergetools/bc

+5
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ translate_merge_tool_path() {
2121
echo bcompare
2222
fi
2323
}
24+
25+
list_tool_variants () {
26+
echo bc
27+
echo bc3
28+
}

mergetools/bc3

-1
This file was deleted.

mergetools/gvimdiff2

-1
This file was deleted.

mergetools/gvimdiff3

-1
This file was deleted.

mergetools/vimdiff

+8
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ translate_merge_tool_path() {
4646
exit_code_trustable () {
4747
true
4848
}
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

-1
This file was deleted.

mergetools/vimdiff3

-1
This file was deleted.

0 commit comments

Comments
 (0)