subtree: more consistent error propagation

Ensure that every $(subshell) that calls a function (as opposed to an
external executable) is followed by `|| exit $?`.  Similarly, ensure that
every `cmd | while read; do ... done` loop is followed by `|| exit $?`.

Both of those constructs mean that it can miss `die` calls, and keep
running when it shouldn't.

Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Luke Shumaker 2021-04-27 15:17:31 -06:00 committed by Junio C Hamano
parent 5a3569774f
commit d2f0f81954
1 changed files with 14 additions and 14 deletions

View File

@ -243,7 +243,7 @@ cache_miss () {
} }


check_parents () { check_parents () {
missed=$(cache_miss "$1") missed=$(cache_miss "$1") || exit $?
local indent=$(($2 + 1)) local indent=$(($2 + 1))
for miss in $missed for miss in $missed
do do
@ -345,7 +345,7 @@ find_latest_squash () {
sub= sub=
;; ;;
esac esac
done done || exit $?
} }


find_existing_splits () { find_existing_splits () {
@ -394,7 +394,7 @@ find_existing_splits () {
sub= sub=
;; ;;
esac esac
done done || exit $?
} }


copy_commit () { copy_commit () {
@ -508,7 +508,7 @@ subtree_for_commit () {
test "$type" = "commit" && continue # ignore submodules test "$type" = "commit" && continue # ignore submodules
echo $tree echo $tree
break break
done done || exit $?
} }


tree_changed () { tree_changed () {
@ -518,7 +518,7 @@ tree_changed () {
then then
return 0 # weird parents, consider it changed return 0 # weird parents, consider it changed
else else
ptree=$(toptree_for_commit $1) ptree=$(toptree_for_commit $1) || exit $?
if test "$ptree" != "$tree" if test "$ptree" != "$tree"
then then
return 0 # changed return 0 # changed
@ -652,7 +652,7 @@ process_split_commit () {
progress "$revcount/$revmax ($createcount) [$extracount]" progress "$revcount/$revmax ($createcount) [$extracount]"


debug "Processing commit: $rev" debug "Processing commit: $rev"
exists=$(cache_get "$rev") exists=$(cache_get "$rev") || exit $?
if test -n "$exists" if test -n "$exists"
then then
debug " prior: $exists" debug " prior: $exists"
@ -661,10 +661,10 @@ process_split_commit () {
createcount=$(($createcount + 1)) createcount=$(($createcount + 1))
debug " parents: $parents" debug " parents: $parents"
check_parents "$parents" "$indent" check_parents "$parents" "$indent"
newparents=$(cache_get $parents) newparents=$(cache_get $parents) || exit $?
debug " newparents: $newparents" debug " newparents: $newparents"


tree=$(subtree_for_commit "$rev" "$dir") tree=$(subtree_for_commit "$rev" "$dir") || exit $?
debug " tree is: $tree" debug " tree is: $tree"


# ugly. is there no better way to tell if this is a subtree # ugly. is there no better way to tell if this is a subtree
@ -750,7 +750,7 @@ cmd_add_commit () {
commit=$(add_squashed_msg "$rev" "$dir" | commit=$(add_squashed_msg "$rev" "$dir" |
git commit-tree "$tree" $headp -p "$rev") || exit $? git commit-tree "$tree" $headp -p "$rev") || exit $?
else else
revp=$(peel_committish "$rev") && revp=$(peel_committish "$rev") || exit $?
commit=$(add_msg "$dir" $headrev "$rev" | commit=$(add_msg "$dir" $headrev "$rev" |
git commit-tree "$tree" $headp -p "$revp") || exit $? git commit-tree "$tree" $headp -p "$revp") || exit $?
fi fi
@ -773,10 +773,10 @@ cmd_split () {
# any parent we find there can be used verbatim # any parent we find there can be used verbatim
debug " cache: $rev" debug " cache: $rev"
cache_set "$rev" "$rev" cache_set "$rev" "$rev"
done done || exit $?
fi fi


unrevs="$(find_existing_splits "$dir" "$revs")" unrevs="$(find_existing_splits "$dir" "$revs")" || exit $?


# We can't restrict rev-list to only $dir here, because some of our # We can't restrict rev-list to only $dir here, because some of our
# parents have the $dir contents the root, and those won't match. # parents have the $dir contents the root, and those won't match.
@ -792,7 +792,7 @@ cmd_split () {
process_split_commit "$rev" "$parents" 0 process_split_commit "$rev" "$parents" 0
done || exit $? done || exit $?


latest_new=$(cache_get latest_new) latest_new=$(cache_get latest_new) || exit $?
if test -z "$latest_new" if test -z "$latest_new"
then then
die "No new revisions were found" die "No new revisions were found"
@ -801,7 +801,7 @@ cmd_split () {
if test -n "$rejoin" if test -n "$rejoin"
then then
debug "Merging split branch into HEAD..." debug "Merging split branch into HEAD..."
latest_old=$(cache_get latest_old) latest_old=$(cache_get latest_old) || exit $?
git merge -s ours \ git merge -s ours \
--allow-unrelated-histories \ --allow-unrelated-histories \
-m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \ -m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
@ -834,7 +834,7 @@ cmd_merge () {


if test -n "$squash" if test -n "$squash"
then then
first_split="$(find_latest_squash "$dir")" first_split="$(find_latest_squash "$dir")" || exit $?
if test -z "$first_split" if test -z "$first_split"
then then
die "Can't squash-merge: '$dir' was never added." die "Can't squash-merge: '$dir' was never added."