Skip to content

Commit 8f1c274

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 5ba68d0 commit 8f1c274

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

658+
core.fscache::
659+
Enable additional caching of file system data for some operations.
660+
+
661+
Git for Windows uses this to bulk-read and cache lstat data of entire
662+
directories (instead of doing lstat file by file).
663+
658664
core.unsetenvvars::
659665
Windows-only: comma-separated list of environment variables'
660666
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
@@ -1540,6 +1540,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15401540
PATHSPEC_PREFER_FULL,
15411541
prefix, argv);
15421542

1543+
enable_fscache(1);
15431544
if (status_format != STATUS_FORMAT_PORCELAIN &&
15441545
status_format != STATUS_FORMAT_PORCELAIN_V2)
15451546
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ enum hide_dotfiles_type {
233233
static int core_restrict_inherited_handles = -1;
234234
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
235235
static char *unset_environment_variables;
236+
int core_fscache;
236237

237238
int mingw_core_config(const char *var, const char *value, void *cb)
238239
{
@@ -244,6 +245,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
244245
return 0;
245246
}
246247

248+
if (!strcmp(var, "core.fscache")) {
249+
core_fscache = git_config_bool(var, value);
250+
return 0;
251+
}
252+
247253
if (!strcmp(var, "core.unsetenvvars")) {
248254
free(unset_environment_variables);
249255
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
@@ -1404,6 +1404,21 @@ static inline int is_missing_file_error(int errno_)
14041404
return (errno_ == ENOENT || errno_ == ENOTDIR);
14051405
}
14061406

1407+
/*
1408+
* Enable/disable a read-only cache for file system data on platforms that
1409+
* support it.
1410+
*
1411+
* Implementing a live-cache is complicated and requires special platform
1412+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1413+
* to mark sections of git code that extensively read from the file system
1414+
* without modifying anything. Implementations can use this to cache e.g. stat
1415+
* data or even file content without the need to synchronize with the file
1416+
* system.
1417+
*/
1418+
#ifndef enable_fscache
1419+
#define enable_fscache(x) /* noop */
1420+
#endif
1421+
14071422
int cmd_main(int, const char **);
14081423

14091424
/*

preload-index.c

Lines changed: 3 additions & 0 deletions
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;
@@ -155,6 +156,8 @@ void preload_index(struct index_state *index,
155156

156157
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
157158
trace2_region_leave("index", "preload", NULL);
159+
160+
enable_fscache(0);
158161
}
159162

160163
int repo_read_index_preload(struct repository *repo,

0 commit comments

Comments
 (0)