From 43c31ecc42ff9312beba58b321141f39505b8531 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 16 Dec 2024 17:25:12 +0000 Subject: [PATCH] repo: don't require oid_type to wrap_odb The `wrap_odb` function doesn't need to know the OID types in the object database; the object database already knows the type. --- include/git2/repository.h | 11 ----------- src/libgit2/repository.c | 25 +++---------------------- src/libgit2/repository.h | 5 ----- tests/libgit2/odb/backend/loose.c | 2 +- tests/libgit2/odb/backend/mempack.c | 2 +- tests/libgit2/refs/iterator.c | 2 +- 6 files changed, 6 insertions(+), 41 deletions(-) diff --git a/include/git2/repository.h b/include/git2/repository.h index d354b5efc..b203576af 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -53,15 +53,6 @@ GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path); */ GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_worktree *wt); -#ifdef GIT_EXPERIMENTAL_SHA256 - -GIT_EXTERN(int) git_repository_wrap_odb( - git_repository **out, - git_odb *odb, - const git_odb_options *opts); - -#else - /** * Create a "fake" repository to wrap an object database * @@ -77,8 +68,6 @@ 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. * The lookup start from base_path and walk across parent directories diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 448bf5e2a..94738fd61 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -1221,19 +1221,15 @@ out: return err; } -int git_repository__wrap_odb( - git_repository **out, - git_odb *odb, - git_oid_t oid_type) +int git_repository_wrap_odb(git_repository **out, git_odb *odb) { git_repository *repo; - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); - repo = repository_alloc(); GIT_ERROR_CHECK_ALLOC(repo); - repo->oid_type = oid_type; + GIT_ASSERT(git_oid_type_is_valid(odb->options.oid_type)); + repo->oid_type = odb->options.oid_type; git_repository_set_odb(repo, odb); *out = repo; @@ -1241,21 +1237,6 @@ int git_repository__wrap_odb( return 0; } -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_repository_wrap_odb( - git_repository **out, - git_odb *odb, - const git_odb_options *opts) -{ - return git_repository__wrap_odb(out, odb, opts ? opts->oid_type : GIT_OID_DEFAULT); -} -#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 79e087bfa..fbf143894 100644 --- a/src/libgit2/repository.h +++ b/src/libgit2/repository.h @@ -199,11 +199,6 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo); int git_repository_grafts__weakptr(git_grafts **out, git_repository *repo); int git_repository_shallow_grafts__weakptr(git_grafts **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 02227945d..f5a0b4f5c 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, GIT_OID_SHA1)); + cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); } void test_odb_backend_loose__cleanup(void) diff --git a/tests/libgit2/odb/backend/mempack.c b/tests/libgit2/odb/backend/mempack.c index 84449090a..462a1d333 100644 --- a/tests/libgit2/odb/backend/mempack.c +++ b/tests/libgit2/odb/backend/mempack.c @@ -15,7 +15,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, GIT_OID_SHA1)); + cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); } void test_odb_backend_mempack__cleanup(void) diff --git a/tests/libgit2/refs/iterator.c b/tests/libgit2/refs/iterator.c index 020ee01a4..a46db6290 100644 --- a/tests/libgit2/refs/iterator.c +++ b/tests/libgit2/refs/iterator.c @@ -129,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, GIT_OID_SHA1)); + cl_git_pass(git_repository_wrap_odb(&empty, odb)); cl_git_pass(git_reference_iterator_new(&iter, empty)); cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&ref, iter));