diff --git a/build.sh b/build.sh index c8dd95d..26e8ee9 100755 --- a/build.sh +++ b/build.sh @@ -57,10 +57,12 @@ Have a free nuggit!" > .git/nuggits . "$DOCDIR/store_nuggits.sh" # register the nuggits in our "git database" (aka some loose objects) ALMOST_CREDITS_HASH="$(git hash-object -w "$DOCDIR/almost_credits.txt")" # for the final credits do a little rot13, just to make life a bit harder if anyone e.g. greps through the loose objects... -CREDITS_HASH="$(tr 'A-Za-z' 'N-ZA-Mn-za-m' < "$DOCDIR/credits.txt" | git hash-object -w --stdin)" +FINAL_CREDITS_HASH="$(tr 'A-Za-z' 'N-ZA-Mn-za-m' < "$DOCDIR/credits.txt" | git hash-object -w --stdin)" +CREDITS_TREE="$(printf "100644 blob %s almost\n100644 blob %s final\n" "$ALMOST_CREDITS_HASH" "$FINAL_CREDITS_HASH" | git mktree)" + NUMBER_OF_NUGGITS="$(wc -l <"$DOCDIR/nuggits")" -replace NUMBER_OF_NUGGITS ALMOST_CREDITS_HASH CREDITS_HASH NUGGIT_DESCRIPTION_TREE "$DOCDIR/redeem-nuggit.sh" > ./.git/redeem.nuggit +replace NUMBER_OF_NUGGITS CREDITS_TREE NUGGIT_DESCRIPTION_TREE "$DOCDIR/redeem-nuggit.sh" > ./.git/redeem.nuggit chmod a=rx ./.git/redeem.nuggit # ------------------------------------------------------------------------------------------- # diff --git a/src/redeem-nuggit.sh b/src/redeem-nuggit.sh index ea5c9c6..543f90e 100755 --- a/src/redeem-nuggit.sh +++ b/src/redeem-nuggit.sh @@ -27,11 +27,11 @@ git cat-file -e "$(already_redeemed "$nuggit" | git hash-object --stdin)" 2>/dev redeemed_nuggits="$(git rev-list --count nuggits)" redeemed_nuggits=$((redeemed_nuggits - already_redeemed)) -[ "$redeemed_nuggits" -ne $((NUMBER_OF_NUGGITS - 1 )) ] || git cat-file -p ALMOST_CREDITS_HASH; +[ "$redeemed_nuggits" -ne $((NUMBER_OF_NUGGITS - 1 )) ] || git cat-file -p CREDITS_TREE:almost; [ "$redeemed_nuggits" -ne $(( NUMBER_OF_NUGGITS + 0 )) ] || { git cat-file -e "$(git hash-object --stdin <<< "$((NUMBER_OF_NUGGITS - 1))" | git hash-object --stdin)" 2>/dev/null || { echo Noughty boy!; exit 1; } - git cat-file -p CREDITS_HASH | tr 'A-Za-z' 'N-ZA-Mn-za-m'; + git cat-file -p CREDITS_TREE:final | tr 'A-Za-z' 'N-ZA-Mn-za-m'; } git cat-file -p "$(already_redeemed "$nuggit" | git hash-object --stdin)" 2>/dev/null && exit