elixir/utils/pack-repositories
2020-05-23 15:14:21 -04:00

48 lines
1.6 KiB
Bash
Executable file

#!/bin/sh
#
# Goes through all git repositories in the current directory
# and runs "git prune" and "git gc --aggressive" to pack
# objects very efficiently and reduce size sometimes dramatically
#
# Works by finding the repositories which have a gc.log
# file, indicating that git garbage collection failed at some
# point, causing the repository to grow very fast
# each time new objects are fetched.
#
# Example: llvm-project: divided disk usage by 60!
# This file is part of Elixir, a source code cross-referencer.
#
# Copyright (C) 2019--2020 Michael Opdenacker and contributors
#
# Elixir is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Elixir is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.
for f in `find . -name gc.log`
do
d=`dirname $f`
echo "Processing: $d"
cd $d
echo -n "Initial size: "
echo `du -sh .`
rm -f gc.log
git prune
git gc --aggressive
echo -n "Size after first pass: "
echo `du -sh .`
git prune
git gc --aggressive
echo -n "Size after second pass: "
echo `du -sh .`
cd ..
done