]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4024-diff-optimize-common.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t4024-diff-optimize-common.sh
CommitLineData
079fe1da
JH
1#!/bin/sh
2
3test_description='common tail optimization'
4
16d4bd4f 5TEST_PASSES_SANITIZE_LEAK=true
079fe1da
JH
6. ./test-lib.sh
7
8z=zzzzzzzz ;# 8
9z="$z$z$z$z$z$z$z$z" ;# 64
10z="$z$z$z$z$z$z$z$z" ;# 512
11z="$z$z$z$z" ;# 2048
12z2047=$(expr "$z" : '.\(.*\)') ; #2047
13
885ed372
JH
14x=zzzzzzzzzz ;# 10
15y="$x$x$x$x$x$x$x$x$x$x" ;# 100
16z="$y$y$y$y$y$y$y$y$y$y" ;# 1000
17z1000=$z
18z100=$y
19z10=$x
079fe1da 20
885ed372
JH
21zs() {
22 count="$1"
23 while test "$count" -ge 1000
24 do
25 count=$(($count - 1000))
26 printf "%s" $z1000
27 done
28 while test "$count" -ge 100
29 do
30 count=$(($count - 100))
31 printf "%s" $z100
32 done
33 while test "$count" -ge 10
34 do
35 count=$(($count - 10))
36 printf "%s" $z10
37 done
38 while test "$count" -ge 1
39 do
40 count=$(($count - 1))
41 printf "z"
42 done
43}
079fe1da 44
885ed372
JH
45zc () {
46 sed -e "/^index/d" \
47 -e "s/$z1000/Q/g" \
48 -e "s/QQQQQQQQQ/Z9000/g" \
49 -e "s/QQQQQQQQ/Z8000/g" \
50 -e "s/QQQQQQQ/Z7000/g" \
51 -e "s/QQQQQQ/Z6000/g" \
52 -e "s/QQQQQ/Z5000/g" \
53 -e "s/QQQQ/Z4000/g" \
54 -e "s/QQQ/Z3000/g" \
55 -e "s/QQ/Z2000/g" \
56 -e "s/Q/Z1000/g" \
57 -e "s/$z100/Q/g" \
58 -e "s/QQQQQQQQQ/Z900/g" \
59 -e "s/QQQQQQQQ/Z800/g" \
60 -e "s/QQQQQQQ/Z700/g" \
61 -e "s/QQQQQQ/Z600/g" \
62 -e "s/QQQQQ/Z500/g" \
63 -e "s/QQQQ/Z400/g" \
64 -e "s/QQQ/Z300/g" \
65 -e "s/QQ/Z200/g" \
66 -e "s/Q/Z100/g" \
67 -e "s/000Z//g" \
68 -e "s/$z10/Q/g" \
69 -e "s/QQQQQQQQQ/Z90/g" \
70 -e "s/QQQQQQQQ/Z80/g" \
71 -e "s/QQQQQQQ/Z70/g" \
72 -e "s/QQQQQQ/Z60/g" \
73 -e "s/QQQQQ/Z50/g" \
74 -e "s/QQQQ/Z40/g" \
75 -e "s/QQQ/Z30/g" \
76 -e "s/QQ/Z20/g" \
77 -e "s/Q/Z10/g" \
78 -e "s/00Z//g" \
79 -e "s/z/Q/g" \
80 -e "s/QQQQQQQQQ/Z9/g" \
81 -e "s/QQQQQQQQ/Z8/g" \
82 -e "s/QQQQQQQ/Z7/g" \
83 -e "s/QQQQQQ/Z6/g" \
84 -e "s/QQQQQ/Z5/g" \
85 -e "s/QQQQ/Z4/g" \
86 -e "s/QQQ/Z3/g" \
87 -e "s/QQ/Z2/g" \
88 -e "s/Q/Z1/g" \
89 -e "s/0Z//g" \
90 ;
91}
079fe1da 92
885ed372
JH
93expect_pattern () {
94 cnt="$1"
95 cat <<EOF
96diff --git a/file-a$cnt b/file-a$cnt
97--- a/file-a$cnt
98+++ b/file-a$cnt
079fe1da 99@@ -1 +1 @@
885ed372
JH
100-Z${cnt}a
101+Z${cnt}A
102diff --git a/file-b$cnt b/file-b$cnt
103--- a/file-b$cnt
104+++ b/file-b$cnt
079fe1da
JH
105@@ -1 +1 @@
106-b
107+B
885ed372
JH
108diff --git a/file-c$cnt b/file-c$cnt
109--- a/file-c$cnt
110+++ b/file-c$cnt
079fe1da 111@@ -1 +1 @@
885ed372 112-cZ$cnt
079fe1da 113\ No newline at end of file
885ed372 114+CZ$cnt
079fe1da 115\ No newline at end of file
885ed372
JH
116diff --git a/file-d$cnt b/file-d$cnt
117--- a/file-d$cnt
118+++ b/file-d$cnt
079fe1da
JH
119@@ -1 +1 @@
120-d
121+D
122EOF
885ed372
JH
123}
124
125sample='1023 1024 1025 2047 4095'
126
127test_expect_success setup '
128
129 for n in $sample
130 do
f957f03b
ES
131 ( zs $n && echo a ) >file-a$n &&
132 ( echo b && zs $n && echo ) >file-b$n &&
133 ( printf c && zs $n ) >file-c$n &&
134 ( echo d && zs $n ) >file-d$n &&
885ed372
JH
135
136 git add file-a$n file-b$n file-c$n file-d$n &&
137
f957f03b
ES
138 ( zs $n && echo A ) >file-a$n &&
139 ( echo B && zs $n && echo ) >file-b$n &&
140 ( printf C && zs $n ) >file-c$n &&
141 ( echo D && zs $n ) >file-d$n &&
885ed372 142
e6821d09 143 expect_pattern $n || return 1
885ed372
JH
144
145 done >expect
146'
079fe1da
JH
147
148test_expect_success 'diff -U0' '
149
885ed372
JH
150 for n in $sample
151 do
cbe1d9d6 152 git diff -U0 file-?$n || return 1
885ed372 153 done | zc >actual &&
82ebb0b6 154 test_cmp expect actual
079fe1da
JH
155
156'
157
158test_done