@@ -873,14 +873,14 @@ enum path_treatment {
873
873
};
874
874
875
875
static enum path_treatment treat_one_path (struct dir_struct * dir ,
876
- char * path , int * len ,
876
+ struct strbuf * path ,
877
877
const struct path_simplify * simplify ,
878
878
int dtype , struct dirent * de )
879
879
{
880
- int exclude = excluded (dir , path , & dtype );
880
+ int exclude = excluded (dir , path -> buf , & dtype );
881
881
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 );
884
884
885
885
/*
886
886
* Excluded? If we don't explicitly want to show
@@ -890,7 +890,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
890
890
return path_ignored ;
891
891
892
892
if (dtype == DT_UNKNOWN )
893
- dtype = get_dtype (de , path , * len );
893
+ dtype = get_dtype (de , path -> buf , path -> len );
894
894
895
895
/*
896
896
* Do we want to see just the ignored files?
@@ -907,9 +907,8 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
907
907
default :
908
908
return path_ignored ;
909
909
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 )) {
913
912
case show_directory :
914
913
if (exclude != !!(dir -> flags
915
914
& DIR_SHOW_IGNORED ))
@@ -930,26 +929,21 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
930
929
931
930
static enum path_treatment treat_path (struct dir_struct * dir ,
932
931
struct dirent * de ,
933
- char * path , int path_max ,
932
+ struct strbuf * path ,
934
933
int baselen ,
935
- const struct path_simplify * simplify ,
936
- int * len )
934
+ const struct path_simplify * simplify )
937
935
{
938
936
int dtype ;
939
937
940
938
if (is_dot_or_dotdot (de -> d_name ) || !strcmp (de -> d_name , ".git" ))
941
939
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 ))
949
943
return path_ignored ;
950
944
951
945
dtype = DTYPE (de );
952
- return treat_one_path (dir , path , len , simplify , dtype , de );
946
+ return treat_one_path (dir , path , simplify , dtype , de );
953
947
}
954
948
955
949
/*
@@ -969,19 +963,19 @@ static int read_directory_recursive(struct dir_struct *dir,
969
963
DIR * fdir = opendir (* base ? base : "." );
970
964
int contents = 0 ;
971
965
struct dirent * de ;
972
- char path [ PATH_MAX + 1 ] ;
966
+ struct strbuf path = STRBUF_INIT ;
973
967
974
968
if (!fdir )
975
969
return 0 ;
976
970
977
- memcpy ( path , base , baselen );
971
+ strbuf_add ( & path , base , baselen );
978
972
979
973
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 )) {
983
975
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 );
985
979
continue ;
986
980
case path_ignored :
987
981
continue ;
@@ -992,10 +986,11 @@ static int read_directory_recursive(struct dir_struct *dir,
992
986
if (check_only )
993
987
goto exit_early ;
994
988
else
995
- dir_add_name (dir , path , len );
989
+ dir_add_name (dir , path . buf , path . len );
996
990
}
997
991
exit_early :
998
992
closedir (fdir );
993
+ strbuf_release (& path );
999
994
1000
995
return contents ;
1001
996
}
@@ -1058,8 +1053,8 @@ static int treat_leading_path(struct dir_struct *dir,
1058
1053
const char * path , int len ,
1059
1054
const struct path_simplify * simplify )
1060
1055
{
1061
- char pathbuf [ PATH_MAX ] ;
1062
- int baselen , blen ;
1056
+ struct strbuf sb = STRBUF_INIT ;
1057
+ int baselen , rc = 0 ;
1063
1058
const char * cp ;
1064
1059
1065
1060
while (len && path [len - 1 ] == '/' )
@@ -1074,19 +1069,22 @@ static int treat_leading_path(struct dir_struct *dir,
1074
1069
baselen = len ;
1075
1070
else
1076
1071
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 ,
1085
1079
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
+ }
1089
1085
}
1086
+ strbuf_release (& sb );
1087
+ return rc ;
1090
1088
}
1091
1089
1092
1090
int read_directory (struct dir_struct * dir , const char * path , int len , const char * * pathspec )
0 commit comments