setup: enforce that passed-in repo does not carry relevant state

In the preceding patches we have refactored `create_repository()` so
that the passed-in repository is not used anymore to propagate any kind
of state. This was done so that the parameter doesn't act like an in-out
parameter, but only as an out parameter that we initialize with the
state of the newly created repository.

We don't enforce though that the repository _cannot_ be used to
propagate state anymore, which makes it quite easy for state to sneak in
at a later point again.

Ideally, we'd do that by having the function create a newly allocated
repository instead of taking a repository as input. But unfortunately,
that does not work because we end up calling `repo_config_values()` when
we create the "files" ref database, and that function requires that the
passed-in repository is `the_repository`.

Instead, call `repo_clear()` at the beginning of the function, which
gives us a clean slate.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
Patrick Steinhardt 2026-09-28 11:51:08 +02:00 committed by Junio C Hamano
parent b2adfd39a0
commit 0419d7d9c7
1 changed files with 3 additions and 0 deletions

View File

@ -2858,6 +2858,9 @@ void create_repository(struct repository *repo,
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
struct strbuf err = STRBUF_INIT;

repo_clear(repo);
initialize_repository(repo);

if (real_git_dir) {
struct stat st;