]>
Commit | Line | Data |
---|---|---|
b7573536 TB |
1 | #!/bin/sh |
2 | ||
3 | test_description='cruft pack related pack-objects tests' | |
4 | . ./test-lib.sh | |
5 | ||
6 | objdir=.git/objects | |
7 | packdir=$objdir/pack | |
8 | ||
9 | basic_cruft_pack_tests () { | |
10 | expire="$1" | |
11 | ||
12 | test_expect_success "unreachable loose objects are packed (expire $expire)" ' | |
13 | git init repo && | |
14 | test_when_finished "rm -fr repo" && | |
15 | ( | |
16 | cd repo && | |
17 | ||
18 | test_commit base && | |
19 | git repack -Ad && | |
20 | test_commit loose && | |
21 | ||
22 | test-tool chmtime +2000 "$objdir/$(test_oid_to_path \ | |
23 | $(git rev-parse loose:loose.t))" && | |
24 | test-tool chmtime +1000 "$objdir/$(test_oid_to_path \ | |
25 | $(git rev-parse loose^{tree}))" && | |
26 | ||
27 | ( | |
28 | git rev-list --objects --no-object-names base..loose | | |
29 | while read oid | |
30 | do | |
31 | path="$objdir/$(test_oid_to_path "$oid")" && | |
32 | printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" | |
33 | done | | |
34 | sort -k1 | |
35 | ) >expect && | |
36 | ||
37 | keep="$(basename "$(ls $packdir/pack-*.pack)")" && | |
38 | cruft="$(echo $keep | git pack-objects --cruft \ | |
39 | --cruft-expiration="$expire" $packdir/pack)" && | |
40 | test-tool pack-mtimes "pack-$cruft.mtimes" >actual && | |
41 | ||
42 | test_cmp expect actual | |
43 | ) | |
44 | ' | |
45 | ||
46 | test_expect_success "unreachable packed objects are packed (expire $expire)" ' | |
47 | git init repo && | |
48 | test_when_finished "rm -fr repo" && | |
49 | ( | |
50 | cd repo && | |
51 | ||
52 | test_commit packed && | |
53 | git repack -Ad && | |
54 | test_commit other && | |
55 | ||
56 | git rev-list --objects --no-object-names packed.. >objects && | |
57 | keep="$(basename "$(ls $packdir/pack-*.pack)")" && | |
58 | other="$(git pack-objects --delta-base-offset \ | |
59 | $packdir/pack <objects)" && | |
60 | git prune-packed && | |
61 | ||
62 | test-tool chmtime --get -100 "$packdir/pack-$other.pack" >expect && | |
63 | ||
64 | cruft="$(git pack-objects --cruft --cruft-expiration="$expire" $packdir/pack <<-EOF | |
65 | $keep | |
66 | -pack-$other.pack | |
67 | EOF | |
68 | )" && | |
69 | test-tool pack-mtimes "pack-$cruft.mtimes" >actual.raw && | |
70 | ||
71 | cut -d" " -f2 <actual.raw | sort -u >actual && | |
72 | ||
73 | test_cmp expect actual | |
74 | ) | |
75 | ' | |
76 | ||
77 | test_expect_success "unreachable cruft objects are repacked (expire $expire)" ' | |
78 | git init repo && | |
79 | test_when_finished "rm -fr repo" && | |
80 | ( | |
81 | cd repo && | |
82 | ||
83 | test_commit packed && | |
84 | git repack -Ad && | |
85 | test_commit other && | |
86 | ||
87 | git rev-list --objects --no-object-names packed.. >objects && | |
88 | keep="$(basename "$(ls $packdir/pack-*.pack)")" && | |
89 | ||
90 | cruft_a="$(echo $keep | git pack-objects --cruft --cruft-expiration="$expire" $packdir/pack)" && | |
91 | git prune-packed && | |
92 | cruft_b="$(git pack-objects --cruft --cruft-expiration="$expire" $packdir/pack <<-EOF | |
93 | $keep | |
94 | -pack-$cruft_a.pack | |
95 | EOF | |
96 | )" && | |
97 | ||
98 | test-tool pack-mtimes "pack-$cruft_a.mtimes" >expect.raw && | |
99 | test-tool pack-mtimes "pack-$cruft_b.mtimes" >actual.raw && | |
100 | ||
101 | sort <expect.raw >expect && | |
102 | sort <actual.raw >actual && | |
103 | ||
104 | test_cmp expect actual | |
105 | ) | |
106 | ' | |
107 | ||
108 | test_expect_success "multiple cruft packs (expire $expire)" ' | |
109 | git init repo && | |
110 | test_when_finished "rm -fr repo" && | |
111 | ( | |
112 | cd repo && | |
113 | ||
114 | test_commit reachable && | |
115 | git repack -Ad && | |
116 | keep="$(basename "$(ls $packdir/pack-*.pack)")" && | |
117 | ||
118 | test_commit cruft && | |
119 | loose="$objdir/$(test_oid_to_path $(git rev-parse cruft))" && | |
120 | ||
121 | # generate three copies of the cruft object in different | |
122 | # cruft packs, each with a unique mtime: | |
123 | # - one expired (1000 seconds ago) | |
124 | # - two non-expired (one 1000 seconds in the future, | |
125 | # one 1500 seconds in the future) | |
126 | test-tool chmtime =-1000 "$loose" && | |
127 | git pack-objects --cruft $packdir/pack-A <<-EOF && | |
128 | $keep | |
129 | EOF | |
130 | test-tool chmtime =+1000 "$loose" && | |
131 | git pack-objects --cruft $packdir/pack-B <<-EOF && | |
132 | $keep | |
133 | -$(basename $(ls $packdir/pack-A-*.pack)) | |
134 | EOF | |
135 | test-tool chmtime =+1500 "$loose" && | |
136 | git pack-objects --cruft $packdir/pack-C <<-EOF && | |
137 | $keep | |
138 | -$(basename $(ls $packdir/pack-A-*.pack)) | |
139 | -$(basename $(ls $packdir/pack-B-*.pack)) | |
140 | EOF | |
141 | ||
142 | # ensure the resulting cruft pack takes the most recent | |
143 | # mtime among all copies | |
144 | cruft="$(git pack-objects --cruft \ | |
145 | --cruft-expiration="$expire" \ | |
146 | $packdir/pack <<-EOF | |
147 | $keep | |
148 | -$(basename $(ls $packdir/pack-A-*.pack)) | |
149 | -$(basename $(ls $packdir/pack-B-*.pack)) | |
150 | -$(basename $(ls $packdir/pack-C-*.pack)) | |
151 | EOF | |
152 | )" && | |
153 | ||
154 | test-tool pack-mtimes "$(basename $(ls $packdir/pack-C-*.mtimes))" >expect.raw && | |
155 | test-tool pack-mtimes "pack-$cruft.mtimes" >actual.raw && | |
156 | ||
157 | sort expect.raw >expect && | |
158 | sort actual.raw >actual && | |
159 | test_cmp expect actual | |
160 | ) | |
161 | ' | |
162 | ||
163 | test_expect_success "cruft packs tolerate missing trees (expire $expire)" ' | |
164 | git init repo && | |
165 | test_when_finished "rm -fr repo" && | |
166 | ( | |
167 | cd repo && | |
168 | ||
169 | test_commit reachable && | |
170 | test_commit cruft && | |
171 | ||
172 | tree="$(git rev-parse cruft^{tree})" && | |
173 | ||
174 | git reset --hard reachable && | |
175 | git tag -d cruft && | |
176 | git reflog expire --all --expire=all && | |
177 | ||
178 | # remove the unreachable tree, but leave the commit | |
179 | # which has it as its root tree intact | |
180 | rm -fr "$objdir/$(test_oid_to_path "$tree")" && | |
181 | ||
182 | git repack -Ad && | |
183 | basename $(ls $packdir/pack-*.pack) >in && | |
184 | git pack-objects --cruft --cruft-expiration="$expire" \ | |
185 | $packdir/pack <in | |
186 | ) | |
187 | ' | |
188 | ||
189 | test_expect_success "cruft packs tolerate missing blobs (expire $expire)" ' | |
190 | git init repo && | |
191 | test_when_finished "rm -fr repo" && | |
192 | ( | |
193 | cd repo && | |
194 | ||
195 | test_commit reachable && | |
196 | test_commit cruft && | |
197 | ||
198 | blob="$(git rev-parse cruft:cruft.t)" && | |
199 | ||
200 | git reset --hard reachable && | |
201 | git tag -d cruft && | |
202 | git reflog expire --all --expire=all && | |
203 | ||
204 | # remove the unreachable blob, but leave the commit (and | |
205 | # the root tree of that commit) intact | |
206 | rm -fr "$objdir/$(test_oid_to_path "$blob")" && | |
207 | ||
208 | git repack -Ad && | |
209 | basename $(ls $packdir/pack-*.pack) >in && | |
210 | git pack-objects --cruft --cruft-expiration="$expire" \ | |
211 | $packdir/pack <in | |
212 | ) | |
213 | ' | |
214 | } | |
215 | ||
216 | basic_cruft_pack_tests never | |
217 | ||
218 | test_done |