Skip to content

Commit acbaf54

Browse files
committed
Merge branch 'en/tree-walk-optim'
* 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
2 parents d780696 + 7e1ec0d commit acbaf54

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

tree-diff.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
8585
/*
8686
* Is a tree entry interesting given the pathspec we have?
8787
*
88+
* Pre-condition: baselen == 0 || base[baselen-1] == '/'
89+
*
8890
* Return:
8991
* - 2 for "yes, and all subsequent entries will be"
9092
* - 1 for yes
@@ -101,7 +103,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
101103
int never_interesting = -1;
102104

103105
if (!opt->nr_paths)
104-
return 1;
106+
return 2;
105107

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

@@ -257,19 +259,12 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
257259
}
258260
}
259261

260-
static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt)
262+
static void skip_uninteresting(struct tree_desc *t, const char *base, int baselen, struct diff_options *opt, int *all_interesting)
261263
{
262-
int all_interesting = 0;
263264
while (t->size) {
264-
int show;
265-
266-
if (all_interesting)
267-
show = 1;
268-
else {
269-
show = tree_entry_interesting(t, base, baselen, opt);
270-
if (show == 2)
271-
all_interesting = 1;
272-
}
265+
int show = tree_entry_interesting(t, base, baselen, opt);
266+
if (show == 2)
267+
*all_interesting = 1;
273268
if (!show) {
274269
update_tree_entry(t);
275270
continue;
@@ -284,14 +279,20 @@ static void skip_uninteresting(struct tree_desc *t, const char *base, int basele
284279
int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
285280
{
286281
int baselen = strlen(base);
282+
int all_t1_interesting = 0;
283+
int all_t2_interesting = 0;
287284

288285
for (;;) {
289286
if (DIFF_OPT_TST(opt, QUICK) &&
290287
DIFF_OPT_TST(opt, HAS_CHANGES))
291288
break;
292289
if (opt->nr_paths) {
293-
skip_uninteresting(t1, base, baselen, opt);
294-
skip_uninteresting(t2, base, baselen, opt);
290+
if (!all_t1_interesting)
291+
skip_uninteresting(t1, base, baselen, opt,
292+
&all_t1_interesting);
293+
if (!all_t2_interesting)
294+
skip_uninteresting(t2, base, baselen, opt,
295+
&all_t2_interesting);
295296
}
296297
if (!t1->size) {
297298
if (!t2->size)

0 commit comments

Comments
 (0)