Skip to content

Commit

Permalink
Export thread-safe version of 'has_symlink_leading_path()'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jul 10, 2009
1 parent 867f72b commit b9fd284
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
10 changes: 10 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,17 @@ struct checkout {
};

extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);

struct cache_def {
char path[PATH_MAX + 1];
int len;
int flags;
int track_flags;
int prefix_len_stat_func;
};

extern int has_symlink_leading_path(const char *name, int len);
extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
extern int has_symlink_or_noent_leading_path(const char *name, int len);
extern int has_dirs_only_path(const char *name, int len, int prefix_len);
extern void invalidate_lstat_cache(const char *name, int len);
Expand Down
21 changes: 10 additions & 11 deletions symlinks.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ static int longest_path_match(const char *name_a, int len_a,
return match_len;
}

static struct cache_def {
char path[PATH_MAX + 1];
int len;
int flags;
int track_flags;
int prefix_len_stat_func;
} default_cache;
static struct cache_def default_cache;

static inline void reset_lstat_cache(struct cache_def *cache)
{
Expand Down Expand Up @@ -214,15 +208,20 @@ void clear_lstat_cache(void)

#define USE_ONLY_LSTAT 0

/*
* Return non-zero if path 'name' has a leading symlink component
*/
int threaded_has_symlink_leading_path(struct cache_def *cache, const char *name, int len)
{
return lstat_cache(cache, name, len, FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) & FL_SYMLINK;
}

/*
* Return non-zero if path 'name' has a leading symlink component
*/
int has_symlink_leading_path(const char *name, int len)
{
struct cache_def *cache = &default_cache; /* FIXME */
return lstat_cache(cache, name, len,
FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) &
FL_SYMLINK;
return threaded_has_symlink_leading_path(&default_cache, name, len);
}

/*
Expand Down

0 comments on commit b9fd284

Please sign in to comment.