Skip to content

Commit

Permalink
Merge branch 'da/difftool-mergetool-simplify-reporting-status'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Dec 12, 2014
2 parents e886efd + 1e86d5b commit 0ddedd4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 29 deletions.
2 changes: 2 additions & 0 deletions git-difftool--helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ else
shift 7
done
fi

exit 0
20 changes: 5 additions & 15 deletions git-mergetool--lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ translate_merge_tool_path () {
check_unchanged () {
if test "$MERGED" -nt "$BACKUP"
then
status=0
return 0
else
while true
do
echo "$MERGED seems unchanged."
printf "Was the merge successful? [y/n] "
read answer || return 1
case "$answer" in
y*|Y*) status=0; break ;;
n*|N*) status=1; break ;;
y*|Y*) return 0 ;;
n*|N*) return 1 ;;
esac
done
fi
Expand All @@ -119,8 +119,6 @@ setup_user_tool () {

diff_cmd () {
( eval $merge_tool_cmd )
status=$?
return $status
}

merge_cmd () {
Expand All @@ -130,13 +128,10 @@ setup_user_tool () {
then
touch "$BACKUP"
( eval $merge_tool_cmd )
status=$?
check_unchanged
else
( eval $merge_tool_cmd )
status=$?
fi
return $status
}
}

Expand All @@ -153,13 +148,11 @@ setup_tool () {
}

diff_cmd () {
status=1
return $status
return 1
}

merge_cmd () {
status=1
return $status
return 1
}

translate_merge_tool_path () {
Expand Down Expand Up @@ -210,7 +203,6 @@ run_merge_tool () {

merge_tool_path=$(get_merge_tool_path "$1") || exit
base_present="$2"
status=0

# Bring tool-specific functions into scope
setup_tool "$1" || return 1
Expand All @@ -221,8 +213,6 @@ run_merge_tool () {
else
run_diff_cmd "$1"
fi
status=$?
return $status
}

# Run a either a configured or built-in diff tool
Expand Down
16 changes: 5 additions & 11 deletions git-mergetool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,6 @@ fi
merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"

last_status=0
rollup_status=0
files=

if test $# -eq 0
Expand Down Expand Up @@ -455,19 +453,15 @@ printf "%s\n" "$files"

IFS='
'
rc=0
for i in $files
do
if test $last_status -ne 0
then
prompt_after_failed_merge || exit 1
fi
printf "\n"
merge_file "$i"
last_status=$?
if test $last_status -ne 0
if ! merge_file "$i"
then
rollup_status=1
rc=1
prompt_after_failed_merge || exit 1
fi
done

exit $rollup_status
exit $rc
1 change: 0 additions & 1 deletion mergetools/diffmerge
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ merge_cmd () {
"$merge_tool_path" --merge \
--result="$MERGED" "$LOCAL" "$REMOTE"
fi
status=$?
}
1 change: 0 additions & 1 deletion mergetools/emerge
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ merge_cmd () {
"$LOCAL" "$REMOTE" \
"$(basename "$MERGED")"
fi
status=$?
}

translate_merge_tool_path() {
Expand Down
1 change: 0 additions & 1 deletion mergetools/kdiff3
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ merge_cmd () {
-o "$MERGED" "$LOCAL" "$REMOTE" \
>/dev/null 2>&1
fi
status=$?
}

0 comments on commit 0ddedd4

Please sign in to comment.