2
2
#include "php_git2_priv.h"
3
3
#include "repository.h"
4
4
5
+ static void php_git2_array_to_git_repository_init_options (git_repository_init_options * opts , zval * array TSRMLS_DC )
6
+ {
7
+ long lval ;
8
+
9
+ lval = php_git2_read_arrval_long (array , ZEND_STRS ("version" ) TSRMLS_CC );
10
+ if (lval > 0 ) {
11
+ opts -> version = lval ;
12
+ }
13
+ opts -> flags = php_git2_read_arrval_long (array , ZEND_STRS ("flags" ) TSRMLS_CC );
14
+ opts -> mode = php_git2_read_arrval_long (array , ZEND_STRS ("mode" ) TSRMLS_CC );
15
+
16
+ opts -> workdir_path = php_git2_read_arrval_string (array , ZEND_STRS ("workdir_path" ) TSRMLS_CC );
17
+ opts -> description = php_git2_read_arrval_string (array , ZEND_STRS ("description" ) TSRMLS_CC );
18
+ opts -> template_path = php_git2_read_arrval_string (array , ZEND_STRS ("template_path" ) TSRMLS_CC );
19
+ opts -> initial_head = php_git2_read_arrval_string (array , ZEND_STRS ("initial_head" ) TSRMLS_CC );
20
+ opts -> origin_url = php_git2_read_arrval_string (array , ZEND_STRS ("origin_url" ) TSRMLS_CC );
21
+ }
22
+
23
+ static void php_git2_git_repository_init_options_to_array (git_repository_init_options * opts , zval * * out TSRMLS_DC )
24
+ {
25
+ zval * result ;
26
+ MAKE_STD_ZVAL (result );
27
+ array_init (result );
28
+
29
+ add_assoc_long_ex (result , ZEND_STRS ("version" ), opts -> version );
30
+ add_assoc_long_ex (result , ZEND_STRS ("flags" ), opts -> flags );
31
+ add_assoc_long_ex (result , ZEND_STRS ("mode" ), opts -> mode );
32
+
33
+ if (opts -> workdir_path != NULL ) {
34
+ add_assoc_string_ex (result , ZEND_STRS ("workdir_path" ), opts -> workdir_path , 1 );
35
+ } else {
36
+ add_assoc_null_ex (result , ZEND_STRS ("workdir_path" ));
37
+ }
38
+
39
+ if (opts -> workdir_path != NULL ) {
40
+ add_assoc_string_ex (result , ZEND_STRS ("description" ), opts -> description , 1 );
41
+ } else {
42
+ add_assoc_null_ex (result , ZEND_STRS ("description" ));
43
+ }
44
+
45
+ if (opts -> workdir_path != NULL ) {
46
+ add_assoc_string_ex (result , ZEND_STRS ("template_path" ), opts -> template_path , 1 );
47
+ } else {
48
+ add_assoc_null_ex (result , ZEND_STRS ("template_path" ));
49
+ }
50
+
51
+ if (opts -> workdir_path != NULL ) {
52
+ add_assoc_string_ex (result , ZEND_STRS ("initial_head" ), opts -> initial_head , 1 );
53
+ } else {
54
+ add_assoc_null_ex (result , ZEND_STRS ("initial_head" ));
55
+ }
56
+
57
+ if (opts -> workdir_path != NULL ) {
58
+ add_assoc_string_ex (result , ZEND_STRS ("origin_url" ), opts -> origin_url , 1 );
59
+ } else {
60
+ add_assoc_null_ex (result , ZEND_STRS ("origin_url" ));
61
+ }
62
+ * out = result ;
63
+ }
64
+
65
+
5
66
static int php_git2_repository_fetchhead_foreach_cb (const char * ref_name ,
6
67
const char * remote_url ,
7
68
const git_oid * oid ,
@@ -310,25 +371,24 @@ PHP_FUNCTION(git_repository_free)
310
371
}
311
372
/* }}} */
312
373
313
-
314
374
/* {{{ proto resource git_repository_init_ext(string $repo_path, $opts)
315
375
*/
316
376
PHP_FUNCTION (git_repository_init_ext )
317
377
{
378
+ git_repository_init_options options = GIT_REPOSITORY_INIT_OPTIONS_INIT ;
318
379
php_git2_t * result = NULL ;
319
380
git_repository * out = NULL ;
320
381
char * repo_path = NULL ;
321
- int repo_path_len = 0 ;
382
+ int repo_path_len = 0 , error = 0 ;
322
383
zval * opts = NULL ;
323
- int error = 0 ;
324
384
325
- /* TODO(chobie): generate converter */
326
385
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
327
386
"sa" , & repo_path , & repo_path_len , & opts ) == FAILURE ) {
328
387
return ;
329
388
}
330
389
331
- error = git_repository_init_ext (& out , repo_path , opts );
390
+ php_git2_array_to_git_repository_init_options (& options , opts TSRMLS_CC );
391
+ error = git_repository_init_ext (& out , repo_path , & options );
332
392
if (php_git2_check_error (error , "git_repository_init_ext" TSRMLS_CC )) {
333
393
RETURN_FALSE ;
334
394
}
@@ -876,4 +936,16 @@ PHP_FUNCTION(git_repository_is_shallow)
876
936
is_shallow = git_repository_is_shallow (PHP_GIT2_V (_repo , repository ));
877
937
RETURN_LONG (is_shallow );
878
938
}
939
+ /* }}} */
940
+
941
+ /* {{{ proto array git_repository_init_options_new()
942
+ */
943
+ PHP_FUNCTION (git_repository_init_options_new )
944
+ {
945
+ git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT ;
946
+ zval * result ;
947
+
948
+ php_git2_git_repository_init_options_to_array (& opts , & result TSRMLS_CC );
949
+ RETURN_ZVAL (result , 0 , 1 );
950
+ }
879
951
/* }}} */
0 commit comments