From: Junio C Hamano <hidden> Date: 2016-06-15 22:47:03
Nicolas Sebrecht [off-list ref] writes:
I don't see the reason to have the option -v. It's only related to
what's printed to output and doesn't change the exit status which
tell us if an expression has matched.
This gives:
grep -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null &&
patch_format=mbox
That grep says "if you see a single line that matches the pattern, even if
all the other lines are garbage, report it as a match".
See "something like this" patch in my other message. It filters the entire
header to make sure there is no line that does not match (that is what -v
is about), and make it report success when there is even a signle line
that does not.
$ (echo yes; echo no) | grep -v -e yes ; echo $?
no
0
$ (echo yes; echo yes) | grep -v -e yes ; echo $?
1
That is why I wrote the "how about this" patch with "||" like this:
grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||
patch_format=mbox
If everything is header, grep says "nothing matches", and patch_format
is set to mbox.
From: Nicolas Sebrecht <hidden> Date: 2016-06-15 22:47:03
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 <redacted>
---
Documentation/git-am.txt | 6 +++---
git-am.sh | 8 ++++++++
2 files changed, 11 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.
@@ -162,6 +162,14 @@ check_patch_format () {return0fi+# 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+return0+}+# otherwise, check the first few lines of the first patch to try# to detect its format{
From: Nicolas Sebrecht <hidden> Date: 2016-06-15 22:47:03
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 <redacted>
---
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(-)
@@ -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.
@@ -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{
@@ -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.
Also, writing some tests would be helpful.