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

Stop using `the_repository` in `check_repository_format()` 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. Furthermore, the function is never used outside "setup.c". Drop its declaration in "setup.h" and make it static. Note that this requires us to reorder the function. 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 602254dfb032b47349076132ab07dd3951aa2c3d
2 files changed +33 -35
setup.c
+33 -25
@@ -1758,6 +1758,37 @@ enum discovery_result discover_git_directory_reason(struct strbuf *commondir,
1758 return result;
1759 }
1760
1761 +/*
1762 + * Check the repository format version in the path found in repo_get_git_dir(repo),
1763 + * and die if it is a version we don't understand. Generally one would
1764 + * set_git_dir() before calling this, and use it only for "are we in a valid
1765 + * repo?".
1766 + *
1767 + * If successful and fmt is not NULL, fill fmt with data.
1768 + */
1769 +static void check_repository_format(struct repository *repo, struct repository_format *fmt)
1770 +{
1771 + struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
1772 + if (!fmt)
1773 + fmt = &repo_fmt;
1774 + check_repository_format_gently(repo, repo_get_git_dir(repo), fmt, NULL);
1775 + startup_info->have_repository = 1;
1776 + repo_set_hash_algo(repo, fmt->hash_algo);
1777 + repo_set_compat_hash_algo(repo, fmt->compat_hash_algo);
1778 + repo_set_ref_storage_format(repo,
1779 + fmt->ref_storage_format,
1780 + fmt->ref_storage_payload);
1781 + repo->repository_format_worktree_config =
1782 + fmt->worktree_config;
1783 + repo->repository_format_submodule_path_cfg =
1784 + fmt->submodule_path_cfg;
1785 + repo->repository_format_relative_worktrees =
1786 + fmt->relative_worktrees;
1787 + repo->repository_format_partial_clone =
1788 + xstrdup_or_null(fmt->partial_clone);
1789 + clear_repository_format(&repo_fmt);
1790 +}
1791 +
1792 const char *enter_repo(struct repository *repo, const char *path, unsigned flags)
1793 {
1794 static struct strbuf validated_path = STRBUF_INIT;
@@ -1832,7 +1863,7 @@ const char *enter_repo(struct repository *repo, const char *path, unsigned flags
1863
1864 if (is_git_directory(".")) {
1865 set_git_dir(repo, ".", 0);
1835 - check_repository_format(NULL);
1866 + check_repository_format(repo, NULL);
1867 return path;
1868 }
1869
@@ -2107,29 +2138,6 @@ int git_config_perm(const char *var, const char *value)
2138 return -(i & 0666);
2139 }
2140
2110 -void check_repository_format(struct repository_format *fmt)
2111 -{
2112 - struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
2113 - if (!fmt)
2114 - fmt = &repo_fmt;
2115 - check_repository_format_gently(the_repository, repo_get_git_dir(the_repository), fmt, NULL);
2116 - startup_info->have_repository = 1;
2117 - repo_set_hash_algo(the_repository, fmt->hash_algo);
2118 - repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo);
2119 - repo_set_ref_storage_format(the_repository,
2120 - fmt->ref_storage_format,
2121 - fmt->ref_storage_payload);
2122 - the_repository->repository_format_worktree_config =
2123 - fmt->worktree_config;
2124 - the_repository->repository_format_submodule_path_cfg =
2125 - fmt->submodule_path_cfg;
2126 - the_repository->repository_format_relative_worktrees =
2127 - fmt->relative_worktrees;
2128 - the_repository->repository_format_partial_clone =
2129 - xstrdup_or_null(fmt->partial_clone);
2130 - clear_repository_format(&repo_fmt);
2131 -}
2132 -
2141 /*
2142 * Returns the "prefix", a path to the current working directory
2143 * relative to the work tree root, or NULL, if the current working
@@ -2804,7 +2812,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
2812 * config file, so this will not fail. What we are catching
2813 * is an attempt to reinitialize new repository with an old tool.
2814 */
2807 - check_repository_format(&repo_fmt);
2815 + check_repository_format(the_repository, &repo_fmt);
2816
2817 repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
2818
setup.h
-10
@@ -221,16 +221,6 @@ void clear_repository_format(struct repository_format *format);
221 int verify_repository_format(const struct repository_format *format,
222 struct strbuf *err);
223
224 -/*
225 - * Check the repository format version in the path found in repo_get_git_dir(the_repository),
226 - * and die if it is a version we don't understand. Generally one would
227 - * set_git_dir() before calling this, and use it only for "are we in a valid
228 - * repo?".
229 - *
230 - * If successful and fmt is not NULL, fill fmt with data.
231 - */
232 -void check_repository_format(struct repository_format *fmt);
233 -
224 const char *get_template_dir(const char *option_template);
225
226 #define INIT_DB_QUIET (1 << 0)