setup: stop applying repository format twice

When discovering the repository in "setup.c" we apply the final repository format multiple times: - Once via `repository_format_configure()`, where we apply the hash algorithm and ref storage format to both `struct repository_format` and `struct repository`. - And once via `apply_repository_format()`, where we apply these two settings from `struct repository_format` to `struct repository`. With the current flow both of these are in fact necessary. But this is only because we call `repository_format_configure()` after we have called `apply_repository_format()`. Consequently, if we only changed the repository format in `repository_format_configure()` it would never propagate to the repository. 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. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 25, 2026 at 11:20 UTC 93c4361c41c3ac554ce8f61d8551d272d39ccd79
1 file changed +2 -7
setup.c
+2 -7
@@ -2710,8 +2710,7 @@ out:
2710 return ret;
2711 }
2712
2713 -static void repository_format_configure(struct repository *repo,
2714 - struct repository_format *repo_fmt,
2713 +static void repository_format_configure(struct repository_format *repo_fmt,
2714 int hash, enum ref_storage_format ref_format)
2715 {
2716 struct default_format_config cfg = {
@@ -2748,7 +2747,6 @@ static void repository_format_configure(struct repository *repo,
2747 } else if (cfg.hash != GIT_HASH_UNKNOWN) {
2748 repo_fmt->hash_algo = cfg.hash;
2749 }
2751 - repo_set_hash_algo(repo, repo_fmt->hash_algo);
2750
2751 env = getenv("GIT_DEFAULT_REF_FORMAT");
2752 if (repo_fmt->version >= 0 &&
@@ -2786,9 +2784,6 @@ static void repository_format_configure(struct repository *repo,
2784
2785 free(backend);
2786 }
2789 -
2790 - repo_set_ref_storage_format(repo, repo_fmt->ref_storage_format,
2791 - repo_fmt->ref_storage_payload);
2787 }
2788
2789 int init_db(struct repository *repo,
@@ -2830,10 +2825,10 @@ int init_db(struct repository *repo,
2825 * is an attempt to reinitialize new repository with an old tool.
2826 */
2827 check_repository_format_gently(repo_get_git_dir(repo), &repo_fmt, NULL);
2828 + repository_format_configure(&repo_fmt, hash, ref_storage_format);
2829 if (apply_repository_format(repo, &repo_fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
2830 die("%s", err.buf);
2831 startup_info->have_repository = 1;
2836 - repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
2832
2833 /*
2834 * Ensure `core.hidedotfiles` is processed. This must happen after we