Optionally support old diffs
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>
Fri, 17 Feb 2006 14:23:16 +0000 (15:23 +0100)
committerJunio C Hamano <junkio@cox.net>
Sat, 18 Feb 2006 00:32:41 +0000 (16:32 -0800)
Some versions of diff do not correctly detect a missing new-line at the end
of the file under certain circumstances.

When defining NO_ACCURATE_DIFF, work around this bug.

Signed-off-by: Johannes E. Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile
apply.c

index 317be3c373dcfc351ba1f4b0232eb80d88267cfb..697a6ddf6015ef935ec138edb35d728b80581f36 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -55,6 +55,9 @@ all:
 #
 # Define NO_ICONV if your libc does not properly support iconv.
 #
+# Define NO_ACCURATE_DIFF if your diff program at least sometimes misses
+# a missing newline at the end of the file.
+#
 # Define COLLISION_CHECK below if you believe that SHA1's
 # 1461501637330902918203684832716283019655932542976 hashes do not give you
 # sufficient guarantee that no collisions between objects will ever happen.
@@ -403,6 +406,9 @@ else
 endif
 endif
 endif
+ifdef NO_ACCURATE_DIFF
+       ALL_CFLAGS += -DNO_ACCURATE_DIFF
+endif
 
 ALL_CFLAGS += -DSHA1_HEADER=$(call shellquote,$(SHA1_HEADER)) $(COMPAT_CFLAGS)
 LIB_OBJS += $(COMPAT_OBJS)
diff --git a/apply.c b/apply.c
index 2ad47fbbb37b245a78abd8e8255d39b39a52f9a9..1083d4f31677357fe86c5ab85960df44a28ce721 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -1142,6 +1142,14 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
                size -= len;
        }
 
+#ifdef NO_ACCURATE_DIFF
+       if (oldsize > 0 && old[oldsize - 1] == '\n' &&
+                       newsize > 0 && new[newsize - 1] == '\n') {
+               oldsize--;
+               newsize--;
+       }
+#endif
+                       
        offset = find_offset(buf, desc->size, old, oldsize, frag->newpos);
        if (offset >= 0) {
                int diff = newsize - oldsize;