Skip to content

Commit b9fd284

Browse files
torvaldsgitster
authored andcommitted
Export thread-safe version of 'has_symlink_leading_path()'
The threaded index preloading will want it, so that it can avoid locking by simply using a per-thread symlink/directory cache. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 867f72b commit b9fd284

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

cache.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,17 @@ struct checkout {
744744
};
745745

746746
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
747+
748+
struct cache_def {
749+
char path[PATH_MAX + 1];
750+
int len;
751+
int flags;
752+
int track_flags;
753+
int prefix_len_stat_func;
754+
};
755+
747756
extern int has_symlink_leading_path(const char *name, int len);
757+
extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
748758
extern int has_symlink_or_noent_leading_path(const char *name, int len);
749759
extern int has_dirs_only_path(const char *name, int len, int prefix_len);
750760
extern void invalidate_lstat_cache(const char *name, int len);

symlinks.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ static int longest_path_match(const char *name_a, int len_a,
3232
return match_len;
3333
}
3434

35-
static struct cache_def {
36-
char path[PATH_MAX + 1];
37-
int len;
38-
int flags;
39-
int track_flags;
40-
int prefix_len_stat_func;
41-
} default_cache;
35+
static struct cache_def default_cache;
4236

4337
static inline void reset_lstat_cache(struct cache_def *cache)
4438
{
@@ -214,15 +208,20 @@ void clear_lstat_cache(void)
214208

215209
#define USE_ONLY_LSTAT 0
216210

211+
/*
212+
* Return non-zero if path 'name' has a leading symlink component
213+
*/
214+
int threaded_has_symlink_leading_path(struct cache_def *cache, const char *name, int len)
215+
{
216+
return lstat_cache(cache, name, len, FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) & FL_SYMLINK;
217+
}
218+
217219
/*
218220
* Return non-zero if path 'name' has a leading symlink component
219221
*/
220222
int has_symlink_leading_path(const char *name, int len)
221223
{
222-
struct cache_def *cache = &default_cache; /* FIXME */
223-
return lstat_cache(cache, name, len,
224-
FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) &
225-
FL_SYMLINK;
224+
return threaded_has_symlink_leading_path(&default_cache, name, len);
226225
}
227226

228227
/*

0 commit comments

Comments
 (0)