indexer: move oid_type into the opts structure

Object ID type should be an option within the options structure; move it
there.
This commit is contained in:
Edward Thomson
2024-12-16 16:58:50 +00:00
parent 708d64f1e8
commit 9aa5faa38b
9 changed files with 30 additions and 22 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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
/**

View File

@@ -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

View File

@@ -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 @@ cleanup:
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);

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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