Add extern function to initialize submodule update options.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/include/git2/submodule.h b/include/git2/submodule.h
index 31c68e3..f03ea2d 100644
--- a/include/git2/submodule.h
+++ b/include/git2/submodule.h
@@ -110,9 +110,10 @@ typedef enum {
/**
* Submodule update options structure
*
- * Use the GIT_SUBMODULE_UPDATE_OPTIONS_INIT to get the default settings, like this:
+ * Use the GIT_SUBMODULE_UPDATE_OPTIONS_INIT to get the default settings,
+ * like this:
*
- * git_submodule_update_options opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
+ * git_submodule_update_options opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
*/
typedef struct git_submodule_update_options {
unsigned int version;
@@ -149,7 +150,21 @@ typedef struct git_submodule_update_options {
} git_submodule_update_options;
#define GIT_SUBMODULE_UPDATE_OPTIONS_VERSION 1
-#define GIT_SUBMODULE_UPDATE_OPTIONS_INIT {GIT_CHECKOUT_OPTIONS_VERSION, {GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE}, GIT_REMOTE_CALLBACKS_INIT, GIT_CHECKOUT_SAFE_CREATE}
+#define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \
+ { GIT_CHECKOUT_OPTIONS_VERSION, \
+ { GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE}, \
+ GIT_REMOTE_CALLBACKS_INIT, GIT_CHECKOUT_SAFE_CREATE }
+
+/**
+ * Initializes a `git_submodule_update_options` with default values.
+ * Equivalent to creating an instance with GIT_SUBMODULE_UPDATE_OPTIONS_INIT.
+ *
+ * @param opts The `git_submodule_update_options` instance to initialize.
+ * @param version Version of struct; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`
+ * @return Zero on success; -1 on failure.
+ */
+GIT_EXTERN(int) git_submodule_update_init_options(
+ git_submodule_update_options *opts, unsigned int version);
/**
* Update a submodule. This will clone a missing submodule and
diff --git a/src/submodule.c b/src/submodule.c
index a7bdebe..03714b4 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -898,6 +898,13 @@ static int git_submodule_update_repo_init_cb(
return submodule_repo_create(out, sm->repo, path);
}
+int git_submodule_update_init_options(git_submodule_update_options *opts, unsigned int version)
+{
+ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
+ opts, version, git_submodule_update_options, GIT_SUBMODULE_UPDATE_OPTIONS_INIT);
+ return 0;
+}
+
int git_submodule_update(git_submodule *sm, int init, git_submodule_update_options *_update_options)
{
int error;
diff --git a/tests/structinit/structinit.c b/tests/structinit/structinit.c
index def9fef..0e00ab5 100644
--- a/tests/structinit/structinit.c
+++ b/tests/structinit/structinit.c
@@ -125,4 +125,9 @@ void test_structinit_structinit__compare(void)
CHECK_MACRO_FUNC_INIT_EQUAL( \
git_refdb_backend, GIT_REFDB_BACKEND_VERSION, \
GIT_REFDB_BACKEND_INIT, git_refdb_init_backend);
+
+ /* submodule update */
+ CHECK_MACRO_FUNC_INIT_EQUAL( \
+ git_submodule_update_options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, \
+ GIT_SUBMODULE_UPDATE_OPTIONS_INIT, git_submodule_update_init_options);
}