Skip to content

Commit 08e3000

Browse files
committed
[ref] add foreach_glob
1 parent 0543448 commit 08e3000

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

reference.c

+29-23
Original file line numberDiff line numberDiff line change
@@ -263,23 +263,25 @@ PHP_FUNCTION(git_reference_target_peel)
263263
RETURN_STRING(out, 1);
264264
}
265265

266-
/* {{{ proto resource git_reference_symbolic_target(ref)
267-
*/
266+
/* {{{ proto string git_reference_symbolic_target(resource $ref)
267+
*/
268268
PHP_FUNCTION(git_reference_symbolic_target)
269269
{
270-
zval *ref;
271-
php_git2_t *_ref;
272-
273-
/* TODO(chobie): implement this */
274-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_symbolic_target not implemented yet");
275-
return;
270+
const char *result = NULL;
271+
zval *ref = NULL;
272+
php_git2_t *_ref = NULL;
276273

277274
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
278275
"r", &ref) == FAILURE) {
279276
return;
280277
}
278+
281279
ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
280+
result = git_reference_symbolic_target(PHP_GIT2_V(_ref, reference));
281+
RETURN_STRING(result, 1);
282282
}
283+
/* }}} */
284+
283285

284286
/* {{{ proto resource git_reference_type(ref)
285287
*/
@@ -731,29 +733,33 @@ PHP_FUNCTION(git_reference_iterator_free)
731733
}
732734
/* }}} */
733735

734-
735-
/* {{{ proto long git_reference_foreach_glob(repo, glob, callback, payload)
736-
*/
736+
/* {{{ proto long git_reference_foreach_glob(resource $repo, string $glob, $callback, $payload)
737+
*/
737738
PHP_FUNCTION(git_reference_foreach_glob)
738739
{
739-
zval *repo;
740-
php_git2_t *_repo;
741-
char *glob = {0};
742-
int glob_len;
743-
zval *callback;
744-
php_git2_t *_callback;
745-
zval *payload;
746-
747-
/* TODO(chobie): implement this */
748-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_foreach_glob not implemented yet");
749-
return;
740+
int result = 0, glob_len = 0, error = 0;
741+
zval *repo = NULL, *callback = NULL;
742+
php_git2_t *_repo = NULL;
743+
char *glob = NULL;
744+
zend_fcall_info fci = empty_fcall_info;
745+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
746+
php_git2_cb_t *cb;
747+
zval *payload = NULL;
750748

751749
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
752-
"rsrz", &repo, &glob, &glob_len, &callback, &payload) == FAILURE) {
750+
"rsfz", &repo, &glob, &glob_len, &fci, &fcc, &payload) == FAILURE) {
753751
return;
754752
}
753+
755754
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
755+
if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {
756+
RETURN_FALSE;
757+
}
758+
result = git_reference_foreach_glob(PHP_GIT2_V(_repo, repository), glob, php_git2_reference_foreach_name_cb, cb);
759+
php_git2_cb_free(cb);
760+
RETURN_LONG(result);
756761
}
762+
/* }}} */
757763

758764
/* {{{ proto long git_reference_has_log(ref)
759765
*/

0 commit comments

Comments
 (0)