Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH] Teach 'git-apply --whitespace=strip' to remove empty lines at end of file

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:11
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Marco Costalba [off-list ref] writes:
quoted hunk
Signed-off-by: Marco Costalba <redacted>
---
  builtin-apply.c |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 0399743..f17f838 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1738,6 +1738,10 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag, i
  		newsize--;
  	}

+	if (new_whitespace == strip_whitespace)
+		while (newsize > 1 && !strncmp(new + newsize - 2, "\n\n", 2))
+			newsize--;
+
  	oldlines = old;
  	newlines = new;
  	leading = frag->leading;
I agree to what you are trying to do, but this patch is wrong.
You are stripping trailing newlines that were NOT introduced by
the patch, but happened to be present in the preimage (and in
the context).

Try it on this test vector:

cat >AAA <<\EOF
a
b
c
d


e
f
g
h
i


j
k


EOF
cat >P.diff <<\EOF
diff --git a/AAA b/AAA
index 59f6a9c..ffb28f5 100644
--- a/AAA
+++ b/AAA
@@ -1,4 +1,4 @@
-a
+A
 b
 c
 d
@@ -6,12 +6,11 @@ d
 
 e
 f
+
+
 g
 h
-i
-
 
-j
 k
 
 
EOF
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help