Re: [PATCH 2/9] setup: stop applying repository format twice
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Jun 12, 2026, 09:00 UTC
- Message-ID
- <CAOLa=ZQC7YCBxjxkbm8qcWqpNFgAKNpvw9B6t=+XnX4bbkGq0Q@mail.gmail.com>
- In-Reply-To
- <20260610-b4-pks-refs-avoid-chdir-notify-reparent-v1-2-56c864b01c43@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 10 quoted lines
> When discovering the repository in "setup.c" we apply the final > repository format multiple times: > > - Once via `repository_format_configure()`, where we configure the > repository format for both `struct repository_format` and `struct > repository`. > > - And once via `apply_repository_format()`, where we then apply the > `struct repository_format` to the `struct repository` again. >
Okay so we're talking applying the repository format to the `struct repository` specifically.
> As the format will be applied to the repository when applying the format > it's thus somewhat unnecessary to also apply it to the repository when > adapting the discovered format.
This was a bit confusing to read at first. Okay since we already apply the format in the second step, the first is not necessary.
> The only reason we have to do this is > because we call `repository_format_configure()` after we have already > applied it.
Right, so there is a need to do this.
Show 5 quoted lines
> > Refactor the code so that we first configure the repository format > before applying it to the repository so that we can stop setting the > hash and reference storage format multiple times. >
Makse sense.
Show 52 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> setup.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index a9db1f2c23..2748155964 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -2710,8 +2710,7 @@ static int read_default_format_config(const char *key, const char *value,
> return ret;
> }
>
> -static void repository_format_configure(struct repository *repo,
> - struct repository_format *repo_fmt,
> +static void repository_format_configure(struct repository_format *repo_fmt,
> int hash, enum ref_storage_format ref_format)
> {
> struct default_format_config cfg = {
> @@ -2748,7 +2747,6 @@ static void repository_format_configure(struct repository *repo,
> } else if (cfg.hash != GIT_HASH_UNKNOWN) {
> repo_fmt->hash_algo = cfg.hash;
> }
> - repo_set_hash_algo(repo, repo_fmt->hash_algo);
>
> env = getenv("GIT_DEFAULT_REF_FORMAT");
> if (repo_fmt->version >= 0 &&
> @@ -2786,9 +2784,6 @@ static void repository_format_configure(struct repository *repo,
>
> free(backend);
> }
> -
> - repo_set_ref_storage_format(repo, repo_fmt->ref_storage_format,
> - repo_fmt->ref_storage_payload);
> }
>
> int init_db(struct repository *repo,
> @@ -2830,10 +2825,10 @@ int init_db(struct repository *repo,
> * is an attempt to reinitialize new repository with an old tool.
> */
> check_repository_format_gently(repo_get_git_dir(repo), &repo_fmt, NULL);
> + repository_format_configure(&repo_fmt, hash, ref_storage_format);
> if (apply_repository_format(repo, &repo_fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
> die("%s", err.buf);
> startup_info->have_repository = 1;
> - repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
>
> /*
> * Ensure `core.hidedotfiles` is processed. This must happen after we
>
> --
> 2.54.0.1189.g8c84645362.dirtyThe patch looks good.