forked from jwiegley/git-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-discover-large-blobs
executable file
·53 lines (44 loc) · 1.68 KB
/
git-discover-large-blobs
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
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
#
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# ChangeLog
#
# Originally by Antony Stubbs http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
#
# <javabrett>
# - Make command work when in the non-root directory of a repo, or from the top-level of a bare repo
#
# set the internal field separator to line break, so that we can iterate easily over the verify-pack output
IFS=$'\n';
# find top-level dir of a non-bare repo
_GIT_DIR=`git rev-parse --show-toplevel` || exit 1
if [ -n ${_GIT_DIR} ] && [ -d ${_GIT_DIR}/.git/objects/pack ]; then
PACK_DIR=${_GIT_DIR}/.git/objects/pack
elif [ -d ./objects/pack ]; then
# bare repo
PACK_DIR=./objects/pack
else
echo "Cannot locate pack directory"
exit 1
fi
# list all objects including their size, sort by size, take top 10
objects=`git verify-pack -v ${PACK_DIR}/pack-*.idx | grep -v chain | sort -k3nr | head`
echo "All sizes are in kB's. 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=`git rev-list --all --objects | grep $sha`
#lineBreak=`echo -e "\n"`
output="${output}\n${size},${compressedSize},${other}"
done
echo -e $output | column -t -s ', '