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

Commit e462944

Browse files
kbleeskasal
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 0ac3c91 commit e462944

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
@@ -623,6 +623,12 @@ relatively high IO latencies. With this set to 'true', Git will do the
623623
index comparison to the filesystem data in parallel, allowing
624624
overlapping IO's.
625625

626+
core.fscache::
627+
Enable additional caching of file system data for some operations.
628+
+
629+
Git for Windows uses this to bulk-read and cache lstat data of entire
630+
directories (instead of doing lstat file by file).
631+
626632
core.createObject::
627633
You can set this to 'link', in which case a hardlink followed by
628634
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
@@ -1296,6 +1296,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12961296
PATHSPEC_PREFER_FULL,
12971297
prefix, argv);
12981298

1299+
enable_fscache(1);
12991300
read_cache_preload(&s.pathspec);
13001301
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
13011302

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ enum hide_dotfiles_type {
610610
};
611611
extern enum hide_dotfiles_type hide_dotfiles;
612612

613+
extern int core_fscache;
614+
613615
enum branch_track {
614616
BRANCH_TRACK_UNSPECIFIED = -1,
615617
BRANCH_TRACK_NEVER = 0,

config.c

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

886+
if (!strcmp(var, "core.fscache")) {
887+
core_fscache = git_config_bool(var, value);
888+
return 0;
889+
}
890+
886891
/* Add other config variables here and to Documentation/config.txt. */
887892
return 0;
888893
}

environment.c

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

6869
/*
6970
* 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 tm *git_gmtime_r(const time_t *, struct tm *);
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
@@ -84,6 +84,7 @@ static void preload_index(struct index_state *index,
8484
offset = 0;
8585
work = DIV_ROUND_UP(index->cache_nr, threads);
8686
memset(&data, 0, sizeof(data));
87+
enable_fscache(1);
8788
for (i = 0; i < threads; i++) {
8889
struct thread_data *p = data+i;
8990
p->index = index;
@@ -100,6 +101,7 @@ static void preload_index(struct index_state *index,
100101
if (pthread_join(p->pthread, NULL))
101102
die("unable to join threaded lstat");
102103
}
104+
enable_fscache(0);
103105
}
104106
#endif
105107

0 commit comments

Comments
 (0)