+#!/bin/sh
+#
+# server-gc -- Run git-gc on each git repository found within the provided
+# filesystem directory tree. Useful for shared on-server repos that don't
+# automatically do gc operations. This script was first posted at
+# http://groups.google.com/group/repo-discuss/web/repository-repacking
+#
+# NOTE: THIS UTILITY DOES NOT REALLY APPEAR TO BE NEEDED.
+
+if [ $(whoami) != "root" ]; then
+ echo "usage: $0 must be ran as root" >&2
+ exit 1
+fi
+
+TOP=$1
+if [ ! -d "$TOP" ]; then
+ echo "usage: $0 <topdir>>" >&2
+ exit 1
+fi
+
+cd $TOP
+for p in $(find . -type d -name \*.git | sed 's,^./,,')
+do
+ d=$TOP/$p
+ echo
+ echo "*** Repository $d ***"
+
+ git --git-dir=$d config repack.usedeltabaseoffset true
+ git --git-dir=$d config pack.compression 9
+ git --git-dir=$d config pack.indexversion 2
+
+ git --git-dir=$d config gc.autopacklimit 4
+ git --git-dir=$d config gc.packrefs true
+ git --git-dir=$d config gc.reflogexpire never
+ git --git-dir=$d config gc.reflogexpireunreachable never
+
+ case $p in
+ kernel/lk.git)
+ : use defaults
+ ;;
+ kernel/*)
+ git --git-dir=$d config pack.threads 6
+ git --git-dir=$d config pack.window 250
+ git --git-dir=$d config pack.depth 50
+ ;;
+ esac
+
+ rm -rf $d/logs/refs/changes 2>/dev/null
+
+ git --git-dir=$d gc --auto --aggressive --prune || break
+
+ (find $d/refs/changes -type d | xargs rmdir;
+ find $d/refs/changes -type d | xargs rmdir
+ ) 2>/dev/null
+done