Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 5347b02

Browse files
committed
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 3e47623 commit 5347b02

File tree

7 files changed

+32
-0
lines changed

7 files changed

+32
-0
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,12 @@ relatively high IO latencies. With this set to 'true', Git will do the
620620
index comparison to the filesystem data in parallel, allowing
621621
overlapping IO's.
622622

623+
core.fscache::
624+
Enable additional caching of file system data for some operations.
625+
+
626+
Git for Windows uses this to bulk-read and cache lstat data of entire
627+
directories (instead of doing lstat file by file).
628+
623629
core.createObject::
624630
You can set this to 'link', in which case a hardlink followed by
625631
a delete of the source are used to make sure that object creation

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12891289
PATHSPEC_PREFER_FULL,
12901290
prefix, argv);
12911291

1292+
enable_fscache(1);
12921293
read_cache_preload(&s.pathspec);
12931294
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
12941295

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ enum hide_dotfiles_type {
598598
};
599599
extern enum hide_dotfiles_type hide_dotfiles;
600600

601+
extern int core_fscache;
602+
601603
enum branch_track {
602604
BRANCH_TRACK_UNSPECIFIED = -1,
603605
BRANCH_TRACK_NEVER = 0,

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,11 @@ static int git_default_core_config(const char *var, const char *value)
890890
return 0;
891891
}
892892

893+
if (!strcmp(var, "core.fscache")) {
894+
core_fscache = git_config_bool(var, value);
895+
return 0;
896+
}
897+
893898
/* Add other config variables here and to Documentation/config.txt. */
894899
return 0;
895900
}

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
6363
struct startup_info *startup_info;
6464
unsigned long pack_size_limit_cfg;
6565
enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
66+
int core_fscache;
6667

6768
/*
6869
* The character that begins a commented line in user-editable file

git-compat-util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,19 @@ struct passwd *xgetpwuid_self(void);
731731
#define get_home_directory() getenv("HOME")
732732
#endif
733733

734+
/*
735+
* Enable/disable a read-only cache for file system data on platforms that
736+
* support it.
737+
*
738+
* Implementing a live-cache is complicated and requires special platform
739+
* support (inotify, ReadDirectoryChangesW...). enable_fscache shall be used
740+
* to mark sections of git code that extensively read from the file system
741+
* without modifying anything. Implementations can use this to cache e.g. stat
742+
* data or even file content without the need to synchronize with the file
743+
* system.
744+
*/
745+
#ifndef enable_fscache
746+
#define enable_fscache(x) /* noop */
747+
#endif
748+
734749
#endif

preload-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static void preload_index(struct index_state *index,
8383
offset = 0;
8484
work = DIV_ROUND_UP(index->cache_nr, threads);
8585
memset(&data, 0, sizeof(data));
86+
enable_fscache(1);
8687
for (i = 0; i < threads; i++) {
8788
struct thread_data *p = data+i;
8889
p->index = index;
@@ -99,6 +100,7 @@ static void preload_index(struct index_state *index,
99100
if (pthread_join(p->pthread, NULL))
100101
die("unable to join threaded lstat");
101102
}
103+
enable_fscache(0);
102104
}
103105
#endif
104106

0 commit comments

Comments
 (0)