@@ -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+
17581789const 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
0 commit comments