From 161d8a12e70936222a55b5571098299957cdee04 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 5 May 2023 16:29:58 +0100 Subject: sha256: wrap_odb supports SHA256 --- include/git2/repository.h | 14 ++++++++++++-- src/libgit2/repository.c | 24 +++++++++++++++++++++--- src/libgit2/repository.h | 5 +++++ tests/libgit2/odb/backend/loose.c | 2 +- tests/libgit2/odb/backend/mempack.c | 2 +- tests/libgit2/refs/iterator.c | 3 ++- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/include/git2/repository.h b/include/git2/repository.h index 560e70ab6..6ec2ac822 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -56,9 +56,19 @@ GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_work * * @param out pointer to the repo * @param odb the object database to wrap + * @param oid_type the oid type of the object database * @return 0 or an error code */ -GIT_EXTERN(int) git_repository_wrap_odb(git_repository **out, git_odb *odb); +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_repository_wrap_odb( + git_repository **out, + git_odb *odb, + git_oid_t oid_type); +#else +GIT_EXTERN(int) git_repository_wrap_odb( + git_repository **out, + git_odb *odb); +#endif /** * Look for a git repository and copy its path in the given buffer. @@ -536,7 +546,7 @@ GIT_EXTERN(const char *) git_repository_workdir(const git_repository *repo); /** * Get the path of the shared common directory for this repository. - * + * * If the repository is bare, it is the root directory for the repository. * If the repository is a worktree, it is the parent repo's gitdir. * Otherwise, it is the gitdir. diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index c45c58550..473f3b146 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -1145,21 +1145,39 @@ out: return err; } -int git_repository_wrap_odb(git_repository **repo_out, git_odb *odb) +int git_repository__wrap_odb( + git_repository **out, + git_odb *odb, + git_oid_t oid_type) { git_repository *repo; repo = repository_alloc(); GIT_ERROR_CHECK_ALLOC(repo); - repo->oid_type = GIT_OID_DEFAULT; + repo->oid_type = oid_type; git_repository_set_odb(repo, odb); - *repo_out = repo; + *out = repo; return 0; } +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_repository_wrap_odb( + git_repository **out, + git_odb *odb, + git_oid_t oid_type) +{ + return git_repository__wrap_odb(out, odb, oid_type); +} +#else +int git_repository_wrap_odb(git_repository **out, git_odb *odb) +{ + return git_repository__wrap_odb(out, odb, GIT_OID_DEFAULT); +} +#endif + int git_repository_discover( git_buf *out, const char *start_path, diff --git a/src/libgit2/repository.h b/src/libgit2/repository.h index 9a36ef972..b2208b8a6 100644 --- a/src/libgit2/repository.h +++ b/src/libgit2/repository.h @@ -190,6 +190,11 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo); int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo); int git_repository_index__weakptr(git_index **out, git_repository *repo); +int git_repository__wrap_odb( + git_repository **out, + git_odb *odb, + git_oid_t oid_type); + /* * Configuration map cache * diff --git a/tests/libgit2/odb/backend/loose.c b/tests/libgit2/odb/backend/loose.c index f5a0b4f5c..02227945d 100644 --- a/tests/libgit2/odb/backend/loose.c +++ b/tests/libgit2/odb/backend/loose.c @@ -21,7 +21,7 @@ void test_odb_backend_loose__initialize(void) cl_git_pass(git_odb__new(&_odb, NULL)); cl_git_pass(git_odb_add_backend(_odb, backend, 10)); - cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); + cl_git_pass(git_repository__wrap_odb(&_repo, _odb, GIT_OID_SHA1)); } void test_odb_backend_loose__cleanup(void) diff --git a/tests/libgit2/odb/backend/mempack.c b/tests/libgit2/odb/backend/mempack.c index eb8ab3cb0..c8a86a2ae 100644 --- a/tests/libgit2/odb/backend/mempack.c +++ b/tests/libgit2/odb/backend/mempack.c @@ -16,7 +16,7 @@ void test_odb_backend_mempack__initialize(void) cl_git_pass(git_mempack_new(&backend)); cl_git_pass(git_odb__new(&_odb, NULL)); cl_git_pass(git_odb_add_backend(_odb, backend, 10)); - cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); + cl_git_pass(git_repository__wrap_odb(&_repo, _odb, GIT_OID_SHA1)); } void test_odb_backend_mempack__cleanup(void) diff --git a/tests/libgit2/refs/iterator.c b/tests/libgit2/refs/iterator.c index f40d35d11..706fd1ef7 100644 --- a/tests/libgit2/refs/iterator.c +++ b/tests/libgit2/refs/iterator.c @@ -2,6 +2,7 @@ #include "refs.h" #include "vector.h" #include "odb.h" +#include "repository.h" static git_repository *repo; @@ -128,7 +129,7 @@ void test_refs_iterator__empty(void) git_repository *empty; cl_git_pass(git_odb__new(&odb, NULL)); - cl_git_pass(git_repository_wrap_odb(&empty, odb)); + cl_git_pass(git_repository__wrap_odb(&empty, odb, GIT_OID_SHA1)); cl_git_pass(git_reference_iterator_new(&iter, empty)); cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&ref, iter)); -- cgit v1.2.1