summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-04-30 11:16:31 -0700
committerRussell Belfer <rb@github.com>2014-04-30 11:16:31 -0700
commit8655a8985bcf2891390d464401b198d629edbfc3 (patch)
tree342130ee269448aa7b31c37f56df9d2b02f63abb
parenta4f9e1f0d41a9c78b304d3c1b8ef5270c30b208f (diff)
downloadlibgit2-rb/diff-update-index-stat-cache.tar.gz
Fix remaining init_options inconsistenciesrb/diff-update-index-stat-cache
There were a couple of "init_opts()" functions a few more cases of structure initialization that I somehow missed.
-rw-r--r--include/git2/checkout.h11
-rw-r--r--include/git2/cherrypick.h11
-rw-r--r--include/git2/remote.h9
-rw-r--r--include/git2/revert.h11
-rw-r--r--include/git2/sys/config.h9
-rw-r--r--include/git2/sys/odb_backend.h9
-rw-r--r--include/git2/sys/refdb_backend.h9
-rw-r--r--include/git2/transport.h9
-rw-r--r--src/checkout.c13
-rw-r--r--src/cherrypick.c14
-rw-r--r--src/config.c13
-rw-r--r--src/diff.c11
-rw-r--r--src/odb.c13
-rw-r--r--src/refdb.c13
-rw-r--r--src/remote.c13
-rw-r--r--src/revert.c13
-rw-r--r--src/status.c7
-rw-r--r--src/transport.c13
-rw-r--r--tests/structinit/structinit.c4
19 files changed, 74 insertions, 131 deletions
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index 69addb7d9..494f67456 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -270,14 +270,13 @@ typedef struct git_checkout_options {
* Initializes a `git_checkout_options` with default values. Equivalent to
* creating an instance with GIT_CHECKOUT_OPTIONS_INIT.
*
-* @param opts the `git_checkout_options` instance to initialize.
-* @param version the version of the struct; you should pass
-* `GIT_CHECKOUT_OPTIONS_VERSION` here.
+* @param opts the `git_checkout_options` struct to initialize.
+* @param version Version of struct; pass `GIT_CHECKOUT_OPTIONS_VERSION`
* @return Zero on success; -1 on failure.
*/
-GIT_EXTERN(int) git_checkout_init_opts(
- git_checkout_options* opts,
- int version);
+GIT_EXTERN(int) git_checkout_init_options(
+ git_checkout_options *opts,
+ unsigned int version);
/**
* Updates files in the index and the working tree to match the content of
diff --git a/include/git2/cherrypick.h b/include/git2/cherrypick.h
index 7c48e6659..e998d325f 100644
--- a/include/git2/cherrypick.h
+++ b/include/git2/cherrypick.h
@@ -37,14 +37,13 @@ typedef struct {
* Initializes a `git_cherry_pick_options` with default values. Equivalent to
* creating an instance with GIT_CHERRY_PICK_OPTIONS_INIT.
*
- * @param opts the `git_cherry_pick_options` instance to initialize.
- * @param version the version of the struct; you should pass
- * `GIT_CHERRY_PICK_OPTIONS_VERSION` here.
+ * @param opts the `git_cherry_pick_options` struct to initialize
+ * @param version Version of struct; pass `GIT_CHERRY_PICK_OPTIONS_VERSION`
* @return Zero on success; -1 on failure.
*/
-GIT_EXTERN(int) git_cherry_pick_init_opts(
- git_cherry_pick_options* opts,
- int version);
+GIT_EXTERN(int) git_cherry_pick_init_options(
+ git_cherry_pick_options *opts,
+ unsigned int version);
/**
* Cherry-picks the given commit against the given "our" commit, producing an
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 11e1e26d0..3633501e2 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -501,14 +501,13 @@ struct git_remote_callbacks {
* 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.
+ * @param opts the `git_remote_callbacks` struct to initialize
+ * @param version Version of struct; pass `GIT_REMOTE_CALLBACKS_VERSION`
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_remote_init_callbacks(
- git_remote_callbacks* opts,
- int version);
+ git_remote_callbacks *opts,
+ unsigned int version);
/**
* Set the callbacks for a remote
diff --git a/include/git2/revert.h b/include/git2/revert.h
index 3a6beb6b8..da37fbe7b 100644
--- a/include/git2/revert.h
+++ b/include/git2/revert.h
@@ -37,14 +37,13 @@ typedef struct {
* Initializes a `git_revert_options` with default values. Equivalent to
* creating an instance with GIT_REVERT_OPTIONS_INIT.
*
- * @param opts the `git_revert_options` instance to initialize.
- * @param version the version of the struct; you should pass
- * `GIT_REVERT_OPTIONS_VERSION` here.
+ * @param opts the `git_revert_options` struct to initialize
+ * @param version Version of struct; pass `GIT_REVERT_OPTIONS_VERSION`
* @return Zero on success; -1 on failure.
*/
-GIT_EXTERN(int) git_revert_init_opts(
- git_revert_options* opts,
- int version);
+GIT_EXTERN(int) git_revert_init_options(
+ git_revert_options *opts,
+ unsigned int version);
/**
* Reverts the given commit against the given "our" commit, producing an
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index 3df2ba327..46bb65293 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -73,14 +73,13 @@ struct git_config_backend {
* 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.
+ * @param opts the `git_config_backend` struct to initialize.
+ * @param version Version of struct; pass `GIT_CONFIG_BACKEND_VERSION`
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_config_init_backend(
- git_config_backend* backend,
- int version);
+ git_config_backend *backend,
+ unsigned int version);
/**
* Add a generic config file instance to an existing config
diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h
index 77fe0dd31..1fc3c3159 100644
--- a/include/git2/sys/odb_backend.h
+++ b/include/git2/sys/odb_backend.h
@@ -93,14 +93,13 @@ struct git_odb_backend {
* 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.
+ * @param opts the `git_odb_backend` struct to initialize.
+ * @param version Version the struct; pass `GIT_ODB_BACKEND_VERSION`
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_odb_init_backend(
- git_odb_backend* backend,
- int version);
+ git_odb_backend *backend,
+ unsigned int version);
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h
index dce142c77..3b216a287 100644
--- a/include/git2/sys/refdb_backend.h
+++ b/include/git2/sys/refdb_backend.h
@@ -162,14 +162,13 @@ struct git_refdb_backend {
* 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.
+ * @param opts the `git_refdb_backend` struct to initialize
+ * @param version Version of struct; pass `GIT_REFDB_BACKEND_VERSION`
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_refdb_init_backend(
- git_refdb_backend* backend,
- int version);
+ git_refdb_backend *backend,
+ unsigned int version);
/**
* Constructors for default filesystem-based refdb backend
diff --git a/include/git2/transport.h b/include/git2/transport.h
index a33146ca8..af7812b5d 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -314,14 +314,13 @@ struct git_transport {
* 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.
+ * @param opts the `git_transport` struct to initialize
+ * @param version Version of struct; pass `GIT_TRANSPORT_VERSION`
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_transport_init(
- git_transport* opts,
- int version);
+ git_transport *opts,
+ unsigned int version);
/**
* Function to use to create a transport from a URL. The transport database
diff --git a/src/checkout.c b/src/checkout.c
index 727911694..b869efe2b 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -2240,14 +2240,9 @@ int git_checkout_head(
return git_checkout_tree(repo, NULL, opts);
}
-int git_checkout_init_opts(git_checkout_options* opts, int version)
+int git_checkout_init_options(git_checkout_options *opts, unsigned int version)
{
- if (version != GIT_CHECKOUT_OPTIONS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_checkout_options", version);
- return -1;
- } else {
- git_checkout_options o = GIT_CHECKOUT_OPTIONS_INIT;
- memcpy(opts, &o, sizeof(o));
- return 0;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_checkout_options, GIT_CHECKOUT_OPTIONS_INIT);
+ return 0;
}
diff --git a/src/cherrypick.c b/src/cherrypick.c
index 6a5ca834c..e02348a03 100644
--- a/src/cherrypick.c
+++ b/src/cherrypick.c
@@ -217,14 +217,10 @@ done:
return error;
}
-int git_cherry_pick_init_opts(git_cherry_pick_options* opts, int version)
+int git_cherry_pick_init_options(
+ git_cherry_pick_options *opts, unsigned int version)
{
- if (version != GIT_CHERRY_PICK_OPTIONS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_cherry_pick_options", version);
- return -1;
- } else {
- git_cherry_pick_options o = GIT_CHERRY_PICK_OPTIONS_INIT;
- memcpy(opts, &o, sizeof(o));
- return 0;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_cherry_pick_options, GIT_CHERRY_PICK_OPTIONS_INIT);
+ return 0;
}
diff --git a/src/config.c b/src/config.c
index b3168f735..ffc3bca29 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1276,14 +1276,9 @@ cleanup:
return error;
}
-int git_config_init_backend(git_config_backend* backend, int version)
+int git_config_init_backend(git_config_backend *backend, unsigned 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;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ backend, version, git_config_backend, GIT_CONFIG_BACKEND_INIT);
+ return 0;
}
diff --git a/src/diff.c b/src/diff.c
index 56f333f76..781f23ec6 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1310,17 +1310,10 @@ int git_diff_is_sorted_icase(const git_diff *diff)
return (diff->opts.flags & GIT_DIFF_IGNORE_CASE) != 0;
}
-static int diff_options_bad_version(int version, const char *thing)
-{
- giterr_set(GITERR_INVALID, "Invalid version %d for %s", version, thing);
- return -1;
-}
-
int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
{
- if (!out || out->version != GIT_DIFF_PERFDATA_VERSION)
- return diff_options_bad_version(
- out ? out->version : 0, "git_diff_perfdata");
+ assert(out);
+ GITERR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata");
out->stat_calls = diff->perf.stat_calls;
out->oid_calculations = diff->perf.oid_calculations;
return 0;
diff --git a/src/odb.c b/src/odb.c
index 00740d2e2..20a3f6c6e 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -1123,14 +1123,9 @@ int git_odb__error_ambiguous(const char *message)
return GIT_EAMBIGUOUS;
}
-int git_odb_init_backend(git_odb_backend* backend, int version)
+int git_odb_init_backend(git_odb_backend *backend, unsigned 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;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ backend, version, git_odb_backend, GIT_ODB_BACKEND_INIT);
+ return 0;
}
diff --git a/src/refdb.c b/src/refdb.c
index 3e7a592f8..69bf74734 100644
--- a/src/refdb.c
+++ b/src/refdb.c
@@ -236,14 +236,9 @@ 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)
+int git_refdb_init_backend(git_refdb_backend *backend, unsigned 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;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ backend, version, git_refdb_backend, GIT_REFDB_BACKEND_INIT);
+ return 0;
}
diff --git a/src/remote.c b/src/remote.c
index ea638e373..e43f31dd1 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1736,14 +1736,9 @@ 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)
+int git_remote_init_callbacks(git_remote_callbacks *opts, unsigned 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;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_remote_callbacks, GIT_REMOTE_CALLBACKS_INIT);
+ return 0;
}
diff --git a/src/revert.c b/src/revert.c
index 29e124f6c..9c587724b 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -220,14 +220,9 @@ done:
return error;
}
-int git_revert_init_opts(git_revert_options* opts, int version)
+int git_revert_init_options(git_revert_options *opts, unsigned int version)
{
- if (version != GIT_REVERT_OPTIONS_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_revert_options", version);
- return -1;
- } else {
- git_revert_options o = GIT_REVERT_OPTIONS_INIT;
- memcpy(opts, &o, sizeof(o));
- return 0;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_revert_options, GIT_REVERT_OPTIONS_INIT);
+ return 0;
}
diff --git a/src/status.c b/src/status.c
index bcc2692d2..8d7612f72 100644
--- a/src/status.c
+++ b/src/status.c
@@ -528,11 +528,8 @@ int git_status_init_options(git_status_options *opts, unsigned int version)
int git_status_list_get_perfdata(
git_diff_perfdata *out, const git_status_list *status)
{
- if (!out || out->version != GIT_DIFF_PERFDATA_VERSION) {
- giterr_set(GITERR_INVALID, "Invalid version %d for git_diff_perfdata",
- out ? out->version : 0);
- return -1;
- }
+ assert(out);
+ GITERR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata");
out->stat_calls = 0;
out->oid_calculations = 0;
diff --git a/src/transport.c b/src/transport.c
index dc074a503..2194b1864 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -218,14 +218,9 @@ int git_remote_supported_url(const char* url)
return fn != &git_transport_dummy;
}
-int git_transport_init(git_transport* opts, int version)
+int git_transport_init(git_transport *opts, unsigned 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;
- }
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_transport, GIT_TRANSPORT_INIT);
+ return 0;
}
diff --git a/tests/structinit/structinit.c b/tests/structinit/structinit.c
index 2942099dd..38bedada7 100644
--- a/tests/structinit/structinit.c
+++ b/tests/structinit/structinit.c
@@ -48,7 +48,7 @@ void test_structinit_structinit__compare(void)
/* checkout */
CHECK_MACRO_FUNC_INIT_EQUAL( \
git_checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, \
- GIT_CHECKOUT_OPTIONS_INIT, git_checkout_init_opts);
+ GIT_CHECKOUT_OPTIONS_INIT, git_checkout_init_options);
/* clone */
CHECK_MACRO_FUNC_INIT_EQUAL( \
@@ -98,7 +98,7 @@ void test_structinit_structinit__compare(void)
/* revert */
CHECK_MACRO_FUNC_INIT_EQUAL( \
git_revert_options, GIT_REVERT_OPTIONS_VERSION, \
- GIT_REVERT_OPTIONS_INIT, git_revert_init_opts);
+ GIT_REVERT_OPTIONS_INIT, git_revert_init_options);
/* status */
CHECK_MACRO_FUNC_INIT_EQUAL( \