|
2 | 2 | #include "php_git2_priv.h"
|
3 | 3 | #include "clone.h"
|
4 | 4 |
|
| 5 | +static void php_git2_git_clone_options_to_array(git_clone_options *options, zval **out TSRMLS_DC) |
| 6 | +{ |
| 7 | + zval *result, *pathspec; |
| 8 | + |
| 9 | + MAKE_STD_ZVAL(result); |
| 10 | + array_init(result); |
| 11 | + |
| 12 | + add_assoc_long_ex(result, ZEND_STRS("version"), options->version); |
| 13 | + add_assoc_long_ex(result, ZEND_STRS("bare"), options->bare); |
| 14 | + add_assoc_long_ex(result, ZEND_STRS("ignore_cert_errors"), options->ignore_cert_errors); |
| 15 | + /* TODO: make other options available */ |
| 16 | + *out = result; |
| 17 | +} |
| 18 | + |
| 19 | +static void php_git2_array_to_git_clone_options(git_clone_options *options, zval *array TSRMLS_DC) |
| 20 | +{ |
| 21 | + options->version = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 1 TSRMLS_CC); |
| 22 | + options->bare = php_git2_read_arrval_long2(array, ZEND_STRS("bare"), 0 TSRMLS_CC); |
| 23 | + options->ignore_cert_errors = php_git2_read_arrval_long2(array, ZEND_STRS("ignore_cert_errors"), 0 TSRMLS_CC); |
| 24 | +} |
| 25 | + |
5 | 26 | /* {{{ proto resource git_clone(string $url, string $localpath[, array $options])
|
6 | 27 | */
|
7 | 28 | PHP_FUNCTION(git_clone)
|
8 | 29 | {
|
9 | 30 | char *url, *localpath;
|
10 | 31 | int url_len, localpath_len;
|
11 |
| - zval *options;// = GIT_OPTIONS_INIT; |
| 32 | + zval *opts = NULL;// = GIT_OPTIONS_INIT; |
12 | 33 | php_git2_t *git2;
|
13 | 34 | git_repository *repository;
|
14 | 35 | int error;
|
| 36 | + git_clone_options options = GIT_CLONE_OPTIONS_INIT; |
15 | 37 |
|
16 | 38 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
17 |
| - "ss|a", &url, &url_len, &localpath, &localpath_len, &options) == FAILURE) { |
| 39 | + "ss|a", &url, &url_len, &localpath, &localpath_len, &opts) == FAILURE) { |
18 | 40 | return;
|
19 | 41 | }
|
20 | 42 |
|
21 | 43 | /* TODO(chobie): convert options to git_clone_options */
|
22 | 44 |
|
23 |
| - error = git_clone(&repository, url, localpath, NULL); |
| 45 | + php_git2_array_to_git_clone_options(&options, opts TSRMLS_CC); |
| 46 | + |
| 47 | + |
| 48 | + error = git_clone(&repository, url, localpath, &options); |
24 | 49 | if (php_git2_check_error(error, "git_clone" TSRMLS_CC)) {
|
25 | 50 | RETURN_FALSE
|
26 | 51 | }
|
|
0 commit comments