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

[1/4] Report info from trees

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Apr 19, 2005, 01:51 UTC
Message-ID
<Pine.LNX.4.21.0504182148330.30848-100000@iabervon.org>
In-Reply-To
<Pine.LNX.4.21.0504182139250.30848-100000@iabervon.org>

This patch adds actual information to struct tree, making it possible to tell what sorts of things the referenced objects are. This is needed for http-pull, and Junio wanted something of the sort.

Signed-Off-By: Daniel Barkalow <barkalow@iabervon.org>
Index: tree.c
===================================================================
--- 1172a9b8f45b2fd640985595cc5258db3b027828/tree.c  (mode:100644 sha1:7c5e5e46f4967b0812b06c0114946c3a6432c8d8)
+++ 7e5a0d93117ecadfb15de3a6bebdb1aa94234fde/tree.c  (mode:100644 sha1:39f9cbd1908e9046c148339f816025c9313ec142)
@@ -27,6 +27,7 @@
 	char type[20];
 	void *buffer, *bufptr;
 	unsigned long size;
+	struct tree_entry_list **list_p;
 	if (item->object.parsed)
 		return 0;
 	item->object.parsed = 1;
@@ -38,8 +39,10 @@
 	if (strcmp(type, tree_type))
 		return error("Object %s not a tree",
 			     sha1_to_hex(item->object.sha1));
+	list_p = &item->entries;
 	while (size) {
 		struct object *obj;
+		struct tree_entry_list *entry;
 		int len = 1+strlen(bufptr);
 		unsigned char *file_sha1 = bufptr + len;
 		char *path = strchr(bufptr, ' ');
@@ -48,6 +51,11 @@
 		    sscanf(bufptr, "%o", &mode) != 1)
 			return -1;
 
+		entry = malloc(sizeof(struct tree_entry_list));
+		entry->directory = S_ISDIR(mode);
+		entry->executable = mode & S_IXUSR;
+		entry->next = NULL;
+
 		/* Warn about trees that don't do the recursive thing.. */
 		if (strchr(path, '/')) {
 			item->has_full_path = 1;
@@ -56,12 +64,17 @@
 		bufptr += len + 20;
 		size -= len + 20;
 
-		if (S_ISDIR(mode)) {
-			obj = &lookup_tree(file_sha1)->object;
+		if (entry->directory) {
+			entry->item.tree = lookup_tree(file_sha1);
+			obj = &entry->item.tree->object;
 		} else {
-			obj = &lookup_blob(file_sha1)->object;
+			entry->item.blob = lookup_blob(file_sha1);
+			obj = &entry->item.blob->object;
 		}
 		add_ref(&item->object, obj);
+
+		*list_p = entry;
+		list_p = &entry->next;
 	}
 	return 0;
 }
Index: tree.h
===================================================================
--- 1172a9b8f45b2fd640985595cc5258db3b027828/tree.h  (mode:100644 sha1:14ebbacded09d5e058c7f94652dcb9e12bc31cae)
+++ 7e5a0d93117ecadfb15de3a6bebdb1aa94234fde/tree.h  (mode:100644 sha1:985500e2a9130fe8c33134ca121838af9320c465)
@@ -5,9 +5,20 @@
 
 extern const char *tree_type;
 
+struct tree_entry_list {
+	struct tree_entry_list *next;
+	unsigned directory : 1;
+	unsigned executable : 1;
+	union {
+		struct tree *tree;
+		struct blob *blob;
+	} item;
+};
+
 struct tree {
 	struct object object;
 	unsigned has_full_path : 1;
+	struct tree_entry_list *entries;
 };
 
 struct tree *lookup_tree(unsigned char *sha1);
Previous: Daniel BarkalowNext: Junio C Hamano
Message 2 of 12 in “More patches”
  1. Daniel BarkalowApr 19, 2005
  2. 1/4 Report info from treesDaniel Barkalow, Apr 19, 2005
  3. Junio C HamanoApr 19, 2005
  4. Daniel BarkalowApr 19, 2005
  5. 2/4 Sorting commits by dateDaniel Barkalow, Apr 19, 2005
  6. Petr BaudisApr 19, 2005
  7. David A. WheelerApr 19, 2005
  8. Daniel BarkalowApr 19, 2005
  9. Petr BaudisApr 19, 2005
  10. Daniel BarkalowApr 19, 2005
  11. 3/4 Add http-pullDaniel Barkalow, Apr 19, 2005
  12. 4/4 Make merge-base use dates to find answerDaniel Barkalow, Apr 19, 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.