@@ -577,27 +577,23 @@ static int match_dir_prefix(const char *base,
577577 *
578578 * Pre-condition: either baselen == base_offset (i.e. empty path)
579579 * or base[baselen-1] == '/' (i.e. with trailing slash).
580- *
581- * Return:
582- * - 2 for "yes, and all subsequent entries will be"
583- * - 1 for yes
584- * - zero for no
585- * - negative for "no, and no subsequent entries will be either"
586580 */
587- int tree_entry_interesting (const struct name_entry * entry ,
588- struct strbuf * base , int base_offset ,
589- const struct pathspec * ps )
581+ enum interesting tree_entry_interesting (const struct name_entry * entry ,
582+ struct strbuf * base , int base_offset ,
583+ const struct pathspec * ps )
590584{
591585 int i ;
592586 int pathlen , baselen = base -> len - base_offset ;
593- int never_interesting = ps -> has_wildcard ? 0 : -1 ;
587+ int never_interesting = ps -> has_wildcard ?
588+ entry_not_interesting : all_entries_not_interesting ;
594589
595590 if (!ps -> nr ) {
596591 if (!ps -> recursive || ps -> max_depth == -1 )
597- return 2 ;
598- return !!within_depth (base -> buf + base_offset , baselen ,
599- !!S_ISDIR (entry -> mode ),
600- ps -> max_depth );
592+ return all_entries_interesting ;
593+ return within_depth (base -> buf + base_offset , baselen ,
594+ !!S_ISDIR (entry -> mode ),
595+ ps -> max_depth ) ?
596+ entry_interesting : entry_not_interesting ;
601597 }
602598
603599 pathlen = tree_entry_len (entry );
@@ -614,31 +610,32 @@ int tree_entry_interesting(const struct name_entry *entry,
614610 goto match_wildcards ;
615611
616612 if (!ps -> recursive || ps -> max_depth == -1 )
617- return 2 ;
613+ return all_entries_interesting ;
618614
619- return !!within_depth (base_str + matchlen + 1 ,
620- baselen - matchlen - 1 ,
621- !!S_ISDIR (entry -> mode ),
622- ps -> max_depth );
615+ return within_depth (base_str + matchlen + 1 ,
616+ baselen - matchlen - 1 ,
617+ !!S_ISDIR (entry -> mode ),
618+ ps -> max_depth ) ?
619+ entry_interesting : entry_not_interesting ;
623620 }
624621
625622 /* Either there must be no base, or the base must match. */
626623 if (baselen == 0 || !strncmp (base_str , match , baselen )) {
627624 if (match_entry (entry , pathlen ,
628625 match + baselen , matchlen - baselen ,
629626 & never_interesting ))
630- return 1 ;
627+ return entry_interesting ;
631628
632629 if (ps -> items [i ].use_wildcard ) {
633630 if (!fnmatch (match + baselen , entry -> path , 0 ))
634- return 1 ;
631+ return entry_interesting ;
635632
636633 /*
637634 * Match all directories. We'll try to
638635 * match files later on.
639636 */
640637 if (ps -> recursive && S_ISDIR (entry -> mode ))
641- return 1 ;
638+ return entry_interesting ;
642639 }
643640
644641 continue ;
@@ -657,7 +654,7 @@ int tree_entry_interesting(const struct name_entry *entry,
657654
658655 if (!fnmatch (match , base -> buf + base_offset , 0 )) {
659656 strbuf_setlen (base , base_offset + baselen );
660- return 1 ;
657+ return entry_interesting ;
661658 }
662659 strbuf_setlen (base , base_offset + baselen );
663660
@@ -666,7 +663,7 @@ int tree_entry_interesting(const struct name_entry *entry,
666663 * later on.
667664 */
668665 if (ps -> recursive && S_ISDIR (entry -> mode ))
669- return 1 ;
666+ return entry_interesting ;
670667 }
671668 return never_interesting ; /* No matches */
672669}
0 commit comments