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

[PATCH v2 01/13] setup: rename `check_repository_format_gently()`

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 7, 2026, 07:21 UTC
Message-ID
<20260707-pks-setup-split-discovery-and-setup-v2-1-aab372cd227c@pks.im>
In-Reply-To
<20260707-pks-setup-split-discovery-and-setup-v2-0-aab372cd227c@pks.im>

The function `check_repository_format_gently()` receives a format as input. An unknowing reader may thus suspect that this function actually checks the passed-in format for consistency. While the function indeed checks the repository format, it actually serves two purposes:

  - It reads the repository's format and populates the passed-in format
    with that information.
  - It then indeed checks whether the format is consistent.

Rename the function to `read_and_verify_repository_format()` to clarify its functionality. While at it, reorder the parameters so that the format comes first to better match other functions that pass around the format.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 setup.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/setup.c b/setup.c
index 951ab9eedb..118416e350 100644
--- a/setup.c
+++ b/setup.c
@@ -749,9 +749,9 @@ static int check_repo_format(const char *var, const char *value,
 	return read_worktree_config(var, value, ctx, vdata);
 }
 
-static int check_repository_format_gently(const char *gitdir,
-					  struct repository_format *candidate,
-					  int *nongit_ok)
+static int read_and_verify_repository_format(struct repository_format *format,
+					     const char *gitdir,
+					     int *nongit_ok)
 {
 	struct strbuf sb = STRBUF_INIT;
 	struct strbuf err = STRBUF_INIT;
@@ -759,7 +759,7 @@ static int check_repository_format_gently(const char *gitdir,
 
 	has_common = get_common_dir(&sb, gitdir);
 	strbuf_addstr(&sb, "/config");
-	read_repository_format(candidate, sb.buf);
+	read_repository_format(format, sb.buf);
 	strbuf_release(&sb);
 
 	/*
@@ -767,10 +767,10 @@ static int check_repository_format_gently(const char *gitdir,
 	 * we treat a missing config as a silent "ok", even when nongit_ok
 	 * is unset.
 	 */
-	if (candidate->version < 0)
+	if (format->version < 0)
 		return 0;
 
-	if (verify_repository_format(candidate, &err) < 0) {
+	if (verify_repository_format(format, &err) < 0) {
 		if (nongit_ok) {
 			warning("%s", err.buf);
 			strbuf_release(&err);
@@ -780,37 +780,37 @@ static int check_repository_format_gently(const char *gitdir,
 		die("%s", err.buf);
 	}
 
-	string_list_clear(&candidate->unknown_extensions, 0);
-	string_list_clear(&candidate->v1_only_extensions, 0);
+	string_list_clear(&format->unknown_extensions, 0);
+	string_list_clear(&format->v1_only_extensions, 0);
 
-	if (candidate->worktree_config) {
+	if (format->worktree_config) {
 		/*
 		 * pick up core.bare and core.worktree from per-worktree
 		 * config if present
 		 */
 		strbuf_addf(&sb, "%s/config.worktree", gitdir);
-		git_config_from_file(read_worktree_config, sb.buf, candidate);
+		git_config_from_file(read_worktree_config, sb.buf, format);
 		strbuf_release(&sb);
 		has_common = 0;
 	}
 
 	if (startup_info->force_bare_repository) {
-		candidate->is_bare = 1;
-		FREE_AND_NULL(candidate->work_tree);
+		format->is_bare = 1;
+		FREE_AND_NULL(format->work_tree);
 	} else if (has_common) {
 		/*
 		 * When sharing a common dir with another repository (e.g. a
 		 * linked worktree), do not let this repository's config
 		 * dictate bareness; it is inherited from the main worktree.
 		 */
-		candidate->is_bare = -1;
+		format->is_bare = -1;
 
 		/*
 		 * Furthermore, "core.worktree" is supposed to be ignored when
 		 * we have a commondir configured, unless it comes from the
 		 * per-worktree configuration.
 		 */
-		FREE_AND_NULL(candidate->work_tree);
+		FREE_AND_NULL(format->work_tree);
 	}
 
 	return 0;
@@ -1141,7 +1141,7 @@ static const char *setup_explicit_git_dir(struct repository *repo,
 		die(_("not a git repository: '%s'"), gitdirenv);
 	}
 
-	if (check_repository_format_gently(gitdirenv, repo_fmt, nongit_ok)) {
+	if (read_and_verify_repository_format(repo_fmt, gitdirenv, nongit_ok)) {
 		free(gitfile);
 		return NULL;
 	}
@@ -1218,7 +1218,7 @@ static const char *setup_discovered_git_dir(struct repository *repo,
 					    struct repository_format *repo_fmt,
 					    int *nongit_ok)
 {
-	if (check_repository_format_gently(gitdir, repo_fmt, nongit_ok))
+	if (read_and_verify_repository_format(repo_fmt, gitdir, nongit_ok))
 		return NULL;
 
 	/* --work-tree is set without --git-dir; use discovered one */
@@ -1266,7 +1266,7 @@ static const char *setup_bare_git_dir(struct repository *repo,
 {
 	int root_len;
 
-	if (check_repository_format_gently(".", repo_fmt, nongit_ok))
+	if (read_and_verify_repository_format(repo_fmt, ".", nongit_ok))
 		return NULL;
 
 	setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1);
@@ -1874,7 +1874,7 @@ const char *enter_repo(struct repository *repo, const char *path, unsigned flags
 		struct strbuf err = STRBUF_INIT;
 
 		set_git_dir(repo, ".", 0);
-		check_repository_format_gently(".", &fmt, NULL);
+		read_and_verify_repository_format(&fmt, ".", NULL);
 		if (apply_repository_format(repo, &fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
 			die("%s", err.buf);
 		startup_info->have_repository = 1;
@@ -2836,7 +2836,7 @@ int init_db(struct repository *repo,
 	 * 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_gently(repo_get_git_dir(repo), &repo_fmt, NULL);
+	read_and_verify_repository_format(&repo_fmt, repo_get_git_dir(repo), 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);
-- 
2.55.0.141.g00534a21ce.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 2 of 18 in “setup: split up repository discovery and setup”
  1. 00/13 setup: split up repository discovery and setupPatrick Steinhardt, Jul 7, 2026
  2. 01/13 setup: rename `check_repository_format_gently()`Patrick Steinhardt, Jul 7, 2026
  3. 02/13 setup: mark bogus worktree in `apply_repository_format()`Patrick Steinhardt, Jul 7, 2026
  4. 03/13 setup: unify setup of shallow filePatrick Steinhardt, Jul 7, 2026
  5. 04/13 setup: split up concerns of `setup_git_env_internal()`Patrick Steinhardt, Jul 7, 2026
  6. 05/13 setup: introduce explicit repository discoveryPatrick Steinhardt, Jul 7, 2026
  7. Toon ClaesJul 8, 2026
  8. 06/13 setup: embed repository format in discoveryPatrick Steinhardt, Jul 7, 2026
  9. 08/13 setup: drop static `cwd` variablePatrick Steinhardt, Jul 7, 2026
  10. 07/13 setup: move prefix into repositoryPatrick Steinhardt, Jul 7, 2026
  11. 09/13 setup: propagate prefix via repository discoveryPatrick Steinhardt, Jul 7, 2026
  12. 10/13 setup: make repository discovery self-containedPatrick Steinhardt, Jul 7, 2026
  13. 11/13 setup: drop redundant configuration of `startup_info->have_repository`Patrick Steinhardt, Jul 7, 2026
  14. 12/13 setup: pass worktree to `init_db()`Patrick Steinhardt, Jul 7, 2026
  15. 13/13 setup: mark `set_git_work_tree()` as file-localPatrick Steinhardt, Jul 7, 2026
  16. Justin ToblerJul 7, 2026
  17. Junio C HamanoJul 7, 2026
  18. Toon ClaesJul 8, 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.