6 top="$(WVPASS pwd)" || exit $?
7 tmpdir="$(WVPASS wvmktempdir)" || exit $?
9 export BUP_DIR="$tmpdir/bup"
10 export GIT_DIR="$tmpdir/bup"
14 bup() { "$top/bup" "$@"; }
15 compare-trees() { "$top/t/compare-trees" "$@"; }
16 data-size() { "$top/t/data-size" "$@"; }
22 WVSTART "gc (unchanged repo)"
25 WVPASS bup random 1k > src-1/1
26 WVPASS bup index src-1
27 WVPASS bup save --strip -n src-1 src-1
29 WVPASS bup gc $GC_OPTS -v
31 WVPASS bup restore -C "$tmpdir/restore" /src-1/latest
32 WVPASS compare-trees src-1/ "$tmpdir/restore/latest/"
35 WVSTART "gc (unchanged, new branch)"
38 WVPASS bup random 10M > src-2/1
39 WVPASS bup index src-2
40 WVPASS bup save --strip -n src-2 src-2
42 WVPASS bup gc $GC_OPTS -v
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/"
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/"
53 WVSTART "gc (removed branch)"
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 $?
60 WVPASS [ "$size_before" -gt 5000000 ]
61 WVPASS [ "$size_after" -lt 50000 ]
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/"
67 WVPASS rm -r "$tmpdir/restore"
68 WVFAIL bup restore -C "$tmpdir/restore" /src-2/latest
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
76 WVSTART "gc (rewriting)"
78 WVPASS rm -rf "$BUP_DIR"
81 WVPASS cp -pPR src-ab-clean src-ab
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
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 $?
94 WVPASS [ "$size_before" -gt 5000000 ]
95 WVPASS [ "$size_after" -lt 100000 ]
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/"
101 WVPASS rm -r "$tmpdir/restore"
102 WVFAIL bup restore -C "$tmpdir/restore" /src-ab/latest
105 WVSTART "gc (save -r after repo rewriting)"
107 WVPASS rm -rf "$BUP_DIR"
109 WVPASS bup -d bup-remote init
111 WVPASS cp -pPR src-ab-clean src-ab
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
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 $?
124 WVPASS [ "$size_before" -gt 5000000 ]
125 WVPASS [ "$size_after" -lt 100000 ]
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/"
131 WVPASS rm -r "$tmpdir/restore"
132 WVFAIL bup -d bup-remote restore -C "$tmpdir/restore" /src-ab/latest
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/"
142 WVSTART "gc (bup on after repo rewriting)"
144 WVPASS rm -rf "$BUP_DIR"
147 WVPASS cp -pPR src-ab-clean src-ab
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
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 $?
160 WVPASS [ "$size_before" -gt 5000000 ]
161 WVPASS [ "$size_after" -lt 100000 ]
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/"
167 WVPASS rm -r "$tmpdir/restore"
168 WVFAIL bup restore -C "$tmpdir/restore" /src-ab/latest
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/"
178 WVSTART "gc (threshold)"
180 WVPASS rm -rf "$BUP_DIR"
182 WVPASS rm -rf src && mkdir src
183 WVPASS echo 0 > src/0
184 WVPASS echo 1 > src/1
187 WVPASS bup save -n src-1 src
190 WVPASS bup save -n src-2 src
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"
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)"
203 # Check that only one pack was rewritten
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 $?
210 only_in_before="$(comm -2 -3 <(echo "$packs_before") <(echo "$packs_after"))" \
213 only_in_after="$(comm -1 -3 <(echo "$packs_before") <(echo "$packs_after"))" \
216 in_both="$(comm -1 -2 <(echo "$packs_before") <(echo "$packs_after"))" || die $?
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)
222 WVSTART "gc (threshold 0)"
224 WVPASS rm -rf "$BUP_DIR"
226 WVPASS rm -rf src && mkdir src
227 WVPASS echo 0 > src/0
228 WVPASS echo 1 > src/1
231 WVPASS bup save -n src-1 src
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"
241 WVPASS rm -rf "$tmpdir"