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
index 53a41629e6..d60d1b60bc 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1186,7 +1186,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);
builtin/init-db.c
+1
-1
index e626b0d8b7..c55517ad94 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -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);
setup.c
+22
-21
index 9c49319568..6aee839d8c 100644
--- a/setup.c
+++ b/setup.c
@@ -2778,7 +2778,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,
@@ -2798,13 +2799,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;
@@ -2814,27 +2815,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
@@ -2842,29 +2843,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] != '/' ? "/" : "");
setup.h
+2
-1
index 21737e9bd6..9409326fe4 100644
--- 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,