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

Re: [PATCH] revision.c: set-up "index_state.repo", don't segfault in pack-objects

From
Jeff King <peff@peff.net>
Date
Aug 9, 2022, 12:54 UTC
Message-ID
<YvJZCGyhd6KJCabi@coredump.intra.peff.net>
In-Reply-To
<xmqqo7wyzlpm.fsf@gitster.g>
On Fri, Aug 05, 2022 at 09:41:57AM -0700, Junio C Hamano wrote:
Show 13 quoted lines
> Ah, OK, I think the steps can be tweaked to
> 
>       git config core.untrackedCache true
>     - git worktree add at
>     - rm .git/worktrees/wt/index
>     + git worktree add --no-checkout wt
> 
>       git gc
> 
> i.e. (1) With "worktree add --no-checkout", there is no need to
> manually remove the index file, and (2) "at" is an obvious typo of
> "wt".  This does not require the history to be a singleton empty
> tree, either.

That makes sense. I worked backwards from the guess that Martin's patch was relevant, hence trying to trigger ENOENT on the file. Using --no-checkout is a plausible way to get there. (And yes, the "at" is a typo. I double-checked the script I actually ran and it did not have the typo; not sure how I managed to introduce it via cut and paste!).

The singleton empty tree was only there in my example because "git worktree" insists on having a starting point. Its contents shouldn't matter either way.

Here's the test addition you mentioned, though I'm really not sure it's adding much. The source lines for both the bug/fix and the spot where we segfault should be identical between the two cases. It's really just about how we ended up calling into the code.

-- >8 --
Subject: [PATCH] t7063: add another missing-index test

Commit 4447d4129d (read-cache: make `do_read_index()` always set up `istate->repo`, 2022-07-22) fixed a case where a missing "index" file caused us to segfault in the untracked-cache code.

We ran into another situation in the wild which caused a similar segfault, this time with an empty worktree. These actually segfault at the same spot (inside the index reading code), but the call path to get there is different between the two, hence it may be worth checking both.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 t/t7063-status-untracked-cache.sh | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
index c1f0d95036..a0e8920ffa 100755
--- a/t/t7063-status-untracked-cache.sh
+++ b/t/t7063-status-untracked-cache.sh
@@ -990,4 +990,9 @@ test_expect_success 'empty repo (no index) and core.untrackedCache' '
 	git -C emptyrepo -c core.untrackedCache=true write-tree
 '
 
+test_expect_success 'empty worktree and core.untrackedCache' '
+	git worktree add --no-checkout empty-worktree &&
+	git -c core.untrackedCache=true gc
+'
+
 test_done
-- 
2.37.1.845.ge5d2b690ea
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 15 in “Bugreport: pack-objects died of signal 11”
  1. Paul HornJul 12, 2022
  2. Jeff KingJul 14, 2022
  3. Emily NonemanAug 4, 2022
  4. Derrick StoleeAug 4, 2022
  5. Ævar Arnfjörð BjarmasonAug 4, 2022
  6. Emily NonemanAug 4, 2022
  7. revision.c: set-up "index_state.repo", don't segfault in pack-objectsÆvar Arnfjörð Bjarmason, Aug 5, 2022
  8. Derrick StoleeAug 5, 2022
  9. Jeff KingAug 5, 2022
  10. Junio C HamanoAug 5, 2022
  11. Emily NonemanAug 8, 2022
  12. Jeff KingAug 9, 2022
  13. Junio C HamanoAug 9, 2022
  14. Jeff KingAug 9, 2022
  15. Junio C HamanoAug 9, 2022

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.