Skip to content

Commit 2d40e26

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 5228a5a commit 2d40e26

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
@@ -685,6 +685,12 @@ relatively high IO latencies. When enabled, Git will do the
685685
index comparison to the filesystem data in parallel, allowing
686686
overlapping IO's. Defaults to true.
687687

688+
core.fscache::
689+
Enable additional caching of file system data for some operations.
690+
+
691+
Git for Windows uses this to bulk-read and cache lstat data of entire
692+
directories (instead of doing lstat file by file).
693+
688694
core.unsetenvvars::
689695
Windows-only: comma-separated list of environment variables'
690696
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
@@ -1583,6 +1583,7 @@ struct repository *repo UNUSED)
15831583
PATHSPEC_PREFER_FULL,
15841584
prefix, argv);
15851585

1586+
enable_fscache(1);
15861587
if (status_format != STATUS_FORMAT_PORCELAIN &&
15871588
status_format != STATUS_FORMAT_PORCELAIN_V2)
15881589
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ enum hide_dotfiles_type {
246246
static int core_restrict_inherited_handles = -1;
247247
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
248248
static char *unset_environment_variables;
249+
int core_fscache;
249250

250251
int mingw_core_config(const char *var, const char *value,
251252
const struct config_context *ctx UNUSED,
@@ -259,6 +260,11 @@ int mingw_core_config(const char *var, const char *value,
259260
return 0;
260261
}
261262

263+
if (!strcmp(var, "core.fscache")) {
264+
core_fscache = git_config_bool(var, value);
265+
return 0;
266+
}
267+
262268
if (!strcmp(var, "core.unsetenvvars")) {
263269
if (!value)
264270
return config_error_nonbool(var);

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
@@ -1555,6 +1555,21 @@ static inline int is_missing_file_error(int errno_)
15551555
return (errno_ == ENOENT || errno_ == ENOTDIR);
15561556
}
15571557

1558+
/*
1559+
* Enable/disable a read-only cache for file system data on platforms that
1560+
* support it.
1561+
*
1562+
* Implementing a live-cache is complicated and requires special platform
1563+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1564+
* to mark sections of git code that extensively read from the file system
1565+
* without modifying anything. Implementations can use this to cache e.g. stat
1566+
* data or even file content without the need to synchronize with the file
1567+
* system.
1568+
*/
1569+
#ifndef enable_fscache
1570+
#define enable_fscache(x) /* noop */
1571+
#endif
1572+
15581573
int cmd_main(int, const char **);
15591574

15601575
/*

preload-index.c

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

139+
enable_fscache(1);
139140
for (i = 0; i < threads; i++) {
140141
struct thread_data *p = data+i;
141142
int err;
@@ -171,6 +172,8 @@ void preload_index(struct index_state *index,
171172

172173
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
173174
trace2_region_leave("index", "preload", NULL);
175+
176+
enable_fscache(0);
174177
}
175178

176179
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)