@@ -76,6 +76,45 @@ static PHP_METHOD(Reference, dwim) {
7676 }
7777}
7878
79+ ZEND_BEGIN_ARG_INFO_EX (arginfo_reference_list , 0 , 0 , 1 )
80+ ZEND_ARG_OBJ_INFO (0 , repository , Git2 \\Repository , 0 )
81+ ZEND_END_ARG_INFO ()
82+
83+ static int git2_reference_list_callback (git_reference * ref , void * payload ) {
84+ git2_reference_object_t * intern ;
85+ zval * obj ;
86+ ALLOC_ZVAL (obj );
87+
88+ object_init_ex (obj , php_git2_reference_ce );
89+ intern = (git2_reference_object_t * )Z_OBJ_P (obj );
90+ intern -> ref = ref ;
91+
92+ add_next_index_zval ((zval * )payload , obj );
93+ return 0 ;
94+ }
95+
96+ static PHP_METHOD (Reference , list ) {
97+ zval * z_repo ;
98+ git_repository * repo ;
99+
100+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "O" , & z_repo , git2_reference_class_entry ()) == FAILURE )
101+ return ;
102+
103+ repo = git2_repository_fetch_from_zval (z_repo );
104+ if (repo == NULL ) {
105+ git2_throw_exception (0 TSRMLS_CC , "Parameter must be a valid git repository" );
106+ return ;
107+ }
108+
109+ array_init (return_value );
110+
111+ int res = git_reference_foreach (repo , git2_reference_list_callback , & return_value );
112+ if (res != 0 ) {
113+ git2_throw_last_error ();
114+ return ;
115+ }
116+ }
117+
79118
80119#define GIT2_REFERENCE_FETCH () git2_reference_object_t *intern = (git2_reference_object_t*)Z_OBJ_P(getThis()); \
81120 if (intern->ref == NULL) { \
@@ -219,6 +258,7 @@ static void php_git2_reference_free_object(zend_object *object TSRMLS_DC) {
219258static zend_function_entry git2_reference_methods [] = {
220259 PHP_ME (Reference , lookup_name , arginfo_reference_lookup_name , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
221260 PHP_ME (Reference , dwim , arginfo_reference_dwim , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
261+ PHP_ME (Reference , list , arginfo_reference_list , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
222262 PHP_ME (Reference , name , arginfo_reference_name , ZEND_ACC_PUBLIC )
223263 PHP_ME (Reference , is_branch , arginfo_reference_is_branch , ZEND_ACC_PUBLIC )
224264 PHP_ME (Reference , is_remote , arginfo_reference_is_remote , ZEND_ACC_PUBLIC )
0 commit comments