@@ -162,6 +162,17 @@ check_patch_format () {return0fi+# 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+return0+}+# otherwise, check the first few lines of the first patch to try# to detect its format{
This fails t4150-am.sh #10 (am -3 -q is quiet). You should redirect the
output of the sed and grep to /dev/null like Junio did in his "how about
this" patch.
Honestly speaking, I do not understand why Nicolas changed my patch at
all.
This patch wastes an extra sed process, introduces [[:blank::]] where
space and tab inside [] is perfectly adequate, and we know the latter is
understood by everybody's sed.
The worst part is that this check was moved before the most common case of
mbox file for which none of the overhead for this this extra processing is
necessary.
Admittedly, it was a "something like this" patch and wasn't tested at all,
and I would not be entirely surprised if he saw some breakages in it after
testing with my patch, but if that was the case, some comment after ---
would have been very helpful. Nicolas?
Also, writing some tests would be helpful.
That is true. A test would illustrate why this more expensive test must
come before the existing cheaper tests for common cases (if such a
breakage was the reason his patch looks different from mine), for example.
From: Nicolas Sebrecht <hidden> Date: 2016-06-15 22:47:03
The 16/07/09, Junio C Hamano wrote:
Stephen Boyd [off-list ref] writes:
quoted
Nicolas Sebrecht wrote:
quoted
quoted
+ # 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
{
This fails t4150-am.sh #10 (am -3 -q is quiet). You should redirect the
output of the sed and grep to /dev/null like Junio did in his "how about
this" patch.
Thank you.
Honestly speaking, I do not understand why Nicolas changed my patch at
all.
This patch wastes an extra sed process
Should we really worry about that in a script like git-am.sh? I mean,
does it matter in a day to day work?
introduces [[:blank::]] where
space and tab inside [] is perfectly adequate, and we know the latter is
understood by everybody's sed.
But is harder to read in editors.
The worst part is that this check was moved before the most common case of
mbox file for which none of the overhead for this this extra processing is
necessary.
Well, I did this move just because of the logical structure of the code.
That said, you're right about the overhead.
--
Nicolas Sebrecht
From: Nicolas Sebrecht <hidden> Date: 2016-06-15 22:47:03
The 16/07/09, Nicolas Sebrecht wrote:
The 16/07/09, Junio C Hamano wrote:
quoted
Stephen Boyd [off-list ref] writes:
quoted
Nicolas Sebrecht wrote:
quoted
quoted
+ # 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
{
This fails t4150-am.sh #10 (am -3 -q is quiet). You should redirect the
output of the sed and grep to /dev/null like Junio did in his "how about
this" patch.
Thank you.
quoted
Honestly speaking, I do not understand why Nicolas changed my patch at
all.
This patch wastes an extra sed process
Should we really worry about that in a script like git-am.sh? I mean,
does it matter in a day to day work?
Oh I've forgotten, yes we need it: sed -e '/^$/q' leaves this matching
line to the output. An extra CRLF makes 'grep -v' fail.
quoted
introduces [[:blank::]] where
space and tab inside [] is perfectly adequate, and we know the latter is
understood by everybody's sed.
But is harder to read in editors.
quoted
The worst part is that this check was moved before the most common case of
mbox file for which none of the overhead for this this extra processing is
necessary.
Well, I did this move just because of the logical structure of the code.
That said, you're right about the overhead.
From: Nicolas Sebrecht <hidden> Date: 2016-06-15 22:47:04
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 <redacted>
---
Documentation/git-am.txt | 6 ++--
git-am.sh | 14 ++++++++++++
t/t4150-am.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 3 deletions(-)
@@ -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.
@@ -191,6 +191,20 @@ check_patch_format () {esac;;esac+iftest-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'-ep"$1"|+grep-v-E-e'^[A-Za-z]+(-[A-Za-z]+)*:'>/dev/null||+patch_format=mbox+fi}<"$1"||clean_abort}
@@ -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:deliverytouser@domain.name+Received:(qmailinvokedbyalias);16Jul200905:25:49-0000+Received:fromvger.knl.xyz(EHLOvger.knl.xyz)[4.3.2.1]+bymx0.gmx.com(mx-us004)withSMTP;16Jul200901:25:49-0400+Received:(majordomo@vger.knl.xyz)byvger.knl.xyzvialistexpand+idS1757506AbZGPFZp(ORCPT<rfc822;user@domain.name>);+Thu,16Jul200901:25:45-0400+Received:(majordomo@vger.knl.xyz)byvger.knl.xyzidF1757505AbZGPPER+(ORCPT<rfc822;git-outgoing>);Thu,16Jul200901:25:45-0400+Received:fromhsmail.qwknetllc.com([208.71.137.138]:35086"EHLO+hsmail.qwknetllc.com" rhost-flags-OK-OK-OK-OK) by vger.knl.xyz+withESMTPidF1757505AbZGPPER(ORCPT<rfc822;git@vger.knl.xyz>);+Thu,16Jul200901:25:44-0400+X-Greylist:delayed401secondsbypostgrey-1.27atvger.knl.xyz;Thu,16Jul200901:25:44EDT+Received:(qmail31380invokedbyuid399);15Jul200923:19:01-0600+Received:fromunknown(HELO?192.168.1.107?)(user@domain.name@1.2.3.4)+byhsmail.qwknetllc.comwithESMTPAM;15Jul200923:19:01-0600+X-Originating-IP:1.2.3.4+Message-ID:<ADDDASSSS.123456789@domain.name>+Date:Wed,15Jul200923:19:05-0600+From:sender<user@domain.name>+User-Agent:Thunderbird2.0.0.22(Windows/20090605)+MIME-Version:1.0+To:git@vger.knl.xyz+Subject:[PATCH]applypatchfromrfc2822formatedemail+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(novirusfound)+X-Antispam:-2(notscanned,spamfilterdisabled)+X-UID:PIhtafixEX1VXO6puPmJy7wxySDc4NMwX+Content-Length:123465++Thistextispartoftheinternalformatofyourmailfolder,andisnot+arealmessage.Itiscreatedautomaticallybythemailsystemsoftware.+Ifdeleted,importantfolderdatawillbelost,anditwillbere-created+withthedataresettoinitialvalues.++EOF+echo"Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>">expected test_expect_successsetup'
@@ -222,6 +269,13 @@ test_expect_success 'am takes patches from a Pine mailbox' 'test-z"$(gitdiffmaster^..HEAD)"'+test_expect_success'am takes patches from a RFC2822 formated email''+gitcheckoutfirst&&+catrfc2822_emailpatch1|gitam&&+!test-d.git/rebase-apply&&+test-z"$(gitdiffmaster^..HEAD)"+'+ test_expect_success'am fails on mail without patch''test_must_failgitam<failmail&&rm-r.git/rebase-apply/
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 <redacted>
---
Could you summarize the changes since v5 here? Is the change the same as Junio's patch (if so shouldn't you credit him in the commit log message)?
@@ -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.
I wasn't following the discussion closely, and at first I didn't understand this change to the documentation, because it doesn't say how <mbox> and <email> are different. I'm afraid many readers of the documentation don't understand it either.
Why does this description have ... in it? If I'm reading it correctly, the code in check_patch_format function checks only the first file.
--
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/