Skip to content

Commit 5b5d4d9

Browse files
dschoJunio C Hamano
authored andcommitted
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>
1 parent 8e1618f commit 5b5d4d9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ all:
5555
#
5656
# Define NO_ICONV if your libc does not properly support iconv.
5757
#
58+
# Define NO_ACCURATE_DIFF if your diff program at least sometimes misses
59+
# a missing newline at the end of the file.
60+
#
5861
# Define COLLISION_CHECK below if you believe that SHA1's
5962
# 1461501637330902918203684832716283019655932542976 hashes do not give you
6063
# sufficient guarantee that no collisions between objects will ever happen.
@@ -403,6 +406,9 @@ else
403406
endif
404407
endif
405408
endif
409+
ifdef NO_ACCURATE_DIFF
410+
ALL_CFLAGS += -DNO_ACCURATE_DIFF
411+
endif
406412

407413
ALL_CFLAGS += -DSHA1_HEADER=$(call shellquote,$(SHA1_HEADER)) $(COMPAT_CFLAGS)
408414
LIB_OBJS += $(COMPAT_OBJS)

apply.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,14 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
11421142
size -= len;
11431143
}
11441144

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+
11451153
offset = find_offset(buf, desc->size, old, oldsize, frag->newpos);
11461154
if (offset >= 0) {
11471155
int diff = newsize - oldsize;

0 commit comments

Comments
 (0)