Git fork

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>

authored by

David Aguilar and committed by
Junio C Hamano
073678b8 62957bea

+34 -52
+31 -30
git-mergetool--lib.sh
··· 1 1 #!/bin/sh 2 2 # git-mergetool--lib is a library for common merge tool functions 3 + MERGE_TOOLS_DIR=$(git --exec-path)/mergetools 4 + 3 5 diff_mode() { 4 6 test "$TOOL_MODE" = diff 5 7 } ··· 44 46 } 45 47 46 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 + 70 + translate_merge_tool_path () { 71 + echo "$1" 72 + } 56 73 57 - # Load the default definitions 58 - . "$mergetools/defaults" 59 - if ! test -f "$mergetools/$tool" 74 + if ! test -f "$MERGE_TOOLS_DIR/$tool" 60 75 then 61 76 # Use a special return code for this case since we want to 62 77 # source "defaults" even when an explicit tool path is ··· 66 81 fi 67 82 68 83 # Load the redefined functions 69 - . "$mergetools/$tool" 84 + . "$MERGE_TOOLS_DIR/$tool" 70 85 71 86 if merge_mode && ! can_merge 72 87 then ··· 194 209 show_tool_help () { 195 210 unavailable= available= LF=' 196 211 ' 197 - 198 - scriptlets="$(git --exec-path)"/mergetools 199 - for i in "$scriptlets"/* 212 + for i in "$MERGE_TOOLS_DIR"/* 200 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 215 216 216 217 merge_tool_path=$(translate_merge_tool_path "$tool") 217 218 if type "$merge_tool_path" >/dev/null 2>&1
-22
mergetools/defaults
··· 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 - }
+1
mergetools/gvimdiff
··· 1 + . "$MERGE_TOOLS_DIR/vimdiff"
+1
mergetools/gvimdiff2
··· 1 + . "$MERGE_TOOLS_DIR/vimdiff"
mergetools/vim mergetools/vimdiff
+1
mergetools/vimdiff2
··· 1 + . "$MERGE_TOOLS_DIR/vimdiff"