git-am: refactor 'cleaning up and aborting'
Introduce a clean_abort function that echoes an optional error message to standard error, removes the dotest directory and exits with status 1. Use it when patch format detection or patch splitting fails early. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
May 27, 2009 at 11:25 UTC
0cd29a0371838228e2c942058e8829f5d0d4a077
1 file changed
+13
-14
git-am.sh
+13
-14
@@ -134,6 +134,12 @@ It does not apply to blobs recorded in its index."
134
unset GITHEAD_$his_tree
135
}
136
137
+clean_abort () {
138
+ test $# = 0 || echo >&2 "$@"
139
+ rm -fr "$dotest"
140
+ exit 1
141
+}
142
+
143
patch_format=
144
145
check_patch_format () {
@@ -180,22 +186,19 @@ check_patch_format () {
186
esac
187
;;
188
esac
183
- } < "$1"
189
+ } < "$1" || clean_abort
190
}
191
192
split_patches () {
193
case "$patch_format" in
194
mbox)
189
- git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
190
- rm -fr "$dotest"
191
- exit 1
192
- }
195
+ git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||
196
+ clean_abort
197
;;
198
stgit-series)
199
if test $# -ne 1
200
then
197
- echo "Only one StGIT patch series can be applied at once"
198
- exit 1
201
+ clean_abort "Only one StGIT patch series can be applied at once"
202
fi
203
series_dir=`dirname "$1"`
204
series_file="$1"
@@ -210,7 +213,7 @@ split_patches () {
213
shift
214
# remove the arg coming from the first-line comment
215
shift
213
- } < "$series_file"
216
+ } < "$series_file" || clean_abort
217
# set the patch format appropriately
218
patch_format=stgit
219
# now handle the actual StGIT patches
@@ -239,18 +242,14 @@ split_patches () {
242
print "Subject: ", $_ ;
243
$subject = 1;
244
}
242
- ' < "$stgit" > "$dotest/$msgnum" || {
243
- echo "Failed to import $patch_format patch $stgit"
244
- exit 1
245
- }
245
+ ' < "$stgit" > "$dotest/$msgnum" || clean_abort
246
done
247
echo "$this" > "$dotest/last"
248
this=
249
msgnum=
250
;;
251
*)
252
- echo "Patch format $patch_format is not supported."
253
- exit 1
252
+ clean_abort "Patch format $patch_format is not supported."
253
;;
254
esac
255
}