From: Junio C Hamano <gitster@pobox.com>
To: "Martin Ågren" <martin.agren@gmail.com>
Cc: Joey Hess <id@joeyh.name>,
git@vger.kernel.org, Tao Klerks <tao@klerks.biz>,
Derrick Stolee <derrickstolee@github.com>,
Victoria Dye <vdye@github.com>
Subject: Re: [PATCH] read-cache: make `do_read_index()` always set up `istate->repo`
Date: Fri, 22 Jul 2022 14:46:42 -0700 [thread overview]
Message-ID: <xmqqtu78bz25.fsf@gitster.g> (raw)
In-Reply-To: <20220722212232.833188-1-martin.agren@gmail.com> ("Martin Ågren"'s message of "Fri, 22 Jul 2022 23:22:32 +0200")
Martin Ågren <martin.agren@gmail.com> writes:
> If there is no index file, e.g., because the repository has just been
> created, we return zero early (unless `must_exist` makes us die
> instead.)
>
> This early return means we do not set up `istate->repo`. With
> `core.untrackedCache=true`, the recent e6a653554b ("untracked-cache:
> support '--untracked-files=all' if configured", 2022-03-31) will
> eventually pass down `istate->repo` as a null pointer to
> `repo_config_get_string()`, causing a segmentation fault.
>
> If we do hit this early return, set up `istate->repo` similar to when we
> actually read the index.
>
> Reported-by: Joey Hess <id@joeyh.name>
> Signed-off-by: Martin Ågren <martin.agren@gmail.com>
> ---
> read-cache.c | 5 ++++-
> t/t7063-status-untracked-cache.sh | 6 ++++++
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 3e0e7d4183..68ed65035b 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2268,8 +2268,11 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
> istate->timestamp.nsec = 0;
> fd = open(path, O_RDONLY);
> if (fd < 0) {
> - if (!must_exist && errno == ENOENT)
> + if (!must_exist && errno == ENOENT) {
> + if (!istate->repo)
> + istate->repo = the_repository;
> return 0;
> + }
Makes sense.
> die_errno(_("%s: index file open failed"), path);
> }
>
> diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh
> index 9936cc329e..7dc5631f3d 100755
> --- a/t/t7063-status-untracked-cache.sh
> +++ b/t/t7063-status-untracked-cache.sh
> @@ -985,4 +985,10 @@ test_expect_success '"status" after file replacement should be clean with UC=fal
> status_is_clean
> '
>
> +test_expect_success 'empty repo (no index) and core.untrackedCache' '
> + git init emptyrepo &&
> + cd emptyrepo/ &&
> + git -c core.untrackedCache=true write-tree
> +'
I'll tweak this with "-C emptyrepo" so that future developers do not
have to get bitten when they add more tests to this script.
THanks for a quick fix. Very much appreciated.
> test_done
next prev parent reply other threads:[~2022-07-22 21:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-22 17:24 git write-tree segfault with core.untrackedCache true and nonexistent index Joey Hess
2022-07-22 19:25 ` Martin Ågren
2022-07-22 19:41 ` Junio C Hamano
2022-07-22 21:22 ` [PATCH] read-cache: make `do_read_index()` always set up `istate->repo` Martin Ågren
2022-07-22 21:46 ` Junio C Hamano [this message]
2022-07-22 22:00 ` Martin Ågren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqtu78bz25.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=id@joeyh.name \
--cc=martin.agren@gmail.com \
--cc=tao@klerks.biz \
--cc=vdye@github.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).