#!/bin/sh # Goal: Show total versioned and unversioned size of local tree. # # Current status: shows total unversioned size in bytes in SVN trees # # TODO: # - This should work with more VCSs than just SVN. # - Should show the largest files, or all files over size N # - Should print output human-readably if [ ! -d ".git" -a ! -d ".svn" ]; then echo "ERROR: must be run from the top of a version-controlled tree" >&2 exit 1 fi if [ ! -d ".svn" ]; then echo "ERROR: er, actually, this only supports SVN right now, sorry" >&2 exit 1 fi echo "Gathering sizes..." TOTAL_BYTES=`du -s --block-size=1 | cut -f1` SAVED_IFS="${IFS}" IFS=' ' for name in `svn status | grep -E "^? " | cut -c9-`; do # ls --block-size=1 -s "${name}" stat -c "%s" "${name}" done > vsize-tmp-$$ IFS="${SAVED_IFS}" UNVERSIONED_BYTES=`awk '{ sum += $1 } END { print sum }' vsize-tmp-$$` VERSIONED_BYTES=`dc -e "${TOTAL_BYTES} ${UNVERSIONED_BYTES} - p"` # It would be interesting to compare $VERSIONED_BYTES as obtained via # the above method with calculating it from 'svn ls -vR' output (or # with whatever the equivalent in git is). BYTES_PER_MB=1048576 # old-style megabytes are (1024 * 1024) bytes TOTAL_MB=`dc -e "${TOTAL_BYTES} ${BYTES_PER_MB} / p"` UNVERSIONED_MB=`dc -e "${UNVERSIONED_BYTES} ${BYTES_PER_MB} / p"` VERSIONED_MB=`dc -e "${VERSIONED_BYTES} ${BYTES_PER_MB} / p"` echo "" echo "Sizes (MB == 1024x1024 bytes):" echo "" echo "Total size: ${TOTAL_MB} MB" echo "Versioned size: ${VERSIONED_MB} MB" echo "Unversioned size: ${UNVERSIONED_MB} MB" echo "" rm vsize-tmp-$$