11#include "php_git2.h"
22#include "git2_exception.h"
3+ #include "git2_repository.h"
34#include "git2_reference.h"
45#include "git2_commit.h"
56#include "git2_tree.h"
@@ -13,6 +14,37 @@ typedef struct _git2_reference_object {
1314 git_reference * ref ;
1415} git2_reference_object_t ;
1516
17+ ZEND_BEGIN_ARG_INFO_EX (arginfo_reference_lookup_name , 0 , 0 , 2 )
18+ ZEND_ARG_OBJ_INFO (0 , repository , Git2 \\Repository , 0 )
19+ ZEND_ARG_INFO (0 , name )
20+ ZEND_END_ARG_INFO ()
21+
22+ static PHP_METHOD (Reference , lookup_name ) {
23+ zval * z_repo ;
24+ git_repository * repo ;
25+ char * name ;
26+ size_t name_len ;
27+ git2_reference_object_t * intern ;
28+
29+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "Os" , & z_repo , git2_reference_class_entry (), & name , & name_len ) == FAILURE )
30+ return ;
31+
32+ repo = git2_repository_fetch_from_zval (z_repo );
33+ if (repo == NULL ) {
34+ git2_throw_exception (0 TSRMLS_CC , "Parameter must be a valid git repository" );
35+ return ;
36+ }
37+
38+ object_init_ex (return_value , php_git2_reference_ce );
39+ intern = (git2_reference_object_t * )Z_OBJ_P (return_value );
40+ int res = git_reference_lookup (& intern -> ref , repo , name );
41+
42+ if (res != 0 ) {
43+ git2_throw_last_error ();
44+ return ;
45+ }
46+ }
47+
1648
1749#define GIT2_REFERENCE_FETCH () git2_reference_object_t *intern = (git2_reference_object_t*)Z_OBJ_P(getThis()); \
1850 if (intern->ref == NULL) { \
@@ -154,6 +186,7 @@ static void php_git2_reference_free_object(zend_object *object TSRMLS_DC) {
154186}
155187
156188static zend_function_entry git2_reference_methods [] = {
189+ PHP_ME (Reference , lookup_name , arginfo_reference_lookup_name , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
157190 PHP_ME (Reference , name , arginfo_reference_name , ZEND_ACC_PUBLIC )
158191 PHP_ME (Reference , is_branch , arginfo_reference_is_branch , ZEND_ACC_PUBLIC )
159192 PHP_ME (Reference , is_remote , arginfo_reference_is_remote , ZEND_ACC_PUBLIC )
0 commit comments