@@ -64,6 +64,102 @@ static void php_git2_config_get_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2
6464 }
6565}
6666
67+ static void php_git2_config_set_with (INTERNAL_FUNCTION_PARAMETERS , enum php_git2_config type )
68+ {
69+ zval * cfg ;
70+ php_git2_t * _cfg ;
71+ char * name = {0 };
72+ int name_len ;
73+ int error = 0 ;
74+ zval * value ;
75+
76+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
77+ "rsz" , & cfg , & name , & name_len , & value ) == FAILURE ) {
78+ return ;
79+ }
80+ ZEND_FETCH_RESOURCE (_cfg , php_git2_t * , & cfg , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
81+
82+ switch (type ) {
83+ case PHP_GIT2_CONFIG_STRING : {
84+ if (Z_TYPE_P (value ) != IS_STRING ) {
85+ convert_to_string (value );
86+ }
87+ error = git_config_set_string (PHP_GIT2_V (_cfg , config ), name , Z_STRVAL_P (value ));
88+ if (php_git2_check_error (error , "git_config_set_string" TSRMLS_CC )) {
89+ RETURN_FALSE
90+ }
91+ RETURN_TRUE ;
92+ break ;
93+ }
94+ case PHP_GIT2_CONFIG_BOOL : {
95+ if (Z_TYPE_P (value ) != IS_BOOL ) {
96+ convert_to_bool (value );
97+ }
98+ error = git_config_set_bool (PHP_GIT2_V (_cfg , config ), name , Z_LVAL_P (value ));
99+ if (php_git2_check_error (error , "git_config_set_bool" TSRMLS_CC )) {
100+ RETURN_FALSE
101+ }
102+ RETURN_TRUE ;
103+ break ;
104+ }
105+ case PHP_GIT2_CONFIG_INT32 : {
106+ if (Z_TYPE_P (value ) != IS_LONG ) {
107+ convert_to_long (value );
108+ }
109+ error = git_config_set_int32 (PHP_GIT2_V (_cfg , config ), name , Z_LVAL_P (value ));
110+ if (php_git2_check_error (error , "git_config_set_int32" TSRMLS_CC )) {
111+ RETURN_FALSE
112+ }
113+ RETURN_TRUE ;
114+ break ;
115+ }
116+ case PHP_GIT2_CONFIG_INT64 : {
117+ if (Z_TYPE_P (value ) != IS_LONG ) {
118+ convert_to_long (value );
119+ }
120+ error = git_config_set_int64 (PHP_GIT2_V (_cfg , config ), name , Z_LVAL_P (value ));
121+ if (php_git2_check_error (error , "git_config_set_int64" TSRMLS_CC )) {
122+ RETURN_FALSE
123+ }
124+ RETURN_TRUE ;
125+ break ;
126+ }
127+ }
128+ }
129+
130+
131+ static void php_git2_config_parse_with (INTERNAL_FUNCTION_PARAMETERS , enum php_git2_config type )
132+ {
133+ char * value = {0 };
134+ int value_len ;
135+ int error = 0 ;
136+
137+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
138+ "s" , & value , & value_len ) == FAILURE ) {
139+ return ;
140+ }
141+
142+ switch (type ) {
143+ case PHP_GIT2_CONFIG_BOOL : {
144+ int result ;
145+ result = git_config_parse_bool (& result , value );
146+ RETURN_BOOL (result );
147+ break ;
148+ }
149+ case PHP_GIT2_CONFIG_INT32 : {
150+ int32_t result ;
151+ result = git_config_parse_int32 (& result , value );
152+ RETURN_LONG (result );
153+ break ;
154+ }
155+ case PHP_GIT2_CONFIG_INT64 : {
156+ int64_t result ;
157+ result = git_config_parse_int64 (& result , value );
158+ RETURN_LONG (result );
159+ break ;
160+ }
161+ }
162+ }
67163
68164/* {{{ proto resource git_config_find_global()
69165*/
@@ -420,85 +516,28 @@ PHP_FUNCTION(git_config_iterator_free)
420516*/
421517PHP_FUNCTION (git_config_set_int32 )
422518{
423- zval * cfg ;
424- php_git2_t * _cfg ;
425- char * name = {0 };
426- int name_len ;
427- long value ;
428-
429- /* TODO(chobie): implement this */
430- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_set_int32 not implemented yet" );
431- return ;
432-
433- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
434- "rsl" , & cfg , & name , & name_len , & value ) == FAILURE ) {
435- return ;
436- }
437- ZEND_FETCH_RESOURCE (_cfg , php_git2_t * , & cfg , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
519+ php_git2_config_set_with (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GIT2_CONFIG_INT32 );
438520}
439521
440522/* {{{ proto long git_config_set_int64(cfg, name, value)
441523*/
442524PHP_FUNCTION (git_config_set_int64 )
443525{
444- zval * cfg ;
445- php_git2_t * _cfg ;
446- char * name = {0 };
447- int name_len ;
448- long value ;
449-
450- /* TODO(chobie): implement this */
451- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_set_int64 not implemented yet" );
452- return ;
453-
454- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
455- "rsl" , & cfg , & name , & name_len , & value ) == FAILURE ) {
456- return ;
457- }
458- ZEND_FETCH_RESOURCE (_cfg , php_git2_t * , & cfg , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
526+ php_git2_config_set_with (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GIT2_CONFIG_INT64 );
459527}
460528
461529/* {{{ proto long git_config_set_bool(cfg, name, value)
462530*/
463531PHP_FUNCTION (git_config_set_bool )
464532{
465- zval * cfg ;
466- php_git2_t * _cfg ;
467- char * name = {0 };
468- int name_len ;
469- long value ;
470-
471- /* TODO(chobie): implement this */
472- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_set_bool not implemented yet" );
473- return ;
474-
475- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
476- "rsl" , & cfg , & name , & name_len , & value ) == FAILURE ) {
477- return ;
478- }
479- ZEND_FETCH_RESOURCE (_cfg , php_git2_t * , & cfg , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
533+ php_git2_config_set_with (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GIT2_CONFIG_BOOL );
480534}
481535
482536/* {{{ proto long git_config_set_string(cfg, name, value)
483537*/
484538PHP_FUNCTION (git_config_set_string )
485539{
486- zval * cfg ;
487- php_git2_t * _cfg ;
488- char * name = {0 };
489- int name_len ;
490- char * value = {0 };
491- int value_len ;
492-
493- /* TODO(chobie): implement this */
494- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_set_string not implemented yet" );
495- return ;
496-
497- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
498- "rss" , & cfg , & name , & name_len , & value , & value_len ) == FAILURE ) {
499- return ;
500- }
501- ZEND_FETCH_RESOURCE (_cfg , php_git2_t * , & cfg , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
540+ php_git2_config_set_with (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GIT2_CONFIG_STRING );
502541}
503542
504543/* {{{ proto long git_config_set_multivar(cfg, name, regexp, value)
@@ -533,16 +572,20 @@ PHP_FUNCTION(git_config_delete_entry)
533572 php_git2_t * _cfg ;
534573 char * name = {0 };
535574 int name_len ;
536-
537- /* TODO(chobie): implement this */
538- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_delete_entry not implemented yet" );
539- return ;
575+ int error = 0 ;
540576
541577 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
542578 "rs" , & cfg , & name , & name_len ) == FAILURE ) {
543579 return ;
544580 }
545581 ZEND_FETCH_RESOURCE (_cfg , php_git2_t * , & cfg , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
582+
583+ error = git_config_delete_entry (PHP_GIT2_V (_cfg , config ), name );
584+ if (php_git2_check_error (error , "git_config_delete_entry" TSRMLS_CC )) {
585+ RETURN_FALSE
586+ }
587+
588+ RETURN_TRUE ;
546589}
547590
548591/* {{{ proto long git_config_delete_multivar(cfg, name, regexp)
@@ -695,51 +738,21 @@ PHP_FUNCTION(git_config_lookup_map_value)
695738*/
696739PHP_FUNCTION (git_config_parse_bool )
697740{
698- char * value = {0 };
699- int value_len ;
700-
701- /* TODO(chobie): implement this */
702- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_parse_bool not implemented yet" );
703- return ;
704-
705- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
706- "s" , & value , & value_len ) == FAILURE ) {
707- return ;
708- }
741+ php_git2_config_parse_with (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GIT2_CONFIG_BOOL );
709742}
710743
711744/* {{{ proto resource git_config_parse_int32(value)
712745*/
713746PHP_FUNCTION (git_config_parse_int32 )
714747{
715- char * value = {0 };
716- int value_len ;
717-
718- /* TODO(chobie): implement this */
719- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_parse_int32 not implemented yet" );
720- return ;
721-
722- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
723- "s" , & value , & value_len ) == FAILURE ) {
724- return ;
725- }
748+ php_git2_config_parse_with (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GIT2_CONFIG_INT32 );
726749}
727750
728751/* {{{ proto resource git_config_parse_int64(value)
729752*/
730753PHP_FUNCTION (git_config_parse_int64 )
731754{
732- char * value = {0 };
733- int value_len ;
734-
735- /* TODO(chobie): implement this */
736- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_config_parse_int64 not implemented yet" );
737- return ;
738-
739- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
740- "s" , & value , & value_len ) == FAILURE ) {
741- return ;
742- }
755+ php_git2_config_parse_with (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GIT2_CONFIG_INT64 );
743756}
744757
745758/* {{{ proto long git_config_backend_foreach_match(backend, regexp, , ), data)
0 commit comments