Skip to content

Commit

Permalink
reflist (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicalTux committed Nov 21, 2017
1 parent 0b80858 commit 32d63a2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions git2_reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,45 @@ static PHP_METHOD(Reference, dwim) {
}
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_reference_list, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, repository, Git2\\Repository, 0)
ZEND_END_ARG_INFO()

static int git2_reference_list_callback(git_reference *ref, void *payload) {
git2_reference_object_t *intern;
zval *obj;
ALLOC_ZVAL(obj);

object_init_ex(obj, php_git2_reference_ce);
intern = (git2_reference_object_t*)Z_OBJ_P(obj);
intern->ref = ref;

add_next_index_zval((zval*)payload, obj);
return 0;
}

static PHP_METHOD(Reference, list) {
zval *z_repo;
git_repository *repo;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &z_repo, git2_reference_class_entry()) == FAILURE)
return;

repo = git2_repository_fetch_from_zval(z_repo);
if (repo == NULL) {
git2_throw_exception(0 TSRMLS_CC, "Parameter must be a valid git repository");
return;
}

array_init(return_value);

int res = git_reference_foreach(repo, git2_reference_list_callback, &return_value);
if (res != 0) {
git2_throw_last_error();
return;
}
}


#define GIT2_REFERENCE_FETCH() git2_reference_object_t *intern = (git2_reference_object_t*)Z_OBJ_P(getThis()); \
if (intern->ref == NULL) { \
Expand Down Expand Up @@ -219,6 +258,7 @@ static void php_git2_reference_free_object(zend_object *object TSRMLS_DC) {
static zend_function_entry git2_reference_methods[] = {
PHP_ME(Reference, lookup_name, arginfo_reference_lookup_name, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Reference, dwim, arginfo_reference_dwim, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Reference, list, arginfo_reference_list, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Reference, name, arginfo_reference_name, ZEND_ACC_PUBLIC)
PHP_ME(Reference, is_branch, arginfo_reference_is_branch, ZEND_ACC_PUBLIC)
PHP_ME(Reference, is_remote, arginfo_reference_is_remote, ZEND_ACC_PUBLIC)
Expand Down

0 comments on commit 32d63a2

Please sign in to comment.