Skip to content

Commit fff578e

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 <blees@dcon.de>
1 parent f9a3ac1 commit fff578e

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

Documentation/config.txt

+6
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,12 @@ relatively high IO latencies. When enabled, Git will do the
909909
index comparison to the filesystem data in parallel, allowing
910910
overlapping IO's. Defaults to true.
911911

912+
core.fscache::
913+
Enable additional caching of file system data for some operations.
914+
+
915+
Git for Windows uses this to bulk-read and cache lstat data of entire
916+
directories (instead of doing lstat file by file).
917+
912918
core.unsetenvvars::
913919
EXPERIMENTAL, Windows-only: comma-separated list of environment
914920
variables' names that need to be unset before spawning any other

builtin/commit.c

+1
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13551355
PATHSPEC_PREFER_FULL,
13561356
prefix, argv);
13571357

1358+
enable_fscache(1);
13581359
read_cache_preload(&s.pathspec);
13591360
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13601361

compat/mingw.c

+6
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ enum hide_dotfiles_type {
212212

213213
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
214214
static char *unset_environment_variables;
215+
int core_fscache;
215216

216217
int mingw_core_config(const char *var, const char *value, void *cb)
217218
{
@@ -223,6 +224,11 @@ int mingw_core_config(const char *var, const char *value, void *cb)
223224
return 0;
224225
}
225226

227+
if (!strcmp(var, "core.fscache")) {
228+
core_fscache = git_config_bool(var, value);
229+
return 0;
230+
}
231+
226232
if (!strcmp(var, "core.unsetenvvars")) {
227233
free(unset_environment_variables);
228234
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
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

+15
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,21 @@ static inline int is_missing_file_error(int errno_)
12341234
return (errno_ == ENOENT || errno_ == ENOTDIR);
12351235
}
12361236

1237+
/*
1238+
* Enable/disable a read-only cache for file system data on platforms that
1239+
* support it.
1240+
*
1241+
* Implementing a live-cache is complicated and requires special platform
1242+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
1243+
* to mark sections of git code that extensively read from the file system
1244+
* without modifying anything. Implementations can use this to cache e.g. stat
1245+
* data or even file content without the need to synchronize with the file
1246+
* system.
1247+
*/
1248+
#ifndef enable_fscache
1249+
#define enable_fscache(x) /* noop */
1250+
#endif
1251+
12371252
extern int cmd_main(int, const char **);
12381253

12391254
/*

preload-index.c

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static void preload_index(struct index_state *index,
9393
offset = 0;
9494
work = DIV_ROUND_UP(index->cache_nr, threads);
9595
memset(&data, 0, sizeof(data));
96+
enable_fscache(1);
9697
for (i = 0; i < threads; i++) {
9798
struct thread_data *p = data+i;
9899
p->index = index;
@@ -110,6 +111,7 @@ static void preload_index(struct index_state *index,
110111
die("unable to join threaded lstat");
111112
}
112113
trace_performance_since(start, "preload index");
114+
enable_fscache(0);
113115
}
114116
#endif
115117

0 commit comments

Comments
 (0)