Skip to content

Commit 0abdfec

Browse files
committed
Merge pull request jwiegley#25 from javabrett/git-discover-large-blobs-bare-or-anywhere
Make command work when in the non-root directory of a repo, or from t…
2 parents 74eac86 + f0eb80d commit 0abdfec

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

git-discover-large-blobs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,33 @@
55
#
66
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
77
# @author Antony Stubbs
8+
# ChangeLog
9+
#
10+
# Originally by Antony Stubbs http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
11+
#
12+
# <javabrett>
13+
# - Make command work when in the non-root directory of a repo, or from the top-level of a bare repo
14+
#
15+
816

917
# set the internal field separator to line break, so that we can iterate easily over the verify-pack output
1018
IFS=$'\n';
1119

20+
# find top-level dir of a non-bare repo
21+
_GIT_DIR=`git rev-parse --show-toplevel` || exit 1
22+
23+
if [ -n ${_GIT_DIR} ] && [ -d ${_GIT_DIR}/.git/objects/pack ]; then
24+
PACK_DIR=${_GIT_DIR}/.git/objects/pack
25+
elif [ -d ./objects/pack ]; then
26+
# bare repo
27+
PACK_DIR=./objects/pack
28+
else
29+
echo "Cannot locate pack directory"
30+
exit 1
31+
fi
32+
1233
# list all objects including their size, sort by size, take top 10
13-
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
34+
objects=`git verify-pack -v ${PACK_DIR}/pack-*.idx | grep -v chain | sort -k3nr | head`
1435

1536
echo "All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file."
1637

0 commit comments

Comments
 (0)