3 test_description='exercise basic bitmap functionality'
7 echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
10 # show objects present in pack ($1 should be associated *.idx)
11 list_packed_objects () {
12 git show-index <"$1" >object-list &&
13 cut -d' ' -f2 object-list
16 # has_any pattern-file content-file
17 # tests whether content-file has any entry from pattern-file with entries being
23 test_expect_success 'setup repo with moderate-sized history' '
24 for i in $(test_seq 1 10)
28 git checkout -b other HEAD~5 &&
29 for i in $(test_seq 1 10)
33 git checkout master &&
34 bitmaptip=$(git rev-parse master) &&
35 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
36 git tag tagged-blob $blob &&
37 git config repack.writebitmaps true &&
38 git config pack.writebitmaphashcache true
41 test_expect_success 'full repack creates bitmaps' '
43 ls .git/objects/pack/ | grep bitmap >output &&
44 test_line_count = 1 output
47 test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
48 git rev-list --test-bitmap HEAD
54 test_expect_success "counting commits via bitmap ($state)" '
55 git rev-list --count HEAD >expect &&
56 git rev-list --use-bitmap-index --count HEAD >actual &&
57 test_cmp expect actual
60 test_expect_success "counting partial commits via bitmap ($state)" '
61 git rev-list --count HEAD~5..HEAD >expect &&
62 git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
63 test_cmp expect actual
66 test_expect_success "counting commits with limit ($state)" '
67 git rev-list --count -n 1 HEAD >expect &&
68 git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
69 test_cmp expect actual
72 test_expect_success "counting non-linear history ($state)" '
73 git rev-list --count other...master >expect &&
74 git rev-list --use-bitmap-index --count other...master >actual &&
75 test_cmp expect actual
78 test_expect_success "counting commits with limiting ($state)" '
79 git rev-list --count HEAD -- 1.t >expect &&
80 git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
81 test_cmp expect actual
84 test_expect_success "enumerate --objects ($state)" '
85 git rev-list --objects --use-bitmap-index HEAD >tmp &&
86 cut -d" " -f1 <tmp >tmp2 &&
88 git rev-list --objects HEAD >tmp &&
89 cut -d" " -f1 <tmp >tmp2 &&
91 test_cmp expect actual
94 test_expect_success "bitmap --objects handles non-commit objects ($state)" '
95 git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
100 rev_list_tests 'full bitmap'
102 test_expect_success 'clone from bitmapped repository' '
103 git clone --no-local --bare . clone.git &&
104 git rev-parse HEAD >expect &&
105 git --git-dir=clone.git rev-parse HEAD >actual &&
106 test_cmp expect actual
109 test_expect_success 'setup further non-bitmapped commits' '
110 for i in $(test_seq 1 10)
112 test_commit further-$i
116 rev_list_tests 'partial bitmap'
118 test_expect_success 'fetch (partial bitmap)' '
119 git --git-dir=clone.git fetch origin master:master &&
120 git rev-parse HEAD >expect &&
121 git --git-dir=clone.git rev-parse HEAD >actual &&
122 test_cmp expect actual
125 test_expect_success 'incremental repack fails when bitmaps are requested' '
126 test_commit more-1 &&
127 test_must_fail git repack -d 2>err &&
128 test_i18ngrep "Incremental repacks are incompatible with bitmap" err
131 test_expect_success 'incremental repack can disable bitmaps' '
132 test_commit more-2 &&
133 git repack -d --no-write-bitmap-index
136 test_expect_success 'pack-objects respects --local (non-local loose)' '
137 git init --bare alt.git &&
138 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
139 echo content1 >file1 &&
140 # non-local loose object which is not present in bitmapped pack
141 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
142 # non-local loose object which is also present in bitmapped pack
143 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
146 git commit -m commit_file1 &&
147 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
148 git index-pack 1.pack &&
149 list_packed_objects 1.idx >1.objects &&
150 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
151 ! has_any nonlocal-loose 1.objects
154 test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
155 echo content2 >file2 &&
156 blob2=$(git hash-object -w file2) &&
159 git commit -m commit_file2 &&
160 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
161 pack2=$(git pack-objects pack2 <keepobjects) &&
162 mv pack2-$pack2.* .git/objects/pack/ &&
163 >.git/objects/pack/pack2-$pack2.keep &&
164 rm $(objpath $blob2) &&
165 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
166 git index-pack 2a.pack &&
167 list_packed_objects 2a.idx >2a.objects &&
168 ! has_any keepobjects 2a.objects
171 test_expect_success 'pack-objects respects --local (non-local pack)' '
172 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
173 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
174 git index-pack 2b.pack &&
175 list_packed_objects 2b.idx >2b.objects &&
176 ! has_any keepobjects 2b.objects
179 test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
180 ls .git/objects/pack/ | grep bitmap >output &&
181 test_line_count = 1 output &&
182 packbitmap=$(basename $(cat output) .bitmap) &&
183 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
184 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
185 >.git/objects/pack/$packbitmap.keep &&
186 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
187 git index-pack 3a.pack &&
188 list_packed_objects 3a.idx >3a.objects &&
189 ! has_any packbitmap.objects 3a.objects
192 test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
193 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
194 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
195 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
196 git index-pack 3b.pack &&
197 list_packed_objects 3b.idx >3b.objects &&
198 ! has_any packbitmap.objects 3b.objects
201 test_expect_success 'pack-objects to file can use bitmap' '
202 # make sure we still have 1 bitmap index from previous tests
203 ls .git/objects/pack/ | grep bitmap >output &&
204 test_line_count = 1 output &&
205 # verify equivalent packs are generated with/without using bitmap index
206 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
207 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
208 list_packed_objects packa-$packasha1.idx >packa.objects &&
209 list_packed_objects packb-$packbsha1.idx >packb.objects &&
210 test_cmp packa.objects packb.objects
213 test_expect_success 'full repack, reusing previous bitmaps' '
215 ls .git/objects/pack/ | grep bitmap >output &&
216 test_line_count = 1 output
219 test_expect_success 'fetch (full bitmap)' '
220 git --git-dir=clone.git fetch origin master:master &&
221 git rev-parse HEAD >expect &&
222 git --git-dir=clone.git rev-parse HEAD >actual &&
223 test_cmp expect actual
226 test_expect_success 'create objects for missing-HAVE tests' '
227 blob=$(echo "missing have" | git hash-object -w --stdin) &&
228 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
229 parent=$(echo parent | git commit-tree $tree) &&
230 commit=$(echo commit | git commit-tree $tree -p $parent) &&
238 test_expect_success 'pack-objects respects --incremental' '
243 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
244 git index-pack 4.pack &&
245 list_packed_objects 4.idx >4.objects &&
246 test_line_count = 4 4.objects &&
247 git rev-list --objects $commit >revlist &&
248 cut -d" " -f1 revlist |sort >objects &&
249 test_cmp 4.objects objects
252 test_expect_success 'pack with missing blob' '
253 rm $(objpath $blob) &&
254 git pack-objects --stdout --revs <revs >/dev/null
257 test_expect_success 'pack with missing tree' '
258 rm $(objpath $tree) &&
259 git pack-objects --stdout --revs <revs >/dev/null
262 test_expect_success 'pack with missing parent' '
263 rm $(objpath $parent) &&
264 git pack-objects --stdout --revs <revs >/dev/null
267 test_expect_success JGIT 'we can read jgit bitmaps' '
268 git clone --bare . compat-jgit.git &&
270 cd compat-jgit.git &&
271 rm -f .git/objects/pack/*.bitmap &&
273 git rev-list --test-bitmap HEAD
277 test_expect_success JGIT 'jgit can read our bitmaps' '
278 git clone --bare . compat-us.git &&
282 # jgit gc will barf if it does not like our bitmaps
287 test_expect_success 'splitting packs does not generate bogus bitmaps' '
288 test-tool genrandom foo $((1024 * 1024)) >rand &&
290 git commit -m "commit with big file" &&
291 git -c pack.packSizeLimit=500k repack -adb &&
292 git init --bare no-bitmaps.git &&
293 git -C no-bitmaps.git fetch .. HEAD
296 test_expect_success 'set up reusable pack' '
297 rm -f .git/objects/pack/*.keep &&
300 git for-each-ref --format="%(objectname)" |
301 git pack-objects --delta-base-offset --revs --stdout "$@"
305 test_expect_success 'pack reuse respects --honor-pack-keep' '
306 test_when_finished "rm -f .git/objects/pack/*.keep" &&
307 for i in .git/objects/pack/*.pack
311 reusable_pack --honor-pack-keep >empty.pack &&
312 git index-pack empty.pack &&
313 git show-index <empty.idx >actual &&
314 test_must_be_empty actual
317 test_expect_success 'pack reuse respects --local' '
318 mv .git/objects/pack/* alt.git/objects/pack/ &&
319 test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
320 reusable_pack --local >empty.pack &&
321 git index-pack empty.pack &&
322 git show-index <empty.idx >actual &&
323 test_must_be_empty actual
326 test_expect_success 'pack reuse respects --incremental' '
327 reusable_pack --incremental >empty.pack &&
328 git index-pack empty.pack &&
329 git show-index <empty.idx >actual &&
330 test_must_be_empty actual
333 test_expect_success 'truncated bitmap fails gracefully' '
335 git rev-list --use-bitmap-index --count --all >expect &&
336 bitmap=$(ls .git/objects/pack/*.bitmap) &&
337 test_when_finished "rm -f $bitmap" &&
338 head -c 512 <$bitmap >$bitmap.tmp &&
339 mv -f $bitmap.tmp $bitmap &&
340 git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
341 test_cmp expect actual &&
342 test_i18ngrep corrupt stderr