public inbox for git@vger.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[3/4]: Allow tree-id to return the ID of a tree object
Date: Thu, 28 Apr 2005 00:16:27 -0700	[thread overview]
Message-ID: <42708DCB.1040007@mindspring.com> (raw)
In-Reply-To: <20050427232223.GM22956@pasky.ji.cz>

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

Convert tree-id to use cg-Xnormid to normalize an ID

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

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

Index: tree-id
===================================================================
--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/tree-id  (mode:100755 sha1:1495ff78af71b57e21653512932bcda88fe05454)
+++ uncommitted/tree-id  (mode:100775)
@@ -1,17 +1,31 @@
 #!/usr/bin/env bash
 #
 # Get ID of tree associated with given commit or HEAD.
+#
 # Copyright (c) Petr Baudis, 2005
 #
-# Takes ID of the appropriate commit, defaults to HEAD.
 
-SHA1="[A-Za-z0-9]{40}"
-TREE="^tree $SHA1$"
+# Save for later error message
+orig="$1"
 
-id=$(cat-file commit $(commit-id "$1") | egrep "$TREE" | cut -d ' ' -f 2)
+# Normalize to SHA1 form
+id=$(cg-Xnormid "$1")
+if [ ! "$id" ]; then
+	# cg-Xnormid already reported the error
+	exit 1
+fi
+
+# Is it a commit?
+idtype=$(cat-file -t $id 2>/dev/null)
+if [ "$idtype" = "commit" ]; then
+	# Get the tree
+	id=$(cat-file commit "$id" | sed -e 's/tree //;q')
+fi
 
-if [ "$(cat-file -t "$id")" != "tree" ]; 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)" != "tree" ]; then
+	echo "Invalid tree 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   ` PATCH[2/4]: " Philip Pokorny
2005-05-02  5:46     ` Philip Pokorny
2005-04-28  7:16   ` Philip Pokorny [this message]
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=42708DCB.1040007@mindspring.com \
    --to=ppokorny@mindspring$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=pasky@ucw$(echo .)cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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