forked from msysgit/msysgit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhat-made-this-repo-so-large.sh
executable file
·46 lines (40 loc) · 1.15 KB
/
what-made-this-repo-so-large.sh
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
#!/bin/sh
# This script tries to find out what made your repository so large.
# It sorts the loose and packed objects by size (for packed objects, we look
# at the size in the pack) and shows the largest ten.
die () {
echo "$*" >&2
exit 1
}
identify_object () {
LINES="$(git log --root --raw --abbrev=40 --all --format="commit %H" |
grep -e '^commit' -e "^:[^ ]* [^ ]* [^ ]* $1" |
grep -m1 -B1 "^:[^ ]* [^ ]* [^ ]* $1")"
if test -n "$LINES"
then
COMMIT="$(git name-rev $(echo "$LINES" |
sed -n 's/commit //p') |
sed 's/^[^ ]* //')"
PATH="$(echo "$LINES" | sed -n 's/^.* //p')"
printf "'%s:%s'" $COMMIT "$PATH"
fi
}
N=10
test $# -gt 0 && N=$1
GIT_DIR="$(git rev-parse --git-dir)" || die "No repository found"
OBJECT_LIST="$( (cd "$GIT_DIR" &&
ls -l objects/??/* |
sed 's/^\([^ ]* *\)\{4\}\([^ ]*\).* objects\/\(..\)\/\(.\{38\}\)$/\2 \3\4/' &&
for pack in "$(ls objects/pack/*.pack 2> /dev/null)"
do
git verify-pack -v "$pack" 2>&1 |
sed -n 's/^\([^ ]\{40\}\) *[^ ]* *[^ ]* *\([1-9][0-9]*\).*$/\2 \1/p'
done) |
sort -n -r |
uniq |
head -n "$N")"
echo "$OBJECT_LIST" |
while read size sha1
do
echo $size $sha1 "$(identify_object $sha1)"
done