tree_entry_interesting(): remove dependency on struct diff_options

This function can be potentially used in more places than just
tree-diff.c. "struct diff_options" does not make much sense outside
diff_tree_sha1().

While removing the use of diff_options, it also removes
tree_entry_extract() call, which means S_ISDIR() uses the entry->mode
directly, without being filtered by canon_mode() (called internally
inside tree_entry_extract).

The only use of the mode information in this function is to check the
type of the entry by giving it to S_ISDIR() macro, and the result does
not change with or without canon_mode(), so it is ok to bypass
tree_entry_extract().

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2010-12-15 22:02:39 +07:00 committed by Junio C Hamano
parent 66f136252f
commit 475005a117

View File

@ -93,24 +93,19 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
* - zero for no * - zero for no
* - negative for "no, and no subsequent entries will be either" * - negative for "no, and no subsequent entries will be either"
*/ */
static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt) static int tree_entry_interesting(const struct name_entry *entry, const char *base, int baselen, const struct pathspec *ps)
{ {
const char *path;
const unsigned char *sha1;
unsigned mode;
int i; int i;
int pathlen; int pathlen;
int never_interesting = -1; int never_interesting = -1;
if (!opt->pathspec.nr) if (!ps || !ps->nr)
return 2; return 2;
sha1 = tree_entry_extract(desc, &path, &mode); pathlen = tree_entry_len(entry->path, entry->sha1);
pathlen = tree_entry_len(path, sha1); for (i = 0; i < ps->nr; i++) {
const struct pathspec_item *item = ps->items+i;
for (i = 0; i < opt->pathspec.nr; i++) {
const struct pathspec_item *item = opt->pathspec.items+i;
const char *match = item->match; const char *match = item->match;
int matchlen = item->len; int matchlen = item->len;
int m = -1; /* signals that we haven't called strncmp() */ int m = -1; /* signals that we haven't called strncmp() */
@ -150,7 +145,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
* Does match sort strictly earlier than path * Does match sort strictly earlier than path
* with their common parts? * with their common parts?
*/ */
m = strncmp(match, path, m = strncmp(match, entry->path,
(matchlen < pathlen) ? matchlen : pathlen); (matchlen < pathlen) ? matchlen : pathlen);
if (m < 0) if (m < 0)
continue; continue;
@ -177,7 +172,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
if (matchlen > pathlen) { if (matchlen > pathlen) {
if (match[pathlen] != '/') if (match[pathlen] != '/')
continue; continue;
if (!S_ISDIR(mode)) if (!S_ISDIR(entry->mode))
continue; continue;
} }
@ -186,7 +181,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
* we cheated and did not do strncmp(), so we do * we cheated and did not do strncmp(), so we do
* that here. * that here.
*/ */
m = strncmp(match, path, pathlen); m = strncmp(match, entry->path, pathlen);
/* /*
* If common part matched earlier then it is a hit, * If common part matched earlier then it is a hit,
@ -209,8 +204,7 @@ static void show_tree(struct diff_options *opt, const char *prefix, struct tree_
if (all_interesting) if (all_interesting)
show = 1; show = 1;
else { else {
show = tree_entry_interesting(desc, base, baselen, show = tree_entry_interesting(&desc->entry, base, baselen, &opt->pathspec);
opt);
if (show == 2) if (show == 2)
all_interesting = 1; all_interesting = 1;
} }
@ -263,7 +257,7 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt, int *all_interesting) static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt, int *all_interesting)
{ {
while (t->size) { while (t->size) {
int show = tree_entry_interesting(t, base, baselen, opt); int show = tree_entry_interesting(&t->entry, base, baselen, &opt->pathspec);
if (show == 2) if (show == 2)
*all_interesting = 1; *all_interesting = 1;
if (!show) { if (!show) {