#!/bin/sh

# (c) by Bernd Gloss
# gbernd@gmx.de
# no waranty, this script has no purpose and it is known to have bugs.

UNIX_ORIGIN_OF_TIME="1970-01-01 UTC"

# find the latest local modification time (or 0 if no local file is modified)
mod_time_local=0;
if [ "`svn status | wc -l`" -gt 0 ]; then
	mod_time_local="`svn status | grep "^M" | cut -c 8- | grep -v \"/$\" | xargs ls -t 2>/dev/null | head -n1 | xargs date +%s -r`"
fi
echo "latest local modification: `date -d \"${UNIX_ORIGIN_OF_TIME} + ${mod_time_local} seconds\"`"

# find the repository modification date (date of the root directory)
mod_time_repository_string="`svn info . | grep \"^Last Changed Date:\" | sed -e \"s/^Last Changed Date:[[:space:]]*//\" -e \"s/(.*//\"`"
mod_time_repository="`date +\"%s\" -d \"${mod_time_repository_string}\"`"
echo "latest repository modification: `date -d \"${UNIX_ORIGIN_OF_TIME} + ${mod_time_repository} seconds\"`"

# determine the latest modification date
if [ "${mod_time_local}" -gt "${mod_time_repository}" ]; then
	mod_time="${mod_time_local}";
else
	mod_time="${mod_time_repository}";
fi
echo "latest modification: `date -d \"${UNIX_ORIGIN_OF_TIME} + ${mod_time} seconds\"`"
