@matheusbsbs / matheus-bagliano / commits / 0790a42a50
Fork 0

Switch "read_tree_recursive()" over to tree-walk functionality

Don't use the tree_entry list any more. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed May 29, 2006 at 12:17 UTC 0790a42a502701c7b58e9ad4123e46bf46bbf319
1 file changed +20 -13
tree.c
+20 -13
@@ -78,19 +78,26 @@ int read_tree_recursive(struct tree *tree,
78 int stage, const char **match,
79 read_tree_fn_t fn)
80 {
81 - struct tree_entry_list *list;
81 + struct tree_desc desc;
82 +
83 if (parse_tree(tree))
84 return -1;
84 - list = tree->entries;
85 - while (list) {
86 - struct tree_entry_list *current = list;
87 - list = list->next;
88 - if (!match_tree_entry(base, baselen, current->name,
89 - current->mode, match))
85 +
86 + desc.buf = tree->buffer;
87 + desc.size = tree->size;
88 +
89 + while (desc.size) {
90 + unsigned mode;
91 + const char *name;
92 + const unsigned char *sha1;
93 +
94 + sha1 = tree_entry_extract(&desc, &name, &mode);
95 + update_tree_entry(&desc);
96 +
97 + if (!match_tree_entry(base, baselen, name, mode, match))
98 continue;
99
92 - switch (fn(current->sha1, base, baselen,
93 - current->name, current->mode, stage)) {
100 + switch (fn(sha1, base, baselen, name, mode, stage)) {
101 case 0:
102 continue;
103 case READ_TREE_RECURSIVE:
@@ -98,16 +105,16 @@ int read_tree_recursive(struct tree *tree,
105 default:
106 return -1;
107 }
101 - if (current->directory) {
108 + if (S_ISDIR(mode)) {
109 int retval;
103 - int pathlen = strlen(current->name);
110 + int pathlen = strlen(name);
111 char *newbase;
112
113 newbase = xmalloc(baselen + 1 + pathlen);
114 memcpy(newbase, base, baselen);
108 - memcpy(newbase + baselen, current->name, pathlen);
115 + memcpy(newbase + baselen, name, pathlen);
116 newbase[baselen + pathlen] = '/';
110 - retval = read_tree_recursive(lookup_tree(current->sha1),
117 + retval = read_tree_recursive(lookup_tree(sha1),
118 newbase,
119 baselen + pathlen + 1,
120 stage, match, fn);