]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: stop applying repository format twice
authorPatrick Steinhardt <ps@pks.im>
Thu, 25 Jun 2026 09:20:00 +0000 (11:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jun 2026 20:19:57 +0000 (13:19 -0700)
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>
setup.c

diff --git a/setup.c b/setup.c
index a9db1f2c23f32a9dd7b1bba12d862e22c7e68180..27481559644bc8aa3ca65548f15172ee56b5f4ee 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2710,8 +2710,7 @@ out:
        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