diff options
-rw-r--r-- | include/git2/repository.h | 14 | ||||
-rw-r--r-- | src/CMakeLists.txt | 20 | ||||
-rw-r--r-- | src/libgit2/repository.c | 24 | ||||
-rw-r--r-- | src/libgit2/repository.h | 5 | ||||
-rw-r--r-- | src/util/git2_features.h.in | 3 | ||||
-rw-r--r-- | src/util/util.c | 17 | ||||
-rw-r--r-- | tests/libgit2/odb/backend/loose.c | 23 | ||||
-rw-r--r-- | tests/libgit2/odb/backend/mempack.c | 2 | ||||
-rw-r--r-- | tests/libgit2/refs/iterator.c | 3 |
9 files changed, 92 insertions, 19 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/CMakeLists.txt b/src/CMakeLists.txt index cc0a0d4dc..de591e4e4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,15 +58,29 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support") # qsort +# old-style FreeBSD qsort_r() has the 'context' parameter as the first argument +# of the comparison function: check_prototype_definition(qsort_r - "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))" + "void (qsort_r)(void *base, size_t nmemb, size_t size, void *context, int (*compar)(void *, const void *, const void *))" "" "stdlib.h" GIT_QSORT_R_BSD) +# GNU or POSIX qsort_r() has the 'context' parameter as the last argument of the +# comparison function: check_prototype_definition(qsort_r - "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)" + "void (qsort_r)(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *context)" "" "stdlib.h" GIT_QSORT_R_GNU) -check_function_exists(qsort_s GIT_QSORT_S) +# C11 qsort_s() has the 'context' parameter as the last argument of the +# comparison function, and returns an error status: +check_prototype_definition(qsort_s + "errno_t (qsort_s)(void *base, rsize_t nmemb, rsize_t size, int (*compar)(const void *, const void *, void *), void *context)" + "0" "stdlib.h" GIT_QSORT_S_C11) + +# MSC qsort_s() has the 'context' parameter as the first argument of the +# comparison function, and as the last argument of qsort_s(): +check_prototype_definition(qsort_s + "void (qsort_s)(void *base, size_t num, size_t width, int (*compare )(void *, const void *, const void *), void *context)" + "" "stdlib.h" GIT_QSORT_S_MSC) # random / entropy data diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 8fcc4e2ba..d2fe1e6bb 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -1172,19 +1172,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 = 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 8dc20324d..6d2b64c03 100644 --- a/src/libgit2/repository.h +++ b/src/libgit2/repository.h @@ -196,6 +196,11 @@ 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/src/util/git2_features.h.in b/src/util/git2_features.h.in index 1575be641..5f606df84 100644 --- a/src/util/git2_features.h.in +++ b/src/util/git2_features.h.in @@ -26,7 +26,8 @@ #cmakedefine GIT_QSORT_R_BSD #cmakedefine GIT_QSORT_R_GNU -#cmakedefine GIT_QSORT_S +#cmakedefine GIT_QSORT_S_C11 +#cmakedefine GIT_QSORT_S_MSC #cmakedefine GIT_SSH 1 #cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1 diff --git a/src/util/util.c b/src/util/util.c index 9c9f2c040..f4eaf5835 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -18,7 +18,7 @@ # endif # include <windows.h> -# ifdef GIT_QSORT_S +# ifdef GIT_QSORT_S_MSC # include <search.h> # endif #endif @@ -673,7 +673,7 @@ size_t git__unescape(char *str) return (pos - str); } -#if defined(GIT_QSORT_S) || defined(GIT_QSORT_R_BSD) +#if defined(GIT_QSORT_S_MSC) || defined(GIT_QSORT_R_BSD) typedef struct { git__sort_r_cmp cmp; void *payload; @@ -690,7 +690,8 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp( #if !defined(GIT_QSORT_R_BSD) && \ !defined(GIT_QSORT_R_GNU) && \ - !defined(GIT_QSORT_S) + !defined(GIT_QSORT_S_C11) && \ + !defined(GIT_QSORT_S_MSC) static void swap(uint8_t *a, uint8_t *b, size_t elsize) { char tmp[256]; @@ -721,12 +722,14 @@ static void insertsort( void git__qsort_r( void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload) { -#if defined(GIT_QSORT_R_BSD) +#if defined(GIT_QSORT_R_GNU) + qsort_r(els, nel, elsize, cmp, payload); +#elif defined(GIT_QSORT_S_C11) + qsort_s(els, nel, elsize, cmp, payload); +#elif defined(GIT_QSORT_R_BSD) git__qsort_r_glue glue = { cmp, payload }; qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp); -#elif defined(GIT_QSORT_R_GNU) - qsort_r(els, nel, elsize, cmp, payload); -#elif defined(GIT_QSORT_S) +#elif defined(GIT_QSORT_S_MSC) git__qsort_r_glue glue = { cmp, payload }; qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue); #else diff --git a/tests/libgit2/odb/backend/loose.c b/tests/libgit2/odb/backend/loose.c index 781b61d9f..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) @@ -32,7 +32,7 @@ void test_odb_backend_loose__cleanup(void) 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_odb_object *obj; @@ -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_odb_read(&obj, _odb, &oid)); 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); } 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)); |