#!/bin/sh -efu

. shell-error
PROG='girar-recent-mtime'

usage()
{
	[ -z "$*" ] || message "$*"
	echo >&2 "usage: $PROG <repo_dir>"
	exit 1
}

if [ "${1-}" = '--help' ]; then
	usage
fi

[ "$#" -le 1 ] || usage 'Too many arguments.'
[ "$#" -ge 1 ] || usage 'Not enough arguments.'

repo_dir="$1"
[ -d "$repo_dir" ] ||
	fatal "Repository directory '$repo_dir' not exist"

mtime=
if [ -f "$repo_dir/recent_committer" ]; then
	mtime=$(stat -c %Y "$repo_dir/recent_committer")
elif [ -f "$repo_dir/info/refs" ]; then
	mtime=$(stat -c %Y "$repo_dir/info/refs")
else
	mtime=$(stat -c %Y "$repo_dir")
fi

printf '%s\t%s\n' "$repo_dir" "$mtime"
