Skip to content

Commit 9530b39

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 d532d85 commit 9530b39

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

Documentation/config/core.txt

+6
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

+1
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15511551
PATHSPEC_PREFER_FULL,
15521552
prefix, argv);
15531553

1554+
enable_fscache(1);
15541555
if (status_format != STATUS_FORMAT_PORCELAIN &&
15551556
status_format != STATUS_FORMAT_PORCELAIN_V2)
15561557
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

+6
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ enum hide_dotfiles_type {
236236
static int core_restrict_inherited_handles = -1;
237237
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
238238
static char *unset_environment_variables;
239+
int core_fscache;
239240

240241
int mingw_core_config(const char *var, const char *value, void *cb)
241242
{
@@ -247,6 +248,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
247248
return 0;
248249
}
249250

251+
if (!strcmp(var, "core.fscache")) {
252+
core_fscache = git_config_bool(var, value);
253+
return 0;
254+
}
255+
250256
if (!strcmp(var, "core.unsetenvvars")) {
251257
free(unset_environment_variables);
252258
unset_environment_variables = xstrdup(value);

compat/mingw.h

+2
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

+15
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,21 @@ static inline int is_missing_file_error(int errno_)
15351535
return (errno_ == ENOENT || errno_ == ENOTDIR);
15361536
}
15371537

1538+
/*
1539+
* Enable/disable a read-only cache for file system data on platforms that
1540+
* support it.
1541+
*
1542+
* Implementing a live-cache is complicated and requires special platform
1543+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1544+
* to mark sections of git code that extensively read from the file system
1545+
* without modifying anything. Implementations can use this to cache e.g. stat
1546+
* data or even file content without the need to synchronize with the file
1547+
* system.
1548+
*/
1549+
#ifndef enable_fscache
1550+
#define enable_fscache(x) /* noop */
1551+
#endif
1552+
15381553
int cmd_main(int, const char **);
15391554

15401555
/*

preload-index.c

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void preload_index(struct index_state *index,
126126
pthread_mutex_init(&pd.mutex, NULL);
127127
}
128128

129+
enable_fscache(1);
129130
for (i = 0; i < threads; i++) {
130131
struct thread_data *p = data+i;
131132
int err;
@@ -161,6 +162,8 @@ void preload_index(struct index_state *index,
161162

162163
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
163164
trace2_region_leave("index", "preload", NULL);
165+
166+
enable_fscache(0);
164167
}
165168

166169
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)