]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5310-pack-bitmaps.sh
rev-list: allow bitmaps when counting objects
[thirdparty/git.git] / t / t5310-pack-bitmaps.sh
CommitLineData
212f2ffb
JK
1#!/bin/sh
2
3test_description='exercise basic bitmap functionality'
4. ./test-lib.sh
5
2db1a43f
VM
6objpath () {
7 echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
8}
9
702d1b95
KS
10# show objects present in pack ($1 should be associated *.idx)
11list_packed_objects () {
10c60017
SG
12 git show-index <"$1" >object-list &&
13 cut -d' ' -f2 object-list
702d1b95
KS
14}
15
16# has_any pattern-file content-file
17# tests whether content-file has any entry from pattern-file with entries being
18# whole lines.
19has_any () {
20 grep -Ff "$1" "$2"
21}
22
212f2ffb 23test_expect_success 'setup repo with moderate-sized history' '
1ac96cd1 24 test_commit_bulk --id=file 100 &&
212f2ffb 25 git checkout -b other HEAD~5 &&
b1c36cb8 26 test_commit_bulk --id=side 10 &&
212f2ffb 27 git checkout master &&
702d1b95 28 bitmaptip=$(git rev-parse master) &&
212f2ffb
JK
29 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
30 git tag tagged-blob $blob &&
d4316604 31 git config repack.writebitmaps true
212f2ffb
JK
32'
33
34test_expect_success 'full repack creates bitmaps' '
35 git repack -ad &&
36 ls .git/objects/pack/ | grep bitmap >output &&
37 test_line_count = 1 output
38'
39
40test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
41 git rev-list --test-bitmap HEAD
42'
43
44rev_list_tests() {
45 state=$1
46
47 test_expect_success "counting commits via bitmap ($state)" '
48 git rev-list --count HEAD >expect &&
49 git rev-list --use-bitmap-index --count HEAD >actual &&
50 test_cmp expect actual
51 '
52
53 test_expect_success "counting partial commits via bitmap ($state)" '
54 git rev-list --count HEAD~5..HEAD >expect &&
55 git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
56 test_cmp expect actual
57 '
58
5c9f9bf3
JK
59 test_expect_success "counting commits with limit ($state)" '
60 git rev-list --count -n 1 HEAD >expect &&
61 git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
62 test_cmp expect actual
63 '
64
212f2ffb
JK
65 test_expect_success "counting non-linear history ($state)" '
66 git rev-list --count other...master >expect &&
67 git rev-list --use-bitmap-index --count other...master >actual &&
68 test_cmp expect actual
69 '
70
c8a70d35
JK
71 test_expect_success "counting commits with limiting ($state)" '
72 git rev-list --count HEAD -- 1.t >expect &&
73 git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
74 test_cmp expect actual
75 '
76
608d9c93
JK
77 test_expect_success "counting objects via bitmap ($state)" '
78 git rev-list --count --objects HEAD >expect &&
79 git rev-list --use-bitmap-index --count --objects HEAD >actual &&
80 test_cmp expect actual
81 '
82
212f2ffb
JK
83 test_expect_success "enumerate --objects ($state)" '
84 git rev-list --objects --use-bitmap-index HEAD >tmp &&
85 cut -d" " -f1 <tmp >tmp2 &&
86 sort <tmp2 >actual &&
87 git rev-list --objects HEAD >tmp &&
88 cut -d" " -f1 <tmp >tmp2 &&
89 sort <tmp2 >expect &&
90 test_cmp expect actual
91 '
92
93 test_expect_success "bitmap --objects handles non-commit objects ($state)" '
94 git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
95 grep $blob actual
96 '
97}
98
99rev_list_tests 'full bitmap'
100
101test_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
106'
107
108test_expect_success 'setup further non-bitmapped commits' '
b1c36cb8 109 test_commit_bulk --id=further 10
212f2ffb
JK
110'
111
112rev_list_tests 'partial bitmap'
113
114test_expect_success 'fetch (partial bitmap)' '
115 git --git-dir=clone.git fetch origin master:master &&
116 git rev-parse HEAD >expect &&
117 git --git-dir=clone.git rev-parse HEAD >actual &&
118 test_cmp expect actual
119'
120
1c409a70 121test_expect_success 'incremental repack fails when bitmaps are requested' '
212f2ffb 122 test_commit more-1 &&
1c409a70
DT
123 test_must_fail git repack -d 2>err &&
124 test_i18ngrep "Incremental repacks are incompatible with bitmap" err
212f2ffb
JK
125'
126
127test_expect_success 'incremental repack can disable bitmaps' '
128 test_commit more-2 &&
129 git repack -d --no-write-bitmap-index
130'
131
702d1b95
KS
132test_expect_success 'pack-objects respects --local (non-local loose)' '
133 git init --bare alt.git &&
134 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
135 echo content1 >file1 &&
136 # non-local loose object which is not present in bitmapped pack
137 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
138 # non-local loose object which is also present in bitmapped pack
139 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
140 git add file1 &&
141 test_tick &&
142 git commit -m commit_file1 &&
143 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
144 git index-pack 1.pack &&
145 list_packed_objects 1.idx >1.objects &&
146 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
147 ! has_any nonlocal-loose 1.objects
148'
149
150test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
151 echo content2 >file2 &&
152 blob2=$(git hash-object -w file2) &&
153 git add file2 &&
154 test_tick &&
155 git commit -m commit_file2 &&
156 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
157 pack2=$(git pack-objects pack2 <keepobjects) &&
158 mv pack2-$pack2.* .git/objects/pack/ &&
159 >.git/objects/pack/pack2-$pack2.keep &&
160 rm $(objpath $blob2) &&
161 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
162 git index-pack 2a.pack &&
163 list_packed_objects 2a.idx >2a.objects &&
164 ! has_any keepobjects 2a.objects
165'
166
167test_expect_success 'pack-objects respects --local (non-local pack)' '
168 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
169 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
170 git index-pack 2b.pack &&
171 list_packed_objects 2b.idx >2b.objects &&
172 ! has_any keepobjects 2b.objects
173'
174
175test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
176 ls .git/objects/pack/ | grep bitmap >output &&
177 test_line_count = 1 output &&
178 packbitmap=$(basename $(cat output) .bitmap) &&
179 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
180 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
181 >.git/objects/pack/$packbitmap.keep &&
182 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
183 git index-pack 3a.pack &&
184 list_packed_objects 3a.idx >3a.objects &&
185 ! has_any packbitmap.objects 3a.objects
186'
187
188test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
189 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
0465a505 190 rm -f .git/objects/pack/multi-pack-index &&
702d1b95
KS
191 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
192 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
193 git index-pack 3b.pack &&
194 list_packed_objects 3b.idx >3b.objects &&
195 ! has_any packbitmap.objects 3b.objects
196'
197
645c432d
KS
198test_expect_success 'pack-objects to file can use bitmap' '
199 # make sure we still have 1 bitmap index from previous tests
200 ls .git/objects/pack/ | grep bitmap >output &&
201 test_line_count = 1 output &&
202 # verify equivalent packs are generated with/without using bitmap index
203 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
204 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
10c60017
SG
205 list_packed_objects packa-$packasha1.idx >packa.objects &&
206 list_packed_objects packb-$packbsha1.idx >packb.objects &&
645c432d
KS
207 test_cmp packa.objects packb.objects
208'
209
212f2ffb
JK
210test_expect_success 'full repack, reusing previous bitmaps' '
211 git repack -ad &&
212 ls .git/objects/pack/ | grep bitmap >output &&
213 test_line_count = 1 output
214'
215
216test_expect_success 'fetch (full bitmap)' '
217 git --git-dir=clone.git fetch origin master:master &&
218 git rev-parse HEAD >expect &&
219 git --git-dir=clone.git rev-parse HEAD >actual &&
220 test_cmp expect actual
221'
222
2db1a43f
VM
223test_expect_success 'create objects for missing-HAVE tests' '
224 blob=$(echo "missing have" | git hash-object -w --stdin) &&
225 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
226 parent=$(echo parent | git commit-tree $tree) &&
227 commit=$(echo commit | git commit-tree $tree -p $parent) &&
228 cat >revs <<-EOF
229 HEAD
230 ^HEAD^
231 ^$commit
232 EOF
233'
234
702d1b95
KS
235test_expect_success 'pack-objects respects --incremental' '
236 cat >revs2 <<-EOF &&
237 HEAD
238 $commit
239 EOF
240 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
241 git index-pack 4.pack &&
242 list_packed_objects 4.idx >4.objects &&
243 test_line_count = 4 4.objects &&
244 git rev-list --objects $commit >revlist &&
245 cut -d" " -f1 revlist |sort >objects &&
246 test_cmp 4.objects objects
247'
248
2db1a43f
VM
249test_expect_success 'pack with missing blob' '
250 rm $(objpath $blob) &&
251 git pack-objects --stdout --revs <revs >/dev/null
252'
253
254test_expect_success 'pack with missing tree' '
255 rm $(objpath $tree) &&
256 git pack-objects --stdout --revs <revs >/dev/null
257'
258
259test_expect_success 'pack with missing parent' '
260 rm $(objpath $parent) &&
261 git pack-objects --stdout --revs <revs >/dev/null
262'
263
212f2ffb 264test_expect_success JGIT 'we can read jgit bitmaps' '
87a6bb70 265 git clone --bare . compat-jgit.git &&
212f2ffb 266 (
87a6bb70 267 cd compat-jgit.git &&
90ca1495 268 rm -f objects/pack/*.bitmap &&
212f2ffb
JK
269 jgit gc &&
270 git rev-list --test-bitmap HEAD
271 )
272'
273
274test_expect_success JGIT 'jgit can read our bitmaps' '
87a6bb70 275 git clone --bare . compat-us.git &&
212f2ffb 276 (
87a6bb70 277 cd compat-us.git &&
212f2ffb
JK
278 git repack -adb &&
279 # jgit gc will barf if it does not like our bitmaps
280 jgit gc
281 )
282'
283
21134714 284test_expect_success 'splitting packs does not generate bogus bitmaps' '
c680668d 285 test-tool genrandom foo $((1024 * 1024)) >rand &&
21134714
JK
286 git add rand &&
287 git commit -m "commit with big file" &&
288 git -c pack.packSizeLimit=500k repack -adb &&
289 git init --bare no-bitmaps.git &&
290 git -C no-bitmaps.git fetch .. HEAD
291'
292
9df4a607
JK
293test_expect_success 'set up reusable pack' '
294 rm -f .git/objects/pack/*.keep &&
295 git repack -adb &&
296 reusable_pack () {
297 git for-each-ref --format="%(objectname)" |
298 git pack-objects --delta-base-offset --revs --stdout "$@"
299 }
300'
301
302test_expect_success 'pack reuse respects --honor-pack-keep' '
303 test_when_finished "rm -f .git/objects/pack/*.keep" &&
da5a1f81
JK
304 for i in .git/objects/pack/*.pack
305 do
9df4a607
JK
306 >${i%.pack}.keep
307 done &&
308 reusable_pack --honor-pack-keep >empty.pack &&
309 git index-pack empty.pack &&
9df4a607 310 git show-index <empty.idx >actual &&
d3c6751b 311 test_must_be_empty actual
9df4a607
JK
312'
313
314test_expect_success 'pack reuse respects --local' '
315 mv .git/objects/pack/* alt.git/objects/pack/ &&
316 test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
317 reusable_pack --local >empty.pack &&
318 git index-pack empty.pack &&
9df4a607 319 git show-index <empty.idx >actual &&
d3c6751b 320 test_must_be_empty actual
9df4a607
JK
321'
322
323test_expect_success 'pack reuse respects --incremental' '
324 reusable_pack --incremental >empty.pack &&
325 git index-pack empty.pack &&
9df4a607 326 git show-index <empty.idx >actual &&
d3c6751b 327 test_must_be_empty actual
9df4a607 328'
9d2e330b
JK
329
330test_expect_success 'truncated bitmap fails gracefully' '
331 git repack -ad &&
332 git rev-list --use-bitmap-index --count --all >expect &&
333 bitmap=$(ls .git/objects/pack/*.bitmap) &&
334 test_when_finished "rm -f $bitmap" &&
2a59a6ef 335 test_copy_bytes 512 <$bitmap >$bitmap.tmp &&
9d2e330b
JK
336 mv -f $bitmap.tmp $bitmap &&
337 git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
338 test_cmp expect actual &&
339 test_i18ngrep corrupt stderr
340'
341
c0d61dfc
JK
342# have_delta <obj> <expected_base>
343#
344# Note that because this relies on cat-file, it might find _any_ copy of an
345# object in the repository. The caller is responsible for making sure
346# there's only one (e.g., via "repack -ad", or having just fetched a copy).
347have_delta () {
348 echo $2 >expect &&
349 echo $1 | git cat-file --batch-check="%(deltabase)" >actual &&
350 test_cmp expect actual
351}
352
353# Create a state of history with these properties:
354#
355# - refs that allow a client to fetch some new history, while sharing some old
356# history with the server; we use branches delta-reuse-old and
357# delta-reuse-new here
358#
359# - the new history contains an object that is stored on the server as a delta
360# against a base that is in the old history
361#
362# - the base object is not immediately reachable from the tip of the old
363# history; finding it would involve digging down through history we know the
364# other side has
365#
366# This should result in a state where fetching from old->new would not
367# traditionally reuse the on-disk delta (because we'd have to dig to realize
368# that the client has it), but we will do so if bitmaps can tell us cheaply
369# that the other side has it.
370test_expect_success 'set up thin delta-reuse parent' '
371 # This first commit contains the buried base object.
372 test-tool genrandom delta 16384 >file &&
373 git add file &&
374 git commit -m "delta base" &&
375 base=$(git rev-parse --verify HEAD:file) &&
376
377 # These intermediate commits bury the base back in history.
378 # This becomes the "old" state.
379 for i in 1 2 3 4 5
380 do
381 echo $i >file &&
382 git commit -am "intermediate $i" || return 1
383 done &&
384 git branch delta-reuse-old &&
385
386 # And now our new history has a delta against the buried base. Note
387 # that this must be smaller than the original file, since pack-objects
388 # prefers to create deltas from smaller objects to larger.
389 test-tool genrandom delta 16300 >file &&
390 git commit -am "delta result" &&
391 delta=$(git rev-parse --verify HEAD:file) &&
392 git branch delta-reuse-new &&
393
394 # Repack with bitmaps and double check that we have the expected delta
395 # relationship.
396 git repack -adb &&
397 have_delta $delta $base
398'
399
400# Now we can sanity-check the non-bitmap behavior (that the server is not able
401# to reuse the delta). This isn't strictly something we care about, so this
402# test could be scrapped in the future. But it makes sure that the next test is
403# actually triggering the feature we want.
404#
405# Note that our tools for working with on-the-wire "thin" packs are limited. So
406# we actually perform the fetch, retain the resulting pack, and inspect the
407# result.
408test_expect_success 'fetch without bitmaps ignores delta against old base' '
409 test_config pack.usebitmaps false &&
410 test_when_finished "rm -rf client.git" &&
411 git init --bare client.git &&
412 (
413 cd client.git &&
414 git config transfer.unpackLimit 1 &&
415 git fetch .. delta-reuse-old:delta-reuse-old &&
416 git fetch .. delta-reuse-new:delta-reuse-new &&
417 have_delta $delta $ZERO_OID
418 )
419'
420
421# And do the same for the bitmap case, where we do expect to find the delta.
422test_expect_success 'fetch with bitmaps can reuse old base' '
423 test_config pack.usebitmaps true &&
424 test_when_finished "rm -rf client.git" &&
425 git init --bare client.git &&
426 (
427 cd client.git &&
428 git config transfer.unpackLimit 1 &&
429 git fetch .. delta-reuse-old:delta-reuse-old &&
430 git fetch .. delta-reuse-new:delta-reuse-new &&
431 have_delta $delta $base
432 )
433'
434
212f2ffb 435test_done