Skip to content

Commit 36a167b

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 440bc42 + 63e2eac commit 36a167b

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
@@ -810,12 +810,27 @@ static int add_excludes(const char *fname, const char *base, int baselen,
810810
size_t size = 0;
811811
char *buf;
812812

813-
fd = open(fname, O_RDONLY);
814-
if (fd < 0 || fstat(fd, &st) < 0) {
815-
if (fd < 0)
816-
warn_on_fopen_errors(fname);
817-
else
818-
close(fd);
813+
if (is_fscache_enabled()) {
814+
if (lstat(fname, &st) < 0) {
815+
fd = -1;
816+
} else {
817+
fd = open(fname, O_RDONLY);
818+
if (fd < 0)
819+
warn_on_fopen_errors(fname);
820+
}
821+
} else {
822+
fd = open(fname, O_RDONLY);
823+
if (fd < 0 || fstat(fd, &st) < 0) {
824+
if (fd < 0)
825+
warn_on_fopen_errors(fname);
826+
else {
827+
close(fd);
828+
fd = -1;
829+
}
830+
}
831+
}
832+
833+
if (fd < 0) {
819834
if (!istate)
820835
return -1;
821836
r = read_skip_worktree_file_from_index(istate, fname,

git-compat-util.h

+4
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,10 @@ static inline int is_missing_file_error(int errno_)
12611261
#define enable_fscache(x) /* noop */
12621262
#endif
12631263

1264+
#ifndef is_fscache_enabled
1265+
#define is_fscache_enabled() (0)
1266+
#endif
1267+
12641268
extern int cmd_main(int, const char **);
12651269

12661270
/*

0 commit comments

Comments
 (0)