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

[PATCH 1/4] Add a function for getting a struct tree for an ent.

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Sep 5, 2005, 06:03 UTC
Message-ID
<Pine.LNX.4.63.0509050203270.23242@iabervon.org>
In-Reply-To
<Pine.LNX.4.63.0509050151240.23242@iabervon.org>
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 tree.c |   21 +++++++++++++++++++++
 tree.h |    3 +++
 2 files changed, 24 insertions(+), 0 deletions(-)
3bfcc20b6aeff3e1fbcce97a426383c9770a2105
diff --git a/tree.c b/tree.c
--- a/tree.c
+++ b/tree.c
@@ -1,5 +1,7 @@
 #include "tree.h"
 #include "blob.h"
+#include "commit.h"
+#include "tag.h"
 #include "cache.h"
 #include <stdlib.h>
 
@@ -212,3 +214,22 @@ int parse_tree(struct tree *item)
 	free(buffer);
 	return ret;
 }
+
+struct tree *parse_tree_indirect(const unsigned char *sha1)
+{
+	struct object *obj = parse_object(sha1);
+	do {
+		if (!obj)
+			return NULL;
+		if (obj->type == tree_type)
+			return (struct tree *) obj;
+		else if (obj->type == commit_type)
+			obj = &(((struct commit *) obj)->tree->object);
+		else if (obj->type == tag_type)
+			obj = ((struct tag *) obj)->tagged;
+		else
+			return NULL;
+		if (!obj->parsed)
+			parse_object(obj->sha1);
+	} while (1);
+}
diff --git a/tree.h b/tree.h
--- a/tree.h
+++ b/tree.h
@@ -32,4 +32,7 @@ int parse_tree_buffer(struct tree *item,
 
 int parse_tree(struct tree *tree);
 
+/* Parses and returns the tree in the given ent, chasing tags and commits. */
+struct tree *parse_tree_indirect(const unsigned char *sha1);
+
 #endif /* TREE_H */
Previous: Daniel BarkalowNext: Daniel Barkalow
Message 2 of 5 in “Support multiple ancestors in read-tree”
  1. 0/4 Support multiple ancestors in read-treeDaniel Barkalow, Sep 5, 2005
  2. 1/4 Add a function for getting a struct tree for an ent.Daniel Barkalow, Sep 5, 2005
  3. 2/4 Add function to append to an object_list.Daniel Barkalow, Sep 5, 2005
  4. 3/4 Rewrite read-treeDaniel Barkalow, Sep 5, 2005
  5. 4/4 Document the trivial merge rules for 3(+more ancestors)-way merges.Daniel Barkalow, Sep 5, 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.