66 */ 
77PHP_FUNCTION (git_branch_create )
88{
9- 	php_git2_t  * result  =  NULL ;
9+ 	php_git2_t  * result  =  NULL ,  * _repo   =   NULL ,  * _target   =   NULL ;
1010	git_reference  * out  =  NULL ;
11- 	zval  * repo  =  NULL ;
12- 	php_git2_t  * _repo  =  NULL ;
11+ 	zval  * repo  =  NULL , * target  =  NULL ;
1312	char  * branch_name  =  NULL ;
14- 	int  branch_name_len  =  0 ;
15- 	zval  * target  =  NULL ;
16- 	php_git2_t  * _target  =  NULL ;
13+ 	int  branch_name_len  =  0 , error  =  0 ;
1714	long  force  =  0 ;
18- 	int  error  =  0 ;
1915
2016	if  (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
2117		"rsrl" , & repo , & branch_name , & branch_name_len , & target , & force ) ==  FAILURE ) {
@@ -28,12 +24,10 @@ PHP_FUNCTION(git_branch_create)
2824	if  (php_git2_check_error (error , "git_branch_create"  TSRMLS_CC )) {
2925		RETURN_FALSE ;
3026	}
31- 	PHP_GIT2_MAKE_RESOURCE (result );
32- 	PHP_GIT2_V (result , reference ) =  out ;
33- 	result -> type  =  PHP_GIT2_TYPE_REFERENCE ;
34- 	result -> resource_id  =  PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
35- 	result -> should_free_v  =  1 ;
36- 	ZVAL_RESOURCE (return_value , result -> resource_id );
27+ 	if  (php_git2_make_resource (& result , PHP_GIT2_TYPE_REFERENCE , out , 1  TSRMLS_CC )) {
28+ 		RETURN_FALSE ;
29+ 	}
30+ 	ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
3731}
3832/* }}} */ 
3933
@@ -63,12 +57,11 @@ PHP_FUNCTION(git_branch_delete)
6357 */ 
6458PHP_FUNCTION (git_branch_iterator_new )
6559{
66- 	php_git2_t  * result  =  NULL ;
60+ 	php_git2_t  * result  =  NULL ,  * _repo   =   NULL ;
6761	git_branch_iterator  * out  =  NULL ;
6862	zval  * repo  =  NULL ;
69- 	php_git2_t  * _repo  =  NULL ;
70- 	long  list_flags  =  0 ;
7163	int  error  =  0 ;
64+ 	long  list_flags  =  0 ;
7265
7366	if  (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
7467		"rl" , & repo , & list_flags ) ==  FAILURE ) {
@@ -80,12 +73,10 @@ PHP_FUNCTION(git_branch_iterator_new)
8073	if  (php_git2_check_error (error , "git_branch_iterator_new"  TSRMLS_CC )) {
8174		RETURN_FALSE ;
8275	}
83- 	PHP_GIT2_MAKE_RESOURCE (result );
84- 	PHP_GIT2_V (result , branch_iterator ) =  out ;
85- 	result -> type  =  PHP_GIT2_TYPE_BRANCH_ITERATOR ;
86- 	result -> resource_id  =  PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
87- 	result -> should_free_v  =  0 ;
88- 	ZVAL_RESOURCE (return_value , result -> resource_id );
76+ 	if  (php_git2_make_resource (& result , PHP_GIT2_TYPE_BRANCH_ITERATOR , out , 1  TSRMLS_CC )) {
77+ 		RETURN_FALSE ;
78+ 	}
79+ 	ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
8980}
9081/* }}} */ 
9182
@@ -94,11 +85,10 @@ PHP_FUNCTION(git_branch_iterator_new)
9485 */ 
9586PHP_FUNCTION (git_branch_next )
9687{
97- 	php_git2_t  * result  =  NULL ;
88+ 	php_git2_t  * result  =  NULL ,  * _iter   =   NULL ;
9889	git_reference  * out  =  NULL ;
99- 	long  out_type  =  0 ;
10090	zval  * iter  =  NULL ;
101- 	php_git2_t   * _iter  =  NULL ;
91+ 	long   out_type  =  0 ;
10292	int  error  =  0 ;
10393
10494	if  (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
@@ -111,16 +101,13 @@ PHP_FUNCTION(git_branch_next)
111101	if  (php_git2_check_error (error , "git_branch_next"  TSRMLS_CC )) {
112102		RETURN_FALSE ;
113103	}
114- 	PHP_GIT2_MAKE_RESOURCE (result );
115- 	PHP_GIT2_V (result , reference ) =  out ;
116- 	result -> type  =  PHP_GIT2_TYPE_REFERENCE ;
117- 	result -> resource_id  =  PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
118- 	result -> should_free_v  =  0 ;
119- 	ZVAL_RESOURCE (return_value , result -> resource_id );
104+ 	if  (php_git2_make_resource (& result , PHP_GIT2_TYPE_REFERENCE , out , 1  TSRMLS_CC )) {
105+ 		RETURN_FALSE ;
106+ 	}
107+ 	ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
120108}
121109/* }}} */ 
122110
123- 
124111/* {{{ proto void git_branch_iterator_free(resource $iter) 
125112 */ 
126113PHP_FUNCTION (git_branch_iterator_free )
@@ -134,8 +121,9 @@ PHP_FUNCTION(git_branch_iterator_free)
134121	}
135122
136123	ZEND_FETCH_RESOURCE (_iter , php_git2_t * , & iter , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
137- 	if  (_iter -> should_free_v ) {
124+ 	if  (GIT2_SHOULD_FREE ( _iter ) ) {
138125		git_branch_iterator_free (PHP_GIT2_V (_iter , branch_iterator ));
126+ 		GIT2_SHOULD_FREE (_iter ) =  0 ;
139127	};
140128	zval_ptr_dtor (& iter );
141129}
@@ -145,14 +133,12 @@ PHP_FUNCTION(git_branch_iterator_free)
145133 */ 
146134PHP_FUNCTION (git_branch_move )
147135{
148- 	php_git2_t  * result  =  NULL ;
136+ 	php_git2_t  * result  =  NULL ,  * _branch   =   NULL ;
149137	git_reference  * out  =  NULL ;
150138	zval  * branch  =  NULL ;
151- 	php_git2_t  * _branch  =  NULL ;
152139	char  * new_branch_name  =  NULL ;
153- 	int  new_branch_name_len  =  0 ;
140+ 	int  new_branch_name_len  =  0 ,  error   =   0 ;
154141	long  force  =  0 ;
155- 	int  error  =  0 ;
156142
157143	if  (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
158144		"rsl" , & branch , & new_branch_name , & new_branch_name_len , & force ) ==  FAILURE ) {
@@ -164,27 +150,24 @@ PHP_FUNCTION(git_branch_move)
164150	if  (php_git2_check_error (error , "git_branch_move"  TSRMLS_CC )) {
165151		RETURN_FALSE ;
166152	}
167- 	PHP_GIT2_MAKE_RESOURCE (result );
168- 	PHP_GIT2_V (result , reference ) =  out ;
169- 	result -> type  =  PHP_GIT2_TYPE_REFERENCE ;
170- 	result -> resource_id  =  PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
171- 	result -> should_free_v  =  0 ;
172- 	ZVAL_RESOURCE (return_value , result -> resource_id );
153+ 	if  (php_git2_make_resource (& result , PHP_GIT2_TYPE_REFERENCE , out , 1  TSRMLS_CC )) {
154+ 		RETURN_FALSE ;
155+ 	}
156+ 	ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
173157}
174158/* }}} */ 
175159
176- /* {{{ proto resource git_branch_lookup(resource $repo, string $branch_name, long $branch_type) 
160+ 
161+ /* {{{ proto resource git_branch_lookup(resource $repo, string $branch_name,  $branch_type) 
177162 */ 
178163PHP_FUNCTION (git_branch_lookup )
179164{
180- 	php_git2_t  * result  =  NULL ;
165+ 	php_git2_t  * result  =  NULL ,  * _repo   =   NULL ;
181166	git_reference  * out  =  NULL ;
182167	zval  * repo  =  NULL ;
183- 	php_git2_t  * _repo  =  NULL ;
184168	char  * branch_name  =  NULL ;
185- 	int  branch_name_len  =  0 ;
169+ 	int  branch_name_len  =  0 ,  error   =   0 ;
186170	long  branch_type  =  0 ;
187- 	int  error  =  0 ;
188171
189172	if  (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
190173		"rsl" , & repo , & branch_name , & branch_name_len , & branch_type ) ==  FAILURE ) {
@@ -196,16 +179,13 @@ PHP_FUNCTION(git_branch_lookup)
196179	if  (php_git2_check_error (error , "git_branch_lookup"  TSRMLS_CC )) {
197180		RETURN_FALSE ;
198181	}
199- 	PHP_GIT2_MAKE_RESOURCE (result );
200- 	PHP_GIT2_V (result , reference ) =  out ;
201- 	result -> type  =  PHP_GIT2_TYPE_REFERENCE ;
202- 	result -> resource_id  =  PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
203- 	result -> should_free_v  =  0 ;
204- 	ZVAL_RESOURCE (return_value , result -> resource_id );
182+ 	if  (php_git2_make_resource (& result , PHP_GIT2_TYPE_REFERENCE , out , 1  TSRMLS_CC )) {
183+ 		RETURN_FALSE ;
184+ 	}
185+ 	ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
205186}
206187/* }}} */ 
207188
208- 
209189/* {{{ proto resource git_branch_name(resource $ref) 
210190 */ 
211191PHP_FUNCTION (git_branch_name )
@@ -234,10 +214,9 @@ PHP_FUNCTION(git_branch_name)
234214 */ 
235215PHP_FUNCTION (git_branch_upstream )
236216{
237- 	php_git2_t  * result  =  NULL ;
217+ 	php_git2_t  * result  =  NULL ,  * _branch   =   NULL ;
238218	git_reference  * out  =  NULL ;
239219	zval  * branch  =  NULL ;
240- 	php_git2_t  * _branch  =  NULL ;
241220	int  error  =  0 ;
242221
243222	if  (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
@@ -250,15 +229,14 @@ PHP_FUNCTION(git_branch_upstream)
250229	if  (php_git2_check_error (error , "git_branch_upstream"  TSRMLS_CC )) {
251230		RETURN_FALSE ;
252231	}
253- 	PHP_GIT2_MAKE_RESOURCE (result );
254- 	PHP_GIT2_V (result , reference ) =  out ;
255- 	result -> type  =  PHP_GIT2_TYPE_REFERENCE ;
256- 	result -> resource_id  =  PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
257- 	result -> should_free_v  =  0 ;
258- 	ZVAL_RESOURCE (return_value , result -> resource_id );
232+ 	if  (php_git2_make_resource (& result , PHP_GIT2_TYPE_REFERENCE , out , 1  TSRMLS_CC )) {
233+ 		RETURN_FALSE ;
234+ 	}
235+ 	ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
259236}
260237/* }}} */ 
261238
239+ 
262240/* {{{ proto resource git_branch_upstream_name(resource $repo, string $canonical_branch_name) 
263241 */ 
264242PHP_FUNCTION (git_branch_upstream_name )
0 commit comments