mergetool: dissect strings with shell variable magic instead of `expr`

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>

Johannes Sixt committed Jun 12, 2019 at 18:33 UTC 8b014655105e27d44cf62f61dd6b24322a57048f
1 file changed +11 -9
git-mergetool.sh
+11 -9
@@ -228,9 +228,8 @@ stage_submodule () {
228 }
229
230 checkout_staged_file () {
231 - tmpfile=$(expr \
232 - "$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" \
233 - : '\([^ ]*\) ')
231 + tmpfile="$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" &&
232 + tmpfile=${tmpfile%%' '*}
233
234 if test $? -eq 0 && test -n "$tmpfile"
235 then
@@ -255,13 +254,16 @@ merge_file () {
254 return 1
255 fi
256
258 - if BASE=$(expr "$MERGED" : '\(.*\)\.[^/]*$')
259 - then
260 - ext=$(expr "$MERGED" : '.*\(\.[^/]*\)$')
261 - else
257 + # extract file extension from the last path component
258 + case "${MERGED##*/}" in
259 + *.*)
260 + ext=.${MERGED##*.}
261 + BASE=${MERGED%"$ext"}
262 + ;;
263 + *)
264 BASE=$MERGED
265 ext=
264 - fi
266 + esac
267
268 mergetool_tmpdir_init
269
@@ -406,7 +408,7 @@ main () {
408 -t|--tool*)
409 case "$#,$1" in
410 *,*=*)
409 - merge_tool=$(expr "z$1" : 'z-[^=]*=\(.*\)')
411 + merge_tool=${1#*=}
412 ;;
413 1,*)
414 usage ;;