2
2
#include "php_git2_priv.h"
3
3
#include "object.h"
4
4
5
- /* {{{ proto resource git_object_lookup(repo, id, type)
6
- */
5
+ /* {{{ proto long git_object_lookup(resource $ repo, string $ id, long $ type)
6
+ */
7
7
PHP_FUNCTION (git_object_lookup )
8
8
{
9
- zval * repo ;
10
- php_git2_t * _repo , * result ;
11
- char * id = {0 };
12
- int id_len ;
13
- zval * type ;
14
- php_git2_t * _type ;
15
- int error = 0 ;
16
- git_object * object ;
17
- git_oid oid ;
9
+ int result = 0 , id_len = 0 , error = 0 ;
10
+ git_object * object = NULL ;
11
+ zval * repo = NULL ;
12
+ php_git2_t * _repo = NULL ;
13
+ char * id = NULL ;
14
+ git_oid __id = {0 };
15
+ long type = 0 ;
18
16
19
17
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
20
- "rsr " , & repo , & id , & id_len , & type ) == FAILURE ) {
18
+ "rsl " , & repo , & id , & id_len , & type ) == FAILURE ) {
21
19
return ;
22
20
}
21
+
23
22
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
24
- if (git_oid_fromstrn (& oid , id , id_len ) != GIT_OK ) {
25
- return ;
23
+ if (git_oid_fromstrn (& __id , id , id_len )) {
24
+ RETURN_FALSE ;
26
25
}
27
- error = git_object_lookup (& object , PHP_GIT2_V (_repo , repository ), & oid , type );
28
- if (php_git2_check_error (error , "git_object_lookup" TSRMLS_CC )) {
29
- RETURN_FALSE
30
- }
31
- PHP_GIT2_MAKE_RESOURCE (result );
32
- PHP_GIT2_V (result , object ) = object ;
33
- result -> type = PHP_GIT2_TYPE_OBJECT ;
34
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
35
- result -> should_free_v = 1 ;
36
-
37
- ZVAL_RESOURCE (return_value , result -> resource_id );
26
+ result = git_object_lookup (& object , PHP_GIT2_V (_repo , repository ), & __id , type );
27
+ RETURN_LONG (result );
38
28
}
29
+ /* }}} */
39
30
40
- /* {{{ proto resource git_object_lookup_prefix(repo, id, len, type)
41
- */
31
+ /* {{{ proto resource git_object_lookup_prefix(resource $ repo, string $ id, long $ len, long $ type)
32
+ */
42
33
PHP_FUNCTION (git_object_lookup_prefix )
43
34
{
44
- zval * repo ;
45
- php_git2_t * _repo ;
46
- char * id = {0 };
47
- int id_len ;
48
- zval * type ;
49
- php_git2_t * _type ;
50
-
51
- /* TODO(chobie): implement this */
52
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_object_lookup_prefix not implemented yet" );
53
- return ;
54
-
55
- // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
56
- // "rsr", &repo, &id, &id_len, &len, &type) == FAILURE) {
57
- // return;
58
- // }
35
+ php_git2_t * result = NULL , * _repo = NULL ;
36
+ git_object * object_out = NULL ;
37
+ zval * repo = NULL ;
38
+ char * id = NULL ;
39
+ int id_len = 0 , error = 0 ;
40
+ git_oid __id = {0 };
41
+ long len = 0 , type = 0 ;
42
+
43
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
44
+ "rsll" , & repo , & id , & id_len , & len , & type ) == FAILURE ) {
45
+ return ;
46
+ }
47
+
59
48
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
49
+ if (git_oid_fromstrn (& __id , id , id_len )) {
50
+ RETURN_FALSE ;
51
+ }
52
+ error = git_object_lookup_prefix (& object_out , PHP_GIT2_V (_repo , repository ), & __id , len , type );
53
+ if (php_git2_check_error (error , "git_object_lookup_prefix" TSRMLS_CC )) {
54
+ RETURN_FALSE ;
55
+ }
56
+ if (php_git2_make_resource (& result , PHP_GIT2_TYPE_OBJECT , object_out , 1 TSRMLS_CC )) {
57
+ RETURN_FALSE ;
58
+ }
59
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
60
60
}
61
+ /* }}} */
61
62
62
- /* {{{ proto resource git_object_lookup_bypath(treeish, path, type)
63
- */
63
+ /* {{{ proto resource git_object_lookup_bypath(resource $ treeish, string $ path, long $ type)
64
+ */
64
65
PHP_FUNCTION (git_object_lookup_bypath )
65
66
{
66
- zval * treeish ;
67
- php_git2_t * _treeish , * result ;
68
- char * path = {0 };
69
- int path_len ;
70
- zval * type ;
71
- php_git2_t * _type ;
72
- git_object * object ;
73
- int error ;
67
+ php_git2_t * result = NULL , * _treeish = NULL ;
68
+ git_object * out = NULL ;
69
+ zval * treeish = NULL ;
70
+ char * path = NULL ;
71
+ int path_len = 0 , error = 0 ;
72
+ long type = 0 ;
74
73
75
74
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
76
- "rsr " , & treeish , & path , & path_len , & type ) == FAILURE ) {
75
+ "rsl " , & treeish , & path , & path_len , & type ) == FAILURE ) {
77
76
return ;
78
77
}
78
+
79
79
ZEND_FETCH_RESOURCE (_treeish , php_git2_t * , & treeish , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
80
- // TODO: cast object
81
- error = git_object_lookup_bypath (& object , PHP_GIT2_V (_treeish , tree ), path , type );
80
+ error = git_object_lookup_bypath (& out , PHP_GIT2_V (_treeish , object ), path , type );
82
81
if (php_git2_check_error (error , "git_object_lookup_bypath" TSRMLS_CC )) {
83
- RETURN_FALSE
82
+ RETURN_FALSE ;
84
83
}
85
- PHP_GIT2_MAKE_RESOURCE (result );
86
- PHP_GIT2_V (result , object ) = object ;
87
- result -> type = PHP_GIT2_TYPE_OBJECT ;
88
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
89
- result -> should_free_v = 0 ;
90
-
91
- ZVAL_RESOURCE (return_value , result -> resource_id );
84
+ if (php_git2_make_resource (& result , PHP_GIT2_TYPE_OBJECT , out , 1 TSRMLS_CC )) {
85
+ RETURN_FALSE ;
86
+ }
87
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
92
88
}
89
+ /* }}} */
93
90
94
91
/* {{{ proto resource git_object_id(obj)
95
92
*/
@@ -109,84 +106,86 @@ PHP_FUNCTION(git_object_id)
109
106
git_oid_fmt (buf , id );
110
107
RETURN_STRING (buf , 1 );
111
108
}
109
+ /* }}} */
112
110
113
- /* {{{ proto resource git_object_type(obj)
114
- */
111
+ /* {{{ proto resource git_object_type(resource $ obj)
112
+ */
115
113
PHP_FUNCTION (git_object_type )
116
114
{
117
- zval * obj ;
118
- php_git2_t * _obj ;
119
- const git_otype * type ;
115
+ git_otype * result = NULL ;
116
+ zval * obj = NULL ;
117
+ php_git2_t * _obj = NULL ;
120
118
121
119
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
122
120
"r" , & obj ) == FAILURE ) {
123
121
return ;
124
122
}
123
+
125
124
ZEND_FETCH_RESOURCE (_obj , php_git2_t * , & obj , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
126
- type = git_object_type (PHP_GIT2_V (_obj , object ));
127
- RETURN_LONG (type );
125
+ result = git_object_type (PHP_GIT2_V (_obj , object ));
126
+ RETURN_LONG (result );
128
127
}
128
+ /* }}} */
129
129
130
- /* {{{ proto resource git_object_owner(obj)
131
- */
130
+ /* {{{ proto resource git_object_owner(resource $ obj)
131
+ */
132
132
PHP_FUNCTION (git_object_owner )
133
133
{
134
- zval * obj ;
135
- php_git2_t * _obj , * result ;
136
- git_repository * repository ;
134
+ git_repository * result = NULL ;
135
+ zval * obj = NULL ;
136
+ php_git2_t * _obj = NULL , * __result = NULL ;
137
137
138
138
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
139
139
"r" , & obj ) == FAILURE ) {
140
140
return ;
141
141
}
142
+
142
143
ZEND_FETCH_RESOURCE (_obj , php_git2_t * , & obj , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
143
- // TODO: consider cast
144
- repository = git_object_owner (PHP_GIT2_V (_obj , object ));
145
- PHP_GIT2_MAKE_RESOURCE (result );
146
- PHP_GIT2_V (result , repository ) = repository ;
147
- result -> type = PHP_GIT2_TYPE_REPOSITORY ;
148
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
149
- result -> should_free_v = 0 ;
150
-
151
- ZVAL_RESOURCE (return_value , result -> resource_id );
144
+ result = git_object_owner (PHP_GIT2_V (_obj , object ));
145
+ if (php_git2_make_resource (& __result , PHP_GIT2_TYPE_OBJECT , result , 1 TSRMLS_CC )) {
146
+ RETURN_FALSE ;
147
+ }
148
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (__result ));
152
149
}
150
+ /* }}} */
153
151
154
- /* {{{ proto void git_object_free(object)
155
- */
152
+ /* {{{ proto void git_object_free(resource $ object)
153
+ */
156
154
PHP_FUNCTION (git_object_free )
157
155
{
158
- zval * object ;
159
- php_git2_t * _object ;
156
+ zval * object = NULL ;
157
+ php_git2_t * _object = NULL ;
160
158
161
159
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
162
160
"r" , & object ) == FAILURE ) {
163
161
return ;
164
162
}
163
+
165
164
ZEND_FETCH_RESOURCE (_object , php_git2_t * , & object , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
166
- if (_object -> should_free_v ) {
165
+ if (GIT2_SHOULD_FREE ( _object ) ) {
167
166
git_object_free (PHP_GIT2_V (_object , object ));
168
- _object -> should_free_v = 0 ;
169
- }
167
+ GIT2_SHOULD_FREE ( _object ) = 0 ;
168
+ };
170
169
zval_ptr_dtor (& object );
171
170
}
171
+ /* }}} */
172
172
173
- /* {{{ proto resource git_object_type2string(type)
174
- */
173
+ /* {{{ proto string git_object_type2string(long $ type)
174
+ */
175
175
PHP_FUNCTION (git_object_type2string )
176
176
{
177
- zval * type ;
178
- php_git2_t * _type ;
179
- const char * result ;
177
+ const char * result = NULL ;
178
+ long type = 0 ;
180
179
181
180
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
182
- "r " , & type ) == FAILURE ) {
181
+ "l " , & type ) == FAILURE ) {
183
182
return ;
184
183
}
185
- ZEND_FETCH_RESOURCE (_type , php_git2_t * , & type , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
186
- // TODO: consider cast
187
- result = git_object_type2string (PHP_GIT2_V (_type , object ));
184
+
185
+ result = git_object_type2string (type );
188
186
RETURN_STRING (result , 1 );
189
187
}
188
+ /* }}} */
190
189
191
190
/* {{{ proto resource git_object_string2type(str)
192
191
*/
@@ -203,26 +202,24 @@ PHP_FUNCTION(git_object_string2type)
203
202
type = git_object_string2type (str );
204
203
RETURN_LONG (type );
205
204
}
205
+ /* }}} */
206
206
207
- /* {{{ proto long git_object_typeisloose(type)
208
- */
207
+ /* {{{ proto long git_object_typeisloose(long $ type)
208
+ */
209
209
PHP_FUNCTION (git_object_typeisloose )
210
210
{
211
- zval * type ;
212
- php_git2_t * _type ;
213
- int error = 0 ;
211
+ int result = 0 , error = 0 ;
212
+ long type = 0 ;
214
213
215
214
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
216
- "r " , & type ) == FAILURE ) {
215
+ "l " , & type ) == FAILURE ) {
217
216
return ;
218
217
}
219
- ZEND_FETCH_RESOURCE (_type , php_git2_t * , & type , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
220
- error = git_object_typeisloose (PHP_GIT2_V (_type , object ));
221
- if (php_git2_check_error (error , "git_object_typeisloose" TSRMLS_CC )) {
222
- RETURN_FALSE
223
- }
224
- RETURN_TRUE ;
218
+
219
+ result = git_object_typeisloose (type );
220
+ RETURN_LONG (result );
225
221
}
222
+ /* }}} */
226
223
227
224
/* {{{ proto resource git_object__size(type)
228
225
*/
@@ -239,56 +236,49 @@ PHP_FUNCTION(git_object__size)
239
236
RETURN_LONG (size );
240
237
}
241
238
242
- /* {{{ proto resource git_object_peel(object, target_type)
243
- */
239
+ /* {{{ proto long git_object_peel(resource $ object, long $ target_type)
240
+ */
244
241
PHP_FUNCTION (git_object_peel )
245
242
{
246
- zval * object ;
247
- php_git2_t * _object , * result ;
248
- zval * target_type ;
249
- php_git2_t * _target_type ;
250
- int error = 0 ;
251
- git_object * out ;
252
-
243
+ int result = 0 , error = 0 ;
244
+ git_object * peeled = NULL ;
245
+ zval * object = NULL ;
246
+ php_git2_t * _object = NULL , * _result ;
247
+ long target_type = 0 ;
248
+
253
249
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
254
- "rr " , & object , & target_type ) == FAILURE ) {
250
+ "rl " , & object , & target_type ) == FAILURE ) {
255
251
return ;
256
252
}
253
+
257
254
ZEND_FETCH_RESOURCE (_object , php_git2_t * , & object , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
258
- error = git_object_peel (& out , PHP_GIT2_V (_object , object ), target_type );
259
- if (php_git2_check_error ( error , "git_object_peel" TSRMLS_CC )) {
260
- RETURN_FALSE
255
+ result = git_object_peel (& peeled , PHP_GIT2_V (_object , object ), target_type );
256
+ if (php_git2_make_resource ( & _result , PHP_GIT2_TYPE_OBJECT , peeled , 1 TSRMLS_CC )) {
257
+ RETURN_FALSE ;
261
258
}
262
- PHP_GIT2_MAKE_RESOURCE (result );
263
- PHP_GIT2_V (result , object ) = object ;
264
- result -> type = PHP_GIT2_TYPE_OBJECT ;
265
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
266
- result -> should_free_v = 1 ;
267
-
268
- ZVAL_RESOURCE (return_value , result -> resource_id );
259
+ ZVAL_RESOURCE (return_value , GIT_RVAL_P (_result ));
269
260
}
261
+ /* }}} */
270
262
271
- /* {{{ proto resource git_object_dup(source)
272
- */
263
+ /* {{{ proto long git_object_dup(resource $ source)
264
+ */
273
265
PHP_FUNCTION (git_object_dup )
274
266
{
275
- zval * source ;
276
- php_git2_t * _source , * result ;
277
- git_object * dest ;
278
- int error = 0 ;
267
+ int result = 0 , error = 0 ;
268
+ git_object * dest = NULL ;
269
+ zval * source = NULL ;
270
+ php_git2_t * _source = NULL , * _result = NULL ;
279
271
280
272
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
281
273
"r" , & source ) == FAILURE ) {
282
274
return ;
283
275
}
276
+
284
277
ZEND_FETCH_RESOURCE (_source , php_git2_t * , & source , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
285
- error = git_object_dup (& dest , PHP_GIT2_V (_source , object ));
286
- PHP_GIT2_MAKE_RESOURCE (result );
287
- PHP_GIT2_V (result , object ) = dest ;
288
- result -> type = PHP_GIT2_TYPE_OBJECT ;
289
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
290
- result -> should_free_v = 1 ;
291
-
292
- ZVAL_RESOURCE (return_value , result -> resource_id );
278
+ result = git_object_dup (& dest , PHP_GIT2_V (_source , object ));
279
+ if (php_git2_make_resource (& _result , PHP_GIT2_TYPE_OBJECT , dest , 1 TSRMLS_CC )) {
280
+ RETURN_FALSE ;
281
+ }
282
+ ZVAL_RESOURCE (return_value , GIT_RVAL_P (_result ));
293
283
}
294
-
284
+ /* }}} */
0 commit comments