[PATCH v4] git-am: allow e-mail file(s) as input

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We traditionally allowed a mbox file or a directory name of a maildir to be
given to "git am". Even though file in a maildir (or more generally, a piece
of RFC2822 e-mail) is not a mbox file, it contains enough information to create
a commit out of it, so there is no reason to reject one.

This builds on top of a5a6755 (git-am foreign patch support: introduce
patch_format, 2009-05-27) that introduced mailbox format detection. The codepath
to deal with a mbox requires it to begin with "From " line and also allows it to
begin with "From: ", but a random piece of e-mail can and often do begin with
any valid RFC2822 header lines.

Instead of checking the first line, we extract all the lines up to the
first empty line, and make sure they look like e-mail headers.

Signed-off-by: Nicolas Sebrecht <nicolas.s.dev@xxxxxx>
---
 Documentation/git-am.txt |    6 +++---
 git-am.sh                |    8 ++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 32e689b..2a930a7 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -14,7 +14,7 @@ SYNOPSIS
 	 [--ignore-date]
 	 [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
 	 [--reject] [-q | --quiet]
-	 [<mbox> | <Maildir>...]
+	 [<mbox> | <Maildir>... | <email>... ]
 'git am' (--skip | --resolved | --abort)
 
 DESCRIPTION
@@ -25,8 +25,8 @@ current branch.
 
 OPTIONS
 -------
-<mbox>|<Maildir>...::
-	The list of mailbox files to read patches from. If you do not
+<mbox>|<Maildir>...|<email>...::
+	The list of mailbox files or email to read patches from. If you do not
 	supply this argument, the command reads from the standard input.
 	If you supply directories, they will be treated as Maildirs.
 
diff --git a/git-am.sh b/git-am.sh
index d64d997..87a886d 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -162,6 +162,14 @@ check_patch_format () {
 		return 0
 	fi
 
+	# then, accept (series of) email(s)
+	sed -e '/^$/q' -e '/^[[:blank:]]/d' "$1" |
+	grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null &&
+	{
+		patch_format=mbox
+		return 0
+	}
+
 	# otherwise, check the first few lines of the first patch to try
 	# to detect its format
 	{
-- 
1.6.4.rc0.129.gdc42

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]