]> git.donarmstrong.com Git - bin.git/commitdiff
add git-hogs command
authorDon Armstrong <don@donarmstrong.com>
Wed, 10 May 2017 18:59:10 +0000 (11:59 -0700)
committerDon Armstrong <don@donarmstrong.com>
Wed, 10 May 2017 18:59:10 +0000 (11:59 -0700)
git-hogs [new file with mode: 0755]

diff --git a/git-hogs b/git-hogs
new file mode 100755 (executable)
index 0000000..be521c5
--- /dev/null
+++ b/git-hogs
@@ -0,0 +1,29 @@
+#!/bin/bash
+#set -x 
+
+
+# The original genesis for this came from
+# http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/ Antony Stubbs
+
+# Modified to use numfmt and only call rev-list once by Don Armstrong
+
+# list all objects including their size, sort by size, take top 10
+
+ALL_OBJECTS=`git rev-list --all --objects`
+OBJECTS=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
+IFS=$'\n'
+OUTPUT="Size,Packed,SHA1,Name";
+for y in $OBJECTS
+do
+       # the size is in the 5th field; convert to IEC
+       SIZE=$(echo "$y" | cut -f 5 -d ' '|numfmt --to=iec)
+       # the compressed size is in the 6th field; convert to IEC
+       COMPRESSED_SIZE=$(echo "$y" | cut -f 6 -d ' '|numfmt --to=iec)
+       # extract the SHA
+       SHA=`echo $y | cut -f 1 -d ' '`
+       # find the objects location in the repository tree
+       OTHER=`echo "$ALL_OBJECTS" | grep "$SHA"`
+       OUTPUT="${OUTPUT}\n${SIZE},${COMPRESSED_SIZE},${OTHER}"
+done
+
+echo -e $OUTPUT | column -t -s ', '