Skip to content

Commit ef1c414

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 700965f commit ef1c414

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

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

1374+
enable_fscache(1);
13741375
if (status_format != STATUS_FORMAT_PORCELAIN &&
13751376
status_format != STATUS_FORMAT_PORCELAIN_V2)
13761377
progress_flag = REFRESH_PROGRESS;

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ enum hide_dotfiles_type {
227227

228228
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
229229
static char *unset_environment_variables;
230+
int core_fscache;
230231

231232
int mingw_core_config(const char *var, const char *value, void *cb)
232233
{
@@ -238,6 +239,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
238239
return 0;
239240
}
240241

242+
if (!strcmp(var, "core.fscache")) {
243+
core_fscache = git_config_bool(var, value);
244+
return 0;
245+
}
246+
241247
if (!strcmp(var, "core.unsetenvvars")) {
242248
free(unset_environment_variables);
243249
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
extern 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
@@ -1281,6 +1281,21 @@ static inline int is_missing_file_error(int errno_)
12811281
return (errno_ == ENOENT || errno_ == ENOTDIR);
12821282
}
12831283

1284+
/*
1285+
* Enable/disable a read-only cache for file system data on platforms that
1286+
* support it.
1287+
*
1288+
* Implementing a live-cache is complicated and requires special platform
1289+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1290+
* to mark sections of git code that extensively read from the file system
1291+
* without modifying anything. Implementations can use this to cache e.g. stat
1292+
* data or even file content without the need to synchronize with the file
1293+
* system.
1294+
*/
1295+
#ifndef enable_fscache
1296+
#define enable_fscache(x) /* noop */
1297+
#endif
1298+
12841299
int cmd_main(int, const char **);
12851300

12861301
/*

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)