Skip to content

Commit

Permalink
mergetool: dissect strings with shell variable magic instead of expr
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
j6t authored and gitster committed Jun 12, 2019
1 parent e10dffd commit 8b01465
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions git-mergetool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -406,7 +408,7 @@ main () {
-t|--tool*)
case "$#,$1" in
*,*=*)
merge_tool=$(expr "z$1" : 'z-[^=]*=\(.*\)')
merge_tool=${1#*=}
;;
1,*)
usage ;;
Expand Down

0 comments on commit 8b01465

Please sign in to comment.