@@ -118,7 +118,7 @@ PHP_FUNCTION(git_odb_read)
118118}
119119/* }}} */
120120
121- /* {{{ proto resource git_odb_read_prefix(resource $db, string $short_id, long $len )
121+ /* {{{ proto resource git_odb_read_prefix(resource $db, string $short_id)
122122 */
123123PHP_FUNCTION (git_odb_read_prefix )
124124{
@@ -131,15 +131,15 @@ PHP_FUNCTION(git_odb_read_prefix)
131131 long len = 0 ;
132132
133133 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
134- "rsl " , & db , & short_id , & short_id_len , & len ) == FAILURE ) {
134+ "rs " , & db , & short_id , & short_id_len ) == FAILURE ) {
135135 return ;
136136 }
137137
138138 ZEND_FETCH_RESOURCE (_db , php_git2_t * , & db , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
139139 if (git_oid_fromstrn (& __short_id , short_id , short_id_len )) {
140140 RETURN_FALSE ;
141141 }
142- error = git_odb_read_prefix (& out , PHP_GIT2_V (_db , odb ), & __short_id , len );
142+ error = git_odb_read_prefix (& out , PHP_GIT2_V (_db , odb ), & __short_id , short_id_len );
143143 if (php_git2_check_error (error , "git_odb_read_prefix" TSRMLS_CC )) {
144144 RETURN_FALSE ;
145145 }
@@ -784,14 +784,60 @@ static int php_git2_odb_backend_write(git_odb_backend *backend, const git_oid *o
784784 return retval ;
785785}
786786static int php_git2_odb_backend_read_prefix (git_oid * out_oid ,
787- void * * buffer_p ,
788- size_t * len_p ,
789- git_otype * type_p ,
790- git_odb_backend * backend ,
791- const git_oid * short_oid ,
792- size_t len )
787+ void * * buffer_p ,
788+ size_t * len_p ,
789+ git_otype * type_p ,
790+ git_odb_backend * backend ,
791+ const git_oid * short_oid ,
792+ size_t len )
793793{
794- fprintf (stderr , "READ_PREFIX" );
794+ php_git2_t * result ;
795+ php_git2_odb_backend * php_backend = (php_git2_odb_backend * )backend ;
796+ zval * param_short_oid = NULL , * retval_ptr = NULL ;
797+ php_git2_multi_cb_t * p = php_backend -> multi ;
798+ int i = 0 , retval = 0 ;
799+ GIT2_TSRMLS_SET (p -> tsrm_ls );
800+ char buf [41 ] = {0 };
801+
802+ git_oid_nfmt (buf , len , short_oid );
803+ MAKE_STD_ZVAL (param_short_oid );
804+ ZVAL_STRING (param_short_oid , buf , 1 );
805+
806+ if (php_git2_call_function_v (& p -> callbacks [2 ].fci , & p -> callbacks [2 ].fcc TSRMLS_CC , & retval_ptr , 1 , & param_short_oid )) {
807+ return GIT_EUSER ;
808+ }
809+
810+ if (Z_TYPE_P (retval_ptr ) == IS_ARRAY ) {
811+ zval * * value , * * otype , * * _oid ;
812+ char * pp ;
813+
814+ if (zend_hash_num_elements (Z_ARRVAL_P (retval_ptr )) != 3 ) {
815+ return GIT_ENOTFOUND ;
816+ }
817+
818+ zend_hash_get_current_data (Z_ARRVAL_P (retval_ptr ), (void * * )& value );
819+ pp = git_odb_backend_malloc (backend , Z_STRLEN_PP (value ));
820+ memset (pp , '\0' , Z_STRLEN_PP (value ));
821+ memcpy (pp , Z_STRVAL_PP (value ), Z_STRLEN_PP (value ));
822+
823+ * buffer_p = pp ;
824+ * len_p = Z_STRLEN_PP (value );
825+
826+ zend_hash_move_forward (Z_ARRVAL_P (retval_ptr ));
827+ zend_hash_get_current_data (Z_ARRVAL_P (retval_ptr ), (void * * )& otype );
828+ * type_p = Z_LVAL_PP (otype );
829+
830+ zend_hash_move_forward (Z_ARRVAL_P (retval_ptr ));
831+ zend_hash_get_current_data (Z_ARRVAL_P (retval_ptr ), (void * * )& _oid );
832+ if (git_oid_fromstrn (out_oid , Z_STRVAL_PP (_oid ), Z_STRLEN_PP (_oid )) != GIT_OK ) {
833+ return GIT_EUSER ;
834+ }
835+ } else {
836+ retval = GIT_ENOTFOUND ;
837+ }
838+
839+ zval_ptr_dtor (& retval_ptr );
840+ return retval ;
795841}
796842
797843static int php_git2_odb_backend_read_header (size_t * len_p , git_otype * type_p , git_odb_backend * backend , const git_oid * oid )
@@ -910,6 +956,10 @@ PHP_FUNCTION(git_odb_backend_new)
910956 if (tmp ) {
911957 php_git2_fcall_info_wrapper2 (tmp , & read_header_fci , & read_header_fcc TSRMLS_CC );
912958 }
959+ tmp = php_git2_read_arrval (callbacks , ZEND_STRS ("read_prefix" ) TSRMLS_CC );
960+ if (tmp ) {
961+ php_git2_fcall_info_wrapper2 (tmp , & read_prefix_fci , & read_prefix_fcc TSRMLS_CC );
962+ }
913963 tmp = php_git2_read_arrval (callbacks , ZEND_STRS ("exists" ) TSRMLS_CC );
914964 if (tmp ) {
915965 php_git2_fcall_info_wrapper2 (tmp , & exists_fci , & exists_fcc TSRMLS_CC );
0 commit comments