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