@@ -45,6 +45,32 @@ static PHP_METHOD(Reference, lookup_name) {
4545 }
4646}
4747
48+ static PHP_METHOD (Reference , dwim ) {
49+ zval * z_repo ;
50+ git_repository * repo ;
51+ char * name ;
52+ size_t name_len ;
53+ git2_reference_object_t * intern ;
54+
55+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "Os" , & z_repo , git2_reference_class_entry (), & name , & name_len ) == FAILURE )
56+ return ;
57+
58+ repo = git2_repository_fetch_from_zval (z_repo );
59+ if (repo == NULL ) {
60+ git2_throw_exception (0 TSRMLS_CC , "Parameter must be a valid git repository" );
61+ return ;
62+ }
63+
64+ object_init_ex (return_value , php_git2_reference_ce );
65+ intern = (git2_reference_object_t * )Z_OBJ_P (return_value );
66+ int res = git_reference_dwim (& intern -> ref , repo , name );
67+
68+ if (res != 0 ) {
69+ git2_throw_last_error ();
70+ return ;
71+ }
72+ }
73+
4874
4975#define GIT2_REFERENCE_FETCH () git2_reference_object_t *intern = (git2_reference_object_t*)Z_OBJ_P(getThis()); \
5076 if (intern->ref == NULL) { \
@@ -187,6 +213,7 @@ static void php_git2_reference_free_object(zend_object *object TSRMLS_DC) {
187213
188214static zend_function_entry git2_reference_methods [] = {
189215 PHP_ME (Reference , lookup_name , arginfo_reference_lookup_name , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
216+ PHP_ME (Reference , dwim , arginfo_reference_lookup_name , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
190217 PHP_ME (Reference , name , arginfo_reference_name , ZEND_ACC_PUBLIC )
191218 PHP_ME (Reference , is_branch , arginfo_reference_is_branch , ZEND_ACC_PUBLIC )
192219 PHP_ME (Reference , is_remote , arginfo_reference_is_remote , ZEND_ACC_PUBLIC )
0 commit comments