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

Re: [PATCH v3] git-am: fix maildir support regression: accept email file as patch

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 15, 2009, 23:56 UTC
Message-ID
<7vfxcxcxg1.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7v1voheevy.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 5 quoted lines
> Please describe what that new something is.
>...
> Running three independent printf piped to two processes in a loop is
> quite silly.
> ...
That is, something like this.
-- >8 --
Subject: mailinfo: allow individual e-mail files as input

We traditionally allowed a mbox file or a directory name of a maildir (but never an individual file inside a maildir) to be given to "git am". Even though an individual 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. Running mailsplit on such a file feels stupid, but it does not hurt.

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: Junio C Hamano <gitster@pobox.com>
---
 git-am.sh |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index d64d997..617ca2f 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -191,6 +191,20 @@ check_patch_format () {
 			esac
 			;;
 		esac
+		if test -z "$patch_format" &&
+			test -n "$l1" &&
+			test -n "$l2" &&
+			test -n "$l3"
+		then
+			# This begins with three non-empty lines.  Is this a
+			# piece of e-mail a-la RFC2822?  Grab all the headers,
+			# discarding the indented remainder of folded lines,
+			# and see if it looks like that they all begin with the
+			# header field names...
+			sed -n -e '/^$/q' -e '/^[ 	]/d' -e p "$1" |
+			grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||
+			patch_format=mbox
+		fi
 	} < "$1" || clean_abort
 }
 
Previous: Junio C HamanoNext: Nicolas Sebrecht
Message 4 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.