@@ -14,8 +14,7 @@ struct path_simplify {
1414 const char * path ;
1515};
1616
17- static int read_directory_recursive (struct dir_struct * dir ,
18- const char * path , const char * base , int baselen ,
17+ static int read_directory_recursive (struct dir_struct * dir , const char * path , int len ,
1918 int check_only , const struct path_simplify * simplify );
2019static int get_dtype (struct dirent * de , const char * path );
2120
@@ -54,23 +53,22 @@ static int common_prefix(const char **pathspec)
5453
5554int fill_directory (struct dir_struct * dir , const char * * pathspec )
5655{
57- const char * path , * base ;
58- int baselen ;
56+ const char * path ;
57+ int len ;
5958
6059 /*
6160 * Calculate common prefix for the pathspec, and
6261 * use that to optimize the directory walk
6362 */
64- baselen = common_prefix (pathspec );
63+ len = common_prefix (pathspec );
6564 path = "" ;
66- base = "" ;
6765
68- if (baselen )
69- path = base = xmemdupz (* pathspec , baselen );
66+ if (len )
67+ path = xmemdupz (* pathspec , len );
7068
7169 /* Read the directory and prune it */
72- read_directory (dir , path , base , baselen , pathspec );
73- return baselen ;
70+ read_directory (dir , path , len , pathspec );
71+ return len ;
7472}
7573
7674/*
@@ -526,7 +524,7 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
526524 /* This is the "show_other_directories" case */
527525 if (!(dir -> flags & DIR_HIDE_EMPTY_DIRECTORIES ))
528526 return show_directory ;
529- if (!read_directory_recursive (dir , dirname , dirname , len , 1 , simplify ))
527+ if (!read_directory_recursive (dir , dirname , len , 1 , simplify ))
530528 return ignore_directory ;
531529 return show_directory ;
532530}
@@ -595,15 +593,15 @@ static int get_dtype(struct dirent *de, const char *path)
595593 * Also, we ignore the name ".git" (even if it is not a directory).
596594 * That likely will not change.
597595 */
598- static int read_directory_recursive (struct dir_struct * dir , const char * path , const char * base , int baselen , int check_only , const struct path_simplify * simplify )
596+ static int read_directory_recursive (struct dir_struct * dir , const char * base , int baselen , int check_only , const struct path_simplify * simplify )
599597{
600- DIR * fdir = opendir (* path ? path : "." );
598+ DIR * fdir = opendir (* base ? base : "." );
601599 int contents = 0 ;
602600
603601 if (fdir ) {
604602 struct dirent * de ;
605- char fullname [PATH_MAX + 1 ];
606- memcpy (fullname , base , baselen );
603+ char path [PATH_MAX + 1 ];
604+ memcpy (path , base , baselen );
607605
608606 while ((de = readdir (fdir )) != NULL ) {
609607 int len , dtype ;
@@ -614,17 +612,18 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
614612 continue ;
615613 len = strlen (de -> d_name );
616614 /* Ignore overly long pathnames! */
617- if (len + baselen + 8 > sizeof (fullname ))
615+ if (len + baselen + 8 > sizeof (path ))
618616 continue ;
619- memcpy (fullname + baselen , de -> d_name , len + 1 );
620- if (simplify_away (fullname , baselen + len , simplify ))
617+ memcpy (path + baselen , de -> d_name , len + 1 );
618+ len = baselen + len ;
619+ if (simplify_away (path , len , simplify ))
621620 continue ;
622621
623622 dtype = DTYPE (de );
624- exclude = excluded (dir , fullname , & dtype );
623+ exclude = excluded (dir , path , & dtype );
625624 if (exclude && (dir -> flags & DIR_COLLECT_IGNORED )
626- && in_pathspec (fullname , baselen + len , simplify ))
627- dir_add_ignored (dir , fullname , baselen + len );
625+ && in_pathspec (path , len , simplify ))
626+ dir_add_ignored (dir , path , len );
628627
629628 /*
630629 * Excluded? If we don't explicitly want to show
@@ -634,7 +633,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
634633 continue ;
635634
636635 if (dtype == DT_UNKNOWN )
637- dtype = get_dtype (de , fullname );
636+ dtype = get_dtype (de , path );
638637
639638 /*
640639 * Do we want to see just the ignored files?
@@ -651,17 +650,17 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
651650 default :
652651 continue ;
653652 case DT_DIR :
654- memcpy (fullname + baselen + len , "/" , 2 );
653+ memcpy (path + len , "/" , 2 );
655654 len ++ ;
656- switch (treat_directory (dir , fullname , baselen + len , simplify )) {
655+ switch (treat_directory (dir , path , len , simplify )) {
657656 case show_directory :
658657 if (exclude != !!(dir -> flags
659658 & DIR_SHOW_IGNORED ))
660659 continue ;
661660 break ;
662661 case recurse_into_directory :
663662 contents += read_directory_recursive (dir ,
664- fullname , fullname , baselen + len , 0 , simplify );
663+ path , len , 0 , simplify );
665664 continue ;
666665 case ignore_directory :
667666 continue ;
@@ -675,7 +674,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
675674 if (check_only )
676675 goto exit_early ;
677676 else
678- dir_add_name (dir , fullname , baselen + len );
677+ dir_add_name (dir , path , len );
679678 }
680679exit_early :
681680 closedir (fdir );
@@ -738,15 +737,15 @@ static void free_simplify(struct path_simplify *simplify)
738737 free (simplify );
739738}
740739
741- int read_directory (struct dir_struct * dir , const char * path , const char * base , int baselen , const char * * pathspec )
740+ int read_directory (struct dir_struct * dir , const char * path , int len , const char * * pathspec )
742741{
743742 struct path_simplify * simplify ;
744743
745- if (has_symlink_leading_path (path , strlen ( path ) ))
744+ if (has_symlink_leading_path (path , len ))
746745 return dir -> nr ;
747746
748747 simplify = create_simplify (pathspec );
749- read_directory_recursive (dir , path , base , baselen , 0 , simplify );
748+ read_directory_recursive (dir , path , len , 0 , simplify );
750749 free_simplify (simplify );
751750 qsort (dir -> entries , dir -> nr , sizeof (struct dir_entry * ), cmp_name );
752751 qsort (dir -> ignored , dir -> ignored_nr , sizeof (struct dir_entry * ), cmp_name );
0 commit comments