@@ -578,78 +578,6 @@ void add_excludes_from_file(struct dir_struct *dir, const char *fname)
578578 die ("cannot use %s as an exclude file" , fname );
579579}
580580
581- /*
582- * Loads the per-directory exclude list for the substring of base
583- * which has a char length of baselen.
584- */
585- static void prep_exclude (struct dir_struct * dir , const char * base , int baselen )
586- {
587- struct exclude_list_group * group ;
588- struct exclude_list * el ;
589- struct exclude_stack * stk = NULL ;
590- int current ;
591-
592- if ((!dir -> exclude_per_dir ) ||
593- (baselen + strlen (dir -> exclude_per_dir ) >= PATH_MAX ))
594- return ; /* too long a path -- ignore */
595-
596- group = & dir -> exclude_list_group [EXC_DIRS ];
597-
598- /* Pop the exclude lists from the EXCL_DIRS exclude_list_group
599- * which originate from directories not in the prefix of the
600- * path being checked. */
601- while ((stk = dir -> exclude_stack ) != NULL ) {
602- if (stk -> baselen <= baselen &&
603- !strncmp (dir -> basebuf , base , stk -> baselen ))
604- break ;
605- el = & group -> el [dir -> exclude_stack -> exclude_ix ];
606- dir -> exclude_stack = stk -> prev ;
607- free ((char * )el -> src ); /* see strdup() below */
608- clear_exclude_list (el );
609- free (stk );
610- group -> nr -- ;
611- }
612-
613- /* Read from the parent directories and push them down. */
614- current = stk ? stk -> baselen : -1 ;
615- while (current < baselen ) {
616- struct exclude_stack * stk = xcalloc (1 , sizeof (* stk ));
617- const char * cp ;
618-
619- if (current < 0 ) {
620- cp = base ;
621- current = 0 ;
622- }
623- else {
624- cp = strchr (base + current + 1 , '/' );
625- if (!cp )
626- die ("oops in prep_exclude" );
627- cp ++ ;
628- }
629- stk -> prev = dir -> exclude_stack ;
630- stk -> baselen = cp - base ;
631- memcpy (dir -> basebuf + current , base + current ,
632- stk -> baselen - current );
633- strcpy (dir -> basebuf + stk -> baselen , dir -> exclude_per_dir );
634- /*
635- * dir->basebuf gets reused by the traversal, but we
636- * need fname to remain unchanged to ensure the src
637- * member of each struct exclude correctly
638- * back-references its source file. Other invocations
639- * of add_exclude_list provide stable strings, so we
640- * strdup() and free() here in the caller.
641- */
642- el = add_exclude_list (dir , EXC_DIRS , strdup (dir -> basebuf ));
643- stk -> exclude_ix = group -> nr - 1 ;
644- add_excludes_from_file_to_list (dir -> basebuf ,
645- dir -> basebuf , stk -> baselen ,
646- el , 1 );
647- dir -> exclude_stack = stk ;
648- current = stk -> baselen ;
649- }
650- dir -> basebuf [baselen ] = '\0' ;
651- }
652-
653581int match_basename (const char * basename , int basenamelen ,
654582 const char * pattern , int prefix , int patternlen ,
655583 int flags )
@@ -815,6 +743,78 @@ static struct exclude *last_exclude_matching_from_lists(struct dir_struct *dir,
815743 return NULL ;
816744}
817745
746+ /*
747+ * Loads the per-directory exclude list for the substring of base
748+ * which has a char length of baselen.
749+ */
750+ static void prep_exclude (struct dir_struct * dir , const char * base , int baselen )
751+ {
752+ struct exclude_list_group * group ;
753+ struct exclude_list * el ;
754+ struct exclude_stack * stk = NULL ;
755+ int current ;
756+
757+ if ((!dir -> exclude_per_dir ) ||
758+ (baselen + strlen (dir -> exclude_per_dir ) >= PATH_MAX ))
759+ return ; /* too long a path -- ignore */
760+
761+ group = & dir -> exclude_list_group [EXC_DIRS ];
762+
763+ /* Pop the exclude lists from the EXCL_DIRS exclude_list_group
764+ * which originate from directories not in the prefix of the
765+ * path being checked. */
766+ while ((stk = dir -> exclude_stack ) != NULL ) {
767+ if (stk -> baselen <= baselen &&
768+ !strncmp (dir -> basebuf , base , stk -> baselen ))
769+ break ;
770+ el = & group -> el [dir -> exclude_stack -> exclude_ix ];
771+ dir -> exclude_stack = stk -> prev ;
772+ free ((char * )el -> src ); /* see strdup() below */
773+ clear_exclude_list (el );
774+ free (stk );
775+ group -> nr -- ;
776+ }
777+
778+ /* Read from the parent directories and push them down. */
779+ current = stk ? stk -> baselen : -1 ;
780+ while (current < baselen ) {
781+ struct exclude_stack * stk = xcalloc (1 , sizeof (* stk ));
782+ const char * cp ;
783+
784+ if (current < 0 ) {
785+ cp = base ;
786+ current = 0 ;
787+ }
788+ else {
789+ cp = strchr (base + current + 1 , '/' );
790+ if (!cp )
791+ die ("oops in prep_exclude" );
792+ cp ++ ;
793+ }
794+ stk -> prev = dir -> exclude_stack ;
795+ stk -> baselen = cp - base ;
796+ memcpy (dir -> basebuf + current , base + current ,
797+ stk -> baselen - current );
798+ strcpy (dir -> basebuf + stk -> baselen , dir -> exclude_per_dir );
799+ /*
800+ * dir->basebuf gets reused by the traversal, but we
801+ * need fname to remain unchanged to ensure the src
802+ * member of each struct exclude correctly
803+ * back-references its source file. Other invocations
804+ * of add_exclude_list provide stable strings, so we
805+ * strdup() and free() here in the caller.
806+ */
807+ el = add_exclude_list (dir , EXC_DIRS , strdup (dir -> basebuf ));
808+ stk -> exclude_ix = group -> nr - 1 ;
809+ add_excludes_from_file_to_list (dir -> basebuf ,
810+ dir -> basebuf , stk -> baselen ,
811+ el , 1 );
812+ dir -> exclude_stack = stk ;
813+ current = stk -> baselen ;
814+ }
815+ dir -> basebuf [baselen ] = '\0' ;
816+ }
817+
818818/*
819819 * Loads the exclude lists for the directory containing pathname, then
820820 * scans all exclude lists to determine whether pathname is excluded.
0 commit comments