]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: stop using `the_repository` in `check_repository_format()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 20 Apr 2026 08:22:45 +0000 (10:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Apr 2026 16:53:58 +0000 (09:53 -0700)
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>
setup.c
setup.h

diff --git a/setup.c b/setup.c
index a4e294b096ed97a9e65e569ee98891395964469c..803d482849807b1fd2464f38a8fb16c6aa210b22 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1749,6 +1749,37 @@ enum discovery_result discover_git_directory_reason(struct strbuf *commondir,
        return result;
 }
 
+/*
+ * Check the repository format version in the path found in repo_get_git_dir(repo),
+ * and die if it is a version we don't understand. Generally one would
+ * set_git_dir() before calling this, and use it only for "are we in a valid
+ * repo?".
+ *
+ * If successful and fmt is not NULL, fill fmt with data.
+ */
+static void check_repository_format(struct repository *repo, struct repository_format *fmt)
+{
+       struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+       if (!fmt)
+               fmt = &repo_fmt;
+       check_repository_format_gently(repo, repo_get_git_dir(repo), fmt, NULL);
+       startup_info->have_repository = 1;
+       repo_set_hash_algo(repo, fmt->hash_algo);
+       repo_set_compat_hash_algo(repo, fmt->compat_hash_algo);
+       repo_set_ref_storage_format(repo,
+                                   fmt->ref_storage_format,
+                                   fmt->ref_storage_payload);
+       repo->repository_format_worktree_config =
+               fmt->worktree_config;
+       repo->repository_format_submodule_path_cfg =
+               fmt->submodule_path_cfg;
+       repo->repository_format_relative_worktrees =
+               fmt->relative_worktrees;
+       repo->repository_format_partial_clone =
+               xstrdup_or_null(fmt->partial_clone);
+       clear_repository_format(&repo_fmt);
+}
+
 const char *enter_repo(struct repository *repo, const char *path, unsigned flags)
 {
        static struct strbuf validated_path = STRBUF_INIT;
@@ -1823,7 +1854,7 @@ const char *enter_repo(struct repository *repo, const char *path, unsigned flags
 
        if (is_git_directory(".")) {
                set_git_dir(repo, ".", 0);
-               check_repository_format(NULL);
+               check_repository_format(repo, NULL);
                return path;
        }
 
@@ -2098,29 +2129,6 @@ int git_config_perm(const char *var, const char *value)
        return -(i & 0666);
 }
 
-void check_repository_format(struct repository_format *fmt)
-{
-       struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
-       if (!fmt)
-               fmt = &repo_fmt;
-       check_repository_format_gently(the_repository, repo_get_git_dir(the_repository), fmt, NULL);
-       startup_info->have_repository = 1;
-       repo_set_hash_algo(the_repository, fmt->hash_algo);
-       repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo);
-       repo_set_ref_storage_format(the_repository,
-                                   fmt->ref_storage_format,
-                                   fmt->ref_storage_payload);
-       the_repository->repository_format_worktree_config =
-               fmt->worktree_config;
-       the_repository->repository_format_submodule_path_cfg =
-               fmt->submodule_path_cfg;
-       the_repository->repository_format_relative_worktrees =
-               fmt->relative_worktrees;
-       the_repository->repository_format_partial_clone =
-               xstrdup_or_null(fmt->partial_clone);
-       clear_repository_format(&repo_fmt);
-}
-
 /*
  * Returns the "prefix", a path to the current working directory
  * relative to the work tree root, or NULL, if the current working
@@ -2795,7 +2803,7 @@ 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(&repo_fmt);
+       check_repository_format(the_repository, &repo_fmt);
 
        repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
 
diff --git a/setup.h b/setup.h
index b779661ce7df479bf77f4a104a597a7c5d52e33b..a820041af05ffbd83d0d640dbc8da104bd78bf2a 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -221,16 +221,6 @@ void clear_repository_format(struct repository_format *format);
 int verify_repository_format(const struct repository_format *format,
                             struct strbuf *err);
 
-/*
- * Check the repository format version in the path found in repo_get_git_dir(the_repository),
- * and die if it is a version we don't understand. Generally one would
- * set_git_dir() before calling this, and use it only for "are we in a valid
- * repo?".
- *
- * If successful and fmt is not NULL, fill fmt with data.
- */
-void check_repository_format(struct repository_format *fmt);
-
 const char *get_template_dir(const char *option_template);
 
 #define INIT_DB_QUIET      (1 << 0)