git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] am: ignore leading whitespace before patch

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 8, 2011, 02:49 UTC
Message-ID
<20110808024904.GF19551@elie.gateway.2wire.net>
In-Reply-To
<7vvcub16e7.fsf@alter.siamese.dyndns.org>
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:
Show 5 quoted lines
> 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
Previous: Junio C HamanoNext: David Barr
Message 8 of 10 in “git-am: ignore leading whitespace before patch”
  1. git-am: ignore leading whitespace before patchDavid Barr, Aug 2, 2011
  2. Tay Ray ChuanAug 3, 2011
  3. Sverre RabbelierAug 3, 2011
  4. Tay Ray ChuanAug 3, 2011
  5. Sverre RabbelierAug 3, 2011
  6. David BarrAug 6, 2011
  7. Junio C HamanoAug 6, 2011
  8. am: ignore leading whitespace before patchJonathan Nieder, Aug 8, 2011
  9. David BarrAug 8, 2011
  10. David BarrAug 8, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.