git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv3 (resend) 4/4] git-am: refactor 'cleaning up and aborting'

From
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Date
Jun 1, 2009, 23:10 UTC
Message-ID
<1243897841-8923-5-git-send-email-giuseppe.bilotta@gmail.com>
In-Reply-To
<1243897841-8923-4-git-send-email-giuseppe.bilotta@gmail.com>

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>
---
 git-am.sh |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index d05c9b4..e8b2bc2 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -134,6 +134,15 @@ It does not apply to blobs recorded in its index."
     unset GITHEAD_$his_tree
 }
 
+clean_abort () {
+	if test $# -gt 0
+	then
+		echo "$@" > /dev/stderr
+	fi
+	rm -fr "$dotest"
+	exit 1
+}
+
 patch_format=
 
 check_patch_format () {
@@ -180,22 +189,18 @@ check_patch_format () {
 			esac
 			;;
 		esac
-	} < "$1"
+	} < "$1" || clean_abort
 }
 
 split_patches () {
 	case "$patch_format" in
 	mbox)
-		git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||  {
-			rm -fr "$dotest"
-			exit 1
-		}
+		git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || clean_abort
 		;;
 	stgit-series)
 		if test $# -ne 1
 		then
-			echo "Only one StGIT patch series can be applied at once"
-			exit 1
+			clean_abort "Only one StGIT patch series can be applied at once"
 		fi
 		series_dir=`dirname "$1"`
 		series_file="$1"
@@ -210,7 +215,7 @@ split_patches () {
 			shift
 			# remove the arg coming from the first-line comment
 			shift
-		} < "$series_file"
+		} < "$series_file" || clean_abort
 		# set the patch format appropriately
 		patch_format=stgit
 		# now handle the actual StGIT patches
@@ -239,18 +244,14 @@ split_patches () {
 					print "Subject: ", $_ ;
 					$subject = 1;
 				}
-			' < "$stgit" > "$dotest/$msgnum" || {
-				echo "Failed to import $patch_format patch $stgit"
-				exit 1
-			}
+			' < "$stgit" > "$dotest/$msgnum" || clean_abort
 		done
 		echo "$this" > "$dotest/last"
 		this=
 		msgnum=
 		;;
 	*)
-		echo "Patch format $patch_format is not supported."
-		exit 1
+		clean_abort "Patch format $patch_format is not supported."
 		;;
 	esac
 }
-- 
1.6.3.1.282.g9f93
Previous: Giuseppe BilottaNext: Nanako Shiraishi
Message 5 of 7 in “[PATCHv3 (resend) 0/4] git-am foreign patch support”
  1. Giuseppe BilottaJun 1, 2009
  2. 1/4 git-am foreign patch support: introduce patch_formatGiuseppe Bilotta, Jun 1, 2009
  3. 2/4 git-am foreign patch support: autodetect some patch formatsGiuseppe Bilotta, Jun 1, 2009
  4. 3/4 git-am foreign patch support: StGIT supportGiuseppe Bilotta, Jun 1, 2009
  5. 4/4 git-am: refactor 'cleaning up and aborting'Giuseppe Bilotta, Jun 1, 2009
  6. Nanako ShiraishiJun 2, 2009
  7. Junio C HamanoJun 2, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.