Switch "read_tree_recursive()" over to tree-walk functionality
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
a755dfe45c
commit
2522c13244
33
tree.c
33
tree.c
@ -78,19 +78,26 @@ int read_tree_recursive(struct tree *tree,
|
|||||||
int stage, const char **match,
|
int stage, const char **match,
|
||||||
read_tree_fn_t fn)
|
read_tree_fn_t fn)
|
||||||
{
|
{
|
||||||
struct tree_entry_list *list;
|
struct tree_desc desc;
|
||||||
|
|
||||||
if (parse_tree(tree))
|
if (parse_tree(tree))
|
||||||
return -1;
|
return -1;
|
||||||
list = tree->entries;
|
|
||||||
while (list) {
|
desc.buf = tree->buffer;
|
||||||
struct tree_entry_list *current = list;
|
desc.size = tree->size;
|
||||||
list = list->next;
|
|
||||||
if (!match_tree_entry(base, baselen, current->name,
|
while (desc.size) {
|
||||||
current->mode, match))
|
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;
|
continue;
|
||||||
|
|
||||||
switch (fn(current->sha1, base, baselen,
|
switch (fn(sha1, base, baselen, name, mode, stage)) {
|
||||||
current->name, current->mode, stage)) {
|
|
||||||
case 0:
|
case 0:
|
||||||
continue;
|
continue;
|
||||||
case READ_TREE_RECURSIVE:
|
case READ_TREE_RECURSIVE:
|
||||||
@ -98,16 +105,16 @@ int read_tree_recursive(struct tree *tree,
|
|||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (current->directory) {
|
if (S_ISDIR(mode)) {
|
||||||
int retval;
|
int retval;
|
||||||
int pathlen = strlen(current->name);
|
int pathlen = strlen(name);
|
||||||
char *newbase;
|
char *newbase;
|
||||||
|
|
||||||
newbase = xmalloc(baselen + 1 + pathlen);
|
newbase = xmalloc(baselen + 1 + pathlen);
|
||||||
memcpy(newbase, base, baselen);
|
memcpy(newbase, base, baselen);
|
||||||
memcpy(newbase + baselen, current->name, pathlen);
|
memcpy(newbase + baselen, name, pathlen);
|
||||||
newbase[baselen + pathlen] = '/';
|
newbase[baselen + pathlen] = '/';
|
||||||
retval = read_tree_recursive(lookup_tree(current->sha1),
|
retval = read_tree_recursive(lookup_tree(sha1),
|
||||||
newbase,
|
newbase,
|
||||||
baselen + pathlen + 1,
|
baselen + pathlen + 1,
|
||||||
stage, match, fn);
|
stage, match, fn);
|
||||||
|
Loading…
Reference in New Issue
Block a user