@@ -503,6 +503,25 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
503503 dir -> basebuf [baselen ] = '\0' ;
504504}
505505
506+ static int match_basename (const char * basename , int basenamelen ,
507+ const char * pattern , int prefix , int patternlen ,
508+ int flags )
509+ {
510+ if (prefix == patternlen ) {
511+ if (!strcmp_icase (pattern , basename ))
512+ return 1 ;
513+ } else if (flags & EXC_FLAG_ENDSWITH ) {
514+ if (patternlen - 1 <= basenamelen &&
515+ !strcmp_icase (pattern + 1 ,
516+ basename + basenamelen - patternlen + 1 ))
517+ return 1 ;
518+ } else {
519+ if (fnmatch_icase (pattern , basename , 0 ) == 0 )
520+ return 1 ;
521+ }
522+ return 0 ;
523+ }
524+
506525/* Scan the list and let the last match determine the fate.
507526 * Return 1 for exclude, 0 for include and -1 for undecided.
508527 */
@@ -529,19 +548,11 @@ int excluded_from_list(const char *pathname,
529548 }
530549
531550 if (x -> flags & EXC_FLAG_NODIR ) {
532- /* match basename */
533- if (prefix == x -> patternlen ) {
534- if (!strcmp_icase (exclude , basename ))
535- return to_exclude ;
536- } else if (x -> flags & EXC_FLAG_ENDSWITH ) {
537- int len = pathlen - (basename - pathname );
538- if (x -> patternlen - 1 <= len &&
539- !strcmp_icase (exclude + 1 , basename + len - x -> patternlen + 1 ))
540- return to_exclude ;
541- } else {
542- if (fnmatch_icase (exclude , basename , 0 ) == 0 )
543- return to_exclude ;
544- }
551+ if (match_basename (basename ,
552+ pathlen - (basename - pathname ),
553+ exclude , prefix , x -> patternlen ,
554+ x -> flags ))
555+ return to_exclude ;
545556 continue ;
546557 }
547558
0 commit comments