@@ -44,6 +44,12 @@ zend_object_value php_git2_blob_new(zend_class_entry *ce TSRMLS_DC)
4444 return retval ;
4545}
4646
47+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_blob_create , 0 ,0 ,2 )
48+ ZEND_ARG_INFO (0 , repository )
49+ ZEND_ARG_INFO (0 , contents )
50+ ZEND_END_ARG_INFO ()
51+
52+
4753
4854/*
4955{{{ proto: Git2\Blob::__toString()
@@ -67,9 +73,43 @@ PHP_METHOD(git2_blob, __toString)
6773}
6874/* }}} */
6975
76+ /*
77+ {{{ proto: Git2\Blob::create(Git2\Repository $repository, string $contents)
78+ */
79+ PHP_METHOD (git2_blob , create )
80+ {
81+ char * contents ;
82+ int contents_len , error = 0 ;
83+ zval * repository ;
84+ php_git2_repository * m_repository ;
85+ char oid_out [GIT_OID_HEXSZ ] = {0 };
86+ git_oid oid ;
87+
88+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
89+ "Os" , & repository , git2_repository_class_entry , & contents , & contents_len ) == FAILURE ) {
90+ return ;
91+ }
92+
93+ m_repository = PHP_GIT2_GET_OBJECT (php_git2_repository , repository );
94+
95+ if (m_repository != NULL ) {
96+ if (m_repository -> repository == NULL ) {
97+ RETURN_FALSE ;
98+ }
99+
100+ error = git_blob_create_frombuffer (& oid , m_repository -> repository , contents , contents_len );
101+ git_oid_fmt (oid_out , & oid );
102+ RETVAL_STRINGL (oid_out ,GIT_OID_HEXSZ ,1 );
103+ } else {
104+ RETURN_FALSE ;
105+ }
106+ }
107+ /* }}} */
108+
70109
71110static zend_function_entry php_git2_blob_methods [] = {
72- PHP_ME (git2_blob , __toString , NULL , ZEND_ACC_PUBLIC )
111+ PHP_ME (git2_blob , __toString , NULL , ZEND_ACC_PUBLIC )
112+ PHP_ME (git2_blob , create , arginfo_git2_blob_create , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
73113 {NULL ,NULL ,NULL }
74114};
75115
0 commit comments