Skip to content

Commit

Permalink
Optionally support old diffs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Feb 18, 2006
1 parent 8e1618f commit 5b5d4d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5b5d4d9

Please sign in to comment.