summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 127f72e)
raw | patch | inline | side by side (parent: 127f72e)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 16 Dec 2007 21:49:17 +0000 (13:49 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 16 Dec 2007 22:00:30 +0000 (14:00 -0800) |
We need to be extra careful recovering the removed common section, so
that we do not break context nor the changed incomplete line (i.e. the
last line that does not end with LF).
Signed-off-by: Junio C Hamano <gitster@pobox.com>
that we do not break context nor the changed incomplete line (i.e. the
last line that does not end with LF).
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4024-diff-optimize-common.sh | [new file with mode: 0755] | patch | blob |
xdiff-interface.c | patch | blob | history |
diff --git a/t/t4024-diff-optimize-common.sh b/t/t4024-diff-optimize-common.sh
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+test_description='common tail optimization'
+
+. ./test-lib.sh
+
+z=zzzzzzzz ;# 8
+z="$z$z$z$z$z$z$z$z" ;# 64
+z="$z$z$z$z$z$z$z$z" ;# 512
+z="$z$z$z$z" ;# 2048
+z2047=$(expr "$z" : '.\(.*\)') ; #2047
+
+test_expect_success setup '
+
+ echo "a$z2047" >file-a &&
+ echo "b" >file-b &&
+ echo "$z2047" >>file-b &&
+ echo "c$z2047" | tr -d "\012" >file-c &&
+ echo "d" >file-d &&
+ echo "$z2047" | tr -d "\012" >>file-d &&
+
+ git add file-a file-b file-c file-d &&
+
+ echo "A$z2047" >file-a &&
+ echo "B" >file-b &&
+ echo "$z2047" >>file-b &&
+ echo "C$z2047" | tr -d "\012" >file-c &&
+ echo "D" >file-d &&
+ echo "$z2047" | tr -d "\012" >>file-d
+
+'
+
+cat >expect <<\EOF
+diff --git a/file-a b/file-a
+--- a/file-a
++++ b/file-a
+@@ -1 +1 @@
+-aZ
++AZ
+diff --git a/file-b b/file-b
+--- a/file-b
++++ b/file-b
+@@ -1 +1 @@
+-b
++B
+diff --git a/file-c b/file-c
+--- a/file-c
++++ b/file-c
+@@ -1 +1 @@
+-cZ
+\ No newline at end of file
++CZ
+\ No newline at end of file
+diff --git a/file-d b/file-d
+--- a/file-d
++++ b/file-d
+@@ -1 +1 @@
+-d
++D
+EOF
+
+test_expect_success 'diff -U0' '
+
+ git diff -U0 | sed -e "/^index/d" -e "s/$z2047/Z/g" >actual &&
+ diff -u expect actual
+
+'
+
+test_done
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 98b02eda3576505e621099c75abdf75f4a403f27..9ee877c6f4d281ad86c8760aa9ee7b4289f647ac 100644 (file)
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
bp -= blk;
}
- while (recovered < trimmed && ctx)
+ while (recovered < trimmed && 0 <= ctx)
if (ap[recovered++] == '\n')
ctx--;
a->size -= (trimmed - recovered);