Skip to content

Commit c868981

Browse files
calaveraEdward Thomson
authored andcommitted
Add extern function to initialize submodule update options.
1 parent 6a6c24e commit c868981

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

include/git2/submodule.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ typedef enum {
110110
/**
111111
* Submodule update options structure
112112
*
113-
* Use the GIT_SUBMODULE_UPDATE_OPTIONS_INIT to get the default settings, like this:
113+
* Use the GIT_SUBMODULE_UPDATE_OPTIONS_INIT to get the default settings,
114+
* like this:
114115
*
115-
* git_submodule_update_options opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
116+
* git_submodule_update_options opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
116117
*/
117118
typedef struct git_submodule_update_options {
118119
unsigned int version;
@@ -149,7 +150,21 @@ typedef struct git_submodule_update_options {
149150
} git_submodule_update_options;
150151

151152
#define GIT_SUBMODULE_UPDATE_OPTIONS_VERSION 1
152-
#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}
153+
#define GIT_SUBMODULE_UPDATE_OPTIONS_INIT \
154+
{ GIT_CHECKOUT_OPTIONS_VERSION, \
155+
{ GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE}, \
156+
GIT_REMOTE_CALLBACKS_INIT, GIT_CHECKOUT_SAFE_CREATE }
157+
158+
/**
159+
* Initializes a `git_submodule_update_options` with default values.
160+
* Equivalent to creating an instance with GIT_SUBMODULE_UPDATE_OPTIONS_INIT.
161+
*
162+
* @param opts The `git_submodule_update_options` instance to initialize.
163+
* @param version Version of struct; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`
164+
* @return Zero on success; -1 on failure.
165+
*/
166+
GIT_EXTERN(int) git_submodule_update_init_options(
167+
git_submodule_update_options *opts, unsigned int version);
153168

154169
/**
155170
* Update a submodule. This will clone a missing submodule and

src/submodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,13 @@ static int git_submodule_update_repo_init_cb(
898898
return submodule_repo_create(out, sm->repo, path);
899899
}
900900

901+
int git_submodule_update_init_options(git_submodule_update_options *opts, unsigned int version)
902+
{
903+
GIT_INIT_STRUCTURE_FROM_TEMPLATE(
904+
opts, version, git_submodule_update_options, GIT_SUBMODULE_UPDATE_OPTIONS_INIT);
905+
return 0;
906+
}
907+
901908
int git_submodule_update(git_submodule *sm, int init, git_submodule_update_options *_update_options)
902909
{
903910
int error;

tests/structinit/structinit.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,9 @@ void test_structinit_structinit__compare(void)
125125
CHECK_MACRO_FUNC_INIT_EQUAL( \
126126
git_refdb_backend, GIT_REFDB_BACKEND_VERSION, \
127127
GIT_REFDB_BACKEND_INIT, git_refdb_init_backend);
128+
129+
/* submodule update */
130+
CHECK_MACRO_FUNC_INIT_EQUAL( \
131+
git_submodule_update_options, GIT_SUBMODULE_UPDATE_OPTIONS_VERSION, \
132+
GIT_SUBMODULE_UPDATE_OPTIONS_INIT, git_submodule_update_init_options);
128133
}

0 commit comments

Comments
 (0)