3434
3535# include "php.h"
3636# include "ext/spl/spl_exceptions.h"
37+ # include <date/php_date.h>
3738# include <git2.h>
3839# include <git2/odb_backend.h>
3940
@@ -48,8 +49,8 @@ extern PHPAPI zend_class_entry *git2_blob_class_entry;
4849extern PHPAPI zend_class_entry * git2_tree_class_entry ;
4950extern PHPAPI zend_class_entry * git2_tree_builder_class_entry ;
5051extern PHPAPI zend_class_entry * git2_tree_entry_class_entry ;
51- extern PHPAPI zend_class_entry * git2_tree_signature_entry ;
52- extern PHPAPI zend_class_entry * git2_walker_entry ;
52+ extern PHPAPI zend_class_entry * git2_signature_class_entry ;
53+ extern PHPAPI zend_class_entry * git2_walker_class_entry ;
5354
5455typedef struct {
5556 zend_object zo ;
@@ -129,4 +130,38 @@ extern int php_git2_add_protected_property_string_ex(zval *object, char *name, i
129130extern zval * php_git2_object_new (php_git2_repository * repository , git_object * object TSRMLS_DC );
130131extern int php_git2_call_user_function_v (zval * * retval , zval * obj , char * method , unsigned int method_len , unsigned int param_count , ...);
131132
133+ extern inline void php_git2_create_signature (zval * object , char * name , int name_len , char * email , int email_len , zval * date TSRMLS_DC );
134+
135+
136+ static inline php_git2_create_signature_from_commit (zval * * object , php_git2_commit * commit , int type TSRMLS_DC )
137+ {
138+ zval * ret ;
139+ zval * z_signature , * date ;
140+ char time_str [12 ] = {0 };
141+ git_signature * author ;
142+ php_git2_signature * m_signature ;
143+
144+ if (type == 0 ) {
145+ author = git_commit_author (commit );
146+ } else {
147+ author = git_commit_committer (commit );
148+ }
149+
150+ MAKE_STD_ZVAL (ret );
151+ MAKE_STD_ZVAL (date );
152+
153+ object_init_ex (ret ,git2_signature_class_entry );
154+ m_signature = PHP_GIT2_GET_OBJECT (php_git2_signature , ret );
155+ add_property_string_ex (ret ,"name" ,sizeof ("name" ), author -> name ,1 TSRMLS_CC );
156+ add_property_string_ex (ret ,"email" ,sizeof ("email" ),author -> email ,1 TSRMLS_CC );
157+
158+ php_date_instantiate (php_date_get_date_ce (), date TSRMLS_CC );
159+ snprintf (time_str ,12 ,"%c%ld" ,'@' ,author -> when .time );
160+ php_date_initialize (zend_object_store_get_object (date TSRMLS_CC ), time_str , strlen (time_str ), NULL , NULL , 0 TSRMLS_CC );
161+
162+ add_property_zval (ret ,"time" ,date );
163+ zval_ptr_dtor (& date );
164+ * object = ret ;
165+ }
166+
132167#endif /* PHP_GIT2_H */
0 commit comments