{"thread":{"id":"66940","subject":"[PATCH] read-cache: hash the shared index even with index.skipHash","startedAt":"2026-11-26T13:57:23Z","lastAt":"2026-11-30T07:47:53Z","messageCount":7,"participants":["blanet via GitGitGadget","Junio C Hamano","Xing Xin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559455","messageId":"pull.2337.git.1795701443098.gitgitgadget@gmail.com","threadId":"66940","inReplyTo":null,"subject":"[PATCH] read-cache: hash the shared index even with index.skipHash","fromName":"blanet via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-26T13:57:23Z","receivedAt":"2026-11-26T13:57:23Z","isPatch":true,"sender":{"key":"name:blanet","avatar":null},"body":"From: Xing Xin <xingxin.xx@bytedance.com>\n\nThe shared index of a split index is named after its trailing hash,\nwhich the split index records in its \"link\" extension to find it.\nSince ee1f0c242e (read-cache: add index.skipHash config option,\n2023-01-06), do_write_index() skips that hash for the shared index\ntoo, so with index.skipHash and core.splitIndex both set, the shared\nindex is written as \"sharedindex.<null OID>\" and the split index\nrecords a null OID as its base. Reading the index back, a null base\nmeans there is no shared index: the entries that were moved there are\nlost, \"git ls-files\" no longer shows them and \"git status\" reports\nthem as deleted and untracked. With fsmonitor, it hits a BUG() in\nfsmonitor.c instead, as the fsmonitor bitmap refers to more entries\nthan the index has.\n\nScalar sets index.skipHash since 05f28e4b3c (scalar: use\nindex.skipHash=true for performance, 2025-12-12), and feature.manyFiles\nimplies it. The tests that ran into this under GIT_TEST_SPLIT_INDEX\nunset that variable instead, in 05f28e4b3c, in 7cce609e08 (t9210,\nt9211: disable GIT_TEST_SPLIT_INDEX for scalar clone tests,\n2026-04-15) and in a644ad5f34 (status: lock the index only to write\nit, 2026-10-22).\n\nLet the callers of do_write_index() decide whether to skip the hash,\nand always compute it for the shared index. This keeps most of the\nbenefit: the shared index is rewritten only now and then (see\nsplitIndex.maxPercentChange), while the split index, written on every\nindex update, still skips it.\n\nAdd a test, and drop the workarounds, as those tests now pass with\nGIT_TEST_SPLIT_INDEX.\n\nSigned-off-by: Xing Xin <xingxin.xx@bytedance.com>\n---\n    read-cache: hash the shared index even with index.skipHash\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2337%2Fblanet%2Fxx%2Fsplit-index-skip-hash-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2337/blanet/xx/split-index-skip-hash-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2337\n\n Documentation/config/index.adoc |  4 +++-\n read-cache.c                    | 18 ++++++++++++------\n t/t1700-split-index.sh          | 23 +++++++++++++++++++++++\n t/t7508-status.sh               | 10 ----------\n t/t9210-scalar.sh               | 10 ----------\n t/t9211-scalar-clone.sh         |  5 -----\n 6 files changed, 38 insertions(+), 32 deletions(-)\n\ndiff --git a/Documentation/config/index.adoc b/Documentation/config/index.adoc\nindex a23be914e3..e878145158 100644\n--- a/Documentation/config/index.adoc\n+++ b/Documentation/config/index.adoc\n@@ -41,7 +41,9 @@ index.skipHash::\n \tThis accelerates Git commands that manipulate the index, such as\n \t`git add`, `git commit`, or `git status`. Instead of storing the\n \tchecksum, write a trailing set of bytes with value zero, indicating\n-\tthat the computation was skipped.\n+\tthat the computation was skipped. The shared index of a split index\n+\t(see `core.splitIndex`) is still hashed, as it is named after its\n+\thash.\n +\n If you enable `index.skipHash`, then Git clients older than 2.13.0 will\n refuse to parse the index and Git clients older than 2.40.0 will report an\ndiff --git a/read-cache.c b/read-cache.c\nindex 595497d14c..a734943c97 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2878,7 +2878,8 @@ enum write_extensions {\n  * rely on it.\n  */\n static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n-\t\t\t  enum write_extensions write_extensions, unsigned flags)\n+\t\t\t  enum write_extensions write_extensions, unsigned flags,\n+\t\t\t  int skip_hash)\n {\n \tuint64_t start = getnanotime();\n \tstruct hashfile *f;\n@@ -2900,9 +2901,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n \tint nr, nr_threads, ret;\n \n \tf = hashfd(the_repository->hash_algo, tempfile->fd, tempfile->filename.buf);\n-\n-\tprepare_repo_settings(r);\n-\tf->skip_hash = r->settings.index_skip_hash;\n+\tf->skip_hash = skip_hash;\n \n \tfor (i = removed = extended = 0; i < entries; i++) {\n \t\tif (cache[i]->ce_flags & CE_REMOVE)\n@@ -3224,9 +3223,11 @@ static int do_write_locked_index(struct index_state *istate,\n \t\treturn ret;\n \t}\n \n+\tprepare_repo_settings(istate->repo);\n \ttrace2_region_enter_printf(\"index\", \"do_write_index\", istate->repo,\n \t\t\t\t   \"%s\", get_lock_file_path(lock));\n-\tret = do_write_index(istate, lock->tempfile, write_extensions, flags);\n+\tret = do_write_index(istate, lock->tempfile, write_extensions, flags,\n+\t\t\t     istate->repo->settings.index_skip_hash);\n \ttrace2_region_leave_printf(\"index\", \"do_write_index\", istate->repo,\n \t\t\t\t   \"%s\", get_lock_file_path(lock));\n \n@@ -3339,9 +3340,14 @@ static int write_shared_index(struct index_state *istate,\n \tmove_cache_to_base_index(istate);\n \tconvert_to_sparse(istate, 0);\n \n+\t/*\n+\t * The shared index is named after its trailing hash, which the\n+\t * split index records to find it: compute it even with\n+\t * index.skipHash.\n+\t */\n \ttrace2_region_enter_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n-\tret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags);\n+\tret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags, 0);\n \ttrace2_region_leave_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n \ndiff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh\nindex 887e72a5fa..86eae9eb1d 100755\n--- a/t/t1700-split-index.sh\n+++ b/t/t1700-split-index.sh\n@@ -544,4 +544,27 @@ test_expect_success 'GIT_TEST_SPLIT_INDEX works' '\n \t)\n '\n \n+test_expect_success 'shared index is hashed even with index.skipHash' '\n+\tgit init skip-hash &&\n+\t(\n+\t\tcd skip-hash &&\n+\t\tgit config core.splitIndex true &&\n+\t\tgit config index.skipHash true &&\n+\t\ttest_commit one &&\n+\t\ttest_commit two &&\n+\n+\t\ttest-tool dump-split-index .git/index >dump &&\n+\t\techo \"own $ZERO_OID\" >expect &&\n+\t\tgrep \"^own \" dump >actual &&\n+\t\ttest_cmp expect actual &&\n+\t\tbase=$(sed -n \"s/^base //p\" dump) &&\n+\t\ttest \"$base\" != \"$ZERO_OID\" &&\n+\t\ttest_path_is_file .git/sharedindex.$base &&\n+\n+\t\tgit ls-files >actual &&\n+\t\ttest_write_lines one.t two.t >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..dde5dd1020 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -1691,11 +1691,6 @@ do\n \t\tgit init update-after-read &&\n \t\t(\n \t\t\tcd update-after-read &&\n-\t\t\tif test $skip_hash = true\n-\t\t\tthen\n-\t\t\t\t# index.skipHash does not work with a split index.\n-\t\t\t\tsane_unset GIT_TEST_SPLIT_INDEX\n-\t\t\tfi &&\n \t\t\tgit config index.skipHash $skip_hash &&\n \t\t\ttest_commit base &&\n \t\t\twrite_script .git/fsmonitor-hook <<-\\EOF &&\n@@ -1769,11 +1764,6 @@ do\n \ttest_expect_success \"status refresh does not overwrite an index update made while collecting (index.skipHash=$skip_hash)\" '\n \t\ttest_when_finished \"rm -rf refresh-while-collecting\" &&\n \t\t(\n-\t\t\tif test $skip_hash = true\n-\t\t\tthen\n-\t\t\t\t# index.skipHash does not work with a split index.\n-\t\t\t\tsane_unset GIT_TEST_SPLIT_INDEX\n-\t\t\tfi &&\n \t\t\tsetup_index_update_during_collection refresh-while-collecting &&\n \t\t\tcd refresh-while-collecting &&\n \t\t\tgit config index.skipHash $skip_hash &&\ndiff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh\nindex 137765d3b8..32ad85c577 100755\n--- a/t/t9210-scalar.sh\n+++ b/t/t9210-scalar.sh\n@@ -152,10 +152,6 @@ test_expect_success 'set up repository to clone' '\n '\n \n test_expect_success 'scalar clone' '\n-\t# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are\n-\t# incompatible: the shared index gets a null OID and fails to\n-\t# load on re-read.\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n \tsecond=$(git rev-parse --verify second:second.t) &&\n \tscalar clone \"file://$(pwd)\" cloned --single-branch &&\n \t(\n@@ -186,7 +182,6 @@ test_expect_success 'scalar clone' '\n '\n \n test_expect_success 'scalar clone --no-... opts' '\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n \t# Note: redirect stderr always to avoid having a verbose test\n \t# run result in a difference in the --[no-]progress option.\n \tGIT_TRACE2_EVENT=\"$(pwd)/no-opt-trace\" scalar clone \\\n@@ -251,10 +246,6 @@ test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '\n '\n \n test_expect_success 'scalar reconfigure --all with detached HEADs' '\n-\t# This test demonstrates an issue with index.skipHash=true and\n-\t# this test variable for the split index. Disable the test variable.\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n-\n \trepos=\"two three four\" &&\n \tfor num in $repos\n \tdo\n@@ -317,7 +308,6 @@ test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '\n \n SQ=\"'\"\n test_expect_success UNZIP 'scalar diagnose' '\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n \tscalar clone \"file://$(pwd)\" cloned --single-branch &&\n \tgit repack &&\n \techo \"$(pwd)/.git/objects/\" >>cloned/src/.git/objects/info/alternates &&\ndiff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh\nindex 002d6ecdc1..110985f58d 100755\n--- a/t/t9211-scalar-clone.sh\n+++ b/t/t9211-scalar-clone.sh\n@@ -8,11 +8,6 @@ test_description='test the `scalar clone` subcommand'\n GIT_TEST_MAINT_SCHEDULER=\"crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true\"\n export GIT_TEST_MAINT_SCHEDULER\n \n-# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are\n-# incompatible: the shared index gets a null OID and fails to\n-# load on re-read.  Every test here uses scalar clone.\n-sane_unset GIT_TEST_SPLIT_INDEX\n-\n test_expect_success 'set up repository to clone' '\n \trm -rf .git &&\n \tgit init to-clone &&\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\n-- \ngitgitgadget\n\n"},{"id":"559484","messageId":"xmqqld6fjt55.fsf@gitster.g","threadId":"66940","inReplyTo":"pull.2337.git.1795701443098.gitgitgadget@gmail.com","subject":"Re: [PATCH] read-cache: hash the shared index even with index.skipHash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-26T19:21:26Z","receivedAt":"2026-11-26T19:21:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"blanet via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Xing Xin <xingxin.xx@bytedance.com>\n>\n> The shared index of a split index is named after its trailing hash,\n> which the split index records in its \"link\" extension to find it.\n> Since ee1f0c242e (read-cache: add index.skipHash config option,\n> 2023-01-06), do_write_index() skips that hash for the shared index\n> too, so with index.skipHash and core.splitIndex both set, the shared\n> index is written as \"sharedindex.<null OID>\" and the split index\n> records a null OID as its base. Reading the index back, a null base\n> means there is no shared index: the entries that were moved there are\n> lost, \"git ls-files\" no longer shows them and \"git status\" reports\n> them as deleted and untracked. With fsmonitor, it hits a BUG() in\n> fsmonitor.c instead, as the fsmonitor bitmap refers to more entries\n> than the index has.\n\nIt is correct to point out that the two \"features\", skipHash and\nsplitIndex, are incompatible.  With skipHash, splitIndex will not\ncorrectly work.  We can say skipHash breaks splitIndex.\n\nBut does this change to _force_ the base index files to be hashed,\nagainst the user's wish expressed by skipHash, take us in a better\ndirection, I have to wonder?  With this change, skipHash's promise to\nimprove performance is not kept.  We can say splitIndex breaks skipHash.\n\nStepping back a bit, isn't the expectation of splitIndex that these\nincremental modifications held in non-base index files are relatively\nsmall, thanks to the bulk of data that the base index file holds\ncovering almost everything in the repository?  In other words, isn't the\nuse of splitIndex a strong sign that the base index file would benefit\nthe most from skipHash?  And this patch is breaking the skipHash feature\nfor the use case that would benefit the most.  And not hashing the index\nfiles that are not bases would not save as much, since they are expected\nto be much smaller.\n\nI wonder if going in the other direction, i.e., when both are enabled,\ndisabling splitIndex and working only on the base hash, would be an\nalternative that is equally viable as this change?  Both will *break*\nthe promise of one feature so that the result can live with the other\nfeature.  What are the pros and cons between them?\n\n\n"},{"id":"559523","messageId":"5dfa732c.94b8.1a21d16a974.Coremail.bupt_xingxin@163.com","threadId":"66940","inReplyTo":"xmqqld6fjt55.fsf@gitster.g","subject":"Re:Re: [PATCH] read-cache: hash the shared index even with index.skipHash","fromName":"Xing Xin","fromEmail":"bupt_xingxin@163.com","sentAt":"2026-11-27T12:59:14Z","receivedAt":"2026-11-27T12:59:14Z","isPatch":true,"sender":{"key":"bupt_xingxin@163.com","avatar":null},"body":"At 2026-11-27 03:21:26, \"Junio C Hamano\" <gitster@pobox.com> wrote:\n\n> It is correct to point out that the two \"features\", skipHash and\n> splitIndex, are incompatible.  With skipHash, splitIndex will not\n> correctly work.  We can say skipHash breaks splitIndex.\n>\n> But does this change to _force_ the base index files to be hashed,\n> against the user's wish expressed by skipHash, take us in a better\n> direction, I have to wonder?  With this change, skipHash's promise to\n> improve performance is not kept.  We can say splitIndex breaks skipHash.\n\nYou are right, and the log message overstates the case when it says\nthat this \"keeps most of the benefit\".  As the numbers below show,\nthe split index file is small enough that skipping its hash saves\nnext to nothing, so with this patch index.skipHash has little effect\nonce a split index is in use.\n\nThat said, I do not think both can be kept without changing the index\nformat.  Readers die() unless the \"link\" extension names the trailing\nhash of the shared index, and a trailer that is neither null nor the\nreal hash makes \"git fsck\" fail.  So a shared index written without\nits hash can only be called sharedindex.<null OID>, which is exactly\nwhat goes wrong today.  One of the two has to give.\n\n> Stepping back a bit, isn't the expectation of splitIndex that these\n> incremental modifications held in non-base index files are relatively\n> small, thanks to the bulk of data that the base index file holds\n> covering almost everything in the repository?  In other words, isn't the\n> use of splitIndex a strong sign that the base index file would benefit\n> the most from skipHash?  And this patch is breaking the skipHash feature\n> for the use case that would benefit the most.  And not hashing the index\n> files that are not bases would not save as much, since they are expected\n> to be much smaller.\n\nPer write, yes.  But what skipHash saves is the hashing done on each\nwrite, and the shared index is only written when it is rewritten,\nwhich the split index is designed to make rare.  The frequent writes\nare of the small split index, where, as you say, there is little to\nsave.\n\n> I wonder if going in the other direction, i.e., when both are enabled,\n> disabling splitIndex and working only on the base hash, would be an\n> alternative that is equally viable as this change?  Both will *break*\n> the promise of one feature so that the result can live with the other\n> feature.  What are the pros and cons between them?\n\nI see three ways to resolve it when both are set:\n\n  1. disable the split index and keep skipHash (your suggestion),\n  2. keep the split index and ignore index.skipHash while it is in\n     use,\n  3. keep both, but always hash the shared index (this patch).\n\nTo compare them, I measured a repository with 100k files in 1,000\ndirectories, index v4 (7.0MB) with the untracked cache enabled, so\nthat the split index carries the cache-tree and untracked cache\nextensions as it would in practice.  Each round changes K files and\nruns \"git add -u\", \"git commit\", \"git status\" (after touching the\nfiles), and \"git checkout HEAD~1\" and back.  1 and 2 are emulated by\nturning the other setting off.  The times are the index write and\nread regions from trace2, median of 7 runs, averaged over add, commit\nand status (Apple M4 Pro, SHA1DC):\n\n                          index write (ms)     index    .git/index\n                        K=1   K=100  K=10000   read     K=1 / K=10000\n  neither              18.3   15.2    15.5     3 ms     7.0 / 7.0 MB\n  1: skipHash only      6.1    6.0     6.1     3 ms     7.0 / 7.0 MB\n  2: splitIndex only    0.4    0.4     1.9     3 ms    0.07 / 0.75 MB\n  3: both, this patch   0.3    0.3     0.9     3 ms    0.07 / 0.75 MB\n\nRewriting the whole index takes 15-20ms with neither feature and 6ms\nwith skipHash; rewriting the shared index takes 15-22ms with 2 or 3,\nas both hash it.  The checkout round trip, which writes the index\ntwice, shows the same pattern.\n\n - The write time hardly depends on K: without a split index every\n   write covers all entries, and with one the split index stays small\n   (0.75MB at K=10000).  No K up to 10000 (10% of the entries) made 2\n   or 3 rewrite the shared index; that takes new or re-created entries\n   beyond splitIndex.maxPercentChange (20% by default), e.g. when\n   checking out a distant branch.\n\n - 1 cuts each write from ~15-18ms to ~6ms.  2 cuts it to under 2ms,\n   but pays ~10-15ms more than 1 whenever it rewrites the shared\n   index, so it comes out ahead unless about one write in three does\n   so.\n\n - 3 differs from 2 only in hashing .git/index, which costs ~0.1ms\n   for 0.07MB and ~1ms for 0.75MB here.  That is all index.skipHash\n   can still save with a split index.\n\n - The index read time is the same ~3ms in all four.\n\n - At this size, all of this is small next to the run times of the\n   commands (110ms to 3.8s), which are dominated by the work on the\n   files themselves, and the differences there are mostly within the\n   noise.\n\nPerformance aside, the two settings do not come from symmetric\nplaces, which matters for 1:\n\n - index.skipHash is only ever a configuration variable: it is either\n   implied by feature.manyFiles, or set as index.skipHash, by the user\n   or by Scalar, which writes index.skipHash=true into the repository\n   configuration and resets it on \"scalar reconfigure\".\n\n - The split index is enabled by core.splitIndex, which neither a\n   feature.* setting nor Scalar sets, or by \"git update-index\n   --split-index\", which stays in effect while core.splitIndex is\n   unset.\n\nWhen both are set in the configuration, there is no telling which one\nthe user cares about more.  But 1 would let a default implied by\nfeature.manyFiles override an explicit core.splitIndex, although\nfeature.* is documented to only change defaults.  For \"git\nupdate-index --split-index\", 1 would either have to let a\nconfiguration variable override a command line option, whereas today\nthe option still takes effect, with a warning, when core.splitIndex\nis false, or honor the option for that write, which needs the change\nin this patch anyway.  And in a Scalar enlistment, core.splitIndex\nwould only work after setting index.skipHash=false, and would stop\nworking again at the next \"scalar reconfigure\".  There is also\nprecedent for the split index taking priority: the sparse index is\nnot written while a split index is in use (see\nis_sparse_index_allowed()).\n\nBetween 2 and 3 the performance is practically the same, so it comes\ndown to principle.  3 deviates from the configuration only where the\nindex format forces it to.  2 is simpler to explain (\"index.skipHash\nhas no effect with a split index\") and keeps the checksum of\n.git/index, at the cost of ignoring a setting it does not strictly\nneed to ignore.  I lean towards 3, but would be happy to switch to 2\nif you prefer the simpler rule; the difference is a single condition.\n\nOnce we settle on the direction, I will send a v2 with the log\nmessage and documentation updated accordingly.\n\nThanks."},{"id":"559546","messageId":"xmqqwlpy8681.fsf@gitster.g","threadId":"66940","inReplyTo":"5dfa732c.94b8.1a21d16a974.Coremail.bupt_xingxin@163.com","subject":"Re: [PATCH] read-cache: hash the shared index even with index.skipHash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-27T18:44:14Z","receivedAt":"2026-11-27T18:44:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Xing Xin\" <bupt_xingxin@163.com> writes:\n\n>> the most from skipHash?  And this patch is breaking the skipHash feature\n>> for the use case that would benefit the most.  And not hashing the index\n>> files that are not bases would not save as much, since they are expected\n>> to be much smaller.\n>\n> Per write, yes.  But what skipHash saves is the hashing done on each\n> write, and the shared index is only written when it is rewritten,\n> which the split index is designed to make rare.  The frequent writes\n> are of the small split index, where, as you say, there is little to\n> save.\n\nThat is a very good justification to give in the proposed commit log\nmessage and also in the documentation (the behaviour may already be\ndocumented in this initial version of the patch, but the reason why the\nbase index ignores the skipHash configuration deserves a mention, too).\n\n>  - index.skipHash is only ever a configuration variable: it is either\n>    implied by feature.manyFiles, or set as index.skipHash, by the user\n>    or by Scalar, which writes index.skipHash=true into the repository\n>    configuration and resets it on \"scalar reconfigure\".\n>\n>  - The split index is enabled by core.splitIndex, which neither a\n>    feature.* setting nor Scalar sets, or by \"git update-index\n>    --split-index\", which stays in effect while core.splitIndex is\n>    unset.\n>\n> When both are set in the configuration, there is no telling which one\n> the user cares about more.\n\nIsn't that mostly a defect of Scalar?  Such a tool that configures the\nrepository without close supervision by the user should be responsible\nfor ensuring that the resulting set of configuration variables gives a\ncoherent story of what the user wants.\n\nBut by going the route of your patch, we no longer have to worry about\nthese two features conflicting, so I would say it is a good direction to\ngo.\n\nThanks.\n\n"},{"id":"559593","messageId":"pull.2337.v2.git.1795858039529.gitgitgadget@gmail.com","threadId":"66940","inReplyTo":"pull.2337.git.1795701443098.gitgitgadget@gmail.com","subject":"[PATCH v2] read-cache: hash the shared index even with index.skipHash","fromName":"blanet via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-28T09:27:19Z","receivedAt":"2026-11-28T09:27:19Z","isPatch":true,"sender":{"key":"name:blanet","avatar":null},"body":"From: Xing Xin <xingxin.xx@bytedance.com>\n\nThe shared index of a split index is named after its trailing hash,\nwhich the split index records in its \"link\" extension to find it.\nSince ee1f0c242e (read-cache: add index.skipHash config option,\n2023-01-06), do_write_index() skips that hash for the shared index\ntoo, so with index.skipHash and core.splitIndex both set, the shared\nindex is written as \"sharedindex.<null OID>\" and the split index\nrecords a null OID as its base. Reading the index back, a null base\nmeans there is no shared index: the entries that were moved there are\nlost, \"git ls-files\" no longer shows them and \"git status\" reports\nthem as deleted and untracked. With fsmonitor, it can hit a BUG() in\nfsmonitor.c instead, when the fsmonitor bitmap refers to more entries\nthan the index has.\n\nScalar has enabled index.skipHash since 05f28e4b3c (scalar: use\nindex.skipHash=true for performance, 2025-12-12), and\nfeature.manyFiles implies it. The tests that ran into this under\nGIT_TEST_SPLIT_INDEX unset that variable instead, in 05f28e4b3c, in\n7cce609e08 (t9210, t9211: disable GIT_TEST_SPLIT_INDEX for scalar\nclone tests, 2026-04-15), and in 6b6d1d56eb (read-cache: verify\nskipHash index by stat data, 2026-10-22) and a644ad5f34 (status: lock\nthe index only to write it, 2026-10-22).\n\nLet the callers of do_write_index() decide whether to skip the hash,\nand always compute it for the shared index, so that the two settings\nno longer conflict.\n\nThis gives up index.skipHash on the file where skipping the hash would\nsave the most per write, as the shared index holds nearly all the\nentries. But what index.skipHash saves is the hashing done on each\nwrite, and the split index is designed to make writing a shared index\nrare: once there is one, a new one is written only when more than\nsplitIndex.maxPercentChange of the entries (20% by default) are not\nin it. The frequent writes are of the split index, which holds the\nentries added or changed since the shared index was written, as well\nas all the extensions, and still skips the hash.\n\nDocument this under index.skipHash, add a test, and drop the\nworkarounds, as those tests now pass with GIT_TEST_SPLIT_INDEX.\n\nSigned-off-by: Xing Xin <xingxin.xx@bytedance.com>\n---\n    read-cache: hash the shared index even with index.skipHash\n    \n    Changes since v1:\n    \n     * Explain in the log message why hashing the shared index despite\n       index.skipHash is acceptable, as it is rewritten only rarely, and\n       drop the claim that this keeps most of the benefit.\n     * Say the same in the index.skipHash documentation.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2337%2Fblanet%2Fxx%2Fsplit-index-skip-hash-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2337/blanet/xx/split-index-skip-hash-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/2337\n\nRange-diff vs v1:\n\n 1:  0502560699 ! 1:  16091375ca read-cache: hash the shared index even with index.skipHash\n     @@ Commit message\n          records a null OID as its base. Reading the index back, a null base\n          means there is no shared index: the entries that were moved there are\n          lost, \"git ls-files\" no longer shows them and \"git status\" reports\n     -    them as deleted and untracked. With fsmonitor, it hits a BUG() in\n     -    fsmonitor.c instead, as the fsmonitor bitmap refers to more entries\n     +    them as deleted and untracked. With fsmonitor, it can hit a BUG() in\n     +    fsmonitor.c instead, when the fsmonitor bitmap refers to more entries\n          than the index has.\n      \n     -    Scalar sets index.skipHash since 05f28e4b3c (scalar: use\n     -    index.skipHash=true for performance, 2025-12-12), and feature.manyFiles\n     -    implies it. The tests that ran into this under GIT_TEST_SPLIT_INDEX\n     -    unset that variable instead, in 05f28e4b3c, in 7cce609e08 (t9210,\n     -    t9211: disable GIT_TEST_SPLIT_INDEX for scalar clone tests,\n     -    2026-04-15) and in a644ad5f34 (status: lock the index only to write\n     -    it, 2026-10-22).\n     +    Scalar has enabled index.skipHash since 05f28e4b3c (scalar: use\n     +    index.skipHash=true for performance, 2025-12-12), and\n     +    feature.manyFiles implies it. The tests that ran into this under\n     +    GIT_TEST_SPLIT_INDEX unset that variable instead, in 05f28e4b3c, in\n     +    7cce609e08 (t9210, t9211: disable GIT_TEST_SPLIT_INDEX for scalar\n     +    clone tests, 2026-04-15), and in 6b6d1d56eb (read-cache: verify\n     +    skipHash index by stat data, 2026-10-22) and a644ad5f34 (status: lock\n     +    the index only to write it, 2026-10-22).\n      \n          Let the callers of do_write_index() decide whether to skip the hash,\n     -    and always compute it for the shared index. This keeps most of the\n     -    benefit: the shared index is rewritten only now and then (see\n     -    splitIndex.maxPercentChange), while the split index, written on every\n     -    index update, still skips it.\n     +    and always compute it for the shared index, so that the two settings\n     +    no longer conflict.\n      \n     -    Add a test, and drop the workarounds, as those tests now pass with\n     -    GIT_TEST_SPLIT_INDEX.\n     +    This gives up index.skipHash on the file where skipping the hash would\n     +    save the most per write, as the shared index holds nearly all the\n     +    entries. But what index.skipHash saves is the hashing done on each\n     +    write, and the split index is designed to make writing a shared index\n     +    rare: once there is one, a new one is written only when more than\n     +    splitIndex.maxPercentChange of the entries (20% by default) are not\n     +    in it. The frequent writes are of the split index, which holds the\n     +    entries added or changed since the shared index was written, as well\n     +    as all the extensions, and still skips the hash.\n     +\n     +    Document this under index.skipHash, add a test, and drop the\n     +    workarounds, as those tests now pass with GIT_TEST_SPLIT_INDEX.\n      \n          Signed-off-by: Xing Xin <xingxin.xx@bytedance.com>\n      \n       ## Documentation/config/index.adoc ##\n      @@ Documentation/config/index.adoc: index.skipHash::\n     - \tThis accelerates Git commands that manipulate the index, such as\n     - \t`git add`, `git commit`, or `git status`. Instead of storing the\n       \tchecksum, write a trailing set of bytes with value zero, indicating\n     --\tthat the computation was skipped.\n     -+\tthat the computation was skipped. The shared index of a split index\n     -+\t(see `core.splitIndex`) is still hashed, as it is named after its\n     -+\thash.\n     + \tthat the computation was skipped.\n       +\n     ++With a split index (see `core.splitIndex`), only the split index, which\n     ++is written on every index update, skips the hash. The shared index is\n     ++still hashed, as it is named after its hash, but it is rewritten only\n     ++when too many entries are not in it (see `splitIndex.maxPercentChange`).\n     +++\n       If you enable `index.skipHash`, then Git clients older than 2.13.0 will\n       refuse to parse the index and Git clients older than 2.40.0 will report an\n     + error during `git fsck`.\n      \n       ## read-cache.c ##\n      @@ read-cache.c: enum write_extensions {\n\n\n Documentation/config/index.adoc |  5 +++++\n read-cache.c                    | 18 ++++++++++++------\n t/t1700-split-index.sh          | 23 +++++++++++++++++++++++\n t/t7508-status.sh               | 10 ----------\n t/t9210-scalar.sh               | 10 ----------\n t/t9211-scalar-clone.sh         |  5 -----\n 6 files changed, 40 insertions(+), 31 deletions(-)\n\ndiff --git a/Documentation/config/index.adoc b/Documentation/config/index.adoc\nindex a23be914e3..08620846b5 100644\n--- a/Documentation/config/index.adoc\n+++ b/Documentation/config/index.adoc\n@@ -43,6 +43,11 @@ index.skipHash::\n \tchecksum, write a trailing set of bytes with value zero, indicating\n \tthat the computation was skipped.\n +\n+With a split index (see `core.splitIndex`), only the split index, which\n+is written on every index update, skips the hash. The shared index is\n+still hashed, as it is named after its hash, but it is rewritten only\n+when too many entries are not in it (see `splitIndex.maxPercentChange`).\n++\n If you enable `index.skipHash`, then Git clients older than 2.13.0 will\n refuse to parse the index and Git clients older than 2.40.0 will report an\n error during `git fsck`.\ndiff --git a/read-cache.c b/read-cache.c\nindex 595497d14c..a734943c97 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2878,7 +2878,8 @@ enum write_extensions {\n  * rely on it.\n  */\n static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n-\t\t\t  enum write_extensions write_extensions, unsigned flags)\n+\t\t\t  enum write_extensions write_extensions, unsigned flags,\n+\t\t\t  int skip_hash)\n {\n \tuint64_t start = getnanotime();\n \tstruct hashfile *f;\n@@ -2900,9 +2901,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n \tint nr, nr_threads, ret;\n \n \tf = hashfd(the_repository->hash_algo, tempfile->fd, tempfile->filename.buf);\n-\n-\tprepare_repo_settings(r);\n-\tf->skip_hash = r->settings.index_skip_hash;\n+\tf->skip_hash = skip_hash;\n \n \tfor (i = removed = extended = 0; i < entries; i++) {\n \t\tif (cache[i]->ce_flags & CE_REMOVE)\n@@ -3224,9 +3223,11 @@ static int do_write_locked_index(struct index_state *istate,\n \t\treturn ret;\n \t}\n \n+\tprepare_repo_settings(istate->repo);\n \ttrace2_region_enter_printf(\"index\", \"do_write_index\", istate->repo,\n \t\t\t\t   \"%s\", get_lock_file_path(lock));\n-\tret = do_write_index(istate, lock->tempfile, write_extensions, flags);\n+\tret = do_write_index(istate, lock->tempfile, write_extensions, flags,\n+\t\t\t     istate->repo->settings.index_skip_hash);\n \ttrace2_region_leave_printf(\"index\", \"do_write_index\", istate->repo,\n \t\t\t\t   \"%s\", get_lock_file_path(lock));\n \n@@ -3339,9 +3340,14 @@ static int write_shared_index(struct index_state *istate,\n \tmove_cache_to_base_index(istate);\n \tconvert_to_sparse(istate, 0);\n \n+\t/*\n+\t * The shared index is named after its trailing hash, which the\n+\t * split index records to find it: compute it even with\n+\t * index.skipHash.\n+\t */\n \ttrace2_region_enter_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n-\tret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags);\n+\tret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags, 0);\n \ttrace2_region_leave_printf(\"index\", \"shared/do_write_index\",\n \t\t\t\t   the_repository, \"%s\", get_tempfile_path(*temp));\n \ndiff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh\nindex 887e72a5fa..86eae9eb1d 100755\n--- a/t/t1700-split-index.sh\n+++ b/t/t1700-split-index.sh\n@@ -544,4 +544,27 @@ test_expect_success 'GIT_TEST_SPLIT_INDEX works' '\n \t)\n '\n \n+test_expect_success 'shared index is hashed even with index.skipHash' '\n+\tgit init skip-hash &&\n+\t(\n+\t\tcd skip-hash &&\n+\t\tgit config core.splitIndex true &&\n+\t\tgit config index.skipHash true &&\n+\t\ttest_commit one &&\n+\t\ttest_commit two &&\n+\n+\t\ttest-tool dump-split-index .git/index >dump &&\n+\t\techo \"own $ZERO_OID\" >expect &&\n+\t\tgrep \"^own \" dump >actual &&\n+\t\ttest_cmp expect actual &&\n+\t\tbase=$(sed -n \"s/^base //p\" dump) &&\n+\t\ttest \"$base\" != \"$ZERO_OID\" &&\n+\t\ttest_path_is_file .git/sharedindex.$base &&\n+\n+\t\tgit ls-files >actual &&\n+\t\ttest_write_lines one.t two.t >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..dde5dd1020 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -1691,11 +1691,6 @@ do\n \t\tgit init update-after-read &&\n \t\t(\n \t\t\tcd update-after-read &&\n-\t\t\tif test $skip_hash = true\n-\t\t\tthen\n-\t\t\t\t# index.skipHash does not work with a split index.\n-\t\t\t\tsane_unset GIT_TEST_SPLIT_INDEX\n-\t\t\tfi &&\n \t\t\tgit config index.skipHash $skip_hash &&\n \t\t\ttest_commit base &&\n \t\t\twrite_script .git/fsmonitor-hook <<-\\EOF &&\n@@ -1769,11 +1764,6 @@ do\n \ttest_expect_success \"status refresh does not overwrite an index update made while collecting (index.skipHash=$skip_hash)\" '\n \t\ttest_when_finished \"rm -rf refresh-while-collecting\" &&\n \t\t(\n-\t\t\tif test $skip_hash = true\n-\t\t\tthen\n-\t\t\t\t# index.skipHash does not work with a split index.\n-\t\t\t\tsane_unset GIT_TEST_SPLIT_INDEX\n-\t\t\tfi &&\n \t\t\tsetup_index_update_during_collection refresh-while-collecting &&\n \t\t\tcd refresh-while-collecting &&\n \t\t\tgit config index.skipHash $skip_hash &&\ndiff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh\nindex 137765d3b8..32ad85c577 100755\n--- a/t/t9210-scalar.sh\n+++ b/t/t9210-scalar.sh\n@@ -152,10 +152,6 @@ test_expect_success 'set up repository to clone' '\n '\n \n test_expect_success 'scalar clone' '\n-\t# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are\n-\t# incompatible: the shared index gets a null OID and fails to\n-\t# load on re-read.\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n \tsecond=$(git rev-parse --verify second:second.t) &&\n \tscalar clone \"file://$(pwd)\" cloned --single-branch &&\n \t(\n@@ -186,7 +182,6 @@ test_expect_success 'scalar clone' '\n '\n \n test_expect_success 'scalar clone --no-... opts' '\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n \t# Note: redirect stderr always to avoid having a verbose test\n \t# run result in a difference in the --[no-]progress option.\n \tGIT_TRACE2_EVENT=\"$(pwd)/no-opt-trace\" scalar clone \\\n@@ -251,10 +246,6 @@ test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '\n '\n \n test_expect_success 'scalar reconfigure --all with detached HEADs' '\n-\t# This test demonstrates an issue with index.skipHash=true and\n-\t# this test variable for the split index. Disable the test variable.\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n-\n \trepos=\"two three four\" &&\n \tfor num in $repos\n \tdo\n@@ -317,7 +308,6 @@ test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '\n \n SQ=\"'\"\n test_expect_success UNZIP 'scalar diagnose' '\n-\tsane_unset GIT_TEST_SPLIT_INDEX &&\n \tscalar clone \"file://$(pwd)\" cloned --single-branch &&\n \tgit repack &&\n \techo \"$(pwd)/.git/objects/\" >>cloned/src/.git/objects/info/alternates &&\ndiff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh\nindex 002d6ecdc1..110985f58d 100755\n--- a/t/t9211-scalar-clone.sh\n+++ b/t/t9211-scalar-clone.sh\n@@ -8,11 +8,6 @@ test_description='test the `scalar clone` subcommand'\n GIT_TEST_MAINT_SCHEDULER=\"crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true\"\n export GIT_TEST_MAINT_SCHEDULER\n \n-# index.skipHash (Scalar default) and GIT_TEST_SPLIT_INDEX are\n-# incompatible: the shared index gets a null OID and fails to\n-# load on re-read.  Every test here uses scalar clone.\n-sane_unset GIT_TEST_SPLIT_INDEX\n-\n test_expect_success 'set up repository to clone' '\n \trm -rf .git &&\n \tgit init to-clone &&\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\n-- \ngitgitgadget\n\n"},{"id":"559614","messageId":"xmqq7bhwvdle.fsf@gitster.g","threadId":"66940","inReplyTo":"pull.2337.v2.git.1795858039529.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] read-cache: hash the shared index even with index.skipHash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-28T21:41:01Z","receivedAt":"2026-11-28T21:41:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"blanet via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Xing Xin <xingxin.xx@bytedance.com>\n>\n> The shared index of a split index is named after its trailing hash,\n> which the split index records in its \"link\" extension to find it.\n> Since ee1f0c242e (read-cache: add index.skipHash config option,\n> 2023-01-06), do_write_index() skips that hash for the shared index\n> too, so with index.skipHash and core.splitIndex both set, the shared\n> index is written as \"sharedindex.<null OID>\" and the split index\n> records a null OID as its base. Reading the index back, a null base\n> ...\n> This gives up index.skipHash on the file where skipping the hash would\n> save the most per write, as the shared index holds nearly all the\n> entries. But what index.skipHash saves is the hashing done on each\n> write, and the split index is designed to make writing a shared index\n> rare: once there is one, a new one is written only when more than\n> splitIndex.maxPercentChange of the entries (20% by default) are not\n> in it. The frequent writes are of the split index, which holds the\n> entries added or changed since the shared index was written, as well\n> as all the extensions, and still skips the hash.\n\nThe updated commit message explains both the failure mode and the\ntrade-off clearly, without overstating the savings on split-index\nwrites.\n\nIt is also worth checking how concurrent-update detection behaves when\nboth features are active.  Suppose a repository has both core.splitIndex\nand index.skipHash enabled, and \"git status\" reads the split index and\nlater calls repo_verify_index() before writing back.\n\nBecause do_write_locked_index() still writes the split index with\nskip_hash enabled, the split index has a null trailing hash on disk, and\nmerge_base_index() does not overwrite '.oid' or '.file_stat' on the main\nindex_state.  Thus verify_index_from() still sees a null '.oid' and\nfalls back to index_file_unchanged() on .git/index, so concurrent\nupdates are still detected correctly?  \n\nLikewise, \"git fsck\" runs read_index_from() with verify_index_checksum\nset, so verify_hdr() accepts the null trailer on .git/index while\nverifying the real hash on the shared index file.\n\n"},{"id":"559671","messageId":"47be148e.6b3d.1a22b6cb367.Coremail.bupt_xingxin@163.com","threadId":"66940","inReplyTo":"xmqq7bhwvdle.fsf@gitster.g","subject":"Re:Re: [PATCH v2] read-cache: hash the shared index even with index.skipHash","fromName":"Xing Xin","fromEmail":"bupt_xingxin@163.com","sentAt":"2026-11-30T07:47:53Z","receivedAt":"2026-11-30T07:47:53Z","isPatch":true,"sender":{"key":"bupt_xingxin@163.com","avatar":null},"body":"At 2026-11-29 05:41:01, \"Junio C Hamano\" <gitster@pobox.com> wrote:\n\n> The updated commit message explains both the failure mode and the\n> trade-off clearly, without overstating the savings on split-index\n> writes.\n\nThanks.\n\n> It is also worth checking how concurrent-update detection behaves when\n> both features are active.  Suppose a repository has both core.splitIndex\n> and index.skipHash enabled, and \"git status\" reads the split index and\n> later calls repo_verify_index() before writing back.\n>\n> Because do_write_locked_index() still writes the split index with\n> skip_hash enabled, the split index has a null trailing hash on disk, and\n> merge_base_index() does not overwrite '.oid' or '.file_stat' on the main\n> index_state.  Thus verify_index_from() still sees a null '.oid' and\n> falls back to index_file_unchanged() on .git/index, so concurrent\n> updates are still detected correctly?\n\nYes. read_index_from() reads .git/index into the index_state itself,\nwhere do_read_index() records its null trailer in istate->oid and its\nstat data in istate->file_stat, and reads the shared index into the\nseparate istate->split_index->base. Nothing touches these two fields\nof the main index_state after that: merge_base_index() only copies\ncache entries out of istate->split_index->base, and do_write_index()\nsets them only on the index_state that it writes, which is\nistate->split_index->base for the shared index. So verify_index_from()\nalways checks .git/index, and since every index update, with or\nwithout a new shared index, ends by renaming a new .git/index into\nplace, index_file_unchanged() notices it.\n\nThe two index.skipHash=true tests in t7508, \"status keeps an index\nupdate made after it read the index\" and \"status refresh does not\noverwrite an index update made while collecting\", check exactly this.\nThis patch drops the workaround that made them unset\nGIT_TEST_SPLIT_INDEX, so they now also run with a split index in the\nlinux-feature-testbed CI job, which sets it. With\nGIT_TEST_SPLIT_INDEX=1 they pass, and they fail when\nverify_index_from() skips the stat check. I also ran the first one\nwith core.splitIndex=true instead, with the same results.\n\n> Likewise, \"git fsck\" runs read_index_from() with verify_index_checksum\n> set, so verify_hdr() accepts the null trailer on .git/index while\n> verifying the real hash on the shared index file.\n\nRight. do_read_index() calls verify_hdr() for both files, and with\nthis patch the shared index always has a real trailer, so \"git fsck\"\nverifies it: flipping a byte in an entry of the shared index makes it\nfail with \"bad index file sha1 signature\". The split index, like any\nindex written with index.skipHash, has no checksum to verify.\n"}]}