Skip to contentSkip to conversation

cg-object-id: use git-rev-parse(1) for date parsing

PATCH New Jonas Fonseca 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

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).

---

The mixing of date parsing behaviours might be a little questionable, but it's good to stay compatible with git.

commit 41447107236a7d23daa6ab0f40a0829935485bc8
tree 27863684c19e7f129304d2a1573c08f974126e2a
parent f0535e9952f1cace89d03649e8238aca69a6df44
author Jonas Fonseca <[email protected]> Wed, 07 Dec 2005 22:16:50 +0100 committer Jonas Fonseca <[email protected]> Wed, 07 Dec 2005 22:16:50 +0100

 cg-object-id |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
cg-object-id +8 -1
index ea04dca..baf096e 100755
@@ -73,7 +73,14 @@ normalize_id()
 	fi
 
 	if [ "$id" != " " ] && [ ! "$valid" ]; then
-		reqsecs=$(date --date="$id" +'%s' 2>/dev/null)
+		curtime=$(date +'%s' 2>/dev/null)
+		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 [ "$curtime" -le "$reqsecs" ]; then
+			reqsecs=$(date --date="$id" +'%s' 2>/dev/null)
+		fi
 
 		if [ "$reqsecs" ]; then
 			id=$(git-rev-list --min-age=$reqsecs --max-count=1 HEAD)
Signature · 1 line
Jonas Fonseca