Subject: [PATCH] cg-object-id: cleanup id verifying

From: Jonas Fonseca <[email-masked]>
Date: Wed, 7 Dec 2005 22:39:29 +0100

Signed-off-by: Jonas Fonseca <[email-masked]>

---
commit 36c0d9fae209ab7fa889333e8eebef22e7f0f55c
tree 364122ed83e2b920b0f0f5fe18c608a22aea6d07
parent 964e5ec2dd0ff3b073fbb9f3ad6f11c640a96a04
author Jonas Fonseca <[email-masked]> Wed, 07 Dec 2005 08:11:43 +0100
committer Jonas Fonseca <[email-masked]> Wed, 07 Dec 2005 08:11:43 +0100

 cg-object-id |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cg-object-id b/cg-object-id
index c7efa8a..56d9f91 100755
--- a/cg-object-id
+++ b/cg-object-id
@@ -50,6 +50,7 @@ normalize_id()
 	revid="$(git-rev-parse --verify "$id^0" 2>/dev/null)"
 	if [ "$revid" ]; then
 		id="$revid"
+		valid=1
 
 	# 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
@@ -60,8 +61,8 @@ normalize_id()
 		idmatch=($_git_objects/$idpref/$idpost*)
 
 		if [ ${#idmatch[*]} -eq 1 ] && [ -r "$idmatch" ]; then
-			exid=$idpref${idmatch#$_git_objects/$idpref/}
-			[ ${#exid} -eq 40 ] && [ "$(git-rev-parse --revs-only "$exid")" ] && id="$exid"
+			id=$idpref${idmatch#$_git_objects/$idpref/}
+			[ ${#id} -eq 40 ] && [ "$(git-rev-parse --revs-only "$id")" ] && valid=1
 		elif [ ${#idmatch[*]} -gt 1 ]; then
 			echo "Ambiguous id: $id" >&2
 			echo "${idmatch[@]}" >&2
@@ -69,13 +70,12 @@ normalize_id()
 		fi
 	fi
 
-	valid=; [ ${#id} -eq 40 ] && [ "$(git-rev-parse --revs-only "$id")" ] && valid=1
-	if ([ "$id" ] && [ "$id" != " " ]) && [ ! "$valid" ]; then
+	if [ "$id" != " " ] && [ ! "$valid" ]; then
 		reqsecs=$(date --date="$id" +'%s' 2>/dev/null)
 
 		if [ "$reqsecs" ]; then
 			id=$(git-rev-list --min-age=$reqsecs --max-count=1 HEAD)
-			valid=; [ ${#id} -eq 40 ] && [ "$(git-rev-parse --revs-only "$id")" ] && valid=1
+			[ ${#id} -eq 40 ] && [ "$(git-rev-parse --revs-only "$id")" ] && valid=1
 		fi
 	fi

-- 
Jonas Fonseca