]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: stop using `the_repository` in `init_db()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 20 Apr 2026 08:22:48 +0000 (10:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Apr 2026 16:53:59 +0000 (09:53 -0700)
Stop using `the_repository` in `init_db()` and instead accept
the repository as a parameter. The injection of `the_repository` is thus
bumped one level higher, where callers now pass it in explicitly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
builtin/init-db.c
setup.c
setup.h

index d8640222149c8c143427e3049954425c898b12a8..bc35a3c0b18fcbec113d1d918e969ce6570f9db1 100644 (file)
@@ -1184,7 +1184,7 @@ int cmd_clone(int argc,
         * repository, and reference backends may persist that information into
         * their on-disk data structures.
         */
-       init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
+       init_db(the_repository, git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
                ref_storage_format, NULL,
                do_not_override_repo_unix_permissions, INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
 
index e626b0d8b7ccc6366f632e38ee064db2843e15c0..c55517ad94d4470764fa7f97b4e0e06011351558 100644 (file)
@@ -252,7 +252,7 @@ int cmd_init_db(int argc,
        }
 
        flags |= INIT_DB_EXIST_OK;
-       ret = init_db(git_dir, real_git_dir, template_dir, hash_algo,
+       ret = init_db(the_repository, git_dir, real_git_dir, template_dir, hash_algo,
                      ref_storage_format, initial_branch,
                      init_shared_repository, flags);
 
diff --git a/setup.c b/setup.c
index 8616f5e619ea17ba2995e4f924b74c8813e13d87..18471116167fa4026a1ddef272725a626d8b0660 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2769,7 +2769,8 @@ static void repository_format_configure(struct repository *repo,
                                    repo_fmt->ref_storage_payload);
 }
 
-int init_db(const char *git_dir, const char *real_git_dir,
+int init_db(struct repository *repo,
+           const char *git_dir, const char *real_git_dir,
            const char *template_dir, int hash,
            enum ref_storage_format ref_storage_format,
            const char *initial_branch,
@@ -2789,13 +2790,13 @@ int init_db(const char *git_dir, const char *real_git_dir,
                if (!exist_ok && !stat(real_git_dir, &st))
                        die(_("%s already exists"), real_git_dir);
 
-               set_git_dir(the_repository, real_git_dir, 1);
-               git_dir = repo_get_git_dir(the_repository);
+               set_git_dir(repo, real_git_dir, 1);
+               git_dir = repo_get_git_dir(repo);
                separate_git_dir(git_dir, original_git_dir);
        }
        else {
-               set_git_dir(the_repository, git_dir, 1);
-               git_dir = repo_get_git_dir(the_repository);
+               set_git_dir(repo, git_dir, 1);
+               git_dir = repo_get_git_dir(repo);
        }
        startup_info->have_repository = 1;
 
@@ -2805,27 +2806,27 @@ int init_db(const char *git_dir, const char *real_git_dir,
         * config file, so this will not fail.  What we are catching
         * is an attempt to reinitialize new repository with an old tool.
         */
-       check_repository_format(the_repository, &repo_fmt);
+       check_repository_format(repo, &repo_fmt);
 
-       repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
+       repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
 
        /*
         * Ensure `core.hidedotfiles` is processed. This must happen after we
         * have set up the repository format such that we can evaluate
         * includeIf conditions correctly in the case of re-initialization.
         */
-       repo_config(the_repository, git_default_core_config, NULL);
+       repo_config(repo, git_default_core_config, NULL);
 
-       safe_create_dir(the_repository, git_dir, 0);
+       safe_create_dir(repo, git_dir, 0);
 
-       reinit = create_default_files(the_repository, template_dir, original_git_dir,
+       reinit = create_default_files(repo, template_dir, original_git_dir,
                                      &repo_fmt, init_shared_repository);
 
        if (!(flags & INIT_DB_SKIP_REFDB))
-               create_reference_database(the_repository, initial_branch, flags & INIT_DB_QUIET);
-       create_object_directory(the_repository);
+               create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET);
+       create_object_directory(repo);
 
-       if (repo_settings_get_shared_repository(the_repository)) {
+       if (repo_settings_get_shared_repository(repo)) {
                char buf[10];
                /* We do not spell "group" and such, so that
                 * the configuration can be read by older version
@@ -2833,29 +2834,29 @@ int init_db(const char *git_dir, const char *real_git_dir,
                 * and compatibility values for PERM_GROUP and
                 * PERM_EVERYBODY.
                 */
-               if (repo_settings_get_shared_repository(the_repository) < 0)
+               if (repo_settings_get_shared_repository(repo) < 0)
                        /* force to the mode value */
-                       xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(the_repository));
-               else if (repo_settings_get_shared_repository(the_repository) == PERM_GROUP)
+                       xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(repo));
+               else if (repo_settings_get_shared_repository(repo) == PERM_GROUP)
                        xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
-               else if (repo_settings_get_shared_repository(the_repository) == PERM_EVERYBODY)
+               else if (repo_settings_get_shared_repository(repo) == PERM_EVERYBODY)
                        xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
                else
                        BUG("invalid value for shared_repository");
-               repo_config_set(the_repository, "core.sharedrepository", buf);
-               repo_config_set(the_repository, "receive.denyNonFastforwards", "true");
+               repo_config_set(repo, "core.sharedrepository", buf);
+               repo_config_set(repo, "receive.denyNonFastforwards", "true");
        }
 
        if (!(flags & INIT_DB_QUIET)) {
                int len = strlen(git_dir);
 
                if (reinit)
-                       printf(repo_settings_get_shared_repository(the_repository)
+                       printf(repo_settings_get_shared_repository(repo)
                               ? _("Reinitialized existing shared Git repository in %s%s\n")
                               : _("Reinitialized existing Git repository in %s%s\n"),
                               git_dir, len && git_dir[len-1] != '/' ? "/" : "");
                else
-                       printf(repo_settings_get_shared_repository(the_repository)
+                       printf(repo_settings_get_shared_repository(repo)
                               ? _("Initialized empty shared Git repository in %s%s\n")
                               : _("Initialized empty Git repository in %s%s\n"),
                               git_dir, len && git_dir[len-1] != '/' ? "/" : "");
diff --git a/setup.h b/setup.h
index 21737e9bd69108349779a077830afb3711b21873..9409326fe47c7098c8d4ca2d3b3d717b6432bc31 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -227,7 +227,8 @@ const char *get_template_dir(const char *option_template);
 #define INIT_DB_EXIST_OK   (1 << 1)
 #define INIT_DB_SKIP_REFDB (1 << 2)
 
-int init_db(const char *git_dir, const char *real_git_dir,
+int init_db(struct repository *repo,
+           const char *git_dir, const char *real_git_dir,
            const char *template_dir, int hash_algo,
            enum ref_storage_format ref_storage_format,
            const char *initial_branch, int init_shared_repository,