Skip to content

Commit a2aa9db

Browse files
committed
Added calculation for disk size saved
1 parent 1208fd1 commit a2aa9db

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

repo-converter/build/sg_maintenance.sh

+19-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
# -u Exit if a variable is referenced before assigned
4646
# -x Print out commands before they are executed
4747
# -o pipefail Include non-zero exit codes, even if a command piped into another command fails
48-
set -euxo pipefail
48+
# -o pipefail seems to cause all piping to fail
49+
#set -euxo pipefail
50+
set -eux
4951

5052
# Get the repo's root directory as the first parameter
5153
# Assumes this directory has a .git subdirectory
@@ -74,6 +76,7 @@ cd "$REPOSITORY_DIRECTORY"
7476
# Print the sizes of files in the repo's directory
7577
echo "Sizes in the repo's .git directory, before garbage collection:"
7678
du -sc .git/*
79+
start_size="$(du -s .git | awk '{print $1}')"
7780

7881
# Track files to be cleaned up on exit
7982
declare -a files_to_cleanup
@@ -229,8 +232,11 @@ git pack-refs --all --prune
229232
# Continue the script if this command fails
230233
set +e
231234
# Try to get the git config values, if they exist
232-
git config get gc.reflogExpire
233-
git config get gc.reflogExpireUnreachable
235+
# If they don't exist, git config returns a non-zero exit code
236+
reflogExpire=$(git config get gc.reflogExpire)
237+
reflogExpireUnreachable=$(git config get gc.reflogExpireUnreachable)
238+
echo "gc.reflogExpire: $reflogExpire"
239+
echo "gc.reflogExpireUnreachable: $reflogExpireUnreachable"
234240
# Revert back to the previous Bash options
235241
set -e
236242
#
@@ -290,7 +296,7 @@ git repack -d -A --unpack-unreachable=now --write-bitmap-index -l --window-memor
290296
git commit-graph write --reachable --changed-paths --progress
291297

292298
# Reset Bash option for pipefail, because it seems to break piping git | head
293-
set +o pipefail
299+
# set +o pipefail
294300

295301
# Test if the repo is corrupted
296302
git show HEAD | head -n 1
@@ -301,4 +307,13 @@ git log --all | head -n 1
301307
# Print the sizes of files in the repo's directory
302308
echo "Sizes in the repo's .git directory, after garbage collection:"
303309
du -sc .git/*
310+
311+
# Subtract 4 KB for the lock files which haven't been removed yet
312+
end_size="$(du -s .git | awk '{print $1}')"
313+
end_size="$((end_size - 4))"
314+
315+
echo "Repo $REPOSITORY_DIRECTORY"
316+
echo "Size before garbage collection: $start_size KB"
317+
echo "Size after garbage collection: $end_size KB"
318+
echo "Storage saved: $((start_size - end_size)) KB"
304319
###############################################################################

0 commit comments

Comments
 (0)