Skip to content

Commit ae56627

Browse files
jeffhostetlerdscho
authored andcommitted
dir.c: make add_excludes aware of fscache during status
Teach read_directory_recursive() and add_excludes() to be aware of optional fscache and avoid trying to open() and fstat() non-existant ".gitignore" files in every directory in the worktree. The current code in add_excludes() calls open() and then fstat() for a ".gitignore" file in each directory present in the worktree. Change that when fscache is enabled to call lstat() first and if present, call open(). This seems backwards because both lstat needs to do more work than fstat. But when fscache is enabled, fscache will already know if the .gitignore file exists and can completely avoid the IO calls. This works because of the lstat diversion to mingw_lstat when fscache is enabled. This reduced status times on a 350K file enlistment of the Windows repo on a NVMe SSD by 0.25 seconds. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 411e669 commit ae56627

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

compat/win32/fscache.c

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

13+
int fscache_is_enabled(void)
14+
{
15+
return enabled;
16+
}
17+
1318
/*
1419
* An entry in the file system cache. Used for both entire directory listings
1520
* 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

+24-9
Original file line numberDiff line numberDiff line change
@@ -1061,16 +1061,31 @@ static int add_patterns(const char *fname, const char *base, int baselen,
10611061
size_t size = 0;
10621062
char *buf;
10631063

1064-
if (flags & PATTERN_NOFOLLOW)
1065-
fd = open_nofollow(fname, O_RDONLY);
1066-
else
1067-
fd = open(fname, O_RDONLY);
1068-
1069-
if (fd < 0 || fstat(fd, &st) < 0) {
1070-
if (fd < 0)
1071-
warn_on_fopen_errors(fname);
1064+
if (is_fscache_enabled()) {
1065+
if (lstat(fname, &st) < 0) {
1066+
fd = -1;
1067+
} else {
1068+
fd = open(fname, O_RDONLY);
1069+
if (fd < 0)
1070+
warn_on_fopen_errors(fname);
1071+
}
1072+
} else {
1073+
if (flags & PATTERN_NOFOLLOW)
1074+
fd = open_nofollow(fname, O_RDONLY);
10721075
else
1073-
close(fd);
1076+
fd = open(fname, O_RDONLY);
1077+
1078+
if (fd < 0 || fstat(fd, &st) < 0) {
1079+
if (fd < 0)
1080+
warn_on_fopen_errors(fname);
1081+
else {
1082+
close(fd);
1083+
fd = -1;
1084+
}
1085+
}
1086+
}
1087+
1088+
if (fd < 0) {
10741089
if (!istate)
10751090
return -1;
10761091
r = read_skip_worktree_file_from_index(istate, fname,

git-compat-util.h

+4
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,10 @@ static inline int is_missing_file_error(int errno_)
15521552
#define enable_fscache(x) /* noop */
15531553
#endif
15541554

1555+
#ifndef is_fscache_enabled
1556+
#define is_fscache_enabled() (0)
1557+
#endif
1558+
15551559
int cmd_main(int, const char **);
15561560

15571561
/*

0 commit comments

Comments
 (0)