setup: rename `check_repository_format_gently()`

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 7, 2026 at 09:21 UTC 9ca3ea9881a1c1e238820ce3f6a63f6ad6fce4d5
1 file changed +19 -19
setup.c
+19 -19
@@ -749,9 +749,9 @@ static int check_repo_format(const char *var, const char *value,
749 return read_worktree_config(var, value, ctx, vdata);
750 }
751
752 -static int check_repository_format_gently(const char *gitdir,
753 - struct repository_format *candidate,
754 - int *nongit_ok)
752 +static int read_and_verify_repository_format(struct repository_format *format,
753 + const char *gitdir,
754 + int *nongit_ok)
755 {
756 struct strbuf sb = STRBUF_INIT;
757 struct strbuf err = STRBUF_INIT;
@@ -759,7 +759,7 @@ static int check_repository_format_gently(const char *gitdir,
759
760 has_common = get_common_dir(&sb, gitdir);
761 strbuf_addstr(&sb, "/config");
762 - read_repository_format(candidate, sb.buf);
762 + read_repository_format(format, sb.buf);
763 strbuf_release(&sb);
764
765 /*
@@ -767,10 +767,10 @@ static int check_repository_format_gently(const char *gitdir,
767 * we treat a missing config as a silent "ok", even when nongit_ok
768 * is unset.
769 */
770 - if (candidate->version < 0)
770 + if (format->version < 0)
771 return 0;
772
773 - if (verify_repository_format(candidate, &err) < 0) {
773 + if (verify_repository_format(format, &err) < 0) {
774 if (nongit_ok) {
775 warning("%s", err.buf);
776 strbuf_release(&err);
@@ -780,37 +780,37 @@ static int check_repository_format_gently(const char *gitdir,
780 die("%s", err.buf);
781 }
782
783 - string_list_clear(&candidate->unknown_extensions, 0);
784 - string_list_clear(&candidate->v1_only_extensions, 0);
783 + string_list_clear(&format->unknown_extensions, 0);
784 + string_list_clear(&format->v1_only_extensions, 0);
785
786 - if (candidate->worktree_config) {
786 + if (format->worktree_config) {
787 /*
788 * pick up core.bare and core.worktree from per-worktree
789 * config if present
790 */
791 strbuf_addf(&sb, "%s/config.worktree", gitdir);
792 - git_config_from_file(read_worktree_config, sb.buf, candidate);
792 + git_config_from_file(read_worktree_config, sb.buf, format);
793 strbuf_release(&sb);
794 has_common = 0;
795 }
796
797 if (startup_info->force_bare_repository) {
798 - candidate->is_bare = 1;
799 - FREE_AND_NULL(candidate->work_tree);
798 + format->is_bare = 1;
799 + FREE_AND_NULL(format->work_tree);
800 } else if (has_common) {
801 /*
802 * When sharing a common dir with another repository (e.g. a
803 * linked worktree), do not let this repository's config
804 * dictate bareness; it is inherited from the main worktree.
805 */
806 - candidate->is_bare = -1;
806 + format->is_bare = -1;
807
808 /*
809 * Furthermore, "core.worktree" is supposed to be ignored when
810 * we have a commondir configured, unless it comes from the
811 * per-worktree configuration.
812 */
813 - FREE_AND_NULL(candidate->work_tree);
813 + FREE_AND_NULL(format->work_tree);
814 }
815
816 return 0;
@@ -1141,7 +1141,7 @@ static const char *setup_explicit_git_dir(struct repository *repo,
1141 die(_("not a git repository: '%s'"), gitdirenv);
1142 }
1143
1144 - if (check_repository_format_gently(gitdirenv, repo_fmt, nongit_ok)) {
1144 + if (read_and_verify_repository_format(repo_fmt, gitdirenv, nongit_ok)) {
1145 free(gitfile);
1146 return NULL;
1147 }
@@ -1218,7 +1218,7 @@ static const char *setup_discovered_git_dir(struct repository *repo,
1218 struct repository_format *repo_fmt,
1219 int *nongit_ok)
1220 {
1221 - if (check_repository_format_gently(gitdir, repo_fmt, nongit_ok))
1221 + if (read_and_verify_repository_format(repo_fmt, gitdir, nongit_ok))
1222 return NULL;
1223
1224 /* --work-tree is set without --git-dir; use discovered one */
@@ -1266,7 +1266,7 @@ static const char *setup_bare_git_dir(struct repository *repo,
1266 {
1267 int root_len;
1268
1269 - if (check_repository_format_gently(".", repo_fmt, nongit_ok))
1269 + if (read_and_verify_repository_format(repo_fmt, ".", nongit_ok))
1270 return NULL;
1271
1272 setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1);
@@ -1874,7 +1874,7 @@ const char *enter_repo(struct repository *repo, const char *path, unsigned flags
1874 struct strbuf err = STRBUF_INIT;
1875
1876 set_git_dir(repo, ".", 0);
1877 - check_repository_format_gently(".", &fmt, NULL);
1877 + read_and_verify_repository_format(&fmt, ".", NULL);
1878 if (apply_repository_format(repo, &fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
1879 die("%s", err.buf);
1880 startup_info->have_repository = 1;
@@ -2836,7 +2836,7 @@ int init_db(struct repository *repo,
2836 * config file, so this will not fail. What we are catching
2837 * is an attempt to reinitialize new repository with an old tool.
2838 */
2839 - check_repository_format_gently(repo_get_git_dir(repo), &repo_fmt, NULL);
2839 + read_and_verify_repository_format(&repo_fmt, repo_get_git_dir(repo), NULL);
2840 repository_format_configure(&repo_fmt, hash, ref_storage_format);
2841 if (apply_repository_format(repo, &repo_fmt, APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
2842 die("%s", err.buf);