Skip to content

Commit 0926dd2

Browse files
kbleesdscho
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 83a756d commit 0926dd2

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

Documentation/config/core.txt

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

673+
core.fscache::
674+
Enable additional caching of file system data for some operations.
675+
+
676+
Git for Windows uses this to bulk-read and cache lstat data of entire
677+
directories (instead of doing lstat file by file).
678+
673679
core.unsetenvvars::
674680
Windows-only: comma-separated list of environment variables'
675681
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
@@ -1566,6 +1566,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15661566
PATHSPEC_PREFER_FULL,
15671567
prefix, argv);
15681568

1569+
enable_fscache(1);
15691570
if (status_format != STATUS_FORMAT_PORCELAIN &&
15701571
status_format != STATUS_FORMAT_PORCELAIN_V2)
15711572
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ enum hide_dotfiles_type {
244244
static int core_restrict_inherited_handles = -1;
245245
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
246246
static char *unset_environment_variables;
247+
int core_fscache;
247248

248249
int mingw_core_config(const char *var, const char *value,
249250
const struct config_context *ctx, void *cb)
@@ -256,6 +257,11 @@ int mingw_core_config(const char *var, const char *value,
256257
return 0;
257258
}
258259

260+
if (!strcmp(var, "core.fscache")) {
261+
core_fscache = git_config_bool(var, value);
262+
return 0;
263+
}
264+
259265
if (!strcmp(var, "core.unsetenvvars")) {
260266
free(unset_environment_variables);
261267
unset_environment_variables = xstrdup(value);

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ typedef _sigset_t sigset_t;
1111
#undef _POSIX_THREAD_SAFE_FUNCTIONS
1212
#endif
1313

14+
extern int core_fscache;
15+
1416
struct config_context;
1517
int mingw_core_config(const char *var, const char *value,
1618
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
@@ -1482,6 +1482,21 @@ static inline int is_missing_file_error(int errno_)
14821482
return (errno_ == ENOENT || errno_ == ENOTDIR);
14831483
}
14841484

1485+
/*
1486+
* Enable/disable a read-only cache for file system data on platforms that
1487+
* support it.
1488+
*
1489+
* Implementing a live-cache is complicated and requires special platform
1490+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1491+
* to mark sections of git code that extensively read from the file system
1492+
* without modifying anything. Implementations can use this to cache e.g. stat
1493+
* data or even file content without the need to synchronize with the file
1494+
* system.
1495+
*/
1496+
#ifndef enable_fscache
1497+
#define enable_fscache(x) /* noop */
1498+
#endif
1499+
14851500
int cmd_main(int, const char **);
14861501

14871502
/*

preload-index.c

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

135+
enable_fscache(1);
135136
for (i = 0; i < threads; i++) {
136137
struct thread_data *p = data+i;
137138
int err;
@@ -167,6 +168,8 @@ void preload_index(struct index_state *index,
167168

168169
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
169170
trace2_region_leave("index", "preload", NULL);
171+
172+
enable_fscache(0);
170173
}
171174

172175
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)