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

[PATCHv3 (resend) 2/4] git-am foreign patch support: autodetect some patch formats

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

Default to mbox format if input is from stdin. Otherwise, look at the first few lines of the first patch to try to guess its format.

Include checks for mailboxes, stgit patch series, stgit single patches
and hg patches.
---
 git-am.sh |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index da160de..8519701 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -142,7 +142,45 @@ check_patch_format () {
 	then
 		return 0
 	fi
-	patch_format=mbox
+
+	# we default to mbox format if input is from stdin and for
+	# directories
+	if test $# = 0 || test "x$1" = "x-" || test -d "$1"
+	then
+		patch_format=mbox
+		return 0
+	fi
+
+	# otherwise, check the first few lines of the first patch to try
+	# to detect its format
+	{
+		read l1
+		read l2
+		read l3
+		case "$l1" in
+		"From "*|"From: "*)
+			patch_format=mbox
+			;;
+		'# This series applies on GIT commit'*)
+			patch_format=stgit-series
+			;;
+		"# HG changeset patch")
+			patch_format=hg
+			;;
+		*)
+			# if the second line is empty and the third is
+			# a From, Author or Date entry, this is very
+			# likely an StGIT patch
+			case "$l2,$l3" in
+			,"From: "*|,"Author: "*|,"Date: "*)
+				patch_format=stgit
+				;;
+			*)
+				;;
+			esac
+			;;
+		esac
+	} < "$1"
 }
 
 split_patches () {
-- 
1.6.3.1.282.g9f93
Previous: Giuseppe BilottaNext: Giuseppe Bilotta
Message 3 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.