@@ -64,6 +64,102 @@ static void php_git2_config_get_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2
64
64
}
65
65
}
66
66
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
+ }
67
163
68
164
/* {{{ proto resource git_config_find_global()
69
165
*/
@@ -420,85 +516,28 @@ PHP_FUNCTION(git_config_iterator_free)
420
516
*/
421
517
PHP_FUNCTION (git_config_set_int32 )
422
518
{
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 );
438
520
}
439
521
440
522
/* {{{ proto long git_config_set_int64(cfg, name, value)
441
523
*/
442
524
PHP_FUNCTION (git_config_set_int64 )
443
525
{
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 );
459
527
}
460
528
461
529
/* {{{ proto long git_config_set_bool(cfg, name, value)
462
530
*/
463
531
PHP_FUNCTION (git_config_set_bool )
464
532
{
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 );
480
534
}
481
535
482
536
/* {{{ proto long git_config_set_string(cfg, name, value)
483
537
*/
484
538
PHP_FUNCTION (git_config_set_string )
485
539
{
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 );
502
541
}
503
542
504
543
/* {{{ proto long git_config_set_multivar(cfg, name, regexp, value)
@@ -533,16 +572,20 @@ PHP_FUNCTION(git_config_delete_entry)
533
572
php_git2_t * _cfg ;
534
573
char * name = {0 };
535
574
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 ;
540
576
541
577
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
542
578
"rs" , & cfg , & name , & name_len ) == FAILURE ) {
543
579
return ;
544
580
}
545
581
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 ;
546
589
}
547
590
548
591
/* {{{ proto long git_config_delete_multivar(cfg, name, regexp)
@@ -695,51 +738,21 @@ PHP_FUNCTION(git_config_lookup_map_value)
695
738
*/
696
739
PHP_FUNCTION (git_config_parse_bool )
697
740
{
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 );
709
742
}
710
743
711
744
/* {{{ proto resource git_config_parse_int32(value)
712
745
*/
713
746
PHP_FUNCTION (git_config_parse_int32 )
714
747
{
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 );
726
749
}
727
750
728
751
/* {{{ proto resource git_config_parse_int64(value)
729
752
*/
730
753
PHP_FUNCTION (git_config_parse_int64 )
731
754
{
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 );
743
756
}
744
757
745
758
/* {{{ proto long git_config_backend_foreach_match(backend, regexp, , ), data)
0 commit comments