Skip to content

Commit 7a3e8fb

Browse files
committed
handle array options in remote
1 parent a54147a commit 7a3e8fb

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

git2_php_util.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,12 @@ void git2_parse_remote_callbacks(git_remote_callbacks *opts, HashTable *ht) {
133133
ARRAY_FETCH_CALLBACK(transport, payload);
134134
}
135135

136+
void git2_parse_push_options(git_push_options *opts, HashTable *ht) {
137+
zval *data;
138+
if (ht == NULL) return;
139+
140+
ARRAY_FETCH_LONG(pb_parallelism);
141+
ARRAY_FETCH_OPTIONS(callbacks, git2_parse_remote_callbacks);
142+
ARRAY_FETCH_STRARRAY(custom_headers);
143+
}
144+

git2_php_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ void git2_parse_clone_options(git_clone_options *opts, HashTable *ht);
99
void git2_parse_checkout_options(git_checkout_options *opts, HashTable *ht);
1010
void git2_parse_fetch_options(git_fetch_options *opts, HashTable *ht);
1111
void git2_parse_remote_callbacks(git_remote_callbacks *opts, HashTable *ht);
12+
void git2_parse_push_options(git_push_options *opts, HashTable *ht);
1213

1314
#endif /* GIT2_PHP_UTIL_H */

git2_remote.c

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "git2_exception.h"
33
#include "git2_remote.h"
44
#include "git2_repository.h"
5+
#include "git2_php_util.h"
56

67
static zend_class_entry *php_git2_remote_ce;
78
static zend_object_handlers php_git2_remote_handler;
@@ -193,18 +194,22 @@ static PHP_METHOD(Remote, disconnect) {
193194

194195
ZEND_BEGIN_ARG_INFO_EX(arginfo_remote_download, 0, 0, 0)
195196
ZEND_ARG_INFO(0, refspecs)
197+
ZEND_ARG_INFO(0, opts)
196198
ZEND_END_ARG_INFO()
197199

198200
static PHP_METHOD(Remote, download) {
199201
HashTable *refspecs = NULL;
202+
HashTable *opts = NULL;
200203

201-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &refspecs) != SUCCESS) {
204+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|aa", &refspecs, &opts) != SUCCESS) {
202205
return;
203206
}
204207

205208
GIT2_REMOTE_FETCH();
206-
// TODO add git_fetch_options handling
209+
207210
git_fetch_options git_opts = GIT_FETCH_OPTIONS_INIT;
211+
git2_parse_fetch_options(&git_opts, opts);
212+
208213
git_strarray git_refspecs;
209214
git_refspecs.count = 0;
210215

@@ -223,18 +228,22 @@ static PHP_METHOD(Remote, download) {
223228

224229
ZEND_BEGIN_ARG_INFO_EX(arginfo_remote_fetch, 0, 0, 0)
225230
ZEND_ARG_INFO(0, refspecs)
231+
ZEND_ARG_INFO(0, opts)
226232
ZEND_END_ARG_INFO()
227233

228234
static PHP_METHOD(Remote, fetch) {
229235
HashTable *refspecs = NULL;
236+
HashTable *opts = NULL;
230237

231-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &refspecs) != SUCCESS) {
238+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|aa", &refspecs, &opts) != SUCCESS) {
232239
return;
233240
}
234241

235242
GIT2_REMOTE_FETCH();
236-
// TODO add git_fetch_options handling and reflog_message
243+
237244
git_fetch_options git_opts = GIT_FETCH_OPTIONS_INIT;
245+
git2_parse_fetch_options(&git_opts, opts);
246+
238247
git_strarray git_refspecs;
239248
git_refspecs.count = 0;
240249

@@ -254,14 +263,29 @@ static PHP_METHOD(Remote, fetch) {
254263
}
255264

256265
ZEND_BEGIN_ARG_INFO_EX(arginfo_remote_upload, 0, 0, 0)
266+
ZEND_ARG_INFO(0, refspecs)
267+
ZEND_ARG_INFO(0, opts)
257268
ZEND_END_ARG_INFO()
258269

259270
static PHP_METHOD(Remote, upload) {
260-
if (zend_parse_parameters_none() == FAILURE) return;
271+
HashTable *refspecs = NULL;
272+
HashTable *opts = NULL;
273+
274+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|aa", &refspecs, &opts) != SUCCESS) {
275+
return;
276+
}
261277
GIT2_REMOTE_FETCH();
262-
// TODO add git_push_options handling
263278

264-
int res = git_remote_upload(intern->remote, NULL, NULL);
279+
git_push_options git_opts;
280+
git2_parse_push_options(&git_opts, opts);
281+
282+
git_strarray git_refspecs;
283+
git_refspecs.count = 0;
284+
285+
if (refspecs)
286+
php_git2_ht_to_strarray(&git_refspecs, refspecs);
287+
288+
int res = git_remote_upload(intern->remote, &git_refspecs, &git_opts);
265289

266290
if (res == 0) {
267291
RETURN_TRUE;
@@ -270,14 +294,29 @@ static PHP_METHOD(Remote, upload) {
270294
}
271295

272296
ZEND_BEGIN_ARG_INFO_EX(arginfo_remote_push, 0, 0, 0)
297+
ZEND_ARG_INFO(0, refspecs)
298+
ZEND_ARG_INFO(0, opts)
273299
ZEND_END_ARG_INFO()
274300

275301
static PHP_METHOD(Remote, push) {
276-
if (zend_parse_parameters_none() == FAILURE) return;
302+
HashTable *refspecs = NULL;
303+
HashTable *opts = NULL;
304+
305+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|aa", &refspecs, &opts) != SUCCESS) {
306+
return;
307+
}
277308
GIT2_REMOTE_FETCH();
278-
// TODO add git_push_options handling
279309

280-
int res = git_remote_push(intern->remote, NULL, NULL);
310+
git_push_options git_opts;
311+
git2_parse_push_options(&git_opts, opts);
312+
313+
git_strarray git_refspecs;
314+
git_refspecs.count = 0;
315+
316+
if (refspecs)
317+
php_git2_ht_to_strarray(&git_refspecs, refspecs);
318+
319+
int res = git_remote_push(intern->remote, &git_refspecs, &git_opts);
281320

282321
if (res == 0) {
283322
RETURN_TRUE;

0 commit comments

Comments
 (0)