Skip to content

Commit 1398970

Browse files
jeffhostetlerdscho
authored andcommitted
add: use preload-index and fscache for performance
Teach "add" to use preload-index and fscache features to improve performance on very large repositories. During an "add", a call is made to run_diff_files() which calls check_remove() for each index-entry. This calls lstat(). On Windows, the fscache code intercepts the lstat() calls and builds a private cache using the FindFirst/FindNext routines, which are much faster. Somewhat independent of this, is the preload-index code which distributes some of the start-up costs across multiple threads. We need to keep the call to read_cache() before parsing the pathspecs (and hence cannot use the pathspecs to limit any preload) because parse_pathspec() is using the index to determine whether a pathspec is, in fact, in a submodule. If we would not read the index first, parse_pathspec() would not error out on a path that is inside a submodule, and t7400-submodule-basic.sh would fail with not ok 47 - do not add files from a submodule We still want the nice preload performance boost, though, so we simply call read_cache_preload(&pathspecs) after parsing the pathspecs. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 187eacd commit 1398970

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

builtin/add.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ int cmd_add(int argc,
477477
die_in_unpopulated_submodule(repo->index, prefix);
478478
die_path_inside_submodule(repo->index, &pathspec);
479479

480+
enable_fscache(1);
481+
/* We do not really re-read the index but update the up-to-date flags */
482+
preload_index(repo->index, &pathspec, 0);
483+
480484
if (add_new_files) {
481485
int baselen;
482486

@@ -589,5 +593,6 @@ int cmd_add(int argc,
589593
free(ps_matched);
590594
dir_clear(&dir);
591595
clear_pathspec(&pathspec);
596+
enable_fscache(0);
592597
return exit_status;
593598
}

0 commit comments

Comments
 (0)