#!/bin/sh

CLASS=scripts
INSTANCE=@
FULL=0

OPTS=$(getopt -o c:i:f -l class:,instance:,full -n "$0" -- "$@") || exit $?
eval set -- "$OPTS"
while :; do
    case "$1" in
	-c|--class) CLASS=$2; shift 2;;
	-i|--instance) INSTANCE=$2; shift 2;;
	-f|--full) FULL=1; shift;;
	--) shift; break;;
	*) exit 1;;
    esac
done
[ $# -ge 2 ] || exit 1
REPOS=$1
REV=$2

if [ "$INSTANCE" = "${INSTANCE%@}@" ]; then
    INSTANCE=${INSTANCE%@}r$REV
fi

dirs=$(svnlook dirs-changed "$REPOS" -r "$REV")
svnlook info "$REPOS" -r "$REV" | (
    read -r author
    read -r datestamp
    read -r logsize
    log=$(cat)
    echo "r$REV by $author $datestamp"
    echo "$log"
    svnlook changed "$REPOS" -r "$REV"
    if [ "$FULL" -eq 1 ]; then
	echo
	svnlook diff "$REPOS" -r "$REV"
    else
	echo svnlook diff "$REPOS" -r "$REV"
    fi
) | zwrite -d -c "$CLASS" -i "$INSTANCE" -s "r$REV - $dirs"
