]> git.donarmstrong.com Git - bin.git/blobdiff - git-hogs
use cat-file instead
[bin.git] / git-hogs
index be521c551f069d1bb208f56be871aec435502d15..c74f628cda6588d47090768dc2d4cf53c8acd5fa 100755 (executable)
--- a/git-hogs
+++ b/git-hogs
@@ -7,23 +7,25 @@
 
 # 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
+# list all objects with size first; sort, and take the top 10.
+
+NUM="${1:-10}"
 
 ALL_OBJECTS=`git rev-list --all --objects`
-OBJECTS=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
+OBJECTS=`git cat-file --batch-check='%(objectsize) %(objectsize:disk) %(objectname) %(objecttype)' --batch-all-objects|grep blob| sort -nr | head -n $NUM`
 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)
+       SIZE=$(echo "$y" | cut -f 1 -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)
+       COMPRESSED_SIZE=$(echo "$y" | cut -f 2 -d ' '|numfmt --to=iec)
        # extract the SHA
-       SHA=`echo $y | cut -f 1 -d ' '`
+       SHA=`echo $y | cut -f 3 -d ' '`
        # find the objects location in the repository tree
-       OTHER=`echo "$ALL_OBJECTS" | grep "$SHA"`
-       OUTPUT="${OUTPUT}\n${SIZE},${COMPRESSED_SIZE},${OTHER}"
+       OTHER=`echo "$ALL_OBJECTS" | grep "$SHA"|cut -f2 -d ' '`
+       OUTPUT="${OUTPUT}\n${SIZE},${COMPRESSED_SIZE},${SHA},${OTHER}"
 done
 
 echo -e $OUTPUT | column -t -s ', '