git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: PATCH[3/4]: Allow tree-id to return the ID of a tree object

From
PPPhilip Pokorny <ppokorny@mindspring.com>
Date
Apr 28, 2005, 07:16 UTC
Message-ID
<42708DCB.1040007@mindspring.com>
In-Reply-To
<20050427232223.GM22956@pasky.ji.cz>
Convert tree-id to use cg-Xnormid to normalize an ID
Signed-off-by: Philip Pokorny <ppokorny@mindspring.com>
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
 
Previous: Philip PokornyNext: Philip Pokorny
Message 7 of 8 in “PATCH: Allow tree-id to return the ID of a tree object”
  1. Philip PokornyApr 27, 2005
  2. Petr BaudisApr 27, 2005
  3. Philip PokornyApr 28, 2005
  4. Philip PokornyApr 28, 2005
  5. Philip PokornyApr 28, 2005
  6. Philip PokornyMay 2, 2005
  7. Philip PokornyApr 28, 2005
  8. Philip PokornyApr 28, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.