]> Kevux Git Server - rit/blob
4fe57414c1
[rit] /
1 #!/bin/sh
2
3 test_description='exercise basic multi-pack bitmap functionality'
4 . ./test-lib.sh
5 . "${TEST_DIRECTORY}/lib-bitmap.sh"
6
7 # We'll be writing our own midx and bitmaps, so avoid getting confused by the
8 # automatic ones.
9 GIT_TEST_MULTI_PACK_INDEX=0
10 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
11
12 # This test exercise multi-pack bitmap functionality where the object order is
13 # stored and read from a special chunk within the MIDX, so use the default
14 # behavior here.
15 sane_unset GIT_TEST_MIDX_WRITE_REV
16 sane_unset GIT_TEST_MIDX_READ_RIDX
17
18 midx_bitmap_core
19
20 bitmap_reuse_tests() {
21         from=$1
22         to=$2
23
24         test_expect_success "setup pack reuse tests ($from -> $to)" '
25                 rm -fr repo &&
26                 git init repo &&
27                 (
28                         cd repo &&
29                         test_commit_bulk 16 &&
30                         git tag old-tip &&
31
32                         git config core.multiPackIndex true &&
33                         if test "MIDX" = "$from"
34                         then
35                                 git repack -Ad &&
36                                 git multi-pack-index write --bitmap
37                         else
38                                 git repack -Adb
39                         fi
40                 )
41         '
42
43         test_expect_success "build bitmap from existing ($from -> $to)" '
44                 (
45                         cd repo &&
46                         test_commit_bulk --id=further 16 &&
47                         git tag new-tip &&
48
49                         if test "MIDX" = "$to"
50                         then
51                                 git repack -d &&
52                                 git multi-pack-index write --bitmap
53                         else
54                                 git repack -Adb
55                         fi
56                 )
57         '
58
59         test_expect_success "verify resulting bitmaps ($from -> $to)" '
60                 (
61                         cd repo &&
62                         git for-each-ref &&
63                         git rev-list --test-bitmap refs/tags/old-tip &&
64                         git rev-list --test-bitmap refs/tags/new-tip
65                 )
66         '
67 }
68
69 bitmap_reuse_tests 'pack' 'MIDX'
70 bitmap_reuse_tests 'MIDX' 'pack'
71 bitmap_reuse_tests 'MIDX' 'MIDX'
72
73 test_expect_success 'missing object closure fails gracefully' '
74         rm -fr repo &&
75         git init repo &&
76         test_when_finished "rm -fr repo" &&
77         (
78                 cd repo &&
79
80                 test_commit loose &&
81                 test_commit packed &&
82
83                 # Do not pass "--revs"; we want a pack without the "loose"
84                 # commit.
85                 git pack-objects $objdir/pack/pack <<-EOF &&
86                 $(git rev-parse packed)
87                 EOF
88
89                 test_must_fail git multi-pack-index write --bitmap 2>err &&
90                 grep "doesn.t have full closure" err &&
91                 test_path_is_missing $midx
92         )
93 '
94
95 midx_bitmap_partial_tests
96
97 test_expect_success 'removing a MIDX clears stale bitmaps' '
98         rm -fr repo &&
99         git init repo &&
100         test_when_finished "rm -fr repo" &&
101         (
102                 cd repo &&
103                 test_commit base &&
104                 git repack &&
105                 git multi-pack-index write --bitmap &&
106
107                 # Write a MIDX and bitmap; remove the MIDX but leave the bitmap.
108                 stale_bitmap=$midx-$(midx_checksum $objdir).bitmap &&
109                 rm $midx &&
110
111                 # Then write a new MIDX.
112                 test_commit new &&
113                 git repack &&
114                 git multi-pack-index write --bitmap &&
115
116                 test_path_is_file $midx &&
117                 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
118                 test_path_is_missing $stale_bitmap
119         )
120 '
121
122 test_expect_success 'pack.preferBitmapTips' '
123         git init repo &&
124         test_when_finished "rm -fr repo" &&
125         (
126                 cd repo &&
127
128                 test_commit_bulk --message="%s" 103 &&
129
130                 git log --format="%H" >commits.raw &&
131                 sort <commits.raw >commits &&
132
133                 git log --format="create refs/tags/%s %H" HEAD >refs &&
134                 git update-ref --stdin <refs &&
135
136                 git multi-pack-index write --bitmap &&
137                 test_path_is_file $midx &&
138                 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
139
140                 test-tool bitmap list-commits | sort >bitmaps &&
141                 comm -13 bitmaps commits >before &&
142                 test_line_count = 1 before &&
143
144                 perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \
145                         <before | git update-ref --stdin &&
146
147                 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
148                 rm -fr $midx &&
149
150                 git -c pack.preferBitmapTips=refs/tags/include \
151                         multi-pack-index write --bitmap &&
152                 test-tool bitmap list-commits | sort >bitmaps &&
153                 comm -13 bitmaps commits >after &&
154
155                 ! test_cmp before after
156         )
157 '
158
159 test_expect_success 'writing a bitmap with --refs-snapshot' '
160         git init repo &&
161         test_when_finished "rm -fr repo" &&
162         (
163                 cd repo &&
164
165                 test_commit one &&
166                 test_commit two &&
167
168                 git rev-parse one >snapshot &&
169
170                 git repack -ad &&
171
172                 # First, write a MIDX which see both refs/tags/one and
173                 # refs/tags/two (causing both of those commits to receive
174                 # bitmaps).
175                 git multi-pack-index write --bitmap &&
176
177                 test_path_is_file $midx &&
178                 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
179
180                 test-tool bitmap list-commits | sort >bitmaps &&
181                 grep "$(git rev-parse one)" bitmaps &&
182                 grep "$(git rev-parse two)" bitmaps &&
183
184                 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
185                 rm -fr $midx &&
186
187                 # Then again, but with a refs snapshot which only sees
188                 # refs/tags/one.
189                 git multi-pack-index write --bitmap --refs-snapshot=snapshot &&
190
191                 test_path_is_file $midx &&
192                 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
193
194                 test-tool bitmap list-commits | sort >bitmaps &&
195                 grep "$(git rev-parse one)" bitmaps &&
196                 ! grep "$(git rev-parse two)" bitmaps
197         )
198 '
199
200 test_expect_success 'write a bitmap with --refs-snapshot (preferred tips)' '
201         git init repo &&
202         test_when_finished "rm -fr repo" &&
203         (
204                 cd repo &&
205
206                 test_commit_bulk --message="%s" 103 &&
207
208                 git log --format="%H" >commits.raw &&
209                 sort <commits.raw >commits &&
210
211                 git log --format="create refs/tags/%s %H" HEAD >refs &&
212                 git update-ref --stdin <refs &&
213
214                 git multi-pack-index write --bitmap &&
215                 test_path_is_file $midx &&
216                 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
217
218                 test-tool bitmap list-commits | sort >bitmaps &&
219                 comm -13 bitmaps commits >before &&
220                 test_line_count = 1 before &&
221
222                 (
223                         grep -vf before commits.raw &&
224                         # mark missing commits as preferred
225                         sed "s/^/+/" before
226                 ) >snapshot &&
227
228                 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
229                 rm -fr $midx &&
230
231                 git multi-pack-index write --bitmap --refs-snapshot=snapshot &&
232                 test-tool bitmap list-commits | sort >bitmaps &&
233                 comm -13 bitmaps commits >after &&
234
235                 ! test_cmp before after
236         )
237 '
238
239 test_expect_success 'hash-cache values are propagated from pack bitmaps' '
240         rm -fr repo &&
241         git init repo &&
242         test_when_finished "rm -fr repo" &&
243         (
244                 cd repo &&
245
246                 test_commit base &&
247                 test_commit base2 &&
248                 git repack -adb &&
249
250                 test-tool bitmap dump-hashes >pack.raw &&
251                 test_file_not_empty pack.raw &&
252                 sort pack.raw >pack.hashes &&
253
254                 test_commit new &&
255                 git repack &&
256                 git multi-pack-index write --bitmap &&
257
258                 test-tool bitmap dump-hashes >midx.raw &&
259                 sort midx.raw >midx.hashes &&
260
261                 # ensure that every namehash in the pack bitmap can be found in
262                 # the midx bitmap (i.e., that there are no oid-namehash pairs
263                 # unique to the pack bitmap).
264                 comm -23 pack.hashes midx.hashes >dropped.hashes &&
265                 test_must_be_empty dropped.hashes
266         )
267 '
268
269 test_expect_success 'no .bitmap is written without any objects' '
270         rm -fr repo &&
271         git init repo &&
272         test_when_finished "rm -fr repo" &&
273         (
274                 cd repo &&
275
276                 empty="$(git pack-objects $objdir/pack/pack </dev/null)" &&
277                 cat >packs <<-EOF &&
278                 pack-$empty.idx
279                 EOF
280
281                 git multi-pack-index write --bitmap --stdin-packs \
282                         <packs 2>err &&
283
284                 grep "bitmap without any objects" err &&
285
286                 test_path_is_file $midx &&
287                 test_path_is_missing $midx-$(midx_checksum $objdir).bitmap
288         )
289 '
290
291 test_expect_success 'graceful fallback when missing reverse index' '
292         rm -fr repo &&
293         git init repo &&
294         test_when_finished "rm -fr repo" &&
295         (
296                 cd repo &&
297
298                 test_commit base &&
299
300                 # write a pack and MIDX bitmap containing base
301                 git repack -adb &&
302                 git multi-pack-index write --bitmap &&
303
304                 GIT_TEST_MIDX_READ_RIDX=0 \
305                         git rev-list --use-bitmap-index HEAD 2>err &&
306                 ! grep "ignoring extra bitmap file" err
307         )
308 '
309
310 test_done