Skip to content

Instantly share code, notes, and snippets.

@za3k
Created May 4, 2017 19:06
Show Gist options
  • Save za3k/ba966cd443146214b5fb884c86448987 to your computer and use it in GitHub Desktop.
Save za3k/ba966cd443146214b5fb884c86448987 to your computer and use it in GitHub Desktop.
Print the size breakdown of git objects
#!/bin/sh
NUMFORMAT=cat
for program in numfmt gnumfmt
do
if which "${program}" 2>/dev/null >/dev/null
then
NUMFORMAT="${program} --to=si"
break
fi
done
echo "Size of actual bare repo (objects and packfiles): " && du -sh .git/objects .git
for type in tree blob tag commit
do
DISK=$(git cat-file --batch-all-objects --batch-check="%(objectname) %(objecttype) %(objectsize:disk)" | grep ${type} | cut -f 3 -d' ' | awk '{s+=$1} END {print s}' | ${NUMFORMAT})
THEORY=$(git cat-file --batch-all-objects --batch-check="%(objectname) %(objecttype) %(objectsize)" | grep ${type} | cut -f 3 -d' ' | awk '{s+=$1} END {print s}' | ${NUMFORMAT})
printf "Size of %+7s: %+4s (disk) %+4s (expanded)\n" ${type}s ${DISK} ${THEORY}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment