From: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>
To: <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Stephen Boyd <bebarino@gmail.com>,
Nicolas Sebrecht <nicolas.s.dev@gmx.fr>
Subject: [PATCH v6] mailinfo: allow e-mail files as input
Date: Thu, 16 Jul 2009 19:45:34 +0200 [thread overview]
Message-ID: <f006bbb9c754c80c133798ff70db5b5291dae060.1247766192.git.nicolas.s.dev@gmx.fr> (raw)
In-Reply-To: <7v8wip9jjw.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 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.
It allows to run 'git am' with an email list argument, something like:
$ git am dir/*
$ git am email1 email2
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>
---
Documentation/git-am.txt | 6 ++--
git-am.sh | 14 ++++++++++++
t/t4150-am.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 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..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
}
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index a12bf84..4c99240 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -63,6 +63,53 @@ with the data reset to initial values.
EOF
+cat >rfc2822_email <<EOF
+Return-Path: <user@domain.name>
+X-Flags: 0000
+ 999
+Delivered-To: delivery to user@domain.name
+Received: (qmail invoked by alias); 16 Jul 2009 05:25:49 -0000
+Received: from vger.knl.xyz (EHLO vger.knl.xyz) [4.3.2.1]
+ by mx0.gmx.com (mx-us004) with SMTP; 16 Jul 2009 01:25:49 -0400
+Received: (majordomo@vger.knl.xyz) by vger.knl.xyz via listexpand
+ id S1757506AbZGPFZp (ORCPT <rfc822;user@domain.name>);
+ Thu, 16 Jul 2009 01:25:45 -0400
+Received: (majordomo@vger.knl.xyz) by vger.knl.xyz id F1757505AbZGPPER
+ (ORCPT <rfc822;git-outgoing>); Thu, 16 Jul 2009 01:25:45 -0400
+Received: from hsmail.qwknetllc.com ([208.71.137.138]:35086 "EHLO
+ hsmail.qwknetllc.com" rhost-flags-OK-OK-OK-OK) by vger.knl.xyz
+ with ESMTP id F1757505AbZGPPER (ORCPT <rfc822;git@vger.knl.xyz>);
+ Thu, 16 Jul 2009 01:25:44 -0400
+X-Greylist: delayed 401 seconds by postgrey-1.27 at vger.knl.xyz; Thu, 16 Jul 2009 01:25:44 EDT
+Received: (qmail 31380 invoked by uid 399); 15 Jul 2009 23:19:01 -0600
+Received: from unknown (HELO ?192.168.1.107?) (user@domain.name@1.2.3.4)
+ by hsmail.qwknetllc.com with ESMTPAM; 15 Jul 2009 23:19:01 -0600
+X-Originating-IP: 1.2.3.4
+Message-ID: <ADDDASSSS.123456789@domain.name>
+Date: Wed, 15 Jul 2009 23:19:05 -0600
+From: sender <user@domain.name>
+User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
+MIME-Version: 1.0
+To: git@vger.knl.xyz
+Subject: [PATCH] apply patch from rfc2822 formated email
+Content-Type: text/plain; charset=ISO-8859-1; format=flowed
+Content-Transfer-Encoding: 7bit
+Sender: git-owner@vger.knl.xyz
+Precedence: bulk
+List-ID: <git.vger.knl.xyz>
+X-Mailing-List: git@vger.knl.xyz
+X-Antivirus: 0 (no virus found)
+X-Antispam: -2 (not scanned, spam filter disabled)
+X-UID: PIhtafixEX1VXO6puPmJy7wxySDc4NMwX
+Content-Length: 123465
+
+This text is part of the internal format of your mail folder, and is not
+a real message. It is created automatically by the mail system software.
+If deleted, important folder data will be lost, and it will be re-created
+with the data reset to initial values.
+
+EOF
+
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected
test_expect_success setup '
@@ -222,6 +269,13 @@ test_expect_success 'am takes patches from a Pine mailbox' '
test -z "$(git diff master^..HEAD)"
'
+test_expect_success 'am takes patches from a RFC2822 formated email' '
+ git checkout first &&
+ cat rfc2822_email patch1 | git am &&
+ ! test -d .git/rebase-apply &&
+ test -z "$(git diff master^..HEAD)"
+'
+
test_expect_success 'am fails on mail without patch' '
test_must_fail git am <failmail &&
rm -r .git/rebase-apply/
--
1.6.4.rc1.169.gd0406
next prev parent reply other threads:[~2009-07-16 17:45 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-15 22:19 [PATCH v3] git-am: fix maildir support regression: accept email file as patch Nicolas Sebrecht
2009-07-15 22:43 ` [PATCH v3] " Nicolas Sebrecht
2009-07-15 22:54 ` [PATCH v3] " Junio C Hamano
2009-07-15 23:56 ` Junio C Hamano
2009-07-16 1:00 ` [PATCH v3] " Nicolas Sebrecht
2009-07-16 2:06 ` Nicolas Sebrecht
2009-07-16 2:30 ` Junio C Hamano
2009-07-16 2:59 ` Nicolas Sebrecht
2009-07-16 0:49 ` Nicolas Sebrecht
2009-07-16 2:41 ` Junio C Hamano
2009-07-16 4:05 ` [PATCH v4] git-am: allow e-mail file(s) as input Nicolas Sebrecht
2009-07-16 4:10 ` [PATCH v4] " Nicolas Sebrecht
2009-07-16 5:23 ` [PATCH v5] " Nicolas Sebrecht
2009-07-16 7:09 ` Stephen Boyd
2009-07-16 7:24 ` Junio C Hamano
2009-07-16 7:50 ` [PATCH v5] " Nicolas Sebrecht
2009-07-16 8:06 ` Nicolas Sebrecht
2009-07-16 8:17 ` Johannes Sixt
2009-07-16 8:12 ` Johannes Sixt
2009-07-16 17:45 ` Nicolas Sebrecht [this message]
2009-07-17 1:05 ` [PATCH v6] mailinfo: allow e-mail files " Junio C Hamano
2009-07-17 2:20 ` [PATCH v6] " Nicolas Sebrecht
2009-07-17 10:06 ` [PATCH v6] " Nanako Shiraishi
2009-07-17 19:54 ` Junio C Hamano
2009-07-17 22:04 ` [PATCH v6] " Nicolas Sebrecht
2009-08-06 17:07 ` [PATCH v7] " Nicolas Sebrecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f006bbb9c754c80c133798ff70db5b5291dae060.1247766192.git.nicolas.s.dev@gmx.fr \
--to=nicolas.s.dev@gmx.fr \
--cc=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).