@matheusbsbs / matheus-bagliano / commits / b9fd284657
Fork 0

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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Jul 9, 2009 at 13:35 UTC b9fd284657de3ec30922fb17c0baf243ae947fdd
2 files changed +20 -11
cache.h
+10
@@ -744,7 +744,17 @@ struct checkout {
744 };
745
746 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 +
756 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);
758 extern int has_symlink_or_noent_leading_path(const char *name, int len);
759 extern int has_dirs_only_path(const char *name, int len, int prefix_len);
760 extern void invalidate_lstat_cache(const char *name, int len);
symlinks.c
+10 -11
@@ -32,13 +32,7 @@ static int longest_path_match(const char *name_a, int len_a,
32 return match_len;
33 }
34
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;
36
37 static inline void reset_lstat_cache(struct cache_def *cache)
38 {
@@ -214,15 +208,20 @@ void clear_lstat_cache(void)
208
209 #define USE_ONLY_LSTAT 0
210
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 +
219 /*
220 * Return non-zero if path 'name' has a leading symlink component
221 */
222 int has_symlink_leading_path(const char *name, int len)
223 {
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);
225 }
226
227 /*