midx: write object id fanout chunk
[git/git.git] / t / t5319-multi-pack-index.sh
CommitLineData
a3407730
DS
1#!/bin/sh
2
3test_description='multi-pack-indexes'
4. ./test-lib.sh
5
4d80560c 6midx_read_expect () {
396f2570 7 NUM_PACKS=$1
d7cacf29 8 NUM_OBJECTS=$2
3227565c
DS
9 {
10 cat <<-EOF &&
d7cacf29
DS
11 header: 4d494458 1 3 $NUM_PACKS
12 chunks: pack-names oid-fanout oid-lookup
13 num_objects: $NUM_OBJECTS
3227565c
DS
14 packs:
15 EOF
16 if test $NUM_PACKS -ge 1
17 then
18 ls pack/ | grep idx | sort
19 fi &&
20 printf "object-dir: .\n"
21 } >expect &&
4d80560c
DS
22 test-tool read-midx . >actual &&
23 test_cmp expect actual
24}
25
a3407730 26test_expect_success 'write midx with no packs' '
fc59e748
DS
27 test_when_finished rm -f pack/multi-pack-index &&
28 git multi-pack-index --object-dir=. write &&
d7cacf29 29 midx_read_expect 0 0
a3407730
DS
30'
31
2c381335
DS
32generate_objects () {
33 i=$1
34 iii=$(printf '%03i' $i)
35 {
36 test-tool genrandom "bar" 200 &&
37 test-tool genrandom "baz $iii" 50
38 } >wide_delta_$iii &&
39 {
40 test-tool genrandom "foo"$i 100 &&
41 test-tool genrandom "foo"$(( $i + 1 )) 100 &&
42 test-tool genrandom "foo"$(( $i + 2 )) 100
43 } >deep_delta_$iii &&
44 {
45 echo $iii &&
46 test-tool genrandom "$iii" 8192
47 } >file_$iii &&
48 git update-index --add file_$iii deep_delta_$iii wide_delta_$iii
49}
50
51commit_and_list_objects () {
52 {
53 echo 101 &&
54 test-tool genrandom 100 8192;
55 } >file_101 &&
56 git update-index --add file_101 &&
57 tree=$(git write-tree) &&
58 commit=$(git commit-tree $tree -p HEAD</dev/null) &&
59 {
60 echo $tree &&
61 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
62 } >obj-list &&
63 git reset --hard $commit
64}
65
66test_expect_success 'create objects' '
67 test_commit initial &&
68 for i in $(test_seq 1 5)
69 do
70 generate_objects $i
71 done &&
72 commit_and_list_objects
73'
74
75test_expect_success 'write midx with one v1 pack' '
76 pack=$(git pack-objects --index-version=1 pack/test <obj-list) &&
77 test_when_finished rm pack/test-$pack.pack pack/test-$pack.idx pack/multi-pack-index &&
78 git multi-pack-index --object-dir=. write &&
d7cacf29 79 midx_read_expect 1 18
2c381335
DS
80'
81
82test_expect_success 'write midx with one v2 pack' '
83 git pack-objects --index-version=2,0x40 pack/test <obj-list &&
84 git multi-pack-index --object-dir=. write &&
d7cacf29 85 midx_read_expect 1 18
2c381335
DS
86'
87
88test_expect_success 'add more objects' '
89 for i in $(test_seq 6 10)
90 do
91 generate_objects $i
92 done &&
93 commit_and_list_objects
94'
95
96test_expect_success 'write midx with two packs' '
97 git pack-objects --index-version=1 pack/test-2 <obj-list &&
98 git multi-pack-index --object-dir=. write &&
d7cacf29 99 midx_read_expect 2 34
2c381335
DS
100'
101
102test_expect_success 'add more packs' '
103 for j in $(test_seq 11 20)
104 do
105 generate_objects $j &&
106 commit_and_list_objects &&
396f2570 107 git pack-objects --index-version=2 pack/test-pack <obj-list
2c381335
DS
108 done
109'
110
111test_expect_success 'write midx with twelve packs' '
112 git multi-pack-index --object-dir=. write &&
d7cacf29 113 midx_read_expect 12 74
2c381335
DS
114'
115
a3407730 116test_done