@@ -64,11 +64,13 @@ static inline void reset_lstat_cache(struct cache_def *cache)
64
64
* of the prefix, where the cache should use the stat() function
65
65
* instead of the lstat() function to test each path component.
66
66
*/
67
- static int lstat_cache (struct cache_def * cache , const char * name , int len ,
68
- int track_flags , int prefix_len_stat_func )
67
+ static int lstat_cache_matchlen (struct cache_def * cache ,
68
+ const char * name , int len ,
69
+ int * ret_flags , int track_flags ,
70
+ int prefix_len_stat_func )
69
71
{
70
72
int match_len , last_slash , last_slash_dir , previous_slash ;
71
- int match_flags , ret_flags , save_flags , max_len , ret ;
73
+ int save_flags , max_len , ret ;
72
74
struct stat st ;
73
75
74
76
if (cache -> track_flags != track_flags ||
@@ -90,13 +92,13 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
90
92
match_len = last_slash =
91
93
longest_path_match (name , len , cache -> path , cache -> len ,
92
94
& previous_slash );
93
- match_flags = cache -> flags & track_flags & (FL_NOENT |FL_SYMLINK );
95
+ * ret_flags = cache -> flags & track_flags & (FL_NOENT |FL_SYMLINK );
94
96
95
97
if (!(track_flags & FL_FULLPATH ) && match_len == len )
96
98
match_len = last_slash = previous_slash ;
97
99
98
- if (match_flags && match_len == cache -> len )
99
- return match_flags ;
100
+ if (* ret_flags && match_len == cache -> len )
101
+ return match_len ;
100
102
/*
101
103
* If we now have match_len > 0, we would know that
102
104
* the matched part will always be a directory.
@@ -105,16 +107,16 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
105
107
* a substring of the cache on a path component basis,
106
108
* we can return immediately.
107
109
*/
108
- match_flags = track_flags & FL_DIR ;
109
- if (match_flags && len == match_len )
110
- return match_flags ;
110
+ * ret_flags = track_flags & FL_DIR ;
111
+ if (* ret_flags && len == match_len )
112
+ return match_len ;
111
113
}
112
114
113
115
/*
114
116
* Okay, no match from the cache so far, so now we have to
115
117
* check the rest of the path components.
116
118
*/
117
- ret_flags = FL_DIR ;
119
+ * ret_flags = FL_DIR ;
118
120
last_slash_dir = last_slash ;
119
121
max_len = len < PATH_MAX ? len : PATH_MAX ;
120
122
while (match_len < max_len ) {
@@ -133,16 +135,16 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
133
135
ret = lstat (cache -> path , & st );
134
136
135
137
if (ret ) {
136
- ret_flags = FL_LSTATERR ;
138
+ * ret_flags = FL_LSTATERR ;
137
139
if (errno == ENOENT )
138
- ret_flags |= FL_NOENT ;
140
+ * ret_flags |= FL_NOENT ;
139
141
} else if (S_ISDIR (st .st_mode )) {
140
142
last_slash_dir = last_slash ;
141
143
continue ;
142
144
} else if (S_ISLNK (st .st_mode )) {
143
- ret_flags = FL_SYMLINK ;
145
+ * ret_flags = FL_SYMLINK ;
144
146
} else {
145
- ret_flags = FL_ERR ;
147
+ * ret_flags = FL_ERR ;
146
148
}
147
149
break ;
148
150
}
@@ -152,7 +154,7 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
152
154
* path types, FL_NOENT, FL_SYMLINK and FL_DIR, can be cached
153
155
* for the moment!
154
156
*/
155
- save_flags = ret_flags & track_flags & (FL_NOENT |FL_SYMLINK );
157
+ save_flags = * ret_flags & track_flags & (FL_NOENT |FL_SYMLINK );
156
158
if (save_flags && last_slash > 0 && last_slash <= PATH_MAX ) {
157
159
cache -> path [last_slash ] = '\0' ;
158
160
cache -> len = last_slash ;
@@ -176,7 +178,16 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
176
178
} else {
177
179
reset_lstat_cache (cache );
178
180
}
179
- return ret_flags ;
181
+ return match_len ;
182
+ }
183
+
184
+ static int lstat_cache (struct cache_def * cache , const char * name , int len ,
185
+ int track_flags , int prefix_len_stat_func )
186
+ {
187
+ int flags ;
188
+ (void )lstat_cache_matchlen (cache , name , len , & flags , track_flags ,
189
+ prefix_len_stat_func );
190
+ return flags ;
180
191
}
181
192
182
193
#define USE_ONLY_LSTAT 0
0 commit comments