@@ -63,6 +63,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_exists, 0,0,1)
6363 ZEND_ARG_INFO (0 , exists )
6464ZEND_END_ARG_INFO ()
6565
66+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_repository_lookup , 0 ,0 ,1 )
67+ ZEND_ARG_INFO (0 , lookup )
68+ ZEND_ARG_INFO (0 , type )
69+ ZEND_END_ARG_INFO ()
70+
6671/*
6772{{{ proto: Git2\Repsotiroy::__construct(string $path)
6873*/
@@ -283,7 +288,7 @@ PHP_METHOD(git2_repository, discover)
283288 return ;
284289 }
285290
286- if (git_repository_discover (& path_buffer ,path_size ,start_path ,(int )across_fs , ceiling_dirs ) == GIT_SUCCESS ) {
291+ if (git_repository_discover (path_buffer ,path_size ,( const char * ) start_path ,(int )across_fs , ( const char * ) ceiling_dirs ) == GIT_SUCCESS ) {
287292 RETVAL_STRING (path_buffer , 1 );
288293 } else {
289294 RETURN_FALSE ;
@@ -326,6 +331,47 @@ PHP_METHOD(git2_repository, exists)
326331/* }}} */
327332
328333
334+ /*
335+ {{{ proto: Git2\Repsotiroy::lookup(string $sha1[, int type = GIT_OBJ_ANY])
336+ */
337+ PHP_METHOD (git2_repository , lookup )
338+ {
339+ char * hash ;
340+ int error , hash_len = 0 ;
341+ git_odb * odb ;
342+ git_oid id ;
343+ git_object * object ;
344+ long type = GIT_OBJ_ANY ;
345+ php_git2_repository * m_repository ;
346+
347+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
348+ "s|l" , & hash , & hash_len , type ) == FAILURE ) {
349+ return ;
350+ }
351+
352+ m_repository = PHP_GIT2_GET_OBJECT (php_git2_repository , getThis ());
353+ if (git_repository_odb (& odb , m_repository -> repository ) == GIT_SUCCESS ) {
354+ zval * result = NULL ;
355+
356+ if (git_oid_fromstrn (& id , hash , hash_len ) != GIT_SUCCESS ) {
357+ RETURN_FALSE ;
358+ }
359+
360+ if (hash_len < GIT_OID_HEXSZ ) {
361+ error = git_object_lookup_prefix (& object , m_repository -> repository , & id , hash_len , (git_otype )type );
362+ } else {
363+ error = git_object_lookup (& object , m_repository -> repository , & id , (git_otype )type );
364+ }
365+
366+ result = php_git2_object_new (m_repository , object TSRMLS_CC );
367+ RETVAL_ZVAL (result ,0 ,1 );
368+ } else {
369+ /* @todo: throws an exception */
370+ RETURN_FALSE ;
371+ }
372+ }
373+ /* }}} */
374+
329375
330376static zend_function_entry php_git2_repository_methods [] = {
331377 PHP_ME (git2_repository , __construct , arginfo_git2_repository___construct , ZEND_ACC_PUBLIC )
@@ -338,6 +384,13 @@ static zend_function_entry php_git2_repository_methods[] = {
338384 PHP_ME (git2_repository , init , arginfo_git2_repository_init , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
339385 PHP_ME (git2_repository , discover , arginfo_git2_repository_discover , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
340386 PHP_ME (git2_repository , exists , arginfo_git2_repository_exists , ZEND_ACC_PUBLIC )
387+ #ifdef lookup
388+ #undef lookup
389+ #endif
390+ PHP_ME (git2_repository , lookup , arginfo_git2_repository_lookup , ZEND_ACC_PUBLIC )
391+ #ifndef lookup
392+ #define lookup php_lookup
393+ #endif
341394 {NULL ,NULL ,NULL }
342395};
343396
0 commit comments