@@ -873,14 +873,14 @@ enum path_treatment {
873873};
874874
875875static enum path_treatment treat_one_path (struct dir_struct * dir ,
876- char * path , int * len ,
876+ struct strbuf * path ,
877877 const struct path_simplify * simplify ,
878878 int dtype , struct dirent * de )
879879{
880- int exclude = excluded (dir , path , & dtype );
880+ int exclude = excluded (dir , path -> buf , & dtype );
881881 if (exclude && (dir -> flags & DIR_COLLECT_IGNORED )
882- && exclude_matches_pathspec (path , * len , simplify ))
883- dir_add_ignored (dir , path , * len );
882+ && exclude_matches_pathspec (path -> buf , path -> len , simplify ))
883+ dir_add_ignored (dir , path -> buf , path -> len );
884884
885885 /*
886886 * Excluded? If we don't explicitly want to show
@@ -890,7 +890,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
890890 return path_ignored ;
891891
892892 if (dtype == DT_UNKNOWN )
893- dtype = get_dtype (de , path , * len );
893+ dtype = get_dtype (de , path -> buf , path -> len );
894894
895895 /*
896896 * Do we want to see just the ignored files?
@@ -907,9 +907,8 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
907907 default :
908908 return path_ignored ;
909909 case DT_DIR :
910- memcpy (path + * len , "/" , 2 );
911- (* len )++ ;
912- switch (treat_directory (dir , path , * len , simplify )) {
910+ strbuf_addch (path , '/' );
911+ switch (treat_directory (dir , path -> buf , path -> len , simplify )) {
913912 case show_directory :
914913 if (exclude != !!(dir -> flags
915914 & DIR_SHOW_IGNORED ))
@@ -930,26 +929,21 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
930929
931930static enum path_treatment treat_path (struct dir_struct * dir ,
932931 struct dirent * de ,
933- char * path , int path_max ,
932+ struct strbuf * path ,
934933 int baselen ,
935- const struct path_simplify * simplify ,
936- int * len )
934+ const struct path_simplify * simplify )
937935{
938936 int dtype ;
939937
940938 if (is_dot_or_dotdot (de -> d_name ) || !strcmp (de -> d_name , ".git" ))
941939 return path_ignored ;
942- * len = strlen (de -> d_name );
943- /* Ignore overly long pathnames! */
944- if (* len + baselen + 8 > path_max )
945- return path_ignored ;
946- memcpy (path + baselen , de -> d_name , * len + 1 );
947- * len += baselen ;
948- if (simplify_away (path , * len , simplify ))
940+ strbuf_setlen (path , baselen );
941+ strbuf_addstr (path , de -> d_name );
942+ if (simplify_away (path -> buf , path -> len , simplify ))
949943 return path_ignored ;
950944
951945 dtype = DTYPE (de );
952- return treat_one_path (dir , path , len , simplify , dtype , de );
946+ return treat_one_path (dir , path , simplify , dtype , de );
953947}
954948
955949/*
@@ -969,19 +963,19 @@ static int read_directory_recursive(struct dir_struct *dir,
969963 DIR * fdir = opendir (* base ? base : "." );
970964 int contents = 0 ;
971965 struct dirent * de ;
972- char path [ PATH_MAX + 1 ] ;
966+ struct strbuf path = STRBUF_INIT ;
973967
974968 if (!fdir )
975969 return 0 ;
976970
977- memcpy ( path , base , baselen );
971+ strbuf_add ( & path , base , baselen );
978972
979973 while ((de = readdir (fdir )) != NULL ) {
980- int len ;
981- switch (treat_path (dir , de , path , sizeof (path ),
982- baselen , simplify , & len )) {
974+ switch (treat_path (dir , de , & path , baselen , simplify )) {
983975 case path_recurse :
984- contents += read_directory_recursive (dir , path , len , 0 , simplify );
976+ contents += read_directory_recursive (dir , path .buf ,
977+ path .len , 0 ,
978+ simplify );
985979 continue ;
986980 case path_ignored :
987981 continue ;
@@ -992,10 +986,11 @@ static int read_directory_recursive(struct dir_struct *dir,
992986 if (check_only )
993987 goto exit_early ;
994988 else
995- dir_add_name (dir , path , len );
989+ dir_add_name (dir , path . buf , path . len );
996990 }
997991exit_early :
998992 closedir (fdir );
993+ strbuf_release (& path );
999994
1000995 return contents ;
1001996}
@@ -1058,8 +1053,8 @@ static int treat_leading_path(struct dir_struct *dir,
10581053 const char * path , int len ,
10591054 const struct path_simplify * simplify )
10601055{
1061- char pathbuf [ PATH_MAX ] ;
1062- int baselen , blen ;
1056+ struct strbuf sb = STRBUF_INIT ;
1057+ int baselen , rc = 0 ;
10631058 const char * cp ;
10641059
10651060 while (len && path [len - 1 ] == '/' )
@@ -1074,19 +1069,22 @@ static int treat_leading_path(struct dir_struct *dir,
10741069 baselen = len ;
10751070 else
10761071 baselen = cp - path ;
1077- memcpy (pathbuf , path , baselen );
1078- pathbuf [baselen ] = '\0' ;
1079- if (!is_directory (pathbuf ))
1080- return 0 ;
1081- if (simplify_away (pathbuf , baselen , simplify ))
1082- return 0 ;
1083- blen = baselen ;
1084- if (treat_one_path (dir , pathbuf , & blen , simplify ,
1072+ strbuf_setlen (& sb , 0 );
1073+ strbuf_add (& sb , path , baselen );
1074+ if (!is_directory (sb .buf ))
1075+ break ;
1076+ if (simplify_away (sb .buf , sb .len , simplify ))
1077+ break ;
1078+ if (treat_one_path (dir , & sb , simplify ,
10851079 DT_DIR , NULL ) == path_ignored )
1086- return 0 ; /* do not recurse into it */
1087- if (len <= baselen )
1088- return 1 ; /* finished checking */
1080+ break ; /* do not recurse into it */
1081+ if (len <= baselen ) {
1082+ rc = 1 ;
1083+ break ; /* finished checking */
1084+ }
10891085 }
1086+ strbuf_release (& sb );
1087+ return rc ;
10901088}
10911089
10921090int read_directory (struct dir_struct * dir , const char * path , int len , const char * * pathspec )
0 commit comments