mergetool: dissect strings with shell variable magic instead of `expr`
authorJohannes Sixt <j6t@kdbg.org>
Wed, 12 Jun 2019 16:33:47 +0000 (18:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Jun 2019 20:20:56 +0000 (13:20 -0700)
git-mergetool spawns an enormous amount of processes. For this reason,
the test script, t7610, is exceptionally slow, in particular, on
Windows. Most of the processes are invocations of git. There are
also some that can be replaced with shell builtins. Do so with `expr`.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-mergetool.sh

index 88fa6a9..8a937f6 100755 (executable)
@@ -228,9 +228,8 @@ stage_submodule () {
 }
 
 checkout_staged_file () {
-       tmpfile=$(expr \
-               "$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" \
-               : '\([^ ]*\)    ')
+       tmpfile="$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" &&
+       tmpfile=${tmpfile%%'    '*}
 
        if test $? -eq 0 && test -n "$tmpfile"
        then
@@ -255,13 +254,16 @@ merge_file () {
                return 1
        fi
 
-       if BASE=$(expr "$MERGED" : '\(.*\)\.[^/]*$')
-       then
-               ext=$(expr "$MERGED" : '.*\(\.[^/]*\)$')
-       else
+       # extract file extension from the last path component
+       case "${MERGED##*/}" in
+       *.*)
+               ext=.${MERGED##*.}
+               BASE=${MERGED%"$ext"}
+               ;;
+       *)
                BASE=$MERGED
                ext=
-       fi
+       esac
 
        mergetool_tmpdir_init
 
@@ -406,7 +408,7 @@ main () {
                -t|--tool*)
                        case "$#,$1" in
                        *,*=*)
-                               merge_tool=$(expr "z$1" : 'z-[^=]*=\(.*\)')
+                               merge_tool=${1#*=}
                                ;;
                        1,*)
                                usage ;;