Skip to content

Commit 1d20679

Browse files
committed
[status] update code base
1 parent 384367d commit 1d20679

File tree

1 file changed

+70
-78
lines changed

1 file changed

+70
-78
lines changed

status.c

+70-78
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,102 @@
22
#include "php_git2_priv.h"
33
#include "status.h"
44

5-
/* {{{ proto long git_status_foreach(repo, callback, payload)
6-
*/
5+
/* {{{ proto long git_status_foreach(resource $repo, Callable $callback, $payload)
6+
*/
77
PHP_FUNCTION(git_status_foreach)
88
{
9-
zval *repo;
10-
php_git2_t *_repo;
11-
zval *callback;
12-
php_git2_t *_callback;
13-
zval *payload;
14-
15-
/* TODO(chobie): implement this */
16-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_foreach not implemented yet");
17-
return;
18-
9+
int result = 0, error = 0;
10+
zval *repo = NULL, *callback = NULL, *payload = NULL;
11+
php_git2_t *_repo = NULL;
12+
zend_fcall_info fci = empty_fcall_info;
13+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
14+
php_git2_cb_t *cb = NULL;
15+
1916
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
20-
"rrz", &repo, &callback, &payload) == FAILURE) {
17+
"rfz", &repo, &fci, &fcc, &payload) == FAILURE) {
2118
return;
2219
}
20+
2321
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
22+
if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {
23+
RETURN_FALSE;
24+
}
25+
//result = git_status_foreach(PHP_GIT2_V(_repo, repository), <CHANGEME>, cb);
26+
php_git2_cb_free(cb);
27+
RETURN_LONG(result);
2428
}
29+
/* }}} */
2530

26-
/* {{{ proto long git_status_foreach_ext(repo, opts, callback, payload)
27-
*/
31+
/* {{{ proto long git_status_foreach_ext(resource $repo, $opts, Callable $callback, $payload)
32+
*/
2833
PHP_FUNCTION(git_status_foreach_ext)
2934
{
30-
zval *repo;
31-
php_git2_t *_repo;
32-
zval *opts;
33-
php_git2_t *_opts;
34-
zval *callback;
35-
php_git2_t *_callback;
36-
zval *payload;
37-
38-
/* TODO(chobie): implement this */
39-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_foreach_ext not implemented yet");
40-
return;
41-
35+
int result = 0, error = 0;
36+
zval *repo = NULL, *opts = NULL, *callback = NULL, *payload = NULL;
37+
php_git2_t *_repo = NULL;
38+
zend_fcall_info fci = empty_fcall_info;
39+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
40+
php_git2_cb_t *cb = NULL;
41+
4242
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
43-
"rrrz", &repo, &opts, &callback, &payload) == FAILURE) {
43+
"r<git_status_options>fz", &repo, &opts, &fci, &fcc, &payload) == FAILURE) {
4444
return;
4545
}
46+
4647
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
48+
if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {
49+
RETURN_FALSE;
50+
}
51+
//result = git_status_foreach_ext(PHP_GIT2_V(_repo, repository), opts, <CHANGEME>, cb);
52+
php_git2_cb_free(cb);
53+
RETURN_LONG(result);
4754
}
55+
/* }}} */
4856

49-
/* {{{ proto long git_status_file(resource $repo, string $path)
57+
/* {{{ proto long git_status_file(long $status_flags, resource $repo, string $path)
5058
*/
5159
PHP_FUNCTION(git_status_file)
5260
{
53-
unsigned int status_flags = 0;
61+
int result = 0, path_len = 0, error = 0;
62+
long status_flags = 0;
5463
zval *repo = NULL;
5564
php_git2_t *_repo = NULL;
5665
char *path = NULL;
57-
int path_len = 0;
58-
int error = 0;
59-
66+
6067
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
61-
"rs", &repo, &path, &path_len) == FAILURE) {
68+
"lrs", &status_flags, &repo, &path, &path_len) == FAILURE) {
6269
return;
6370
}
64-
71+
6572
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
66-
error = git_status_file(status_flags, PHP_GIT2_V(_repo, repository), path);
67-
if (php_git2_check_error(error, "git_status_file" TSRMLS_CC)) {
68-
RETURN_FALSE;
69-
}
70-
RETURN_LONG(status_flags);
73+
result = git_status_file(status_flags, PHP_GIT2_V(_repo, repository), path);
74+
RETURN_LONG(result);
7175
}
7276
/* }}} */
7377

74-
7578
/* {{{ proto resource git_status_list_new(resource $repo, $opts)
7679
*/
7780
PHP_FUNCTION(git_status_list_new)
7881
{
79-
php_git2_t *result = NULL;
82+
php_git2_t *result = NULL, *_repo = NULL;
8083
git_status_list *out = NULL;
81-
zval *repo = NULL;
82-
php_git2_t *_repo = NULL;
83-
zval *opts = NULL;
84+
zval *repo = NULL, *opts = NULL;
8485
int error = 0;
85-
86+
8687
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
87-
"rz", &repo, &opts) == FAILURE) {
88+
"r<git_status_options>", &repo, &opts) == FAILURE) {
8889
return;
8990
}
90-
91-
/* TODO(chobie): convert arra to git_status_options */
92-
91+
9392
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
9493
error = git_status_list_new(&out, PHP_GIT2_V(_repo, repository), opts);
9594
if (php_git2_check_error(error, "git_status_list_new" TSRMLS_CC)) {
9695
RETURN_FALSE;
9796
}
98-
99-
PHP_GIT2_MAKE_RESOURCE(result);
100-
PHP_GIT2_V(result, status_list) = out;
101-
result->type = PHP_GIT2_TYPE_STATUS_LIST;
102-
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
103-
result->should_free_v = 0;
104-
ZVAL_RESOURCE(return_value, result->resource_id);
97+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_STATUS_LIST, out, 1 TSRMLS_CC)) {
98+
RETURN_FALSE;
99+
}
100+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
105101
}
106102
/* }}} */
107103

@@ -112,12 +108,12 @@ PHP_FUNCTION(git_status_list_entrycount)
112108
size_t result = 0;
113109
zval *statuslist = NULL;
114110
php_git2_t *_statuslist = NULL;
115-
111+
116112
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
117113
"r", &statuslist) == FAILURE) {
118114
return;
119115
}
120-
116+
121117
ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
122118
result = git_status_list_entrycount(PHP_GIT2_V(_statuslist, status_list));
123119
RETURN_LONG(result);
@@ -128,16 +124,16 @@ PHP_FUNCTION(git_status_list_entrycount)
128124
*/
129125
PHP_FUNCTION(git_status_byindex)
130126
{
131-
const git_status_entry *result = NULL;
127+
const git_status_entry *result = NULL;
132128
zval *statuslist = NULL;
133129
php_git2_t *_statuslist = NULL;
134130
long idx = 0;
135-
131+
136132
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
137133
"rl", &statuslist, &idx) == FAILURE) {
138134
return;
139135
}
140-
136+
141137
ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
142138
result = git_status_byindex(PHP_GIT2_V(_statuslist, status_list), idx);
143139
/* TODO(chobie): implement this */
@@ -150,43 +146,39 @@ PHP_FUNCTION(git_status_list_free)
150146
{
151147
zval *statuslist = NULL;
152148
php_git2_t *_statuslist = NULL;
153-
149+
154150
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
155151
"r", &statuslist) == FAILURE) {
156152
return;
157153
}
158-
154+
159155
ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
160-
if (_statuslist->should_free_v) {
156+
if (GIT2_SHOULD_FREE(_statuslist)) {
161157
git_status_list_free(PHP_GIT2_V(_statuslist, status_list));
158+
GIT2_SHOULD_FREE(_statuslist) = 0;
162159
};
163160
zval_ptr_dtor(&statuslist);
164161
}
165162
/* }}} */
166163

167-
/* {{{ proto long git_status_should_ignore(resource $repo, string $path)
164+
/* {{{ proto long git_status_should_ignore(long $ignored, resource $repo, string $path)
168165
*/
169166
PHP_FUNCTION(git_status_should_ignore)
170167
{
171-
int ignored = 0;
168+
int result = 0, path_len = 0, error = 0;
169+
long ignored = 0;
172170
zval *repo = NULL;
173171
php_git2_t *_repo = NULL;
174172
char *path = NULL;
175-
int path_len = 0;
176-
int error = 0;
177-
173+
178174
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
179-
"rs", &repo, &path, &path_len) == FAILURE) {
175+
"lrs", &ignored, &repo, &path, &path_len) == FAILURE) {
180176
return;
181177
}
182-
178+
183179
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
184-
error = git_status_should_ignore(&ignored, PHP_GIT2_V(_repo, repository), path);
185-
if (php_git2_check_error(error, "git_status_should_ignore" TSRMLS_CC)) {
186-
RETURN_FALSE;
187-
}
188-
189-
RETURN_LONG(ignored);
180+
result = git_status_should_ignore(ignored, PHP_GIT2_V(_repo, repository), path);
181+
RETURN_LONG(result);
190182
}
191183
/* }}} */
192184

0 commit comments

Comments
 (0)