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

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

From
NSNicolas Sebrecht <nicolas.s.dev@gmx.fr>
Date
Jul 16, 2009, 05:23 UTC
Message-ID
<eb6317e39369adc8d2594c35ee351b49aaadcc24.1247721562.git.nicolas.s.dev@gmx.fr>
In-Reply-To
<7v7hy9bb8k.fsf@alter.siamese.dyndns.org>

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@gmx.fr>
---

This should be the last version of this *%/£ patch. Thanks Junio for your feedbacks.

 Documentation/git-am.txt |    6 +++---
 git-am.sh                |   11 +++++++++++
 2 files changed, 14 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..2b55ddc 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -162,6 +162,17 @@ check_patch_format () {
 		return 0
 	fi
 
+	# Then, accept what really looks like (series of) email(s).
+	# the first sed select headers but the folded ones
+	sed -e '/^$/q' -e '/^[[:blank:]]/d' "$1" |
+	# this one is necessary for the next 'grep -v'
+	sed -e '/^$/d' |
+	grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' ||
+	{
+		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
Previous: Nicolas SebrechtNext: Stephen Boyd
Message 13 of 26 in “git-am: fix maildir support regression: accept email file as patch”
  1. git-am: fix maildir support regression: accept email file as patchNicolas Sebrecht, Jul 15, 2009
  2. Re: git-am: fix maildir support regression: accept email file as patchNicolas Sebrecht, Jul 15, 2009
  3. Junio C HamanoJul 15, 2009
  4. Junio C HamanoJul 15, 2009
  5. Re: git-am: fix maildir support regression: accept email file as patchNicolas Sebrecht, Jul 16, 2009
  6. Re: git-am: fix maildir support regression: accept email file as patchNicolas Sebrecht, Jul 16, 2009
  7. Junio C HamanoJul 16, 2009
  8. Re: git-am: fix maildir support regression: accept email file as patchNicolas Sebrecht, Jul 16, 2009
  9. Re: git-am: fix maildir support regression: accept email file as patchNicolas Sebrecht, Jul 16, 2009
  10. Junio C HamanoJul 16, 2009
  11. git-am: allow e-mail file(s) as inputNicolas Sebrecht, Jul 16, 2009
  12. Re: git-am: allow e-mail file(s) as inputNicolas Sebrecht, Jul 16, 2009
  13. git-am: allow e-mail file(s) as inputNicolas Sebrecht, Jul 16, 2009
  14. Stephen BoydJul 16, 2009
  15. Junio C HamanoJul 16, 2009
  16. Re: git-am: allow e-mail file(s) as inputNicolas Sebrecht, Jul 16, 2009
  17. Re: git-am: allow e-mail file(s) as inputNicolas Sebrecht, Jul 16, 2009
  18. Johannes SixtJul 16, 2009
  19. Johannes SixtJul 16, 2009
  20. mailinfo: allow e-mail files as inputNicolas Sebrecht, Jul 16, 2009
  21. Junio C HamanoJul 17, 2009
  22. Re: mailinfo: allow e-mail files as inputNicolas Sebrecht, Jul 17, 2009
  23. Nanako ShiraishiJul 17, 2009
  24. Junio C HamanoJul 17, 2009
  25. Re: mailinfo: allow e-mail files as inputNicolas Sebrecht, Jul 17, 2009
  26. mailinfo: allow e-mail files as inputNicolas Sebrecht, Aug 6, 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.