]>
Commit | Line | Data |
---|---|---|
4f6d26b1 DS |
1 | #!/bin/sh |
2 | ||
3 | test_description='pack-objects object selection using sparse algorithm' | |
966b4be2 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
4f6d26b1 DS |
7 | . ./test-lib.sh |
8 | ||
9 | test_expect_success 'setup repo' ' | |
10 | test_commit initial && | |
11 | for i in $(test_seq 1 3) | |
12 | do | |
13 | mkdir f$i && | |
14 | for j in $(test_seq 1 3) | |
15 | do | |
16 | mkdir f$i/f$j && | |
17 | echo $j >f$i/f$j/data.txt | |
18 | done | |
19 | done && | |
20 | git add . && | |
21 | git commit -m "Initialized trees" && | |
22 | for i in $(test_seq 1 3) | |
23 | do | |
966b4be2 | 24 | git checkout -b topic$i main && |
4f6d26b1 DS |
25 | echo change-$i >f$i/f$i/data.txt && |
26 | git commit -a -m "Changed f$i/f$i/data.txt" | |
27 | done && | |
28 | cat >packinput.txt <<-EOF && | |
29 | topic1 | |
30 | ^topic2 | |
31 | ^topic3 | |
32 | EOF | |
33 | git rev-parse \ | |
34 | topic1 \ | |
35 | topic1^{tree} \ | |
36 | topic1:f1 \ | |
37 | topic1:f1/f1 \ | |
38 | topic1:f1/f1/data.txt | sort >expect_objects.txt | |
39 | ' | |
40 | ||
41 | test_expect_success 'non-sparse pack-objects' ' | |
99dbbfa8 | 42 | git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack && |
4f6d26b1 DS |
43 | git index-pack -o nonsparse.idx nonsparse.pack && |
44 | git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt && | |
45 | test_cmp expect_objects.txt nonsparse_objects.txt | |
46 | ' | |
47 | ||
48 | test_expect_success 'sparse pack-objects' ' | |
49 | git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack && | |
50 | git index-pack -o sparse.idx sparse.pack && | |
51 | git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && | |
52 | test_cmp expect_objects.txt sparse_objects.txt | |
53 | ' | |
54 | ||
55 | test_expect_success 'duplicate a folder from f3 and commit to topic1' ' | |
56 | git checkout topic1 && | |
57 | echo change-3 >f3/f3/data.txt && | |
58 | git commit -a -m "Changed f3/f3/data.txt" && | |
59 | git rev-parse \ | |
60 | topic1~1 \ | |
61 | topic1~1^{tree} \ | |
62 | topic1^{tree} \ | |
63 | topic1 \ | |
64 | topic1:f1 \ | |
65 | topic1:f1/f1 \ | |
66 | topic1:f1/f1/data.txt | sort >required_objects.txt | |
67 | ' | |
68 | ||
69 | test_expect_success 'non-sparse pack-objects' ' | |
99dbbfa8 | 70 | git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack && |
4f6d26b1 DS |
71 | git index-pack -o nonsparse.idx nonsparse.pack && |
72 | git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt && | |
73 | comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt && | |
74 | test_cmp required_objects.txt nonsparse_required_objects.txt | |
75 | ' | |
76 | ||
77 | test_expect_success 'sparse pack-objects' ' | |
78 | git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack && | |
79 | git index-pack -o sparse.idx sparse.pack && | |
80 | git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && | |
81 | comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt && | |
82 | test_cmp required_objects.txt sparse_required_objects.txt | |
83 | ' | |
84 | ||
d5d2e935 DS |
85 | # Demonstrate that the algorithms differ when we copy a tree wholesale |
86 | # from one folder to another. | |
87 | ||
4f6d26b1 DS |
88 | test_expect_success 'duplicate a folder from f1 into f3' ' |
89 | mkdir f3/f4 && | |
90 | cp -r f1/f1/* f3/f4 && | |
91 | git add f3/f4 && | |
92 | git commit -m "Copied f1/f1 to f3/f4" && | |
93 | cat >packinput.txt <<-EOF && | |
94 | topic1 | |
95 | ^topic1~1 | |
96 | EOF | |
97 | git rev-parse \ | |
98 | topic1 \ | |
99 | topic1^{tree} \ | |
100 | topic1:f3 | sort >required_objects.txt | |
101 | ' | |
102 | ||
103 | test_expect_success 'non-sparse pack-objects' ' | |
d5d2e935 | 104 | git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack && |
4f6d26b1 DS |
105 | git index-pack -o nonsparse.idx nonsparse.pack && |
106 | git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt && | |
107 | comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt && | |
108 | test_cmp required_objects.txt nonsparse_required_objects.txt | |
109 | ' | |
110 | ||
de3a8641 | 111 | # --sparse is enabled by default by pack.useSparse |
4f6d26b1 | 112 | test_expect_success 'sparse pack-objects' ' |
2d657ab9 | 113 | GIT_TEST_PACK_SPARSE=-1 && |
d5d2e935 DS |
114 | git rev-parse \ |
115 | topic1 \ | |
116 | topic1^{tree} \ | |
117 | topic1:f3 \ | |
118 | topic1:f3/f4 \ | |
119 | topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt && | |
de3a8641 | 120 | git pack-objects --stdout --revs <packinput.txt >sparse.pack && |
4f6d26b1 DS |
121 | git index-pack -o sparse.idx sparse.pack && |
122 | git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && | |
d5d2e935 | 123 | test_cmp expect_sparse_objects.txt sparse_objects.txt |
4f6d26b1 DS |
124 | ' |
125 | ||
3d036eb0 DS |
126 | test_expect_success 'pack.useSparse enables algorithm' ' |
127 | git config pack.useSparse true && | |
128 | git pack-objects --stdout --revs <packinput.txt >sparse.pack && | |
129 | git index-pack -o sparse.idx sparse.pack && | |
130 | git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && | |
131 | test_cmp expect_sparse_objects.txt sparse_objects.txt | |
132 | ' | |
133 | ||
134 | test_expect_success 'pack.useSparse overridden' ' | |
135 | git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack && | |
136 | git index-pack -o sparse.idx sparse.pack && | |
137 | git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && | |
138 | test_cmp required_objects.txt sparse_objects.txt | |
139 | ' | |
140 | ||
4f6d26b1 | 141 | test_done |