@@ -733,6 +733,43 @@ static int find_repo(
733733 return error ;
734734}
735735
736+ static int obtain_config_and_set_oid_type (
737+ git_config * * config_ptr ,
738+ git_repository * repo )
739+ {
740+ int error ;
741+ git_config * config = NULL ;
742+ int version = 0 ;
743+
744+ /*
745+ * We'd like to have the config, but git doesn't particularly
746+ * care if it's not there, so we need to deal with that.
747+ */
748+
749+ error = git_repository_config_snapshot (& config , repo );
750+ if (error < 0 && error != GIT_ENOTFOUND )
751+ goto out ;
752+
753+ if (config &&
754+ (error = check_repositoryformatversion (& version , config )) < 0 )
755+ goto out ;
756+
757+ if ((error = check_extensions (config , version )) < 0 )
758+ goto out ;
759+
760+ if (version > 0 ) {
761+ if ((error = load_objectformat (repo , config )) < 0 )
762+ goto out ;
763+ } else {
764+ repo -> oid_type = GIT_OID_SHA1 ;
765+ }
766+
767+ out :
768+ * config_ptr = config ;
769+
770+ return error ;
771+ }
772+
736773int git_repository_open_bare (
737774 git_repository * * repo_ptr ,
738775 const char * bare_path )
@@ -741,6 +778,7 @@ int git_repository_open_bare(
741778 git_repository * repo = NULL ;
742779 bool is_valid ;
743780 int error ;
781+ git_config * config ;
744782
745783 if ((error = git_fs_path_prettify_dir (& path , bare_path , NULL )) < 0 ||
746784 (error = is_valid_repository_path (& is_valid , & path , & common_path )) < 0 )
@@ -766,8 +804,15 @@ int git_repository_open_bare(
766804 repo -> is_worktree = 0 ;
767805 repo -> workdir = NULL ;
768806
807+ if ((error = obtain_config_and_set_oid_type (& config , repo )) < 0 )
808+ goto cleanup ;
809+
769810 * repo_ptr = repo ;
770- return 0 ;
811+
812+ cleanup :
813+ git_config_free (config );
814+
815+ return error ;
771816}
772817
773818static int _git_repository_open_ext_from_env (
@@ -974,7 +1019,6 @@ int git_repository_open_ext(
9741019 gitlink = GIT_STR_INIT , commondir = GIT_STR_INIT ;
9751020 git_repository * repo = NULL ;
9761021 git_config * config = NULL ;
977- int version = 0 ;
9781022
9791023 if (flags & GIT_REPOSITORY_OPEN_FROM_ENV )
9801024 return _git_repository_open_ext_from_env (repo_ptr , start_path );
@@ -1007,20 +1051,8 @@ int git_repository_open_ext(
10071051 goto cleanup ;
10081052 repo -> is_worktree = is_worktree ;
10091053
1010- /*
1011- * We'd like to have the config, but git doesn't particularly
1012- * care if it's not there, so we need to deal with that.
1013- */
1014-
1015- error = git_repository_config_snapshot (& config , repo );
1016- if (error < 0 && error != GIT_ENOTFOUND )
1017- goto cleanup ;
1018-
1019- if (config &&
1020- (error = check_repositoryformatversion (& version , config )) < 0 )
1021- goto cleanup ;
1022-
1023- if ((error = check_extensions (config , version )) < 0 )
1054+ error = obtain_config_and_set_oid_type (& config , repo );
1055+ if (error < 0 )
10241056 goto cleanup ;
10251057
10261058 if ((flags & GIT_REPOSITORY_OPEN_BARE ) != 0 ) {
@@ -1032,13 +1064,6 @@ int git_repository_open_ext(
10321064 goto cleanup ;
10331065 }
10341066
1035- if (version > 0 ) {
1036- if ((error = load_objectformat (repo , config )) < 0 )
1037- goto cleanup ;
1038- } else {
1039- repo -> oid_type = GIT_OID_SHA1 ;
1040- }
1041-
10421067 /*
10431068 * Ensure that the git directory and worktree are
10441069 * owned by the current user.
0 commit comments