Subject: [PATCH] cg-object-id: use git-rev-parse(1) for date parsing

From: Jonas Fonseca <[email-masked]>
Date: Sun, 11 Dec 2005 19:31:07 +0100

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 <[email-masked]>
 
---
 
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