git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] Optionally support old diffs

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 17, 2006, 14:23 UTC
Message-ID
<Pine.LNX.4.63.0602171522560.24274@wbgn013.biozentrum.uni-wuerzburg.de>

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>
---
 Makefile |    6 ++++++
 apply.c  |    8 ++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
46183bd251ffe3fc3cbbf4d94467627f922d6d43
diff --git a/Makefile b/Makefile
index b3401ac..6e00737 100644
--- 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.
@@ -405,6 +408,9 @@ else
 	LIBS += $(LIB_4_CRYPTO)
 endif
 endif
+endif
+ifdef NO_ACCURATE_DIFF
+	ALL_CFLAGS += -DNO_ACCURATE_DIFF
 endif
 
 # Shell quote (do not use $(call) to accomodate ancient setups);
diff --git a/apply.c b/apply.c
index 2ad47fb..1083d4f 100644
--- a/apply.c
+++ b/apply.c
@@ -1142,6 +1142,14 @@ static int apply_one_fragment(struct buf
 		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;
-- 
1.2.1.g09fe-dirty
Message 1 of 1 in “Optionally support old diffs”
  1. 3/5 Optionally support old diffsJohannes Schindelin, Feb 17, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.