Skip to content

Commit aacf38f

Browse files
benpeartGit for Windows Build Agent
authored andcommitted
fscache: fscache takes an initial size
Update enable_fscache() to take an optional initial size parameter which is used to initialize the hashmap so that it can avoid having to rehash as additional entries are added. Add a separate disable_fscache() macro to make the code clearer and easier to read. Signed-off-by: Ben Peart <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent dc65c7a commit aacf38f

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ int cmd_add(int argc,
485485
die_in_unpopulated_submodule(repo->index, prefix);
486486
die_path_inside_submodule(repo->index, &pathspec);
487487

488-
enable_fscache(1);
488+
enable_fscache(0);
489489
/* We do not really re-read the index but update the up-to-date flags */
490490
preload_index(repo->index, &pathspec, 0);
491491

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
415415
if (pc_workers > 1)
416416
init_parallel_checkout();
417417

418-
enable_fscache(1);
418+
enable_fscache(the_repository->index->cache_nr);
419419
for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
420420
struct cache_entry *ce = the_repository->index->cache[pos];
421421
if (ce->ce_flags & CE_MATCHED) {
@@ -441,7 +441,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
441441
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
442442
NULL, NULL);
443443
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
444-
enable_fscache(0);
444+
disable_fscache();
445445
remove_marked_cache_entries(the_repository->index, 1);
446446
remove_scheduled_dirs();
447447
errs |= finish_delayed_checkout(&state, opts->show_progress);

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ struct repository *repo UNUSED)
16091609
PATHSPEC_PREFER_FULL,
16101610
prefix, argv);
16111611

1612-
enable_fscache(1);
1612+
enable_fscache(0);
16131613
if (status_format != STATUS_FORMAT_PORCELAIN &&
16141614
status_format != STATUS_FORMAT_PORCELAIN_V2)
16151615
progress_flag = REFRESH_PROGRESS;
@@ -1650,7 +1650,7 @@ struct repository *repo UNUSED)
16501650
wt_status_print(&s);
16511651
wt_status_collect_free_buffers(&s);
16521652

1653-
enable_fscache(0);
1653+
disable_fscache();
16541654
return 0;
16551655
}
16561656

compat/win32/fscache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
410410
* Enables or disables the cache. Note that the cache is read-only, changes to
411411
* the working directory are NOT reflected in the cache while enabled.
412412
*/
413-
int fscache_enable(int enable)
413+
int fscache_enable(int enable, size_t initial_size)
414414
{
415415
int result;
416416

@@ -426,7 +426,11 @@ int fscache_enable(int enable)
426426
InitializeCriticalSection(&mutex);
427427
lstat_requests = opendir_requests = 0;
428428
fscache_misses = fscache_requests = 0;
429-
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
429+
/*
430+
* avoid having to rehash by leaving room for the parent dirs.
431+
* '4' was determined empirically by testing several repos
432+
*/
433+
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, initial_size * 4);
430434
initialized = 1;
431435
}
432436

compat/win32/fscache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef FSCACHE_H
22
#define FSCACHE_H
33

4-
int fscache_enable(int enable);
5-
#define enable_fscache(x) fscache_enable(x)
4+
int fscache_enable(int enable, size_t initial_size);
5+
#define enable_fscache(initial_size) fscache_enable(1, initial_size)
6+
#define disable_fscache() fscache_enable(0, 0)
67

78
int fscache_enabled(const char *path);
89
#define is_fscache_enabled(path) fscache_enabled(path)

fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
763763
save_commit_buffer = 0;
764764

765765
trace2_region_enter("fetch-pack", "parse_remote_refs_and_find_cutoff", NULL);
766-
enable_fscache(1);
766+
enable_fscache(0);
767767
for (ref = *refs; ref; ref = ref->next) {
768768
struct commit *commit;
769769

@@ -788,7 +788,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
788788
if (!cutoff || cutoff < commit->date)
789789
cutoff = commit->date;
790790
}
791-
enable_fscache(0);
791+
disable_fscache();
792792
trace2_region_leave("fetch-pack", "parse_remote_refs_and_find_cutoff", NULL);
793793

794794
/*

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,10 @@ static inline int is_missing_file_error(int errno_)
10651065
#define enable_fscache(x) /* noop */
10661066
#endif
10671067

1068+
#ifndef disable_fscache
1069+
#define disable_fscache() /* noop */
1070+
#endif
1071+
10681072
#ifndef is_fscache_enabled
10691073
#define is_fscache_enabled(path) (0)
10701074
#endif

preload-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void preload_index(struct index_state *index,
138138
pthread_mutex_init(&pd.mutex, NULL);
139139
}
140140

141-
enable_fscache(1);
141+
enable_fscache(index->cache_nr);
142142
for (i = 0; i < threads; i++) {
143143
struct thread_data *p = data+i;
144144
int err;
@@ -175,7 +175,7 @@ void preload_index(struct index_state *index,
175175
trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
176176
trace2_region_leave("index", "preload", NULL);
177177

178-
enable_fscache(0);
178+
disable_fscache();
179179
}
180180

181181
int repo_read_index_preload(struct repository *repo,

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15041504
typechange_fmt = in_porcelain ? "T\t%s\n" : "%s: needs update\n";
15051505
added_fmt = in_porcelain ? "A\t%s\n" : "%s: needs update\n";
15061506
unmerged_fmt = in_porcelain ? "U\t%s\n" : "%s: needs merge\n";
1507-
enable_fscache(1);
1507+
enable_fscache(0);
15081508
/*
15091509
* Use the multi-threaded preload_index() to refresh most of the
15101510
* cache entries quickly then in the single threaded loop below,
@@ -1599,7 +1599,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15991599
display_progress(progress, istate->cache_nr);
16001600
stop_progress(&progress);
16011601
trace_performance_leave("refresh index");
1602-
enable_fscache(0);
1602+
disable_fscache();
16031603
return has_errors;
16041604
}
16051605

0 commit comments

Comments
 (0)