X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=tree-walk.c;h=f82dba6a1f43bf2a259952a4fd6db94d6335deb7;hb=b5c12797b442ddf4256332fe4baf709f90bb57a5;hp=f5d19f9cc16ec1c94c9b1bf8d14fd3d8620ff871;hpb=0de1633783685e9fb1943551217cdda7edbd245b;p=git.git diff --git a/tree-walk.c b/tree-walk.c index f5d19f9cc..f82dba6a1 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -465,7 +465,6 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch int retval; void *tree; unsigned long size; - struct tree_desc t; unsigned char root[20]; tree = read_object_with_reference(tree_sha1, tree_type, &size, root); @@ -478,8 +477,13 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch return 0; } - init_tree_desc(&t, tree, size); - retval = find_tree_entry(&t, name, sha1, mode); + if (!size) { + retval = -1; + } else { + struct tree_desc t; + init_tree_desc(&t, tree, size); + retval = find_tree_entry(&t, name, sha1, mode); + } free(tree); return retval; } @@ -573,27 +577,23 @@ static int match_dir_prefix(const char *base, * * Pre-condition: either baselen == base_offset (i.e. empty path) * or base[baselen-1] == '/' (i.e. with trailing slash). - * - * Return: - * - 2 for "yes, and all subsequent entries will be" - * - 1 for yes - * - zero for no - * - negative for "no, and no subsequent entries will be either" */ -int tree_entry_interesting(const struct name_entry *entry, - struct strbuf *base, int base_offset, - const struct pathspec *ps) +enum interesting tree_entry_interesting(const struct name_entry *entry, + struct strbuf *base, int base_offset, + const struct pathspec *ps) { int i; int pathlen, baselen = base->len - base_offset; - int never_interesting = ps->has_wildcard ? 0 : -1; + int never_interesting = ps->has_wildcard ? + entry_not_interesting : all_entries_not_interesting; if (!ps->nr) { if (!ps->recursive || ps->max_depth == -1) - return 2; - return !!within_depth(base->buf + base_offset, baselen, - !!S_ISDIR(entry->mode), - ps->max_depth); + return all_entries_interesting; + return within_depth(base->buf + base_offset, baselen, + !!S_ISDIR(entry->mode), + ps->max_depth) ? + entry_interesting : entry_not_interesting; } pathlen = tree_entry_len(entry); @@ -610,12 +610,13 @@ int tree_entry_interesting(const struct name_entry *entry, goto match_wildcards; if (!ps->recursive || ps->max_depth == -1) - return 2; + return all_entries_interesting; - return !!within_depth(base_str + matchlen + 1, - baselen - matchlen - 1, - !!S_ISDIR(entry->mode), - ps->max_depth); + return within_depth(base_str + matchlen + 1, + baselen - matchlen - 1, + !!S_ISDIR(entry->mode), + ps->max_depth) ? + entry_interesting : entry_not_interesting; } /* Either there must be no base, or the base must match. */ @@ -623,25 +624,25 @@ int tree_entry_interesting(const struct name_entry *entry, if (match_entry(entry, pathlen, match + baselen, matchlen - baselen, &never_interesting)) - return 1; + return entry_interesting; - if (ps->items[i].use_wildcard) { + if (item->use_wildcard) { if (!fnmatch(match + baselen, entry->path, 0)) - return 1; + return entry_interesting; /* * Match all directories. We'll try to * match files later on. */ if (ps->recursive && S_ISDIR(entry->mode)) - return 1; + return entry_interesting; } continue; } match_wildcards: - if (!ps->items[i].use_wildcard) + if (!item->use_wildcard) continue; /* @@ -653,7 +654,7 @@ match_wildcards: if (!fnmatch(match, base->buf + base_offset, 0)) { strbuf_setlen(base, base_offset + baselen); - return 1; + return entry_interesting; } strbuf_setlen(base, base_offset + baselen); @@ -662,7 +663,7 @@ match_wildcards: * later on. */ if (ps->recursive && S_ISDIR(entry->mode)) - return 1; + return entry_interesting; } return never_interesting; /* No matches */ }