@@ -80,6 +80,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_add_alternate, 0, 0, 2)
8080 ZEND_ARG_INFO (0 , priority )
8181ZEND_END_ARG_INFO ()
8282
83+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git_get_references , 0 , 0 , 1 )
84+ ZEND_ARG_INFO (0 , flag )
85+ ZEND_END_ARG_INFO ()
86+
8387static void php_git_repository_free_storage (php_git_repository_t * obj TSRMLS_DC )
8488{
8589 // if added some backend. free backend before free zend_object.
@@ -500,6 +504,64 @@ PHP_METHOD(git_repository, lookupRef)
500504 RETURN_ZVAL (ref ,0 ,0 );
501505}
502506
507+ PHP_METHOD (git_repository , getReferences )
508+ {
509+ php_git_repository_t * this = (php_git_repository_t * ) zend_object_store_get_object (getThis () TSRMLS_CC );
510+ git_strarray * list = malloc (sizeof (git_strarray ));
511+ int result ;
512+ int i = 0 ;
513+ git_reference * reference ;
514+ zval * references ;
515+ git_rtype type ;
516+ char out [GIT_OID_HEXSZ + 1 ] = {0 };
517+
518+ git_reference_listall (list ,this -> repository ,GIT_REF_LISTALL );
519+
520+ MAKE_STD_ZVAL (references );
521+ array_init (references );
522+ for (i = 0 ; i < list -> count ; i ++ ){
523+ zval * ref ;
524+
525+ // FIXME
526+ result = git_reference_lookup (& reference , this -> repository , list -> strings [i ]);
527+ if (result != GIT_SUCCESS ) {
528+ zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 TSRMLS_CC ,
529+ "Can't find specified reference." );
530+ RETURN_FALSE ;
531+ }
532+
533+ MAKE_STD_ZVAL (ref );
534+ object_init_ex (ref , git_reference_class_entry );
535+ php_git_reference_t * refobj = (php_git_reference_t * ) zend_object_store_get_object (ref TSRMLS_CC );
536+ refobj -> object = reference ;
537+
538+ add_property_string_ex (ref ,"name" , sizeof ("name" ), (char * )git_reference_name (reference ), 1 TSRMLS_CC );
539+
540+ type = git_reference_type (reference );
541+ if (type == GIT_REF_SYMBOLIC ) {
542+ const char * target = git_reference_target (reference );
543+ if (target != NULL ) {
544+ add_property_string_ex (ref ,"target" ,sizeof ("target" ),(char * )target , 1 TSRMLS_CC );
545+ }
546+ int rr = git_reference_resolve (& refobj -> object ,reference );
547+ if (rr != GIT_SUCCESS ){
548+ zend_throw_exception_ex (spl_ce_InvalidArgumentException , 0 TSRMLS_CC ,
549+ "something wrong" );
550+ RETURN_FALSE ;
551+ }
552+ }
553+
554+ git_oid_to_string (out ,GIT_OID_HEXSZ + 1 ,git_reference_oid (refobj -> object ));
555+ add_property_string_ex (ref ,"oid" ,sizeof ("oid" ),out , 1 TSRMLS_CC );
556+ memset (out ,'\0' ,GIT_OID_HEXSZ + 1 );
557+ //
558+
559+ add_next_index_zval (references , ref );
560+ }
561+
562+ git_strarray_free (list );
563+ RETURN_ZVAL (references ,0 ,0 );
564+ }
503565
504566PHP_METHOD (git_repository , open3 )
505567{
0 commit comments