shopt -s nullglob
case "$DGIT_DRS_DEBUG" in
-''|0!1) ;;
+''|0|1) ;;
*) set -x ;;
esac
+fail () {
+ echo >&2 "dgit-mirror-rsync: $*"; exit 127
+}
+
+if [ $# -lt 2 ]; then fail "too few arguments"; fi
+
self=$0
+
+case "$self" in
+/*) ;;
+*/*) self="$PWD/$self" ;;
+*) ;;
+esac
+
distrodir=$1; shift
action=$1; shift
package=$1
hooktimeout=30
rsynctimeout=900
rsyncssh='ssh -o batchmode=yes'
+mirror_gc_cmd='git gc --auto'
. $distrodir/mirror-settings
cd $repos
queue=_mirror-queue
-fail () {
- echo >&2 "dgit-mirror-rsync: $*"; exit 127
-}
-
case "$remoterepos" in
*:/*|/*) ;;
'') fail "remoterepos config not set" ;;
esac
actually () {
+ if [ "x$mirror_gc_cmd" != x ]; then
+ (
+ cd "$repos/$package.git"
+ $mirror_gc_cmd
+ )
+ fi
"${rsync[@]}" \
--timeout=$rsynctimeout \
-e "$rsyncssh" \
exec \
"$@" \
- "$0" "$distrodir" "reinvoke$newaction" "$package"
+ "$self" "$distrodir" "reinvoke$newaction" "$package"
}
check-package-mirrorable () {
local repo=$repos/$package.git
- local mode=$(stat -c%a "$repo")
+ local mode; mode=$(stat -c%a "$repo")
case $mode in
*5) return 0 ;;
*0) return 1 ;;
}
attempt () {
- exec >"$queue/$package.err" 2>&1
+ exec 3>&2 >"$queue/$package.err" 2>&1
if actually; then
- rm "$queue/$package.a"
+ rm -f "$queue/$package.a"
+ exec 2>&3 2>&1
mv -f "$queue/$package.err" "$queue/$package.log"
+ if ! [ -s "$queue/$package.log" ]; then
+ rm "$queue/$package.log"
+ fi
rm "$queue/$package.lock"
else
- cat >&2 "$queue/$package.err"
+ cat >&3 "$queue/$package.err"
exit 127
fi
}
backlog)
for f in $queue/*.[na]; do
- lock-and-process-baseof-f
+ (lock-and-process-baseof-f ||:)
done
;;
all)
for f in [a-z0-9]*.git; do
- lock-and-process-baseof-f
+ (lock-and-process-baseof-f)
done
;;