All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philip Pokorny <ppokorny@mindspring.com>
To: Petr Baudis <pasky@ucw.cz>
Cc: git@vger.kernel.org
Subject: Re: PATCH[2/4]: Allow tree-id to return the ID of a tree object
Date: Thu, 28 Apr 2005 00:15:26 -0700	[thread overview]
Message-ID: <42708D8E.10003@mindspring.com> (raw)
In-Reply-To: <20050427232223.GM22956@pasky.ji.cz>

[-- Attachment #1: Type: text/plain, Size: 117 bytes --]

Convert commit-id to use the new cg-Xnormid internal script

Signed-off-by: Philip Pokorny <ppokorny@mindspring.com>

[-- Attachment #2: cogito-0.8-commit-id.patch --]
[-- Type: text/plain, Size: 1562 bytes --]

Index: commit-id
===================================================================
--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/commit-id  (mode:100755 sha1:4efcb6bdfdb2b2c5744f5d4d47d92beb7777ed59)
+++ uncommitted/commit-id  (mode:100775)
@@ -1,39 +1,25 @@
 #!/usr/bin/env bash
 #
 # Get ID of commit associated with given id or HEAD.
+#
 # Copyright (c) Petr Baudis, 2005
 #
-# Takes the appropriate ID, defaults to HEAD.
-
-SHA1="[A-Za-z0-9]{40}"
-SHA1ONLY="^$SHA1$"
-
-id=$1
-if [ ! "$id" ] || [ "$id" = "this" ] || [ "$id" = "HEAD" ]; then
-	id=$(cat .git/HEAD)
-fi
 
-if (echo $id | egrep -vq "$SHA1ONLY") && [ -r ".git/refs/tags/$id" ]; then
-	id=$(cat ".git/refs/tags/$id")
-fi
-
-if (echo $id | egrep -vq "$SHA1ONLY") && [ -r ".git/refs/heads/$id" ]; then
-	id=$(cat ".git/refs/heads/$id")
-fi
+# Save for later error message
+orig="$1"
 
-idpref=$(echo "$id" | cut -c -2)
-idpost=$(echo "$id" | cut -c 3-)
-if [ $(find ".git/objects/$idpref" -name "$idpost*" 2>/dev/null | wc -l) -eq 1 ]; then
-	id=$idpref$(basename $(echo .git/objects/$idpref/$idpost*))
-fi
+# Normalize to SHA1 form
+id=$(cg-Xnormid "$orig")
 
-if echo $id | egrep -vq "$SHA1ONLY"; then
-	echo "Invalid id: $id" >&2
+if [ ! "$id" ]; then
+	# cg-Xnormid already reported the error
 	exit 1
 fi
 
-if [ "$(cat-file -t "$id")" != "commit" ]; then
-	echo "Invalid id: $id" >&2
+# cat-file will verify that $id is a valid SHA1 ID for us
+# If it isn't, we'll get '' back
+if [ "$(cat-file -t "$id" 2>/dev/null)" != "commit" ]; then
+	echo "Invalid commit id: $orig" >&2
 	exit 1
 fi
 

  parent reply	other threads:[~2005-04-28  7:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-27 16:20 PATCH: Allow tree-id to return the ID of a tree object Philip Pokorny
2005-04-27 23:22 ` Petr Baudis
2005-04-28  7:11   ` PATCH[0/4]: " Philip Pokorny
2005-04-28  7:14   ` PATCH[1/4]: " Philip Pokorny
2005-04-28  7:15   ` Philip Pokorny [this message]
2005-05-02  5:46     ` PATCH[2/4]: " Philip Pokorny
2005-04-28  7:16   ` PATCH[3/4]: " Philip Pokorny
2005-04-28  7:17   ` PATCH[4/4]: " Philip Pokorny

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=42708D8E.10003@mindspring.com \
    --to=ppokorny@mindspring.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.