summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-02-09 17:14:01 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-12 22:02:00 +0000
commit8eadeedee46e8cd4ac2364134b4696b1473d17dc (patch)
treeaaae8940509e446ade6e2fa8c695ecc11248c86d
parentaf20d13b18dbab4de9f244402c255bc85e907ac1 (diff)
downloadlibgit2-8eadeedee46e8cd4ac2364134b4696b1473d17dc.tar.gz
repo: take an oid_type when initializing
-rw-r--r--include/git2/repository.h9
-rw-r--r--src/libgit2/repository.c18
2 files changed, 24 insertions, 3 deletions
diff --git a/include/git2/repository.h b/include/git2/repository.h
index 9b56599d7..04c240d24 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -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
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 928f4635c..489d627a0 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -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;
}