Skip to content

Commit 7a81f1b

Browse files
committed
[tag] add foreach function
1 parent bf9b675 commit 7a81f1b

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

php_git2.c

+22
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,28 @@ static zend_function_entry php_git2_functions[] = {
558558
PHP_FE(git_merge_result_fastforward_oid, arginfo_git_merge_result_fastforward_oid)
559559
PHP_FE(git_merge_result_free, arginfo_git_merge_result_free)
560560

561+
/* tag */
562+
PHP_FE(git_tag_lookup, arginfo_git_tag_lookup)
563+
PHP_FE(git_tag_lookup_prefix, arginfo_git_tag_lookup_prefix)
564+
PHP_FE(git_tag_free, arginfo_git_tag_free)
565+
PHP_FE(git_tag_id, arginfo_git_tag_id)
566+
PHP_FE(git_tag_owner, arginfo_git_tag_owner)
567+
PHP_FE(git_tag_target, arginfo_git_tag_target)
568+
PHP_FE(git_tag_target_id, arginfo_git_tag_target_id)
569+
PHP_FE(git_tag_target_type, arginfo_git_tag_target_type)
570+
PHP_FE(git_tag_name, arginfo_git_tag_name)
571+
PHP_FE(git_tag_tagger, arginfo_git_tag_tagger)
572+
PHP_FE(git_tag_message, arginfo_git_tag_message)
573+
PHP_FE(git_tag_create, arginfo_git_tag_create)
574+
PHP_FE(git_tag_annotation_create, arginfo_git_tag_annotation_create)
575+
PHP_FE(git_tag_create_frombuffer, arginfo_git_tag_create_frombuffer)
576+
PHP_FE(git_tag_create_lightweight, arginfo_git_tag_create_lightweight)
577+
PHP_FE(git_tag_delete, arginfo_git_tag_delete)
578+
PHP_FE(git_tag_list, arginfo_git_tag_list)
579+
PHP_FE(git_tag_list_match, arginfo_git_tag_list_match)
580+
PHP_FE(git_tag_foreach, arginfo_git_tag_foreach)
581+
PHP_FE(git_tag_peel, arginfo_git_tag_peel)
582+
561583
/* misc */
562584
PHP_FE(git_resource_type, arginfo_git_resource_type)
563585
PHP_FE_END

tag.c

+51-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22
#include "php_git2_priv.h"
33
#include "tag.h"
44

5+
static int php_git2_tag_foreach_cb(const char *name, git_oid *oid, void *payload)
6+
{
7+
php_git2_t *result;
8+
zval *param_name, *param_oid, *retval_ptr = NULL;
9+
php_git2_cb_t *p = (php_git2_cb_t*)payload;
10+
int i = 0;
11+
long retval = 0;
12+
char buffer[41] = {0};
13+
GIT2_TSRMLS_SET(p->tsrm_ls)
14+
15+
git_oid_fmt(buffer, oid);
16+
17+
Z_ADDREF_P(p->payload);
18+
MAKE_STD_ZVAL(param_name);
19+
MAKE_STD_ZVAL(param_oid);
20+
ZVAL_STRING(param_name, name, 1);
21+
ZVAL_STRING(param_oid, buffer, 1);
22+
23+
if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, &param_name, &param_oid, &p->payload)) {
24+
zval_ptr_dtor(&retval_ptr);
25+
zend_list_delete(result->resource_id);
26+
return GIT_EUSER;
27+
}
28+
29+
retval = Z_LVAL_P(retval_ptr);
30+
zval_ptr_dtor(&retval_ptr);
31+
zend_list_delete(result->resource_id);
32+
33+
return retval;
34+
}
35+
36+
537
/* {{{ proto resource git_tag_lookup(resource $repo, string $id)
638
*/
739
PHP_FUNCTION(git_tag_lookup)
@@ -482,26 +514,33 @@ PHP_FUNCTION(git_tag_list_match)
482514
/* }}} */
483515

484516

485-
/* {{{ proto long git_tag_foreach(repo, callback, payload)
486-
*/
517+
/* {{{ proto long git_tag_foreach(resource $repo, $callback, $payload)
518+
*/
487519
PHP_FUNCTION(git_tag_foreach)
488520
{
489-
zval *repo;
490-
php_git2_t *_repo;
491-
zval *callback;
492-
php_git2_t *_callback;
493-
zval *payload;
494-
495-
/* TODO(chobie): implement this */
496-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_foreach not implemented yet");
497-
return;
521+
int result = 0, error = 0;
522+
zval *repo = NULL, *callback = NULL;
523+
php_git2_t *_repo = NULL;
524+
zend_fcall_info fci = empty_fcall_info;
525+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
526+
php_git2_cb_t *cb;
527+
zval *payload = NULL;
498528

499529
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
500-
"rrz", &repo, &callback, &payload) == FAILURE) {
530+
"rfz", &repo, &fci, &fcc, &payload) == FAILURE) {
501531
return;
502532
}
533+
503534
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
535+
if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {
536+
RETURN_FALSE;
537+
}
538+
result = git_tag_foreach(PHP_GIT2_V(_repo, repository), php_git2_tag_foreach_cb, cb);
539+
php_git2_cb_free(cb);
540+
RETURN_LONG(result);
504541
}
542+
/* }}} */
543+
505544

506545
/* {{{ proto resource git_tag_peel(resource $tag)
507546
*/

0 commit comments

Comments
 (0)