* [PATCH] read-cache: hash the shared index even with index.skipHash
@ 2026-11-26 13:57 blanet via GitGitGadget
2026-11-26 19:21 ` Junio C Hamano
2026-11-28 9:27 ` [PATCH v2] " blanet via GitGitGadget
0 siblings, 2 replies; 7+ messages in thread
From: blanet via GitGitGadget @ 2026-11-26 13:57 UTC (permalink / raw)
To: git; +Cc: blanet, Xing Xin
From: Xing Xin <xingxin.xx@bytedance.com>
The shared index of a split index is named after its trailing hash,
which the split index records in its "link" extension to find it.
Since ee1f0c242e (read-cache: add index.skipHash config option,
2023-01-06), do_write_index() skips that hash for the shared index
too, so with index.skipHash and core.splitIndex both set, the shared
index is written as "sharedindex.<null OID>" and the split index
records a null OID as its base. Reading the index back, a null base
means there is no shared index: the entries that were moved there are
lost, "git ls-files" no longer shows them and "git status" reports
them as deleted and untracked. With fsmonitor, it hits a BUG() in
fsmonitor.c instead, as the fsmonitor bitmap refers to more entries
than the index has.
Scalar sets index.skipHash since 05f28e4b3c (scalar: use
index.skipHash=true for performance, 2025-12-12), and feature.manyFiles
implies it. The tests that ran into this under GIT_TEST_SPLIT_INDEX
unset that variable instead, in 05f28e4b3c, in 7cce609e08 (t9210,
t9211: disable GIT_TEST_SPLIT_INDEX for scalar clone tests,
2026-04-15) and in a644ad5f34 (status: lock the index only to write
it, 2026-10-22).
Let the callers of do_write_index() decide whether to skip the hash,
and always compute it for the shared index. This keeps most of the
benefit: the shared index is rewritten only now and then (see
splitIndex.maxPercentChange), while the split index, written on every
index update, still skips it.
Add a test, and drop the workarounds, as those tests now pass with
GIT_TEST_SPLIT_INDEX.
Signed-off-by: Xing Xin <xingxin.xx@bytedance.com>
---
read-cache: hash the shared index even with index.skipHash
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2337%2Fblanet%2Fxx%2Fsplit-index-skip-hash-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2337/blanet/xx/split-index-skip-hash-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2337
Documentation/config/index.adoc | 4 +++-
read-cache.c | 18 ++++++++++++------
t/t1700-split-index.sh | 23 +++++++++++++++++++++++
t/t7508-status.sh | 10 ----------
t/t9210-scalar.sh | 10 ----------
t/t9211-scalar-clone.sh | 5 -----
6 files changed, 38 insertions(+), 32 deletions(-)
diff --git a/Documentation/config/index.adoc b/Documentation/config/index.adoc
index a23be914e3..e878145158 100644
--- a/Documentation/config/index.adoc
+++ b/Documentation/config/index.adoc
@@ -41,7 +41,9 @@ index.skipHash::
This accelerates Git commands that manipulate the index, such as
`git add`, `git commit`, or `git status`. Instead of storing the
checksum, write a trailing set of bytes with value zero, indicating
- that the computation was skipped.
+ that the computation was skipped. The shared index of a split index
+ (see `core.splitIndex`) is still hashed, as it is named after its
+ hash.
+
If you enable `index.skipHash`, then Git clients older than 2.13.0 will
refuse to parse the index and Git clients older than 2.40.0 will report an
diff --git a/read-cache.c b/read-cache.c
index 595497d14c..a734943c97 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2878,7 +2878,8 @@ enum write_extensions {
* rely on it.
*/
static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
- enum write_extensions write_extensions, unsigned flags)
+ enum write_extensions write_extensions, unsigned flags,
+ int skip_hash)
{
uint64_t start = getnanotime();
struct hashfile *f;
@@ -2900,9 +2901,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
int nr, nr_threads, ret;
f = hashfd(the_repository->hash_algo, tempfile->fd, tempfile->filename.buf);
-
- prepare_repo_settings(r);
- f->skip_hash = r->settings.index_skip_hash;
+ f->skip_hash = skip_hash;
for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
@@ -3224,9 +3223,11 @@ static int do_write_locked_index(struct index_state *istate,
return ret;
}
+ prepare_repo_settings(istate->repo);
trace2_region_enter_printf("index", "do_write_index", istate->repo,
"%s", get_lock_file_path(lock));
- ret = do_write_index(istate, lock->tempfile, write_extensions, flags);
+ ret = do_write_index(istate, lock->tempfile, write_extensions, flags,
+ istate->repo->settings.index_skip_hash);
trace2_region_leave_printf("index", "do_write_index", istate->repo,
"%s", get_lock_file_path(lock));
@@ -3339,9 +3340,14 @@ static int write_shared_index(struct index_state *istate,
move_cache_to_base_index(istate);
convert_to_sparse(istate, 0);
+ /*
+ * The shared index is named after its trailing hash, which the
+ * split index records to find it: compute it even with
+ * index.skipHash.
+ */
trace2_region_enter_printf("index", "shared/do_write_index",
the_repository, "%s", get_tempfile_path(*temp));
- ret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags);
+ ret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags, 0);
trace2_region_leave_printf("index", "shared/do_write_index",
the_repository, "%s", get_tempfile_path(*temp));
diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh
index 887e72a5fa..86eae9eb1d 100755
--- a/t/t1700-split-index.sh
+++ b/t/t1700-split-index.sh
@@ -544,4 +544,27 @@ test_expect_success 'GIT_TEST_SPLIT_INDEX works' '
)
'
+test_expect_success 'shared index is hashed even with index.skipHash' '
+ git init skip-hash &&
+ (
+ cd skip-hash &&
+ git config core.splitIndex true &&
+ git config index.skipHash true &&
+ test_commit one &&
+ test_commit two &&
+
+ test-tool dump-split-index .git/index >dump &&
+ echo "own $ZERO_OID" >expect &&
+ grep "^own " dump >actual &&
+ test_cmp expect actual &&
+ base=$(sed -n "s/^base //p" dump) &&
+ test "$base" != "$ZERO_OID" &&
+ test_path_is_file .git/sharedindex.$base &&
+
+ git ls-files >actual &&
+ test_write_lines one.t two.t >expect &&
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e10c961268..dde5dd1020 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1691,11 +1691,6 @@ do
git init update-after-read &&
(
cd update-after-read &&
- if test $skip_hash = true
- then
- # index.skipHash does not work with a split index.
- sane_unset GIT_TEST_SPLIT_INDEX
- fi &&
git config index.skipHash $skip_hash &&
test_commit base &&
write_script .git/fsmonitor-hook <<-\EOF &&
@@ -1769,11 +1764,6 @@ do
test_expect_success "status refresh does not overwrite an index update made while collecting (index.skipHash=$skip_hash)" '
test_when_finished "rm -rf refresh-while-collecting" &&
(
- if test $skip_hash = true
- then
- # index.skipHash does not work with a split index.
- sane_unset GIT_TEST_SPLIT_INDEX
- fi &&
setup_index_update_during_collection refresh-while-collecting &&
cd refresh-while-collecting &&
git config index.skipHash $skip_hash &&
diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh
index 137765d3b8..32ad85c577 100755
--- a/t/t9210-scalar.sh
+++ b/t/t9210-scalar.sh
@@ -152,10 +152,6 @@ test_expect_success 'set up repository to clone' '
'
test_expect_success 'scalar clone' '
- # index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are
- # incompatible: the shared index gets a null OID and fails to
- # load on re-read.
- sane_unset GIT_TEST_SPLIT_INDEX &&
second=$(git rev-parse --verify second:second.t) &&
scalar clone "file://$(pwd)" cloned --single-branch &&
(
@@ -186,7 +182,6 @@ test_expect_success 'scalar clone' '
'
test_expect_success 'scalar clone --no-... opts' '
- sane_unset GIT_TEST_SPLIT_INDEX &&
# Note: redirect stderr always to avoid having a verbose test
# run result in a difference in the --[no-]progress option.
GIT_TRACE2_EVENT="$(pwd)/no-opt-trace" scalar clone \
@@ -251,10 +246,6 @@ test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
'
test_expect_success 'scalar reconfigure --all with detached HEADs' '
- # This test demonstrates an issue with index.skipHash=true and
- # this test variable for the split index. Disable the test variable.
- sane_unset GIT_TEST_SPLIT_INDEX &&
-
repos="two three four" &&
for num in $repos
do
@@ -317,7 +308,6 @@ test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
SQ="'"
test_expect_success UNZIP 'scalar diagnose' '
- sane_unset GIT_TEST_SPLIT_INDEX &&
scalar clone "file://$(pwd)" cloned --single-branch &&
git repack &&
echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh
index 002d6ecdc1..110985f58d 100755
--- a/t/t9211-scalar-clone.sh
+++ b/t/t9211-scalar-clone.sh
@@ -8,11 +8,6 @@ test_description='test the `scalar clone` subcommand'
GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
export GIT_TEST_MAINT_SCHEDULER
-# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are
-# incompatible: the shared index gets a null OID and fails to
-# load on re-read. Every test here uses scalar clone.
-sane_unset GIT_TEST_SPLIT_INDEX
-
test_expect_success 'set up repository to clone' '
rm -rf .git &&
git init to-clone &&
base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
--
gitgitgadget
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] read-cache: hash the shared index even with index.skipHash 2026-11-26 13:57 [PATCH] read-cache: hash the shared index even with index.skipHash blanet via GitGitGadget @ 2026-11-26 19:21 ` Junio C Hamano 2026-11-27 12:59 ` Xing Xin 2026-11-28 9:27 ` [PATCH v2] " blanet via GitGitGadget 1 sibling, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2026-11-26 19:21 UTC (permalink / raw) To: blanet via GitGitGadget; +Cc: git, blanet, Xing Xin "blanet via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Xing Xin <xingxin.xx@bytedance.com> > > The shared index of a split index is named after its trailing hash, > which the split index records in its "link" extension to find it. > Since ee1f0c242e (read-cache: add index.skipHash config option, > 2023-01-06), do_write_index() skips that hash for the shared index > too, so with index.skipHash and core.splitIndex both set, the shared > index is written as "sharedindex.<null OID>" and the split index > records a null OID as its base. Reading the index back, a null base > means there is no shared index: the entries that were moved there are > lost, "git ls-files" no longer shows them and "git status" reports > them as deleted and untracked. With fsmonitor, it hits a BUG() in > fsmonitor.c instead, as the fsmonitor bitmap refers to more entries > than the index has. It is correct to point out that the two "features", skipHash and splitIndex, are incompatible. With skipHash, splitIndex will not correctly work. We can say skipHash breaks splitIndex. But does this change to _force_ the base index files to be hashed, against the user's wish expressed by skipHash, take us in a better direction, I have to wonder? With this change, skipHash's promise to improve performance is not kept. We can say splitIndex breaks skipHash. Stepping back a bit, isn't the expectation of splitIndex that these incremental modifications held in non-base index files are relatively small, thanks to the bulk of data that the base index file holds covering almost everything in the repository? In other words, isn't the use of splitIndex a strong sign that the base index file would benefit the most from skipHash? And this patch is breaking the skipHash feature for the use case that would benefit the most. And not hashing the index files that are not bases would not save as much, since they are expected to be much smaller. I wonder if going in the other direction, i.e., when both are enabled, disabling splitIndex and working only on the base hash, would be an alternative that is equally viable as this change? Both will *break* the promise of one feature so that the result can live with the other feature. What are the pros and cons between them? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re:Re: [PATCH] read-cache: hash the shared index even with index.skipHash 2026-11-26 19:21 ` Junio C Hamano @ 2026-11-27 12:59 ` Xing Xin 2026-11-27 18:44 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Xing Xin @ 2026-11-27 12:59 UTC (permalink / raw) To: Junio C Hamano; +Cc: blanet via GitGitGadget, git, Xing Xin At 2026-11-27 03:21:26, "Junio C Hamano" <gitster@pobox.com> wrote: > It is correct to point out that the two "features", skipHash and > splitIndex, are incompatible. With skipHash, splitIndex will not > correctly work. We can say skipHash breaks splitIndex. > > But does this change to _force_ the base index files to be hashed, > against the user's wish expressed by skipHash, take us in a better > direction, I have to wonder? With this change, skipHash's promise to > improve performance is not kept. We can say splitIndex breaks skipHash. You are right, and the log message overstates the case when it says that this "keeps most of the benefit". As the numbers below show, the split index file is small enough that skipping its hash saves next to nothing, so with this patch index.skipHash has little effect once a split index is in use. That said, I do not think both can be kept without changing the index format. Readers die() unless the "link" extension names the trailing hash of the shared index, and a trailer that is neither null nor the real hash makes "git fsck" fail. So a shared index written without its hash can only be called sharedindex.<null OID>, which is exactly what goes wrong today. One of the two has to give. > Stepping back a bit, isn't the expectation of splitIndex that these > incremental modifications held in non-base index files are relatively > small, thanks to the bulk of data that the base index file holds > covering almost everything in the repository? In other words, isn't the > use of splitIndex a strong sign that the base index file would benefit > the most from skipHash? And this patch is breaking the skipHash feature > for the use case that would benefit the most. And not hashing the index > files that are not bases would not save as much, since they are expected > to be much smaller. Per write, yes. But what skipHash saves is the hashing done on each write, and the shared index is only written when it is rewritten, which the split index is designed to make rare. The frequent writes are of the small split index, where, as you say, there is little to save. > I wonder if going in the other direction, i.e., when both are enabled, > disabling splitIndex and working only on the base hash, would be an > alternative that is equally viable as this change? Both will *break* > the promise of one feature so that the result can live with the other > feature. What are the pros and cons between them? I see three ways to resolve it when both are set: 1. disable the split index and keep skipHash (your suggestion), 2. keep the split index and ignore index.skipHash while it is in use, 3. keep both, but always hash the shared index (this patch). To compare them, I measured a repository with 100k files in 1,000 directories, index v4 (7.0MB) with the untracked cache enabled, so that the split index carries the cache-tree and untracked cache extensions as it would in practice. Each round changes K files and runs "git add -u", "git commit", "git status" (after touching the files), and "git checkout HEAD~1" and back. 1 and 2 are emulated by turning the other setting off. The times are the index write and read regions from trace2, median of 7 runs, averaged over add, commit and status (Apple M4 Pro, SHA1DC): index write (ms) index .git/index K=1 K=100 K=10000 read K=1 / K=10000 neither 18.3 15.2 15.5 3 ms 7.0 / 7.0 MB 1: skipHash only 6.1 6.0 6.1 3 ms 7.0 / 7.0 MB 2: splitIndex only 0.4 0.4 1.9 3 ms 0.07 / 0.75 MB 3: both, this patch 0.3 0.3 0.9 3 ms 0.07 / 0.75 MB Rewriting the whole index takes 15-20ms with neither feature and 6ms with skipHash; rewriting the shared index takes 15-22ms with 2 or 3, as both hash it. The checkout round trip, which writes the index twice, shows the same pattern. - The write time hardly depends on K: without a split index every write covers all entries, and with one the split index stays small (0.75MB at K=10000). No K up to 10000 (10% of the entries) made 2 or 3 rewrite the shared index; that takes new or re-created entries beyond splitIndex.maxPercentChange (20% by default), e.g. when checking out a distant branch. - 1 cuts each write from ~15-18ms to ~6ms. 2 cuts it to under 2ms, but pays ~10-15ms more than 1 whenever it rewrites the shared index, so it comes out ahead unless about one write in three does so. - 3 differs from 2 only in hashing .git/index, which costs ~0.1ms for 0.07MB and ~1ms for 0.75MB here. That is all index.skipHash can still save with a split index. - The index read time is the same ~3ms in all four. - At this size, all of this is small next to the run times of the commands (110ms to 3.8s), which are dominated by the work on the files themselves, and the differences there are mostly within the noise. Performance aside, the two settings do not come from symmetric places, which matters for 1: - index.skipHash is only ever a configuration variable: it is either implied by feature.manyFiles, or set as index.skipHash, by the user or by Scalar, which writes index.skipHash=true into the repository configuration and resets it on "scalar reconfigure". - The split index is enabled by core.splitIndex, which neither a feature.* setting nor Scalar sets, or by "git update-index --split-index", which stays in effect while core.splitIndex is unset. When both are set in the configuration, there is no telling which one the user cares about more. But 1 would let a default implied by feature.manyFiles override an explicit core.splitIndex, although feature.* is documented to only change defaults. For "git update-index --split-index", 1 would either have to let a configuration variable override a command line option, whereas today the option still takes effect, with a warning, when core.splitIndex is false, or honor the option for that write, which needs the change in this patch anyway. And in a Scalar enlistment, core.splitIndex would only work after setting index.skipHash=false, and would stop working again at the next "scalar reconfigure". There is also precedent for the split index taking priority: the sparse index is not written while a split index is in use (see is_sparse_index_allowed()). Between 2 and 3 the performance is practically the same, so it comes down to principle. 3 deviates from the configuration only where the index format forces it to. 2 is simpler to explain ("index.skipHash has no effect with a split index") and keeps the checksum of .git/index, at the cost of ignoring a setting it does not strictly need to ignore. I lean towards 3, but would be happy to switch to 2 if you prefer the simpler rule; the difference is a single condition. Once we settle on the direction, I will send a v2 with the log message and documentation updated accordingly. Thanks. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] read-cache: hash the shared index even with index.skipHash 2026-11-27 12:59 ` Xing Xin @ 2026-11-27 18:44 ` Junio C Hamano 0 siblings, 0 replies; 7+ messages in thread From: Junio C Hamano @ 2026-11-27 18:44 UTC (permalink / raw) To: Xing Xin; +Cc: blanet via GitGitGadget, git, Xing Xin "Xing Xin" <bupt_xingxin@163.com> writes: >> the most from skipHash? And this patch is breaking the skipHash feature >> for the use case that would benefit the most. And not hashing the index >> files that are not bases would not save as much, since they are expected >> to be much smaller. > > Per write, yes. But what skipHash saves is the hashing done on each > write, and the shared index is only written when it is rewritten, > which the split index is designed to make rare. The frequent writes > are of the small split index, where, as you say, there is little to > save. That is a very good justification to give in the proposed commit log message and also in the documentation (the behaviour may already be documented in this initial version of the patch, but the reason why the base index ignores the skipHash configuration deserves a mention, too). > - index.skipHash is only ever a configuration variable: it is either > implied by feature.manyFiles, or set as index.skipHash, by the user > or by Scalar, which writes index.skipHash=true into the repository > configuration and resets it on "scalar reconfigure". > > - The split index is enabled by core.splitIndex, which neither a > feature.* setting nor Scalar sets, or by "git update-index > --split-index", which stays in effect while core.splitIndex is > unset. > > When both are set in the configuration, there is no telling which one > the user cares about more. Isn't that mostly a defect of Scalar? Such a tool that configures the repository without close supervision by the user should be responsible for ensuring that the resulting set of configuration variables gives a coherent story of what the user wants. But by going the route of your patch, we no longer have to worry about these two features conflicting, so I would say it is a good direction to go. Thanks. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] read-cache: hash the shared index even with index.skipHash 2026-11-26 13:57 [PATCH] read-cache: hash the shared index even with index.skipHash blanet via GitGitGadget 2026-11-26 19:21 ` Junio C Hamano @ 2026-11-28 9:27 ` blanet via GitGitGadget 2026-11-28 21:41 ` Junio C Hamano 1 sibling, 1 reply; 7+ messages in thread From: blanet via GitGitGadget @ 2026-11-28 9:27 UTC (permalink / raw) To: git; +Cc: Junio C Hamano, blanet, Xing Xin From: Xing Xin <xingxin.xx@bytedance.com> The shared index of a split index is named after its trailing hash, which the split index records in its "link" extension to find it. Since ee1f0c242e (read-cache: add index.skipHash config option, 2023-01-06), do_write_index() skips that hash for the shared index too, so with index.skipHash and core.splitIndex both set, the shared index is written as "sharedindex.<null OID>" and the split index records a null OID as its base. Reading the index back, a null base means there is no shared index: the entries that were moved there are lost, "git ls-files" no longer shows them and "git status" reports them as deleted and untracked. With fsmonitor, it can hit a BUG() in fsmonitor.c instead, when the fsmonitor bitmap refers to more entries than the index has. Scalar has enabled index.skipHash since 05f28e4b3c (scalar: use index.skipHash=true for performance, 2025-12-12), and feature.manyFiles implies it. The tests that ran into this under GIT_TEST_SPLIT_INDEX unset that variable instead, in 05f28e4b3c, in 7cce609e08 (t9210, t9211: disable GIT_TEST_SPLIT_INDEX for scalar clone tests, 2026-04-15), and in 6b6d1d56eb (read-cache: verify skipHash index by stat data, 2026-10-22) and a644ad5f34 (status: lock the index only to write it, 2026-10-22). Let the callers of do_write_index() decide whether to skip the hash, and always compute it for the shared index, so that the two settings no longer conflict. This gives up index.skipHash on the file where skipping the hash would save the most per write, as the shared index holds nearly all the entries. But what index.skipHash saves is the hashing done on each write, and the split index is designed to make writing a shared index rare: once there is one, a new one is written only when more than splitIndex.maxPercentChange of the entries (20% by default) are not in it. The frequent writes are of the split index, which holds the entries added or changed since the shared index was written, as well as all the extensions, and still skips the hash. Document this under index.skipHash, add a test, and drop the workarounds, as those tests now pass with GIT_TEST_SPLIT_INDEX. Signed-off-by: Xing Xin <xingxin.xx@bytedance.com> --- read-cache: hash the shared index even with index.skipHash Changes since v1: * Explain in the log message why hashing the shared index despite index.skipHash is acceptable, as it is rewritten only rarely, and drop the claim that this keeps most of the benefit. * Say the same in the index.skipHash documentation. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2337%2Fblanet%2Fxx%2Fsplit-index-skip-hash-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2337/blanet/xx/split-index-skip-hash-v2 Pull-Request: https://github.com/gitgitgadget/git/pull/2337 Range-diff vs v1: 1: 0502560699 ! 1: 16091375ca read-cache: hash the shared index even with index.skipHash @@ Commit message records a null OID as its base. Reading the index back, a null base means there is no shared index: the entries that were moved there are lost, "git ls-files" no longer shows them and "git status" reports - them as deleted and untracked. With fsmonitor, it hits a BUG() in - fsmonitor.c instead, as the fsmonitor bitmap refers to more entries + them as deleted and untracked. With fsmonitor, it can hit a BUG() in + fsmonitor.c instead, when the fsmonitor bitmap refers to more entries than the index has. - Scalar sets index.skipHash since 05f28e4b3c (scalar: use - index.skipHash=true for performance, 2025-12-12), and feature.manyFiles - implies it. The tests that ran into this under GIT_TEST_SPLIT_INDEX - unset that variable instead, in 05f28e4b3c, in 7cce609e08 (t9210, - t9211: disable GIT_TEST_SPLIT_INDEX for scalar clone tests, - 2026-04-15) and in a644ad5f34 (status: lock the index only to write - it, 2026-10-22). + Scalar has enabled index.skipHash since 05f28e4b3c (scalar: use + index.skipHash=true for performance, 2025-12-12), and + feature.manyFiles implies it. The tests that ran into this under + GIT_TEST_SPLIT_INDEX unset that variable instead, in 05f28e4b3c, in + 7cce609e08 (t9210, t9211: disable GIT_TEST_SPLIT_INDEX for scalar + clone tests, 2026-04-15), and in 6b6d1d56eb (read-cache: verify + skipHash index by stat data, 2026-10-22) and a644ad5f34 (status: lock + the index only to write it, 2026-10-22). Let the callers of do_write_index() decide whether to skip the hash, - and always compute it for the shared index. This keeps most of the - benefit: the shared index is rewritten only now and then (see - splitIndex.maxPercentChange), while the split index, written on every - index update, still skips it. + and always compute it for the shared index, so that the two settings + no longer conflict. - Add a test, and drop the workarounds, as those tests now pass with - GIT_TEST_SPLIT_INDEX. + This gives up index.skipHash on the file where skipping the hash would + save the most per write, as the shared index holds nearly all the + entries. But what index.skipHash saves is the hashing done on each + write, and the split index is designed to make writing a shared index + rare: once there is one, a new one is written only when more than + splitIndex.maxPercentChange of the entries (20% by default) are not + in it. The frequent writes are of the split index, which holds the + entries added or changed since the shared index was written, as well + as all the extensions, and still skips the hash. + + Document this under index.skipHash, add a test, and drop the + workarounds, as those tests now pass with GIT_TEST_SPLIT_INDEX. Signed-off-by: Xing Xin <xingxin.xx@bytedance.com> ## Documentation/config/index.adoc ## @@ Documentation/config/index.adoc: index.skipHash:: - This accelerates Git commands that manipulate the index, such as - `git add`, `git commit`, or `git status`. Instead of storing the checksum, write a trailing set of bytes with value zero, indicating -- that the computation was skipped. -+ that the computation was skipped. The shared index of a split index -+ (see `core.splitIndex`) is still hashed, as it is named after its -+ hash. + that the computation was skipped. + ++With a split index (see `core.splitIndex`), only the split index, which ++is written on every index update, skips the hash. The shared index is ++still hashed, as it is named after its hash, but it is rewritten only ++when too many entries are not in it (see `splitIndex.maxPercentChange`). +++ If you enable `index.skipHash`, then Git clients older than 2.13.0 will refuse to parse the index and Git clients older than 2.40.0 will report an + error during `git fsck`. ## read-cache.c ## @@ read-cache.c: enum write_extensions { Documentation/config/index.adoc | 5 +++++ read-cache.c | 18 ++++++++++++------ t/t1700-split-index.sh | 23 +++++++++++++++++++++++ t/t7508-status.sh | 10 ---------- t/t9210-scalar.sh | 10 ---------- t/t9211-scalar-clone.sh | 5 ----- 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/Documentation/config/index.adoc b/Documentation/config/index.adoc index a23be914e3..08620846b5 100644 --- a/Documentation/config/index.adoc +++ b/Documentation/config/index.adoc @@ -43,6 +43,11 @@ index.skipHash:: checksum, write a trailing set of bytes with value zero, indicating that the computation was skipped. + +With a split index (see `core.splitIndex`), only the split index, which +is written on every index update, skips the hash. The shared index is +still hashed, as it is named after its hash, but it is rewritten only +when too many entries are not in it (see `splitIndex.maxPercentChange`). ++ If you enable `index.skipHash`, then Git clients older than 2.13.0 will refuse to parse the index and Git clients older than 2.40.0 will report an error during `git fsck`. diff --git a/read-cache.c b/read-cache.c index 595497d14c..a734943c97 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2878,7 +2878,8 @@ enum write_extensions { * rely on it. */ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, - enum write_extensions write_extensions, unsigned flags) + enum write_extensions write_extensions, unsigned flags, + int skip_hash) { uint64_t start = getnanotime(); struct hashfile *f; @@ -2900,9 +2901,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, int nr, nr_threads, ret; f = hashfd(the_repository->hash_algo, tempfile->fd, tempfile->filename.buf); - - prepare_repo_settings(r); - f->skip_hash = r->settings.index_skip_hash; + f->skip_hash = skip_hash; for (i = removed = extended = 0; i < entries; i++) { if (cache[i]->ce_flags & CE_REMOVE) @@ -3224,9 +3223,11 @@ static int do_write_locked_index(struct index_state *istate, return ret; } + prepare_repo_settings(istate->repo); trace2_region_enter_printf("index", "do_write_index", istate->repo, "%s", get_lock_file_path(lock)); - ret = do_write_index(istate, lock->tempfile, write_extensions, flags); + ret = do_write_index(istate, lock->tempfile, write_extensions, flags, + istate->repo->settings.index_skip_hash); trace2_region_leave_printf("index", "do_write_index", istate->repo, "%s", get_lock_file_path(lock)); @@ -3339,9 +3340,14 @@ static int write_shared_index(struct index_state *istate, move_cache_to_base_index(istate); convert_to_sparse(istate, 0); + /* + * The shared index is named after its trailing hash, which the + * split index records to find it: compute it even with + * index.skipHash. + */ trace2_region_enter_printf("index", "shared/do_write_index", the_repository, "%s", get_tempfile_path(*temp)); - ret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags); + ret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags, 0); trace2_region_leave_printf("index", "shared/do_write_index", the_repository, "%s", get_tempfile_path(*temp)); diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh index 887e72a5fa..86eae9eb1d 100755 --- a/t/t1700-split-index.sh +++ b/t/t1700-split-index.sh @@ -544,4 +544,27 @@ test_expect_success 'GIT_TEST_SPLIT_INDEX works' ' ) ' +test_expect_success 'shared index is hashed even with index.skipHash' ' + git init skip-hash && + ( + cd skip-hash && + git config core.splitIndex true && + git config index.skipHash true && + test_commit one && + test_commit two && + + test-tool dump-split-index .git/index >dump && + echo "own $ZERO_OID" >expect && + grep "^own " dump >actual && + test_cmp expect actual && + base=$(sed -n "s/^base //p" dump) && + test "$base" != "$ZERO_OID" && + test_path_is_file .git/sharedindex.$base && + + git ls-files >actual && + test_write_lines one.t two.t >expect && + test_cmp expect actual + ) +' + test_done diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e10c961268..dde5dd1020 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1691,11 +1691,6 @@ do git init update-after-read && ( cd update-after-read && - if test $skip_hash = true - then - # index.skipHash does not work with a split index. - sane_unset GIT_TEST_SPLIT_INDEX - fi && git config index.skipHash $skip_hash && test_commit base && write_script .git/fsmonitor-hook <<-\EOF && @@ -1769,11 +1764,6 @@ do test_expect_success "status refresh does not overwrite an index update made while collecting (index.skipHash=$skip_hash)" ' test_when_finished "rm -rf refresh-while-collecting" && ( - if test $skip_hash = true - then - # index.skipHash does not work with a split index. - sane_unset GIT_TEST_SPLIT_INDEX - fi && setup_index_update_during_collection refresh-while-collecting && cd refresh-while-collecting && git config index.skipHash $skip_hash && diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index 137765d3b8..32ad85c577 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -152,10 +152,6 @@ test_expect_success 'set up repository to clone' ' ' test_expect_success 'scalar clone' ' - # index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are - # incompatible: the shared index gets a null OID and fails to - # load on re-read. - sane_unset GIT_TEST_SPLIT_INDEX && second=$(git rev-parse --verify second:second.t) && scalar clone "file://$(pwd)" cloned --single-branch && ( @@ -186,7 +182,6 @@ test_expect_success 'scalar clone' ' ' test_expect_success 'scalar clone --no-... opts' ' - sane_unset GIT_TEST_SPLIT_INDEX && # Note: redirect stderr always to avoid having a verbose test # run result in a difference in the --[no-]progress option. GIT_TRACE2_EVENT="$(pwd)/no-opt-trace" scalar clone \ @@ -251,10 +246,6 @@ test_expect_success 'scalar reconfigure --all with includeIf.onbranch' ' ' test_expect_success 'scalar reconfigure --all with detached HEADs' ' - # This test demonstrates an issue with index.skipHash=true and - # this test variable for the split index. Disable the test variable. - sane_unset GIT_TEST_SPLIT_INDEX && - repos="two three four" && for num in $repos do @@ -317,7 +308,6 @@ test_expect_success '`scalar [...] <dir>` errors out when dir is missing' ' SQ="'" test_expect_success UNZIP 'scalar diagnose' ' - sane_unset GIT_TEST_SPLIT_INDEX && scalar clone "file://$(pwd)" cloned --single-branch && git repack && echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates && diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh index 002d6ecdc1..110985f58d 100755 --- a/t/t9211-scalar-clone.sh +++ b/t/t9211-scalar-clone.sh @@ -8,11 +8,6 @@ test_description='test the `scalar clone` subcommand' GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true" export GIT_TEST_MAINT_SCHEDULER -# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are -# incompatible: the shared index gets a null OID and fails to -# load on re-read. Every test here uses scalar clone. -sane_unset GIT_TEST_SPLIT_INDEX - test_expect_success 'set up repository to clone' ' rm -rf .git && git init to-clone && base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe -- gitgitgadget ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] read-cache: hash the shared index even with index.skipHash 2026-11-28 9:27 ` [PATCH v2] " blanet via GitGitGadget @ 2026-11-28 21:41 ` Junio C Hamano 2026-11-30 7:47 ` Xing Xin 0 siblings, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2026-11-28 21:41 UTC (permalink / raw) To: blanet via GitGitGadget; +Cc: git, blanet, Xing Xin "blanet via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Xing Xin <xingxin.xx@bytedance.com> > > The shared index of a split index is named after its trailing hash, > which the split index records in its "link" extension to find it. > Since ee1f0c242e (read-cache: add index.skipHash config option, > 2023-01-06), do_write_index() skips that hash for the shared index > too, so with index.skipHash and core.splitIndex both set, the shared > index is written as "sharedindex.<null OID>" and the split index > records a null OID as its base. Reading the index back, a null base > ... > This gives up index.skipHash on the file where skipping the hash would > save the most per write, as the shared index holds nearly all the > entries. But what index.skipHash saves is the hashing done on each > write, and the split index is designed to make writing a shared index > rare: once there is one, a new one is written only when more than > splitIndex.maxPercentChange of the entries (20% by default) are not > in it. The frequent writes are of the split index, which holds the > entries added or changed since the shared index was written, as well > as all the extensions, and still skips the hash. The updated commit message explains both the failure mode and the trade-off clearly, without overstating the savings on split-index writes. It is also worth checking how concurrent-update detection behaves when both features are active. Suppose a repository has both core.splitIndex and index.skipHash enabled, and "git status" reads the split index and later calls repo_verify_index() before writing back. Because do_write_locked_index() still writes the split index with skip_hash enabled, the split index has a null trailing hash on disk, and merge_base_index() does not overwrite '.oid' or '.file_stat' on the main index_state. Thus verify_index_from() still sees a null '.oid' and falls back to index_file_unchanged() on .git/index, so concurrent updates are still detected correctly? Likewise, "git fsck" runs read_index_from() with verify_index_checksum set, so verify_hdr() accepts the null trailer on .git/index while verifying the real hash on the shared index file. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re:Re: [PATCH v2] read-cache: hash the shared index even with index.skipHash 2026-11-28 21:41 ` Junio C Hamano @ 2026-11-30 7:47 ` Xing Xin 0 siblings, 0 replies; 7+ messages in thread From: Xing Xin @ 2026-11-30 7:47 UTC (permalink / raw) To: Junio C Hamano; +Cc: blanet via GitGitGadget, git, Xing Xin At 2026-11-29 05:41:01, "Junio C Hamano" <gitster@pobox.com> wrote: > The updated commit message explains both the failure mode and the > trade-off clearly, without overstating the savings on split-index > writes. Thanks. > It is also worth checking how concurrent-update detection behaves when > both features are active. Suppose a repository has both core.splitIndex > and index.skipHash enabled, and "git status" reads the split index and > later calls repo_verify_index() before writing back. > > Because do_write_locked_index() still writes the split index with > skip_hash enabled, the split index has a null trailing hash on disk, and > merge_base_index() does not overwrite '.oid' or '.file_stat' on the main > index_state. Thus verify_index_from() still sees a null '.oid' and > falls back to index_file_unchanged() on .git/index, so concurrent > updates are still detected correctly? Yes. read_index_from() reads .git/index into the index_state itself, where do_read_index() records its null trailer in istate->oid and its stat data in istate->file_stat, and reads the shared index into the separate istate->split_index->base. Nothing touches these two fields of the main index_state after that: merge_base_index() only copies cache entries out of istate->split_index->base, and do_write_index() sets them only on the index_state that it writes, which is istate->split_index->base for the shared index. So verify_index_from() always checks .git/index, and since every index update, with or without a new shared index, ends by renaming a new .git/index into place, index_file_unchanged() notices it. The two index.skipHash=true tests in t7508, "status keeps an index update made after it read the index" and "status refresh does not overwrite an index update made while collecting", check exactly this. This patch drops the workaround that made them unset GIT_TEST_SPLIT_INDEX, so they now also run with a split index in the linux-feature-testbed CI job, which sets it. With GIT_TEST_SPLIT_INDEX=1 they pass, and they fail when verify_index_from() skips the stat check. I also ran the first one with core.splitIndex=true instead, with the same results. > Likewise, "git fsck" runs read_index_from() with verify_index_checksum > set, so verify_hdr() accepts the null trailer on .git/index while > verifying the real hash on the shared index file. Right. do_read_index() calls verify_hdr() for both files, and with this patch the shared index always has a real trailer, so "git fsck" verifies it: flipping a byte in an entry of the shared index makes it fail with "bad index file sha1 signature". The split index, like any index written with index.skipHash, has no checksum to verify. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-30 7:48 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-26 13:57 [PATCH] read-cache: hash the shared index even with index.skipHash blanet via GitGitGadget 2026-11-26 19:21 ` Junio C Hamano 2026-11-27 12:59 ` Xing Xin 2026-11-27 18:44 ` Junio C Hamano 2026-11-28 9:27 ` [PATCH v2] " blanet via GitGitGadget 2026-11-28 21:41 ` Junio C Hamano 2026-11-30 7:47 ` Xing Xin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox