git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/9] apply --whitespace=fix: detect new blank lines at eof   correctly
Date: Fri, 04 Sep 2009 14:02:03 +0200	[thread overview]
Message-ID: <4AA101BB.7010206@viscovery.net> (raw)
In-Reply-To: <1252061718-11579-3-git-send-email-gitster@pobox.com>

Junio C Hamano schrieb:
> The command tries to strip blank lines at the end of the file added by a
> patch.  However, if the original ends with blank lines, often the patch
> hunk ends like this:
> 
>     @@ -l,5 +m,7 @@$
>     _context$
>     _context$
>     -deleted$
>     +$
>     +$
>     +$
>     _$
>     _$
> 
> where _ stands for SP and $ shows a end-of-line.  This example patch adds
> three trailing blank lines, but the code fails to notice it, because it
> only pays attention to added blank lines at the very end of the hunk.  In
> this example, the three added blank lines do not appear textually at the
> end in the patch, even though you can see that they are indeed added at
> the end, if you rearrange the diff like this:
> 
>     @@ -l,5 +m,7 @@$
>     _context$
>     _context$
>     -deleted$
>     _$
>     _$
>     +$
>     +$
>     +$
> 
> Fix this by not resetting the number of (candidate) added blank lines at
> the end when the loop sees a context line that is empty.

After reading this explanation, I was worried that added blank lines that
are at the end of a patch but apply in the middle of a file would be
mis-attributed as blank lines at EOF. But appearently, they are not, i.e.
such added blank lines are not removed. Could you squash in this test case
that checks for this condition.

-- Hannes

diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
index ba2b7f9..fedc8b9 100755
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
@@ -189,4 +189,16 @@ test_expect_success 'blank at EOF with --whitespace=fix (3)' '
 	test_cmp expect one
 '

+test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' '
+	{ echo a; echo b; echo; echo; echo; echo; echo; echo d; } >one &&
+	git add one &&
+	{ echo a; echo c; echo; echo; echo; echo; echo; echo; echo d; } >expect &&
+	cp expect one &&
+	git diff -- one >patch &&
+
+	git checkout one &&
+	git apply --whitespace=fix patch &&
+	test_cmp expect one
+'
+
 test_done

  reply	other threads:[~2009-09-04 12:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-04 10:55 [PATCH 0/9] War on blank-at-eof Junio C Hamano
2009-09-04 10:55 ` [PATCH 1/9] apply --whitespace=fix: fix handling of blank lines at the eof Junio C Hamano
2009-09-04 10:55 ` [PATCH 2/9] apply --whitespace=fix: detect new blank lines at eof correctly Junio C Hamano
2009-09-04 12:02   ` Johannes Sixt [this message]
2009-09-04 16:26     ` Junio C Hamano
2009-09-04 10:55 ` [PATCH 3/9] apply.c: split check_whitespace() into two Junio C Hamano
2009-09-04 10:55 ` [PATCH 4/9] apply --whitespace=warn/error: diagnose blank at EOF Junio C Hamano
2009-09-04 10:55 ` [PATCH 5/9] apply --whitespace: warn blank but not necessarily empty lines " Junio C Hamano
2009-09-04 10:55 ` [PATCH 6/9] diff.c: the builtin_diff() deals with only two-file comparison Junio C Hamano
2009-09-04 10:55 ` [PATCH 7/9] diff --whitespace=warn/error: obey blank-at-eof Junio C Hamano
2009-09-04 10:55 ` [PATCH 8/9] diff --whitespace=warn/error: fix blank-at-eof check Junio C Hamano
2009-09-04 10:55 ` [PATCH 9/9] diff --color: color blank-at-eof Junio C Hamano
2009-09-05 21:28 ` [PATCH 0/9] War on blank-at-eof Thell Fowler
2009-09-06  6:13   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AA101BB.7010206@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).