Unverified Commit fc4c00b2 by Edward Thomson Committed by GitHub

Merge pull request #6556 from libgit2/ethomson/wrap_odb

Support SHA256 in git_repository_wrap_odb
parents 30917576 161d8a12
...@@ -56,9 +56,19 @@ GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_work ...@@ -56,9 +56,19 @@ GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_work
* *
* @param out pointer to the repo * @param out pointer to the repo
* @param odb the object database to wrap * @param odb the object database to wrap
* @param oid_type the oid type of the object database
* @return 0 or an error code * @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. * 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); ...@@ -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. * 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 bare, it is the root directory for the repository.
* If the repository is a worktree, it is the parent repo's gitdir. * If the repository is a worktree, it is the parent repo's gitdir.
* Otherwise, it is the gitdir. * Otherwise, it is the gitdir.
......
...@@ -1145,21 +1145,39 @@ out: ...@@ -1145,21 +1145,39 @@ out:
return err; 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; git_repository *repo;
repo = repository_alloc(); repo = repository_alloc();
GIT_ERROR_CHECK_ALLOC(repo); GIT_ERROR_CHECK_ALLOC(repo);
repo->oid_type = GIT_OID_DEFAULT; repo->oid_type = oid_type;
git_repository_set_odb(repo, odb); git_repository_set_odb(repo, odb);
*repo_out = repo; *out = repo;
return 0; 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( int git_repository_discover(
git_buf *out, git_buf *out,
const char *start_path, const char *start_path,
......
...@@ -190,6 +190,11 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo); ...@@ -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_refdb__weakptr(git_refdb **out, git_repository *repo);
int git_repository_index__weakptr(git_index **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 * Configuration map cache
* *
......
...@@ -21,7 +21,7 @@ void test_odb_backend_loose__initialize(void) ...@@ -21,7 +21,7 @@ void test_odb_backend_loose__initialize(void)
cl_git_pass(git_odb__new(&_odb, NULL)); cl_git_pass(git_odb__new(&_odb, NULL));
cl_git_pass(git_odb_add_backend(_odb, backend, 10)); 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) void test_odb_backend_loose__cleanup(void)
...@@ -32,7 +32,7 @@ void test_odb_backend_loose__cleanup(void) ...@@ -32,7 +32,7 @@ void test_odb_backend_loose__cleanup(void)
cl_fixture_cleanup("testrepo.git"); cl_fixture_cleanup("testrepo.git");
} }
void test_odb_backend_loose__read(void) void test_odb_backend_loose__read_from_odb(void)
{ {
git_oid oid; git_oid oid;
git_odb_object *obj; git_odb_object *obj;
...@@ -40,4 +40,23 @@ void test_odb_backend_loose__read(void) ...@@ -40,4 +40,23 @@ void test_odb_backend_loose__read(void)
cl_git_pass(git_oid__fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); cl_git_pass(git_oid__fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1));
cl_git_pass(git_odb_read(&obj, _odb, &oid)); cl_git_pass(git_odb_read(&obj, _odb, &oid));
git_odb_object_free(obj); git_odb_object_free(obj);
cl_git_pass(git_oid__fromstr(&oid, "fd093bff70906175335656e6ce6ae05783708765", GIT_OID_SHA1));
cl_git_pass(git_odb_read(&obj, _odb, &oid));
git_odb_object_free(obj);
}
void test_odb_backend_loose__read_from_repo(void)
{
git_oid oid;
git_blob *blob;
git_tree *tree;
cl_git_pass(git_oid__fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1));
cl_git_pass(git_blob_lookup(&blob, _repo, &oid));
git_blob_free(blob);
cl_git_pass(git_oid__fromstr(&oid, "fd093bff70906175335656e6ce6ae05783708765", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &oid));
git_tree_free(tree);
} }
...@@ -16,7 +16,7 @@ void test_odb_backend_mempack__initialize(void) ...@@ -16,7 +16,7 @@ void test_odb_backend_mempack__initialize(void)
cl_git_pass(git_mempack_new(&backend)); cl_git_pass(git_mempack_new(&backend));
cl_git_pass(git_odb__new(&_odb, NULL)); cl_git_pass(git_odb__new(&_odb, NULL));
cl_git_pass(git_odb_add_backend(_odb, backend, 10)); 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) void test_odb_backend_mempack__cleanup(void)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "refs.h" #include "refs.h"
#include "vector.h" #include "vector.h"
#include "odb.h" #include "odb.h"
#include "repository.h"
static git_repository *repo; static git_repository *repo;
...@@ -128,7 +129,7 @@ void test_refs_iterator__empty(void) ...@@ -128,7 +129,7 @@ void test_refs_iterator__empty(void)
git_repository *empty; git_repository *empty;
cl_git_pass(git_odb__new(&odb, NULL)); 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_git_pass(git_reference_iterator_new(&iter, empty));
cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&ref, iter)); cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&ref, iter));
......
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