Skip to content

Commit 8223eb3

Browse files
kbleesdscho
authored andcommitted
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 e6c805f commit 8223eb3

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

Documentation/config/core.txt

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

556+
core.fscache::
557+
Enable additional caching of file system data for some operations.
558+
+
559+
Git for Windows uses this to bulk-read and cache lstat data of entire
560+
directories (instead of doing lstat file by file).
561+
556562
core.unsetenvvars::
557563
Windows-only: comma-separated list of environment variables'
558564
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
@@ -1413,6 +1413,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14131413
PATHSPEC_PREFER_FULL,
14141414
prefix, argv);
14151415

1416+
enable_fscache(1);
14161417
if (status_format != STATUS_FORMAT_PORCELAIN &&
14171418
status_format != STATUS_FORMAT_PORCELAIN_V2)
14181419
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ enum hide_dotfiles_type {
229229
static int core_restrict_inherited_handles = -1;
230230
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
231231
static char *unset_environment_variables;
232+
int core_fscache;
232233

233234
int mingw_core_config(const char *var, const char *value, void *cb)
234235
{
@@ -240,6 +241,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
240241
return 0;
241242
}
242243

244+
if (!strcmp(var, "core.fscache")) {
245+
core_fscache = git_config_bool(var, value);
246+
return 0;
247+
}
248+
243249
if (!strcmp(var, "core.unsetenvvars")) {
244250
free(unset_environment_variables);
245251
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
int mingw_core_config(const char *var, const char *value, void *cb);
1517
#define platform_core_config mingw_core_config
1618

git-compat-util.h

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

1269+
/*
1270+
* Enable/disable a read-only cache for file system data on platforms that
1271+
* support it.
1272+
*
1273+
* Implementing a live-cache is complicated and requires special platform
1274+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1275+
* to mark sections of git code that extensively read from the file system
1276+
* without modifying anything. Implementations can use this to cache e.g. stat
1277+
* data or even file content without the need to synchronize with the file
1278+
* system.
1279+
*/
1280+
#ifndef enable_fscache
1281+
#define enable_fscache(x) /* noop */
1282+
#endif
1283+
12691284
int cmd_main(int, const char **);
12701285

12711286
/*

preload-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void preload_index(struct index_state *index,
120120
pthread_mutex_init(&pd.mutex, NULL);
121121
}
122122

123+
enable_fscache(1);
123124
for (i = 0; i < threads; i++) {
124125
struct thread_data *p = data+i;
125126
int err;
@@ -145,6 +146,7 @@ void preload_index(struct index_state *index,
145146
stop_progress(&pd.progress);
146147

147148
trace_performance_leave("preload index");
149+
enable_fscache(0);
148150
}
149151

150152
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)