Skip to content

Commit

Permalink
Merge branch 'en/tree-walk-optim'
Browse files Browse the repository at this point in the history
* en/tree-walk-optim:
  diff_tree(): Skip skip_uninteresting() when all remaining paths interesting
  tree_entry_interesting(): Make return value more specific
  tree-walk: Correct bitrotted comment about tree_entry()
  Document pre-condition for tree_entry_interesting
  • Loading branch information
Junio C Hamano committed Oct 27, 2010
2 parents d780696 + 7e1ec0d commit acbaf54
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions tree-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
/*
* Is a tree entry interesting given the pathspec we have?
*
* Pre-condition: baselen == 0 || base[baselen-1] == '/'
*
* Return:
* - 2 for "yes, and all subsequent entries will be"
* - 1 for yes
Expand All @@ -101,7 +103,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
int never_interesting = -1;

if (!opt->nr_paths)
return 1;
return 2;

sha1 = tree_entry_extract(desc, &path, &mode);

Expand Down Expand Up @@ -257,19 +259,12 @@ 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)
static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt, int *all_interesting)
{
int all_interesting = 0;
while (t->size) {
int show;

if (all_interesting)
show = 1;
else {
show = tree_entry_interesting(t, base, baselen, opt);
if (show == 2)
all_interesting = 1;
}
int show = tree_entry_interesting(t, base, baselen, opt);
if (show == 2)
*all_interesting = 1;
if (!show) {
update_tree_entry(t);
continue;
Expand All @@ -284,14 +279,20 @@ static void skip_uninteresting(struct tree_desc *t, const char *base, int basele
int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
{
int baselen = strlen(base);
int all_t1_interesting = 0;
int all_t2_interesting = 0;

for (;;) {
if (DIFF_OPT_TST(opt, QUICK) &&
DIFF_OPT_TST(opt, HAS_CHANGES))
break;
if (opt->nr_paths) {
skip_uninteresting(t1, base, baselen, opt);
skip_uninteresting(t2, base, baselen, opt);
if (!all_t1_interesting)
skip_uninteresting(t1, base, baselen, opt,
&all_t1_interesting);
if (!all_t2_interesting)
skip_uninteresting(t2, base, baselen, opt,
&all_t2_interesting);
}
if (!t1->size) {
if (!t2->size)
Expand Down

0 comments on commit acbaf54

Please sign in to comment.