@@ -85,6 +85,8 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
85
85
/*
86
86
* Is a tree entry interesting given the pathspec we have?
87
87
*
88
+ * Pre-condition: baselen == 0 || base[baselen-1] == '/'
89
+ *
88
90
* Return:
89
91
* - 2 for "yes, and all subsequent entries will be"
90
92
* - 1 for yes
@@ -101,7 +103,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
101
103
int never_interesting = -1 ;
102
104
103
105
if (!opt -> nr_paths )
104
- return 1 ;
106
+ return 2 ;
105
107
106
108
sha1 = tree_entry_extract (desc , & path , & mode );
107
109
@@ -257,19 +259,12 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
257
259
}
258
260
}
259
261
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 )
261
263
{
262
- int all_interesting = 0 ;
263
264
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 ;
273
268
if (!show ) {
274
269
update_tree_entry (t );
275
270
continue ;
@@ -284,14 +279,20 @@ static void skip_uninteresting(struct tree_desc *t, const char *base, int basele
284
279
int diff_tree (struct tree_desc * t1 , struct tree_desc * t2 , const char * base , struct diff_options * opt )
285
280
{
286
281
int baselen = strlen (base );
282
+ int all_t1_interesting = 0 ;
283
+ int all_t2_interesting = 0 ;
287
284
288
285
for (;;) {
289
286
if (DIFF_OPT_TST (opt , QUICK ) &&
290
287
DIFF_OPT_TST (opt , HAS_CHANGES ))
291
288
break ;
292
289
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 );
295
296
}
296
297
if (!t1 -> size ) {
297
298
if (!t2 -> size )
0 commit comments