@@ -35,12 +35,11 @@ static int longest_path_match(const char *name_a, int len_a,
35
35
return match_len ;
36
36
}
37
37
38
- static struct cache_def default_cache ;
38
+ static struct cache_def default_cache = CACHE_DEF_INIT ;
39
39
40
40
static inline void reset_lstat_cache (struct cache_def * cache )
41
41
{
42
- cache -> path [0 ] = '\0' ;
43
- cache -> len = 0 ;
42
+ strbuf_reset (& cache -> path );
44
43
cache -> flags = 0 ;
45
44
/*
46
45
* The track_flags and prefix_len_stat_func members is only
@@ -73,7 +72,7 @@ static int lstat_cache_matchlen(struct cache_def *cache,
73
72
int prefix_len_stat_func )
74
73
{
75
74
int match_len , last_slash , last_slash_dir , previous_slash ;
76
- int save_flags , max_len , ret ;
75
+ int save_flags , ret ;
77
76
struct stat st ;
78
77
79
78
if (cache -> track_flags != track_flags ||
@@ -93,14 +92,14 @@ static int lstat_cache_matchlen(struct cache_def *cache,
93
92
* the 2 "excluding" path types.
94
93
*/
95
94
match_len = last_slash =
96
- longest_path_match (name , len , cache -> path , cache -> len ,
97
- & previous_slash );
95
+ longest_path_match (name , len , cache -> path . buf ,
96
+ cache -> path . len , & previous_slash );
98
97
* ret_flags = cache -> flags & track_flags & (FL_NOENT |FL_SYMLINK );
99
98
100
99
if (!(track_flags & FL_FULLPATH ) && match_len == len )
101
100
match_len = last_slash = previous_slash ;
102
101
103
- if (* ret_flags && match_len == cache -> len )
102
+ if (* ret_flags && match_len == cache -> path . len )
104
103
return match_len ;
105
104
/*
106
105
* If we now have match_len > 0, we would know that
@@ -121,21 +120,22 @@ static int lstat_cache_matchlen(struct cache_def *cache,
121
120
*/
122
121
* ret_flags = FL_DIR ;
123
122
last_slash_dir = last_slash ;
124
- max_len = len < PATH_MAX ? len : PATH_MAX ;
125
- while (match_len < max_len ) {
123
+ if (len > cache -> path .len )
124
+ strbuf_grow (& cache -> path , len - cache -> path .len );
125
+ while (match_len < len ) {
126
126
do {
127
- cache -> path [match_len ] = name [match_len ];
127
+ cache -> path . buf [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
- cache -> path [last_slash ] = '\0' ;
133
+ cache -> path . buf [last_slash ] = '\0' ;
134
134
135
135
if (last_slash <= prefix_len_stat_func )
136
- ret = stat (cache -> path , & st );
136
+ ret = stat (cache -> path . buf , & st );
137
137
else
138
- ret = lstat (cache -> path , & st );
138
+ ret = lstat (cache -> path . buf , & st );
139
139
140
140
if (ret ) {
141
141
* ret_flags = FL_LSTATERR ;
@@ -158,12 +158,11 @@ static int lstat_cache_matchlen(struct cache_def *cache,
158
158
* for the moment!
159
159
*/
160
160
save_flags = * ret_flags & track_flags & (FL_NOENT |FL_SYMLINK );
161
- if (save_flags && last_slash > 0 && last_slash <= PATH_MAX ) {
162
- cache -> path [last_slash ] = '\0' ;
163
- cache -> len = last_slash ;
161
+ if (save_flags && last_slash > 0 ) {
162
+ cache -> path . buf [last_slash ] = '\0' ;
163
+ cache -> path . len = last_slash ;
164
164
cache -> flags = save_flags ;
165
- } else if ((track_flags & FL_DIR ) &&
166
- last_slash_dir > 0 && last_slash_dir <= PATH_MAX ) {
165
+ } else if ((track_flags & FL_DIR ) && last_slash_dir > 0 ) {
167
166
/*
168
167
* We have a separate test for the directory case,
169
168
* since it could be that we have found a symlink or a
@@ -175,8 +174,8 @@ static int lstat_cache_matchlen(struct cache_def *cache,
175
174
* can still cache the path components before the last
176
175
* one (the found symlink or non-existing component).
177
176
*/
178
- cache -> path [last_slash_dir ] = '\0' ;
179
- cache -> len = last_slash_dir ;
177
+ cache -> path . buf [last_slash_dir ] = '\0' ;
178
+ cache -> path . len = last_slash_dir ;
180
179
cache -> flags = FL_DIR ;
181
180
} else {
182
181
reset_lstat_cache (cache );
@@ -273,21 +272,18 @@ static int threaded_has_dirs_only_path(struct cache_def *cache, const char *name
273
272
FL_DIR ;
274
273
}
275
274
276
- static struct removal_def {
277
- char path [PATH_MAX ];
278
- int len ;
279
- } removal ;
275
+ static struct strbuf removal = STRBUF_INIT ;
280
276
281
277
static void do_remove_scheduled_dirs (int new_len )
282
278
{
283
279
while (removal .len > new_len ) {
284
- removal .path [removal .len ] = '\0' ;
285
- if (rmdir (removal .path ))
280
+ removal .buf [removal .len ] = '\0' ;
281
+ if (rmdir (removal .buf ))
286
282
break ;
287
283
do {
288
284
removal .len -- ;
289
285
} while (removal .len > new_len &&
290
- removal .path [removal .len ] != '/' );
286
+ removal .buf [removal .len ] != '/' );
291
287
}
292
288
removal .len = new_len ;
293
289
}
@@ -297,7 +293,7 @@ void schedule_dir_for_removal(const char *name, int len)
297
293
int match_len , last_slash , i , previous_slash ;
298
294
299
295
match_len = last_slash = i =
300
- longest_path_match (name , len , removal .path , removal .len ,
296
+ longest_path_match (name , len , removal .buf , removal .len ,
301
297
& previous_slash );
302
298
/* Find last slash inside 'name' */
303
299
while (i < len ) {
@@ -317,11 +313,8 @@ void schedule_dir_for_removal(const char *name, int len)
317
313
* If we go deeper down the directory tree, we only need to
318
314
* save the new path components as we go down.
319
315
*/
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
- }
316
+ if (match_len < last_slash )
317
+ strbuf_add (& removal , & name [match_len ], last_slash - match_len );
325
318
}
326
319
327
320
void remove_scheduled_dirs (void )
0 commit comments