| 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 | bup() { "$top/bup" "$@"; } |
| 13 | |
| 14 | # In the past, gc treated all objects probabilistically (including |
| 15 | # trees and commits). This meant that it could leave tree fragments |
| 16 | # after a collection if the tree were split across packfiles and gc |
| 17 | # decided (based on the --threshold) to remove any of the packfiles |
| 18 | # containing children while keeping packfiles containing any of the |
| 19 | # parents. Other commands could then decide to re-use these |
| 20 | # incomplete trees without noticing that they still needed to fill in |
| 21 | # the holes. This is particularly easy to reproduce via get, which we |
| 22 | # do here. |
| 23 | |
| 24 | WVPASS cd "$tmpdir" |
| 25 | WVPASS bup init |
| 26 | |
| 27 | # Create a save that has two packfiles. The first contains mostly |
| 28 | # data we're going to drop and part of a smaller "straddle" tree we're |
| 29 | # going to keep. The second contains the rest of the straddle tree |
| 30 | # (including the "top"), and a much larger "hold" tree we're going to |
| 31 | # keep. |
| 32 | WVPASS git config pack.packSizeLimit 1000k |
| 33 | WVPASS mkdir -p src/{1-hold,2-straddle,3-transient} |
| 34 | WVPASS bup random -S 1 945k > src/3-transient/data |
| 35 | WVPASS bup random -S 2 100k > src/2-straddle/data |
| 36 | WVPASS bup random -S 3 945k > src/1-hold/data |
| 37 | WVPASS bup index src |
| 38 | WVPASS bup save -vv --strip -n src src |
| 39 | |
| 40 | (cd bup/objects/pack && ls -lrth *.pack) |
| 41 | |
| 42 | packs=($(cd bup/objects/pack && ls -rt *.pack)) |
| 43 | WVPASSEQ "${#packs[@]}" 2 |
| 44 | |
| 45 | transient_oid="$(WVPASS git rev-parse src:3-transient)" || exit $? |
| 46 | straddle_oid="$(WVPASS git rev-parse src:2-straddle)" || exit $? |
| 47 | hold_oid="$(WVPASS git rev-parse src:1-hold)" || exit $? |
| 48 | |
| 49 | WVPASS git show-index < bup/objects/pack/"$(basename ${packs[0]} .pack).idx" \ |
| 50 | | WVPASS grep -F "$transient_oid" |
| 51 | |
| 52 | WVPASS git show-index < bup/objects/pack/"$(basename ${packs[1]} .pack).idx" \ |
| 53 | | WVPASS grep -F "$straddle_oid" |
| 54 | |
| 55 | WVPASS git show-index < bup/objects/pack/"$(basename ${packs[1]} .pack).idx" \ |
| 56 | | WVPASS grep -F "$hold_oid" |
| 57 | |
| 58 | # Keep a safe copy of src in another repo |
| 59 | WVPASS bup -d bup-complete init |
| 60 | WVPASS bup save -r :bup-complete --strip -n src src |
| 61 | |
| 62 | # Promote hold to its own branch so we can drop everything else and gc |
| 63 | WVPASS bup get --append: src/latest/1-hold hold |
| 64 | WVPASS bup rm --unsafe src |
| 65 | WVPASS bup gc --unsafe -v --threshold 10 |
| 66 | |
| 67 | # Fetch src back from the safe copy via get. Because the pack with an |
| 68 | # internal part of straddle was dropped, the pack with hold (that was |
| 69 | # kept) has an incomplete straddle tree; get will happily re-use that |
| 70 | # when creating the local src without noticing it's incomplete, |
| 71 | # creating a broken src. |
| 72 | WVPASS bup get -s bup-complete --append src |
| 73 | WVPASS bup join "$(git rev-parse src)" > /dev/null |
| 74 | |
| 75 | WVPASS rm -rf "$tmpdir" |