]> git.ipfire.org Git - thirdparty/git.git/commit
split-index; stop abusing the `base_oid` to strip the "link" extension
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sun, 26 Mar 2023 22:45:41 +0000 (22:45 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Mar 2023 16:40:39 +0000 (09:40 -0700)
commit3b7a4475b0912d6d78c5e2354599dbc8f1ade479
treeefc496dea2f795e45abb75ff77d342eef5baf4b9
parent3704fed5eae8ca2fa20bcf6adb277ee83b012ce0
split-index; stop abusing the `base_oid` to strip the "link" extension

When a split-index is in effect, the `$GIT_DIR/index` file needs to
contain a "link" extension that contains all the information about the
split-index, including the information about the shared index.

However, in some cases Git needs to suppress writing that "link"
extension (i.e. to fall back to writing a full index) even if the
in-memory index structure _has_ a `split_index` configured. This is the
case e.g. when "too many not shared" index entries exist.

In such instances, the current code sets the `base_oid` field of said
`split_index` structure to all-zero to indicate that `do_write_index()`
should skip writing the "link" extension.

This can lead to problems later on, when the in-memory index is still
used to perform other operations and eventually wants to write a
split-index, detects the presence of the `split_index` and reuses that,
too (under the assumption that it has been initialized correctly and
still has a non-null `base_oid`).

Let's stop zeroing out the `base_oid` to indicate that the "link"
extension should not be written.

One might be tempted to simply call `discard_split_index()` instead,
under the assumption that Git decided to write a non-split index and
therefore the `split_index` structure might no longer be wanted.
However, that is not possible because that would release index entries
in `split_index->base` that are likely to still be in use. Therefore we
cannot do that.

The next best thing we _can_ do is to introduce a bit field to indicate
specifically which index extensions (not) to write. So that's what we do
here.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c
t/t7527-builtin-fsmonitor.sh