]> arthur.barton.de Git - bup.git/blob - t/test-gc.sh
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / t / test-gc.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh
3
4 set -o pipefail
5
6 top="$(WVPASS pwd)" || exit $?
7 tmpdir="$(WVPASS wvmktempdir)" || exit $?
8
9 export BUP_DIR="$tmpdir/bup"
10 export GIT_DIR="$tmpdir/bup"
11
12 GC_OPTS=--unsafe
13
14 bup() { "$top/bup" "$@"; }
15 compare-trees() { "$top/t/compare-trees" "$@"; }
16 data-size() { "$top/t/data-size" "$@"; }
17
18 WVPASS cd "$tmpdir"
19 WVPASS bup init
20
21
22 WVSTART "gc (unchanged repo)"
23
24 WVPASS mkdir src-1
25 WVPASS bup random 1k > src-1/1
26 WVPASS bup index src-1
27 WVPASS bup save --strip -n src-1 src-1
28
29 WVPASS bup gc $GC_OPTS -v
30
31 WVPASS bup restore -C "$tmpdir/restore" /src-1/latest
32 WVPASS compare-trees src-1/ "$tmpdir/restore/latest/"
33
34
35 WVSTART "gc (unchanged, new branch)"
36
37 WVPASS mkdir src-2
38 WVPASS bup random 10M > src-2/1
39 WVPASS bup index src-2
40 WVPASS bup save --strip -n src-2 src-2
41
42 WVPASS bup gc $GC_OPTS -v
43
44 WVPASS rm -r "$tmpdir/restore"
45 WVPASS bup restore -C "$tmpdir/restore" /src-1/latest
46 WVPASS compare-trees src-1/ "$tmpdir/restore/latest/"
47
48 WVPASS rm -r "$tmpdir/restore"
49 WVPASS bup restore -C "$tmpdir/restore" /src-2/latest
50 WVPASS compare-trees src-2/ "$tmpdir/restore/latest/"
51
52
53 WVSTART "gc (removed branch)"
54
55 size_before=$(WVPASS data-size "$BUP_DIR") || exit $?
56 WVPASS rm "$BUP_DIR/refs/heads/src-2"
57 WVPASS bup gc $GC_OPTS -v
58 size_after=$(WVPASS data-size "$BUP_DIR") || exit $?
59
60 WVPASS [ "$size_before" -gt 5000000 ]
61 WVPASS [ "$size_after" -lt 50000 ]
62
63 WVPASS rm -r "$tmpdir/restore"
64 WVPASS bup restore -C "$tmpdir/restore" /src-1/latest
65 WVPASS compare-trees src-1/ "$tmpdir/restore/latest/"
66
67 WVPASS rm -r "$tmpdir/restore"
68 WVFAIL bup restore -C "$tmpdir/restore" /src-2/latest
69  
70
71 WVPASS mkdir src-ab-clean src-ab-clean/a src-ab-clean/b
72 WVPASS bup random 1k > src-ab-clean/a/1
73 WVPASS bup random 10M > src-ab-clean/b/1
74
75
76 WVSTART "gc (rewriting)"
77
78 WVPASS rm -rf "$BUP_DIR"
79 WVPASS bup init
80 WVPASS rm -rf src-ab
81 WVPASS cp -pPR src-ab-clean src-ab
82
83 WVPASS bup index src-ab
84 WVPASS bup save --strip -n src-ab src-ab
85 WVPASS bup index --clear
86 WVPASS bup index src-ab
87 WVPASS bup save -vvv --strip -n a src-ab/a
88
89 size_before=$(WVPASS data-size "$BUP_DIR") || exit $?
90 WVPASS rm "$BUP_DIR/refs/heads/src-ab"
91 WVPASS bup gc $GC_OPTS -v
92 size_after=$(WVPASS data-size "$BUP_DIR") || exit $?
93
94 WVPASS [ "$size_before" -gt 5000000 ]
95 WVPASS [ "$size_after" -lt 100000 ]
96
97 WVPASS rm -r "$tmpdir/restore"
98 WVPASS bup restore -C "$tmpdir/restore" /a/latest
99 WVPASS compare-trees src-ab/a/ "$tmpdir/restore/latest/"
100
101 WVPASS rm -r "$tmpdir/restore"
102 WVFAIL bup restore -C "$tmpdir/restore" /src-ab/latest
103
104
105 WVSTART "gc (save -r after repo rewriting)"
106
107 WVPASS rm -rf "$BUP_DIR"
108 WVPASS bup init
109 WVPASS bup -d bup-remote init
110 WVPASS rm -rf src-ab
111 WVPASS cp -pPR src-ab-clean src-ab
112
113 WVPASS bup index src-ab
114 WVPASS bup save -r :bup-remote --strip -n src-ab src-ab
115 WVPASS bup index --clear
116 WVPASS bup index src-ab
117 WVPASS bup save -r :bup-remote -vvv --strip -n a src-ab/a
118
119 size_before=$(WVPASS data-size bup-remote) || exit $?
120 WVPASS rm bup-remote/refs/heads/src-ab
121 WVPASS bup -d bup-remote gc $GC_OPTS -v
122 size_after=$(WVPASS data-size bup-remote) || exit $?
123
124 WVPASS [ "$size_before" -gt 5000000 ]
125 WVPASS [ "$size_after" -lt 100000 ]
126
127 WVPASS rm -rf "$tmpdir/restore"
128 WVPASS bup -d bup-remote restore -C "$tmpdir/restore" /a/latest
129 WVPASS compare-trees src-ab/a/ "$tmpdir/restore/latest/"
130
131 WVPASS rm -r "$tmpdir/restore"
132 WVFAIL bup -d bup-remote restore -C "$tmpdir/restore" /src-ab/latest
133
134 # Make sure a post-gc index/save that includes gc-ed data works
135 WVPASS bup index src-ab
136 WVPASS bup save -r :bup-remote --strip -n src-ab src-ab
137 WVPASS rm -r "$tmpdir/restore"
138 WVPASS bup -d bup-remote restore -C "$tmpdir/restore" /src-ab/latest
139 WVPASS compare-trees src-ab/ "$tmpdir/restore/latest/"
140
141
142 WVSTART "gc (bup on after repo rewriting)"
143
144 WVPASS rm -rf "$BUP_DIR"
145 WVPASS bup init
146 WVPASS rm -rf src-ab
147 WVPASS cp -pPR src-ab-clean src-ab
148
149 WVPASS bup on - index src-ab
150 WVPASS bup on - save --strip -n src-ab src-ab
151 WVPASS bup index --clear
152 WVPASS bup on - index src-ab
153 WVPASS bup on - save -vvv --strip -n a src-ab/a
154
155 size_before=$(WVPASS data-size "$BUP_DIR") || exit $?
156 WVPASS rm "$BUP_DIR/refs/heads/src-ab"
157 WVPASS bup gc $GC_OPTS -v
158 size_after=$(WVPASS data-size "$BUP_DIR") || exit $?
159
160 WVPASS [ "$size_before" -gt 5000000 ]
161 WVPASS [ "$size_after" -lt 100000 ]
162
163 WVPASS rm -r "$tmpdir/restore"
164 WVPASS bup restore -C "$tmpdir/restore" /a/latest
165 WVPASS compare-trees src-ab/a/ "$tmpdir/restore/latest/"
166
167 WVPASS rm -r "$tmpdir/restore"
168 WVFAIL bup restore -C "$tmpdir/restore" /src-ab/latest
169
170 # Make sure a post-gc index/save that includes gc-ed data works
171 WVPASS bup on - index src-ab
172 WVPASS bup on - save --strip -n src-ab src-ab
173 WVPASS rm -r "$tmpdir/restore"
174 WVPASS bup restore -C "$tmpdir/restore" /src-ab/latest
175 WVPASS compare-trees src-ab/ "$tmpdir/restore/latest/"
176
177
178 WVSTART "gc (threshold)"
179
180 WVPASS rm -rf "$BUP_DIR"
181 WVPASS bup init
182 WVPASS rm -rf src && mkdir src
183 WVPASS echo 0 > src/0
184 WVPASS echo 1 > src/1
185
186 WVPASS bup index src
187 WVPASS bup save -n src-1 src
188 WVPASS rm src/0
189 WVPASS bup index src
190 WVPASS bup save -n src-2 src
191
192 WVPASS bup rm --unsafe src-1
193 packs_before="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $?
194 WVPASS bup gc -v $GC_OPTS --threshold 99 2>&1 | tee gc.log
195 packs_after="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $?
196 WVPASSEQ 0 "$(grep -cE '^rewriting ' gc.log)"
197 WVPASSEQ "$packs_before" "$packs_after"
198
199 WVPASS bup gc -v $GC_OPTS --threshold 1 2>&1 | tee gc.log
200 packs_after="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $?
201 WVPASSEQ 1 "$(grep -cE '^rewriting ' gc.log)"
202
203 # Check that only one pack was rewritten
204
205 # Accommodate some systems that apparently used to change the default
206 # ls sort order which must match LC_COLLATE for comm to work.
207 packs_before="$(sort <(echo "$packs_before"))" || die $?
208 packs_after="$(sort <(echo "$packs_after"))" || die $?
209
210 only_in_before="$(comm -2 -3 <(echo "$packs_before") <(echo "$packs_after"))" \
211     || die $?
212
213 only_in_after="$(comm -1 -3 <(echo "$packs_before") <(echo "$packs_after"))" \
214     || die $?
215
216 in_both="$(comm -1 -2 <(echo "$packs_before") <(echo "$packs_after"))" || die $?
217
218 WVPASSEQ 1 $(echo "$only_in_before" | wc -l)
219 WVPASSEQ 1 $(echo "$only_in_after" | wc -l)
220 WVPASSEQ 1 $(echo "$in_both" | wc -l)
221
222 WVSTART "gc (threshold 0)"
223
224 WVPASS rm -rf "$BUP_DIR"
225 WVPASS bup init
226 WVPASS rm -rf src && mkdir src
227 WVPASS echo 0 > src/0
228 WVPASS echo 1 > src/1
229
230 WVPASS bup index src
231 WVPASS bup save -n src-1 src
232
233 packs_before="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $?
234 WVPASS bup gc -v $GC_OPTS --threshold 0 2>&1 | tee gc.log
235 packs_after="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $?
236 # Check that the pack was rewritten, but not removed (since the
237 # result-pack is equal to the source pack)
238 WVPASSEQ 1 "$(grep -cE '^rewriting ' gc.log)"
239 WVPASSEQ "$packs_before" "$packs_after"
240
241 WVPASS rm -rf "$tmpdir"