mergetool: use shell variable magic instead of `awk`

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. Avoid repeated calls of `git ls-files` and `awk`. 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 7e6d6f7610965906d071022615bf64f14c60c0d2
1 file changed +20 -5
git-mergetool.sh
+20 -5
@@ -279,15 +279,30 @@ merge_file () {
279 REMOTE="$MERGETOOL_TMPDIR/${BASE}_REMOTE_$$$ext"
280 BASE="$MERGETOOL_TMPDIR/${BASE}_BASE_$$$ext"
281
282 - base_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==1) print $1;}')
283 - local_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}')
284 - remote_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}')
282 + base_mode= local_mode= remote_mode=
283 +
284 + # here, $IFS is just a LF
285 + for line in $f
286 + do
287 + mode=${line%% *} # 1st word
288 + sha1=${line#"$mode "}
289 + sha1=${sha1%% *} # 2nd word
290 + case "${line#$mode $sha1 }" in # remainder
291 + '1 '*)
292 + base_mode=$mode
293 + ;;
294 + '2 '*)
295 + local_mode=$mode local_sha1=$sha1
296 + ;;
297 + '3 '*)
298 + remote_mode=$mode remote_sha1=$sha1
299 + ;;
300 + esac
301 + done
302
303 if is_submodule "$local_mode" || is_submodule "$remote_mode"
304 then
305 echo "Submodule merge conflict for '$MERGED':"
289 - local_sha1=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $2;}')
290 - remote_sha1=$(git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $2;}')
306 describe_file "$local_mode" "local" "$local_sha1"
307 describe_file "$remote_mode" "remote" "$remote_sha1"
308 resolve_submodule_merge