{"thread":{"id":"28000","subject":"[PATCH] git-am: ignore leading whitespace before patch","startedAt":"2011-08-02T22:20:46Z","lastAt":"2011-08-08T05:31:03Z","messageCount":10,"participants":["David Barr","Tay Ray Chuan","Sverre Rabbelier","Junio C Hamano","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"172716","messageId":"1312323646-93427-1-git-send-email-davidbarr@google.com","threadId":"28000","inReplyTo":null,"subject":"[PATCH] git-am: ignore leading whitespace before patch","fromName":"David Barr","fromEmail":"davidbarr@google.com","sentAt":"2011-08-02T22:20:46Z","receivedAt":"2011-08-02T22:20:46Z","isPatch":true,"sender":{"key":"davidbarr@google.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":"Some web-based email clients prepend whitespace to raw message\ntranscripts to workaround content-sniffing in some browsers.\nAdjust the patch format detection logic to ignore leading\nwhitespace.\n\nSigned-off-by: David Barr <davidbarr@google.com>\n---\n git-am.sh |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 463c741..19b2f0f 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -199,7 +199,11 @@ check_patch_format () {\n \t# otherwise, check the first few lines of the first patch to try\n \t# to detect its format\n \t{\n-\t\tread l1\n+\t\t# Start from first line containing non-whitespace\n+\t\tuntil [ -n \"$l1\" ]\n+\t\tdo\n+\t\t\tread l1\n+\t\tdone\n \t\tread l2\n \t\tread l3\n \t\tcase \"$l1\" in\n-- \n1.7.6\n"},{"id":"172751","messageId":"CALUzUxpn-vCWpTQyB7z9dsu8a+UBL9MPjEycOfTmyws5ndz5kA@mail.gmail.com","threadId":"28000","inReplyTo":"1312323646-93427-1-git-send-email-davidbarr@google.com","subject":"Re: [PATCH] git-am: ignore leading whitespace before patch","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-08-03T12:28:19Z","receivedAt":"2011-08-03T12:28:19Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"On Wed, Aug 3, 2011 at 6:20 AM, David Barr <davidbarr@google.com> wrote:\n> Some web-based email clients prepend whitespace to raw message\n> transcripts to workaround content-sniffing in some browsers.\n> Adjust the patch format detection logic to ignore leading\n> whitespace.\n>\n> Signed-off-by: David Barr <davidbarr@google.com>\n\nFinally, patches from GMail that play nice with git-am!\n\n  Acked-by: Tay Ray Chuan <rctay89@gmail.com>\n\n-- \nCheers,\nRay Chuan\n"},{"id":"172755","messageId":"CAGdFq_it-QAA5uSme6S715dRzHs-s-Uj=MWKzBK2MOaaSdiXtg@mail.gmail.com","threadId":"28000","inReplyTo":"CALUzUxpn-vCWpTQyB7z9dsu8a+UBL9MPjEycOfTmyws5ndz5kA@mail.gmail.com","subject":"Re: [PATCH] git-am: ignore leading whitespace before patch","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2011-08-03T13:21:44Z","receivedAt":"2011-08-03T13:21:44Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Aug 3, 2011 at 14:28, Tay Ray Chuan <rctay89@gmail.com> wrote:\n> On Wed, Aug 3, 2011 at 6:20 AM, David Barr <davidbarr@google.com> wrote:\n>> Some web-based email clients prepend whitespace to raw message\n>> transcripts to workaround content-sniffing in some browsers.\n>> Adjust the patch format detection logic to ignore leading\n>> whitespace.\n>>\n>> Signed-off-by: David Barr <davidbarr@google.com>\n>\n> Finally, patches from GMail that play nice with git-am!\n\nSo how do you get the patches out of gmail? Do you just copy/paste the\noutput of the \"Show original\" page?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"172757","messageId":"CALUzUxrubhFpLd00BomM5WwPYNwPbxCx6q7U2TG4PssaQODkZQ@mail.gmail.com","threadId":"28000","inReplyTo":"CAGdFq_it-QAA5uSme6S715dRzHs-s-Uj=MWKzBK2MOaaSdiXtg@mail.gmail.com","subject":"Re: [PATCH] git-am: ignore leading whitespace before patch","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2011-08-03T13:31:46Z","receivedAt":"2011-08-03T13:31:46Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"On Wed, Aug 3, 2011 at 9:21 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:\n> So how do you get the patches out of gmail? Do you just copy/paste the\n> output of the \"Show original\" page?\n\nI Ctrl-S from the \"Show original\" page. Using Chrome, that yields a\nmail.txt file.\n\nWithout this patch, I used to manually remove the first line (all\nempty whitespace).\n\n-- \nCheers,\nRay Chuan\n"},{"id":"172760","messageId":"CAGdFq_jm3recWwYGow0fZgw6zgwQBurTAPuAyd_qfzHLD6zGbA@mail.gmail.com","threadId":"28000","inReplyTo":"CALUzUxrubhFpLd00BomM5WwPYNwPbxCx6q7U2TG4PssaQODkZQ@mail.gmail.com","subject":"Re: [PATCH] git-am: ignore leading whitespace before patch","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2011-08-03T13:33:50Z","receivedAt":"2011-08-03T13:33:50Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Aug 3, 2011 at 15:31, Tay Ray Chuan <rctay89@gmail.com> wrote:\n> On Wed, Aug 3, 2011 at 9:21 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:\n>> So how do you get the patches out of gmail? Do you just copy/paste the\n>> output of the \"Show original\" page?\n>\n> I Ctrl-S from the \"Show original\" page. Using Chrome, that yields a\n> mail.txt file.\n\nAh, clever hack! Nice :)\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"172999","messageId":"CAFfmPPMY5FP8NbZ5Q15pW-NC_qs=i6FY7v6Pi8jkMAhkURFTmQ@mail.gmail.com","threadId":"28000","inReplyTo":"CALUzUxpn-vCWpTQyB7z9dsu8a+UBL9MPjEycOfTmyws5ndz5kA@mail.gmail.com","subject":"Re: [PATCH] git-am: ignore leading whitespace before patch","fromName":"David Barr","fromEmail":"davidbarr@google.com","sentAt":"2011-08-06T01:56:53Z","receivedAt":"2011-08-06T01:56:53Z","isPatch":true,"sender":{"key":"davidbarr@google.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":"Hi Jonathan,\n\n> On Wed, Aug 3, 2011 at 6:20 AM, David Barr <davidbarr@google.com> wrote:\n>> Some web-based email clients prepend whitespace to raw message\n>> transcripts to workaround content-sniffing in some browsers.\n>> Adjust the patch format detection logic to ignore leading\n>> whitespace.\n>>\n>> Signed-off-by: David Barr <davidbarr@google.com>\n\n>> diff --git a/git-am.sh b/git-am.sh\n>> index 463c741..19b2f0f 100755\n>> --- a/git-am.sh\n>> +++ b/git-am.sh\n>> @@ -199,7 +199,11 @@ check_patch_format () {\n>>        # otherwise, check the first few lines of the first patch to try\n>>        # to detect its format\n>>        {\n>> -               read l1\n>> +               # Start from first line containing non-whitespace\n>> +               until [ -n \"$l1\" ]\n>> +               do\n>> +                       read l1\n>> +               done\n>>                read l2\n>>                read l3\n>>                case \"$l1\" in\n\nOn Wed, Aug 3, 2011 at 10:28 PM, Tay Ray Chuan <rctay89@gmail.com> wrote:\n> Finally, patches from GMail that play nice with git-am!\n>\n>  Acked-by: Tay Ray Chuan <rctay89@gmail.com>\n\nDo you see any subtle issues in this tiny patch?\nI failed to include a test, I'll add at least one to the next version.\nI did check that it doesn't break any of the existing git-am tests.\n\n--\nDavid Barr\n"},{"id":"173006","messageId":"7vvcub16e7.fsf@alter.siamese.dyndns.org","threadId":"28000","inReplyTo":"CAFfmPPMY5FP8NbZ5Q15pW-NC_qs=i6FY7v6Pi8jkMAhkURFTmQ@mail.gmail.com","subject":"Re: [PATCH] git-am: ignore leading whitespace before patch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-08-06T05:00:16Z","receivedAt":"2011-08-06T05:00:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Barr <davidbarr@google.com> writes:\n\n> Hi Jonathan,\n> ...\n>>> diff --git a/git-am.sh b/git-am.sh\n>>> index 463c741..19b2f0f 100755\n>>> --- a/git-am.sh\n>>> +++ b/git-am.sh\n>>> @@ -199,7 +199,11 @@ check_patch_format () {\n>>>        # otherwise, check the first few lines of the first patch to try\n>>>        # to detect its format\n>>>        {\n>>> -               read l1\n>>> +               # Start from first line containing non-whitespace\n>>> +               until [ -n \"$l1\" ]\n>>> +               do\n>>> +                       read l1\n>>> +               done\n> ...\n> Do you see any subtle issues in this tiny patch?\n> I failed to include a test, I'll add at least one to the next version.\n> I did check that it doesn't break any of the existing git-am tests.\n\nIt no longer checks \"the first few lines\" but can read a lot more, so the\ncomment that precedes this block is now invalid.\n\nAlso we are rather old fashioned and we never say \"until [ ... ]\" anywhere\nin our shell scripts.\n\n\t$ git grep -e until -- '*.sh'\n\nPersonally to me this is a borderline \"Meh\", in the sense that I wouldn't\nbother to waste too much effort rejecting it, as I do not see downsides\nother than these minor points.\n\nThanks.\n"},{"id":"173112","messageId":"20110808024904.GF19551@elie.gateway.2wire.net","threadId":"28000","inReplyTo":"7vvcub16e7.fsf@alter.siamese.dyndns.org","subject":"[PATCH v2] am: ignore leading whitespace before patch","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-08-08T02:49:04Z","receivedAt":"2011-08-08T02:49:04Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"From: David Barr <davidbarr@google.com>\n\nSome web-based email clients prepend whitespace to raw message\ntranscripts to workaround content-sniffing in some browsers.  Adjust\nthe patch format detection logic to ignore leading whitespace.\n\nSo now you can apply patches from GMail with \"git am\" in three steps:\n\n 1. choose \"show original\"\n 2. tell the browser to \"save as\" (for example by pressing Ctrl+S)\n 3. run \"git am\" on the saved file\n\nThis fixes a regression introduced by v1.6.4-rc0~15^2~2 (git-am\nforeign patch support: autodetect some patch formats, 2009-05-27).\nGMail support was first introduced to \"git am\" by v1.5.4-rc0~274^2\n(Make mailsplit and mailinfo strip whitespace from the start of the\ninput, 2007-11-01).\n\nSigned-off-by: David Barr <davidbarr@google.com>\nAcked-by: Tay Ray Chuan <rctay89@gmail.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nJunio C Hamano wrote:\n\n> It no longer checks \"the first few lines\" but can read a lot more, so the\n> comment that precedes this block is now invalid.\n>\n> Also we are rather old fashioned and we never say \"until [ ... ]\" anywhere\n> in our shell scripts.\n\nGood ideas, thanks.  While at it, let's initialize l1 to protect\nagainst any stray value it might have inherited from the environment.\n\nLooking forward to the promised test, :)\nJonathan\n\n git-am.sh |   11 ++++++++---\n 1 files changed, 8 insertions(+), 3 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 463c741d..c8422dbe 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -196,10 +196,15 @@ check_patch_format () {\n \t\treturn 0\n \tfi\n \n-\t# otherwise, check the first few lines of the first patch to try\n-\t# to detect its format\n+\t# otherwise, check the first few non-blank lines of the first\n+\t# patch to try to detect its format\n \t{\n-\t\tread l1\n+\t\t# Start from first line containing non-whitespace\n+\t\tl1=\n+\t\twhile test -z \"$l1\"\n+\t\tdo\n+\t\t\tread l1\n+\t\tdone\n \t\tread l2\n \t\tread l3\n \t\tcase \"$l1\" in\n-- \n1.7.6\n"},{"id":"173118","messageId":"1312780242-91659-1-git-send-email-davidbarr@google.com","threadId":"28000","inReplyTo":"20110808024904.GF19551@elie.gateway.2wire.net","subject":"RE: [PATCH v2] am: ignore leading whitespace before patch","fromName":"David Barr","fromEmail":"davidbarr@google.com","sentAt":"2011-08-08T05:10:42Z","receivedAt":"2011-08-08T05:10:42Z","isPatch":true,"sender":{"key":"davidbarr@google.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":"Add a test for GMail-style padded email files.\n\nSigned-off-by: David Barr <davidbarr@google.com>\n---\n t/t4150-am.sh |   11 +++++++++++\n 1 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex 151404e..40a5a3e 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -167,6 +167,17 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '\n \ttest \"$(git rev-parse second^)\" = \"$(git rev-parse HEAD^)\"\n '\n \n+test_expect_success 'am applies patch e-mail with preceding whitespace' '\n+\trm -fr .git/rebase-apply &&\n+\tgit reset --hard &&\n+\tgit checkout first &&\n+\tprintf \"%256s\\\\n\" \"\" >patch1-ws.eml &&\n+\tcat patch1.eml >>patch1-ws.eml &&\n+\tgit am <patch1-ws.eml >output.out 2>&1 &&\n+\t! test -d .git/rebase-apply &&\n+\tgit diff --exit-code second\n+'\n+\n test_expect_success 'setup: new author and committer' '\n \tGIT_AUTHOR_NAME=\"Another Thor\" &&\n \tGIT_AUTHOR_EMAIL=\"a.thor@example.com\" &&\n-- \n1.7.6\n"},{"id":"173119","messageId":"CAFfmPPPpYDA39U9UYKojj90fST40voe=dgBi3QPjQdhBT89NmQ@mail.gmail.com","threadId":"28000","inReplyTo":"1312780242-91659-1-git-send-email-davidbarr@google.com","subject":"Re: [PATCH v2] am: ignore leading whitespace before patch","fromName":"David Barr","fromEmail":"davidbarr@google.com","sentAt":"2011-08-08T05:31:03Z","receivedAt":"2011-08-08T05:31:03Z","isPatch":true,"sender":{"key":"davidbarr@google.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":"*facepalm*\n\nThis test already passes:\n> +       git am <patch1-ws.eml >output.out 2>&1 &&\n\nAlternatively, the following was failing:\n> +       git am patch1-ws.eml >output.out 2>&1 &&\n\nNote that the email file is passed as an argument rather than a redirect.\n--\nDavid Barr\n"}]}