Skip to content

Commit 8792ccb

Browse files
pks-tgitster
authored andcommitted
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>
1 parent fe9dc12 commit 8792ccb

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

setup.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,37 @@ enum discovery_result discover_git_directory_reason(struct strbuf *commondir,
17551755
return result;
17561756
}
17571757

1758+
/*
1759+
* Check the repository format version in the path found in repo_get_git_dir(the_repository),
1760+
* and die if it is a version we don't understand. Generally one would
1761+
* set_git_dir() before calling this, and use it only for "are we in a valid
1762+
* repo?".
1763+
*
1764+
* If successful and fmt is not NULL, fill fmt with data.
1765+
*/
1766+
static void check_repository_format(struct repository *repo, struct repository_format *fmt)
1767+
{
1768+
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
1769+
if (!fmt)
1770+
fmt = &repo_fmt;
1771+
check_repository_format_gently(repo, repo_get_git_dir(repo), fmt, NULL);
1772+
startup_info->have_repository = 1;
1773+
repo_set_hash_algo(repo, fmt->hash_algo);
1774+
repo_set_compat_hash_algo(repo, fmt->compat_hash_algo);
1775+
repo_set_ref_storage_format(repo,
1776+
fmt->ref_storage_format,
1777+
fmt->ref_storage_payload);
1778+
repo->repository_format_worktree_config =
1779+
fmt->worktree_config;
1780+
repo->repository_format_submodule_path_cfg =
1781+
fmt->submodule_path_cfg;
1782+
repo->repository_format_relative_worktrees =
1783+
fmt->relative_worktrees;
1784+
repo->repository_format_partial_clone =
1785+
xstrdup_or_null(fmt->partial_clone);
1786+
clear_repository_format(&repo_fmt);
1787+
}
1788+
17581789
const char *enter_repo(struct repository *repo, const char *path, unsigned flags)
17591790
{
17601791
static struct strbuf validated_path = STRBUF_INIT;
@@ -1829,7 +1860,7 @@ const char *enter_repo(struct repository *repo, const char *path, unsigned flags
18291860

18301861
if (is_git_directory(".")) {
18311862
set_git_dir(repo, ".", 0);
1832-
check_repository_format(NULL);
1863+
check_repository_format(repo, NULL);
18331864
return path;
18341865
}
18351866

@@ -2104,29 +2135,6 @@ int git_config_perm(const char *var, const char *value)
21042135
return -(i & 0666);
21052136
}
21062137

2107-
void check_repository_format(struct repository_format *fmt)
2108-
{
2109-
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
2110-
if (!fmt)
2111-
fmt = &repo_fmt;
2112-
check_repository_format_gently(the_repository, repo_get_git_dir(the_repository), fmt, NULL);
2113-
startup_info->have_repository = 1;
2114-
repo_set_hash_algo(the_repository, fmt->hash_algo);
2115-
repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo);
2116-
repo_set_ref_storage_format(the_repository,
2117-
fmt->ref_storage_format,
2118-
fmt->ref_storage_payload);
2119-
the_repository->repository_format_worktree_config =
2120-
fmt->worktree_config;
2121-
the_repository->repository_format_submodule_path_cfg =
2122-
fmt->submodule_path_cfg;
2123-
the_repository->repository_format_relative_worktrees =
2124-
fmt->relative_worktrees;
2125-
the_repository->repository_format_partial_clone =
2126-
xstrdup_or_null(fmt->partial_clone);
2127-
clear_repository_format(&repo_fmt);
2128-
}
2129-
21302138
/*
21312139
* Returns the "prefix", a path to the current working directory
21322140
* relative to the work tree root, or NULL, if the current working
@@ -2801,7 +2809,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
28012809
* config file, so this will not fail. What we are catching
28022810
* is an attempt to reinitialize new repository with an old tool.
28032811
*/
2804-
check_repository_format(&repo_fmt);
2812+
check_repository_format(the_repository, &repo_fmt);
28052813

28062814
repository_format_configure(the_repository, &repo_fmt, hash, ref_storage_format);
28072815

setup.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,6 @@ void clear_repository_format(struct repository_format *format);
221221
int verify_repository_format(const struct repository_format *format,
222222
struct strbuf *err);
223223

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-
234224
const char *get_template_dir(const char *option_template);
235225

236226
#define INIT_DB_QUIET (1 << 0)

0 commit comments

Comments
 (0)