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" | cut -d' ' -f2
15 # has_any pattern-file content-file
16 # tests whether content-file has any entry from pattern-file with entries being
22 test_expect_success 'setup repo with moderate-sized history' '
23 for i in $(test_seq 1 10)
27 git checkout -b other HEAD~5 &&
28 for i in $(test_seq 1 10)
32 git checkout master &&
33 bitmaptip=$(git rev-parse master) &&
34 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
35 git tag tagged-blob $blob &&
36 git config repack.writebitmaps true &&
37 git config pack.writebitmaphashcache true
40 test_expect_success 'full repack creates bitmaps' '
42 ls .git/objects/pack/ | grep bitmap >output &&
43 test_line_count = 1 output
46 test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
47 git rev-list --test-bitmap HEAD
53 test_expect_success "counting commits via bitmap ($state)" '
54 git rev-list --count HEAD >expect &&
55 git rev-list --use-bitmap-index --count HEAD >actual &&
56 test_cmp expect actual
59 test_expect_success "counting partial commits via bitmap ($state)" '
60 git rev-list --count HEAD~5..HEAD >expect &&
61 git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
62 test_cmp expect actual
65 test_expect_success "counting commits with limit ($state)" '
66 git rev-list --count -n 1 HEAD >expect &&
67 git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
68 test_cmp expect actual
71 test_expect_success "counting non-linear history ($state)" '
72 git rev-list --count other...master >expect &&
73 git rev-list --use-bitmap-index --count other...master >actual &&
74 test_cmp expect actual
77 test_expect_success "counting commits with limiting ($state)" '
78 git rev-list --count HEAD -- 1.t >expect &&
79 git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
80 test_cmp expect actual
83 test_expect_success "enumerate --objects ($state)" '
84 git rev-list --objects --use-bitmap-index HEAD >tmp &&
85 cut -d" " -f1 <tmp >tmp2 &&
87 git rev-list --objects HEAD >tmp &&
88 cut -d" " -f1 <tmp >tmp2 &&
90 test_cmp expect actual
93 test_expect_success "bitmap --objects handles non-commit objects ($state)" '
94 git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
99 rev_list_tests 'full bitmap'
101 test_expect_success 'clone from bitmapped repository' '
102 git clone --no-local --bare . clone.git &&
103 git rev-parse HEAD >expect &&
104 git --git-dir=clone.git rev-parse HEAD >actual &&
105 test_cmp expect actual
108 test_expect_success 'setup further non-bitmapped commits' '
109 for i in $(test_seq 1 10)
111 test_commit further-$i
115 rev_list_tests 'partial bitmap'
117 test_expect_success 'fetch (partial bitmap)' '
118 git --git-dir=clone.git fetch origin master:master &&
119 git rev-parse HEAD >expect &&
120 git --git-dir=clone.git rev-parse HEAD >actual &&
121 test_cmp expect actual
124 test_expect_success 'incremental repack fails when bitmaps are requested' '
125 test_commit more-1 &&
126 test_must_fail git repack -d 2>err &&
127 test_i18ngrep "Incremental repacks are incompatible with bitmap" err
130 test_expect_success 'incremental repack can disable bitmaps' '
131 test_commit more-2 &&
132 git repack -d --no-write-bitmap-index
135 test_expect_success 'pack-objects respects --local (non-local loose)' '
136 git init --bare alt.git &&
137 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
138 echo content1 >file1 &&
139 # non-local loose object which is not present in bitmapped pack
140 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
141 # non-local loose object which is also present in bitmapped pack
142 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
145 git commit -m commit_file1 &&
146 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
147 git index-pack 1.pack &&
148 list_packed_objects 1.idx >1.objects &&
149 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
150 ! has_any nonlocal-loose 1.objects
153 test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
154 echo content2 >file2 &&
155 blob2=$(git hash-object -w file2) &&
158 git commit -m commit_file2 &&
159 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
160 pack2=$(git pack-objects pack2 <keepobjects) &&
161 mv pack2-$pack2.* .git/objects/pack/ &&
162 >.git/objects/pack/pack2-$pack2.keep &&
163 rm $(objpath $blob2) &&
164 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
165 git index-pack 2a.pack &&
166 list_packed_objects 2a.idx >2a.objects &&
167 ! has_any keepobjects 2a.objects
170 test_expect_success 'pack-objects respects --local (non-local pack)' '
171 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
172 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
173 git index-pack 2b.pack &&
174 list_packed_objects 2b.idx >2b.objects &&
175 ! has_any keepobjects 2b.objects
178 test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
179 ls .git/objects/pack/ | grep bitmap >output &&
180 test_line_count = 1 output &&
181 packbitmap=$(basename $(cat output) .bitmap) &&
182 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
183 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
184 >.git/objects/pack/$packbitmap.keep &&
185 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
186 git index-pack 3a.pack &&
187 list_packed_objects 3a.idx >3a.objects &&
188 ! has_any packbitmap.objects 3a.objects
191 test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
192 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
193 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
194 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
195 git index-pack 3b.pack &&
196 list_packed_objects 3b.idx >3b.objects &&
197 ! has_any packbitmap.objects 3b.objects
200 test_expect_success 'pack-objects to file can use bitmap' '
201 # make sure we still have 1 bitmap index from previous tests
202 ls .git/objects/pack/ | grep bitmap >output &&
203 test_line_count = 1 output &&
204 # verify equivalent packs are generated with/without using bitmap index
205 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
206 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
207 list_packed_objects <packa-$packasha1.idx >packa.objects &&
208 list_packed_objects <packb-$packbsha1.idx >packb.objects &&
209 test_cmp packa.objects packb.objects
212 test_expect_success 'full repack, reusing previous bitmaps' '
214 ls .git/objects/pack/ | grep bitmap >output &&
215 test_line_count = 1 output
218 test_expect_success 'fetch (full bitmap)' '
219 git --git-dir=clone.git fetch origin master:master &&
220 git rev-parse HEAD >expect &&
221 git --git-dir=clone.git rev-parse HEAD >actual &&
222 test_cmp expect actual
225 test_expect_success 'create objects for missing-HAVE tests' '
226 blob=$(echo "missing have" | git hash-object -w --stdin) &&
227 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
228 parent=$(echo parent | git commit-tree $tree) &&
229 commit=$(echo commit | git commit-tree $tree -p $parent) &&
237 test_expect_success 'pack-objects respects --incremental' '
242 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
243 git index-pack 4.pack &&
244 list_packed_objects 4.idx >4.objects &&
245 test_line_count = 4 4.objects &&
246 git rev-list --objects $commit >revlist &&
247 cut -d" " -f1 revlist |sort >objects &&
248 test_cmp 4.objects objects
251 test_expect_success 'pack with missing blob' '
252 rm $(objpath $blob) &&
253 git pack-objects --stdout --revs <revs >/dev/null
256 test_expect_success 'pack with missing tree' '
257 rm $(objpath $tree) &&
258 git pack-objects --stdout --revs <revs >/dev/null
261 test_expect_success 'pack with missing parent' '
262 rm $(objpath $parent) &&
263 git pack-objects --stdout --revs <revs >/dev/null
266 test_expect_success JGIT 'we can read jgit bitmaps' '
267 git clone . compat-jgit &&
270 rm -f .git/objects/pack/*.bitmap &&
272 git rev-list --test-bitmap HEAD
276 test_expect_success JGIT 'jgit can read our bitmaps' '
277 git clone . compat-us &&
281 # jgit gc will barf if it does not like our bitmaps
286 test_expect_success 'splitting packs does not generate bogus bitmaps' '
287 test-tool genrandom foo $((1024 * 1024)) >rand &&
289 git commit -m "commit with big file" &&
290 git -c pack.packSizeLimit=500k repack -adb &&
291 git init --bare no-bitmaps.git &&
292 git -C no-bitmaps.git fetch .. HEAD
295 test_expect_success 'set up reusable pack' '
296 rm -f .git/objects/pack/*.keep &&
299 git for-each-ref --format="%(objectname)" |
300 git pack-objects --delta-base-offset --revs --stdout "$@"
304 test_expect_success 'pack reuse respects --honor-pack-keep' '
305 test_when_finished "rm -f .git/objects/pack/*.keep" &&
306 for i in .git/objects/pack/*.pack
310 reusable_pack --honor-pack-keep >empty.pack &&
311 git index-pack empty.pack &&
313 git show-index <empty.idx >actual &&
314 test_cmp expect 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 &&
323 git show-index <empty.idx >actual &&
324 test_cmp expect actual
327 test_expect_success 'pack reuse respects --incremental' '
328 reusable_pack --incremental >empty.pack &&
329 git index-pack empty.pack &&
331 git show-index <empty.idx >actual &&
332 test_cmp expect actual