#!/bin/sh

DIR=$1
if [ x$DIR = "x" ]
then
	DIR="."
fi

if [ ! -d "${DIR}/.svn/" ]
then
	echo "0"
	exit ;
fi

REVISION="`svnversion $DIR 2> /dev/null | sed 's/[^0-9]*//g'`"

if [ x$REVISION = "x" ]
then
	REVISION="`svn info $DIR 2> /dev/null | grep -i revision | sed 's/[^0-9]*//g'`"
fi

if [ x$REVISION = "x" ]
then
	if [ -f "${DIR}/.svn/entries" ]
	then
		REVISION="`cat ${DIR}/.svn/entries | grep -i revision | head -n 1 | sed 's/[^0-9]*//g'`"
	fi
fi

if [ x$REVISION = "x" ]
then
	REVISION="-1"
fi

echo $REVISION
