Skip to content

Commit 1dba7a7

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 7485ed2 commit 1dba7a7

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
@@ -1562,6 +1562,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15621562
PATHSPEC_PREFER_FULL,
15631563
prefix, argv);
15641564

1565+
enable_fscache(1);
15651566
if (status_format != STATUS_FORMAT_PORCELAIN &&
15661567
status_format != STATUS_FORMAT_PORCELAIN_V2)
15671568
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

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

249250
int mingw_core_config(const char *var, const char *value, void *cb)
250251
{
@@ -256,6 +257,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
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
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
@@ -1599,6 +1599,21 @@ static inline int is_missing_file_error(int errno_)
15991599
return (errno_ == ENOENT || errno_ == ENOTDIR);
16001600
}
16011601

1602+
/*
1603+
* Enable/disable a read-only cache for file system data on platforms that
1604+
* support it.
1605+
*
1606+
* Implementing a live-cache is complicated and requires special platform
1607+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1608+
* to mark sections of git code that extensively read from the file system
1609+
* without modifying anything. Implementations can use this to cache e.g. stat
1610+
* data or even file content without the need to synchronize with the file
1611+
* system.
1612+
*/
1613+
#ifndef enable_fscache
1614+
#define enable_fscache(x) /* noop */
1615+
#endif
1616+
16021617
int cmd_main(int, const char **);
16031618

16041619
/*

preload-index.c

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

133+
enable_fscache(1);
133134
for (i = 0; i < threads; i++) {
134135
struct thread_data *p = data+i;
135136
int err;
@@ -165,6 +166,8 @@ void preload_index(struct index_state *index,
165166

166167
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
167168
trace2_region_leave("index", "preload", NULL);
169+
170+
enable_fscache(0);
168171
}
169172

170173
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)