Skip to content

Instantly share code, notes, and snippets.

@allixsenos
Created April 2, 2019 21:17
Show Gist options
  • Save allixsenos/55fd26c95b17727813c7f24133037f20 to your computer and use it in GitHub Desktop.
Save allixsenos/55fd26c95b17727813c7f24133037f20 to your computer and use it in GitHub Desktop.
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# Modified by Luka Kladaric <luka@noom.com>
# - cache the rev-list instead of pulling it up for each file
# - cache the top objects list, an expensive operation
# - no "drop cache" command, delete *.cache manually
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
IFS=$'\n';
GET_FILES=${1:-100} # default: 100 files
TOP_OBJECTS_CACHE="top_objects.cache"
REV_LIST_CACHE="rev_list.cache"
# cache a list of all objects including their size, sort by size
if [ ! -f $TOP_OBJECTS_CACHE ]
then
git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr > $TOP_OBJECTS_CACHE
rm $REV_LIST_CACHE
fi
# cache a list of all
if [ ! -f $REV_LIST_CACHE ]
then
git rev-list --all --objects > $REV_LIST_CACHE
fi
objects=`head -n $GET_FILES $TOP_OBJECTS_CACHE`
echo "All sizes are in kB. The pack column is the size of the object, compressed, inside the pack file."
output="size,pack,SHA,location"
for y in $objects
do
# extract the size in bytes
size=$((`echo $y | cut -f 5 -d ' '`/1024))
# extract the compressed size in bytes
compressedSize=$((`echo $y | cut -f 6 -d ' '`/1024))
# extract the SHA
sha=`echo $y | cut -f 1 -d ' '`
# find the objects location in the repository tree
other=`grep $sha $REV_LIST_CACHE`
output="${output}\n${size},${compressedSize},${other}"
done
echo -e $output | column -t -s ', '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment