Skip to content

Commit c5e9978

Browse files
jeffhostetlerGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
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 8da718e commit c5e9978

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
@@ -805,12 +805,27 @@ static int add_excludes(const char *fname, const char *base, int baselen,
805805
size_t size = 0;
806806
char *buf;
807807

808-
fd = open(fname, O_RDONLY);
809-
if (fd < 0 || fstat(fd, &st) < 0) {
810-
if (fd < 0)
811-
warn_on_fopen_errors(fname);
812-
else
813-
close(fd);
808+
if (is_fscache_enabled()) {
809+
if (lstat(fname, &st) < 0) {
810+
fd = -1;
811+
} else {
812+
fd = open(fname, O_RDONLY);
813+
if (fd < 0)
814+
warn_on_fopen_errors(fname);
815+
}
816+
} else {
817+
fd = open(fname, O_RDONLY);
818+
if (fd < 0 || fstat(fd, &st) < 0) {
819+
if (fd < 0)
820+
warn_on_fopen_errors(fname);
821+
else {
822+
close(fd);
823+
fd = -1;
824+
}
825+
}
826+
}
827+
828+
if (fd < 0) {
814829
if (!istate)
815830
return -1;
816831
r = read_skip_worktree_file_from_index(istate, fname,

git-compat-util.h

+4
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,10 @@ static inline int is_missing_file_error(int errno_)
12781278
#define enable_fscache(x) /* noop */
12791279
#endif
12801280

1281+
#ifndef is_fscache_enabled
1282+
#define is_fscache_enabled() (0)
1283+
#endif
1284+
12811285
extern int cmd_main(int, const char **);
12821286

12831287
/*

0 commit comments

Comments
 (0)