mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 11:06:32 +00:00
repo: take an oid_type when initializing
This commit is contained in:
@@ -351,6 +351,15 @@ typedef struct {
|
||||
* pointing to this URL.
|
||||
*/
|
||||
const char *origin_url;
|
||||
|
||||
#ifdef GIT_EXPERIMENTAL_SHA256
|
||||
/**
|
||||
*
|
||||
* Type of object IDs to use for this repository, or 0 for
|
||||
* default (currently SHA1).
|
||||
*/
|
||||
git_oid_t oid_type;
|
||||
#endif
|
||||
} git_repository_init_options;
|
||||
|
||||
#define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1
|
||||
|
||||
@@ -1983,7 +1983,8 @@ static int repo_init_config(
|
||||
const char *repo_dir,
|
||||
const char *work_dir,
|
||||
uint32_t flags,
|
||||
uint32_t mode)
|
||||
uint32_t mode,
|
||||
git_oid_t oid_type)
|
||||
{
|
||||
int error = 0;
|
||||
git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
|
||||
@@ -2040,6 +2041,11 @@ static int repo_init_config(
|
||||
SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true);
|
||||
}
|
||||
|
||||
if (oid_type != GIT_OID_SHA1) {
|
||||
SET_REPO_CONFIG(int32, "core.repositoryformatversion", 1);
|
||||
SET_REPO_CONFIG(string, "extensions.objectformat", git_oid_type_name(oid_type));
|
||||
}
|
||||
|
||||
cleanup:
|
||||
git_str_dispose(&cfg_path);
|
||||
git_str_dispose(&worktree_path);
|
||||
@@ -2520,6 +2526,7 @@ int git_repository_init_ext(
|
||||
common_path = GIT_STR_INIT;
|
||||
const char *wd;
|
||||
bool is_valid;
|
||||
git_oid_t oid_type = GIT_OID_DEFAULT;
|
||||
int error;
|
||||
|
||||
GIT_ASSERT_ARG(out);
|
||||
@@ -2528,6 +2535,11 @@ int git_repository_init_ext(
|
||||
|
||||
GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options");
|
||||
|
||||
#ifdef GIT_EXPERIMENTAL_SHA256
|
||||
if (opts->oid_type)
|
||||
oid_type = opts->oid_type;
|
||||
#endif
|
||||
|
||||
if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
|
||||
goto out;
|
||||
|
||||
@@ -2546,13 +2558,13 @@ int git_repository_init_ext(
|
||||
|
||||
opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT;
|
||||
|
||||
if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0)
|
||||
if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0)
|
||||
goto out;
|
||||
|
||||
/* TODO: reinitialize the templates */
|
||||
} else {
|
||||
if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 ||
|
||||
(error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0 ||
|
||||
(error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0 ||
|
||||
(error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user