1
1
#include "cache.h"
2
+ #include "strbuf.h"
2
3
3
4
static int threaded_check_leading_path (struct cache_def * cache , const char * name , int len );
4
5
static 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,
73
74
int prefix_len_stat_func )
74
75
{
75
76
int match_len , last_slash , last_slash_dir , previous_slash ;
76
- int save_flags , max_len , ret ;
77
+ int save_flags , ret ;
77
78
struct stat st ;
78
79
79
80
if (cache -> track_flags != track_flags ||
@@ -121,13 +122,12 @@ static int lstat_cache_matchlen(struct cache_def *cache,
121
122
*/
122
123
* ret_flags = FL_DIR ;
123
124
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 ) {
126
126
do {
127
127
cache -> path [match_len ] = name [match_len ];
128
128
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 ))
131
131
break ;
132
132
last_slash = match_len ;
133
133
cache -> path [last_slash ] = '\0' ;
@@ -273,21 +273,18 @@ static int threaded_has_dirs_only_path(struct cache_def *cache, const char *name
273
273
FL_DIR ;
274
274
}
275
275
276
- static struct removal_def {
277
- char path [PATH_MAX ];
278
- int len ;
279
- } removal ;
276
+ struct strbuf removal = STRBUF_INIT ;
280
277
281
278
static void do_remove_scheduled_dirs (int new_len )
282
279
{
283
280
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 ))
286
283
break ;
287
284
do {
288
285
removal .len -- ;
289
286
} while (removal .len > new_len &&
290
- removal .path [removal .len ] != '/' );
287
+ removal .buf [removal .len ] != '/' );
291
288
}
292
289
removal .len = new_len ;
293
290
}
@@ -297,7 +294,7 @@ void schedule_dir_for_removal(const char *name, int len)
297
294
int match_len , last_slash , i , previous_slash ;
298
295
299
296
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 ,
301
298
& previous_slash );
302
299
/* Find last slash inside 'name' */
303
300
while (i < len ) {
@@ -317,11 +314,8 @@ void schedule_dir_for_removal(const char *name, int len)
317
314
* If we go deeper down the directory tree, we only need to
318
315
* save the new path components as we go down.
319
316
*/
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 );
325
319
}
326
320
327
321
void remove_scheduled_dirs (void )
0 commit comments