11#include "cache.h"
2+ #include "strbuf.h"
23
34static int threaded_check_leading_path (struct cache_def * cache , const char * name , int len );
45static int threaded_has_dirs_only_path (struct cache_def * cache , const char * name , int len , int prefix_len );
@@ -73,7 +74,7 @@ static int lstat_cache_matchlen(struct cache_def *cache,
7374 int prefix_len_stat_func )
7475{
7576 int match_len , last_slash , last_slash_dir , previous_slash ;
76- int save_flags , max_len , ret ;
77+ int save_flags , ret ;
7778 struct stat st ;
7879
7980 if (cache -> track_flags != track_flags ||
@@ -121,13 +122,12 @@ static int lstat_cache_matchlen(struct cache_def *cache,
121122 */
122123 * ret_flags = FL_DIR ;
123124 last_slash_dir = last_slash ;
124- max_len = len < PATH_MAX ? len : PATH_MAX ;
125- while (match_len < max_len ) {
125+ while (match_len < len ) {
126126 do {
127127 cache -> path [match_len ] = name [match_len ];
128128 match_len ++ ;
129- } while (match_len < max_len && name [match_len ] != '/' );
130- if (match_len >= max_len && !(track_flags & FL_FULLPATH ))
129+ } while (match_len < len && name [match_len ] != '/' );
130+ if (match_len >= len && !(track_flags & FL_FULLPATH ))
131131 break ;
132132 last_slash = match_len ;
133133 cache -> path [last_slash ] = '\0' ;
@@ -273,21 +273,18 @@ static int threaded_has_dirs_only_path(struct cache_def *cache, const char *name
273273 FL_DIR ;
274274}
275275
276- static struct removal_def {
277- char path [PATH_MAX ];
278- int len ;
279- } removal ;
276+ struct strbuf removal = STRBUF_INIT ;
280277
281278static void do_remove_scheduled_dirs (int new_len )
282279{
283280 while (removal .len > new_len ) {
284- removal .path [removal .len ] = '\0' ;
285- if (rmdir (removal .path ))
281+ removal .buf [removal .len ] = '\0' ;
282+ if (rmdir (removal .buf ))
286283 break ;
287284 do {
288285 removal .len -- ;
289286 } while (removal .len > new_len &&
290- removal .path [removal .len ] != '/' );
287+ removal .buf [removal .len ] != '/' );
291288 }
292289 removal .len = new_len ;
293290}
@@ -297,7 +294,7 @@ void schedule_dir_for_removal(const char *name, int len)
297294 int match_len , last_slash , i , previous_slash ;
298295
299296 match_len = last_slash = i =
300- longest_path_match (name , len , removal .path , removal .len ,
297+ longest_path_match (name , len , removal .buf , removal .len ,
301298 & previous_slash );
302299 /* Find last slash inside 'name' */
303300 while (i < len ) {
@@ -317,11 +314,8 @@ void schedule_dir_for_removal(const char *name, int len)
317314 * If we go deeper down the directory tree, we only need to
318315 * save the new path components as we go down.
319316 */
320- if (match_len < last_slash ) {
321- memcpy (& removal .path [match_len ], & name [match_len ],
322- last_slash - match_len );
323- removal .len = last_slash ;
324- }
317+ if (match_len < last_slash )
318+ strbuf_add (& removal , & name [match_len ], last_slash - match_len );
325319}
326320
327321void remove_scheduled_dirs (void )
0 commit comments