#!/bin/sh
#
# Pre-commit hook for scalableblog posts

# Read in parameters
REPOS="$1"
TXN="$2"

# Change to line-based processing
IFS="
"
# Examine files; the 'posts' is scalableblog specific
changes=`svnlook changed -t $TXN $REPOS | grep posts`
for change in $changes; do
	mod=`echo $change | awk '{print $1}'`
	file=`echo $change | awk '{print $2}'`
	svnlook diff -t $TXN $REPOS | filterdiff -i "$file" > ~/.precommit.diff
	svnlook cat $REPOS "$file" > ~/.precommit.cat

	# Apply the requested changes to files
	patch ~/.precommit.cat ~/.precommit.diff

	# Run XML validation and abort on error
	echo "<div>" > ~/.post.tmp.xml
	cat ~/.precommit.cat >> ~/.post.tmp.xml
	echo "</div>" >> ~/.post.tmp.xml

	xmllint ~/.post.tmp.xml || { echo "Invalid XML" >&2; exit 1; }
done

exit 0
