Re-re-re-fix common tail optimization
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>
Junio C Hamano committed
Dec 16, 2007 at 13:49 UTC
079fe1dae8504c988c50ce41eba78743d3f588e0
2 files changed
+70
-1
t/t4024-diff-optimize-common.sh
new
+69
@@ -0,0 +1,69 @@
1
+#!/bin/sh
2
+
3
+test_description='common tail optimization'
4
+
5
+. ./test-lib.sh
6
+
7
+z=zzzzzzzz ;# 8
8
+z="$z$z$z$z$z$z$z$z" ;# 64
9
+z="$z$z$z$z$z$z$z$z" ;# 512
10
+z="$z$z$z$z" ;# 2048
11
+z2047=$(expr "$z" : '.\(.*\)') ; #2047
12
+
13
+test_expect_success setup '
14
+
15
+ echo "a$z2047" >file-a &&
16
+ echo "b" >file-b &&
17
+ echo "$z2047" >>file-b &&
18
+ echo "c$z2047" | tr -d "\012" >file-c &&
19
+ echo "d" >file-d &&
20
+ echo "$z2047" | tr -d "\012" >>file-d &&
21
+
22
+ git add file-a file-b file-c file-d &&
23
+
24
+ echo "A$z2047" >file-a &&
25
+ echo "B" >file-b &&
26
+ echo "$z2047" >>file-b &&
27
+ echo "C$z2047" | tr -d "\012" >file-c &&
28
+ echo "D" >file-d &&
29
+ echo "$z2047" | tr -d "\012" >>file-d
30
+
31
+'
32
+
33
+cat >expect <<\EOF
34
+diff --git a/file-a b/file-a
35
+--- a/file-a
36
++++ b/file-a
37
+@@ -1 +1 @@
38
+-aZ
39
++AZ
40
+diff --git a/file-b b/file-b
41
+--- a/file-b
42
++++ b/file-b
43
+@@ -1 +1 @@
44
+-b
45
++B
46
+diff --git a/file-c b/file-c
47
+--- a/file-c
48
++++ b/file-c
49
+@@ -1 +1 @@
50
+-cZ
51
+\ No newline at end of file
52
++CZ
53
+\ No newline at end of file
54
+diff --git a/file-d b/file-d
55
+--- a/file-d
56
++++ b/file-d
57
+@@ -1 +1 @@
58
+-d
59
++D
60
+EOF
61
+
62
+test_expect_success 'diff -U0' '
63
+
64
+ git diff -U0 | sed -e "/^index/d" -e "s/$z2047/Z/g" >actual &&
65
+ diff -u expect actual
66
+
67
+'
68
+
69
+test_done
xdiff-interface.c
+1
-1
@@ -121,7 +121,7 @@ static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx)
121
bp -= blk;
122
}
123
124
- while (recovered < trimmed && ctx)
124
+ while (recovered < trimmed && 0 <= ctx)
125
if (ap[recovered++] == '\n')
126
ctx--;
127
a->size -= (trimmed - recovered);