From: Rob Browning Date: Sat, 16 Jul 2016 16:33:30 +0000 (-0500) Subject: gc: actually allow --threshold arg X-Git-Tag: 0.29-rc1~36 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=931ed838ab9d18d50acc01a7e54f9c13017bc62f;p=bup.git gc: actually allow --threshold arg Thanks to Andrew Skretvedt for reporting the problem. Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/cmd/gc-cmd.py b/cmd/gc-cmd.py index a95f8f6..90874c3 100755 --- a/cmd/gc-cmd.py +++ b/cmd/gc-cmd.py @@ -50,7 +50,7 @@ optspec = """ bup gc [options...] -- v,verbose increase log output (can be used more than once) -threshold only rewrite a packfile if it's over this percent garbage [10] +threshold= only rewrite a packfile if it's over this percent garbage [10] #,compress= set compression level to # (0-9, 9 is highest) [1] unsafe use the command even though it may be DANGEROUS """ diff --git a/t/test-gc.sh b/t/test-gc.sh index 0119f46..f305954 100755 --- a/t/test-gc.sh +++ b/t/test-gc.sh @@ -175,4 +175,39 @@ WVPASS bup restore -C "$tmpdir/restore" /src-ab/latest WVPASS compare-trees src-ab/ "$tmpdir/restore/latest/" +WVSTART "gc (threshold)" + +WVPASS rm -rf "$BUP_DIR" +WVPASS bup init +WVPASS rm -rf src && mkdir src +WVPASS echo 0 > src/0 +WVPASS echo 1 > src/1 + +WVPASS bup index src +WVPASS bup save -n src-1 src +WVPASS rm src/0 +WVPASS bup index src +WVPASS bup save -n src-2 src + +WVPASS bup rm --unsafe src-1 +packs_before="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $? +WVPASS bup gc -v $GC_OPTS --threshold 99 2>&1 | tee gc.log +packs_after="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $? +WVPASSEQ 0 "$(grep -cE '^rewriting ' gc.log)" +WVPASSEQ "$packs_before" "$packs_after" + +WVPASS bup gc -v $GC_OPTS --threshold 1 2>&1 | tee gc.log +packs_after="$(ls "$BUP_DIR/objects/pack/"*.pack)" || exit $? +WVPASSEQ 1 "$(grep -cE '^rewriting ' gc.log)" + +# Check that only one pack was rewritten +only_in_before="$(comm -2 -3 <(echo "$packs_before") <(echo "$packs_after"))" +only_in_after="$(comm -1 -3 <(echo "$packs_before") <(echo "$packs_after"))" +in_both="$(comm -1 -2 <(echo "$packs_before") <(echo "$packs_after"))" + +WVPASSEQ 1 $(echo "$only_in_before" | wc -l) +WVPASSEQ 1 $(echo "$only_in_after" | wc -l) +WVPASSEQ 1 $(echo "$in_both" | wc -l) + + WVPASS rm -rf "$tmpdir"