-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgit-repo.size
executable file
·58 lines (46 loc) · 1.86 KB
/
git-repo.size
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see https://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
IFS=$'\n';
# list all objects including their size, sort by size, take top 10 (or 1st provided argument)
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | egrep -v 'chain|non delta: ' | sort -k3nr 2>/dev/null | head -n ${1:-10}`
echo "The pack column is the size of the object, compressed, inside the pack file."
#? set -x
i=0
echo "size,pack,SHA,location" | column -t -s ', '
for obj in $objects
do
# extract the size in bytes
sizeStr=$( echo $obj | cut -f 5 -d ' ' )
if [ -z "$sizeStr" ]; then
echo "ERROR! Size is empty! Incoming line: [$obj]"
continue;
fi
size=$( numfmt --to=iec-i --suffix=B --format="%.3f" $sizeStr )
# extract the compressed size in bytes
compressedSizeStr=$(echo $obj | cut -f 6 -d ' ')
if [ -z "$compressedSizeStr" ]; then continue; fi
compressedSize=$( numfmt --to=iec-i --suffix=B --format="%.3f" ${compressedSizeStr:-0} )
# extract the SHA
sha=$( echo $obj | cut -f 1 -d ' ' )
# find the objects location in the repository tree
filename=$( git rev-list --all --objects | grep $sha )
# output="${output}\n${size},${compressedSize},${other}"
# Some reconds has no name (tree??). We skip them.
if [ "$sha" = "$filename" ] || [ "$sha " = "$filename" ]; then continue; fi
echo -e "${size},${compressedSize},${filename}" | column -t -s ', '
# echo -e "${size},${compressedSize},=${filename}=,=$sha="
# | column -t -s ', '
if [ 0 -eq $(( ++i % 50 )) ]; then
:
# Debug progress each 50 items
# echo $i 1>&2
fi
done
echo "Total files: $i" 1>&2
#echo -e $output | column -t -s ', '