diff --git a/examples/index-pack.c b/examples/index-pack.c index 0f8234c7591..e9f32b8b291 100644 --- a/examples/index-pack.c +++ b/examples/index-pack.c @@ -29,7 +29,7 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv) } #ifdef GIT_EXPERIMENTAL_SHA256 - error = git_indexer_new(&idx, ".", git_repository_oid_type(repo), NULL); + error = git_indexer_new(&idx, ".", NULL); #else error = git_indexer_new(&idx, ".", 0, NULL, NULL); #endif diff --git a/examples/show-index.c b/examples/show-index.c index 0a5e7d1a2e4..ac0040874ec 100644 --- a/examples/show-index.c +++ b/examples/show-index.c @@ -31,7 +31,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, GIT_OID_SHA1), "could not open index", dir); + 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 diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c index aeba9575c3e..bcbdd8bc40b 100644 --- a/fuzzers/packfile_fuzzer.c +++ b/fuzzers/packfile_fuzzer.c @@ -84,7 +84,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) } #ifdef GIT_EXPERIMENTAL_SHA256 - error = git_indexer_new(&indexer, ".", GIT_OID_SHA1, NULL); + error = git_indexer_new(&indexer, ".", NULL); #else error = git_indexer_new(&indexer, ".", 0, odb, NULL); #endif diff --git a/include/git2/index.h b/include/git2/index.h index 9f3efe1fc7e..0adff1abd95 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -191,25 +191,69 @@ typedef enum { #ifdef GIT_EXPERIMENTAL_SHA256 +/** + * The options for opening or creating an index. + * + * Initialize with `GIT_INDEX_OPTIONS_INIT`. Alternatively, you can + * use `git_index_options_init`. + * + * @options[version] GIT_INDEX_OPTIONS_VERSION + * @options[init_macro] GIT_INDEX_OPTIONS_INIT + * @options[init_function] git_index_options_init + */ +typedef struct git_index_options { + unsigned int version; /**< The version */ + + /** + * The object ID type for the object IDs that exist in the index. + * + * If this is not specified, this defaults to `GIT_OID_SHA1`. + */ + git_oid_t oid_type; +} git_index_options; + +/** Current version for the `git_index_options` structure */ +#define GIT_INDEX_OPTIONS_VERSION 1 + +/** Static constructor for `git_index_options` */ +#define GIT_INDEX_OPTIONS_INIT { GIT_INDEX_OPTIONS_VERSION } + +/** + * Initialize git_index_options structure + * + * Initializes a `git_index_options` with default values. Equivalent to creating + * an instance with GIT_INDEX_OPTIONS_INIT. + * + * @param opts The `git_index_options` struct to initialize. + * @param version The struct version; pass `GIT_INDEX_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ +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 oid_type the object ID type to use for the repository + * @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, git_oid_t oid_type); +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 oid_type the object ID type to use for the repository + * @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, git_oid_t oid_type); +GIT_EXTERN(int) git_index_new(git_index **index_out, const git_index_options *opts); #else diff --git a/include/git2/indexer.h b/include/git2/indexer.h index d47ce2c1885..9aaedc3c43f 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -77,6 +77,9 @@ typedef struct git_indexer_options { /** permissions to use creating packfile or 0 for defaults */ unsigned int mode; + /** the type of object ids in the packfile or 0 for SHA1 */ + git_oid_t oid_type; + /** * object database from which to read base objects when * fixing thin packs. This can be NULL if there are no thin @@ -120,13 +123,12 @@ GIT_EXTERN(int) git_indexer_options_init( * * @param out where to store the indexer instance * @param path to the directory where the packfile should be stored - * @param oid_type the oid type to use for objects + * @param opts the options to create the indexer with * @return 0 or an error code. */ GIT_EXTERN(int) git_indexer_new( git_indexer **out, const char *path, - git_oid_t oid_type, git_indexer_options *opts); #else /** diff --git a/include/git2/repository.h b/include/git2/repository.h index 59c4d0f30d6..b203576affc 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -10,6 +10,7 @@ #include "common.h" #include "types.h" #include "oid.h" +#include "odb.h" #include "buffer.h" #include "commit.h" @@ -52,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, - git_oid_t oid_type); - -#else - /** * Create a "fake" repository to wrap an object database * @@ -76,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/include/git2/sys/commit_graph.h b/include/git2/sys/commit_graph.h index 838efee55bf..ff547ef0c1f 100644 --- a/include/git2/sys/commit_graph.h +++ b/include/git2/sys/commit_graph.h @@ -19,6 +19,45 @@ */ GIT_BEGIN_DECL +/** + * Options structure for `git_commit_graph_open_new`. + * + * Initialize with `GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT`. Alternatively, + * you can use `git_commit_graph_open_options_init`. + */ +typedef struct { + unsigned int version; + +#ifdef GIT_EXPERIMENTAL_SHA256 + /** The object ID type that this commit graph contains. */ + git_oid_t oid_type; +#endif +} git_commit_graph_open_options; + +/** Current version for the `git_commit_graph_open_options` structure */ +#define GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION 1 + +/** Static constructor for `git_commit_graph_open_options` */ +#define GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT { \ + GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION \ + } + +/** + * Initialize git_commit_graph_open_options structure + * + * Initializes a `git_commit_graph_open_options` with default values. + * Equivalent to creating an instance with + * `GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT`. + * + * @param opts The `git_commit_graph_open_options` struct to initialize. + * @param version The struct version; pass `GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ +GIT_EXTERN(int) git_commit_graph_open_options_init( + git_commit_graph_open_options *opts, + unsigned int version); + + /** * Opens a `git_commit_graph` from a path to an objects directory. * @@ -32,7 +71,7 @@ GIT_EXTERN(int) git_commit_graph_open( git_commit_graph **cgraph_out, const char *objects_dir #ifdef GIT_EXPERIMENTAL_SHA256 - , git_oid_t oid_type + , const git_commit_graph_open_options *options #endif ); @@ -46,54 +85,6 @@ GIT_EXTERN(int) git_commit_graph_open( */ GIT_EXTERN(void) git_commit_graph_free(git_commit_graph *cgraph); -/** - * Create a new writer for `commit-graph` files. - * - * @param out Location to store the writer pointer. - * @param objects_info_dir The `objects/info` directory. - * The `commit-graph` file will be written in this directory. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_new( - git_commit_graph_writer **out, - const char *objects_info_dir -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_oid_t oid_type -#endif - ); - -/** - * Free the commit-graph writer and its resources. - * - * @param w The writer to free. If NULL no action is taken. - */ -GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w); - -/** - * Add an `.idx` file (associated to a packfile) to the writer. - * - * @param w The writer. - * @param repo The repository that owns the `.idx` file. - * @param idx_path The path of an `.idx` file. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_add_index_file( - git_commit_graph_writer *w, - git_repository *repo, - const char *idx_path); - -/** - * Add a revwalk to the writer. This will add all the commits from the revwalk - * to the commit-graph. - * - * @param w The writer. - * @param walk The git_revwalk. - * @return 0 or an error code - */ -GIT_EXTERN(int) git_commit_graph_writer_add_revwalk( - git_commit_graph_writer *w, - git_revwalk *walk); - /** * The strategy to use when adding a new set of commits to a pre-existing @@ -108,15 +99,19 @@ typedef enum { } git_commit_graph_split_strategy_t; /** - * Options structure for - * `git_commit_graph_writer_commit`/`git_commit_graph_writer_dump`. + * Options structure for `git_commit_graph_writer_new`. * - * Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, you - * can use `git_commit_graph_writer_options_init`. + * Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, + * you can use `git_commit_graph_writer_options_init`. */ typedef struct { unsigned int version; +#ifdef GIT_EXPERIMENTAL_SHA256 + /** The object ID type that this commit graph contains. */ + git_oid_t oid_type; +#endif + /** * The strategy to use when adding new commits to a pre-existing commit-graph * chain. @@ -158,29 +153,71 @@ GIT_EXTERN(int) git_commit_graph_writer_options_init( git_commit_graph_writer_options *opts, unsigned int version); +/** + * Create a new writer for `commit-graph` files. + * + * @param out Location to store the writer pointer. + * @param objects_info_dir The `objects/info` directory. + * The `commit-graph` file will be written in this directory. + * @param options The options for the commit graph writer. + * @return 0 or an error code + */ +GIT_EXTERN(int) git_commit_graph_writer_new( + git_commit_graph_writer **out, + const char *objects_info_dir, + const git_commit_graph_writer_options *options); + +/** + * Free the commit-graph writer and its resources. + * + * @param w The writer to free. If NULL no action is taken. + */ +GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w); + +/** + * Add an `.idx` file (associated to a packfile) to the writer. + * + * @param w The writer. + * @param repo The repository that owns the `.idx` file. + * @param idx_path The path of an `.idx` file. + * @return 0 or an error code + */ +GIT_EXTERN(int) git_commit_graph_writer_add_index_file( + git_commit_graph_writer *w, + git_repository *repo, + const char *idx_path); + +/** + * Add a revwalk to the writer. This will add all the commits from the revwalk + * to the commit-graph. + * + * @param w The writer. + * @param walk The git_revwalk. + * @return 0 or an error code + */ +GIT_EXTERN(int) git_commit_graph_writer_add_revwalk( + git_commit_graph_writer *w, + git_revwalk *walk); + /** * Write a `commit-graph` file to a file. * * @param w The writer - * @param opts Pointer to git_commit_graph_writer_options struct. * @return 0 or an error code */ GIT_EXTERN(int) git_commit_graph_writer_commit( - git_commit_graph_writer *w, - git_commit_graph_writer_options *opts); + git_commit_graph_writer *w); /** * Dump the contents of the `commit-graph` to an in-memory buffer. * - * @param buffer Buffer where to store the contents of the `commit-graph`. + * @param[out] buffer Buffer where to store the contents of the `commit-graph`. * @param w The writer. - * @param opts Pointer to git_commit_graph_writer_options struct. * @return 0 or an error code */ GIT_EXTERN(int) git_commit_graph_writer_dump( git_buf *buffer, - git_commit_graph_writer *w, - git_commit_graph_writer_options *opts); + git_commit_graph_writer *w); /** @} */ GIT_END_DECL diff --git a/include/git2/sys/midx.h b/include/git2/sys/midx.h index 2bf0d01eb48..b3a68afbfc5 100644 --- a/include/git2/sys/midx.h +++ b/include/git2/sys/midx.h @@ -19,6 +19,44 @@ */ GIT_BEGIN_DECL +/** + * Options structure for `git_midx_writer_options`. + * + * Initialize with `GIT_MIDX_WRITER_OPTIONS_INIT`. Alternatively, + * you can use `git_midx_writer_options_init`. + */ +typedef struct { + unsigned int version; + +#ifdef GIT_EXPERIMENTAL_SHA256 + /** The object ID type that this commit graph contains. */ + git_oid_t oid_type; +#endif +} git_midx_writer_options; + +/** Current version for the `git_midx_writer_options` structure */ +#define GIT_MIDX_WRITER_OPTIONS_VERSION 1 + +/** Static constructor for `git_midx_writer_options` */ +#define GIT_MIDX_WRITER_OPTIONS_INIT { \ + GIT_MIDX_WRITER_OPTIONS_VERSION \ + } + +/** + * Initialize git_midx_writer_options structure + * + * Initializes a `git_midx_writer_options` with default values. + * Equivalent to creating an instance with + * `GIT_MIDX_WRITER_OPTIONS_INIT`. + * + * @param opts The `git_midx_writer_options` struct to initialize. + * @param version The struct version; pass `GIT_MIDX_WRITER_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ +GIT_EXTERN(int) git_midx_writer_options_init( + git_midx_writer_options *opts, + unsigned int version); + /** * Create a new writer for `multi-pack-index` files. * @@ -31,7 +69,7 @@ GIT_EXTERN(int) git_midx_writer_new( git_midx_writer **out, const char *pack_dir #ifdef GIT_EXPERIMENTAL_SHA256 - , git_oid_t oid_type + , git_midx_writer_options *options #endif ); diff --git a/include/git2/sys/repository.h b/include/git2/sys/repository.h index eb0a33a92de..026ac8a1d1a 100644 --- a/include/git2/sys/repository.h +++ b/include/git2/sys/repository.h @@ -22,14 +22,56 @@ GIT_BEGIN_DECL #ifdef GIT_EXPERIMENTAL_SHA256 +/** + * The options for creating an repository from scratch. + * + * Initialize with `GIT_REPOSITORY_NEW_OPTIONS_INIT`. Alternatively, + * you can use `git_repository_new_options_init`. + * + * @options[version] GIT_REPOSITORY_NEW_OPTIONS_VERSION + * @options[init_macro] GIT_REPOSITORY_NEW_OPTIONS_INIT + * @options[init_function] git_repository_new_options_init + */ +typedef struct git_repository_new_options { + unsigned int version; /**< The version */ + + /** + * The object ID type for the object IDs that exist in the index. + * + * If this is not specified, this defaults to `GIT_OID_SHA1`. + */ + git_oid_t oid_type; +} git_repository_new_options; + +/** Current version for the `git_repository_new_options` structure */ +#define GIT_REPOSITORY_NEW_OPTIONS_VERSION 1 + +/** Static constructor for `git_repository_new_options` */ +#define GIT_REPOSITORY_NEW_OPTIONS_INIT { GIT_REPOSITORY_NEW_OPTIONS_VERSION } + +/** + * Initialize git_repository_new_options structure + * + * Initializes a `git_repository_new_options` with default values. + * Equivalent to creating an instance with + * `GIT_REPOSITORY_NEW_OPTIONS_INIT`. + * + * @param opts The `git_repository_new_options` struct to initialize. + * @param version The struct version; pass `GIT_REPOSITORY_NEW_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ +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 oid_type the object ID type for this 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_oid_t oid_type); +GIT_EXTERN(int) git_repository_new(git_repository **out, git_repository_new_options *opts); #else /** diff --git a/src/cli/cmd_index_pack.c b/src/cli/cmd_index_pack.c index b8e9749de6a..6a67990b47d 100644 --- a/src/cli/cmd_index_pack.c +++ b/src/cli/cmd_index_pack.c @@ -78,7 +78,9 @@ int cmd_index_pack(int argc, char **argv) } #ifdef GIT_EXPERIMENTAL_SHA256 - ret = git_indexer_new(&idx, ".", GIT_OID_SHA1, &idx_opts); + idx_opts.oid_type = GIT_OID_SHA1; + + ret = git_indexer_new(&idx, ".", &idx_opts); #else ret = git_indexer_new(&idx, ".", 0, NULL, &idx_opts); #endif diff --git a/src/libgit2/commit_graph.c b/src/libgit2/commit_graph.c index 8fd59692730..92785049e4e 100644 --- a/src/libgit2/commit_graph.c +++ b/src/libgit2/commit_graph.c @@ -365,15 +365,24 @@ int git_commit_graph_open( git_commit_graph **cgraph_out, const char *objects_dir #ifdef GIT_EXPERIMENTAL_SHA256 - , git_oid_t oid_type + , const git_commit_graph_open_options *opts #endif ) { -#ifndef GIT_EXPERIMENTAL_SHA256 - git_oid_t oid_type = GIT_OID_SHA1; -#endif + git_oid_t oid_type; int error; +#ifdef GIT_EXPERIMENTAL_SHA256 + GIT_ERROR_CHECK_VERSION(opts, + GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION, + "git_commit_graph_open_options"); + + oid_type = opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT; + GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); +#else + oid_type = GIT_OID_SHA1; +#endif + error = git_commit_graph_new(cgraph_out, objects_dir, true, oid_type); @@ -684,21 +693,40 @@ static int packed_commit__cmp(const void *a_, const void *b_) return git_oid_cmp(&a->sha1, &b->sha1); } +int git_commit_graph_writer_options_init( + git_commit_graph_writer_options *opts, + unsigned int version) +{ + GIT_INIT_STRUCTURE_FROM_TEMPLATE( + opts, + version, + git_commit_graph_writer_options, + GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT); + return 0; +} + int git_commit_graph_writer_new( git_commit_graph_writer **out, - const char *objects_info_dir -#ifdef GIT_EXPERIMENTAL_SHA256 - , git_oid_t oid_type -#endif + const char *objects_info_dir, + const git_commit_graph_writer_options *opts ) { git_commit_graph_writer *w; + git_oid_t oid_type; + +#ifdef GIT_EXPERIMENTAL_SHA256 + GIT_ERROR_CHECK_VERSION(opts, + GIT_COMMIT_GRAPH_WRITER_OPTIONS_VERSION, + "git_commit_graph_writer_options"); -#ifndef GIT_EXPERIMENTAL_SHA256 - git_oid_t oid_type = GIT_OID_SHA1; + oid_type = opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT; + GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); +#else + GIT_UNUSED(opts); + oid_type = GIT_OID_SHA1; #endif - GIT_ASSERT_ARG(out && objects_info_dir && oid_type); + GIT_ASSERT_ARG(out && objects_info_dir); w = git__calloc(1, sizeof(git_commit_graph_writer)); GIT_ERROR_CHECK_ALLOC(w); @@ -775,9 +803,9 @@ static int object_entry__cb(const git_oid *id, void *data) } int git_commit_graph_writer_add_index_file( - git_commit_graph_writer *w, - git_repository *repo, - const char *idx_path) + git_commit_graph_writer *w, + git_repository *repo, + const char *idx_path) { int error; struct git_pack_file *p = NULL; @@ -1043,9 +1071,9 @@ static void packed_commit_free_dup(void *packed_commit) } static int commit_graph_write( - git_commit_graph_writer *w, - commit_graph_write_cb write_cb, - void *cb_data) + git_commit_graph_writer *w, + commit_graph_write_cb write_cb, + void *cb_data) { int error = 0; size_t i; @@ -1249,30 +1277,13 @@ static int commit_graph_write_filebuf(const char *buf, size_t size, void *data) return git_filebuf_write(f, buf, size); } -int git_commit_graph_writer_options_init( - git_commit_graph_writer_options *opts, - unsigned int version) -{ - GIT_INIT_STRUCTURE_FROM_TEMPLATE( - opts, - version, - git_commit_graph_writer_options, - GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT); - return 0; -} - -int git_commit_graph_writer_commit( - git_commit_graph_writer *w, - git_commit_graph_writer_options *opts) +int git_commit_graph_writer_commit(git_commit_graph_writer *w) { int error; int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER; git_str commit_graph_path = GIT_STR_INIT; git_filebuf output = GIT_FILEBUF_INIT; - /* TODO: support options and fill in defaults. */ - GIT_UNUSED(opts); - error = git_str_joinpath( &commit_graph_path, git_str_cstr(&w->objects_info_dir), "commit-graph"); if (error < 0) @@ -1296,18 +1307,14 @@ int git_commit_graph_writer_commit( int git_commit_graph_writer_dump( git_buf *cgraph, - git_commit_graph_writer *w, - git_commit_graph_writer_options *opts) + git_commit_graph_writer *w) { - GIT_BUF_WRAP_PRIVATE(cgraph, git_commit_graph__writer_dump, w, opts); + GIT_BUF_WRAP_PRIVATE(cgraph, git_commit_graph__writer_dump, w); } int git_commit_graph__writer_dump( git_str *cgraph, - git_commit_graph_writer *w, - git_commit_graph_writer_options *opts) + git_commit_graph_writer *w) { - /* TODO: support options. */ - GIT_UNUSED(opts); return commit_graph_write(w, commit_graph_write_buf, cgraph); } diff --git a/src/libgit2/commit_graph.h b/src/libgit2/commit_graph.h index ecf4379bdb6..a06f3f86219 100644 --- a/src/libgit2/commit_graph.h +++ b/src/libgit2/commit_graph.h @@ -156,8 +156,7 @@ struct git_commit_graph_writer { int git_commit_graph__writer_dump( git_str *cgraph, - git_commit_graph_writer *w, - git_commit_graph_writer_options *opts); + git_commit_graph_writer *w); /* * Returns whether the git_commit_graph_file needs to be reloaded since the diff --git a/src/libgit2/index.c b/src/libgit2/index.c index 29d10ef7213..a3142c8bcd9 100644 --- a/src/libgit2/index.c +++ b/src/libgit2/index.c @@ -399,6 +399,7 @@ int git_index__open( 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; if (git_pool_init(&index->tree_pool, 1) < 0) @@ -441,9 +442,13 @@ int git_index__open( } #ifdef GIT_EXPERIMENTAL_SHA256 -int git_index_open(git_index **index_out, const char *index_path, git_oid_t oid_type) +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, oid_type); + 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) @@ -458,9 +463,10 @@ int git_index__new(git_index **out, git_oid_t oid_type) } #ifdef GIT_EXPERIMENTAL_SHA256 -int git_index_new(git_index **out, git_oid_t oid_type) +int git_index_new(git_index **out, const git_index_options *opts) { - return git_index__new(out, oid_type); + return git_index__new(out, + opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); } #else int git_index_new(git_index **out) diff --git a/src/libgit2/indexer.c b/src/libgit2/indexer.c index 32a37e0670a..e62daacfa51 100644 --- a/src/libgit2/indexer.c +++ b/src/libgit2/indexer.c @@ -171,9 +171,12 @@ static int indexer_new( if (in_opts) memcpy(&opts, in_opts, sizeof(opts)); + if (oid_type) + GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); + idx = git__calloc(1, sizeof(git_indexer)); GIT_ERROR_CHECK_ALLOC(idx); - idx->oid_type = oid_type; + idx->oid_type = oid_type ? oid_type : GIT_OID_DEFAULT; idx->odb = odb; idx->progress_cb = opts.progress_cb; idx->progress_payload = opts.progress_cb_payload; @@ -233,13 +236,12 @@ static int indexer_new( int git_indexer_new( git_indexer **out, const char *prefix, - git_oid_t oid_type, git_indexer_options *opts) { return indexer_new( out, prefix, - oid_type, + opts ? opts->oid_type : 0, opts ? opts->mode : 0, opts ? opts->odb : NULL, opts); diff --git a/src/libgit2/midx.c b/src/libgit2/midx.c index 0b16af94390..1336ed85f88 100644 --- a/src/libgit2/midx.c +++ b/src/libgit2/midx.c @@ -508,20 +508,28 @@ static int packfile__cmp(const void *a_, const void *b_) } int git_midx_writer_new( - git_midx_writer **out, - const char *pack_dir + git_midx_writer **out, + const char *pack_dir #ifdef GIT_EXPERIMENTAL_SHA256 - , git_oid_t oid_type + , git_midx_writer_options *opts #endif ) { git_midx_writer *w; + git_oid_t oid_type; -#ifndef GIT_EXPERIMENTAL_SHA256 - git_oid_t oid_type = GIT_OID_SHA1; -#endif + GIT_ASSERT_ARG(out && pack_dir); - GIT_ASSERT_ARG(out && pack_dir && oid_type); +#ifdef GIT_EXPERIMENTAL_SHA256 + GIT_ERROR_CHECK_VERSION(opts, + GIT_MIDX_WRITER_OPTIONS_VERSION, + "git_midx_writer_options"); + + oid_type = opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT; + GIT_ASSERT_ARG(git_oid_type_is_valid(oid_type)); +#else + oid_type = GIT_OID_SHA1; +#endif w = git__calloc(1, sizeof(git_midx_writer)); GIT_ERROR_CHECK_ALLOC(w); diff --git a/src/libgit2/odb_pack.c b/src/libgit2/odb_pack.c index 96d3a2be476..ef8d35309fe 100644 --- a/src/libgit2/odb_pack.c +++ b/src/libgit2/odb_pack.c @@ -743,10 +743,10 @@ static int pack_backend__writepack(struct git_odb_writepack **out, #ifdef GIT_EXPERIMENTAL_SHA256 opts.odb = odb; + opts.oid_type = backend->opts.oid_type; error = git_indexer_new(&writepack->indexer, backend->pack_folder, - backend->opts.oid_type, &opts); #else error = git_indexer_new(&writepack->indexer, @@ -796,13 +796,21 @@ static int pack_backend__writemidx(git_odb_backend *_backend) size_t i; int error = 0; +#ifdef GIT_EXPERIMENTAL_SHA256 + git_midx_writer_options midx_opts = GIT_MIDX_WRITER_OPTIONS_INIT; +#endif + GIT_ASSERT_ARG(_backend); backend = (struct pack_backend *)_backend; +#ifdef GIT_EXPERIMENTAL_SHA256 + midx_opts.oid_type = backend->opts.oid_type; +#endif + error = git_midx_writer_new(&w, backend->pack_folder #ifdef GIT_EXPERIMENTAL_SHA256 - , backend->opts.oid_type + , &midx_opts #endif ); diff --git a/src/libgit2/oid.h b/src/libgit2/oid.h index f25a899a681..9415915fcb2 100644 --- a/src/libgit2/oid.h +++ b/src/libgit2/oid.h @@ -66,6 +66,15 @@ GIT_INLINE(size_t) git_oid_hexsize(git_oid_t type) return 0; } +GIT_INLINE(bool) git_oid_type_is_valid(git_oid_t type) +{ + return (type == GIT_OID_SHA1 +#ifdef GIT_EXPERIMENTAL_SHA256 + || type == GIT_OID_SHA256 +#endif + ); +} + GIT_INLINE(const char *) git_oid_type_name(git_oid_t type) { switch (type) { diff --git a/src/libgit2/pack-objects.c b/src/libgit2/pack-objects.c index 298e70aa605..ced98e8c86d 100644 --- a/src/libgit2/pack-objects.c +++ b/src/libgit2/pack-objects.c @@ -1442,8 +1442,9 @@ int git_packbuilder_write( #ifdef GIT_EXPERIMENTAL_SHA256 opts.mode = mode; opts.odb = pb->odb; + opts.oid_type = GIT_OID_SHA1; - error = git_indexer_new(&indexer, path, GIT_OID_SHA1, &opts); + error = git_indexer_new(&indexer, path, &opts); #else error = git_indexer_new(&indexer, path, mode, pb->odb, &opts); #endif diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index d41fa3933ad..82aea517a1c 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -335,6 +335,8 @@ int git_repository__new(git_repository **out, git_oid_t 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; @@ -343,9 +345,9 @@ int git_repository__new(git_repository **out, git_oid_t oid_type) } #ifdef GIT_EXPERIMENTAL_SHA256 -int git_repository_new(git_repository **out, git_oid_t oid_type) +int git_repository_new(git_repository **out, git_repository_new_options *opts) { - return git_repository__new(out, oid_type); + return git_repository__new(out, opts && opts->oid_type ? opts->oid_type : GIT_OID_DEFAULT); } #else int git_repository_new(git_repository** out) @@ -1221,17 +1223,15 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w 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; 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; @@ -1239,21 +1239,6 @@ int git_repository__wrap_odb( 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 79e087bfa93..fbf143894e6 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/attr/repo.c b/tests/libgit2/attr/repo.c index 747715b51fa..793c1a7d041 100644 --- a/tests/libgit2/attr/repo.c +++ b/tests/libgit2/attr/repo.c @@ -318,7 +318,7 @@ void test_attr_repo__inmemory_repo_without_index(void) /* setup bare in-memory repo without index */ #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_repository_new(&inmemory, GIT_OID_SHA1)); + cl_git_pass(git_repository_new(&inmemory, NULL)); #else cl_git_pass(git_repository_new(&inmemory)); #endif diff --git a/tests/libgit2/graph/commitgraph.c b/tests/libgit2/graph/commitgraph.c index 53869d61db0..363806bd9e9 100644 --- a/tests/libgit2/graph/commitgraph.c +++ b/tests/libgit2/graph/commitgraph.c @@ -105,18 +105,19 @@ void test_graph_commitgraph__writer(void) cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info")); #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path), GIT_OID_SHA1)); -#else - cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path))); + opts.oid_type = GIT_OID_SHA1; #endif + cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path), &opts)); + /* This is equivalent to `git commit-graph write --reachable`. */ cl_git_pass(git_revwalk_new(&walk, repo)); cl_git_pass(git_revwalk_push_glob(walk, "refs/*")); cl_git_pass(git_commit_graph_writer_add_revwalk(w, walk)); git_revwalk_free(walk); - cl_git_pass(git_commit_graph_writer_dump(&cgraph, w, &opts)); + cl_git_pass(git_commit_graph_writer_dump(&cgraph, w)); + cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info/commit-graph")); cl_git_pass(git_futils_readbuffer(&expected_cgraph, git_str_cstr(&path))); @@ -136,12 +137,16 @@ void test_graph_commitgraph__validate(void) struct git_commit_graph *cgraph; git_str objects_dir = GIT_STR_INIT; +#ifdef GIT_EXPERIMENTAL_SHA256 + git_commit_graph_open_options opts = GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT; +#endif + cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_git_pass(git_str_joinpath(&objects_dir, git_repository_path(repo), "objects")); /* git_commit_graph_open() calls git_commit_graph_validate() */ #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir), GIT_OID_SHA1)); + cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir), &opts)); #else cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir))); #endif @@ -157,6 +162,10 @@ void test_graph_commitgraph__validate_corrupt(void) struct git_commit_graph *cgraph; int fd = -1; +#ifdef GIT_EXPERIMENTAL_SHA256 + git_commit_graph_open_options opts = GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT; +#endif + cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&repo, cl_git_sandbox_path(1, "testrepo.git", NULL))); @@ -168,7 +177,7 @@ void test_graph_commitgraph__validate_corrupt(void) /* git_commit_graph_open() calls git_commit_graph_validate() */ #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL), GIT_OID_SHA1)); + cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL), &opts)); #else cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL))); #endif diff --git a/tests/libgit2/network/remote/local.c b/tests/libgit2/network/remote/local.c index f69502c7b15..9f3c8b61179 100644 --- a/tests/libgit2/network/remote/local.c +++ b/tests/libgit2/network/remote/local.c @@ -471,10 +471,14 @@ 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, GIT_OID_SHA1)); + cl_git_pass(git_repository_new(&inmemory, &repo_opts)); #else cl_git_pass(git_repository_new(&inmemory)); #endif diff --git a/tests/libgit2/odb/backend/loose.c b/tests/libgit2/odb/backend/loose.c index 02227945d71..f5a0b4f5caf 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 84449090a06..462a1d333a6 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/odb/backend/nobackend.c b/tests/libgit2/odb/backend/nobackend.c index a81e5857715..e8af9a6d6fa 100644 --- a/tests/libgit2/odb/backend/nobackend.c +++ b/tests/libgit2/odb/backend/nobackend.c @@ -12,7 +12,11 @@ void test_odb_backend_nobackend__initialize(void) git_refdb *refdb; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_repository_new(&_repo, GIT_OID_SHA1)); + 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 diff --git a/tests/libgit2/pack/indexer.c b/tests/libgit2/pack/indexer.c index 9722decafc0..023eb5da795 100644 --- a/tests/libgit2/pack/indexer.c +++ b/tests/libgit2/pack/indexer.c @@ -101,7 +101,7 @@ void test_pack_indexer__out_of_order(void) git_indexer_progress stats = { 0 }; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", NULL)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); #endif @@ -123,7 +123,7 @@ void test_pack_indexer__missing_trailer(void) git_indexer_progress stats = { 0 }; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", NULL)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); #endif @@ -144,7 +144,7 @@ void test_pack_indexer__leaky(void) git_indexer_progress stats = { 0 }; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", NULL)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); #endif @@ -178,7 +178,7 @@ void test_pack_indexer__fix_thin(void) #ifdef GIT_EXPERIMENTAL_SHA256 opts.odb = odb; - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); + cl_git_pass(git_indexer_new(&idx, ".", &opts)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, odb, &opts)); #endif @@ -215,7 +215,7 @@ void test_pack_indexer__fix_thin(void) cl_git_pass(p_stat(name, &st)); #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", NULL)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); #endif @@ -255,7 +255,8 @@ void test_pack_indexer__corrupt_length(void) #ifdef GIT_EXPERIMENTAL_SHA256 opts.odb = odb; - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); + opts.oid_type = GIT_OID_SHA1; + cl_git_pass(git_indexer_new(&idx, ".", &opts)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, odb, &opts)); #endif @@ -281,7 +282,7 @@ void test_pack_indexer__incomplete_pack_fails_with_strict(void) opts.verify = 1; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); + cl_git_pass(git_indexer_new(&idx, ".", &opts)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, &opts)); #endif @@ -306,7 +307,7 @@ void test_pack_indexer__out_of_order_with_connectivity_checks(void) opts.verify = 1; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); + cl_git_pass(git_indexer_new(&idx, ".", &opts)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, &opts)); #endif @@ -354,7 +355,7 @@ void test_pack_indexer__no_tmp_files(void) cl_assert(git_str_len(&first_tmp_file) == 0); #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", NULL)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); #endif diff --git a/tests/libgit2/pack/midx.c b/tests/libgit2/pack/midx.c index 4c4dfc51178..d7180c47898 100644 --- a/tests/libgit2/pack/midx.c +++ b/tests/libgit2/pack/midx.c @@ -59,7 +59,7 @@ void test_pack_midx__writer(void) cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/pack")); #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_midx_writer_new(&w, git_str_cstr(&path), GIT_OID_SHA1)); + cl_git_pass(git_midx_writer_new(&w, git_str_cstr(&path), NULL)); #else cl_git_pass(git_midx_writer_new(&w, git_str_cstr(&path))); #endif diff --git a/tests/libgit2/pack/packbuilder.c b/tests/libgit2/pack/packbuilder.c index 05dea29d10e..2c598b6ee94 100644 --- a/tests/libgit2/pack/packbuilder.c +++ b/tests/libgit2/pack/packbuilder.c @@ -102,7 +102,7 @@ void test_pack_packbuilder__create_pack(void) seed_packbuilder(); #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&_indexer, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&_indexer, ".", NULL)); #else cl_git_pass(git_indexer_new(&_indexer, ".", 0, NULL, NULL)); #endif @@ -261,7 +261,7 @@ void test_pack_packbuilder__foreach(void) seed_packbuilder(); #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", NULL)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); #endif @@ -285,7 +285,7 @@ void test_pack_packbuilder__foreach_with_cancel(void) seed_packbuilder(); #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", NULL)); #else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); #endif diff --git a/tests/libgit2/refs/iterator.c b/tests/libgit2/refs/iterator.c index 020ee01a484..a46db629085 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)); diff --git a/tests/libgit2/repo/new.c b/tests/libgit2/repo/new.c index aaa917a4aba..5136e60b09d 100644 --- a/tests/libgit2/repo/new.c +++ b/tests/libgit2/repo/new.c @@ -6,7 +6,11 @@ void test_repo_new__has_nothing(void) git_repository *repo; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1)); + 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 @@ -21,7 +25,11 @@ void test_repo_new__is_bare_until_workdir_set(void) git_repository *repo; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1)); + 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 @@ -38,7 +46,11 @@ void test_repo_new__sha1(void) git_repository *repo; #ifdef GIT_EXPERIMENTAL_SHA256 - cl_git_pass(git_repository_new(&repo, GIT_OID_SHA1)); + 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 @@ -53,8 +65,11 @@ void test_repo_new__sha256(void) cl_skip(); #else git_repository *repo; + git_repository_new_options repo_opts = GIT_REPOSITORY_NEW_OPTIONS_INIT; + + repo_opts.oid_type = GIT_OID_SHA256; - cl_git_pass(git_repository_new(&repo, GIT_OID_SHA256)); + cl_git_pass(git_repository_new(&repo, &repo_opts)); cl_assert_equal_i(GIT_OID_SHA256, git_repository_oid_type(repo)); git_repository_free(repo);