-
Notifications
You must be signed in to change notification settings - Fork 10
/
status.c
268 lines (214 loc) · 6.65 KB
/
status.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include "php_git2.h"
#include "php_git2_priv.h"
#include "status.h"
/* {{{ proto long git_status_foreach(resource $repo, Callable $callback, void $payload)
*/
PHP_FUNCTION(git_status_foreach)
{
int result;
zval *repo = NULL, *payload = NULL;
php_git2_t *_repo = NULL;
zend_fcall_info callback_fci = empty_fcall_info;
zend_fcall_info_cache callback_fcc = empty_fcall_info_cache;
php_git2_cb_t *callback_cb = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rfz", &repo, &callback_fci, &callback_fcc, &payload) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
if (php_git2_cb_init(&callback_cb, &callback_fci, &callback_fcc, payload TSRMLS_CC)) {
RETURN_FALSE;
}
result = git_status_foreach(PHP_GIT2_V(_repo, repository), php_git2_git_status_cb, callback_cb);
php_git2_cb_free(callback_cb);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_status_foreach_ext(resource $repo, array $opts, Callable $callback, void $payload)
*/
PHP_FUNCTION(git_status_foreach_ext)
{
int result, should_free = 0;
zval *repo = NULL, *opts = NULL, *payload = NULL;
php_git2_t *_repo = NULL;
git_status_options _opts = {0};
zend_fcall_info callback_fci = empty_fcall_info;
zend_fcall_info_cache callback_fcc = empty_fcall_info_cache;
php_git2_cb_t *callback_cb = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r|afz", &repo, &opts, &callback_fci, &callback_fcc, &payload) == FAILURE) {
return;
}
if (opts != NULL) {
php_git2_array_to_git_status_options(&_opts, opts TSRMLS_CC);
should_free = 1;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
if (php_git2_cb_init(&callback_cb, &callback_fci, &callback_fcc, payload TSRMLS_CC)) {
RETURN_FALSE;
}
result = git_status_foreach_ext(PHP_GIT2_V(_repo, repository), &_opts, php_git2_git_status_cb, callback_cb);
if (should_free) {
php_git2_git_status_options_free(&_opts TSRMLS_CC);
}
php_git2_cb_free(callback_cb);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_status_file(resource $repo, string $path)
*/
PHP_FUNCTION(git_status_file)
{
unsigned int status_flags = 0;
zval *repo = NULL;
php_git2_t *_repo = NULL;
char *path = NULL;
size_t path_len;
int error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs", &repo, &path, &path_len) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_status_file(&status_flags, PHP_GIT2_V(_repo, repository), path);
if (php_git2_check_error(error, "git_status_file" TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_LONG(status_flags);
}
/* }}} */
/* {{{ proto resource git_status_list_new(resource $repo, array $opts)
*/
PHP_FUNCTION(git_status_list_new)
{
php_git2_t *result = NULL, *_repo = NULL;
git_status_list *out = NULL;
zval *repo = NULL, *opts = NULL;
git_status_options _opts = {0};
int should_free = 0, error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r|a", &repo, &opts) == FAILURE) {
return;
}
if (opts != NULL) {
php_git2_array_to_git_status_options(&_opts, opts TSRMLS_CC);
should_free = 1;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_status_list_new(&out, PHP_GIT2_V(_repo, repository), &_opts);
if (php_git2_check_error(error, "git_status_list_new" TSRMLS_CC)) {
RETURN_FALSE;
}
if (should_free) {
php_git2_git_status_options_free(&_opts TSRMLS_CC);
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_STATUS_LIST, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_RES(GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto long git_status_list_entrycount(resource $statuslist)
*/
PHP_FUNCTION(git_status_list_entrycount)
{
size_t result;
zval *statuslist = NULL;
php_git2_t *_statuslist = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &statuslist) == FAILURE) {
return;
}
if ((_statuslist = (php_git2_t *) zend_fetch_resource(Z_RES_P(statuslist), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
result = git_status_list_entrycount(PHP_GIT2_V(_statuslist, status_list));
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto array git_status_byindex(resource $statuslist, long $idx)
*/
PHP_FUNCTION(git_status_byindex)
{
const git_status_entry *result = NULL;
zval *statuslist = NULL;
php_git2_t *_statuslist = NULL;
zend_long idx;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rl", &statuslist, &idx) == FAILURE) {
return;
}
if ((_statuslist = (php_git2_t *) zend_fetch_resource(Z_RES_P(statuslist), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
result = git_status_byindex(PHP_GIT2_V(_statuslist, status_list), idx);
if (result == NULL) {
RETURN_FALSE;
}
array_init(return_value);
php_git2_git_status_entry_to_array(result, return_value TSRMLS_CC);
RETVAL_ARR(Z_ARRVAL_P(return_value));
}
/* }}} */
/* {{{ proto void git_status_list_free(resource $statuslist)
*/
PHP_FUNCTION(git_status_list_free)
{
zval *statuslist = NULL;
php_git2_t *_statuslist = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &statuslist) == FAILURE) {
return;
}
if ((_statuslist = (php_git2_t *) zend_fetch_resource(Z_RES_P(statuslist), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
// todo rework
if (0 /* GIT2_SHOULD_FREE(_statuslist) */) {
git_status_list_free(PHP_GIT2_V(_statuslist, status_list));
GIT2_SHOULD_FREE(_statuslist) = 0;
}
//zval_ptr_dtor(statuslist);
}
/* }}} */
/* {{{ proto long git_status_should_ignore(resource $repo, string $path)
*/
PHP_FUNCTION(git_status_should_ignore)
{
int ignored = 0, error;
zval *repo = NULL;
php_git2_t *_repo = NULL;
char *path = NULL;
size_t path_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs", &repo, &path, &path_len) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_status_should_ignore(&ignored, PHP_GIT2_V(_repo, repository), path);
if (php_git2_check_error(error, "git_status_should_ignore" TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_LONG(ignored);
}
/* }}} */
/* {{{ proto array git_status_options_new()
*/
PHP_FUNCTION(git_status_options_new)
{
zval *result;
git_status_options options = GIT_STATUS_OPTIONS_INIT;
php_git2_git_status_options_to_array(&options, result TSRMLS_CC);
RETURN_ZVAL(result, 0, 1);
}
/* }}} */