{"thread":{"id":"20125","subject":"[PATCH v3] git-am: fix maildir support regression: accept email file as patch","startedAt":"2009-07-15T22:19:36Z","lastAt":"2009-08-06T17:07:50Z","messageCount":26,"participants":["Nicolas Sebrecht","Junio C Hamano","Stephen Boyd","Johannes Sixt","Nanako Shiraishi"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"118049","messageId":"1654b578a7e045b564c46df4abb6e2196422c2b2.1247696294.git.nicolas.s.dev@gmx.fr","threadId":"20125","inReplyTo":null,"subject":"[PATCH v3] git-am: fix maildir support regression: accept email file as patch","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-15T22:19:36Z","receivedAt":"2009-07-15T22:19:36Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"Patch format detection introduced by a5a6755a1d4707bf2fab7752e5c974ebf63d086a\nmay refuse valid patches.\n\nWe keep detection on the first three lines. Emails may have:\n - header fields in a random order;\n - folded lines.\n\nSigned-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n---\n git-am.sh |   17 +++++++++++++++++\n 1 files changed, 17 insertions(+), 0 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex d64d997..6190297 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -146,6 +146,7 @@ clean_abort () {\n }\n \n patch_format=\n+is_email=\n \n check_patch_format () {\n \t# early return if patch_format was set from the command line\n@@ -191,6 +192,22 @@ check_patch_format () {\n \t\t\tesac\n \t\t\t;;\n \t\tesac\n+\t\t# Keep maildir workflows support.\n+\t\t# Emails may have header fields in random order.\n+\t\tis_email='true'\n+\t\tfor line in \"$l1\" \"$l2\" \"$l3\"\n+\t\tdo\n+\t\t\tprintf \"$line\" |\n+\t\t\t\t# The line may be a folded line\n+\t\t\t\tsed -e '/^$/q' -e '/^[ ]/d' |\n+\t\t\t\tgrep -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n+\t\t\t\tis_email='false'\n+\t\tdone\n+\t\t# next treatments don't differ from mailbox format\n+\t\tif [ $is_email == 'true' ]\n+\t\tthen\n+\t\t\tpatch_format=mbox\n+\t\tfi\n \t} < \"$1\" || clean_abort\n }\n \n-- \n1.6.4.rc0.128.g69018\n"},{"id":"118053","messageId":"20090715224308.GA12971@vidovic","threadId":"20125","inReplyTo":"1654b578a7e045b564c46df4abb6e2196422c2b2.1247696294.git.nicolas.s.dev@gmx.fr","subject":"[PATCH v3] Re: git-am: fix maildir support regression: accept email file as patch","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-15T22:43:08Z","receivedAt":"2009-07-15T22:43:08Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 16/07/09, Nicolas Sebrecht wrote:\n\n> Patch format detection introduced by a5a6755a1d4707bf2fab7752e5c974ebf63d086a\n> may refuse valid patches.\n> \n> We keep detection on the first three lines. Emails may have:\n>  - header fields in a random order;\n>  - folded lines.\n\nI realized this patch is wrong. Please ignore it.\n\n-- \nNicolas Sebrecht\n"},{"id":"118054","messageId":"7v1voheevy.fsf@alter.siamese.dyndns.org","threadId":"20125","inReplyTo":"1654b578a7e045b564c46df4abb6e2196422c2b2.1247696294.git.nicolas.s.dev@gmx.fr","subject":"Re: [PATCH v3] git-am: fix maildir support regression: accept email file as patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-15T22:54:25Z","receivedAt":"2009-07-15T22:54:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:\n\n> Patch format detection introduced by a5a6755a1d4707bf2fab7752e5c974ebf63d086a\n> may refuse valid patches.\n\nThis message is even worse than the previous round.\n\nBy definition what git-am does not accept is invalid, and you are\nloosening that definition to include something else newly as valid.\n\nPlease describe what that new something is.\n\nIf you are claiming a5a6755 (git-am foreign patch support: introduce\npatch_format, 2009-05-27) is an regression, and before it X, Y and Z\nformat were supported but after that only X and Y format are, then for the\nsame reason please specify what that Z you are resurrecting the support\nfor is.\n\nThat way, people who have been frustrated that their randomly formatted\nfiles were not processible without first converting them to mbox format\nwill know that now their favorite format is now/again also supported.\n\n> We keep detection on the first three lines. Emails may have:\n>  - header fields in a random order;\n>  - folded lines.\n>\n> Signed-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n> ---\n>  git-am.sh |   17 +++++++++++++++++\n>  1 files changed, 17 insertions(+), 0 deletions(-)\n>\n\nPlease do not break the thread.  Make this message a response to my\nmessage you lifted the idea from, which in turn was sent as a response in\nthe thread of v2 patch.\n\n\n> +\t\tfor line in \"$l1\" \"$l2\" \"$l3\"\n> +\t\tdo\n> +\t\t\tprintf \"$line\" |\n> +\t\t\t\t# The line may be a folded line\n> +\t\t\t\tsed -e '/^$/q' -e '/^[ ]/d' |\n> +\t\t\t\tgrep -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n> +\t\t\t\tis_email='false'\n\nRunning three independent printf piped to two processes in a loop is\nquite silly.\n\nI think you did not understand the point of the three liner I sent you.\n\n\tsed -e '/^$/q' -e '/^[ \t]/d' \"$1\" |\n\n    The point of this is not to use the silly \"we only look at the first\n    three lines\" rule.  Instead, it ignores these l1/l2/l3, but grabs all\n    the header lines, but discards second and subsequent physical lines if\n    a logical line was folded.  Which means that the effect of this is to\n    pipe the whole header (again, without worrying about the indented\n    remainder of folded lines) to downsream, which is the grep -v below\n\n        grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n\n    This checks if there is a line that does _NOT_ match the usual\n    e-mail header pattern.  If there is such a line, it means that the\n    file is not an e-mail message.  If there is no such line, we say...\n\n        patch_format=mbox\n\nOne caveat is that the above logic alone won't catch a random file that\ndoes not have _any_ e-mail headers in it.  So you might need to do\nsomething like:\n\n\tLF='\n        '\n\tcase \"$l1$LF$l2$LF$l3\" in\n        *\"$LF$LF\"*)\n        \t# has a completely empty line in there?\n                # that means the message has only two headers at most;\n                # that cannot be an email.\n\t\t;;\n\t*)\n                sed -e '/^$/q' -e '/^[ \t]/d' \"$1\" |\n                grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n                patch_format=mbox\n\tesac\n\nto completely replace that \"for line in...\" loop.\n"},{"id":"118055","messageId":"7vfxcxcxg1.fsf@alter.siamese.dyndns.org","threadId":"20125","inReplyTo":"7v1voheevy.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v3] git-am: fix maildir support regression: accept email file as patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-15T23:56:30Z","receivedAt":"2009-07-15T23:56:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Please describe what that new something is.\n>...\n> Running three independent printf piped to two processes in a loop is\n> quite silly.\n> ...\n\nThat is, something like this.\n\n-- >8 --\nSubject: mailinfo: allow individual e-mail files as input\n\nWe traditionally allowed a mbox file or a directory name of a maildir (but\nnever an individual file inside a maildir) to be given to \"git am\".  Even\nthough an individual file in a maildir (or more generally, a piece of\nRFC2822 e-mail) is not a mbox file, it contains enough information to\ncreate a commit out of it, so there is no reason to reject one.  Running\nmailsplit on such a file feels stupid, but it does not hurt.\n\nThis builds on top of a5a6755 (git-am foreign patch support: introduce\npatch_format, 2009-05-27) that introduced mailbox format detection.  The\ncodepath to deal with a mbox requires it to begin with \"From \" line and\nalso allows it to begin with \"From: \", but a random piece of e-mail can\nand often do begin with any valid RFC2822 header lines.\n\nInstead of checking the first line, we extract all the lines up to the\nfirst empty line, and make sure they look like e-mail headers.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-am.sh |   14 ++++++++++++++\n 1 files changed, 14 insertions(+), 0 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex d64d997..617ca2f 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -191,6 +191,20 @@ check_patch_format () {\n \t\t\tesac\n \t\t\t;;\n \t\tesac\n+\t\tif test -z \"$patch_format\" &&\n+\t\t\ttest -n \"$l1\" &&\n+\t\t\ttest -n \"$l2\" &&\n+\t\t\ttest -n \"$l3\"\n+\t\tthen\n+\t\t\t# This begins with three non-empty lines.  Is this a\n+\t\t\t# piece of e-mail a-la RFC2822?  Grab all the headers,\n+\t\t\t# discarding the indented remainder of folded lines,\n+\t\t\t# and see if it looks like that they all begin with the\n+\t\t\t# header field names...\n+\t\t\tsed -n -e '/^$/q' -e '/^[ \t]/d' -e p \"$1\" |\n+\t\t\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n+\t\t\tpatch_format=mbox\n+\t\tfi\n \t} < \"$1\" || clean_abort\n }\n \n"},{"id":"118059","messageId":"20090716004952.GB12971@vidovic","threadId":"20125","inReplyTo":"7v1voheevy.fsf@alter.siamese.dyndns.org","subject":"[PATCH v3] Re: git-am: fix maildir support regression: accept email file as patch","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T00:49:52Z","receivedAt":"2009-07-16T00:49:52Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 15/07/09, Junio C Hamano wrote:\n\n> I think you did not understand the point of the three liner I sent you.\n> \n> \tsed -e '/^$/q' -e '/^[ \t]/d' \"$1\" |\n\nI'll change it to\n\n \tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n\nto conform to reality (and the paragraph 3.4.2 of the RFC 822).\n\n>     The point of this is not to use the silly \"we only look at the first\n>     three lines\" rule.  Instead, it ignores these l1/l2/l3, but grabs all\n>     the header lines, but discards second and subsequent physical lines if\n>     a logical line was folded.  Which means that the effect of this is to\n>     pipe the whole header (again, without worrying about the indented\n>     remainder of folded lines) to downsream, which is the grep -v below\n> \n>         grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n>\n>     This checks if there is a line that does _NOT_ match the usual\n>     e-mail header pattern.  If there is such a line, it means that the\n>     file is not an e-mail message.  If there is no such line, we say...\n\nI don't see the reason to have the option -v. It's only related to\nwhat's printed to output and doesn't change the exit status which\ntell us if an expression has matched.\n\nThis gives:\n\n   grep -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null &&\n   patch_format=mbox\n\n> One caveat is that the above logic alone won't catch a random file that\n> does not have _any_ e-mail headers in it.  So you might need to do\n> something like:\n> \n> \tLF='\n>         '\n> \tcase \"$l1$LF$l2$LF$l3\" in\n>         *\"$LF$LF\"*)\n>         \t# has a completely empty line in there?\n>                 # that means the message has only two headers at most;\n>                 # that cannot be an email.\n> \t\t;;\n\nI think we can strip this part. The purpose is to accept what _may_ be a\npatch. Any wrong patch or random file will be rejected later.\n\n-- \nNicolas Sebrecht\n"},{"id":"118062","messageId":"20090716010001.GC12971@vidovic","threadId":"20125","inReplyTo":"7vfxcxcxg1.fsf@alter.siamese.dyndns.org","subject":"[PATCH v3] Re: git-am: fix maildir support regression: accept email file as patch","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T01:00:01Z","receivedAt":"2009-07-16T01:00:01Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 15/07/09, Junio C Hamano wrote:\n\n> We traditionally allowed a mbox file or a directory name of a maildir (but\n> never an individual file inside a maildir) to be given to \"git am\".  Even\n> though an individual file in a maildir (or more generally, a piece of\n> RFC2822 e-mail) is not a mbox file, it contains enough information to\n> create a commit out of it, so there is no reason to reject one.  Running\n> mailsplit on such a file feels stupid, but it does not hurt.\n\nJunio, I'm sorry but you missed the point.\n\nIt is not about adding a new feature. It's about keeping compatibility\nwith maildir. The current version _rejects_ good patches.\n\nBut, as it's very easy to move emails from a maildir _or_ have a symlink\nwhich links to \"maildir/cur\" or whatever, we really should rely on the\ncontent of the files.\n\n-- \nNicolas Sebrecht\n"},{"id":"118063","messageId":"20090716020632.GD12971@vidovic","threadId":"20125","inReplyTo":"20090716010001.GC12971@vidovic","subject":"[PATCH v3] Re: git-am: fix maildir support regression: accept email file as patch","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T02:06:32Z","receivedAt":"2009-07-16T02:06:32Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 16/07/09, Nicolas Sebrecht wrote:\n\n> It is not about adding a new feature. It's about keeping compatibility\n> with maildir. The current version _rejects_ good patches.\n> \n> But, as it's very easy to move emails from a maildir _or_ have a symlink\n> which links to \"maildir/cur\" or whatever, we really should rely on the\n> content of the files.\n\nHum, it's not true. \n\nSymlink as parameter didn't work before. So, it breaks things like:\n\n\t$ git am symlink/*\n\t$ git am directory/{anything relying on shell globbing}\n\t$ git am patch1 patch2\n\nThis was traditionally permitted even if git-am was not designed to. I\nwonder if we should add this feature as it could break end-user\nworkflows.\n\n-- \nNicolas Sebrecht\n"},{"id":"118066","messageId":"7vfxcxbbqw.fsf@alter.siamese.dyndns.org","threadId":"20125","inReplyTo":"20090716010001.GC12971@vidovic","subject":"Re: [PATCH v3] Re: git-am: fix maildir support regression: accept email file as patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-16T02:30:31Z","receivedAt":"2009-07-16T02:30:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:\n\n> It is not about adding a new feature. It's about keeping compatibility\n> with maildir. The current version _rejects_ good patches.\n\nYou almost gave me a heart attack.  I wondered if the detection code, like\nit did when it saw a stgit series, saw that the parameter was a directory\n(in which case the original code blindly took it as a maildir), and added\nan extra check to see each file in that specified directory is a mbox or\nbegins with \"From: \", and reject it otherwise.\n\nIf it were what Giuseppe's patch did, clearly that would have been a\nbreakage that rejects a good maildir.  So I looked at the code again.\n\nA very early part of check_patch_format says \"a directory?  we say it is\nmbox (even though we should call it maildir) and let split_patches() call\ngit-mailsplit, as it knows how to deal with a maildir\".\n\nSo I do not think there is any breakage that rejects good input with his\npatch.\n\nI am not opposed to add support for individual pieces of e-mail without\nforcing them to be in Berkeley mbox format.  Not everybody uses mbox\nformat, and it is a logical thing to do.  Also I do not think the amount\nof new code necessary to do so is excessive, nor such a change is risky\neven late in a cycle after -rc0.\n\nI however _do_ have issues with labeling other's patch that did not break\nany documented behaviour as a regression, even if it is to get extra\nattention to the issue.  That's not how we do things.\n"},{"id":"118068","messageId":"7v7hy9bb8k.fsf@alter.siamese.dyndns.org","threadId":"20125","inReplyTo":"20090716004952.GB12971@vidovic","subject":"Re: [PATCH v3] Re: git-am: fix maildir support regression: accept email file as patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-16T02:41:31Z","receivedAt":"2009-07-16T02:41:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:\n\n> I don't see the reason to have the option -v. It's only related to\n> what's printed to output and doesn't change the exit status which\n> tell us if an expression has matched.\n>\n> This gives:\n>\n>    grep -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null &&\n>    patch_format=mbox\n\nThat grep says \"if you see a single line that matches the pattern, even if\nall the other lines are garbage, report it as a match\".\n\nSee \"something like this\" patch in my other message. It filters the entire\nheader to make sure there is no line that does not match (that is what -v\nis about), and make it report success when there is even a signle line\nthat does not.\n\n    $ (echo yes; echo no) | grep -v -e yes ; echo $?\n    no\n    0\n    $ (echo yes; echo yes) | grep -v -e yes ; echo $?\n    1\n\nThat is why I wrote the \"how about this\" patch with \"||\" like this:\n\n    grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n    patch_format=mbox\n\nIf everything is header, grep says \"nothing matches\", and patch_format\nis set to mbox.\n"},{"id":"118069","messageId":"20090716025921.GE12971@vidovic","threadId":"20125","inReplyTo":"7vfxcxbbqw.fsf@alter.siamese.dyndns.org","subject":"[PATCH v3] Re: git-am: fix maildir support regression: accept email file as patch","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T02:59:21Z","receivedAt":"2009-07-16T02:59:21Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 15/07/09, Junio C Hamano wrote:\n> Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:\n>\n> So I do not think there is any breakage that rejects good input with his\n> patch.\n\nExact. It broke my workflow (at least) and was able to do it because the\nprevious git-am was permiting it. Looking closer to the code made me\nunderstand where I was wrong.\n\n> I am not opposed to add support for individual pieces of e-mail without\n> forcing them to be in Berkeley mbox format.  Not everybody uses mbox\n> format, and it is a logical thing to do.  Also I do not think the amount\n> of new code necessary to do so is excessive, nor such a change is risky\n> even late in a cycle after -rc0.\n\nWill do, then.\n\n> I however _do_ have issues with labeling other's patch that did not break\n> any documented behaviour as a regression, even if it is to get extra\n> attention to the issue.  That's not how we do things.\n\nOf course. As we was able to do more than documented, I did not see it\nin first place. It's a wrong assumption coming from my initial\ngit-bisect, some \"hidden\" globbing shell, and my learning curve of the\ncurrent code.\n\nIt is _NOT_ in my intention to blame anyone.\n\n-- \nNicolas Sebrecht\n"},{"id":"118072","messageId":"eae6ce0ac7ff600e3e7ab261a5f020651e39ddfa.1247717023.git.nicolas.s.dev@gmx.fr","threadId":"20125","inReplyTo":"7v7hy9bb8k.fsf@alter.siamese.dyndns.org","subject":"[PATCH v4] git-am: allow e-mail file(s) as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T04:05:23Z","receivedAt":"2009-07-16T04:05:23Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"We traditionally allowed a mbox file or a directory name of a maildir to be\ngiven to \"git am\". Even though file in a maildir (or more generally, a piece\nof RFC2822 e-mail) is not a mbox file, it contains enough information to create\na commit out of it, so there is no reason to reject one.\n\nThis builds on top of a5a6755 (git-am foreign patch support: introduce\npatch_format, 2009-05-27) that introduced mailbox format detection. The codepath\nto deal with a mbox requires it to begin with \"From \" line and also allows it to\nbegin with \"From: \", but a random piece of e-mail can and often do begin with\nany valid RFC2822 header lines.\n\nInstead of checking the first line, we extract all the lines up to the\nfirst empty line, and make sure they look like e-mail headers.\n\nSigned-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n---\n Documentation/git-am.txt |    6 +++---\n git-am.sh                |    8 ++++++++\n 2 files changed, 11 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex 32e689b..2a930a7 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -14,7 +14,7 @@ SYNOPSIS\n \t [--ignore-date]\n \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n \t [--reject] [-q | --quiet]\n-\t [<mbox> | <Maildir>...]\n+\t [<mbox> | <Maildir>... | <email>... ]\n 'git am' (--skip | --resolved | --abort)\n \n DESCRIPTION\n@@ -25,8 +25,8 @@ current branch.\n \n OPTIONS\n -------\n-<mbox>|<Maildir>...::\n-\tThe list of mailbox files to read patches from. If you do not\n+<mbox>|<Maildir>...|<email>...::\n+\tThe list of mailbox files or email to read patches from. If you do not\n \tsupply this argument, the command reads from the standard input.\n \tIf you supply directories, they will be treated as Maildirs.\n \ndiff --git a/git-am.sh b/git-am.sh\nindex d64d997..87a886d 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -162,6 +162,14 @@ check_patch_format () {\n \t\treturn 0\n \tfi\n \n+\t# then, accept (series of) email(s)\n+\tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n+\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null &&\n+\t{\n+\t\tpatch_format=mbox\n+\t\treturn 0\n+\t}\n+\n \t# otherwise, check the first few lines of the first patch to try\n \t# to detect its format\n \t{\n-- \n1.6.4.rc0.129.gdc42\n"},{"id":"118073","messageId":"20090716041056.GF12971@vidovic","threadId":"20125","inReplyTo":"eae6ce0ac7ff600e3e7ab261a5f020651e39ddfa.1247717023.git.nicolas.s.dev@gmx.fr","subject":"[PATCH v4] Re: git-am: allow e-mail file(s) as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T04:10:56Z","receivedAt":"2009-07-16T04:10:56Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 16/07/09, Nicolas Sebrecht wrote:\n\n> +\t# then, accept (series of) email(s)\n> +\tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n> +\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null &&\n\nAnd again, it's wrong here.\n\n-- \nNicolas Sebrecht\n"},{"id":"118074","messageId":"eb6317e39369adc8d2594c35ee351b49aaadcc24.1247721562.git.nicolas.s.dev@gmx.fr","threadId":"20125","inReplyTo":"7v7hy9bb8k.fsf@alter.siamese.dyndns.org","subject":"[PATCH v5] git-am: allow e-mail file(s) as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T05:23:02Z","receivedAt":"2009-07-16T05:23:02Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"We traditionally allowed a mbox file or a directory name of a maildir to be\ngiven to \"git am\". Even though file in a maildir (or more generally, a piece\nof RFC2822 e-mail) is not a mbox file, it contains enough information to create\na commit out of it, so there is no reason to reject one.\n\nThis builds on top of a5a6755 (git-am foreign patch support: introduce\npatch_format, 2009-05-27) that introduced mailbox format detection. The codepath\nto deal with a mbox requires it to begin with \"From \" line and also allows it to\nbegin with \"From: \", but a random piece of e-mail can and often do begin with\nany valid RFC2822 header lines.\n\nInstead of checking the first line, we extract all the lines up to the\nfirst empty line, and make sure they look like e-mail headers.\n\nSigned-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n---\n\nThis should be the last version of this *%/Â£ patch.\nThanks Junio for your feedbacks.\n\n Documentation/git-am.txt |    6 +++---\n git-am.sh                |   11 +++++++++++\n 2 files changed, 14 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex 32e689b..2a930a7 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -14,7 +14,7 @@ SYNOPSIS\n \t [--ignore-date]\n \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n \t [--reject] [-q | --quiet]\n-\t [<mbox> | <Maildir>...]\n+\t [<mbox> | <Maildir>... | <email>... ]\n 'git am' (--skip | --resolved | --abort)\n \n DESCRIPTION\n@@ -25,8 +25,8 @@ current branch.\n \n OPTIONS\n -------\n-<mbox>|<Maildir>...::\n-\tThe list of mailbox files to read patches from. If you do not\n+<mbox>|<Maildir>...|<email>...::\n+\tThe list of mailbox files or email to read patches from. If you do not\n \tsupply this argument, the command reads from the standard input.\n \tIf you supply directories, they will be treated as Maildirs.\n \ndiff --git a/git-am.sh b/git-am.sh\nindex d64d997..2b55ddc 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -162,6 +162,17 @@ check_patch_format () {\n \t\treturn 0\n \tfi\n \n+\t# Then, accept what really looks like (series of) email(s).\n+\t# the first sed select headers but the folded ones\n+\tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n+\t# this one is necessary for the next 'grep -v'\n+\tsed -e '/^$/d' |\n+\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' ||\n+\t{\n+\t\tpatch_format=mbox\n+\t\treturn 0\n+\t}\n+\n \t# otherwise, check the first few lines of the first patch to try\n \t# to detect its format\n \t{\n-- \n1.6.4.rc0.129.gdc42\n"},{"id":"118083","messageId":"4A5ED22B.6050101@gmail.com","threadId":"20125","inReplyTo":"eb6317e39369adc8d2594c35ee351b49aaadcc24.1247721562.git.nicolas.s.dev@gmx.fr","subject":"Re: [PATCH v5] git-am: allow e-mail file(s) as input","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-16T07:09:31Z","receivedAt":"2009-07-16T07:09:31Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Nicolas Sebrecht wrote:\n> diff --git a/git-am.sh b/git-am.sh\n> index d64d997..2b55ddc 100755\n> --- a/git-am.sh\n> +++ b/git-am.sh\n> @@ -162,6 +162,17 @@ check_patch_format () {\n>  \t\treturn 0\n>  \tfi\n>  \n> +\t# Then, accept what really looks like (series of) email(s).\n> +\t# the first sed select headers but the folded ones\n> +\tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n> +\t# this one is necessary for the next 'grep -v'\n> +\tsed -e '/^$/d' |\n> +\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' ||\n> +\t{\n> +\t\tpatch_format=mbox\n> +\t\treturn 0\n> +\t}\n> +\n>  \t# otherwise, check the first few lines of the first patch to try\n>  \t# to detect its format\n>  \t{\n\nThis fails t4150-am.sh #10 (am -3 -q is quiet). You should redirect the\noutput of the sed and grep to /dev/null like Junio did in his \"how about\nthis\" patch.\n\nAlso, writing some tests would be helpful.\n"},{"id":"118087","messageId":"7v8wip9jjw.fsf@alter.siamese.dyndns.org","threadId":"20125","inReplyTo":"4A5ED22B.6050101@gmail.com","subject":"Re: [PATCH v5] git-am: allow e-mail file(s) as input","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-16T07:24:51Z","receivedAt":"2009-07-16T07:24:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stephen Boyd <bebarino@gmail.com> writes:\n\n> Nicolas Sebrecht wrote:\n>> diff --git a/git-am.sh b/git-am.sh\n>> index d64d997..2b55ddc 100755\n>> --- a/git-am.sh\n>> +++ b/git-am.sh\n>> @@ -162,6 +162,17 @@ check_patch_format () {\n>>  \t\treturn 0\n>>  \tfi\n>>  \n>> +\t# Then, accept what really looks like (series of) email(s).\n>> +\t# the first sed select headers but the folded ones\n>> +\tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n>> +\t# this one is necessary for the next 'grep -v'\n>> +\tsed -e '/^$/d' |\n>> +\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' ||\n>> +\t{\n>> +\t\tpatch_format=mbox\n>> +\t\treturn 0\n>> +\t}\n>> +\n>>  \t# otherwise, check the first few lines of the first patch to try\n>>  \t# to detect its format\n>>  \t{\n>\n> This fails t4150-am.sh #10 (am -3 -q is quiet). You should redirect the\n> output of the sed and grep to /dev/null like Junio did in his \"how about\n> this\" patch.\n\nHonestly speaking, I do not understand why Nicolas changed my patch at\nall.\n\nThis patch wastes an extra sed process, introduces [[:blank::]] where\nspace and tab inside [] is perfectly adequate, and we know the latter is\nunderstood by everybody's sed.\n\nThe worst part is that this check was moved before the most common case of\nmbox file for which none of the overhead for this this extra processing is\nnecessary.\n\nAdmittedly, it was a \"something like this\" patch and wasn't tested at all,\nand I would not be entirely surprised if he saw some breakages in it after\ntesting with my patch, but if that was the case, some comment after ---\nwould have been very helpful.  Nicolas?\n\n> Also, writing some tests would be helpful.\n\nThat is true.  A test would illustrate why this more expensive test must\ncome before the existing cheaper tests for common cases (if such a\nbreakage was the reason his patch looks different from mine), for example.\n"},{"id":"118090","messageId":"20090716075055.GI12971@vidovic","threadId":"20125","inReplyTo":"7v8wip9jjw.fsf@alter.siamese.dyndns.org","subject":"[PATCH v5] Re: git-am: allow e-mail file(s) as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T07:50:55Z","receivedAt":"2009-07-16T07:50:55Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 16/07/09, Junio C Hamano wrote:\n> Stephen Boyd <bebarino@gmail.com> writes:\n> > Nicolas Sebrecht wrote:\n> \n> >> +\t# Then, accept what really looks like (series of) email(s).\n> >> +\t# the first sed select headers but the folded ones\n> >> +\tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n> >> +\t# this one is necessary for the next 'grep -v'\n> >> +\tsed -e '/^$/d' |\n> >> +\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' ||\n> >> +\t{\n> >> +\t\tpatch_format=mbox\n> >> +\t\treturn 0\n> >> +\t}\n> >> +\n> >>  \t# otherwise, check the first few lines of the first patch to try\n> >>  \t# to detect its format\n> >>  \t{\n> >\n> > This fails t4150-am.sh #10 (am -3 -q is quiet). You should redirect the\n> > output of the sed and grep to /dev/null like Junio did in his \"how about\n> > this\" patch.\n\nThank you.\n\n> Honestly speaking, I do not understand why Nicolas changed my patch at\n> all.\n> \n> This patch wastes an extra sed process\n\nShould we really worry about that in a script like git-am.sh? I mean,\ndoes it matter in a day to day work?\n\n>                                         introduces [[:blank::]] where\n> space and tab inside [] is perfectly adequate, and we know the latter is\n> understood by everybody's sed.\n\nBut is harder to read in editors.\n\n> The worst part is that this check was moved before the most common case of\n> mbox file for which none of the overhead for this this extra processing is\n> necessary.\n\nWell, I did this move just because of the logical structure of the code.\nThat said, you're right about the overhead.\n\n-- \nNicolas Sebrecht\n"},{"id":"118093","messageId":"20090716080657.GJ12971@vidovic","threadId":"20125","inReplyTo":"20090716075055.GI12971@vidovic","subject":"[PATCH v5] Re: git-am: allow e-mail file(s) as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T08:06:57Z","receivedAt":"2009-07-16T08:06:57Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 16/07/09, Nicolas Sebrecht wrote:\n> The 16/07/09, Junio C Hamano wrote:\n> > Stephen Boyd <bebarino@gmail.com> writes:\n> > > Nicolas Sebrecht wrote:\n> > \n> > >> +\t# Then, accept what really looks like (series of) email(s).\n> > >> +\t# the first sed select headers but the folded ones\n> > >> +\tsed -e '/^$/q' -e '/^[[:blank:]]/d' \"$1\" |\n> > >> +\t# this one is necessary for the next 'grep -v'\n> > >> +\tsed -e '/^$/d' |\n> > >> +\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' ||\n> > >> +\t{\n> > >> +\t\tpatch_format=mbox\n> > >> +\t\treturn 0\n> > >> +\t}\n> > >> +\n> > >>  \t# otherwise, check the first few lines of the first patch to try\n> > >>  \t# to detect its format\n> > >>  \t{\n> > >\n> > > This fails t4150-am.sh #10 (am -3 -q is quiet). You should redirect the\n> > > output of the sed and grep to /dev/null like Junio did in his \"how about\n> > > this\" patch.\n> \n> Thank you.\n> \n> > Honestly speaking, I do not understand why Nicolas changed my patch at\n> > all.\n> > \n> > This patch wastes an extra sed process\n> \n> Should we really worry about that in a script like git-am.sh? I mean,\n> does it matter in a day to day work?\n\nOh I've forgotten, yes we need it: sed -e '/^$/q' leaves this matching\nline to the output. An extra CRLF makes 'grep -v' fail.\n\n> >                                         introduces [[:blank::]] where\n> > space and tab inside [] is perfectly adequate, and we know the latter is\n> > understood by everybody's sed.\n> \n> But is harder to read in editors.\n> \n> > The worst part is that this check was moved before the most common case of\n> > mbox file for which none of the overhead for this this extra processing is\n> > necessary.\n> \n> Well, I did this move just because of the logical structure of the code.\n> That said, you're right about the overhead.\n\n-- \nNicolas Sebrecht\n"},{"id":"118097","messageId":"4A5EE0EA.5000008@viscovery.net","threadId":"20125","inReplyTo":"20090716075055.GI12971@vidovic","subject":"Re: [PATCH v5] Re: git-am: allow e-mail file(s) as input","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-07-16T08:12:26Z","receivedAt":"2009-07-16T08:12:26Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Nicolas Sebrecht schrieb:\n> The 16/07/09, Junio C Hamano wrote:\n>>                                         introduces [[:blank::]] where\n>> space and tab inside [] is perfectly adequate, and we know the latter is\n>> understood by everybody's sed.\n> \n> But is harder to read in editors.\n\nTough luck. [[:blank:]] is a *portability* obstacle.\n\n-- Hannes\n"},{"id":"118099","messageId":"4A5EE224.6020702@viscovery.net","threadId":"20125","inReplyTo":"20090716080657.GJ12971@vidovic","subject":"Re: [PATCH v5] Re: git-am: allow e-mail file(s) as input","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-07-16T08:17:40Z","receivedAt":"2009-07-16T08:17:40Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Nicolas Sebrecht schrieb:\n> The 16/07/09, Nicolas Sebrecht wrote:\n>> The 16/07/09, Junio C Hamano wrote:\n>>> This patch wastes an extra sed process\n>> Should we really worry about that in a script like git-am.sh? I mean,\n>> does it matter in a day to day work?\n> \n> Oh I've forgotten, yes we need it: sed -e '/^$/q' leaves this matching\n> line to the output. An extra CRLF makes 'grep -v' fail.\n\nThen make it\n\n    sed -n -e '/^$/q' -e p\n\nThis won't print the trailing empty line.\n\n-- Hannes\n"},{"id":"118122","messageId":"f006bbb9c754c80c133798ff70db5b5291dae060.1247766192.git.nicolas.s.dev@gmx.fr","threadId":"20125","inReplyTo":"7v8wip9jjw.fsf@alter.siamese.dyndns.org","subject":"[PATCH v6] mailinfo: allow e-mail files as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-16T17:45:34Z","receivedAt":"2009-07-16T17:45:34Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"We traditionally allowed a mbox file or a directory name of a maildir to be\ngiven to \"git am\".  Even though an individual file in a maildir (or more\ngenerally, a piece of RFC2822 e-mail) is not a mbox file, it contains enough\ninformation to create a commit out of it, so there is no reason to reject one.\nIt allows to run 'git am' with an email list argument, something like:\n\n $ git am dir/*\n $ git am email1 email2\n\nThis builds on top of a5a6755 (git-am foreign patch support: introduce\npatch_format, 2009-05-27) that introduced mailbox format detection.  The\ncodepath to deal with a mbox requires it to begin with \"From \" line and\nalso allows it to begin with \"From: \", but a random piece of e-mail can\nand often do begin with any valid RFC2822 header lines.\n\nInstead of checking the first line, we extract all the lines up to the\nfirst empty line, and make sure they look like e-mail headers.\n\nSigned-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n---\n Documentation/git-am.txt |    6 ++--\n git-am.sh                |   14 ++++++++++++\n t/t4150-am.sh            |   54 ++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 71 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex 32e689b..2a930a7 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -14,7 +14,7 @@ SYNOPSIS\n \t [--ignore-date]\n \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n \t [--reject] [-q | --quiet]\n-\t [<mbox> | <Maildir>...]\n+\t [<mbox> | <Maildir>... | <email>... ]\n 'git am' (--skip | --resolved | --abort)\n \n DESCRIPTION\n@@ -25,8 +25,8 @@ current branch.\n \n OPTIONS\n -------\n-<mbox>|<Maildir>...::\n-\tThe list of mailbox files to read patches from. If you do not\n+<mbox>|<Maildir>...|<email>...::\n+\tThe list of mailbox files or email to read patches from. If you do not\n \tsupply this argument, the command reads from the standard input.\n \tIf you supply directories, they will be treated as Maildirs.\n \ndiff --git a/git-am.sh b/git-am.sh\nindex d64d997..617ca2f 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -191,6 +191,20 @@ check_patch_format () {\n \t\t\tesac\n \t\t\t;;\n \t\tesac\n+\t\tif test -z \"$patch_format\" &&\n+\t\t\ttest -n \"$l1\" &&\n+\t\t\ttest -n \"$l2\" &&\n+\t\t\ttest -n \"$l3\"\n+\t\tthen\n+\t\t\t# This begins with three non-empty lines.  Is this a\n+\t\t\t# piece of e-mail a-la RFC2822?  Grab all the headers,\n+\t\t\t# discarding the indented remainder of folded lines,\n+\t\t\t# and see if it looks like that they all begin with the\n+\t\t\t# header field names...\n+\t\t\tsed -n -e '/^$/q' -e '/^[ \t]/d' -e p \"$1\" |\n+\t\t\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n+\t\t\tpatch_format=mbox\n+\t\tfi\n \t} < \"$1\" || clean_abort\n }\n \ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex a12bf84..4c99240 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -63,6 +63,53 @@ with the data reset to initial values.\n \n EOF\n \n+cat >rfc2822_email <<EOF\n+Return-Path: <user@domain.name>\n+X-Flags: 0000\n+\t999\n+Delivered-To: delivery to user@domain.name\n+Received: (qmail invoked by alias); 16 Jul 2009 05:25:49 -0000\n+Received: from vger.knl.xyz (EHLO vger.knl.xyz) [4.3.2.1]\n+  by mx0.gmx.com (mx-us004) with SMTP; 16 Jul 2009 01:25:49 -0400\n+Received: (majordomo@vger.knl.xyz) by vger.knl.xyz via listexpand\n+\tid S1757506AbZGPFZp (ORCPT <rfc822;user@domain.name>);\n+\tThu, 16 Jul 2009 01:25:45 -0400\n+Received: (majordomo@vger.knl.xyz) by vger.knl.xyz id F1757505AbZGPPER\n+\t(ORCPT <rfc822;git-outgoing>); Thu, 16 Jul 2009 01:25:45 -0400\n+Received: from hsmail.qwknetllc.com ([208.71.137.138]:35086 \"EHLO\n+\thsmail.qwknetllc.com\" rhost-flags-OK-OK-OK-OK) by vger.knl.xyz\n+\twith ESMTP id F1757505AbZGPPER (ORCPT <rfc822;git@vger.knl.xyz>);\n+\tThu, 16 Jul 2009 01:25:44 -0400\n+X-Greylist: delayed 401 seconds by postgrey-1.27 at vger.knl.xyz; Thu, 16 Jul 2009 01:25:44 EDT\n+Received: (qmail 31380 invoked by uid 399); 15 Jul 2009 23:19:01 -0600\n+Received: from unknown (HELO ?192.168.1.107?) (user@domain.name@1.2.3.4)\n+  by hsmail.qwknetllc.com with ESMTPAM; 15 Jul 2009 23:19:01 -0600\n+X-Originating-IP: 1.2.3.4\n+Message-ID: <ADDDASSSS.123456789@domain.name>\n+Date:\tWed, 15 Jul 2009 23:19:05 -0600\n+From:\tsender <user@domain.name>\n+User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)\n+MIME-Version: 1.0\n+To:\tgit@vger.knl.xyz\n+Subject: [PATCH] apply patch from rfc2822 formated email\n+Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n+Content-Transfer-Encoding: 7bit\n+Sender:\tgit-owner@vger.knl.xyz\n+Precedence: bulk\n+List-ID: <git.vger.knl.xyz>\n+X-Mailing-List:\tgit@vger.knl.xyz\n+X-Antivirus: 0 (no virus found)\n+X-Antispam: -2 (not scanned, spam filter disabled)\n+X-UID: PIhtafixEX1VXO6puPmJy7wxySDc4NMwX\n+Content-Length: 123465\n+\n+This text is part of the internal format of your mail folder, and is not\n+a real message.  It is created automatically by the mail system software.\n+If deleted, important folder data will be lost, and it will be re-created\n+with the data reset to initial values.\n+\n+EOF\n+\n echo \"Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\" >expected\n \n test_expect_success setup '\n@@ -222,6 +269,13 @@ test_expect_success 'am takes patches from a Pine mailbox' '\n \ttest -z \"$(git diff master^..HEAD)\"\n '\n \n+test_expect_success 'am takes patches from a RFC2822 formated email' '\n+\tgit checkout first &&\n+\tcat rfc2822_email patch1 | git am &&\n+\t! test -d .git/rebase-apply &&\n+\ttest -z \"$(git diff master^..HEAD)\"\n+'\n+\n test_expect_success 'am fails on mail without patch' '\n \ttest_must_fail git am <failmail &&\n \trm -r .git/rebase-apply/\n-- \n1.6.4.rc1.169.gd0406\n"},{"id":"118147","messageId":"7v1vog6rw9.fsf@alter.siamese.dyndns.org","threadId":"20125","inReplyTo":"f006bbb9c754c80c133798ff70db5b5291dae060.1247766192.git.nicolas.s.dev@gmx.fr","subject":"Re: [PATCH v6] mailinfo: allow e-mail files as input","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-17T01:05:10Z","receivedAt":"2009-07-17T01:05:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:\n\n> We traditionally allowed a mbox file or a directory name of a maildir to be\n> ...\n> Signed-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n\nThanks.\n\nI have one more comment on the test script, but it's something I can\nlocally fix (iow, there is no need to resend your patch if there is no\nother issue pointed out by others, and if you agree to my suggested\nimprovements).\n\n> diff --git a/t/t4150-am.sh b/t/t4150-am.sh\n> index a12bf84..4c99240 100755\n> --- a/t/t4150-am.sh\n> +++ b/t/t4150-am.sh\n> @@ -63,6 +63,53 @@ with the data reset to initial values.\n>  \n>  EOF\n>  \n> +cat >rfc2822_email <<EOF\n> +Return-Path: <user@domain.name>\n> +X-Flags: 0000\n> +\t999\n\nPlease quote that EOF if you do not mean to have any $variable substituted\nin the \"here document\", like this:\n\n\tcat >rfc2822_email <<\\EOF\n        ... here document comes here ...\n\tEOF\n\nOtherwise reviewers need to waste time looking for what is being replaced\nin the huge here document to understand what is going on.\n\n> +Delivered-To: delivery to user@domain.name\n> +Received: (qmail invoked by alias); 16 Jul 2009 05:25:49 -0000\n> +Received: from vger.knl.xyz (EHLO vger.knl.xyz) [4.3.2.1]\n> +  by mx0.gmx.com (mx-us004) with SMTP; 16 Jul 2009 01:25:49 -0400\n> ...\n> +\n> +EOF\n> +\n\nThe headers look a bit too excessive to my taste, but probably you wanted\nto take a real-life example.  If that is the case, I suspect the manually\nadded X-Flags: at the beginning defeats that purpose, though.  I'd suggest\neither removing the hand-munging, or triming the Received: sequence to\nmake it a bit shorter.\n\n> @@ -222,6 +269,13 @@ test_expect_success 'am takes patches from a Pine mailbox' '\n>  \ttest -z \"$(git diff master^..HEAD)\"\n>  '\n>  \n> +test_expect_success 'am takes patches from a RFC2822 formated email' '\n> +\tgit checkout first &&\n> +\tcat rfc2822_email patch1 | git am &&\n> +\t! test -d .git/rebase-apply &&\n> +\ttest -z \"$(git diff master^..HEAD)\"\n> +'\n\nThese days we tend to write the last step\n\n\tgit diff --exit-code master^ HEAD\n\nwhich allows \"sh t4150-am.sh -i -v\" to be more useful when debugging.  But\nthe existing tests in this script are old fashioned, and you matched their\nstyle in this patch, which is very good.\n\nWe probably would want a separate patch to modernize them after 1.6.4,\nthough.\n"},{"id":"118151","messageId":"20090717022048.GA12945@vidovic","threadId":"20125","inReplyTo":"7v1vog6rw9.fsf@alter.siamese.dyndns.org","subject":"[PATCH v6] Re: mailinfo: allow e-mail files as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-17T02:20:48Z","receivedAt":"2009-07-17T02:20:48Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 16/07/09, Junio C Hamano wrote:\n> Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:\n> \n> > We traditionally allowed a mbox file or a directory name of a maildir to be\n> > ...\n> > Signed-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n> \n> Thanks.\n\nThank you in first place. I appreciate your patience and explanations.\n\n> I have one more comment on the test script, but it's something I can\n> locally fix (iow, there is no need to resend your patch if there is no\n> other issue pointed out by others, and if you agree to my suggested\n> improvements).\n\n... and thank you for leting the door open to agreements.\n\n> > +cat >rfc2822_email <<EOF\n> > +Return-Path: <user@domain.name>\n> > +X-Flags: 0000\n> > +\t999\n> \n> The headers look a bit too excessive to my taste, but probably you wanted\n> to take a real-life example.\n\nYes.\n\n>                               If that is the case, I suspect the manually\n> added X-Flags: at the beginning defeats that purpose, though.\n\nI don't see what purpose it defeats. What am I missing?\n\n>                                                                I'd suggest\n> either removing the hand-munging, or triming the Received: sequence to\n> make it a bit shorter.\n\nIt's fine here.\n\n> These days we tend to write the last step\n> \n> \tgit diff --exit-code master^ HEAD\n> \n> which allows \"sh t4150-am.sh -i -v\" to be more useful when debugging.\n\nI'll look at that closer.\n\n-- \nNicolas Sebrecht\n"},{"id":"118169","messageId":"20090717190601.6117@nanako3.lavabit.com","threadId":"20125","inReplyTo":"f006bbb9c754c80c133798ff70db5b5291dae060.1247766192.git.nicolas.s.dev@gmx.fr","subject":"Re: [PATCH v6] mailinfo: allow e-mail files as input","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2009-07-17T10:06:01Z","receivedAt":"2009-07-17T10:06:01Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting Nicolas Sebrecht <nicolas.s.dev@gmx.fr>:\n\n> We traditionally allowed a mbox file or a directory name of a maildir to be\n> given to \"git am\".  Even though an individual file in a maildir (or more\n> generally, a piece of RFC2822 e-mail) is not a mbox file, it contains enough\n> information to create a commit out of it, so there is no reason to reject one.\n> It allows to run 'git am' with an email list argument, something like:\n>\n>  $ git am dir/*\n>  $ git am email1 email2\n>\n> This builds on top of a5a6755 (git-am foreign patch support: introduce\n> patch_format, 2009-05-27) that introduced mailbox format detection.  The\n> codepath to deal with a mbox requires it to begin with \"From \" line and\n> also allows it to begin with \"From: \", but a random piece of e-mail can\n> and often do begin with any valid RFC2822 header lines.\n>\n> Instead of checking the first line, we extract all the lines up to the\n> first empty line, and make sure they look like e-mail headers.\n>\n> Signed-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n> ---\n\nCould 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)? \n\n>  Documentation/git-am.txt |    6 ++--\n>  git-am.sh                |   14 ++++++++++++\n>  t/t4150-am.sh            |   54 ++++++++++++++++++++++++++++++++++++++++++++++\n>  3 files changed, 71 insertions(+), 3 deletions(-)\n>\n> diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\n> index 32e689b..2a930a7 100644\n> --- a/Documentation/git-am.txt\n> +++ b/Documentation/git-am.txt\n> @@ -14,7 +14,7 @@ SYNOPSIS\n>  \t [--ignore-date]\n>  \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n>  \t [--reject] [-q | --quiet]\n> -\t [<mbox> | <Maildir>...]\n> +\t [<mbox> | <Maildir>... | <email>... ]\n>  'git am' (--skip | --resolved | --abort)\n>  \n>  DESCRIPTION\n> @@ -25,8 +25,8 @@ current branch.\n>  \n>  OPTIONS\n>  -------\n> -<mbox>|<Maildir>...::\n> -\tThe list of mailbox files to read patches from. If you do not\n> +<mbox>|<Maildir>...|<email>...::\n> +\tThe list of mailbox files or email to read patches from. If you do not\n>  \tsupply this argument, the command reads from the standard input.\n>  \tIf you supply directories, they will be treated as Maildirs.\n>  \n\nI 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.\n\nWhy does this description have ... in it? If I'm reading it correctly, the code in check_patch_format function checks only the first file.\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"},{"id":"118195","messageId":"7vtz1b3x26.fsf@alter.siamese.dyndns.org","threadId":"20125","inReplyTo":"20090717190601.6117@nanako3.lavabit.com","subject":"Re: [PATCH v6] mailinfo: allow e-mail files as input","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-07-17T19:54:09Z","receivedAt":"2009-07-17T19:54:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nanako Shiraishi <nanako3@lavabit.com> writes:\n\n>>  OPTIONS\n>>  -------\n>> -<mbox>|<Maildir>...::\n>> -\tThe list of mailbox files to read patches from. If you do not\n>> +<mbox>|<Maildir>...|<email>...::\n>> +\tThe list of mailbox files or email to read patches from. If you do not\n>>  \tsupply this argument, the command reads from the standard input.\n>>  \tIf you supply directories, they will be treated as Maildirs.\n>>  \n>\n> 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.\n\nI could tell _you_ that I prefer to see people go back to the list archive\ninstead of saying \"I wasn't following\", but I cannot say that to readers\nof the documentation after this patch is applied.  After re-reading the\nabove, you are right---it is unclear.\n\n> 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.\n\nGood eyes.\n\nThis actually is an issue with the Guiseppe's multi-format support patch\nin that we assume that the command line input are of uniform type, check\nonly $1 and assume $2 and subsequent are suitable to be fed to the same\nsplitter.\n\nI do not think it is necessary to allow mixed input.  We certainly could,\nbut why bother?  It is not a sensible nor common thing to do.\n\nAlso the documentation said we take only one mbox or multiple Maildirs,\nbut in reality we can take multiple mboxes just fine, so <mbox> should\nhave had \"...\" at the end (we could lose the ellipses from all of them for\nbrevity).  Oh, and it should list the other formats Giuseppe added.\n\n    <mbox>|<maildir>|<email>::\n\n\t    One or more of the same type of mail source to read e-mails\n            from.  A directory is taken as a mailbox in the maildir\n            format.  A file is taken as UNIX mbox, StGit patch series\n            file, or a single piece of e-mail in RFC2822 format.\n"},{"id":"118205","messageId":"20090717220424.GA12968@vidovic","threadId":"20125","inReplyTo":"7vtz1b3x26.fsf@alter.siamese.dyndns.org","subject":"[PATCH v6] Re: mailinfo: allow e-mail files as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-07-17T22:04:24Z","receivedAt":"2009-07-17T22:04:24Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"The 17/07/09, Junio C Hamano wrote:\n> Nanako Shiraishi <nanako3@lavabit.com> writes:\n> \n> > 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.\n\n( Please, wrap your lines to something convenient. )\n\n> Good eyes.\n> \n> This actually is an issue with the Guiseppe's multi-format support patch\n> in that we assume that the command line input are of uniform type, check\n> only $1 and assume $2 and subsequent are suitable to be fed to the same\n> splitter.\n> \n> I do not think it is necessary to allow mixed input.  We certainly could,\n> but why bother?  It is not a sensible nor common thing to do.\n\nI agree.\n\n> Also the documentation said we take only one mbox or multiple Maildirs,\n> but in reality we can take multiple mboxes just fine, so <mbox> should\n> have had \"...\" at the end (we could lose the ellipses from all of them for\n> brevity).  Oh, and it should list the other formats Giuseppe added.\n> \n>     <mbox>|<maildir>|<email>::\n> \n> \t    One or more of the same type of mail source to read e-mails\n>             from.  A directory is taken as a mailbox in the maildir\n>             format.  A file is taken as UNIX mbox, StGit patch series\n>             file, or a single piece of e-mail in RFC2822 format.\n\nStrictly speacking, this is not what I understand from the code: only\none StGit patch series can be given at the command line.\n\n     <mbox>|<maildir>|<stgit>|<email>::\n \n \t    One or more of the same type of mail source to read e-mails\n             from.  A directory is taken as a mailbox in the maildir\n             format.  A file is taken as UNIX mbox, StGit patch file,\n             or a single piece of e-mail in RFC2822 format.  StGit\n             patches series are also supported but only one series at\n             a time. \n\n\n-- \nNicolas Sebrecht\n"},{"id":"119800","messageId":"538521a8fef8b898717e52e4d1913fdf24593679.1249577595.git.nicolas.s.dev@gmx.fr","threadId":"20125","inReplyTo":"20090717220424.GA12968@vidovic","subject":"[PATCH v7] mailinfo: allow e-mail files as input","fromName":"Nicolas Sebrecht","fromEmail":"nicolas.s.dev@gmx.fr","sentAt":"2009-08-06T17:07:50Z","receivedAt":"2009-08-06T17:07:50Z","isPatch":true,"sender":{"key":"nicolas.s.dev@gmx.fr","avatar":null},"body":"We traditionally allowed a mbox file or a directory name of a maildir to be\ngiven to \"git am\".  Even though an individual file in a maildir (or more\ngenerally, a piece of RFC2822 e-mail) is not a mbox file, it contains enough\ninformation to create a commit out of it, so there is no reason to reject one.\nIt allows to run 'git am' with an email list argument, something like:\n\n $ git am dir/*\n $ git am email1 email2\n\nThis builds on top of a5a6755 (git-am foreign patch support: introduce\npatch_format, 2009-05-27) that introduced mailbox format detection.  The\ncodepath to deal with a mbox requires it to begin with \"From \" line and\nalso allows it to begin with \"From: \", but a random piece of e-mail can\nand often do begin with any valid RFC2822 header lines.\n\nInstead of checking the first line, we extract all the lines up to the\nfirst empty line, and make sure they look like e-mail headers.\n\nCredit on most of how this has been written goes to Junio.\n\nSigned-off-by: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n---\n\nThis round after v1.6.4 release and includes last comments pointed out in\n\n\tSubject: Re: [PATCH v6] mailinfo: allow e-mail files as input\n\tFrom: Junio C Hamano <gitster@pobox.com>\n\tDate: Thu, 16 Jul 2009 18:05:10 -0700\n\tMessage-ID: <7v1vog6rw9.fsf@alter.siamese.dyndns.org>\n\n\tSubject: [PATCH v6] Re: mailinfo: allow e-mail files as input\n\tFrom: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>\n\tDate: Sat, 18 Jul 2009 00:04:24 +0200\n\tMessage-ID: <20090717220424.GA12968@vidovic>\n\n\n Documentation/git-am.txt |   13 ++++++++-----\n git-am.sh                |   14 ++++++++++++++\n t/t4150-am.sh            |   30 ++++++++++++++++++++++++++++++\n 3 files changed, 52 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex 32e689b..a19a82d 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -14,7 +14,7 @@ SYNOPSIS\n \t [--ignore-date]\n \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n \t [--reject] [-q | --quiet]\n-\t [<mbox> | <Maildir>...]\n+\t [<mbox> | <Maildir>... | <email>... ]\n 'git am' (--skip | --resolved | --abort)\n \n DESCRIPTION\n@@ -25,10 +25,13 @@ current branch.\n \n OPTIONS\n -------\n-<mbox>|<Maildir>...::\n-\tThe list of mailbox files to read patches from. If you do not\n-\tsupply this argument, the command reads from the standard input.\n-\tIf you supply directories, they will be treated as Maildirs.\n+<mbox>|<Maildir>|<stgit>|<email>::\n+\tOne or more of the same type of mail source to read e-mails\n+\tfrom.  A directory is taken as a mailbox in the maildir\n+\tformat.  A file is taken as UNIX mbox, StGit patch file,\n+\tor a single piece of e-mail in RFC2822 format.  StGit\n+\tpatches series are also supported but only one series at\n+\ta time.\n \n -s::\n --signoff::\ndiff --git a/git-am.sh b/git-am.sh\nindex d64d997..617ca2f 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -191,6 +191,20 @@ check_patch_format () {\n \t\t\tesac\n \t\t\t;;\n \t\tesac\n+\t\tif test -z \"$patch_format\" &&\n+\t\t\ttest -n \"$l1\" &&\n+\t\t\ttest -n \"$l2\" &&\n+\t\t\ttest -n \"$l3\"\n+\t\tthen\n+\t\t\t# This begins with three non-empty lines.  Is this a\n+\t\t\t# piece of e-mail a-la RFC2822?  Grab all the headers,\n+\t\t\t# discarding the indented remainder of folded lines,\n+\t\t\t# and see if it looks like that they all begin with the\n+\t\t\t# header field names...\n+\t\t\tsed -n -e '/^$/q' -e '/^[ \t]/d' -e p \"$1\" |\n+\t\t\tgrep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||\n+\t\t\tpatch_format=mbox\n+\t\tfi\n \t} < \"$1\" || clean_abort\n }\n \ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex a12bf84..46adbc3 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -63,6 +63,29 @@ with the data reset to initial values.\n \n EOF\n \n+cat >rfc2822_email <<\\EOF\n+Return-Path: <user@domain.name>\n+X-Flags: 0000\n+\t999\n+Delivered-To: delivery to user@domain.name\n+Received: (qmail invoked by alias); 16 Jul 2009 05:25:49 -0000\n+Received: from vger.knl.xyz (EHLO vger.knl.xyz) [4.3.2.1]\n+  by mx0.gmx.com (mx-us004) with SMTP; 16 Jul 2009 01:25:49 -0400\n+Received: (majordomo@vger.knl.xyz) by vger.knl.xyz via listexpand\n+\tid S1757506AbZGPFZp (ORCPT <rfc822;user@domain.name>);\n+\tThu, 16 Jul 2009 01:25:45 -0400\n+Date:\tWed, 15 Jul 2009 23:19:05 -0600\n+From:\tsender <user@domain.name>\n+Subject: [PATCH] apply patch from rfc2822 formated email\n+Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n+\n+This text is part of the internal format of your mail folder, and is not\n+a real message.  It is created automatically by the mail system software.\n+If deleted, important folder data will be lost, and it will be re-created\n+with the data reset to initial values.\n+\n+EOF\n+\n echo \"Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\" >expected\n \n test_expect_success setup '\n@@ -222,6 +245,13 @@ test_expect_success 'am takes patches from a Pine mailbox' '\n \ttest -z \"$(git diff master^..HEAD)\"\n '\n \n+test_expect_success 'am takes patches from a RFC2822 formated email' '\n+\tgit checkout first &&\n+\tcat rfc2822_email patch1 | git am &&\n+\t! test -d .git/rebase-apply &&\n+\tgit diff --exit-code master^ HEAD\n+'\n+\n test_expect_success 'am fails on mail without patch' '\n \ttest_must_fail git am <failmail &&\n \trm -r .git/rebase-apply/\n-- \n1.6.4.124.gf10b\n"}]}