Avoid doing extra 'lstat()'s for d_type if we have an up-to-date cache entry
On filesystems without d_type, we can look at the cache entry first. Doing an lstat() can be expensive. Reported by Dmitry Potapov for Cygwin. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
dba2e2037f
commit
caa6b7825a
14
dir.c
14
dir.c
@ -16,7 +16,7 @@ struct path_simplify {
|
|||||||
|
|
||||||
static int read_directory_recursive(struct dir_struct *dir, const char *path, int len,
|
static int read_directory_recursive(struct dir_struct *dir, const char *path, int len,
|
||||||
int check_only, const struct path_simplify *simplify);
|
int check_only, const struct path_simplify *simplify);
|
||||||
static int get_dtype(struct dirent *de, const char *path);
|
static int get_dtype(struct dirent *de, const char *path, int len);
|
||||||
|
|
||||||
static int common_prefix(const char **pathspec)
|
static int common_prefix(const char **pathspec)
|
||||||
{
|
{
|
||||||
@ -326,7 +326,7 @@ static int excluded_1(const char *pathname,
|
|||||||
|
|
||||||
if (x->flags & EXC_FLAG_MUSTBEDIR) {
|
if (x->flags & EXC_FLAG_MUSTBEDIR) {
|
||||||
if (*dtype == DT_UNKNOWN)
|
if (*dtype == DT_UNKNOWN)
|
||||||
*dtype = get_dtype(NULL, pathname);
|
*dtype = get_dtype(NULL, pathname, pathlen);
|
||||||
if (*dtype != DT_DIR)
|
if (*dtype != DT_DIR)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -566,14 +566,18 @@ static int in_pathspec(const char *path, int len, const struct path_simplify *si
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_dtype(struct dirent *de, const char *path)
|
static int get_dtype(struct dirent *de, const char *path, int len)
|
||||||
{
|
{
|
||||||
int dtype = de ? DTYPE(de) : DT_UNKNOWN;
|
int dtype = de ? DTYPE(de) : DT_UNKNOWN;
|
||||||
|
struct cache_entry *ce;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (dtype != DT_UNKNOWN)
|
if (dtype != DT_UNKNOWN)
|
||||||
return dtype;
|
return dtype;
|
||||||
if (lstat(path, &st))
|
ce = cache_name_exists(path, len, 0);
|
||||||
|
if (ce && ce_uptodate(ce))
|
||||||
|
st.st_mode = ce->ce_mode;
|
||||||
|
else if (lstat(path, &st))
|
||||||
return dtype;
|
return dtype;
|
||||||
if (S_ISREG(st.st_mode))
|
if (S_ISREG(st.st_mode))
|
||||||
return DT_REG;
|
return DT_REG;
|
||||||
@ -633,7 +637,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *base, in
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (dtype == DT_UNKNOWN)
|
if (dtype == DT_UNKNOWN)
|
||||||
dtype = get_dtype(de, path);
|
dtype = get_dtype(de, path, len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do we want to see just the ignored files?
|
* Do we want to see just the ignored files?
|
||||||
|
Loading…
Reference in New Issue
Block a user