From 56e2a85643fab018c154767e5a1f5fbf794fc774 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 23 Dec 2024 11:53:23 +0000 Subject: [PATCH] sha256: simplify API changes for sha256 support There are several places where users may want to specify the type of object IDs (sha1 or sha256) that should be used, for example, when dealing with repositories, indexes, etc. However, given that sha256 support remains disappointingly uncommon in the wild, we should avoid hard API breaks when possible. Instead, update these APIs to have an "extended" format (eg, `git_odb_open_ext`) that provides an options structure with oid type information. This allows callers who do care about sha256 to use it, and callers who do not to avoid gratuitous API breakage. --- examples/diff.c | 6 --- examples/show-index.c | 4 -- fuzzers/packfile_fuzzer.c | 7 --- include/git2/diff.h | 44 ++++++++++++++--- include/git2/index.h | 68 ++++++++++++++++----------- include/git2/odb.h | 65 ++++++++++++++----------- include/git2/sys/repository.h | 28 ++++++----- src/libgit2/apply.c | 8 ++-- src/libgit2/diff.h | 10 ++++ src/libgit2/diff_parse.c | 19 ++++---- src/libgit2/index.c | 45 ++++++------------ src/libgit2/index.h | 30 +++++++----- src/libgit2/merge.c | 8 +++- src/libgit2/odb.c | 39 +++++---------- src/libgit2/odb.h | 22 +++++---- src/libgit2/repository.c | 34 ++++++++------ src/libgit2/repository.h | 12 ++++- src/libgit2/stash.c | 12 +++-- tests/libgit2/attr/repo.c | 4 -- tests/libgit2/checkout/index.c | 5 +- tests/libgit2/clone/nonetwork.c | 6 ++- tests/libgit2/diff/diff_helpers.c | 10 ---- tests/libgit2/diff/index.c | 5 +- tests/libgit2/index/cache.c | 13 +++-- tests/libgit2/index/inmemory.c | 4 +- tests/libgit2/index/racy.c | 5 +- tests/libgit2/index/read_index.c | 18 ++++--- tests/libgit2/index/tests.c | 33 +++++++------ tests/libgit2/index/tests256.c | 65 ++++++++++++++++++++----- tests/libgit2/network/remote/local.c | 10 +--- tests/libgit2/object/raw/write.c | 2 +- tests/libgit2/object/tree/update.c | 12 ++--- tests/libgit2/odb/backend/loose.c | 2 +- tests/libgit2/odb/backend/mempack.c | 2 +- tests/libgit2/odb/backend/nobackend.c | 10 ++-- tests/libgit2/odb/foreach.c | 5 +- tests/libgit2/odb/loose.c | 25 +++++----- tests/libgit2/odb/mixed.c | 2 +- tests/libgit2/odb/open.c | 8 ++-- tests/libgit2/odb/packed.c | 2 +- tests/libgit2/odb/packed256.c | 2 +- tests/libgit2/odb/packedone.c | 3 +- tests/libgit2/odb/packedone256.c | 2 +- tests/libgit2/odb/sorting.c | 4 +- tests/libgit2/refs/iterator.c | 2 +- tests/libgit2/repo/new.c | 23 ++------- tests/libgit2/repo/setters.c | 7 ++- tests/libgit2/reset/hard.c | 3 +- tests/libgit2/status/worktree_init.c | 4 +- tests/libgit2/submodule/lookup.c | 2 +- 50 files changed, 427 insertions(+), 334 deletions(-) diff --git a/examples/diff.c b/examples/diff.c index 80c5200e9..ed8fbd60d 100644 --- a/examples/diff.c +++ b/examples/diff.c @@ -189,15 +189,9 @@ static void compute_diff_no_index(git_diff **diff, struct diff_options *o) { git_patch_to_buf(&buf, patch), "patch to buf", NULL); -#ifdef GIT_EXPERIMENTAL_SHA256 - check_lg2( - git_diff_from_buffer(diff, buf.ptr, buf.size, NULL), - "diff from patch", NULL); -#else check_lg2( git_diff_from_buffer(diff, buf.ptr, buf.size), "diff from patch", NULL); -#endif git_patch_free(patch); git_buf_dispose(&buf); diff --git a/examples/show-index.c b/examples/show-index.c index ac0040874..fb797e04b 100644 --- a/examples/show-index.c +++ b/examples/show-index.c @@ -30,11 +30,7 @@ int lg2_show_index(git_repository *repo, int argc, char **argv) dirlen = strlen(dir); if (dirlen > 5 && strcmp(dir + dirlen - 5, "index") == 0) { -#ifdef GIT_EXPERIMENTAL_SHA256 - check_lg2(git_index_open(&index, dir, NULL), "could not open index", dir); -#else check_lg2(git_index_open(&index, dir), "could not open index", dir); -#endif } else { check_lg2(git_repository_open_ext(&repo, dir, 0, NULL), "could not open repository", dir); check_lg2(git_repository_index(&index, repo), "could not open repository index", NULL); diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c index bcbdd8bc4..cc4c33ad5 100644 --- a/fuzzers/packfile_fuzzer.c +++ b/fuzzers/packfile_fuzzer.c @@ -37,17 +37,10 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) abort(); } -#ifdef GIT_EXPERIMENTAL_SHA256 - if (git_odb_new(&odb, NULL) < 0) { - fprintf(stderr, "Failed to create the odb\n"); - abort(); - } -#else if (git_odb_new(&odb) < 0) { fprintf(stderr, "Failed to create the odb\n"); abort(); } -#endif if (git_mempack_new(&mempack) < 0) { fprintf(stderr, "Failed to create the mempack\n"); diff --git a/include/git2/diff.h b/include/git2/diff.h index b12e8ab27..856a28f79 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -1321,6 +1321,8 @@ GIT_EXTERN(int) git_diff_buffers( */ typedef struct { unsigned int version; + + /** Object ID type used in the patch file. */ git_oid_t oid_type; } git_diff_parse_options; @@ -1330,8 +1332,36 @@ typedef struct { /** Stack initializer for diff parse options. Alternatively use * `git_diff_parse_options_init` programmatic initialization. */ -#define GIT_DIFF_PARSE_OPTIONS_INIT \ - { GIT_DIFF_PARSE_OPTIONS_VERSION, GIT_OID_DEFAULT } +#define GIT_DIFF_PARSE_OPTIONS_INIT { GIT_DIFF_PARSE_OPTIONS_VERSION } + +/** + * Read the contents of a git patch file into a `git_diff` object. + * + * The diff object produced is similar to the one that would be + * produced if you actually produced it computationally by comparing + * two trees, however there may be subtle differences. For example, + * a patch file likely contains abbreviated object IDs, so the + * object IDs in a `git_diff_delta` produced by this function will + * also be abbreviated. + * + * This function will only read patch files created by a git + * implementation, it will not read unified diffs produced by + * the `diff` program, nor any other types of patch files. + * + * @note This API only supports SHA1 patch files + * @see git_diff_from_buffer_ext + * + * @param out A pointer to a git_diff pointer that will be allocated. + * @param content The contents of a patch file + * @param content_len The length of the patch file contents + * @return 0 or an error code + */ +GIT_EXTERN(int) git_diff_from_buffer( + git_diff **out, + const char *content, + size_t content_len); + +#ifdef GIT_EXPERIMENTAL_SHA256 /** * Read the contents of a git patch file into a `git_diff` object. @@ -1350,16 +1380,16 @@ typedef struct { * @param out A pointer to a git_diff pointer that will be allocated. * @param content The contents of a patch file * @param content_len The length of the patch file contents + * @param opts Options controlling diff parsing * @return 0 or an error code */ -GIT_EXTERN(int) git_diff_from_buffer( +GIT_EXTERN(int) git_diff_from_buffer_ext( git_diff **out, const char *content, - size_t content_len -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_diff_parse_options *opts + size_t content_len, + git_diff_parse_options *opts); + #endif - ); /** * This is an opaque structure which is allocated by `git_diff_get_stats`. diff --git a/include/git2/index.h b/include/git2/index.h index 0adff1abd..6aadbef6b 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -189,8 +189,6 @@ typedef enum { GIT_INDEX_STAGE_THEIRS = 3 } git_index_stage_t; -#ifdef GIT_EXPERIMENTAL_SHA256 - /** * The options for opening or creating an index. * @@ -232,31 +230,6 @@ GIT_EXTERN(int) git_index_options_init( git_index_options *opts, unsigned int version); -/** - * Creates a new bare Git index object, without a repository to back - * it. This index object is capable of storing SHA256 objects. - * - * @param index_out the pointer for the new index - * @param index_path the path to the index file in disk - * @param opts the options for opening the index, or NULL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_open( - git_index **index_out, - const char *index_path, - const git_index_options *opts); - -/** - * Create an in-memory index object. - * - * @param index_out the pointer for the new index - * @param opts the options for opening the index, or NULL - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_new(git_index **index_out, const git_index_options *opts); - -#else - /** * Create a new bare Git index object as a memory representation * of the Git index file in 'index_path', without a repository @@ -271,11 +244,34 @@ GIT_EXTERN(int) git_index_new(git_index **index_out, const git_index_options *op * * The index must be freed once it's no longer in use. * + * @note This API only supports SHA1 indexes + * @see git_index_open_ext + * * @param index_out the pointer for the new index * @param index_path the path to the index file in disk * @return 0 or an error code */ -GIT_EXTERN(int) git_index_open(git_index **index_out, const char *index_path); +GIT_EXTERN(int) git_index_open( + git_index **index_out, + const char *index_path); + +#ifdef GIT_EXPERIMENTAL_SHA256 + +/** + * Creates a new bare Git index object, without a repository to back + * it. This index object is capable of storing SHA256 objects. + * + * @param index_out the pointer for the new index + * @param index_path the path to the index file in disk + * @param opts the options for opening the index, or NULL + * @return 0 or an error code + */ +GIT_EXTERN(int) git_index_open_ext( + git_index **index_out, + const char *index_path, + const git_index_options *opts); + +#endif /** * Create an in-memory index object. @@ -285,11 +281,27 @@ GIT_EXTERN(int) git_index_open(git_index **index_out, const char *index_path); * * The index must be freed once it's no longer in use. * + * @note This API only supports SHA1 indexes + * @see git_index_new_ext + * * @param index_out the pointer for the new index * @return 0 or an error code */ GIT_EXTERN(int) git_index_new(git_index **index_out); +#ifdef GIT_EXPERIMENTAL_SHA256 + +/** + * Create an in-memory index object. + * + * @param index_out the pointer for the new index + * @param opts the options for opening the index, or NULL + * @return 0 or an error code + */ +GIT_EXTERN(int) git_index_new_ext( + git_index **index_out, + const git_index_options *opts); + #endif /** diff --git a/include/git2/odb.h b/include/git2/odb.h index e809c36d7..e81e41c91 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -62,6 +62,20 @@ typedef struct { */ #define GIT_ODB_OPTIONS_INIT { GIT_ODB_OPTIONS_VERSION } +/** + * Create a new object database with no backends. + * + * Before the ODB can be used for read/writing, a custom database + * backend must be manually added using `git_odb_add_backend()` + * + * @note This API only supports SHA1 object databases + * @see git_odb_new_ext + * + * @param[out] odb location to store the database pointer, if opened. + * @return 0 or an error code + */ +GIT_EXTERN(int) git_odb_new(git_odb **odb); + #ifdef GIT_EXPERIMENTAL_SHA256 /** @@ -71,35 +85,11 @@ typedef struct { * @param opts the options for this object database or NULL for defaults * @return 0 or an error code */ -GIT_EXTERN(int) git_odb_new(git_odb **odb, const git_odb_options *opts); - -/** - * Create a new object database and automatically add loose and packed - * backends. - * - * @param[out] odb_out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @param objects_dir path of the backends' "objects" directory. - * @param opts the options for this object database or NULL for defaults - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_open( - git_odb **odb_out, - const char *objects_dir, +GIT_EXTERN(int) git_odb_new_ext( + git_odb **odb, const git_odb_options *opts); -#else - -/** - * Create a new object database with no backends. - * - * Before the ODB can be used for read/writing, a custom database - * backend must be manually added using `git_odb_add_backend()` - * - * @param[out] odb location to store the database pointer, if opened. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_new(git_odb **odb); +#endif /** * Create a new object database and automatically add @@ -112,12 +102,33 @@ GIT_EXTERN(int) git_odb_new(git_odb **odb); * assuming `objects_dir` as the Objects folder which * contains a 'pack/' folder with the corresponding data * + * @note This API only supports SHA1 object databases + * @see git_odb_open_ext + * * @param[out] odb_out location to store the database pointer, if opened. * Set to NULL if the open failed. * @param objects_dir path of the backends' "objects" directory. * @return 0 or an error code */ GIT_EXTERN(int) git_odb_open(git_odb **odb_out, const char *objects_dir); + +#ifdef GIT_EXPERIMENTAL_SHA256 + +/** + * Create a new object database and automatically add loose and packed + * backends. + * + * @param[out] odb_out location to store the database pointer, if opened. + * Set to NULL if the open failed. + * @param objects_dir path of the backends' "objects" directory. + * @param opts the options for this object database or NULL for defaults + * @return 0 or an error code + */ +GIT_EXTERN(int) git_odb_open_ext( + git_odb **odb_out, + const char *objects_dir, + const git_odb_options *opts); + #endif /** diff --git a/include/git2/sys/repository.h b/include/git2/sys/repository.h index 026ac8a1d..cdd1a4bd2 100644 --- a/include/git2/sys/repository.h +++ b/include/git2/sys/repository.h @@ -20,8 +20,6 @@ */ GIT_BEGIN_DECL -#ifdef GIT_EXPERIMENTAL_SHA256 - /** * The options for creating an repository from scratch. * @@ -64,16 +62,6 @@ GIT_EXTERN(int) git_repository_new_options_init( git_repository_new_options *opts, unsigned int version); -/** - * Create a new repository with no backends. - * - * @param[out] out The blank repository - * @param opts the options for repository creation, or NULL for defaults - * @return 0 on success, or an error code - */ -GIT_EXTERN(int) git_repository_new(git_repository **out, git_repository_new_options *opts); -#else - /** * Create a new repository with neither backends nor config object * @@ -84,11 +72,27 @@ GIT_EXTERN(int) git_repository_new(git_repository **out, git_repository_new_opti * can fail to function properly: locations under $GIT_DIR, $GIT_COMMON_DIR, * or $GIT_INFO_DIR are impacted. * + * @note This API only creates SHA1 repositories + * @see git_repository_new_ext + * * @param[out] out The blank repository * @return 0 on success, or an error code */ GIT_EXTERN(int) git_repository_new(git_repository **out); +#ifdef GIT_EXPERIMENTAL_SHA256 + +/** + * Create a new repository with no backends. + * + * @param[out] out The blank repository + * @param opts the options for repository creation, or NULL for defaults + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_repository_new_ext( + git_repository **out, + git_repository_new_options *opts); + #endif /** diff --git a/src/libgit2/apply.c b/src/libgit2/apply.c index 07e502db2..24922cfa5 100644 --- a/src/libgit2/apply.c +++ b/src/libgit2/apply.c @@ -621,6 +621,7 @@ int git_apply_to_tree( { git_index *postimage = NULL; git_reader *pre_reader = NULL, *post_reader = NULL; + git_index_options index_opts = GIT_INDEX_OPTIONS_FOR_REPO(repo); git_apply_options opts = GIT_APPLY_OPTIONS_INIT; const git_diff_delta *delta; size_t i; @@ -643,7 +644,7 @@ int git_apply_to_tree( * put the current tree into the postimage as-is - the diff will * replace any entries contained therein */ - if ((error = git_index__new(&postimage, repo->oid_type)) < 0 || + if ((error = git_index_new_ext(&postimage, &index_opts)) < 0 || (error = git_index_read_tree(postimage, preimage)) < 0 || (error = git_reader_for_index(&post_reader, repo, postimage)) < 0) goto done; @@ -809,6 +810,7 @@ int git_apply( git_index *index = NULL, *preimage = NULL, *postimage = NULL; git_reader *pre_reader = NULL, *post_reader = NULL; git_apply_options opts = GIT_APPLY_OPTIONS_INIT; + git_index_options index_opts = GIT_INDEX_OPTIONS_FOR_REPO(repo); int error = GIT_EINVALID; GIT_ASSERT_ARG(repo); @@ -849,8 +851,8 @@ int git_apply( * having the full repo index, so we will limit our checkout * to only write these files that were affected by the diff. */ - if ((error = git_index__new(&preimage, repo->oid_type)) < 0 || - (error = git_index__new(&postimage, repo->oid_type)) < 0 || + if ((error = git_index_new_ext(&preimage, &index_opts)) < 0 || + (error = git_index_new_ext(&postimage, &index_opts)) < 0 || (error = git_reader_for_index(&post_reader, repo, postimage)) < 0) goto done; diff --git a/src/libgit2/diff.h b/src/libgit2/diff.h index f21b27645..c79a279e3 100644 --- a/src/libgit2/diff.h +++ b/src/libgit2/diff.h @@ -64,4 +64,14 @@ extern int git_diff_delta__casecmp(const void *a, const void *b); extern int git_diff__entry_cmp(const void *a, const void *b); extern int git_diff__entry_icmp(const void *a, const void *b); +#ifndef GIT_EXPERIMENTAL_SHA256 + +int git_diff_from_buffer_ext( + git_diff **out, + const char *content, + size_t content_len, + git_diff_parse_options *opts); + +#endif + #endif diff --git a/src/libgit2/diff_parse.c b/src/libgit2/diff_parse.c index 02eb21ef8..25dcd8e11 100644 --- a/src/libgit2/diff_parse.c +++ b/src/libgit2/diff_parse.c @@ -68,11 +68,16 @@ static git_diff_parsed *diff_parsed_alloc(git_oid_t oid_type) int git_diff_from_buffer( git_diff **out, const char *content, - size_t content_len -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_diff_parse_options *opts -#endif - ) + size_t content_len) +{ + return git_diff_from_buffer_ext(out, content, content_len, NULL); +} + +int git_diff_from_buffer_ext( + git_diff **out, + const char *content, + size_t content_len, + git_diff_parse_options *opts) { git_diff_parsed *diff; git_patch *patch; @@ -83,12 +88,8 @@ int git_diff_from_buffer( *out = NULL; -#ifdef GIT_EXPERIMENTAL_SHA256 oid_type = (opts && opts->oid_type) ? opts->oid_type : GIT_OID_DEFAULT; -#else - oid_type = GIT_OID_DEFAULT; -#endif patch_opts.oid_type = oid_type; diff --git a/src/libgit2/index.c b/src/libgit2/index.c index a3142c8bc..7610781fc 100644 --- a/src/libgit2/index.c +++ b/src/libgit2/index.c @@ -386,21 +386,25 @@ void git_index__set_ignore_case(git_index *index, bool ignore_case) git_vector_sort(&index->reuc); } -int git_index__open( +int git_index_open_ext( git_index **index_out, const char *index_path, - git_oid_t oid_type) + const git_index_options *opts) { git_index *index; int error = -1; GIT_ASSERT_ARG(index_out); + GIT_ERROR_CHECK_VERSION(opts, GIT_INDEX_OPTIONS_VERSION, "git_index_options"); + + if (opts && opts->oid_type) + GIT_ASSERT_ARG(git_oid_type_is_valid(opts->oid_type)); index = git__calloc(1, sizeof(git_index)); GIT_ERROR_CHECK_ALLOC(index); - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); - index->oid_type = oid_type; + index->oid_type = opts && opts->oid_type ? opts->oid_type : + GIT_OID_DEFAULT; if (git_pool_init(&index->tree_pool, 1) < 0) goto fail; @@ -441,39 +445,20 @@ fail: return error; } -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_index_open( - git_index **index_out, - const char *index_path, - const git_index_options *opts) -{ - return git_index__open(index_out, index_path, - opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); -} -#else int git_index_open(git_index **index_out, const char *index_path) { - return git_index__open(index_out, index_path, GIT_OID_SHA1); -} -#endif - -int git_index__new(git_index **out, git_oid_t oid_type) -{ - return git_index__open(out, NULL, oid_type); + return git_index_open_ext(index_out, index_path, NULL); } -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_index_new(git_index **out, const git_index_options *opts) -{ - return git_index__new(out, - opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); -} -#else int git_index_new(git_index **out) { - return git_index__new(out, GIT_OID_SHA1); + return git_index_open_ext(out, NULL, NULL); +} + +int git_index_new_ext(git_index **out, const git_index_options *opts) +{ + return git_index_open_ext(out, NULL, opts); } -#endif static void index_free(git_index *index) { diff --git a/src/libgit2/index.h b/src/libgit2/index.h index 601e98f1c..aa2667de3 100644 --- a/src/libgit2/index.h +++ b/src/libgit2/index.h @@ -20,6 +20,10 @@ #define GIT_INDEX_FILE "index" #define GIT_INDEX_FILE_MODE 0666 +/* Helper to create index options based on repository options */ +#define GIT_INDEX_OPTIONS_FOR_REPO(r) \ + { GIT_INDEX_OPTIONS_VERSION, r ? r->oid_type : 0 } + extern bool git_index__enforce_unsaved_safety; struct git_index { @@ -143,17 +147,6 @@ GIT_INLINE(unsigned char *) git_index__checksum(git_index *index) return index->checksum; } -/* SHA256-aware internal functions */ - -extern int git_index__new( - git_index **index_out, - git_oid_t oid_type); - -extern int git_index__open( - git_index **index_out, - const char *index_path, - git_oid_t oid_type); - /* Copy the current entries vector *and* increment the index refcount. * Call `git_index__release_snapshot` when done. */ @@ -204,4 +197,19 @@ extern int git_indexwriter_commit(git_indexwriter *writer); */ extern void git_indexwriter_cleanup(git_indexwriter *writer); +/* SHA256 support */ + +#ifndef GIT_EXPERIMENTAL_SHA256 + +int git_index_open_ext( + git_index **index_out, + const char *index_path, + const git_index_options *opts); + +GIT_EXTERN(int) git_index_new_ext( + git_index **index_out, + const git_index_options *opts); + +#endif + #endif diff --git a/src/libgit2/merge.c b/src/libgit2/merge.c index 25834c69f..0c5bc0f82 100644 --- a/src/libgit2/merge.c +++ b/src/libgit2/merge.c @@ -2014,11 +2014,14 @@ static int index_from_diff_list( git_index *index; size_t i; git_merge_diff *conflict; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; int error = 0; *out = NULL; - if ((error = git_index__new(&index, oid_type)) < 0) + index_opts.oid_type = oid_type; + + if ((error = git_index_new_ext(&index, &index_opts)) < 0) return error; if ((error = git_index__fill(index, &diff_list->staged)) < 0) @@ -2195,6 +2198,7 @@ int git_merge_trees( { git_iterator *ancestor_iter = NULL, *our_iter = NULL, *their_iter = NULL; git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; + git_index_options index_opts = GIT_INDEX_OPTIONS_FOR_REPO(repo); int error; GIT_ASSERT_ARG(out); @@ -2211,7 +2215,7 @@ int git_merge_trees( result = our_tree; if (result) { - if ((error = git_index__new(out, repo->oid_type)) == 0) + if ((error = git_index_new_ext(out, &index_opts)) == 0) error = git_index_read_tree(*out, result); return error; diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c index 2c308c977..5678524c4 100644 --- a/src/libgit2/odb.c +++ b/src/libgit2/odb.c @@ -536,9 +536,14 @@ static void normalize_options( opts->oid_type = GIT_OID_DEFAULT; } -int git_odb__new(git_odb **out, const git_odb_options *opts) +int git_odb_new_ext(git_odb **out, const git_odb_options *opts) { - git_odb *db = git__calloc(1, sizeof(*db)); + git_odb *db; + + GIT_ASSERT_ARG(out); + GIT_ERROR_CHECK_VERSION(opts, GIT_ODB_OPTIONS_VERSION, "git_odb_options"); + + db = git__calloc(1, sizeof(*db)); GIT_ERROR_CHECK_ALLOC(db); normalize_options(&db->options, opts); @@ -564,17 +569,10 @@ int git_odb__new(git_odb **out, const git_odb_options *opts) return 0; } -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_odb_new(git_odb **out, const git_odb_options *opts) -{ - return git_odb__new(out, opts); -} -#else int git_odb_new(git_odb **out) { - return git_odb__new(out, NULL); + return git_odb_new_ext(out, NULL); } -#endif static int add_backend_internal( git_odb *odb, git_odb_backend *backend, @@ -833,7 +831,7 @@ int git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph) return error; } -int git_odb__open( +int git_odb_open_ext( git_odb **out, const char *objects_dir, const git_odb_options *opts) @@ -842,10 +840,11 @@ int git_odb__open( GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(objects_dir); + GIT_ERROR_CHECK_VERSION(opts, GIT_ODB_OPTIONS_VERSION, "git_odb_options"); *out = NULL; - if (git_odb__new(&db, opts) < 0) + if (git_odb_new_ext(&db, opts) < 0) return -1; if (git_odb__add_default_backends(db, objects_dir, 0, 0) < 0) { @@ -857,25 +856,11 @@ int git_odb__open( return 0; } -#ifdef GIT_EXPERIMENTAL_SHA256 - -int git_odb_open( - git_odb **out, - const char *objects_dir, - const git_odb_options *opts) -{ - return git_odb__open(out, objects_dir, opts); -} - -#else - int git_odb_open(git_odb **out, const char *objects_dir) { - return git_odb__open(out, objects_dir, NULL); + return git_odb_open_ext(out, objects_dir, NULL); } -#endif - int git_odb__set_caps(git_odb *odb, int caps) { if (caps == GIT_ODB_CAP_FROM_OWNER) { diff --git a/src/libgit2/odb.h b/src/libgit2/odb.h index 7a712e202..fa50b9849 100644 --- a/src/libgit2/odb.h +++ b/src/libgit2/odb.h @@ -160,13 +160,6 @@ void git_odb_object__free(void *object); /* SHA256 support */ -int git_odb__new(git_odb **out, const git_odb_options *opts); - -int git_odb__open( - git_odb **out, - const char *objects_dir, - const git_odb_options *opts); - int git_odb__hash( git_oid *out, const void *data, @@ -180,9 +173,22 @@ int git_odb__hashfile( git_object_t object_type, git_oid_t oid_type); -GIT_EXTERN(int) git_odb__backend_loose( +int git_odb__backend_loose( git_odb_backend **out, const char *objects_dir, git_odb_backend_loose_options *opts); +#ifndef GIT_EXPERIMENTAL_SHA256 + +int git_odb_open_ext( + git_odb **odb_out, + const char *objects_dir, + const git_odb_options *opts); + +int git_odb_new_ext( + git_odb **odb, + const git_odb_options *opts); + +#endif + #endif diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index 2c36458b3..3be967c94 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -328,33 +328,35 @@ on_error: return NULL; } -int git_repository__new(git_repository **out, git_oid_t oid_type) +int git_repository_new_ext( + git_repository **out, + git_repository_new_options *opts) { git_repository *repo; + GIT_ASSERT_ARG(out); + GIT_ERROR_CHECK_VERSION(opts, + GIT_REPOSITORY_NEW_OPTIONS_VERSION, + "git_repository_new_options"); + + if (opts && opts->oid_type) + GIT_ASSERT_ARG(git_oid_type_is_valid(opts->oid_type)); + *out = repo = repository_alloc(); GIT_ERROR_CHECK_ALLOC(repo); - GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); - repo->is_bare = 1; repo->is_worktree = 0; - repo->oid_type = oid_type; + repo->oid_type = opts && opts->oid_type ? opts->oid_type : + GIT_OID_DEFAULT; return 0; } -#ifdef GIT_EXPERIMENTAL_SHA256 -int git_repository_new(git_repository **out, git_repository_new_options *opts) +int git_repository_new(git_repository **out) { - return git_repository__new(out, opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); + return git_repository_new_ext(out, NULL); } -#else -int git_repository_new(git_repository** out) -{ - return git_repository__new(out, GIT_OID_SHA1); -} -#endif static int load_config_data(git_repository *repo, const git_config *config) { @@ -1548,7 +1550,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo) odb_opts.oid_type = repo->oid_type; if ((error = repository_odb_path(&odb_path, repo)) < 0 || - (error = git_odb__new(&odb, &odb_opts)) < 0 || + (error = git_odb_new_ext(&odb, &odb_opts)) < 0 || (error = repository_odb_alternates(odb, repo)) < 0) return error; @@ -1657,11 +1659,13 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo) if (repo->_index == NULL) { git_str index_path = GIT_STR_INIT; git_index *index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; if ((error = repository_index_path(&index_path, repo)) < 0) return error; - error = git_index__open(&index, index_path.ptr, repo->oid_type); + index_opts.oid_type = repo->oid_type; + error = git_index_open_ext(&index, index_path.ptr, &index_opts); if (!error) { GIT_REFCOUNT_OWN(index, repo); diff --git a/src/libgit2/repository.h b/src/libgit2/repository.h index fbf143894..7da2d1655 100644 --- a/src/libgit2/repository.h +++ b/src/libgit2/repository.h @@ -15,6 +15,7 @@ #include "git2/repository.h" #include "git2/object.h" #include "git2/config.h" +#include "git2/sys/repository.h" #include "array.h" #include "cache.h" @@ -281,7 +282,14 @@ int git_repository__set_objectformat( git_repository *repo, git_oid_t oid_type); -/* SHA256-aware internal functions */ -int git_repository__new(git_repository **out, git_oid_t oid_type); +/* SHA256 support */ + +#ifndef GIT_EXPERIMENTAL_SHA256 + +GIT_EXTERN(int) git_repository_new_ext( + git_repository **out, + git_repository_new_options *opts); + +#endif #endif diff --git a/src/libgit2/stash.c b/src/libgit2/stash.c index b49e95cdb..23c82b408 100644 --- a/src/libgit2/stash.c +++ b/src/libgit2/stash.c @@ -281,10 +281,11 @@ static int build_untracked_tree( git_tree *i_tree = NULL; git_diff *diff = NULL; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_index_options index_opts = GIT_INDEX_OPTIONS_FOR_REPO(repo); struct stash_update_rules data = {0}; int error; - if ((error = git_index__new(&i_index, repo->oid_type)) < 0) + if ((error = git_index_new_ext(&i_index, &index_opts)) < 0) goto cleanup; if (flags & GIT_STASH_INCLUDE_UNTRACKED) { @@ -484,10 +485,11 @@ static int commit_worktree( { git_index *i_index = NULL, *r_index = NULL; git_tree *w_tree = NULL; + git_index_options index_opts = GIT_INDEX_OPTIONS_FOR_REPO(repo); int error = 0, ignorecase; if ((error = git_repository_index(&r_index, repo) < 0) || - (error = git_index__new(&i_index, repo->oid_type)) < 0 || + (error = git_index_new_ext(&i_index, &index_opts)) < 0 || (error = git_index__fill(i_index, &r_index->entries) < 0) || (error = git_repository__configmap_lookup(&ignorecase, repo, GIT_CONFIGMAP_IGNORECASE)) < 0) goto cleanup; @@ -688,6 +690,7 @@ int git_stash_save_with_opts( git_str msg = GIT_STR_INIT; git_tree *tree = NULL; git_reference *head = NULL; + git_index_options index_opts = GIT_INDEX_OPTIONS_FOR_REPO(repo); bool has_paths = false; int error; @@ -732,7 +735,7 @@ int git_stash_save_with_opts( i_commit, b_commit, u_commit)) < 0) goto cleanup; } else { - if ((error = git_index__new(&paths_index, repo->oid_type)) < 0 || + if ((error = git_index_new_ext(&paths_index, &index_opts)) < 0 || (error = retrieve_head(&head, repo)) < 0 || (error = git_reference_peel((git_object**)&tree, head, GIT_OBJECT_TREE)) < 0 || (error = git_index_read_tree(paths_index, tree)) < 0 || @@ -1010,9 +1013,10 @@ static int stage_new_files( git_iterator *iterators[2] = { NULL, NULL }; git_iterator_options iterator_options = GIT_ITERATOR_OPTIONS_INIT; git_index *index = NULL; + git_index_options index_opts = GIT_INDEX_OPTIONS_FOR_REPO(repo); int error; - if ((error = git_index__new(&index, repo->oid_type)) < 0 || + if ((error = git_index_new_ext(&index, &index_opts)) < 0 || (error = git_iterator_for_tree( &iterators[0], parent_tree, &iterator_options)) < 0 || (error = git_iterator_for_tree( diff --git a/tests/libgit2/attr/repo.c b/tests/libgit2/attr/repo.c index 793c1a7d0..4c71bddb7 100644 --- a/tests/libgit2/attr/repo.c +++ b/tests/libgit2/attr/repo.c @@ -317,11 +317,7 @@ void test_attr_repo__inmemory_repo_without_index(void) git_index *index = NULL; /* setup bare in-memory repo without index */ -#ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_repository_new(&inmemory, NULL)); -#else cl_git_pass(git_repository_new(&inmemory)); -#endif cl_assert(git_repository_is_bare(inmemory)); /* verify repo isn't given an index upfront in future */ diff --git a/tests/libgit2/checkout/index.c b/tests/libgit2/checkout/index.c index 03d5d392b..aa85e24a6 100644 --- a/tests/libgit2/checkout/index.c +++ b/tests/libgit2/checkout/index.c @@ -830,8 +830,11 @@ void test_checkout_index__adding_conflict_removes_stage_0(void) { git_index *new_index, *index; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1)); + index_opts.oid_type = GIT_OID_SHA1; + + cl_git_pass(git_index_new_ext(&new_index, &index_opts)); add_conflict(new_index, "new.txt"); cl_git_pass(git_checkout_index(g_repo, new_index, &opts)); diff --git a/tests/libgit2/clone/nonetwork.c b/tests/libgit2/clone/nonetwork.c index e784ec20f..dfde7f291 100644 --- a/tests/libgit2/clone/nonetwork.c +++ b/tests/libgit2/clone/nonetwork.c @@ -265,13 +265,17 @@ void test_clone_nonetwork__clone_tag_to_tree(void) git_tree *tree; git_reference *tag; git_tree_entry *tentry; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; + const char *file_path = "some/deep/path.txt"; const char *file_content = "some content\n"; const char *tag_name = "refs/tags/tree-tag"; + index_opts.oid_type = GIT_OID_SHA1; + stage = cl_git_sandbox_init("testrepo.git"); cl_git_pass(git_repository_odb(&odb, stage)); - cl_git_pass(git_index__new(&index, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&index, &index_opts)); memset(&entry, 0, sizeof(git_index_entry)); entry.path = file_path; diff --git a/tests/libgit2/diff/diff_helpers.c b/tests/libgit2/diff/diff_helpers.c index 5daebffeb..6a76a92e7 100644 --- a/tests/libgit2/diff/diff_helpers.c +++ b/tests/libgit2/diff/diff_helpers.c @@ -314,15 +314,6 @@ void diff_assert_equal(git_diff *a, git_diff *b) } } -#ifdef GIT_EXPERIMENTAL_SHA256 -int diff_from_buffer( - git_diff **out, - const char *content, - size_t content_len) -{ - return git_diff_from_buffer(out, content, content_len, NULL); -} -#else int diff_from_buffer( git_diff **out, const char *content, @@ -330,4 +321,3 @@ int diff_from_buffer( { return git_diff_from_buffer(out, content, content_len); } -#endif diff --git a/tests/libgit2/diff/index.c b/tests/libgit2/diff/index.c index b7866750b..c6b7037e4 100644 --- a/tests/libgit2/diff/index.c +++ b/tests/libgit2/diff/index.c @@ -276,10 +276,13 @@ void test_diff_index__to_index(void) git_tree *old_tree; git_index *old_index; git_index *new_index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; git_diff *diff; diff_expects exp; - cl_git_pass(git_index__new(&old_index, GIT_OID_SHA1)); + index_opts.oid_type = GIT_OID_SHA1; + + cl_git_pass(git_index_new_ext(&old_index, &index_opts)); old_tree = resolve_commit_oid_to_tree(g_repo, a_commit); cl_git_pass(git_index_read_tree(old_index, old_tree)); diff --git a/tests/libgit2/index/cache.c b/tests/libgit2/index/cache.c index 77f19a50b..1d0f8a3eb 100644 --- a/tests/libgit2/index/cache.c +++ b/tests/libgit2/index/cache.c @@ -24,7 +24,7 @@ void test_index_cache__write_extension_at_root(void) const char *tree_id_str = "45dd856fdd4d89b884c340ba0e047752d9b085d6"; const char *index_file = "index-tree"; - cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1)); + cl_git_pass(git_index_open_ext(&index, index_file, NULL)); cl_assert(index->tree == NULL); cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); @@ -35,7 +35,7 @@ void test_index_cache__write_extension_at_root(void) cl_git_pass(git_index_write(index)); git_index_free(index); - cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1)); + cl_git_pass(git_index_open_ext(&index, index_file, NULL)); cl_assert(index->tree); cl_assert_equal_i(git_index_entrycount(index), index->tree->entry_count); @@ -52,11 +52,12 @@ void test_index_cache__write_extension_invalidated_root(void) git_index *index; git_tree *tree; git_oid id; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; const char *tree_id_str = "45dd856fdd4d89b884c340ba0e047752d9b085d6"; const char *index_file = "index-tree-invalidated"; git_index_entry entry; - cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1)); + cl_git_pass(git_index_open_ext(&index, index_file, &index_opts)); cl_assert(index->tree == NULL); cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); @@ -77,7 +78,9 @@ void test_index_cache__write_extension_invalidated_root(void) cl_git_pass(git_index_write(index)); git_index_free(index); - cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1)); + index_opts.oid_type = GIT_OID_SHA1; + + cl_git_pass(git_index_open_ext(&index, index_file, &index_opts)); cl_assert(index->tree); cl_assert_equal_i(-1, index->tree->entry_count); @@ -96,7 +99,7 @@ void test_index_cache__read_tree_no_children(void) git_tree *tree; git_oid id; - cl_git_pass(git_index__new(&index, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&index)); cl_assert(index->tree == NULL); cl_git_pass(git_oid__fromstr(&id, "45dd856fdd4d89b884c340ba0e047752d9b085d6", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); diff --git a/tests/libgit2/index/inmemory.c b/tests/libgit2/index/inmemory.c index 39374af67..2b4ea9948 100644 --- a/tests/libgit2/index/inmemory.c +++ b/tests/libgit2/index/inmemory.c @@ -5,7 +5,7 @@ void test_index_inmemory__can_create_an_inmemory_index(void) { git_index *index; - cl_git_pass(git_index__new(&index, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&index)); cl_assert_equal_i(0, (int)git_index_entrycount(index)); git_index_free(index); @@ -15,7 +15,7 @@ void test_index_inmemory__cannot_add_bypath_to_an_inmemory_index(void) { git_index *index; - cl_git_pass(git_index__new(&index, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&index, NULL)); cl_assert_equal_i(GIT_ERROR, git_index_add_bypath(index, "test.txt")); diff --git a/tests/libgit2/index/racy.c b/tests/libgit2/index/racy.c index a1d6f9c6e..bbac7a6df 100644 --- a/tests/libgit2/index/racy.c +++ b/tests/libgit2/index/racy.c @@ -279,6 +279,7 @@ void test_index_racy__read_index_smudges(void) { git_index *index, *newindex; const git_index_entry *entry; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; /* if we are reading an index into our new index, ensure that any * racy entries in the index that we're reading are smudged so that @@ -287,7 +288,7 @@ void test_index_racy__read_index_smudges(void) setup_race(); cl_git_pass(git_repository_index(&index, g_repo)); - cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&newindex, &index_opts)); cl_git_pass(git_index_read_index(newindex, index)); cl_assert(entry = git_index_get_bypath(newindex, "A", 0)); @@ -305,7 +306,7 @@ void test_index_racy__read_index_clears_uptodate_bit(void) setup_uptodate_files(); cl_git_pass(git_repository_index(&index, g_repo)); - cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&newindex)); cl_git_pass(git_index_read_index(newindex, index)); /* ensure that files brought in from the other index are not uptodate */ diff --git a/tests/libgit2/index/read_index.c b/tests/libgit2/index/read_index.c index 9c80be299..caaf40f79 100644 --- a/tests/libgit2/index/read_index.c +++ b/tests/libgit2/index/read_index.c @@ -33,8 +33,11 @@ void test_index_read_index__maintains_stat_cache(void) git_index_entry new_entry; const git_index_entry *e; git_tree *tree; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; size_t i; + index_opts.oid_type = GIT_OID_SHA1; + cl_assert_equal_i(4, git_index_entrycount(_index)); /* write-tree */ @@ -42,7 +45,7 @@ void test_index_read_index__maintains_stat_cache(void) /* read-tree, then read index */ git_tree_lookup(&tree, _repo, &index_id); - cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&new_index, &index_opts)); cl_git_pass(git_index_read_tree(new_index, tree)); git_tree_free(tree); @@ -81,7 +84,7 @@ static bool roundtrip_with_read_index(const char *tree_idstr) cl_git_pass(git_oid__fromstr(&tree_id, tree_idstr, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id)); - cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&tree_index)); cl_git_pass(git_index_read_tree(tree_index, tree)); cl_git_pass(git_index_read_index(_index, tree_index)); cl_git_pass(git_index_write_tree(&new_tree_id, _index)); @@ -110,15 +113,18 @@ void test_index_read_index__read_and_writes(void) git_oid tree_id, new_tree_id; git_tree *tree; git_index *tree_index, *new_index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; + + index_opts.oid_type = GIT_OID_SHA1; cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id)); - cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&tree_index, &index_opts)); cl_git_pass(git_index_read_tree(tree_index, tree)); cl_git_pass(git_index_read_index(_index, tree_index)); cl_git_pass(git_index_write(_index)); - cl_git_pass(git_index__open(&new_index, git_index_path(_index), GIT_OID_SHA1)); + cl_git_pass(git_index_open_ext(&new_index, git_index_path(_index), &index_opts)); cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo)); cl_assert_equal_oid(&tree_id, &new_tree_id); @@ -174,8 +180,8 @@ void test_index_read_index__handles_conflicts(void) cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id)); - cl_git_pass(git_index__new(&index, GIT_OID_SHA1)); - cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&index, NULL)); + cl_git_pass(git_index_new_ext(&new_index, NULL)); cl_git_pass(git_index_read_tree(index, tree)); cl_git_pass(git_index_read_tree(new_index, tree)); diff --git a/tests/libgit2/index/tests.c b/tests/libgit2/index/tests.c index b48eb0fc1..fb064ea21 100644 --- a/tests/libgit2/index/tests.c +++ b/tests/libgit2/index/tests.c @@ -81,7 +81,7 @@ void test_index_tests__empty_index(void) { git_index *index; - cl_git_pass(git_index__open(&index, "in-memory-index", GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, "in-memory-index")); cl_assert(index->on_disk == 0); cl_assert(git_index_entrycount(index) == 0); @@ -96,7 +96,7 @@ void test_index_tests__default_test_index(void) unsigned int i; git_index_entry **entries; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); cl_assert(index->on_disk); cl_assert(git_index_entrycount(index) == index_entry_count); @@ -119,7 +119,7 @@ void test_index_tests__gitgit_index(void) { git_index *index; - cl_git_pass(git_index__open(&index, TEST_INDEX2_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX2_PATH)); cl_assert(index->on_disk); cl_assert(git_index_entrycount(index) == index_entry_count_2); @@ -134,7 +134,7 @@ void test_index_tests__find_in_existing(void) git_index *index; unsigned int i; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); for (i = 0; i < ARRAY_SIZE(test_entries); ++i) { size_t idx; @@ -151,7 +151,7 @@ void test_index_tests__find_in_empty(void) git_index *index; unsigned int i; - cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, "fake-index")); for (i = 0; i < ARRAY_SIZE(test_entries); ++i) { cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path)); @@ -166,7 +166,7 @@ void test_index_tests__find_prefix(void) const git_index_entry *entry; size_t pos; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); cl_git_pass(git_index_find_prefix(&pos, index, "src")); entry = git_index_get_byindex(index, pos); @@ -187,7 +187,7 @@ void test_index_tests__write(void) copy_file(TEST_INDEXBIG_PATH, "index_rewrite"); - cl_git_pass(git_index__open(&index, "index_rewrite", GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, "index_rewrite")); cl_assert(index->on_disk); cl_git_pass(git_index_write(index)); @@ -218,7 +218,7 @@ void test_index_tests__sort1(void) /* sort the entries in an empty index */ git_index *index; - cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, "fake-index")); /* FIXME: this test is slightly dumb */ cl_assert(git_vector_is_sorted(&index->entries)); @@ -702,8 +702,11 @@ void test_index_tests__write_tree_invalid_unowned_index(void) git_repository *repo; git_index_entry entry = {{0}}; git_oid tree_id; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + index_opts.oid_type = GIT_OID_SHA1; + + cl_git_pass(git_index_new_ext(&idx, &index_opts)); cl_git_pass(git_oid__fromstr(&entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318", GIT_OID_SHA1)); entry.path = "foo"; @@ -966,7 +969,7 @@ void test_index_tests__reload_from_disk(void) cl_git_pass(git_repository_index(&write_index, repo)); cl_assert_equal_i(false, write_index->on_disk); - cl_git_pass(git_index__open(&read_index, write_index->index_file_path, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&read_index, write_index->index_file_path)); cl_assert_equal_i(false, read_index->on_disk); /* Stage two new files against the write_index */ @@ -1004,7 +1007,7 @@ void test_index_tests__corrupted_extension(void) { git_index *index; - cl_git_fail_with(git_index__open(&index, TEST_INDEXBAD_PATH, GIT_OID_SHA1), GIT_ERROR); + cl_git_fail_with(git_index_open(&index, TEST_INDEXBAD_PATH), GIT_ERROR); } void test_index_tests__reload_while_ignoring_case(void) @@ -1012,7 +1015,7 @@ void test_index_tests__reload_while_ignoring_case(void) git_index *index; unsigned int caps; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); cl_git_pass(git_vector_verify_sorted(&index->entries)); caps = git_index_caps(index); @@ -1037,7 +1040,7 @@ void test_index_tests__change_icase_on_instance(void) unsigned int caps; const git_index_entry *e; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); cl_git_pass(git_vector_verify_sorted(&index->entries)); caps = git_index_caps(index); @@ -1093,7 +1096,7 @@ void test_index_tests__can_iterate(void) size_t i, iterator_idx = 0, found = 0; int ret; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); cl_git_pass(git_index_iterator_new(&iterator, index)); cl_assert(git_vector_is_sorted(&iterator->snap)); @@ -1136,7 +1139,7 @@ void test_index_tests__can_modify_while_iterating(void) size_t expected = 0, seen = 0; int ret; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); cl_git_pass(git_index_iterator_new(&iterator, index)); expected = git_index_entrycount(index); diff --git a/tests/libgit2/index/tests256.c b/tests/libgit2/index/tests256.c index 97246ce4d..c720796d8 100644 --- a/tests/libgit2/index/tests256.c +++ b/tests/libgit2/index/tests256.c @@ -86,8 +86,11 @@ void test_index_tests256__empty_index(void) { #ifdef GIT_EXPERIMENTAL_SHA256 git_index *index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, "in-memory-index", GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, "in-memory-index", &index_opts)); cl_assert(index->on_disk == 0); cl_assert(git_index_entrycount(index) == 0); @@ -103,8 +106,11 @@ void test_index_tests256__default_test_index(void) git_index *index; unsigned int i; git_index_entry **entries; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, TEST_INDEX_PATH, &index_opts)); cl_assert(index->on_disk); cl_assert_equal_sz(git_index_entrycount(index), index_entry_count); @@ -129,8 +135,11 @@ void test_index_tests256__find_in_existing(void) #ifdef GIT_EXPERIMENTAL_SHA256 git_index *index; unsigned int i; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, TEST_INDEX_PATH, &index_opts)); for (i = 0; i < ARRAY_SIZE(test_entries); ++i) { size_t idx; @@ -148,8 +157,11 @@ void test_index_tests256__find_in_empty(void) #ifdef GIT_EXPERIMENTAL_SHA256 git_index *index; unsigned int i; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, "fake-index", &index_opts)); for (i = 0; i < ARRAY_SIZE(test_entries); ++i) { cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path)); @@ -165,8 +177,11 @@ void test_index_tests256__find_prefix(void) git_index *index; const git_index_entry *entry; size_t pos; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, TEST_INDEX_PATH, &index_opts)); cl_git_pass(git_index_find_prefix(&pos, index, "Documentation")); entry = git_index_get_byindex(index, pos); @@ -186,10 +201,13 @@ void test_index_tests256__write(void) { #ifdef GIT_EXPERIMENTAL_SHA256 git_index *index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; + + index_opts.oid_type = GIT_OID_SHA256; copy_file(TEST_INDEX_PATH, "index_rewrite"); - cl_git_pass(git_index__open(&index, "index_rewrite", GIT_OID_SHA256)); + cl_git_pass(git_index_open_ext(&index, "index_rewrite", &index_opts)); cl_assert(index->on_disk); cl_git_pass(git_index_write(index)); @@ -206,8 +224,11 @@ void test_index_tests256__sort1(void) #ifdef GIT_EXPERIMENTAL_SHA256 /* sort the entries in an empty index */ git_index *index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, "fake-index", &index_opts)); /* FIXME: this test is slightly dumb */ cl_assert(git_vector_is_sorted(&index->entries)); @@ -675,8 +696,11 @@ void test_index_tests256__write_tree_invalid_unowned_index(void) git_repository *repo; git_index_entry entry = {{0}}; git_oid tree_id; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__new(&idx, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_new_ext(&idx, &index_opts)); /* TODO: this one is failing */ cl_git_pass(git_oid__fromstr(&entry.id, "a8c2e0a89a9cbab77c732b6bc39b51a783e3a318a847f46cba7614cac9814291", GIT_OID_SHA256)); @@ -947,6 +971,9 @@ void test_index_tests256__reload_from_disk(void) git_repository *repo; git_index *read_index; git_index *write_index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; + + index_opts.oid_type = GIT_OID_SHA256; cl_set_cleanup(&cleanup_myrepo, NULL); @@ -958,7 +985,7 @@ void test_index_tests256__reload_from_disk(void) cl_git_pass(git_repository_index(&write_index, repo)); cl_assert_equal_i(false, write_index->on_disk); - cl_git_pass(git_index__open(&read_index, write_index->index_file_path, GIT_OID_SHA256)); + cl_git_pass(git_index_open_ext(&read_index, write_index->index_file_path, &index_opts)); cl_assert_equal_i(false, read_index->on_disk); /* Stage two new files against the write_index */ @@ -998,8 +1025,11 @@ void test_index_tests256__reload_while_ignoring_case(void) #ifdef GIT_EXPERIMENTAL_SHA256 git_index *index; unsigned int caps; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, TEST_INDEX_PATH, &index_opts)); cl_git_pass(git_vector_verify_sorted(&index->entries)); caps = git_index_caps(index); @@ -1025,8 +1055,11 @@ void test_index_tests256__change_icase_on_instance(void) git_index *index; unsigned int caps; const git_index_entry *e; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, TEST_INDEX_PATH, &index_opts)); cl_git_pass(git_vector_verify_sorted(&index->entries)); caps = git_index_caps(index); @@ -1085,8 +1118,11 @@ void test_index_tests256__can_iterate(void) const git_index_entry *entry; size_t i, iterator_idx = 0, found = 0; int ret; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, TEST_INDEX_PATH, &index_opts)); cl_git_pass(git_index_iterator_new(&iterator, index)); cl_assert(git_vector_is_sorted(&iterator->snap)); @@ -1130,8 +1166,11 @@ void test_index_tests256__can_modify_while_iterating(void) git_index_entry new_entry = {{0}}; size_t expected = 0, seen = 0; int ret; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256)); + index_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_index_open_ext(&index, TEST_INDEX_PATH, &index_opts)); cl_git_pass(git_index_iterator_new(&iterator, index)); expected = git_index_entrycount(index); diff --git a/tests/libgit2/network/remote/local.c b/tests/libgit2/network/remote/local.c index 9f3c8b611..88bf2da78 100644 --- a/tests/libgit2/network/remote/local.c +++ b/tests/libgit2/network/remote/local.c @@ -2,6 +2,7 @@ #include "path.h" #include "posix.h" #include "git2/sys/repository.h" +#include "repository.h" static git_repository *repo; static git_str file_path_buf = GIT_STR_INIT; @@ -470,18 +471,11 @@ void test_network_remote_local__anonymous_remote_inmemory_repo(void) { git_repository *inmemory; git_remote *remote; - -#ifdef GIT_EXPERIMENTAL_SHA256 git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT; -#endif git_str_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git"))); -#ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_repository_new(&inmemory, &repo_opts)); -#else - cl_git_pass(git_repository_new(&inmemory)); -#endif + cl_git_pass(git_repository_new_ext(&inmemory, &repo_opts)); cl_git_pass(git_remote_create_anonymous(&remote, inmemory, git_str_cstr(&file_path_buf))); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, NULL, NULL)); cl_assert(git_remote_connected(remote)); diff --git a/tests/libgit2/object/raw/write.c b/tests/libgit2/object/raw/write.c index 346053df5..b95deffdb 100644 --- a/tests/libgit2/object/raw/write.c +++ b/tests/libgit2/object/raw/write.c @@ -66,7 +66,7 @@ void test_body(object_data *d, git_rawobj *o) git_rawobj tmp; make_odb_dir(); - cl_git_pass(git_odb__open(&db, odb_dir, NULL)); + cl_git_pass(git_odb_open_ext(&db, odb_dir, NULL)); cl_git_pass(git_oid__fromstr(&id1, d->id, GIT_OID_SHA1)); streaming_write(&id2, db, o); diff --git a/tests/libgit2/object/tree/update.c b/tests/libgit2/object/tree/update.c index 1e82bdcd6..13373b6c4 100644 --- a/tests/libgit2/object/tree/update.c +++ b/tests/libgit2/object/tree/update.c @@ -29,7 +29,7 @@ void test_object_tree_update__remove_blob(void) cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&idx)); cl_git_pass(git_index_read_tree(idx, base_tree)); cl_git_pass(git_index_remove(idx, path, 0)); cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo)); @@ -58,7 +58,7 @@ void test_object_tree_update__remove_blob_deeper(void) cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&idx)); cl_git_pass(git_index_read_tree(idx, base_tree)); cl_git_pass(git_index_remove(idx, path, 0)); cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo)); @@ -89,7 +89,7 @@ void test_object_tree_update__remove_all_entries(void) cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&idx)); cl_git_pass(git_index_read_tree(idx, base_tree)); cl_git_pass(git_index_remove(idx, path1, 0)); cl_git_pass(git_index_remove(idx, path2, 0)); @@ -120,7 +120,7 @@ void test_object_tree_update__replace_blob(void) cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&idx)); cl_git_pass(git_index_read_tree(idx, base_tree)); entry.path = path; @@ -172,7 +172,7 @@ void test_object_tree_update__add_blobs(void) int j; /* Create it with an index */ - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&idx)); base_tree = NULL; if (i == 1) { @@ -229,7 +229,7 @@ void test_object_tree_update__add_blobs_unsorted(void) int j; /* Create it with an index */ - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new(&idx)); base_tree = NULL; if (i == 1) { diff --git a/tests/libgit2/odb/backend/loose.c b/tests/libgit2/odb/backend/loose.c index f5a0b4f5c..4e17bb96f 100644 --- a/tests/libgit2/odb/backend/loose.c +++ b/tests/libgit2/odb/backend/loose.c @@ -19,7 +19,7 @@ void test_odb_backend_loose__initialize(void) cl_git_pass(git_odb_backend_loose(&backend, "testrepo.git/objects", 0, 0, 0, 0)); #endif - cl_git_pass(git_odb__new(&_odb, NULL)); + cl_git_pass(git_odb_new(&_odb)); cl_git_pass(git_odb_add_backend(_odb, backend, 10)); cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); } diff --git a/tests/libgit2/odb/backend/mempack.c b/tests/libgit2/odb/backend/mempack.c index 462a1d333..036b13a51 100644 --- a/tests/libgit2/odb/backend/mempack.c +++ b/tests/libgit2/odb/backend/mempack.c @@ -13,7 +13,7 @@ static git_odb_backend *_backend; 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_new(&_odb)); cl_git_pass(git_odb_add_backend(_odb, _backend, 10)); cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); } diff --git a/tests/libgit2/odb/backend/nobackend.c b/tests/libgit2/odb/backend/nobackend.c index e8af9a6d6..b33f79abb 100644 --- a/tests/libgit2/odb/backend/nobackend.c +++ b/tests/libgit2/odb/backend/nobackend.c @@ -11,17 +11,15 @@ void test_odb_backend_nobackend__initialize(void) git_odb *odb; git_refdb *refdb; -#ifdef GIT_EXPERIMENTAL_SHA256 git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT; + git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; repo_opts.oid_type = GIT_OID_SHA1; + odb_opts.oid_type = GIT_OID_SHA1; - cl_git_pass(git_repository_new(&_repo, &repo_opts)); -#else - cl_git_pass(git_repository_new(&_repo)); -#endif + cl_git_pass(git_repository_new_ext(&_repo, &repo_opts)); cl_git_pass(git_config_new(&config)); - cl_git_pass(git_odb__new(&odb, NULL)); + cl_git_pass(git_odb_new_ext(&odb, &odb_opts)); cl_git_pass(git_refdb_new(&refdb, _repo)); git_repository_set_config(_repo, config); diff --git a/tests/libgit2/odb/foreach.c b/tests/libgit2/odb/foreach.c index 56b3e882c..091bd783e 100644 --- a/tests/libgit2/odb/foreach.c +++ b/tests/libgit2/odb/foreach.c @@ -50,8 +50,11 @@ void test_odb_foreach__one_pack(void) { git_odb_backend *backend = NULL; int nobj = 0; + git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; - cl_git_pass(git_odb__new(&_odb, NULL)); + odb_opts.oid_type = GIT_OID_SHA1; + + cl_git_pass(git_odb_new_ext(&_odb, &odb_opts)); #ifdef GIT_EXPERIMENTAL_SHA256 cl_git_pass(git_odb_backend_one_pack(&backend, diff --git a/tests/libgit2/odb/loose.c b/tests/libgit2/odb/loose.c index 0409dfb28..4ad47772c 100644 --- a/tests/libgit2/odb/loose.c +++ b/tests/libgit2/odb/loose.c @@ -44,7 +44,7 @@ static void test_read_object(object_data *data) write_object_files(data); - cl_git_pass(git_odb__open(&odb, "test-objects", &opts)); + cl_git_pass(git_odb_open_ext(&odb, "test-objects", &opts)); cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type)); cl_git_pass(git_odb_read(&obj, odb, &id)); @@ -70,7 +70,7 @@ static void test_read_header(object_data *data) write_object_files(data); - cl_git_pass(git_odb__open(&odb, "test-objects", &opts)); + cl_git_pass(git_odb_open_ext(&odb, "test-objects", &opts)); cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type)); cl_git_pass(git_odb_read_header(&len, &type, odb, &id)); @@ -95,7 +95,7 @@ static void test_readstream_object(object_data *data, size_t blocksize) write_object_files(data); - cl_git_pass(git_odb__open(&odb, "test-objects", &opts)); + cl_git_pass(git_odb_open_ext(&odb, "test-objects", &opts)); cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type)); cl_git_pass(git_odb_open_rstream(&stream, &tmp.len, &tmp.type, odb, &id)); @@ -139,7 +139,7 @@ void test_odb_loose__exists_sha1(void) git_odb *odb; write_object_files(&one); - cl_git_pass(git_odb__open(&odb, "test-objects", NULL)); + cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid__fromstr(&id, one.id, GIT_OID_SHA1)); cl_assert(git_odb_exists(odb, &id)); @@ -170,7 +170,7 @@ void test_odb_loose__exists_sha256(void) odb_opts.oid_type = GIT_OID_SHA256; write_object_files(&one_sha256); - cl_git_pass(git_odb__open(&odb, "test-objects", &odb_opts)); + cl_git_pass(git_odb_open_ext(&odb, "test-objects", &odb_opts)); cl_git_pass(git_oid__fromstr(&id, one_sha256.id, GIT_OID_SHA256)); cl_assert(git_odb_exists(odb, &id)); @@ -304,7 +304,7 @@ static void test_write_object_permission( opts.dir_mode = dir_mode; opts.file_mode = file_mode; - cl_git_pass(git_odb__new(&odb, NULL)); + cl_git_pass(git_odb_new(&odb)); cl_git_pass(git_odb__backend_loose(&backend, "test-objects", &opts)); cl_git_pass(git_odb_add_backend(odb, backend, 1)); cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB)); @@ -338,16 +338,17 @@ static void write_object_to_loose_odb(int fsync) git_odb *odb; git_odb_backend *backend; git_oid oid; - git_odb_backend_loose_options opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; + git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; + git_odb_backend_loose_options backend_opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; if (fsync) - opts.flags |= GIT_ODB_BACKEND_LOOSE_FSYNC; + backend_opts.flags |= GIT_ODB_BACKEND_LOOSE_FSYNC; - opts.dir_mode = 0777; - opts.file_mode = 0666; + backend_opts.dir_mode = 0777; + backend_opts.file_mode = 0666; - cl_git_pass(git_odb__new(&odb, NULL)); - cl_git_pass(git_odb__backend_loose(&backend, "test-objects", &opts)); + cl_git_pass(git_odb_new_ext(&odb, &odb_opts)); + cl_git_pass(git_odb__backend_loose(&backend, "test-objects", &backend_opts)); cl_git_pass(git_odb_add_backend(odb, backend, 1)); cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB)); git_odb_free(odb); diff --git a/tests/libgit2/odb/mixed.c b/tests/libgit2/odb/mixed.c index 19e6dcebf..2cba8cb14 100644 --- a/tests/libgit2/odb/mixed.c +++ b/tests/libgit2/odb/mixed.c @@ -5,7 +5,7 @@ static git_odb *_odb; void test_odb_mixed__initialize(void) { - cl_git_pass(git_odb__open(&_odb, cl_fixture("duplicate.git/objects"), NULL)); + cl_git_pass(git_odb_open_ext(&_odb, cl_fixture("duplicate.git/objects"), NULL)); } void test_odb_mixed__cleanup(void) diff --git a/tests/libgit2/odb/open.c b/tests/libgit2/odb/open.c index 395406d0f..05e65d2c0 100644 --- a/tests/libgit2/odb/open.c +++ b/tests/libgit2/odb/open.c @@ -1,4 +1,5 @@ #include "clar_libgit2.h" +#include "odb.h" void test_odb_open__initialize(void) { @@ -14,15 +15,14 @@ void test_odb_open__exists(void) { git_odb *odb; git_oid one, two; - -#ifdef GIT_EXPERIMENTAL_SHA256 git_odb_options opts = GIT_ODB_OPTIONS_INIT; - cl_git_pass(git_odb_open(&odb, "testrepo.git/objects", &opts)); + cl_git_pass(git_odb_open_ext(&odb, "testrepo.git/objects", &opts)); + +#ifdef GIT_EXPERIMENTAL_SHA256 cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233", GIT_OID_SHA1)); #else - cl_git_pass(git_odb_open(&odb, "testrepo.git/objects")); cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08")); cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233")); #endif diff --git a/tests/libgit2/odb/packed.c b/tests/libgit2/odb/packed.c index b41041fc1..6fbe0a46d 100644 --- a/tests/libgit2/odb/packed.c +++ b/tests/libgit2/odb/packed.c @@ -6,7 +6,7 @@ static git_odb *_odb; void test_odb_packed__initialize(void) { - cl_git_pass(git_odb__open(&_odb, cl_fixture("testrepo.git/objects"), NULL)); + cl_git_pass(git_odb_open_ext(&_odb, cl_fixture("testrepo.git/objects"), NULL)); } void test_odb_packed__cleanup(void) diff --git a/tests/libgit2/odb/packed256.c b/tests/libgit2/odb/packed256.c index 65220fd4c..3b04e88b5 100644 --- a/tests/libgit2/odb/packed256.c +++ b/tests/libgit2/odb/packed256.c @@ -13,7 +13,7 @@ void test_odb_packed256__initialize(void) opts.oid_type = GIT_OID_SHA256; - cl_git_pass(git_odb__open( + cl_git_pass(git_odb_open_ext( &_odb, cl_fixture("testrepo_256.git/objects"), &opts)); diff --git a/tests/libgit2/odb/packedone.c b/tests/libgit2/odb/packedone.c index 8637001ff..4dea474f9 100644 --- a/tests/libgit2/odb/packedone.c +++ b/tests/libgit2/odb/packedone.c @@ -10,7 +10,8 @@ void test_odb_packedone__initialize(void) { git_odb_backend *backend = NULL; - cl_git_pass(git_odb__new(&_odb, NULL)); + cl_git_pass(git_odb_new_ext(&_odb, NULL)); + #ifdef GIT_EXPERIMENTAL_SHA256 cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"), diff --git a/tests/libgit2/odb/packedone256.c b/tests/libgit2/odb/packedone256.c index fdeac4205..6fc6a8081 100644 --- a/tests/libgit2/odb/packedone256.c +++ b/tests/libgit2/odb/packedone256.c @@ -18,7 +18,7 @@ void test_odb_packedone256__initialize(void) odb_opts.oid_type = GIT_OID_SHA256; backend_opts.oid_type = GIT_OID_SHA256; - cl_git_pass(git_odb__new(&_odb, &odb_opts)); + cl_git_pass(git_odb_new_ext(&_odb, &odb_opts)); cl_git_pass(git_odb_backend_one_pack( &backend, cl_fixture("testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx"), diff --git a/tests/libgit2/odb/sorting.c b/tests/libgit2/odb/sorting.c index 3fe52e852..95d471db5 100644 --- a/tests/libgit2/odb/sorting.c +++ b/tests/libgit2/odb/sorting.c @@ -42,7 +42,7 @@ static git_odb *_odb; void test_odb_sorting__initialize(void) { - cl_git_pass(git_odb__new(&_odb, NULL)); + cl_git_pass(git_odb_new(&_odb)); } void test_odb_sorting__cleanup(void) @@ -94,7 +94,7 @@ void test_odb_sorting__override_default_backend_priority(void) ); git_odb__backend_loose(&loose, "./testrepo.git/objects", NULL); - cl_git_pass(git_odb__open(&new_odb, cl_fixture("testrepo.git/objects"), NULL)); + cl_git_pass(git_odb_open(&new_odb, cl_fixture("testrepo.git/objects"))); cl_assert_equal_sz(2, git_odb_num_backends(new_odb)); cl_git_pass(git_odb_get_backend(&backend, new_odb, 0)); diff --git a/tests/libgit2/refs/iterator.c b/tests/libgit2/refs/iterator.c index a46db6290..d79d968a5 100644 --- a/tests/libgit2/refs/iterator.c +++ b/tests/libgit2/refs/iterator.c @@ -128,7 +128,7 @@ void test_refs_iterator__empty(void) git_reference *ref; git_repository *empty; - cl_git_pass(git_odb__new(&odb, NULL)); + cl_git_pass(git_odb_new(&odb)); cl_git_pass(git_repository_wrap_odb(&empty, odb)); cl_git_pass(git_reference_iterator_new(&iter, empty)); diff --git a/tests/libgit2/repo/new.c b/tests/libgit2/repo/new.c index 5136e60b0..92a5a8cfa 100644 --- a/tests/libgit2/repo/new.c +++ b/tests/libgit2/repo/new.c @@ -1,19 +1,15 @@ #include "clar_libgit2.h" #include "git2/sys/repository.h" +#include "repository.h" void test_repo_new__has_nothing(void) { git_repository *repo; - -#ifdef GIT_EXPERIMENTAL_SHA256 git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT; repo_opts.oid_type = GIT_OID_SHA1; - cl_git_pass(git_repository_new(&repo, &repo_opts)); -#else - cl_git_pass(git_repository_new(&repo)); -#endif + cl_git_pass(git_repository_new_ext(&repo, &repo_opts)); cl_assert_equal_b(true, git_repository_is_bare(repo)); cl_assert_equal_p(NULL, git_repository_path(repo)); cl_assert_equal_p(NULL, git_repository_workdir(repo)); @@ -24,15 +20,11 @@ void test_repo_new__is_bare_until_workdir_set(void) { git_repository *repo; -#ifdef GIT_EXPERIMENTAL_SHA256 git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT; repo_opts.oid_type = GIT_OID_SHA1; - cl_git_pass(git_repository_new(&repo, &repo_opts)); -#else - cl_git_pass(git_repository_new(&repo)); -#endif + cl_git_pass(git_repository_new_ext(&repo, &repo_opts)); cl_assert_equal_b(true, git_repository_is_bare(repo)); cl_git_pass(git_repository_set_workdir(repo, clar_sandbox_path(), 0)); @@ -44,16 +36,11 @@ void test_repo_new__is_bare_until_workdir_set(void) void test_repo_new__sha1(void) { git_repository *repo; - -#ifdef GIT_EXPERIMENTAL_SHA256 git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT; repo_opts.oid_type = GIT_OID_SHA1; - cl_git_pass(git_repository_new(&repo, &repo_opts)); -#else - cl_git_pass(git_repository_new(&repo)); -#endif + cl_git_pass(git_repository_new_ext(&repo, &repo_opts)); cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(repo)); git_repository_free(repo); @@ -69,7 +56,7 @@ void test_repo_new__sha256(void) repo_opts.oid_type = GIT_OID_SHA256; - cl_git_pass(git_repository_new(&repo, &repo_opts)); + cl_git_pass(git_repository_new_ext(&repo, &repo_opts)); cl_assert_equal_i(GIT_OID_SHA256, git_repository_oid_type(repo)); git_repository_free(repo); diff --git a/tests/libgit2/repo/setters.c b/tests/libgit2/repo/setters.c index 1ad38bb8b..8e2946d4d 100644 --- a/tests/libgit2/repo/setters.c +++ b/tests/libgit2/repo/setters.c @@ -70,8 +70,11 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void) void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_one_properly_honors_the_refcount(void) { git_index *new_index; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; - cl_git_pass(git_index__open(&new_index, "./my-index", GIT_OID_SHA1)); + index_opts.oid_type = GIT_OID_SHA1; + + cl_git_pass(git_index_open_ext(&new_index, "./my-index", &index_opts)); cl_assert(((git_refcount *)new_index)->refcount.val == 1); git_repository_set_index(repo, new_index); @@ -92,7 +95,7 @@ void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_pro { git_odb *new_odb; - cl_git_pass(git_odb__open(&new_odb, "./testrepo.git/objects", NULL)); + cl_git_pass(git_odb_open(&new_odb, "./testrepo.git/objects")); cl_assert(((git_refcount *)new_odb)->refcount.val == 1); git_repository_set_odb(repo, new_odb); diff --git a/tests/libgit2/reset/hard.c b/tests/libgit2/reset/hard.c index 06a8a049a..fa7c0b3e6 100644 --- a/tests/libgit2/reset/hard.c +++ b/tests/libgit2/reset/hard.c @@ -247,13 +247,14 @@ void test_reset_hard__switch_file_to_dir(void) git_signature *sig; git_oid src_tree_id, tgt_tree_id; git_oid src_id, tgt_id; + git_index_options index_opts = GIT_INDEX_OPTIONS_INIT; cl_git_pass(git_repository_odb(&odb, repo)); cl_git_pass(git_odb_write(&entry.id, odb, "", 0, GIT_OBJECT_BLOB)); git_odb_free(odb); entry.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&idx, &index_opts)); cl_git_pass(git_signature_now(&sig, "foo", "bar")); /* Create the old tree */ diff --git a/tests/libgit2/status/worktree_init.c b/tests/libgit2/status/worktree_init.c index db6e71f12..532b4bba0 100644 --- a/tests/libgit2/status/worktree_init.c +++ b/tests/libgit2/status/worktree_init.c @@ -66,7 +66,7 @@ void test_status_worktree_init__status_file_without_index_or_workdir(void) cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_set_workdir(repo, "wd", false)); - cl_git_pass(git_index__open(&index, "empty-index", GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, "empty-index")); cl_assert_equal_i(0, (int)git_index_entrycount(index)); git_repository_set_index(repo, index); @@ -107,7 +107,7 @@ void test_status_worktree_init__status_file_with_clean_index_and_empty_workdir(v cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_set_workdir(repo, "wd", false)); - cl_git_pass(git_index__open(&index, "my-index", GIT_OID_SHA1)); + cl_git_pass(git_index_open(&index, "my-index")); fill_index_wth_head_entries(repo, index); git_repository_set_index(repo, index); diff --git a/tests/libgit2/submodule/lookup.c b/tests/libgit2/submodule/lookup.c index 14a624bad..2c5c6081f 100644 --- a/tests/libgit2/submodule/lookup.c +++ b/tests/libgit2/submodule/lookup.c @@ -211,7 +211,7 @@ void test_submodule_lookup__lookup_even_with_missing_index(void) git_index *idx; /* give the repo an empty index */ - cl_git_pass(git_index__new(&idx, GIT_OID_SHA1)); + cl_git_pass(git_index_new_ext(&idx, NULL)); git_repository_set_index(g_repo, idx); git_index_free(idx);