]> arthur.barton.de Git - bup.git/commitdiff
gc: actually allow --threshold arg
authorRob Browning <rlb@defaultvalue.org>
Sat, 16 Jul 2016 16:33:30 +0000 (11:33 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 17 Jul 2016 16:59:20 +0000 (11:59 -0500)
Thanks to Andrew Skretvedt for reporting the problem.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/gc-cmd.py
t/test-gc.sh

index a95f8f63416d1ccec84f37eb303a9e7fcc92ae02..90874c3ee03009c1ac29fea8c35014b7d65384df 100755 (executable)
@@ -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
 """
index 0119f467048f54b58161ebef61055bb59858e851..f3059549921a50267cad47c84b8f6143efae1fa8 100755 (executable)
@@ -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"