Merge branch 'dk/blame-el' into pu
[git] / t / t6017-rev-cache-list.sh
1 #!/bin/sh
2
3 test_description='git rev-cache tests'
4 . ./test-lib.sh
5
6 test_cmp_sorted() {
7 # note that we're tip-toeing around the corner case of two objects/names
8 # for the same SHA-1 => discrepencies between cached and non-cached walks
9         sort $1 >.tmpfile1 &&
10         sort $2 >.tmpfile2 &&
11         test_cmp .tmpfile1 .tmpfile2
12 }
13
14 # we want a totally wacked out branch structure...
15 # we need branching and merging of sizes up through 3, tree
16 # addition/deletion, and enough branching to exercise path
17 # reuse
18 test_expect_success 'init repo' '
19         echo bla >file &&
20         mkdir amaindir &&
21         echo watskeburt >amaindir/file &&
22         git add . &&
23         git commit -m "bla" &&
24
25         git branch b1 &&
26         git checkout b1 &&
27         echo blu >file2 &&
28         mkdir d1 &&
29         echo bang >d1/filed1 &&
30         git add . &&
31         git commit -m "blu" &&
32
33         git checkout master &&
34         git branch b2 &&
35         git checkout b2 &&
36         echo kaplaa >>file &&
37         git commit -a -m "kaplaa" &&
38
39         git checkout master &&
40         mkdir smoke &&
41         echo omg >smoke/bong &&
42         git add . &&
43         git commit -m "omg" &&
44
45         sleep 2 &&
46         git branch b4 &&
47         git checkout b4 &&
48         echo shazam >file8 &&
49         git add . &&
50         git commit -m "shazam" &&
51         git merge -m "merge b2" b2 &&
52
53         echo bam >smoke/pipe &&
54         git add . &&
55         git commit -m "bam" &&
56
57         git checkout master &&
58         echo pow >file7 &&
59         git add . &&
60         git commit -m "pow" &&
61         git merge -m "merge b4" b4 &&
62
63         git checkout b1 &&
64         echo stuff >d1/filed1 &&
65         git commit -a -m "stuff" &&
66
67         git branch b11 &&
68         git checkout b11 &&
69         echo wazzup >file3 &&
70         git add file3 &&
71         git commit -m "wazzup" &&
72
73         git checkout b1 &&
74         mkdir d1/d2 &&
75         echo lol >d1/d2/filed2 &&
76         git add . &&
77         git commit -m "lol" &&
78
79         sleep 2 &&
80         git checkout master &&
81         git merge -m "triple merge" b1 b11 &&
82         git rm -r d1 &&
83         sleep 2 &&
84         git commit -a -m "oh noes"
85 '
86
87 max_date=`git-rev-list --timestamp HEAD~1 --max-count=1 | grep -e "^[0-9]*" -o`
88 min_date=`git-rev-list --timestamp b4 --max-count=1 | grep -e "^[0-9]*" -o`
89
90 git-rev-list --topo-order HEAD --not HEAD~3 >proper_commit_list_limited
91 git-rev-list --topo-order HEAD --not HEAD~2 >proper_commit_list_limited2
92 git-rev-list --topo-order HEAD >proper_commit_list
93 git-rev-list --objects HEAD >proper_object_list
94 git-rev-list HEAD --max-age=$min_date --min-age=$max_date >proper_list_date_limited
95
96 cache_sha1=`git-rev-cache add HEAD 2>output.err`
97
98 test_expect_success 'make cache slice' '
99         grep "final return value: 0" output.err
100 '
101
102 test_expect_success 'remake cache slice' '
103         git-rev-cache add HEAD 2>output.err &&
104         grep "final return value: 0" output.err
105 '
106
107 #check core mechanics and rev-list hook for commits
108 test_expect_success 'test rev-caches walker directly (limited)' '
109         git-rev-cache walk HEAD --not HEAD~3 >list &&
110         test_cmp_sorted list proper_commit_list_limited
111 '
112
113 test_expect_success 'test rev-caches walker directly (unlimited)' '
114         git-rev-cache walk HEAD >list &&
115         test_cmp_sorted list proper_commit_list
116 '
117
118 test_expect_success 'test rev-list traversal (limited)' '
119         git-rev-list HEAD --not HEAD~3 >list &&
120         test_cmp list proper_commit_list_limited
121 '
122
123 test_expect_success 'test rev-list traversal (unlimited)' '
124         git-rev-list HEAD >list &&
125         test_cmp list proper_commit_list
126 '
127
128 #do the same for objects
129 test_expect_success 'test rev-caches walker with objects' '
130         git-rev-cache walk --objects HEAD >list &&
131         test_cmp_sorted list proper_object_list
132 '
133
134 test_expect_success 'test rev-list with objects (topo order)' '
135         git-rev-list --topo-order --objects HEAD >list &&
136         test_cmp_sorted list proper_object_list
137 '
138
139 test_expect_success 'test rev-list with objects (no order)' '
140         git-rev-list --objects HEAD >list &&
141         test_cmp_sorted list proper_object_list
142 '
143
144 #verify age limiting
145 test_expect_success 'test rev-list date limiting (topo order)' '
146         git-rev-list --topo-order --max-age=$min_date --min-age=$max_date HEAD >list &&
147         test_cmp_sorted list proper_list_date_limited
148 '
149
150 test_expect_success 'test rev-list date limiting (no order)' '
151         git-rev-list --max-age=$min_date --min-age=$max_date HEAD >list &&
152         test_cmp_sorted list proper_list_date_limited
153 '
154
155 #check partial cache slice
156 test_expect_success 'saving old cache and generating partial slice' '
157         cp ".git/rev-cache/$cache_sha1" .git/rev-cache/.old &&
158         rm ".git/rev-cache/$cache_sha1" .git/rev-cache/index &&
159
160         git-rev-cache add HEAD~2 2>output.err &&
161         grep "final return value: 0" output.err
162 '
163
164 test_expect_success 'rev-list with wholly interesting partial slice' '
165         git-rev-list --topo-order HEAD >list &&
166         test_cmp list proper_commit_list
167 '
168
169 test_expect_success 'rev-list with partly uninteresting partial slice' '
170         git-rev-list --topo-order HEAD --not HEAD~3 >list &&
171         test_cmp list proper_commit_list_limited
172 '
173
174 test_expect_success 'rev-list with wholly uninteresting partial slice' '
175         git-rev-list --topo-order HEAD --not HEAD~2 >list &&
176         test_cmp list proper_commit_list_limited2
177 '
178
179 #try out index generation and fuse (note that --all == HEAD in this case)
180 #probably should make a test for that too...
181 test_expect_success 'test (non-)fusion of one slice' '
182         git-rev-cache fuse >output.err &&
183         grep "nothing to fuse" output.err
184 '
185
186 test_expect_success 'make fresh slice' '
187         git-rev-cache add --all --fresh 2>output.err &&
188         grep "final return value: 0" output.err
189 '
190
191 test_expect_success 'check dual slices' '
192         git-rev-list --topo-order HEAD~2 HEAD >list &&
193         test_cmp list proper_commit_list
194 '
195
196 test_expect_success 'regenerate index' '
197         rm .git/rev-cache/index &&
198         git-rev-cache index 2>output.err &&
199         grep "final return value: 0" output.err
200 '
201
202 test_expect_success 'fuse slices' '
203         test -e .git/rev-cache/.old &&
204         git-rev-cache fuse 2>output.err &&
205         grep "final return value: 0" output.err &&
206         test_cmp .git/rev-cache/$cache_sha1 .git/rev-cache/.old
207 '
208
209 #make sure we can smoothly handle corrupted caches
210 test_expect_success 'corrupt slice' '
211         echo bla >.git/rev-cache/$cache_sha1
212 '
213
214 test_expect_success 'test rev-list traversal (limited) (corrupt slice)' '
215         git-rev-list --topo-order HEAD --not HEAD~3 >list &&
216         test_cmp list proper_commit_list_limited
217 '
218
219 test_expect_success 'test rev-list traversal (unlimited) (corrupt slice)' '
220         git-rev-list HEAD >list &&
221         test_cmp_sorted list proper_commit_list
222 '
223
224 test_expect_success 'corrupt index' '
225         echo blu >.git/rev-cache/index
226 '
227
228 test_expect_success 'test rev-list traversal (limited) (corrupt index)' '
229         git-rev-list --topo-order HEAD --not HEAD~3 >list &&
230         test_cmp list proper_commit_list_limited
231 '
232
233 test_expect_success 'test rev-list traversal (unlimited) (corrupt index)' '
234         git-rev-list HEAD >list &&
235         test_cmp_sorted list proper_commit_list
236 '
237
238 #test --ignore-size in fuse
239 rm .git/rev-cache/*
240 cache_sha1=`git-rev-cache add HEAD~2 2>output.err`
241
242 test_expect_success 'make fragmented slices' '
243         git-rev-cache add HEAD~1 --not HEAD~2 2>>output.err &&
244         git-rev-cache add HEAD --fresh 2>>output.err &&
245         test `grep "final return value: 0" output.err | wc -l` -eq 3
246 '
247
248 cache_size=`wc -c .git/rev-cache/$cache_sha1 | grep -o "[0-9]*"`
249 test_expect_success 'test --ignore-size function in fuse' '
250         git-rev-cache fuse --ignore-size=$cache_size 2>output.err &&
251         grep "final return value: 0" output.err &&
252         test -e .git/rev-cache/$cache_sha1
253 '
254
255 test_done