From 0419d7d9c71a7b5fbe2e7594fb6cc26f43dc748b Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 28 Sep 2026 11:51:08 +0200 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- setup.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.c b/setup.c index 0d0a4abbe6..fa39219d6a 100644 --- a/setup.c +++ b/setup.c @@ -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;