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

Commit c554d49

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 65e5f86 commit c554d49

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

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

1290+
enable_fscache(1);
12901291
read_cache_preload(&s.pathspec);
12911292
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
12921293

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,8 @@ enum hide_dotfiles_type {
601601
};
602602
extern enum hide_dotfiles_type hide_dotfiles;
603603

604+
extern int core_fscache;
605+
604606
enum branch_track {
605607
BRANCH_TRACK_UNSPECIFIED = -1,
606608
BRANCH_TRACK_NEVER = 0,

config.c

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

897+
if (!strcmp(var, "core.fscache")) {
898+
core_fscache = git_config_bool(var, value);
899+
return 0;
900+
}
901+
897902
/* Add other config variables here and to Documentation/config.txt. */
898903
return 0;
899904
}

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
@@ -736,4 +736,19 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
736736
#define get_home_directory() getenv("HOME")
737737
#endif
738738

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