From: Jonas Fonseca Date: Sun, 11 Dec 2005 18:31:07 GMT Subject: [PATCH] cg-object-id: use git-rev-parse(1) for date parsing Message-ID: <20051211183107.GC2960@diku.dk> In-Reply-To: <20051211181901.GA2960@diku.dk> Using the --until switch, git-rev-parse(1) will first be given the ID. If it cannot make sense of the ID fallback to using date(1). Signed-off-by: Jonas Fonseca --- diff --git a/cg-object-id b/cg-object-id index 49d6d99..4e3a3e2 100755 --- a/cg-object-id +++ b/cg-object-id @@ -55,7 +55,14 @@ normalize_id() # date does the wrong thing for empty and single-letter ids if [ ${#id} -gt 1 ] && [ ! "$valid" ]; then - reqsecs=$(date --date="$id" +'%s' 2>/dev/null) + cursecs=$(git-rev-parse --until=yksap); cursecs=${cursecs:10} + reqsecs=$(git-rev-parse --until="$id"); reqsecs=${reqsecs:10} + + # git-rev-parse(1) will output the current time if the ID + # doesn't make sense. Workaround it so date(1) can have a try. + if [ "$cursecs" -le "$reqsecs" ]; then + reqsecs=$(date --date="$id" +'%s' 2>/dev/null) + fi if [ "$reqsecs" ]; then revid=$(git-rev-list --min-age=$reqsecs --max-count=1 HEAD) -- Jonas Fonseca