git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cg-object-id: use git-rev-parse(1) for date parsing
@ 2005-12-07 21:40 Jonas Fonseca
  0 siblings, 0 replies; 2+ messages in thread
From: Jonas Fonseca @ 2005-12-07 21:40 UTC (permalink / raw)
  To: Petr Baudis, git

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>

---

 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 <fonseca@diku.dk> Wed, 07 Dec 2005 22:16:50 +0100
committer Jonas Fonseca <fonseca@antimatter.localdomain> Wed, 07 Dec 2005 22:16:50 +0100

 cg-object-id |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/cg-object-id b/cg-object-id
index ea04dca..baf096e 100755
--- a/cg-object-id
+++ b/cg-object-id
@@ -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)

-- 
Jonas Fonseca

^ permalink raw reply related	[flat|nested] 2+ messages in thread
* [PATCH] Offload most of cg-object-id to git-rev-parse
@ 2005-12-07 21:39 Jonas Fonseca
  2005-12-11 18:19 ` Jonas Fonseca
  0 siblings, 1 reply; 2+ messages in thread
From: Jonas Fonseca @ 2005-12-07 21:39 UTC (permalink / raw)
  To: Petr Baudis, git

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

---
commit 964e5ec2dd0ff3b073fbb9f3ad6f11c640a96a04
tree 97f861c24303936f012523a54f3d53f4939ebf52
parent 554014e31b92c98b35f77b80b19f5b21e8a76cfc
author Jonas Fonseca <fonseca@diku.dk> Wed, 07 Dec 2005 07:44:26 +0100
committer Jonas Fonseca <fonseca@antimatter.localdomain> Wed, 07 Dec 2005 07:44:26 +0100

 TODO         |    2 --
 cg-object-id |   29 +++++++++--------------------
 2 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/TODO b/TODO
index 0658b39..26bb4d0 100644
--- a/TODO
+++ b/TODO
@@ -27,8 +27,6 @@ cg-*patch should be pre-1.0.)
 
 	Includes merge-order cg-log and cg-diff checking for renames.
 
-* Offload most of cg-object-id to git-rev-parse
-
 * Show only first 12 (or so) nibbles of the hashes everywhere
 	Even this might be too much, but more than this is really useless
 	for anyone remotely human. And it's less scary, too.
diff --git a/cg-object-id b/cg-object-id
index ec0362a..c7efa8a 100755
--- a/cg-object-id
+++ b/cg-object-id
@@ -40,27 +40,16 @@ deprecated_alias cg-object-id commit-id 
 normalize_id()
 {
 	local id="$1"
+	local revid=
+	local valid=
 
-	if [ "${id:(-1):1}" = "^" ]; then
-		# find first parent
-		normalize_id "${id%^}"
-		normid=$(git-cat-file commit "$normid" | \
-			 awk '/^parent/{print $2; exit};/^$/{exit}') || exit 1
-		type="commit"
-		return
-	fi
-
-	if [ ! "$id" ] || [ "$id" = "this" ] || [ "$id" = "HEAD" ]; then
-		read id < "$_git/$(git-symbolic-ref HEAD)"
-
-	elif [ -r "$_git/refs/tags/$id" ]; then
-		read id < "$_git/refs/tags/$id"
-
-	elif [ -r "$_git/refs/heads/$id" ]; then
-		read id < "$_git/refs/heads/$id"
+	if [ ! "$id" ] || [ "$id" = "this" ]; then
+		id=HEAD;
+	fi
 
-	elif [ -r "$_git/refs/$id" ]; then
-		read id < "$_git/refs/$id"
+	revid="$(git-rev-parse --verify "$id^0" 2>/dev/null)"
+	if [ "$revid" ]; then
+		id="$revid"
 
 	# Short id's must be lower case and at least 4 digits.
 	elif [[ "$id" == [0-9a-f][0-9a-f][0-9a-f][0-9a-f]* ]]; then
@@ -146,7 +135,7 @@ fi
 
 
 if [ "$show_parent" ]; then
-	git-cat-file commit "$normid" | awk '/^parent/{print $2};/^$/{exit}'
+	git-rev-parse "$normid^"
 	exit 0
 fi
 

-- 
Jonas Fonseca

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-12-11 18:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-07 21:40 [PATCH] cg-object-id: use git-rev-parse(1) for date parsing Jonas Fonseca
  -- strict thread matches above, loose matches on Subject: below --
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   ` [PATCH] cg-object-id: use git-rev-parse(1) for date parsing Jonas Fonseca

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