diff --git a/builtin/add.c b/builtin/add.c index f8ebf1c8e3..1fab75ff6e 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -461,7 +461,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) die_path_inside_submodule(&the_index, &pathspec); - enable_fscache(1); + enable_fscache(0); /* We do not really re-read the index but update the up-to-date flags */ preload_index(&the_index, &pathspec); diff --git a/builtin/checkout.c b/builtin/checkout.c index 07cc016e5c..ec0318231f 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -360,7 +360,7 @@ static int checkout_paths(const struct checkout_opts *opts, state.istate = &the_index; enable_delayed_checkout(&state); - enable_fscache(1); + enable_fscache(active_nr); for (pos = 0; pos < active_nr; pos++) { struct cache_entry *ce = active_cache[pos]; if (ce->ce_flags & CE_MATCHED) { @@ -375,7 +375,7 @@ static int checkout_paths(const struct checkout_opts *opts, pos = skip_same_name(ce, pos) - 1; } } - enable_fscache(0); + disable_fscache(); errs |= finish_delayed_checkout(&state); if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) diff --git a/builtin/commit.c b/builtin/commit.c index 8445d19dee..e98432a752 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1376,7 +1376,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) PATHSPEC_PREFER_FULL, prefix, argv); - enable_fscache(1); + enable_fscache(0); read_cache_preload(&s.pathspec); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL); @@ -1410,7 +1410,7 @@ int cmd_status(int argc, const char **argv, const char *prefix) s.prefix = prefix; wt_status_print(&s); - enable_fscache(0); + disable_fscache(); return 0; } diff --git a/compat/win32/fscache.c b/compat/win32/fscache.c index b81eb62e4f..96fe7e335c 100644 --- a/compat/win32/fscache.c +++ b/compat/win32/fscache.c @@ -401,7 +401,7 @@ static struct fsentry *fscache_get(struct fsentry *key) * Enables or disables the cache. Note that the cache is read-only, changes to * the working directory are NOT reflected in the cache while enabled. */ -int fscache_enable(int enable) +int fscache_enable(int enable, size_t initial_size) { int result; @@ -417,7 +417,11 @@ int fscache_enable(int enable) InitializeCriticalSection(&mutex); lstat_requests = opendir_requests = 0; fscache_misses = fscache_requests = 0; - hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0); + /* + * avoid having to rehash by leaving room for the parent dirs. + * '4' was determined empirically by testing several repos + */ + hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, initial_size * 4); initialized = 1; } diff --git a/compat/win32/fscache.h b/compat/win32/fscache.h index 2f06f8df97..d49c938111 100644 --- a/compat/win32/fscache.h +++ b/compat/win32/fscache.h @@ -1,8 +1,9 @@ #ifndef FSCACHE_H #define FSCACHE_H -int fscache_enable(int enable); -#define enable_fscache(x) fscache_enable(x) +int fscache_enable(int enable, size_t initial_size); +#define enable_fscache(initial_size) fscache_enable(1, initial_size) +#define disable_fscache() fscache_enable(0, 0) int fscache_enabled(const char *path); #define is_fscache_enabled(path) fscache_enabled(path) diff --git a/fetch-pack.c b/fetch-pack.c index 43e0945da1..d4f27db27c 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -678,7 +678,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator, save_commit_buffer = 0; - enable_fscache(1); + enable_fscache(0); for (ref = *refs; ref; ref = ref->next) { struct object *o; unsigned int flags = OBJECT_INFO_QUICK; @@ -708,7 +708,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator, cutoff = commit->date; } } - enable_fscache(0); + disable_fscache(); oidset_clear(&loose_oid_set); diff --git a/git-compat-util.h b/git-compat-util.h index 64a5d43a0e..e1b9e55683 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1259,6 +1259,10 @@ static inline int is_missing_file_error(int errno_) #define enable_fscache(x) /* noop */ #endif +#ifndef disable_fscache +#define disable_fscache() /* noop */ +#endif + #ifndef is_fscache_enabled #define is_fscache_enabled(path) (0) #endif diff --git a/preload-index.c b/preload-index.c index 6857573ce6..af34c3dc59 100644 --- a/preload-index.c +++ b/preload-index.c @@ -91,7 +91,7 @@ void preload_index(struct index_state *index, const struct pathspec *pathspec) offset = 0; work = DIV_ROUND_UP(index->cache_nr, threads); memset(&data, 0, sizeof(data)); - enable_fscache(1); + enable_fscache(index->cache_nr); for (i = 0; i < threads; i++) { struct thread_data *p = data+i; p->index = index; @@ -109,7 +109,7 @@ void preload_index(struct index_state *index, const struct pathspec *pathspec) die("unable to join threaded lstat"); } trace_performance_since(start, "preload index"); - enable_fscache(0); + disable_fscache(); } #endif diff --git a/read-cache.c b/read-cache.c index 18b6fb4214..6be61e5d0c 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1483,7 +1483,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n"); added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n"); unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n"); - enable_fscache(1); + enable_fscache(0); for (i = 0; i < istate->cache_nr; i++) { struct cache_entry *ce, *new_entry; int cache_errno = 0; @@ -1548,7 +1548,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, replace_index_entry(istate, i, new_entry); } - enable_fscache(0); + disable_fscache(); trace_performance_since(start, "refresh index"); return has_errors; }