Skip to content

Commit cc8d7af

Browse files
committed
Merge pull request #1344 from jeffhostetler/perf_add_excludes_with_fscache
dir.c: make add_excludes aware of fscache during status
2 parents 045e8ff + 728edb9 commit cc8d7af

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

compat/win32/fscache.c

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ static struct hashmap map;
99
static CRITICAL_SECTION mutex;
1010
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
1111

12+
int fscache_is_enabled(void)
13+
{
14+
return enabled;
15+
}
16+
1217
/*
1318
* An entry in the file system cache. Used for both entire directory listings
1419
* and file entries.

compat/win32/fscache.h

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
int fscache_enable(int enable);
55
#define enable_fscache(x) fscache_enable(x)
66

7+
int fscache_is_enabled(void);
8+
#define is_fscache_enabled() (fscache_is_enabled())
9+
710
DIR *fscache_opendir(const char *dir);
811
int fscache_lstat(const char *file_name, struct stat *buf);
912

dir.c

+21-6
Original file line numberDiff line numberDiff line change
@@ -758,12 +758,27 @@ static int add_excludes(const char *fname, const char *base, int baselen,
758758
size_t size = 0;
759759
char *buf, *entry;
760760

761-
fd = open(fname, O_RDONLY);
762-
if (fd < 0 || fstat(fd, &st) < 0) {
763-
if (fd < 0)
764-
warn_on_fopen_errors(fname);
765-
else
766-
close(fd);
761+
if (is_fscache_enabled()) {
762+
if (lstat(fname, &st) < 0) {
763+
fd = -1;
764+
} else {
765+
fd = open(fname, O_RDONLY);
766+
if (fd < 0)
767+
warn_on_fopen_errors(fname);
768+
}
769+
} else {
770+
fd = open(fname, O_RDONLY);
771+
if (fd < 0 || fstat(fd, &st) < 0) {
772+
if (fd < 0)
773+
warn_on_fopen_errors(fname);
774+
else {
775+
close(fd);
776+
fd = -1;
777+
}
778+
}
779+
}
780+
781+
if (fd < 0) {
767782
if (!istate ||
768783
(buf = read_skip_worktree_file_from_index(istate, fname, &size, sha1_stat)) == NULL)
769784
return -1;

git-compat-util.h

+4
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,10 @@ static inline int is_missing_file_error(int errno_)
12551255
#define enable_fscache(x) /* noop */
12561256
#endif
12571257

1258+
#ifndef is_fscache_enabled
1259+
#define is_fscache_enabled() (0)
1260+
#endif
1261+
12581262
extern int cmd_main(int, const char **);
12591263

12601264
/*

0 commit comments

Comments
 (0)