Optionally support old diffs
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>
Johannes Schindelin committed
Feb 17, 2006 at 15:23 UTC
5b5d4d9e1b31997b3179e6a253d47b7eea03d0fa
2 files changed
+14
Makefile
+6
@@ -55,6 +55,9 @@ all:
55
#
56
# Define NO_ICONV if your libc does not properly support iconv.
57
#
58
+# Define NO_ACCURATE_DIFF if your diff program at least sometimes misses
59
+# a missing newline at the end of the file.
60
+#
61
# Define COLLISION_CHECK below if you believe that SHA1's
62
# 1461501637330902918203684832716283019655932542976 hashes do not give you
63
# sufficient guarantee that no collisions between objects will ever happen.
@@ -403,6 +406,9 @@ else
406
endif
407
endif
408
endif
409
+ifdef NO_ACCURATE_DIFF
410
+ ALL_CFLAGS += -DNO_ACCURATE_DIFF
411
+endif
412
413
ALL_CFLAGS += -DSHA1_HEADER=$(call shellquote,$(SHA1_HEADER)) $(COMPAT_CFLAGS)
414
LIB_OBJS += $(COMPAT_OBJS)
apply.c
+8
@@ -1142,6 +1142,14 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
1142
size -= len;
1143
}
1144
1145
+#ifdef NO_ACCURATE_DIFF
1146
+ if (oldsize > 0 && old[oldsize - 1] == '\n' &&
1147
+ newsize > 0 && new[newsize - 1] == '\n') {
1148
+ oldsize--;
1149
+ newsize--;
1150
+ }
1151
+#endif
1152
+
1153
offset = find_offset(buf, desc->size, old, oldsize, frag->newpos);
1154
if (offset >= 0) {
1155
int diff = newsize - oldsize;