Skip to content

Commit 1eecdca

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 37a5774 commit 1eecdca

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

compat/win32/fscache.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ static struct hashmap map;
1212
static CRITICAL_SECTION mutex;
1313
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
1414

15+
int fscache_is_enabled(void)
16+
{
17+
return enabled;
18+
}
19+
1520
/*
1621
* An entry in the file system cache. Used for both entire directory listings
1722
* and file entries.

compat/win32/fscache.h

Lines changed: 3 additions & 0 deletions
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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,16 +1115,31 @@ static int add_patterns(const char *fname, const char *base, int baselen,
11151115
size_t size = 0;
11161116
char *buf;
11171117

1118-
if (flags & PATTERN_NOFOLLOW)
1119-
fd = open_nofollow(fname, O_RDONLY);
1120-
else
1121-
fd = open(fname, O_RDONLY);
1122-
1123-
if (fd < 0 || fstat(fd, &st) < 0) {
1124-
if (fd < 0)
1125-
warn_on_fopen_errors(fname);
1118+
if (is_fscache_enabled()) {
1119+
if (lstat(fname, &st) < 0) {
1120+
fd = -1;
1121+
} else {
1122+
fd = open(fname, O_RDONLY);
1123+
if (fd < 0)
1124+
warn_on_fopen_errors(fname);
1125+
}
1126+
} else {
1127+
if (flags & PATTERN_NOFOLLOW)
1128+
fd = open_nofollow(fname, O_RDONLY);
11261129
else
1127-
close(fd);
1130+
fd = open(fname, O_RDONLY);
1131+
1132+
if (fd < 0 || fstat(fd, &st) < 0) {
1133+
if (fd < 0)
1134+
warn_on_fopen_errors(fname);
1135+
else {
1136+
close(fd);
1137+
fd = -1;
1138+
}
1139+
}
1140+
}
1141+
1142+
if (fd < 0) {
11281143
if (!istate)
11291144
return -1;
11301145
r = read_skip_worktree_file_from_index(istate, fname,

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,10 @@ static inline int is_missing_file_error(int errno_)
15721572
#define enable_fscache(x) /* noop */
15731573
#endif
15741574

1575+
#ifndef is_fscache_enabled
1576+
#define is_fscache_enabled() (0)
1577+
#endif
1578+
15751579
int cmd_main(int, const char **);
15761580

15771581
/*

0 commit comments

Comments
 (0)