setup: stop using `the_repository` in `init_db()`

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>

Patrick Steinhardt committed May 19, 2026 at 11:52 UTC df69f40c34de003ebc43cfe514526b11ffdec113
4 files changed +26 -24
builtin/clone.c
+1 -1
@@ -1186,7 +1186,7 @@ int cmd_clone(int argc,
1186 * repository, and reference backends may persist that information into
1187 * their on-disk data structures.
1188 */
1189 - init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
1189 + init_db(the_repository, git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
1190 ref_storage_format, NULL,
1191 do_not_override_repo_unix_permissions, INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
1192
builtin/init-db.c
+1 -1
@@ -252,7 +252,7 @@ int cmd_init_db(int argc,
252 }
253
254 flags |= INIT_DB_EXIST_OK;
255 - ret = init_db(git_dir, real_git_dir, template_dir, hash_algo,
255 + ret = init_db(the_repository, git_dir, real_git_dir, template_dir, hash_algo,
256 ref_storage_format, initial_branch,
257 init_shared_repository, flags);
258
setup.c
+22 -21
@@ -2778,7 +2778,8 @@ static void repository_format_configure(struct repository *repo,
2778 repo_fmt->ref_storage_payload);
2779 }
2780
2781 -int init_db(const char *git_dir, const char *real_git_dir,
2781 +int init_db(struct repository *repo,
2782 + const char *git_dir, const char *real_git_dir,
2783 const char *template_dir, int hash,
2784 enum ref_storage_format ref_storage_format,
2785 const char *initial_branch,
@@ -2798,13 +2799,13 @@ int init_db(const char *git_dir, const char *real_git_dir,
2799 if (!exist_ok && !stat(real_git_dir, &st))
2800 die(_("%s already exists"), real_git_dir);
2801
2801 - set_git_dir(the_repository, real_git_dir, 1);
2802 - git_dir = repo_get_git_dir(the_repository);
2802 + set_git_dir(repo, real_git_dir, 1);
2803 + git_dir = repo_get_git_dir(repo);
2804 separate_git_dir(git_dir, original_git_dir);
2805 }
2806 else {
2806 - set_git_dir(the_repository, git_dir, 1);
2807 - git_dir = repo_get_git_dir(the_repository);
2807 + set_git_dir(repo, git_dir, 1);
2808 + git_dir = repo_get_git_dir(repo);
2809 }
2810 startup_info->have_repository = 1;
2811
@@ -2814,27 +2815,27 @@ int init_db(const char *git_dir, const char *real_git_dir,
2815 * config file, so this will not fail. What we are catching
2816 * is an attempt to reinitialize new repository with an old tool.
2817 */
2817 - check_repository_format(the_repository, &repo_fmt);
2818 + check_repository_format(repo, &repo_fmt);
2819
2819 - repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
2820 + repository_format_configure(repo, &repo_fmt, hash, ref_storage_format);
2821
2822 /*
2823 * Ensure `core.hidedotfiles` is processed. This must happen after we
2824 * have set up the repository format such that we can evaluate
2825 * includeIf conditions correctly in the case of re-initialization.
2826 */
2826 - repo_config(the_repository, git_default_core_config, NULL);
2827 + repo_config(repo, git_default_core_config, NULL);
2828
2828 - safe_create_dir(the_repository, git_dir, 0);
2829 + safe_create_dir(repo, git_dir, 0);
2830
2830 - reinit = create_default_files(the_repository, template_dir, original_git_dir,
2831 + reinit = create_default_files(repo, template_dir, original_git_dir,
2832 &repo_fmt, init_shared_repository);
2833
2834 if (!(flags & INIT_DB_SKIP_REFDB))
2834 - create_reference_database(the_repository, initial_branch, flags & INIT_DB_QUIET);
2835 - create_object_directory(the_repository);
2835 + create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET);
2836 + create_object_directory(repo);
2837
2837 - if (repo_settings_get_shared_repository(the_repository)) {
2838 + if (repo_settings_get_shared_repository(repo)) {
2839 char buf[10];
2840 /* We do not spell "group" and such, so that
2841 * the configuration can be read by older version
@@ -2842,29 +2843,29 @@ int init_db(const char *git_dir, const char *real_git_dir,
2843 * and compatibility values for PERM_GROUP and
2844 * PERM_EVERYBODY.
2845 */
2845 - if (repo_settings_get_shared_repository(the_repository) < 0)
2846 + if (repo_settings_get_shared_repository(repo) < 0)
2847 /* force to the mode value */
2847 - xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(the_repository));
2848 - else if (repo_settings_get_shared_repository(the_repository) == PERM_GROUP)
2848 + xsnprintf(buf, sizeof(buf), "0%o", -repo_settings_get_shared_repository(repo));
2849 + else if (repo_settings_get_shared_repository(repo) == PERM_GROUP)
2850 xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
2850 - else if (repo_settings_get_shared_repository(the_repository) == PERM_EVERYBODY)
2851 + else if (repo_settings_get_shared_repository(repo) == PERM_EVERYBODY)
2852 xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
2853 else
2854 BUG("invalid value for shared_repository");
2854 - repo_config_set(the_repository, "core.sharedrepository", buf);
2855 - repo_config_set(the_repository, "receive.denyNonFastforwards", "true");
2855 + repo_config_set(repo, "core.sharedrepository", buf);
2856 + repo_config_set(repo, "receive.denyNonFastforwards", "true");
2857 }
2858
2859 if (!(flags & INIT_DB_QUIET)) {
2860 int len = strlen(git_dir);
2861
2862 if (reinit)
2862 - printf(repo_settings_get_shared_repository(the_repository)
2863 + printf(repo_settings_get_shared_repository(repo)
2864 ? _("Reinitialized existing shared Git repository in %s%s\n")
2865 : _("Reinitialized existing Git repository in %s%s\n"),
2866 git_dir, len && git_dir[len-1] != '/' ? "/" : "");
2867 else
2867 - printf(repo_settings_get_shared_repository(the_repository)
2868 + printf(repo_settings_get_shared_repository(repo)
2869 ? _("Initialized empty shared Git repository in %s%s\n")
2870 : _("Initialized empty Git repository in %s%s\n"),
2871 git_dir, len && git_dir[len-1] != '/' ? "/" : "");
setup.h
+2 -1
@@ -227,7 +227,8 @@ const char *get_template_dir(const char *option_template);
227 #define INIT_DB_EXIST_OK (1 << 1)
228 #define INIT_DB_SKIP_REFDB (1 << 2)
229
230 -int init_db(const char *git_dir, const char *real_git_dir,
230 +int init_db(struct repository *repo,
231 + const char *git_dir, const char *real_git_dir,
232 const char *template_dir, int hash_algo,
233 enum ref_storage_format ref_storage_format,
234 const char *initial_branch, int init_shared_repository,