aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelley Spoon <kelley.spoon@linaro.org>2018-09-21 12:34:03 -0700
committerKelley Spoon <kelley.spoon@linaro.org>2018-09-26 05:30:24 -0500
commitabfb4176dd3213da8770c80bfff65e6a9065dbd0 (patch)
tree5c3ce9fc31efec5eeb5ede8b1bd0cb200b8ce559
parentbe3d3305674592947580e6820f544f34d0994442 (diff)
downloadlinaro-git-tools-abfb4176dd3213da8770c80bfff65e6a9065dbd0.tar.gz
GitCleaner: add script to clean git repos
Re SYS-146. Introduces a cron script that can be used to run git clean on repos and recover if the repo has too many loose git objects. Change-Id: Ic0f984b20e94ef655357b61546f28eb61adbaefb
-rwxr-xr-xgit_cleaner.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/git_cleaner.sh b/git_cleaner.sh
new file mode 100755
index 0000000..9ab8ddd
--- /dev/null
+++ b/git_cleaner.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+BASE=/srv/repositories
+
+for repo in $(find $BASE -type d -name "*.git");
+do
+ # the gc.log is a copy of the stderr created by a backgrounded
+ # gc process. It will block further git operations until removed
+ # but we need a chance to at least look at what it's complaining
+ # about first.
+ if [ -f ${repo}/gc.log ];
+ then
+ echo "WARNING: found ${repo}/gc.log"
+ cat ${repo}/gc.log
+ rm -f ${repo}/gc.log
+ fi
+
+ # check for dangling commits and orphans
+ if [ ! -z "$(git fsck --connectivity-only --no-progress)" ];
+ then
+ # this causes dangling refs to expire now and prunes
+ # them from the object pack. It's expensive, however,
+ # because we end up repacking the object files.
+ git reflog expire --expire=now --all
+ ionice -c2 -n7 git gc --prune=now --agressive
+ else
+ ionice -c2 -n7 git gc --auto
+ fi
+done