midx: write object id fanout chunk
[git/raj.git] / t / t5319-multi-pack-index.sh
blob95e731ae52f125dc0e2720588588fd52d70b4ae1
1 #!/bin/sh
3 test_description='multi-pack-indexes'
4 . ./test-lib.sh
6 midx_read_expect () {
7 NUM_PACKS=$1
8 NUM_OBJECTS=$2
10 cat <<-EOF &&
11 header: 4d494458 1 3 $NUM_PACKS
12 chunks: pack-names oid-fanout oid-lookup
13 num_objects: $NUM_OBJECTS
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 &&
22 test-tool read-midx . >actual &&
23 test_cmp expect actual
26 test_expect_success 'write midx with no packs' '
27 test_when_finished rm -f pack/multi-pack-index &&
28 git multi-pack-index --object-dir=. write &&
29 midx_read_expect 0 0
32 generate_objects () {
33 i=$1
34 iii=$(printf '%03i' $i)
36 test-tool genrandom "bar" 200 &&
37 test-tool genrandom "baz $iii" 50
38 } >wide_delta_$iii &&
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 &&
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
51 commit_and_list_objects () {
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) &&
60 echo $tree &&
61 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
62 } >obj-list &&
63 git reset --hard $commit
66 test_expect_success 'create objects' '
67 test_commit initial &&
68 for i in $(test_seq 1 5)
70 generate_objects $i
71 done &&
72 commit_and_list_objects
75 test_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 &&
79 midx_read_expect 1 18
82 test_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 &&
85 midx_read_expect 1 18
88 test_expect_success 'add more objects' '
89 for i in $(test_seq 6 10)
91 generate_objects $i
92 done &&
93 commit_and_list_objects
96 test_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 &&
99 midx_read_expect 2 34
102 test_expect_success 'add more packs' '
103 for j in $(test_seq 11 20)
105 generate_objects $j &&
106 commit_and_list_objects &&
107 git pack-objects --index-version=2 pack/test-pack <obj-list
108 done
111 test_expect_success 'write midx with twelve packs' '
112 git multi-pack-index --object-dir=. write &&
113 midx_read_expect 12 74
116 test_done