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