Commit 8eadeede by Edward Thomson

repo: take an oid_type when initializing

parent af20d13b
...@@ -351,6 +351,15 @@ typedef struct { ...@@ -351,6 +351,15 @@ typedef struct {
* pointing to this URL. * pointing to this URL.
*/ */
const char *origin_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; } git_repository_init_options;
#define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1 #define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1
......
...@@ -1983,7 +1983,8 @@ static int repo_init_config( ...@@ -1983,7 +1983,8 @@ static int repo_init_config(
const char *repo_dir, const char *repo_dir,
const char *work_dir, const char *work_dir,
uint32_t flags, uint32_t flags,
uint32_t mode) uint32_t mode,
git_oid_t oid_type)
{ {
int error = 0; int error = 0;
git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT; git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
...@@ -2040,6 +2041,11 @@ static int repo_init_config( ...@@ -2040,6 +2041,11 @@ static int repo_init_config(
SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true); 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: cleanup:
git_str_dispose(&cfg_path); git_str_dispose(&cfg_path);
git_str_dispose(&worktree_path); git_str_dispose(&worktree_path);
...@@ -2520,6 +2526,7 @@ int git_repository_init_ext( ...@@ -2520,6 +2526,7 @@ int git_repository_init_ext(
common_path = GIT_STR_INIT; common_path = GIT_STR_INIT;
const char *wd; const char *wd;
bool is_valid; bool is_valid;
git_oid_t oid_type = GIT_OID_DEFAULT;
int error; int error;
GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(out);
...@@ -2528,6 +2535,11 @@ int git_repository_init_ext( ...@@ -2528,6 +2535,11 @@ int git_repository_init_ext(
GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options"); 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) if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
goto out; goto out;
...@@ -2546,13 +2558,13 @@ int git_repository_init_ext( ...@@ -2546,13 +2558,13 @@ int git_repository_init_ext(
opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT; 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; goto out;
/* TODO: reinitialize the templates */ /* TODO: reinitialize the templates */
} else { } else {
if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 || 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) (error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0)
goto out; goto out;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment