git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 18/18] setup: stop using `the_repository` in `init_db()`

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 30, 2026, 13:17 UTC
Message-ID
<20260330-pks-setup-wo-the-repository-v1-18-0d2e822837aa@pks.im>
In-Reply-To
<20260330-pks-setup-wo-the-repository-v1-0-0d2e822837aa@pks.im>

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>
---
 builtin/clone.c   |  2 +-
 builtin/init-db.c |  2 +-
 setup.c           | 43 ++++++++++++++++++++++---------------------
 setup.h           |  3 ++-
 4 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index d864022214..bc35a3c0b1 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -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);
 
diff --git a/builtin/init-db.c b/builtin/init-db.c
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);
 
diff --git a/setup.c b/setup.c
index efac2dd7b5..67bede8b9d 100644
--- a/setup.c
+++ b/setup.c
@@ -2775,7 +2775,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,
@@ -2795,13 +2796,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;
 
@@ -2811,27 +2812,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
@@ -2839,29 +2840,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 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,
-- 
2.53.0.1185.g05d4b7b318.dirty
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 29 of 31 in “setup: drop uses of `the_repository`”
  1. 00/18 setup: drop uses of `the_repository`Patrick Steinhardt, Mar 30, 2026
  2. 01/18 setup: replace use of `the_repository` in static functionsPatrick Steinhardt, Mar 30, 2026
  3. 02/18 setup: stop using `the_repository` in `is_inside_worktree()`Patrick Steinhardt, Mar 30, 2026
  4. Karthik NayakApr 9, 2026
  5. 03/18 setup: stop using `the_repository` in `is_inside_git_dir()`Patrick Steinhardt, Mar 30, 2026
  6. Karthik NayakApr 9, 2026
  7. Patrick SteinhardtApr 13, 2026
  8. Junio C HamanoApr 13, 2026
  9. 04/18 setup: stop using `the_repository` in `prefix_path()`Patrick Steinhardt, Mar 30, 2026
  10. 05/18 setup: stop using `the_repository` in `path_inside_repo()`Patrick Steinhardt, Mar 30, 2026
  11. 06/18 setup: stop using `the_repository` in `verify_filename()`Patrick Steinhardt, Mar 30, 2026
  12. 07/18 setup: stop using `the_repository` in `verify_non_filename()`Patrick Steinhardt, Mar 30, 2026
  13. 08/18 setup: stop using `the_repository` in `enter_repo()`Patrick Steinhardt, Mar 30, 2026
  14. 09/18 setup: stop using `the_repository` in `setup_work_tree()`Patrick Steinhardt, Mar 30, 2026
  15. Elijah NewrenApr 18, 2026
  16. Patrick SteinhardtApr 20, 2026
  17. 10/18 setup: stop using `the_repository` in `set_git_work_tree()`Patrick Steinhardt, Mar 30, 2026
  18. Elijah NewrenApr 18, 2026
  19. Patrick SteinhardtApr 20, 2026
  20. 11/18 setup: stop using `the_repository` in `setup_git_env()`Patrick Steinhardt, Mar 30, 2026
  21. 12/18 setup: stop using `the_repository` in `setup_git_directory_gently()`Patrick Steinhardt, Mar 30, 2026
  22. 13/18 setup: stop using `the_repository` in `setup_git_directory()`Patrick Steinhardt, Mar 30, 2026
  23. 14/18 setup: stop using `the_repository` in `upgrade_repository_format()`Patrick Steinhardt, Mar 30, 2026
  24. 15/18 setup: stop using `the_repository` in `check_repository_format()`Patrick Steinhardt, Mar 30, 2026
  25. Elijah NewrenApr 18, 2026
  26. Patrick SteinhardtApr 20, 2026
  27. 16/18 setup: stop using `the_repository` in `initialize_repository_version()`Patrick Steinhardt, Mar 30, 2026
  28. 17/18 setup: stop using `the_repository` in `create_reference_database()`Patrick Steinhardt, Mar 30, 2026
  29. 18/18 setup: stop using `the_repository` in `init_db()`Patrick Steinhardt, Mar 30, 2026
  30. Karthik NayakApr 9, 2026
  31. Patrick SteinhardtApr 13, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.