features: feature.manyFiles implies fast index writes

The recent addition of the index.skipHash config option allows index writes to speed up by skipping the hash computation for the trailing checksum. This is particularly critical for repositories with many files at HEAD, so add this config option to two cases where users in that scenario may opt-in to such behavior: 1. The feature.manyFiles config option enables some options that are helpful for repositories with many files at HEAD. 2. 'scalar register' and 'scalar reconfigure' set config options that optimize for large repositories. In both of these cases, set index.skipHash=true to gain this speedup. Add tests that demonstrate the proper way that index.skipHash=true can override feature.manyFiles=true. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 6, 2023 at 16:31 UTC 17194b195d5db1cfd19af57e817c29bd3fa75c02
6 files changed +22 -1
Documentation/config/feature.txt
+5
@@ -23,6 +23,11 @@ feature.manyFiles::
23 working directory. With many files, commands such as `git status` and
24 `git checkout` may be slow and these new defaults improve performance:
25 +
26 +* `index.skipHash=true` speeds up index writes by not computing a trailing
27 + checksum. Note that this will cause Git versions earlier than 2.13.0 to
28 + refuse to parse the index and Git versions earlier than 2.40.0 will report
29 + a corrupted index during `git fsck`.
30 ++
31 * `index.version=4` enables path-prefix compression in the index.
32 +
33 * `core.untrackedCache=true` enables the untracked cache. This setting assumes
read-cache.c
+2 -1
@@ -2927,7 +2927,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
2927
2928 f = hashfd(tempfile->fd, tempfile->filename.buf);
2929
2930 - repo_config_get_bool(r, "index.skiphash", &f->skip_hash);
2930 + prepare_repo_settings(r);
2931 + f->skip_hash = r->settings.index_skip_hash;
2932
2933 for (i = removed = extended = 0; i < entries; i++) {
2934 if (cache[i]->ce_flags & CE_REMOVE)
repo-settings.c
+2
@@ -47,6 +47,7 @@ void prepare_repo_settings(struct repository *r)
47 }
48 if (manyfiles) {
49 r->settings.index_version = 4;
50 + r->settings.index_skip_hash = 1;
51 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
52 }
53
@@ -61,6 +62,7 @@ void prepare_repo_settings(struct repository *r)
62 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
63 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
64 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
65 + repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
66
67 /*
68 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
repository.h
+1
@@ -42,6 +42,7 @@ struct repo_settings {
42 struct fsmonitor_settings *fsmonitor; /* lazily loaded */
43
44 int index_version;
45 + int index_skip_hash;
46 enum untracked_cache_setting core_untracked_cache;
47
48 int pack_use_sparse;
scalar.c
+1
@@ -143,6 +143,7 @@ static int set_recommended_config(int reconfigure)
143 { "credential.validate", "false", 1 }, /* GCM4W-only */
144 { "gc.auto", "0", 1 },
145 { "gui.GCWarning", "false", 1 },
146 + { "index.skipHash", "false", 1 },
147 { "index.threads", "true", 1 },
148 { "index.version", "4", 1 },
149 { "merge.stat", "false", 1 },
t/t1600-index.sh
+11
@@ -73,6 +73,17 @@ test_expect_success 'index.skipHash config option' '
73 test_cmp expect hash &&
74 git fsck &&
75
76 + rm -f .git/index &&
77 + git -c feature.manyFiles=true add a &&
78 + test_trailing_hash .git/index >hash &&
79 + cmp expect hash &&
80 +
81 + rm -f .git/index &&
82 + git -c feature.manyFiles=true \
83 + -c index.skipHash=false add a &&
84 + test_trailing_hash .git/index >hash &&
85 + ! cmp expect hash &&
86 +
87 test_commit start &&
88 git -c protocol.file.allow=always submodule add ./ sub &&
89 git config index.skipHash false &&