mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 17:24:59 +00:00
Merge pull request #2014 from mgbowen/cpp-options-init
Function-based options initializers
This commit is contained in:
commit
efc822ef0d
@ -82,6 +82,19 @@ typedef struct git_blame_options {
|
||||
#define GIT_BLAME_OPTIONS_VERSION 1
|
||||
#define GIT_BLAME_OPTIONS_INIT {GIT_BLAME_OPTIONS_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_blame_options` with default values. Equivalent to
|
||||
* creating an instance with GIT_BLAME_OPTIONS_INIT.
|
||||
*
|
||||
* @param opts the `git_blame_options` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_BLAME_OPTIONS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_blame_init_options(
|
||||
git_blame_options* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Structure that represents a blame hunk.
|
||||
*
|
||||
|
@ -266,6 +266,19 @@ typedef struct git_checkout_opts {
|
||||
#define GIT_CHECKOUT_OPTS_VERSION 1
|
||||
#define GIT_CHECKOUT_OPTS_INIT {GIT_CHECKOUT_OPTS_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_checkout_opts` with default values. Equivalent to
|
||||
* creating an instance with GIT_CHECKOUT_OPTS_INIT.
|
||||
*
|
||||
* @param opts the `git_checkout_opts` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_CHECKOUT_OPTS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_checkout_init_opts(
|
||||
git_checkout_opts* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Updates files in the index and the working tree to match the content of
|
||||
* the commit pointed at by HEAD.
|
||||
|
@ -65,6 +65,19 @@ typedef struct git_clone_options {
|
||||
#define GIT_CLONE_OPTIONS_VERSION 1
|
||||
#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}, GIT_REMOTE_CALLBACKS_INIT}
|
||||
|
||||
/**
|
||||
* Initializes a `git_clone_options` with default values. Equivalent to
|
||||
* creating an instance with GIT_CLONE_OPTIONS_INIT.
|
||||
*
|
||||
* @param opts the `git_clone_options` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_CLONE_OPTIONS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_clone_init_options(
|
||||
git_clone_options* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Clone a remote repository.
|
||||
*
|
||||
|
@ -376,6 +376,19 @@ typedef struct {
|
||||
#define GIT_DIFF_OPTIONS_INIT \
|
||||
{GIT_DIFF_OPTIONS_VERSION, 0, GIT_SUBMODULE_IGNORE_DEFAULT, {NULL,0}, NULL, NULL, 3}
|
||||
|
||||
/**
|
||||
* Initializes a `git_diff_options` with default values. Equivalent to
|
||||
* creating an instance with GIT_DIFF_OPTIONS_INIT.
|
||||
*
|
||||
* @param opts the `git_diff_options` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_DIFF_OPTIONS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_init_options(
|
||||
git_diff_options* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* When iterating over a diff, callback that will be made per file.
|
||||
*
|
||||
@ -604,6 +617,19 @@ typedef struct {
|
||||
#define GIT_DIFF_FIND_OPTIONS_VERSION 1
|
||||
#define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_diff_find_options` with default values. Equivalent to
|
||||
* creating an instance with GIT_DIFF_FIND_OPTIONS_INIT.
|
||||
*
|
||||
* @param opts the `git_diff_find_options` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_DIFF_FIND_OPTIONS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_diff_find_init_options(
|
||||
git_diff_find_options* opts,
|
||||
int version);
|
||||
|
||||
/** @name Diff Generator Functions
|
||||
*
|
||||
* These are the functions you would use to create (or destroy) a
|
||||
|
@ -104,6 +104,18 @@ typedef struct {
|
||||
#define GIT_MERGE_TREE_OPTS_VERSION 1
|
||||
#define GIT_MERGE_TREE_OPTS_INIT {GIT_MERGE_TREE_OPTS_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_merge_tree_opts` with default values. Equivalent to
|
||||
* creating an instance with GIT_MERGE_TREE_OPTS_INIT.
|
||||
*
|
||||
* @param opts the `git_merge_tree_opts` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_MERGE_TREE_OPTS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_merge_tree_init_opts(
|
||||
git_merge_tree_opts* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Option flags for `git_merge`.
|
||||
@ -144,6 +156,18 @@ typedef struct {
|
||||
#define GIT_MERGE_OPTS_VERSION 1
|
||||
#define GIT_MERGE_OPTS_INIT {GIT_MERGE_OPTS_VERSION, 0, GIT_MERGE_TREE_OPTS_INIT, GIT_CHECKOUT_OPTS_INIT}
|
||||
|
||||
/**
|
||||
* Initializes a `git_merge_opts` with default values. Equivalent to creating
|
||||
* an instance with GIT_MERGE_OPTS_INIT.
|
||||
*
|
||||
* @param opts the `git_merge_opts` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_MERGE_OPTS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_merge_init_opts(
|
||||
git_merge_opts* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Find a merge base between two commits
|
||||
|
@ -39,6 +39,19 @@ typedef struct {
|
||||
#define GIT_PUSH_OPTIONS_VERSION 1
|
||||
#define GIT_PUSH_OPTIONS_INIT { GIT_PUSH_OPTIONS_VERSION }
|
||||
|
||||
/**
|
||||
* Initializes a `git_push_options` with default values. Equivalent to
|
||||
* creating an instance with GIT_PUSH_OPTIONS_INIT.
|
||||
*
|
||||
* @param opts the `git_push_options` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_PUSH_OPTIONS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_push_init_options(
|
||||
git_push_options* opts,
|
||||
int version);
|
||||
|
||||
/** Push network progress notification function */
|
||||
typedef int (*git_push_transfer_progress)(
|
||||
unsigned int current,
|
||||
|
@ -494,6 +494,19 @@ struct git_remote_callbacks {
|
||||
#define GIT_REMOTE_CALLBACKS_VERSION 1
|
||||
#define GIT_REMOTE_CALLBACKS_INIT {GIT_REMOTE_CALLBACKS_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_remote_callbacks` with default values. Equivalent to
|
||||
* creating an instance with GIT_REMOTE_CALLBACKS_INIT.
|
||||
*
|
||||
* @param opts the `git_remote_callbacks` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_REMOTE_CALLBACKS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_remote_init_callbacks(
|
||||
git_remote_callbacks* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Set the callbacks for a remote
|
||||
*
|
||||
|
@ -267,6 +267,19 @@ typedef struct {
|
||||
#define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1
|
||||
#define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_repository_init_options` with default values. Equivalent
|
||||
* to creating an instance with GIT_REPOSITORY_INIT_OPTIONS_INIT.
|
||||
*
|
||||
* @param opts the `git_repository_init_options` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_REPOSITORY_INIT_OPTIONS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_repository_init_init_options(
|
||||
git_repository_init_options* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Create a new Git repository in the given folder with extended controls.
|
||||
*
|
||||
|
@ -33,6 +33,19 @@ typedef struct {
|
||||
#define GIT_REVERT_OPTS_VERSION 1
|
||||
#define GIT_REVERT_OPTS_INIT {GIT_REVERT_OPTS_VERSION, 0, GIT_MERGE_TREE_OPTS_INIT, GIT_CHECKOUT_OPTS_INIT}
|
||||
|
||||
/**
|
||||
* Initializes a `git_revert_opts` with default values. Equivalent to
|
||||
* creating an instance with GIT_REVERT_OPTS_INIT.
|
||||
*
|
||||
* @param opts the `git_revert_opts` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_REVERT_OPTS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_revert_init_opts(
|
||||
git_revert_opts* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Reverts the given commit against the given "our" commit, producing an
|
||||
* index that reflects the result of the revert.
|
||||
|
@ -174,6 +174,19 @@ typedef struct {
|
||||
#define GIT_STATUS_OPTIONS_VERSION 1
|
||||
#define GIT_STATUS_OPTIONS_INIT {GIT_STATUS_OPTIONS_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_status_options` with default values. Equivalent to
|
||||
* creating an instance with GIT_STATUS_OPTIONS_INIT.
|
||||
*
|
||||
* @param opts the `git_status_options` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_STATUS_OPTIONS_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_status_init_options(
|
||||
git_status_options* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* A status entry, providing the differences between the file as it exists
|
||||
* in HEAD and the index, and providing the differences between the index
|
||||
|
@ -69,6 +69,19 @@ struct git_config_backend {
|
||||
#define GIT_CONFIG_BACKEND_VERSION 1
|
||||
#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_config_backend` with default values. Equivalent to
|
||||
* creating an instance with GIT_CONFIG_BACKEND_INIT.
|
||||
*
|
||||
* @param opts the `git_config_backend` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_CONFIG_BACKEND_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_config_init_backend(
|
||||
git_config_backend* backend,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Add a generic config file instance to an existing config
|
||||
*
|
||||
|
@ -89,6 +89,19 @@ struct git_odb_backend {
|
||||
#define GIT_ODB_BACKEND_VERSION 1
|
||||
#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_odb_backend` with default values. Equivalent to
|
||||
* creating an instance with GIT_ODB_BACKEND_INIT.
|
||||
*
|
||||
* @param opts the `git_odb_backend` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_ODB_BACKEND_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_odb_init_backend(
|
||||
git_odb_backend* backend,
|
||||
int version);
|
||||
|
||||
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
|
||||
|
||||
GIT_END_DECL
|
||||
|
@ -158,6 +158,19 @@ struct git_refdb_backend {
|
||||
#define GIT_REFDB_BACKEND_VERSION 1
|
||||
#define GIT_REFDB_BACKEND_INIT {GIT_REFDB_BACKEND_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_refdb_backend` with default values. Equivalent to
|
||||
* creating an instance with GIT_REFDB_BACKEND_INIT.
|
||||
*
|
||||
* @param opts the `git_refdb_backend` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_REFDB_BACKEND_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_refdb_init_backend(
|
||||
git_refdb_backend* backend,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Constructors for default filesystem-based refdb backend
|
||||
*
|
||||
|
@ -279,6 +279,19 @@ struct git_transport {
|
||||
#define GIT_TRANSPORT_VERSION 1
|
||||
#define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION}
|
||||
|
||||
/**
|
||||
* Initializes a `git_transport` with default values. Equivalent to
|
||||
* creating an instance with GIT_TRANSPORT_INIT.
|
||||
*
|
||||
* @param opts the `git_transport` instance to initialize.
|
||||
* @param version the version of the struct; you should pass
|
||||
* `GIT_TRANSPORT_VERSION` here.
|
||||
* @return Zero on success; -1 on failure.
|
||||
*/
|
||||
GIT_EXTERN(int) git_transport_init(
|
||||
git_transport* opts,
|
||||
int version);
|
||||
|
||||
/**
|
||||
* Function to use to create a transport from a URL. The transport database
|
||||
* is scanned to find a transport that implements the scheme of the URI (i.e.
|
||||
|
12
src/blame.c
12
src/blame.c
@ -476,3 +476,15 @@ int git_blame_buffer(
|
||||
*out = blame;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int git_blame_init_options(git_blame_options* opts, int version)
|
||||
{
|
||||
if (version != GIT_BLAME_OPTIONS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_blame_options", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_blame_options o = GIT_BLAME_OPTIONS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -2194,3 +2194,15 @@ int git_checkout_head(
|
||||
assert(repo);
|
||||
return git_checkout_tree(repo, NULL, opts);
|
||||
}
|
||||
|
||||
int git_checkout_init_opts(git_checkout_opts* opts, int version)
|
||||
{
|
||||
if (version != GIT_CHECKOUT_OPTS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_checkout_opts", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_checkout_opts o = GIT_CHECKOUT_OPTS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
12
src/clone.c
12
src/clone.c
@ -439,3 +439,15 @@ int git_clone(
|
||||
*out = repo;
|
||||
return error;
|
||||
}
|
||||
|
||||
int git_clone_init_options(git_clone_options* opts, int version)
|
||||
{
|
||||
if (version != GIT_CLONE_OPTIONS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_clone_options", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_clone_options o = GIT_CLONE_OPTIONS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
12
src/config.c
12
src/config.c
@ -1245,3 +1245,15 @@ cleanup:
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int git_config_init_backend(git_config_backend* backend, int version)
|
||||
{
|
||||
if (version != GIT_CONFIG_BACKEND_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_config_backend", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_config_backend b = GIT_CONFIG_BACKEND_INIT;
|
||||
memcpy(backend, &b, sizeof(b));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
24
src/diff.c
24
src/diff.c
@ -1413,3 +1413,27 @@ int git_diff__paired_foreach(
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int git_diff_init_options(git_diff_options* opts, int version)
|
||||
{
|
||||
if (version != GIT_DIFF_OPTIONS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_options", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_diff_options o = GIT_DIFF_OPTIONS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int git_diff_find_init_options(git_diff_find_options* opts, int version)
|
||||
{
|
||||
if (version != GIT_DIFF_FIND_OPTIONS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_find_options", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_diff_find_options o = GIT_DIFF_FIND_OPTIONS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
24
src/merge.c
24
src/merge.c
@ -2744,3 +2744,27 @@ void git_merge_head_free(git_merge_head *head)
|
||||
|
||||
git__free(head);
|
||||
}
|
||||
|
||||
int git_merge_init_opts(git_merge_opts* opts, int version)
|
||||
{
|
||||
if (version != GIT_MERGE_OPTS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_merge_opts", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_merge_opts o = GIT_MERGE_OPTS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int git_merge_tree_init_opts(git_merge_tree_opts* opts, int version)
|
||||
{
|
||||
if (version != GIT_MERGE_TREE_OPTS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_merge_tree_opts", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_merge_tree_opts o = GIT_MERGE_TREE_OPTS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
11
src/odb.c
11
src/odb.c
@ -1113,3 +1113,14 @@ int git_odb__error_ambiguous(const char *message)
|
||||
return GIT_EAMBIGUOUS;
|
||||
}
|
||||
|
||||
int git_odb_init_backend(git_odb_backend* backend, int version)
|
||||
{
|
||||
if (version != GIT_ODB_BACKEND_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_odb_backend", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_odb_backend b = GIT_ODB_BACKEND_INIT;
|
||||
memcpy(backend, &b, sizeof(b));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
12
src/push.c
12
src/push.c
@ -705,3 +705,15 @@ void git_push_free(git_push *push)
|
||||
|
||||
git__free(push);
|
||||
}
|
||||
|
||||
int git_push_init_options(git_push_options* opts, int version)
|
||||
{
|
||||
if (version != GIT_PUSH_OPTIONS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_push_options", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_push_options o = GIT_PUSH_OPTIONS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
12
src/refdb.c
12
src/refdb.c
@ -235,3 +235,15 @@ int git_refdb_ensure_log(git_refdb *db, const char *refname)
|
||||
|
||||
return db->backend->ensure_log(db->backend, refname);
|
||||
}
|
||||
|
||||
int git_refdb_init_backend(git_refdb_backend* backend, int version)
|
||||
{
|
||||
if (version != GIT_REFDB_BACKEND_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_refdb_backend", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_refdb_backend b = GIT_REFDB_BACKEND_INIT;
|
||||
memcpy(backend, &b, sizeof(b));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
12
src/remote.c
12
src/remote.c
@ -1731,3 +1731,15 @@ const git_refspec *git_remote_get_refspec(const git_remote *remote, size_t n)
|
||||
{
|
||||
return git_vector_get(&remote->refspecs, n);
|
||||
}
|
||||
|
||||
int git_remote_init_callbacks(git_remote_callbacks* opts, int version)
|
||||
{
|
||||
if (version != GIT_REMOTE_CALLBACKS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_remote_callbacks", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_remote_callbacks o = GIT_REMOTE_CALLBACKS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -2010,3 +2010,15 @@ int git_repository_is_shallow(git_repository *repo)
|
||||
return error;
|
||||
return st.st_size == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
int git_repository_init_init_options(git_repository_init_options* opts, int version)
|
||||
{
|
||||
if (version != GIT_REPOSITORY_INIT_OPTIONS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_repository_init_options", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_repository_init_options o = GIT_REPOSITORY_INIT_OPTIONS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
12
src/revert.c
12
src/revert.c
@ -218,3 +218,15 @@ done:
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int git_revert_init_opts(git_revert_opts* opts, int version)
|
||||
{
|
||||
if (version != GIT_REVERT_OPTS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_revert_opts", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_revert_opts o = GIT_REVERT_OPTS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
11
src/status.c
11
src/status.c
@ -495,3 +495,14 @@ int git_status_should_ignore(
|
||||
return git_ignore_path_is_ignored(ignored, repo, path);
|
||||
}
|
||||
|
||||
int git_status_init_options(git_status_options* opts, int version)
|
||||
{
|
||||
if (version != GIT_STATUS_OPTIONS_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_status_options", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_status_options o = GIT_STATUS_OPTIONS_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -217,3 +217,15 @@ int git_remote_supported_url(const char* url)
|
||||
|
||||
return fn != &git_transport_dummy;
|
||||
}
|
||||
|
||||
int git_transport_init(git_transport* opts, int version)
|
||||
{
|
||||
if (version != GIT_TRANSPORT_VERSION) {
|
||||
giterr_set(GITERR_INVALID, "Invalid version %d for git_transport", version);
|
||||
return -1;
|
||||
} else {
|
||||
git_transport o = GIT_TRANSPORT_INIT;
|
||||
memcpy(opts, &o, sizeof(o));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
120
tests/structinit/structinit.c
Normal file
120
tests/structinit/structinit.c
Normal file
@ -0,0 +1,120 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include <git2/sys/config.h>
|
||||
#include <git2/sys/odb_backend.h>
|
||||
#include <git2/sys/refdb_backend.h>
|
||||
|
||||
#define STRINGIFY(s) #s
|
||||
|
||||
/* Checks two conditions for the specified structure:
|
||||
* 1. That the initializers for the latest version produces the same
|
||||
* in-memory representation.
|
||||
* 2. That the function-based initializer supports all versions from 1...n,
|
||||
* where n is the latest version (often represented by GIT_*_VERSION).
|
||||
*
|
||||
* Parameters:
|
||||
* structname: The name of the structure to test, e.g. git_blame_options.
|
||||
* structver: The latest version of the specified structure.
|
||||
* macroinit: The macro that initializes the latest version of the structure.
|
||||
* funcinitname: The function that initializes the structure. Must have the
|
||||
* signature "int (structname* instance, int version)".
|
||||
*/
|
||||
#define CHECK_MACRO_FUNC_INIT_EQUAL(structname, structver, macroinit, funcinitname) \
|
||||
structname structname##_macro_latest = macroinit; \
|
||||
structname structname##_func_latest; \
|
||||
cl_git_pass(funcinitname(&structname##_func_latest, structver)); \
|
||||
cl_check_( \
|
||||
memcmp(&structname##_macro_latest, &structname##_func_latest, \
|
||||
sizeof(structname)) == 0, \
|
||||
"Macro-based and function-based initializer for " STRINGIFY(structname) \
|
||||
" are not equivalent."); \
|
||||
\
|
||||
int structname##_curr_ver = structver - 1; \
|
||||
while (structname##_curr_ver > 0) \
|
||||
{ \
|
||||
structname macro; \
|
||||
cl_git_pass(funcinitname(¯o, structname##_curr_ver)); \
|
||||
structname##_curr_ver--; \
|
||||
}
|
||||
|
||||
void test_structinit_structinit__compare(void)
|
||||
{
|
||||
/* blame */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_blame_options, GIT_BLAME_OPTIONS_VERSION, \
|
||||
GIT_BLAME_OPTIONS_INIT, git_blame_init_options);
|
||||
|
||||
/* checkout */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_checkout_opts, GIT_CHECKOUT_OPTS_VERSION, \
|
||||
GIT_CHECKOUT_OPTS_INIT, git_checkout_init_opts);
|
||||
|
||||
/* clone */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_clone_options, GIT_CLONE_OPTIONS_VERSION, \
|
||||
GIT_CLONE_OPTIONS_INIT, git_clone_init_options);
|
||||
|
||||
/* diff */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_diff_options, GIT_DIFF_OPTIONS_VERSION, \
|
||||
GIT_DIFF_OPTIONS_INIT, git_diff_init_options);
|
||||
|
||||
/* diff_find */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_diff_find_options, GIT_DIFF_FIND_OPTIONS_VERSION, \
|
||||
GIT_DIFF_FIND_OPTIONS_INIT, git_diff_find_init_options);
|
||||
|
||||
/* merge_tree */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_merge_tree_opts, GIT_MERGE_TREE_OPTS_VERSION, \
|
||||
GIT_MERGE_TREE_OPTS_INIT, git_merge_tree_init_opts);
|
||||
|
||||
/* merge */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_merge_opts, GIT_MERGE_OPTS_VERSION, \
|
||||
GIT_MERGE_OPTS_INIT, git_merge_init_opts);
|
||||
|
||||
/* push */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_push_options, GIT_PUSH_OPTIONS_VERSION, \
|
||||
GIT_PUSH_OPTIONS_INIT, git_push_init_options);
|
||||
|
||||
/* remote */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_remote_callbacks, GIT_REMOTE_CALLBACKS_VERSION, \
|
||||
GIT_REMOTE_CALLBACKS_INIT, git_remote_init_callbacks);
|
||||
|
||||
/* repository_init */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_repository_init_options, GIT_REPOSITORY_INIT_OPTIONS_VERSION, \
|
||||
GIT_REPOSITORY_INIT_OPTIONS_INIT, git_repository_init_init_options);
|
||||
|
||||
/* revert */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_revert_opts, GIT_REVERT_OPTS_VERSION, \
|
||||
GIT_REVERT_OPTS_INIT, git_revert_init_opts);
|
||||
|
||||
/* status */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_status_options, GIT_STATUS_OPTIONS_VERSION, \
|
||||
GIT_STATUS_OPTIONS_INIT, git_status_init_options);
|
||||
|
||||
/* transport */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_transport, GIT_TRANSPORT_VERSION, \
|
||||
GIT_TRANSPORT_INIT, git_transport_init);
|
||||
|
||||
/* config_backend */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_config_backend, GIT_CONFIG_BACKEND_VERSION, \
|
||||
GIT_CONFIG_BACKEND_INIT, git_config_init_backend);
|
||||
|
||||
/* odb_backend */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_odb_backend, GIT_ODB_BACKEND_VERSION, \
|
||||
GIT_ODB_BACKEND_INIT, git_odb_init_backend);
|
||||
|
||||
/* refdb_backend */
|
||||
CHECK_MACRO_FUNC_INIT_EQUAL( \
|
||||
git_refdb_backend, GIT_REFDB_BACKEND_VERSION, \
|
||||
GIT_REFDB_BACKEND_INIT, git_refdb_init_backend);
|
||||
}
|
Loading…
Reference in New Issue
Block a user