]>
Commit | Line | Data |
---|---|---|
0fabafd0 TB |
1 | #!/bin/sh |
2 | ||
3 | test_description='git repack --geometric works correctly' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | GIT_TEST_MULTI_PACK_INDEX=0 | |
8 | ||
9 | objdir=.git/objects | |
10 | midx=$objdir/pack/multi-pack-index | |
11 | ||
12 | test_expect_success '--geometric with no packs' ' | |
13 | git init geometric && | |
14 | test_when_finished "rm -fr geometric" && | |
15 | ( | |
16 | cd geometric && | |
17 | ||
18 | git repack --geometric 2 >out && | |
19 | test_i18ngrep "Nothing new to pack" out | |
20 | ) | |
21 | ' | |
22 | ||
f25e33c1 TB |
23 | test_expect_success '--geometric with one pack' ' |
24 | git init geometric && | |
25 | test_when_finished "rm -fr geometric" && | |
26 | ( | |
27 | cd geometric && | |
28 | ||
29 | test_commit "base" && | |
30 | git repack -d && | |
31 | ||
32 | git repack --geometric 2 >out && | |
33 | ||
34 | test_i18ngrep "Nothing new to pack" out | |
35 | ) | |
36 | ' | |
37 | ||
0fabafd0 TB |
38 | test_expect_success '--geometric with an intact progression' ' |
39 | git init geometric && | |
40 | test_when_finished "rm -fr geometric" && | |
41 | ( | |
42 | cd geometric && | |
43 | ||
44 | # These packs already form a geometric progression. | |
45 | test_commit_bulk --start=1 1 && # 3 objects | |
46 | test_commit_bulk --start=2 2 && # 6 objects | |
47 | test_commit_bulk --start=4 4 && # 12 objects | |
48 | ||
49 | find $objdir/pack -name "*.pack" | sort >expect && | |
50 | git repack --geometric 2 -d && | |
51 | find $objdir/pack -name "*.pack" | sort >actual && | |
52 | ||
53 | test_cmp expect actual | |
54 | ) | |
55 | ' | |
56 | ||
dab32477 TB |
57 | test_expect_success '--geometric with loose objects' ' |
58 | git init geometric && | |
59 | test_when_finished "rm -fr geometric" && | |
60 | ( | |
61 | cd geometric && | |
62 | ||
63 | # These packs already form a geometric progression. | |
64 | test_commit_bulk --start=1 1 && # 3 objects | |
65 | test_commit_bulk --start=2 2 && # 6 objects | |
66 | # The loose objects are packed together, breaking the | |
67 | # progression. | |
68 | test_commit loose && # 3 objects | |
69 | ||
70 | find $objdir/pack -name "*.pack" | sort >before && | |
71 | git repack --geometric 2 -d && | |
72 | find $objdir/pack -name "*.pack" | sort >after && | |
73 | ||
74 | comm -13 before after >new && | |
75 | comm -23 before after >removed && | |
76 | ||
77 | test_line_count = 1 new && | |
78 | test_must_be_empty removed && | |
79 | ||
80 | git repack --geometric 2 -d && | |
81 | find $objdir/pack -name "*.pack" | sort >after && | |
82 | ||
83 | # The progression (3, 3, 6) is combined into one new pack. | |
84 | test_line_count = 1 after | |
85 | ) | |
86 | ' | |
87 | ||
0fabafd0 TB |
88 | test_expect_success '--geometric with small-pack rollup' ' |
89 | git init geometric && | |
90 | test_when_finished "rm -fr geometric" && | |
91 | ( | |
92 | cd geometric && | |
93 | ||
94 | test_commit_bulk --start=1 1 && # 3 objects | |
95 | test_commit_bulk --start=2 1 && # 3 objects | |
96 | find $objdir/pack -name "*.pack" | sort >small && | |
97 | test_commit_bulk --start=3 4 && # 12 objects | |
98 | test_commit_bulk --start=7 8 && # 24 objects | |
99 | find $objdir/pack -name "*.pack" | sort >before && | |
100 | ||
101 | git repack --geometric 2 -d && | |
102 | ||
103 | # Three packs in total; two of the existing large ones, and one | |
104 | # new one. | |
105 | find $objdir/pack -name "*.pack" | sort >after && | |
106 | test_line_count = 3 after && | |
107 | comm -3 small before | tr -d "\t" >large && | |
108 | grep -qFf large after | |
109 | ) | |
110 | ' | |
111 | ||
112 | test_expect_success '--geometric with small- and large-pack rollup' ' | |
113 | git init geometric && | |
114 | test_when_finished "rm -fr geometric" && | |
115 | ( | |
116 | cd geometric && | |
117 | ||
118 | # size(small1) + size(small2) > size(medium) / 2 | |
119 | test_commit_bulk --start=1 1 && # 3 objects | |
120 | test_commit_bulk --start=2 1 && # 3 objects | |
121 | test_commit_bulk --start=2 3 && # 7 objects | |
122 | test_commit_bulk --start=6 9 && # 27 objects && | |
123 | ||
124 | find $objdir/pack -name "*.pack" | sort >before && | |
125 | ||
126 | git repack --geometric 2 -d && | |
127 | ||
128 | find $objdir/pack -name "*.pack" | sort >after && | |
129 | comm -12 before after >untouched && | |
130 | ||
131 | # Two packs in total; the largest pack from before running "git | |
132 | # repack", and one new one. | |
133 | test_line_count = 1 untouched && | |
134 | test_line_count = 2 after | |
135 | ) | |
136 | ' | |
137 | ||
138 | test_expect_success '--geometric ignores kept packs' ' | |
139 | git init geometric && | |
140 | test_when_finished "rm -fr geometric" && | |
141 | ( | |
142 | cd geometric && | |
143 | ||
144 | test_commit kept && # 3 objects | |
145 | test_commit pack && # 3 objects | |
146 | ||
147 | KEPT=$(git pack-objects --revs $objdir/pack/pack <<-EOF | |
148 | refs/tags/kept | |
149 | EOF | |
150 | ) && | |
151 | PACK=$(git pack-objects --revs $objdir/pack/pack <<-EOF | |
152 | refs/tags/pack | |
153 | ^refs/tags/kept | |
154 | EOF | |
155 | ) && | |
156 | ||
157 | # neither pack contains more than twice the number of objects in | |
158 | # the other, so they should be combined. but, marking one as | |
159 | # .kept on disk will "freeze" it, so the pack structure should | |
160 | # remain unchanged. | |
161 | touch $objdir/pack/pack-$KEPT.keep && | |
162 | ||
163 | find $objdir/pack -name "*.pack" | sort >before && | |
164 | git repack --geometric 2 -d && | |
165 | find $objdir/pack -name "*.pack" | sort >after && | |
166 | ||
167 | # both packs should still exist | |
168 | test_path_is_file $objdir/pack/pack-$KEPT.pack && | |
169 | test_path_is_file $objdir/pack/pack-$PACK.pack && | |
170 | ||
171 | # and no new packs should be created | |
172 | test_cmp before after && | |
173 | ||
174 | # Passing --pack-kept-objects causes packs with a .keep file to | |
175 | # be repacked, too. | |
176 | git repack --geometric 2 -d --pack-kept-objects && | |
177 | ||
178 | find $objdir/pack -name "*.pack" >after && | |
179 | test_line_count = 1 after | |
180 | ) | |
181 | ' | |
182 | ||
183 | test_done |