Skip to content

Commit 4024a38

Browse files
committed
[git_status_list] add stub codes
1 parent ded8f8f commit 4024a38

File tree

2 files changed

+89
-60
lines changed

2 files changed

+89
-60
lines changed

php_git2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ enum php_git2_resource_type {
8787
PHP_GIT2_TYPE_INDEX,
8888
PHP_GIT2_TYPE_ODB,
8989
PHP_GIT2_TYPE_REFDB,
90+
PHP_GIT2_TYPE_STATUS_LIST,
9091
};
9192

9293
typedef struct php_git2_t {
@@ -105,6 +106,7 @@ typedef struct php_git2_t {
105106
git_index *index;
106107
git_odb *odb;
107108
git_refdb *refdb;
109+
git_status_list *status_list;
108110
} v;
109111
int should_free_v;
110112
int resource_id;

status.c

Lines changed: 87 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,120 +46,147 @@ PHP_FUNCTION(git_status_foreach_ext)
4646
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
4747
}
4848

49-
/* {{{ proto long git_status_file(status_flags, repo, path)
50-
*/
49+
/* {{{ proto long git_status_file(resource $repo, string $path)
50+
*/
5151
PHP_FUNCTION(git_status_file)
5252
{
53-
long status_flags;
54-
zval *repo;
55-
php_git2_t *_repo;
56-
char *path = {0};
57-
int path_len;
58-
59-
/* TODO(chobie): implement this */
60-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_file not implemented yet");
61-
return;
53+
unsigned int status_flags = 0;
54+
zval *repo = NULL;
55+
php_git2_t *_repo = NULL;
56+
char *path = NULL;
57+
int path_len = 0;
58+
int error = 0;
6259

6360
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
64-
"lrs", &status_flags, &repo, &path, &path_len) == FAILURE) {
61+
"rs", &repo, &path, &path_len) == FAILURE) {
6562
return;
6663
}
64+
6765
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);
6871
}
72+
/* }}} */
6973

70-
/* {{{ proto resource git_status_list_new(repo, opts)
71-
*/
74+
75+
/* {{{ proto resource git_status_list_new(resource $repo, $opts)
76+
*/
7277
PHP_FUNCTION(git_status_list_new)
7378
{
74-
zval *repo;
75-
php_git2_t *_repo;
76-
zval *opts;
77-
php_git2_t *_opts;
78-
79-
/* TODO(chobie): implement this */
80-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_new not implemented yet");
81-
return;
79+
php_git2_t *result = NULL;
80+
git_status_list *out = NULL;
81+
zval *repo = NULL;
82+
php_git2_t *_repo = NULL;
83+
zval *opts = NULL;
84+
int error = 0;
8285

8386
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
84-
"rr", &repo, &opts) == FAILURE) {
87+
"rz", &repo, &opts) == FAILURE) {
8588
return;
8689
}
90+
91+
/* TODO(chobie): convert arra to git_status_options */
92+
8793
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
94+
error = git_status_list_new(&out, PHP_GIT2_V(_repo, repository), opts);
95+
if (php_git2_check_error(error, "git_status_list_new" TSRMLS_CC)) {
96+
RETURN_FALSE;
97+
}
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);
88105
}
106+
/* }}} */
89107

90-
/* {{{ proto resource git_status_list_entrycount(statuslist)
91-
*/
108+
/* {{{ proto long git_status_list_entrycount(resource $statuslist)
109+
*/
92110
PHP_FUNCTION(git_status_list_entrycount)
93111
{
94-
zval *statuslist;
95-
php_git2_t *_statuslist;
96-
97-
/* TODO(chobie): implement this */
98-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_entrycount not implemented yet");
99-
return;
112+
size_t result = 0;
113+
zval *statuslist = NULL;
114+
php_git2_t *_statuslist = NULL;
100115

101116
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
102117
"r", &statuslist) == FAILURE) {
103118
return;
104119
}
120+
105121
ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
122+
result = git_status_list_entrycount(PHP_GIT2_V(_statuslist, status_list));
123+
RETURN_LONG(result);
106124
}
125+
/* }}} */
107126

108-
/* {{{ proto resource git_status_byindex(statuslist, idx)
109-
*/
127+
/* {{{ proto resource git_status_byindex(resource $statuslist, long $idx)
128+
*/
110129
PHP_FUNCTION(git_status_byindex)
111130
{
112-
zval *statuslist;
113-
php_git2_t *_statuslist;
114-
long idx;
115-
116-
/* TODO(chobie): implement this */
117-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_byindex not implemented yet");
118-
return;
131+
const git_status_entry *result = NULL;
132+
zval *statuslist = NULL;
133+
php_git2_t *_statuslist = NULL;
134+
long idx = 0;
119135

120136
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
121137
"rl", &statuslist, &idx) == FAILURE) {
122138
return;
123139
}
140+
124141
ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
142+
result = git_status_byindex(PHP_GIT2_V(_statuslist, status_list), idx);
143+
/* TODO(chobie): implement this */
125144
}
145+
/* }}} */
126146

127-
/* {{{ proto void git_status_list_free(statuslist)
128-
*/
147+
/* {{{ proto void git_status_list_free(resource $statuslist)
148+
*/
129149
PHP_FUNCTION(git_status_list_free)
130150
{
131-
zval *statuslist;
132-
php_git2_t *_statuslist;
133-
134-
/* TODO(chobie): implement this */
135-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_free not implemented yet");
136-
return;
151+
zval *statuslist = NULL;
152+
php_git2_t *_statuslist = NULL;
137153

138154
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
139155
"r", &statuslist) == FAILURE) {
140156
return;
141157
}
158+
142159
ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
160+
if (_statuslist->should_free_v) {
161+
git_status_list_free(PHP_GIT2_V(_statuslist, status_list));
162+
};
163+
zval_ptr_dtor(&statuslist);
143164
}
165+
/* }}} */
144166

145-
/* {{{ proto long git_status_should_ignore(ignored, repo, path)
146-
*/
167+
/* {{{ proto long git_status_should_ignore(resource $repo, string $path)
168+
*/
147169
PHP_FUNCTION(git_status_should_ignore)
148170
{
149-
long ignored;
150-
zval *repo;
151-
php_git2_t *_repo;
152-
char *path = {0};
153-
int path_len;
154-
155-
/* TODO(chobie): implement this */
156-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_should_ignore not implemented yet");
157-
return;
171+
int ignored = 0;
172+
zval *repo = NULL;
173+
php_git2_t *_repo = NULL;
174+
char *path = NULL;
175+
int path_len = 0;
176+
int error = 0;
158177

159178
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
160-
"lrs", &ignored, &repo, &path, &path_len) == FAILURE) {
179+
"rs", &repo, &path, &path_len) == FAILURE) {
161180
return;
162181
}
182+
163183
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);
164190
}
191+
/* }}} */
165192

0 commit comments

Comments
 (0)