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

[PATCH 3/4] Switch "read_tree_recursive()" over to tree-walk functionality

From
Linus Torvalds <torvalds@osdl.org>
Date
May 28, 2006, 22:11 UTC
Message-ID
<Pine.LNX.4.64.0605281510080.5623@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0605281453460.5623@g5.osdl.org>

Don't use the tree_entry list, it really had no major reason not to just walk the raw tree instead.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
 tree.c |   33 ++++++++++++++++++++-------------
 1 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/tree.c b/tree.c
index ba8742c..8a7fdd4 100644
--- a/tree.c
+++ b/tree.c
@@ -78,19 +78,26 @@ int read_tree_recursive(struct tree *tre
 			int stage, const char **match,
 			read_tree_fn_t fn)
 {
-	struct tree_entry_list *list;
+	struct tree_desc desc;
+
 	if (parse_tree(tree))
 		return -1;
-	list = tree->entries;
-	while (list) {
-		struct tree_entry_list *current = list;
-		list = list->next;
-		if (!match_tree_entry(base, baselen, current->name,
-				      current->mode, match))
+
+	desc.buf = tree->buffer;
+	desc.size = tree->size;
+
+	while (desc.size) {
+		unsigned mode;
+		const char *name;
+		const unsigned char *sha1;
+
+		sha1 = tree_entry_extract(&desc, &name, &mode);
+		update_tree_entry(&desc);
+
+		if (!match_tree_entry(base, baselen, name, mode, match))
 			continue;
 
-		switch (fn(current->sha1, base, baselen,
-			   current->name, current->mode, stage)) {
+		switch (fn(sha1, base, baselen, name, mode, stage)) {
 		case 0:
 			continue;
 		case READ_TREE_RECURSIVE:
@@ -98,16 +105,16 @@ int read_tree_recursive(struct tree *tre
 		default:
 			return -1;
 		}
-		if (current->directory) {
+		if (S_ISDIR(mode)) {
 			int retval;
-			int pathlen = strlen(current->name);
+			int pathlen = strlen(name);
 			char *newbase;
 
 			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
-			memcpy(newbase + baselen, current->name, pathlen);
+			memcpy(newbase + baselen, name, pathlen);
 			newbase[baselen + pathlen] = '/';
-			retval = read_tree_recursive(lookup_tree(current->sha1),
+			retval = read_tree_recursive(lookup_tree(sha1),
 						     newbase,
 						     baselen + pathlen + 1,
 						     stage, match, fn);
Previous: Linus TorvaldsNext: Linus Torvalds
Message 4 of 5 in “Start migrating away from the "struct tree_entry" list”
  1. 0/4 Start migrating away from the "struct tree_entry" listLinus Torvalds, May 28, 2006
  2. 1/4 Add raw tree buffer info to "struct tree"Linus Torvalds, May 28, 2006
  3. 2/4 Make "tree_entry" have a SHA1 instead of a union of object pointersLinus Torvalds, May 28, 2006
  4. 3/4 Switch "read_tree_recursive()" over to tree-walk functionalityLinus Torvalds, May 28, 2006
  5. 4/4 Remove "tree->entries" tree-entry list from tree parserLinus Torvalds, May 28, 2006

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.