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

[PATCH 1/2] Object model additions for read-tree

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Aug 31, 2005, 03:49 UTC
Message-ID
<Pine.LNX.4.63.0508302348350.23242@iabervon.org>
In-Reply-To
<Pine.LNX.4.63.0508302317380.23242@iabervon.org>
Adds object_list_append() and a function to get the struct tree from an ent.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 object.c |   11 +++++++++++
 object.h |    3 +++
 tree.c   |   19 +++++++++++++++++++
 tree.h   |    3 +++
 4 files changed, 36 insertions(+), 0 deletions(-)
49d33c385aa69d17c991300f73e77c6718a2b4a6
diff --git a/object.c b/object.c
--- a/object.c
+++ b/object.c
@@ -184,6 +184,17 @@ struct object_list *object_list_insert(s
         return new_list;
 }

+void object_list_append(struct object *item,
+			struct object_list **list_p)
+{
+	while (*list_p) {
+		list_p = &((*list_p)->next);
+	}
+	*list_p = xmalloc(sizeof(struct object_list));
+	(*list_p)->next = NULL;
+	(*list_p)->item = item;
+}
+
 unsigned object_list_length(struct object_list *list)
 {
 	unsigned ret = 0;
diff --git a/object.h b/object.h
--- a/object.h
+++ b/object.h
@@ -41,6 +41,9 @@ void mark_reachable(struct object *obj,
 struct object_list *object_list_insert(struct object *item,
 				       struct object_list **list_p);

+void object_list_append(struct object *item,
+			struct object_list **list_p);
+
 unsigned object_list_length(struct object_list *list);

 int object_list_contains(struct object_list *list, struct object *obj);
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,20 @@ 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)
+			return ((struct commit *) obj)->tree;
+		else if (obj->type == tag_type)
+			obj = ((struct tag *) obj)->tagged;
+		else
+			return NULL;
+	} 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 11 in “Reorganize read-tree”
  1. 0/2 Reorganize read-treeDaniel Barkalow, Aug 31, 2005
  2. 1/2 Object model additions for read-treeDaniel Barkalow, Aug 31, 2005
  3. Change read-tree to merge before using the index.Daniel Barkalow, Aug 31, 2005
  4. Junio C HamanoAug 31, 2005
  5. Daniel BarkalowAug 31, 2005
  6. Catalin MarinasAug 31, 2005
  7. Daniel BarkalowAug 31, 2005
  8. 1/2 Object model additions for read-treeDaniel Barkalow, Aug 31, 2005
  9. 2/2 Change read-tree to merge before using the index.Daniel Barkalow, Aug 31, 2005
  10. Junio C HamanoSep 5, 2005
  11. Daniel BarkalowSep 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.