Skip to content

Commit efaccdf

Browse files
kbleesGit for Windows Build Agent
authored andcommitted
mingw: add infrastructure for read-only file system level caches
Add a macro to mark code sections that only read from the file system, along with a config option and documentation. This facilitates implementation of relatively simple file system level caches without the need to synchronize with the file system. Enable read-only sections for 'git status' and preload_index. Signed-off-by: Karsten Blees <[email protected]>
1 parent b60f66e commit efaccdf

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

Documentation/config/core.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,12 @@ relatively high IO latencies. When enabled, Git will do the
690690
index comparison to the filesystem data in parallel, allowing
691691
overlapping IO's. Defaults to true.
692692

693+
core.fscache::
694+
Enable additional caching of file system data for some operations.
695+
+
696+
Git for Windows uses this to bulk-read and cache lstat data of entire
697+
directories (instead of doing lstat file by file).
698+
693699
core.unsetenvvars::
694700
Windows-only: comma-separated list of environment variables'
695701
names that need to be unset before spawning any other process.

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ struct repository *repo UNUSED)
16091609
PATHSPEC_PREFER_FULL,
16101610
prefix, argv);
16111611

1612+
enable_fscache(1);
16121613
if (status_format != STATUS_FORMAT_PORCELAIN &&
16131614
status_format != STATUS_FORMAT_PORCELAIN_V2)
16141615
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ enum hide_dotfiles_type {
248248

249249
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
250250
static char *unset_environment_variables;
251+
int core_fscache;
251252

252253
int mingw_core_config(const char *var, const char *value,
253254
const struct config_context *ctx UNUSED,
@@ -261,6 +262,11 @@ int mingw_core_config(const char *var, const char *value,
261262
return 0;
262263
}
263264

265+
if (!strcmp(var, "core.fscache")) {
266+
core_fscache = git_config_bool(var, value);
267+
return 0;
268+
}
269+
264270
if (!strcmp(var, "core.unsetenvvars")) {
265271
if (!value)
266272
return config_error_nonbool(var);

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "mingw-posix.h"
22

3+
extern int core_fscache;
4+
35
struct config_context;
46
int mingw_core_config(const char *var, const char *value,
57
const struct config_context *ctx, void *cb);

git-compat-util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,21 @@ static inline int is_missing_file_error(int errno_)
10481048
return (errno_ == ENOENT || errno_ == ENOTDIR);
10491049
}
10501050

1051+
/*
1052+
* Enable/disable a read-only cache for file system data on platforms that
1053+
* support it.
1054+
*
1055+
* Implementing a live-cache is complicated and requires special platform
1056+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1057+
* to mark sections of git code that extensively read from the file system
1058+
* without modifying anything. Implementations can use this to cache e.g. stat
1059+
* data or even file content without the need to synchronize with the file
1060+
* system.
1061+
*/
1062+
#ifndef enable_fscache
1063+
#define enable_fscache(x) /* noop */
1064+
#endif
1065+
10511066
int cmd_main(int, const char **);
10521067

10531068
/*

preload-index.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void preload_index(struct index_state *index,
141141
pthread_mutex_init(&pd.mutex, NULL);
142142
}
143143

144+
enable_fscache(1);
144145
for (i = 0; i < threads; i++) {
145146
struct thread_data *p = data+i;
146147
int err;
@@ -176,6 +177,8 @@ void preload_index(struct index_state *index,
176177

177178
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
178179
trace2_region_leave("index", "preload", NULL);
180+
181+
enable_fscache(0);
179182
}
180183

181184
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)