mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
midx: add options to writer function
Provide an options structure to MIDX writing. This allows us to specify information (like OID type) during writer creation.
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -508,21 +508,29 @@ 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;
|
||||
GIT_ASSERT_ARG(out && pack_dir);
|
||||
|
||||
#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
|
||||
|
||||
GIT_ASSERT_ARG(out && pack_dir && oid_type);
|
||||
|
||||
w = git__calloc(1, sizeof(git_midx_writer));
|
||||
GIT_ERROR_CHECK_ALLOC(w);
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user