Commit f7d42753 authored by Damyan Ivanov's avatar Damyan Ivanov

gc: add -p option, running 'git gc' via 'parallel', utilising all available CPUs

parent efddd554
......@@ -82,6 +82,7 @@ Suggests: bc,
cdbs,
duck,
moreutils,
parallel,
perl-depends,
python,
python-launchpadlib
......
......@@ -13,8 +13,9 @@ usage() {
STATS=
VERBOSE=
HAVE_BC=
PARALLEL=
while getopts vsh opt; do
while getopts vshp opt; do
case $opt in
h) usage;;
s) STATS=1
......@@ -24,6 +25,13 @@ while getopts vsh opt; do
echo "W: 'bc' not available, stats will use byte units" >&2
fi
;;
p)
if which parallel > /dev/null ; then
PARALLEL=1
else
echo "W: 'parallel' not available, wil run sequentially" >&2
fi
;;
v) VERBOSE=1;;
?) usage;;
esac
......@@ -37,7 +45,7 @@ cd "${DPT_PACKAGES:?}"
if [ -n "$HAVE_BC" ]; then
calc() {
( echo "scale=1"; echo "$@" ) | bc
( echo "scale=1"; echo "$@" ) | LC_ALL=C bc
}
else
calc() {
......@@ -65,38 +73,44 @@ human() {
fi
}
TOTAL_BEFORE=0
TOTAL_AFTER=0
for d in `find . -maxdepth 1 -type d`; do
[ -d "$d/.git" ] || continue
if [ -n "$STATS" ]; then
TOTAL_BEFORE=$(find . -maxdepth 2 -type d -name .git -print0 | du -sbP --total --files0-from=- | tail -1 | cut -f1)
fi
if [ -n "$VERBOSE" ]; then
echo -n "`basename $d`"
fi
if [ -n "$STATS" ]; then
BEFORE=`du -sbP $d/.git | cut -f1`
TOTAL_BEFORE=$(( $TOTAL_BEFORE + $BEFORE ))
fi
GIT_DIR="$d/.git" git gc --quiet
if [ -n "$STATS" ]; then
AFTER=`du -sbP $d/.git | cut -f1`
TOTAL_AFTER=$(( $TOTAL_AFTER + $AFTER ))
fi
if [ -n "$VERBOSE" ]; then
echo -n " done."
if [ -n "$PARALLEL" ]; then
find . -maxdepth 2 -type d -name .git | \
parallel --will-cite sh -c "GIT_DIR='{}' git gc --quiet"
else
for d in `find . -maxdepth 1 -type d`; do
[ -d "$d/.git" ] || continue
if [ -n "$VERBOSE" ]; then
echo -n "`basename $d`"
fi
if [ -n "$STATS" ]; then
printf " %s -> %s (-%s, %0.1f%%)" \
`human $BEFORE` `human $AFTER` \
`human $(( $BEFORE - $AFTER ))` \
`calc "100*($BEFORE-$AFTER)/$BEFORE"`
BEFORE=`du -sbP $d/.git | cut -f1`
fi
echo
fi
done
GIT_DIR="$d/.git" git gc --quiet
if [ -n "$STATS" ]; then
AFTER=`du -sbP $d/.git | cut -f1`
fi
if [ -n "$VERBOSE" ]; then
echo -n " done."
if [ -n "$STATS" ]; then
printf " %s -> %s (-%s, %0.1f%%)" \
`human $BEFORE` `human $AFTER` \
`human $(( $BEFORE - $AFTER ))` \
`calc "100*($BEFORE-$AFTER)/$BEFORE"`
fi
echo
fi
done
fi
if [ -n "$STATS" ]; then
TOTAL_AFTER=$(find . -maxdepth 2 -type d -name .git -print0 | du -sbP --total --files0-from=- | tail -1 | cut -f1)
GAIN=$(( $TOTAL_BEFORE - $TOTAL_AFTER ))
printf "Total disk usage: %s -> %s (-%s, %0.1f%%)" \
printf "Total disk usage: %s -> %s (-%s, %0.1f%%)\n" \
`human $TOTAL_BEFORE` `human $TOTAL_AFTER` \
`human $GAIN` \
`calc "100*($GAIN)/$TOTAL_BEFORE"`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment