2
2
#include "php_git2_priv.h"
3
3
#include "status.h"
4
4
5
+ static void php_git2_git_status_options_to_array (git_status_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 ("show" ), options -> show );
14
+ add_assoc_long_ex (result , ZEND_STRS ("flags" ), options -> flags );
15
+ php_git2_strarray_to_array (& options -> pathspec , & pathspec TSRMLS_CC );
16
+ add_assoc_zval_ex (result , ZEND_STRS ("pathspec" ), pathspec );
17
+
18
+ * out = result ;
19
+ }
20
+
21
+ static void php_git2_array_to_git_status_options (git_status_options * options , zval * array TSRMLS_DC )
22
+ {
23
+ zval * tmp ;
24
+ options -> version = php_git2_read_arrval_long2 (array , ZEND_STRS ("version" ), 1 TSRMLS_CC );
25
+ options -> show = php_git2_read_arrval_long2 (array , ZEND_STRS ("version" ), 0 TSRMLS_CC );
26
+ options -> flags = php_git2_read_arrval_long2 (array , ZEND_STRS ("version" ), 0 TSRMLS_CC );
27
+
28
+ php_git2_array_to_strarray (& options -> pathspec , php_git2_read_arrval (array , ZEND_STRS ("pathspec" ) TSRMLS_CC ) TSRMLS_CC );
29
+ }
30
+
31
+ static void php_git2_git_status_entry_to_array (git_status_entry * entry , zval * * out TSRMLS_DC )
32
+ {
33
+ zval * result , * head_to_index , * index_to_workdir ;
34
+
35
+ MAKE_STD_ZVAL (result );
36
+ array_init (result );
37
+
38
+ if (entry -> head_to_index ) {
39
+ php_git2_diff_delta_to_array (entry -> head_to_index , & head_to_index TSRMLS_CC );
40
+ } else {
41
+ MAKE_STD_ZVAL (head_to_index );
42
+ ZVAL_NULL (head_to_index );
43
+ }
44
+
45
+ if (entry -> index_to_workdir ) {
46
+ php_git2_diff_delta_to_array (entry -> index_to_workdir , & index_to_workdir TSRMLS_CC );
47
+ } else {
48
+ MAKE_STD_ZVAL (index_to_workdir );
49
+ ZVAL_NULL (index_to_workdir );
50
+ }
51
+
52
+ add_assoc_long_ex (result , ZEND_STRS ("status" ), entry -> status );
53
+ add_assoc_zval_ex (result , ZEND_STRS ("head_to_index" ), head_to_index );
54
+ add_assoc_zval_ex (result , ZEND_STRS ("index_to_workdir" ), index_to_workdir );
55
+
56
+ * out = result ;
57
+ }
58
+
59
+ static int php_git2_git_status_cb (
60
+ const char * path , unsigned int status_flags , void * payload )
61
+ {
62
+ php_git2_t * result ;
63
+ zval * param_path , * param_status_flags , * retval_ptr = NULL ;
64
+ php_git2_cb_t * p = (php_git2_cb_t * )payload ;
65
+ int i = 0 ;
66
+ long retval = 0 ;
67
+ GIT2_TSRMLS_SET (p -> tsrm_ls )
68
+
69
+ Z_ADDREF_P (p -> payload );
70
+ MAKE_STD_ZVAL (param_path );
71
+ MAKE_STD_ZVAL (param_status_flags );
72
+ ZVAL_STRING (param_path , path , 1 );
73
+ ZVAL_LONG (param_status_flags , status_flags );
74
+
75
+ if (php_git2_call_function_v (p -> fci , p -> fcc TSRMLS_CC , & retval_ptr , 3 ,
76
+ & param_path , & param_status_flags , & p -> payload )) {
77
+ return GIT_EUSER ;
78
+ }
79
+
80
+ retval = Z_LVAL_P (retval_ptr );
81
+ zval_ptr_dtor (& retval_ptr );
82
+ return retval ;
83
+ }
84
+
5
85
/* {{{ proto long git_status_foreach(resource $repo, Callable $callback, $payload)
6
86
*/
7
87
PHP_FUNCTION (git_status_foreach )
@@ -12,7 +92,7 @@ PHP_FUNCTION(git_status_foreach)
12
92
zend_fcall_info fci = empty_fcall_info ;
13
93
zend_fcall_info_cache fcc = empty_fcall_info_cache ;
14
94
php_git2_cb_t * cb = NULL ;
15
-
95
+
16
96
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
17
97
"rfz" , & repo , & fci , & fcc , & payload ) == FAILURE ) {
18
98
return ;
@@ -22,7 +102,7 @@ PHP_FUNCTION(git_status_foreach)
22
102
if (php_git2_cb_init (& cb , & fci , & fcc , payload TSRMLS_CC )) {
23
103
RETURN_FALSE ;
24
104
}
25
- // result = git_status_foreach(PHP_GIT2_V(_repo, repository), <CHANGEME> , cb);
105
+ result = git_status_foreach (PHP_GIT2_V (_repo , repository ), php_git2_git_status_cb , cb );
26
106
php_git2_cb_free (cb );
27
107
RETURN_LONG (result );
28
108
}
@@ -38,18 +118,23 @@ PHP_FUNCTION(git_status_foreach_ext)
38
118
zend_fcall_info fci = empty_fcall_info ;
39
119
zend_fcall_info_cache fcc = empty_fcall_info_cache ;
40
120
php_git2_cb_t * cb = NULL ;
121
+ git_status_options options = GIT_STATUS_OPTIONS_INIT ;
41
122
42
123
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
43
- "r<git_status_options>fz " , & repo , & opts , & fci , & fcc , & payload ) == FAILURE ) {
124
+ "rafz " , & repo , & opts , & fci , & fcc , & payload ) == FAILURE ) {
44
125
return ;
45
126
}
46
127
47
128
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
129
+ php_git2_array_to_git_status_options (& options , opts TSRMLS_CC );
48
130
if (php_git2_cb_init (& cb , & fci , & fcc , payload TSRMLS_CC )) {
49
131
RETURN_FALSE ;
50
132
}
51
- // result = git_status_foreach_ext(PHP_GIT2_V(_repo, repository), opts, <CHANGEME> , cb);
133
+ result = git_status_foreach_ext (PHP_GIT2_V (_repo , repository ), & options , php_git2_git_status_cb , cb );
52
134
php_git2_cb_free (cb );
135
+ if (options .pathspec .count > 0 ) {
136
+ php_git2_strarray_free (& options .pathspec );
137
+ }
53
138
RETURN_LONG (result );
54
139
}
55
140
/* }}} */
@@ -82,15 +167,20 @@ PHP_FUNCTION(git_status_list_new)
82
167
php_git2_t * result = NULL , * _repo = NULL ;
83
168
git_status_list * out = NULL ;
84
169
zval * repo = NULL , * opts = NULL ;
170
+ git_status_options options = GIT_STATUS_OPTIONS_INIT ;
85
171
int error = 0 ;
86
172
87
173
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
88
- "r<git_status_options> " , & repo , & opts ) == FAILURE ) {
174
+ "ra " , & repo , & opts ) == FAILURE ) {
89
175
return ;
90
176
}
91
177
92
178
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
93
- error = git_status_list_new (& out , PHP_GIT2_V (_repo , repository ), opts );
179
+ php_git2_array_to_git_status_options (& options , opts TSRMLS_CC );
180
+ error = git_status_list_new (& out , PHP_GIT2_V (_repo , repository ), & options );
181
+ if (options .pathspec .count > 0 ) {
182
+ php_git2_strarray_free (& options .pathspec );
183
+ }
94
184
if (php_git2_check_error (error , "git_status_list_new" TSRMLS_CC )) {
95
185
RETURN_FALSE ;
96
186
}
@@ -125,7 +215,7 @@ PHP_FUNCTION(git_status_list_entrycount)
125
215
PHP_FUNCTION (git_status_byindex )
126
216
{
127
217
const git_status_entry * result = NULL ;
128
- zval * statuslist = NULL ;
218
+ zval * statuslist = NULL , * out ;
129
219
php_git2_t * _statuslist = NULL ;
130
220
long idx = 0 ;
131
221
@@ -136,7 +226,11 @@ PHP_FUNCTION(git_status_byindex)
136
226
137
227
ZEND_FETCH_RESOURCE (_statuslist , php_git2_t * , & statuslist , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
138
228
result = git_status_byindex (PHP_GIT2_V (_statuslist , status_list ), idx );
139
- /* TODO(chobie): implement this */
229
+ if (result == NULL ) {
230
+ RETURN_FALSE ;
231
+ }
232
+ php_git2_git_status_entry_to_array (result , & out TSRMLS_CC );
233
+ RETURN_ZVAL (out , 0 , 1 );
140
234
}
141
235
/* }}} */
142
236
@@ -182,3 +276,11 @@ PHP_FUNCTION(git_status_should_ignore)
182
276
}
183
277
/* }}} */
184
278
279
+ PHP_FUNCTION (git_status_options_new )
280
+ {
281
+ git_status_options options = GIT_STATUS_OPTIONS_INIT ;
282
+ zval * result ;
283
+
284
+ php_git2_git_status_options_to_array (& options , & result TSRMLS_CC );
285
+ RETURN_ZVAL (result , 0 , 1 );
286
+ }
0 commit comments