Merge branch 'da/difftool-mergetool-simplify-reporting-status'

Code simplification.

* da/difftool-mergetool-simplify-reporting-status:
  mergetools: stop setting $status in merge_cmd()
  mergetool: simplify conditionals
  difftool--helper: add explicit exit statement
  mergetool--lib: remove use of $status global
  mergetool--lib: remove no-op assignment to $status from setup_user_tool
This commit is contained in:
Junio C Hamano 2014-12-12 14:31:39 -08:00
commit 0ddedd4d6b
6 changed files with 12 additions and 29 deletions

View File

@ -94,3 +94,5 @@ else
shift 7 shift 7
done done
fi fi
exit 0

View File

@ -92,7 +92,7 @@ translate_merge_tool_path () {
check_unchanged () { check_unchanged () {
if test "$MERGED" -nt "$BACKUP" if test "$MERGED" -nt "$BACKUP"
then then
status=0 return 0
else else
while true while true
do do
@ -100,8 +100,8 @@ check_unchanged () {
printf "Was the merge successful? [y/n] " printf "Was the merge successful? [y/n] "
read answer || return 1 read answer || return 1
case "$answer" in case "$answer" in
y*|Y*) status=0; break ;; y*|Y*) return 0 ;;
n*|N*) status=1; break ;; n*|N*) return 1 ;;
esac esac
done done
fi fi
@ -119,8 +119,6 @@ setup_user_tool () {
diff_cmd () { diff_cmd () {
( eval $merge_tool_cmd ) ( eval $merge_tool_cmd )
status=$?
return $status
} }
merge_cmd () { merge_cmd () {
@ -130,13 +128,10 @@ setup_user_tool () {
then then
touch "$BACKUP" touch "$BACKUP"
( eval $merge_tool_cmd ) ( eval $merge_tool_cmd )
status=$?
check_unchanged check_unchanged
else else
( eval $merge_tool_cmd ) ( eval $merge_tool_cmd )
status=$?
fi fi
return $status
} }
} }
@ -153,13 +148,11 @@ setup_tool () {
} }
diff_cmd () { diff_cmd () {
status=1 return 1
return $status
} }
merge_cmd () { merge_cmd () {
status=1 return 1
return $status
} }
translate_merge_tool_path () { translate_merge_tool_path () {
@ -210,7 +203,6 @@ run_merge_tool () {
merge_tool_path=$(get_merge_tool_path "$1") || exit merge_tool_path=$(get_merge_tool_path "$1") || exit
base_present="$2" base_present="$2"
status=0
# Bring tool-specific functions into scope # Bring tool-specific functions into scope
setup_tool "$1" || return 1 setup_tool "$1" || return 1
@ -221,8 +213,6 @@ run_merge_tool () {
else else
run_diff_cmd "$1" run_diff_cmd "$1"
fi fi
status=$?
return $status
} }
# Run a either a configured or built-in diff tool # Run a either a configured or built-in diff tool

View File

@ -426,8 +426,6 @@ fi
merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)" merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)" merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
last_status=0
rollup_status=0
files= files=
if test $# -eq 0 if test $# -eq 0
@ -455,19 +453,15 @@ printf "%s\n" "$files"
IFS=' IFS='
' '
rc=0
for i in $files for i in $files
do do
if test $last_status -ne 0
then
prompt_after_failed_merge || exit 1
fi
printf "\n" printf "\n"
merge_file "$i" if ! merge_file "$i"
last_status=$?
if test $last_status -ne 0
then then
rollup_status=1 rc=1
prompt_after_failed_merge || exit 1
fi fi
done done
exit $rollup_status exit $rc

View File

@ -11,5 +11,4 @@ merge_cmd () {
"$merge_tool_path" --merge \ "$merge_tool_path" --merge \
--result="$MERGED" "$LOCAL" "$REMOTE" --result="$MERGED" "$LOCAL" "$REMOTE"
fi fi
status=$?
} }

View File

@ -15,7 +15,6 @@ merge_cmd () {
"$LOCAL" "$REMOTE" \ "$LOCAL" "$REMOTE" \
"$(basename "$MERGED")" "$(basename "$MERGED")"
fi fi
status=$?
} }
translate_merge_tool_path() { translate_merge_tool_path() {

View File

@ -20,5 +20,4 @@ merge_cmd () {
-o "$MERGED" "$LOCAL" "$REMOTE" \ -o "$MERGED" "$LOCAL" "$REMOTE" \
>/dev/null 2>&1 >/dev/null 2>&1
fi fi
status=$?
} }