git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-am: ignore leading whitespace before patch
@ 2011-08-02 22:20 David Barr
  2011-08-03 12:28 ` Tay Ray Chuan
  2011-08-08  5:10 ` David Barr
  0 siblings, 2 replies; 10+ messages in thread
From: David Barr @ 2011-08-02 22:20 UTC (permalink / raw)
  To: Git Mailing List; +Cc: David Barr

Some web-based email clients prepend whitespace to raw message
transcripts to workaround content-sniffing in some browsers.
Adjust the patch format detection logic to ignore leading
whitespace.

Signed-off-by: David Barr <davidbarr@google.com>
---
 git-am.sh |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 463c741..19b2f0f 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -199,7 +199,11 @@ check_patch_format () {
 	# otherwise, check the first few lines of the first patch to try
 	# to detect its format
 	{
-		read l1
+		# Start from first line containing non-whitespace
+		until [ -n "$l1" ]
+		do
+			read l1
+		done
 		read l2
 		read l3
 		case "$l1" in
-- 
1.7.6

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] git-am: ignore leading whitespace before patch
  2011-08-02 22:20 [PATCH] git-am: ignore leading whitespace before patch David Barr
@ 2011-08-03 12:28 ` Tay Ray Chuan
  2011-08-03 13:21   ` Sverre Rabbelier
  2011-08-06  1:56   ` David Barr
  2011-08-08  5:10 ` David Barr
  1 sibling, 2 replies; 10+ messages in thread
From: Tay Ray Chuan @ 2011-08-03 12:28 UTC (permalink / raw)
  To: David Barr; +Cc: Git Mailing List

On Wed, Aug 3, 2011 at 6:20 AM, David Barr <davidbarr@google.com> wrote:
> Some web-based email clients prepend whitespace to raw message
> transcripts to workaround content-sniffing in some browsers.
> Adjust the patch format detection logic to ignore leading
> whitespace.
>
> Signed-off-by: David Barr <davidbarr@google.com>

Finally, patches from GMail that play nice with git-am!

  Acked-by: Tay Ray Chuan <rctay89@gmail.com>

-- 
Cheers,
Ray Chuan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] git-am: ignore leading whitespace before patch
  2011-08-03 12:28 ` Tay Ray Chuan
@ 2011-08-03 13:21   ` Sverre Rabbelier
  2011-08-03 13:31     ` Tay Ray Chuan
  2011-08-06  1:56   ` David Barr
  1 sibling, 1 reply; 10+ messages in thread
From: Sverre Rabbelier @ 2011-08-03 13:21 UTC (permalink / raw)
  To: David Barr, Tay Ray Chuan; +Cc: Git Mailing List

Heya,

On Wed, Aug 3, 2011 at 14:28, Tay Ray Chuan <rctay89@gmail.com> wrote:
> On Wed, Aug 3, 2011 at 6:20 AM, David Barr <davidbarr@google.com> wrote:
>> Some web-based email clients prepend whitespace to raw message
>> transcripts to workaround content-sniffing in some browsers.
>> Adjust the patch format detection logic to ignore leading
>> whitespace.
>>
>> Signed-off-by: David Barr <davidbarr@google.com>
>
> Finally, patches from GMail that play nice with git-am!

So how do you get the patches out of gmail? Do you just copy/paste the
output of the "Show original" page?

-- 
Cheers,

Sverre Rabbelier

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] git-am: ignore leading whitespace before patch
  2011-08-03 13:21   ` Sverre Rabbelier
@ 2011-08-03 13:31     ` Tay Ray Chuan
  2011-08-03 13:33       ` Sverre Rabbelier
  0 siblings, 1 reply; 10+ messages in thread
From: Tay Ray Chuan @ 2011-08-03 13:31 UTC (permalink / raw)
  To: Sverre Rabbelier; +Cc: David Barr, Git Mailing List

On Wed, Aug 3, 2011 at 9:21 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
> So how do you get the patches out of gmail? Do you just copy/paste the
> output of the "Show original" page?

I Ctrl-S from the "Show original" page. Using Chrome, that yields a
mail.txt file.

Without this patch, I used to manually remove the first line (all
empty whitespace).

-- 
Cheers,
Ray Chuan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] git-am: ignore leading whitespace before patch
  2011-08-03 13:31     ` Tay Ray Chuan
@ 2011-08-03 13:33       ` Sverre Rabbelier
  0 siblings, 0 replies; 10+ messages in thread
From: Sverre Rabbelier @ 2011-08-03 13:33 UTC (permalink / raw)
  To: Tay Ray Chuan; +Cc: David Barr, Git Mailing List

Heya,

On Wed, Aug 3, 2011 at 15:31, Tay Ray Chuan <rctay89@gmail.com> wrote:
> On Wed, Aug 3, 2011 at 9:21 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
>> So how do you get the patches out of gmail? Do you just copy/paste the
>> output of the "Show original" page?
>
> I Ctrl-S from the "Show original" page. Using Chrome, that yields a
> mail.txt file.

Ah, clever hack! Nice :)

-- 
Cheers,

Sverre Rabbelier

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] git-am: ignore leading whitespace before patch
  2011-08-03 12:28 ` Tay Ray Chuan
  2011-08-03 13:21   ` Sverre Rabbelier
@ 2011-08-06  1:56   ` David Barr
  2011-08-06  5:00     ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: David Barr @ 2011-08-06  1:56 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Git Mailing List, Tay Ray Chuan, Sverre Rabbelier

Hi Jonathan,

> On Wed, Aug 3, 2011 at 6:20 AM, David Barr <davidbarr@google.com> wrote:
>> Some web-based email clients prepend whitespace to raw message
>> transcripts to workaround content-sniffing in some browsers.
>> Adjust the patch format detection logic to ignore leading
>> whitespace.
>>
>> Signed-off-by: David Barr <davidbarr@google.com>

>> diff --git a/git-am.sh b/git-am.sh
>> index 463c741..19b2f0f 100755
>> --- a/git-am.sh
>> +++ b/git-am.sh
>> @@ -199,7 +199,11 @@ check_patch_format () {
>>        # otherwise, check the first few lines of the first patch to try
>>        # to detect its format
>>        {
>> -               read l1
>> +               # Start from first line containing non-whitespace
>> +               until [ -n "$l1" ]
>> +               do
>> +                       read l1
>> +               done
>>                read l2
>>                read l3
>>                case "$l1" in

On Wed, Aug 3, 2011 at 10:28 PM, Tay Ray Chuan <rctay89@gmail.com> wrote:
> Finally, patches from GMail that play nice with git-am!
>
>  Acked-by: Tay Ray Chuan <rctay89@gmail.com>

Do you see any subtle issues in this tiny patch?
I failed to include a test, I'll add at least one to the next version.
I did check that it doesn't break any of the existing git-am tests.

--
David Barr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] git-am: ignore leading whitespace before patch
  2011-08-06  1:56   ` David Barr
@ 2011-08-06  5:00     ` Junio C Hamano
  2011-08-08  2:49       ` [PATCH v2] am: " Jonathan Nieder
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2011-08-06  5:00 UTC (permalink / raw)
  To: David Barr
  Cc: Jonathan Nieder, Git Mailing List, Tay Ray Chuan,
	Sverre Rabbelier

David Barr <davidbarr@google.com> writes:

> Hi Jonathan,
> ...
>>> diff --git a/git-am.sh b/git-am.sh
>>> index 463c741..19b2f0f 100755
>>> --- a/git-am.sh
>>> +++ b/git-am.sh
>>> @@ -199,7 +199,11 @@ check_patch_format () {
>>>        # otherwise, check the first few lines of the first patch to try
>>>        # to detect its format
>>>        {
>>> -               read l1
>>> +               # Start from first line containing non-whitespace
>>> +               until [ -n "$l1" ]
>>> +               do
>>> +                       read l1
>>> +               done
> ...
> Do you see any subtle issues in this tiny patch?
> I failed to include a test, I'll add at least one to the next version.
> I did check that it doesn't break any of the existing git-am tests.

It no longer checks "the first few lines" but can read a lot more, so the
comment that precedes this block is now invalid.

Also we are rather old fashioned and we never say "until [ ... ]" anywhere
in our shell scripts.

	$ git grep -e until -- '*.sh'

Personally to me this is a borderline "Meh", in the sense that I wouldn't
bother to waste too much effort rejecting it, as I do not see downsides
other than these minor points.

Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2] am: ignore leading whitespace before patch
  2011-08-06  5:00     ` Junio C Hamano
@ 2011-08-08  2:49       ` Jonathan Nieder
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Nieder @ 2011-08-08  2:49 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: David Barr, Git Mailing List, Tay Ray Chuan, Sverre Rabbelier,
	Giuseppe Bilotta, Simon Sasburg

From: David Barr <davidbarr@google.com>

Some web-based email clients prepend whitespace to raw message
transcripts to workaround content-sniffing in some browsers.  Adjust
the patch format detection logic to ignore leading whitespace.

So now you can apply patches from GMail with "git am" in three steps:

 1. choose "show original"
 2. tell the browser to "save as" (for example by pressing Ctrl+S)
 3. run "git am" on the saved file

This fixes a regression introduced by v1.6.4-rc0~15^2~2 (git-am
foreign patch support: autodetect some patch formats, 2009-05-27).
GMail support was first introduced to "git am" by v1.5.4-rc0~274^2
(Make mailsplit and mailinfo strip whitespace from the start of the
input, 2007-11-01).

Signed-off-by: David Barr <davidbarr@google.com>
Acked-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Junio C Hamano wrote:

> It no longer checks "the first few lines" but can read a lot more, so the
> comment that precedes this block is now invalid.
>
> Also we are rather old fashioned and we never say "until [ ... ]" anywhere
> in our shell scripts.

Good ideas, thanks.  While at it, let's initialize l1 to protect
against any stray value it might have inherited from the environment.

Looking forward to the promised test, :)
Jonathan

 git-am.sh |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 463c741d..c8422dbe 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -196,10 +196,15 @@ check_patch_format () {
 		return 0
 	fi
 
-	# otherwise, check the first few lines of the first patch to try
-	# to detect its format
+	# otherwise, check the first few non-blank lines of the first
+	# patch to try to detect its format
 	{
-		read l1
+		# Start from first line containing non-whitespace
+		l1=
+		while test -z "$l1"
+		do
+			read l1
+		done
 		read l2
 		read l3
 		case "$l1" in
-- 
1.7.6

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* RE: [PATCH v2] am: ignore leading whitespace before patch
  2011-08-02 22:20 [PATCH] git-am: ignore leading whitespace before patch David Barr
  2011-08-03 12:28 ` Tay Ray Chuan
@ 2011-08-08  5:10 ` David Barr
  2011-08-08  5:31   ` David Barr
  1 sibling, 1 reply; 10+ messages in thread
From: David Barr @ 2011-08-08  5:10 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: David Barr, Jonathan Nieder, Git Mailing List, Tay Ray Chuan,
	Sverre Rabbelier, Giuseppe Bilotta, Simon Sasburg

Add a test for GMail-style padded email files.

Signed-off-by: David Barr <davidbarr@google.com>
---
 t/t4150-am.sh |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 151404e..40a5a3e 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -167,6 +167,17 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
 	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
 '
 
+test_expect_success 'am applies patch e-mail with preceding whitespace' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout first &&
+	printf "%256s\\n" "" >patch1-ws.eml &&
+	cat patch1.eml >>patch1-ws.eml &&
+	git am <patch1-ws.eml >output.out 2>&1 &&
+	! test -d .git/rebase-apply &&
+	git diff --exit-code second
+'
+
 test_expect_success 'setup: new author and committer' '
 	GIT_AUTHOR_NAME="Another Thor" &&
 	GIT_AUTHOR_EMAIL="a.thor@example.com" &&
-- 
1.7.6

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] am: ignore leading whitespace before patch
  2011-08-08  5:10 ` David Barr
@ 2011-08-08  5:31   ` David Barr
  0 siblings, 0 replies; 10+ messages in thread
From: David Barr @ 2011-08-08  5:31 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: David Barr, Jonathan Nieder, Git Mailing List, Tay Ray Chuan,
	Sverre Rabbelier, Giuseppe Bilotta, Simon Sasburg

*facepalm*

This test already passes:
> +       git am <patch1-ws.eml >output.out 2>&1 &&

Alternatively, the following was failing:
> +       git am patch1-ws.eml >output.out 2>&1 &&

Note that the email file is passed as an argument rather than a redirect.
--
David Barr

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-08-08  5:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-02 22:20 [PATCH] git-am: ignore leading whitespace before patch David Barr
2011-08-03 12:28 ` Tay Ray Chuan
2011-08-03 13:21   ` Sverre Rabbelier
2011-08-03 13:31     ` Tay Ray Chuan
2011-08-03 13:33       ` Sverre Rabbelier
2011-08-06  1:56   ` David Barr
2011-08-06  5:00     ` Junio C Hamano
2011-08-08  2:49       ` [PATCH v2] am: " Jonathan Nieder
2011-08-08  5:10 ` David Barr
2011-08-08  5:31   ` David Barr

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).