[PATCH] Fix "apply --reverse" with regard to whitespace

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Daniel Barkalow <barkalow@...>
Cc: <git@...>, <gitster@...>
Date: Saturday, July 7, 2007 - 1:50 pm

"git apply" used to take check the whitespace in the wrong
direction.

Noticed by Daniel Barkalow.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	On Fri, 6 Jul 2007, Daniel Barkalow wrote:

	> If you apply in reverse a patch which adds junk (e.g., terminal
	> whitespace), it complains about the junk you're adding, even 
	> though (since it's in reverse) you're actually removing that 
	> junk.

	This fixes it.

 builtin-apply.c          |    6 +++++-
 t/t4116-apply-reverse.sh |    6 ++++++
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index c6f736c..0a0b4a9 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1003,12 +1003,16 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
 			trailing++;
 			break;
 		case '-':
+			if (apply_in_reverse &&
+					new_whitespace != nowarn_whitespace)
+				check_whitespace(line, len);
 			deleted++;
 			oldlines--;
 			trailing = 0;
 			break;
 		case '+':
-			if (new_whitespace != nowarn_whitespace)
+			if (!apply_in_reverse &&
+					new_whitespace != nowarn_whitespace)
 				check_whitespace(line, len);
 			added++;
 			newlines--;
diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh
index a7f5905..9ae2b3a 100755
--- a/t/t4116-apply-reverse.sh
+++ b/t/t4116-apply-reverse.sh
@@ -82,4 +82,10 @@ test_expect_success 'apply in reverse without postimage' '
 	)
 '
 
+test_expect_success 'reversing a whitespace introduction' '
+	sed "s/a/a /" < file1 > file1.new &&
+	mv file1.new file1 &&
+	git diff | git apply --reverse --whitespace=error
+'
+
 test_done
-- 
1.5.3.rc0.2712.g125b7f

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Minor bug in git-apply's patch-cleaning, Daniel Barkalow, (Fri Jul 6, 10:21 pm)
[PATCH] Fix "apply --reverse" with regard to whitespace, Johannes Schindelin, (Sat Jul 7, 1:50 pm)
Re: [PATCH] Fix "apply --reverse" with regard to whitespace, Johannes Schindelin, (Sun Jul 8, 8:47 am)