git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonas Fonseca <fonseca@diku.dk>
To: Petr Baudis <pasky@ucw.cz>, git@vger.kernel.org
Subject: [PATCH] cg-object-id: use git-rev-parse(1) for date parsing
Date: Sun, 11 Dec 2005 19:31:07 +0100	[thread overview]
Message-ID: <20051211183107.GC2960@diku.dk> (raw)
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

  reply	other threads:[~2005-12-11 18:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-07 21:39 [PATCH] Offload most of cg-object-id to git-rev-parse Jonas Fonseca
2005-12-11 18:19 ` Jonas Fonseca
2005-12-11 18:31   ` Jonas Fonseca [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-12-07 21:40 [PATCH] cg-object-id: use git-rev-parse(1) for date parsing Jonas Fonseca

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051211183107.GC2960@diku.dk \
    --to=fonseca@diku.dk \
    --cc=git@vger.kernel.org \
    --cc=pasky@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).