@@ -44,28 +44,39 @@ zend_object_value php_git2_tree_builder_new(zend_class_entry *ce TSRMLS_DC)
4444 return retval ;
4545}
4646
47- ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_tree_builder___construct , 0 ,0 ,0 )
47+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_tree_builder___construct , 0 ,0 ,1 )
48+ ZEND_ARG_INFO (0 , tree )
4849ZEND_END_ARG_INFO ()
4950
50- ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_tree_builder_insert , 0 ,0 ,0 )
51+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_tree_builder_insert , 0 ,0 ,1 )
5152 ZEND_ARG_INFO (0 , entry )
5253ZEND_END_ARG_INFO ()
5354
54- ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_tree_builder_remove , 0 ,0 ,0 )
55- ZEND_END_ARG_INFO ()
56-
57- ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_tree_builder_write , 0 ,0 ,0 )
55+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_tree_builder_remove , 0 ,0 ,1 )
56+ ZEND_ARG_INFO (0 , name )
5857ZEND_END_ARG_INFO ()
5958
6059/*
61- {{{ proto: Git2\TreeBuilder::__construct()
60+ {{{ proto: Git2\TreeBuilder::__construct([Git2\Tree $tree] )
6261*/
6362PHP_METHOD (git2_tree_builder , __construct )
6463{
6564 git_treebuilder * builder ;
65+ zval * z_tree = NULL ;
66+ git_tree * tree = NULL ;
67+ php_git2_tree * m_tree ;
6668 php_git2_tree_builder * m_builder ;
69+
70+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
71+ "|O" , & z_tree , git2_tree_class_entry ) == FAILURE ) {
72+ return ;
73+ }
74+ if (z_tree != NULL ) {
75+ m_tree = PHP_GIT2_GET_OBJECT (php_git2_tree , z_tree );
76+ tree = m_tree -> tree ;
77+ }
6778
68- git_treebuilder_create (& builder , NULL );
79+ git_treebuilder_create (& builder , tree );
6980 m_builder = PHP_GIT2_GET_OBJECT (php_git2_tree_builder , getThis ());
7081 m_builder -> builder = builder ;
7182}
@@ -84,27 +95,40 @@ PHP_METHOD(git2_tree_builder, insert)
8495 char * name ;
8596
8697 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
87- "z " , & m_entry ) == FAILURE ) {
98+ "O " , & m_entry , git2_tree_entry_class_entry ) == FAILURE ) {
8899 return ;
89100 }
90101
91102 z_name = zend_read_property (git2_tree_entry_class_entry , m_entry ,"name" ,sizeof ("name" )- 1 , 0 TSRMLS_CC );
92103 z_oid = zend_read_property (git2_tree_entry_class_entry , m_entry ,"oid" ,sizeof ("oid" )- 1 , 0 TSRMLS_CC );
93104 z_attributes = zend_read_property (git2_tree_entry_class_entry , m_entry ,"attributes" ,sizeof ("attributes" )- 1 , 0 TSRMLS_CC );
105+ m_builder = PHP_GIT2_GET_OBJECT (php_git2_tree_builder , getThis ());
94106
95107 name = Z_STRVAL_P (z_name );
96108 attributes = (unsigned int )Z_LVAL_P (z_attributes );
97109
98- git_oid_fromstrn (& oid , Z_STRVAL_P (z_name ), Z_STRLEN_P (z_name ));
110+ git_oid_fromstrn (& oid , Z_STRVAL_P (z_oid ), Z_STRLEN_P (z_oid ));
99111 error = git_treebuilder_insert (NULL , m_builder -> builder , name , & oid , attributes );
100112}
101113/* }}} */
102114
103115/*
104- {{{ proto: Git2\TreeBuilder::remove()
116+ {{{ proto: Git2\TreeBuilder::remove(string $name )
105117*/
106118PHP_METHOD (git2_tree_builder , remove )
107119{
120+ char * name ;
121+ int name_len = 0 ;
122+ php_git2_tree_builder * m_builder ;
123+ int error = 0 ;
124+
125+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
126+ "s" , & name , & name_len ) == FAILURE ) {
127+ return ;
128+ }
129+ m_builder = PHP_GIT2_GET_OBJECT (php_git2_tree_builder , getThis ());
130+
131+ RETURN_LONG (git_treebuilder_remove (m_builder -> builder , name ));
108132}
109133/* }}} */
110134
@@ -113,6 +137,28 @@ PHP_METHOD(git2_tree_builder, remove)
113137*/
114138PHP_METHOD (git2_tree_builder , write )
115139{
140+ git_oid oid ;
141+ php_git2_repository * m_repository ;
142+ php_git2_tree_builder * m_builder ;
143+ char oid_out [GIT_OID_HEXSZ + 1 ] = {0 };
144+ zval * repository ;
145+ int error = 0 ;
146+
147+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
148+ "O" , & repository , git2_repository_class_entry ) == FAILURE ) {
149+ return ;
150+ }
151+
152+ m_builder = PHP_GIT2_GET_OBJECT (php_git2_tree_builder , getThis ());
153+ m_repository = PHP_GIT2_GET_OBJECT (php_git2_tree_builder , repository );
154+
155+ error = git_treebuilder_write (& oid , m_repository -> repository , m_builder -> builder );
156+ if (error != GIT_SUCCESS ) {
157+ RETURN_FALSE ;
158+ }
159+
160+ git_oid_fmt (oid_out , & oid );
161+ RETURN_STRINGL (oid_out ,GIT_OID_HEXSZ ,1 );
116162}
117163/* }}} */
118164
@@ -121,6 +167,10 @@ PHP_METHOD(git2_tree_builder, write)
121167*/
122168PHP_METHOD (git2_tree_builder , clear )
123169{
170+ php_git2_tree_builder * m_builder ;
171+ m_builder = PHP_GIT2_GET_OBJECT (php_git2_tree_builder , getThis ());
172+
173+ git_treebuilder_clear (m_builder -> builder );
124174}
125175/* }}} */
126176
@@ -129,7 +179,8 @@ static zend_function_entry php_git2_tree_builder_methods[] = {
129179 PHP_ME (git2_tree_builder , insert , arginfo_git2_tree_builder_insert , ZEND_ACC_PUBLIC )
130180 PHP_ME (git2_tree_builder , remove , arginfo_git2_tree_builder_remove , ZEND_ACC_PUBLIC )
131181 PHP_ME (git2_tree_builder , clear , NULL , ZEND_ACC_PUBLIC )
132- PHP_ME (git2_tree_builder , write , arginfo_git2_tree_builder_write , ZEND_ACC_PUBLIC )
182+ PHP_ME (git2_tree_builder , write , NULL , ZEND_ACC_PUBLIC )
183+ /* @todo: filter */
133184 {NULL ,NULL ,NULL }
134185};
135186
0 commit comments