git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: index.skipHash doesn't work with split index, was Re: Bug Report

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 5, 2023, 14:27 UTC
Message-ID
<3b9165a7-e37e-f429-bbcb-1b95aa9731fc@gmx.de>
In-Reply-To
<20230629083859.GA585934@coredump.intra.peff.net>
Hi,
On Thu, 29 Jun 2023, Jeff King wrote:
Show 16 quoted lines
> On Tue, Jun 27, 2023 at 05:02:30PM +0100, Tiago d'Almeida wrote:
>
> > Attached to this email follow the `git bugreport` and global `config`
> > files, and the git_bug repo.
>
> Thanks for providing your config; it was very important to reproducing.
> The bug comes from the combination of "core.splitIndex" and
> "index.skipHash" (the latter is triggered in your config by
> "feature.manyFiles").
>
> Here's a quick reproduction:
>
>   git init repo
>   cd repo
>   touch file
>   git -c core.splitIndex=true -c index.skipHash=true add file

I ran into this issue while debugging the `commit -am` issue I worked on in https://github.com/gitgitgadget/git/pull/1554.

The reason is that `write_shared_index()` calls `do_write_index()` without any additional flags (see https://github.com/git/git/blob/v2.41.0/read-cache.c#L3300) and `do_write_index()` heeds the `index.skipHash` setting always (see https://github.com/git/git/blob/v2.41.0/read-cache.c#L2900).

I briefly experimented with this diff, which is ugly and should not be used as is, but it seemed to fix the issue for me:

-- snip --
diff --git a/read-cache.c b/read-cache.c
index ee6bcf40351..92a4aa2f25a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3292,14 +3294,17 @@ static int write_shared_index(struct index_state *istate,
 			      struct tempfile **temp, unsigned flags)
 {
 	struct split_index *si = istate->split_index;
-	int ret, was_full = !istate->sparse_index;
+	int ret, was_full = !istate->sparse_index, saved_skip_hash;

 	move_cache_to_base_index(istate);
 	convert_to_sparse(istate, 0);

 	trace2_region_enter_printf("index", "shared/do_write_index",
 				   the_repository, "%s", get_tempfile_path(*temp));
+	saved_skip_hash = si->base->repo->settings.index_skip_hash;
+	si->base->repo->settings.index_skip_hash = 0;
 	ret = do_write_index(si->base, *temp, WRITE_NO_EXTENSION, flags);
+	si->base->repo->settings.index_skip_hash = saved_skip_hash;
 	trace2_region_leave_printf("index", "shared/do_write_index",
 				   the_repository, "%s", get_tempfile_path(*temp));

-- snap --

The reason why this is needed is that the shared index _must_ have an
identifer that the split index can use, and that's that index hash.
Skipping it breaks that pattern.

Probably a much better idea than above-mentioned diff would be to add a
new flag as a sibling to `COMMIT_LOCK` (i.e. here:
https://github.com/git/git/blob/v2.41.0/cache.h#L346-L348) and use that
only in `write_shared_index()` to force the index hash to be computed and
written.

I won't have time to work on this, though.

Ciao,
Johannes

>
> That should add "file" to the index but doesn't. Removing either the
> splitIndex option or the skipHash option makes it work. I didn't dig
> further than that.
>
> Adding the author of skipHash to the cc.
>
> -Peff
>
Previous: Jeff KingNext: Junio C Hamano
Message 3 of 5 in “Bug Report”
  1. Tiago d'AlmeidaJun 27, 2023
  2. index.skipHash doesn't work with split index, was Re: Bug ReportJeff King, Jun 29, 2023
  3. Johannes SchindelinJul 5, 2023
  4. Junio C HamanoJul 5, 2023
  5. Jeff KingJul 3, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.