|
1 | 1 | #!/usr/bin/env bash
|
2 |
| -#set -x |
| 2 | +#set -x |
3 | 3 |
|
4 | 4 | # Shows you the largest objects in your repo's pack file.
|
5 | 5 | #
|
|
18 | 18 | IFS=$'\n';
|
19 | 19 |
|
20 | 20 | # find top-level dir of a non-bare repo
|
21 |
| -_GIT_DIR=`git rev-parse --show-toplevel` || exit 1 |
| 21 | +_GIT_DIR=$(git rev-parse --show-toplevel) || exit 1 |
22 | 22 |
|
23 |
| -if [ -n ${_GIT_DIR} ] && [ -d ${_GIT_DIR}/.git/objects/pack ]; then |
| 23 | +if [ -n "${_GIT_DIR}" ] && [ -d "${_GIT_DIR}"/.git/objects/pack ]; then |
24 | 24 | PACK_DIR=${_GIT_DIR}/.git/objects/pack
|
25 | 25 | elif [ -d ./objects/pack ]; then
|
26 | 26 | # bare repo
|
|
29 | 29 | echo "Cannot locate pack directory"
|
30 | 30 | exit 1
|
31 | 31 | fi
|
32 |
| - |
| 32 | + |
33 | 33 | # list all objects including their size, sort by size, take top 10
|
34 |
| -objects=`git verify-pack -v ${PACK_DIR}/pack-*.idx | grep -v chain | sort -k3nr | head` |
| 34 | +objects=$(git verify-pack -v "${PACK_DIR}"/pack-*.idx | grep -v chain | sort -k3nr | head) |
35 | 35 |
|
36 | 36 | echo "All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file."
|
37 | 37 |
|
38 | 38 | output="size,pack,SHA,location"
|
39 | 39 | for y in $objects
|
40 | 40 | do
|
41 | 41 | # extract the size in bytes
|
42 |
| - size=$((`echo $y | cut -f 5 -d ' '`/1024)) |
| 42 | + size=$(($(echo $y | cut -f 5 -d ' ')/1024)) |
43 | 43 | # extract the compressed size in bytes
|
44 |
| - compressedSize=$((`echo $y | cut -f 6 -d ' '`/1024)) |
| 44 | + compressedSize=$(($(echo $y | cut -f 6 -d ' ')/1024)) |
45 | 45 | # extract the SHA
|
46 |
| - sha=`echo $y | cut -f 1 -d ' '` |
| 46 | + sha=$(echo $y | cut -f 1 -d ' ') |
47 | 47 | # find the objects location in the repository tree
|
48 |
| - other=`git rev-list --all --objects | grep $sha` |
| 48 | + other=$(git rev-list --all --objects | grep "$sha") |
49 | 49 | #lineBreak=`echo -e "\n"`
|
50 | 50 | output="${output}\n${size},${compressedSize},${other}"
|
51 | 51 | done
|
52 | 52 |
|
53 |
| -echo -e $output | column -t -s ', ' |
| 53 | +echo -e "$output" | column -t -s ', ' |
0 commit comments