git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jonas Fonseca <fonseca@diku.dk>
Date
Dec 11, 2005, 18:31 UTC
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 <fonseca@diku.dk>
 
---
 
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
Previous: Jonas Fonseca
Message 3 of 3 in “Offload most of cg-object-id to git-rev-parse”
  1. Offload most of cg-object-id to git-rev-parseJonas Fonseca, Dec 7, 2005
  2. Offload most of cg-object-id to git-rev-parseJonas Fonseca, Dec 11, 2005
  3. cg-object-id: use git-rev-parse(1) for date parsingJonas Fonseca, Dec 11, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.