@@ -1983,7 +1983,8 @@ static int repo_init_config(
19831983 const char * repo_dir ,
19841984 const char * work_dir ,
19851985 uint32_t flags ,
1986- uint32_t mode )
1986+ uint32_t mode ,
1987+ git_oid_t oid_type )
19871988{
19881989 int error = 0 ;
19891990 git_str cfg_path = GIT_STR_INIT , worktree_path = GIT_STR_INIT ;
@@ -2040,6 +2041,11 @@ static int repo_init_config(
20402041 SET_REPO_CONFIG (bool , "receive.denyNonFastforwards" , true);
20412042 }
20422043
2044+ if (oid_type != GIT_OID_SHA1 ) {
2045+ SET_REPO_CONFIG (int32 , "core.repositoryformatversion" , 1 );
2046+ SET_REPO_CONFIG (string , "extensions.objectformat" , git_oid_type_name (oid_type ));
2047+ }
2048+
20432049cleanup :
20442050 git_str_dispose (& cfg_path );
20452051 git_str_dispose (& worktree_path );
@@ -2520,6 +2526,7 @@ int git_repository_init_ext(
25202526 common_path = GIT_STR_INIT ;
25212527 const char * wd ;
25222528 bool is_valid ;
2529+ git_oid_t oid_type = GIT_OID_DEFAULT ;
25232530 int error ;
25242531
25252532 GIT_ASSERT_ARG (out );
@@ -2528,6 +2535,11 @@ int git_repository_init_ext(
25282535
25292536 GIT_ERROR_CHECK_VERSION (opts , GIT_REPOSITORY_INIT_OPTIONS_VERSION , "git_repository_init_options" );
25302537
2538+ #ifdef GIT_EXPERIMENTAL_SHA256
2539+ if (opts -> oid_type )
2540+ oid_type = opts -> oid_type ;
2541+ #endif
2542+
25312543 if ((error = repo_init_directories (& repo_path , & wd_path , given_repo , opts )) < 0 )
25322544 goto out ;
25332545
@@ -2546,13 +2558,13 @@ int git_repository_init_ext(
25462558
25472559 opts -> flags |= GIT_REPOSITORY_INIT__IS_REINIT ;
25482560
2549- if ((error = repo_init_config (repo_path .ptr , wd , opts -> flags , opts -> mode )) < 0 )
2561+ if ((error = repo_init_config (repo_path .ptr , wd , opts -> flags , opts -> mode , oid_type )) < 0 )
25502562 goto out ;
25512563
25522564 /* TODO: reinitialize the templates */
25532565 } else {
25542566 if ((error = repo_init_structure (repo_path .ptr , wd , opts )) < 0 ||
2555- (error = repo_init_config (repo_path .ptr , wd , opts -> flags , opts -> mode )) < 0 ||
2567+ (error = repo_init_config (repo_path .ptr , wd , opts -> flags , opts -> mode , oid_type )) < 0 ||
25562568 (error = repo_init_head (repo_path .ptr , opts -> initial_head )) < 0 )
25572569 goto out ;
25582570 }
0 commit comments