Skip to content

Commit

Permalink
store credits in tree object
Browse files Browse the repository at this point in the history
This makes sure that the text does not show up directly when running
    git fsck --dangling | cut -d " " -f3 | xargs -n 1 git cat-file -p
  • Loading branch information
miallo committed Jan 16, 2024
1 parent 97e991d commit b53a9b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ------------------------------------------------------------------------------------------- #
Expand Down
4 changes: 2 additions & 2 deletions src/redeem-nuggit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b53a9b1

Please sign in to comment.