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