2
2
#include "php_git2_priv.h"
3
3
#include "commit.h"
4
4
5
- /* {{{ proto resource git_commit_lookup(resource $repository, mixed $oid )
6
- */
5
+ /* {{{ proto long git_commit_lookup(resource $repo, string $id )
6
+ */
7
7
PHP_FUNCTION (git_commit_lookup )
8
8
{
9
- zval * repository ;
10
- php_git2_t * git2 , * result ;
11
- git_commit * commit ;
12
- char * hash ;
13
- int hash_len ;
14
- int error ;
15
- git_oid id ;
16
-
9
+ int result = 0 , id_len = 0 , error = 0 ;
10
+ git_commit * commit = NULL ;
11
+ zval * repo = NULL ;
12
+ php_git2_t * _repo = NULL , * _result = NULL ;
13
+ char * id = NULL ;
14
+ git_oid __id = {0 };
15
+
17
16
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
18
- "rs" , & repository , & hash , & hash_len ) == FAILURE ) {
17
+ "rs" , & repo , & id , & id_len ) == FAILURE ) {
19
18
return ;
20
19
}
21
-
22
- if (git_oid_fromstrn (& id , hash , hash_len ) != GIT_OK ) {
23
- return ;
20
+
21
+ ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
22
+ if (git_oid_fromstrn (& __id , id , id_len )) {
23
+ RETURN_FALSE ;
24
24
}
25
-
26
- ZEND_FETCH_RESOURCE (git2 , php_git2_t * , & repository , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
27
-
28
- PHP_GIT2_MAKE_RESOURCE (result );
29
- error = git_commit_lookup (& commit , PHP_GIT2_V (git2 , repository ), & id );
30
- if (php_git2_check_error (error , "git_commit_lookup" TSRMLS_CC )) {
31
- RETURN_FALSE
25
+ result = git_commit_lookup (& commit , PHP_GIT2_V (_repo , repository ), & __id );
26
+ if (php_git2_make_resource (& _result , PHP_GIT2_TYPE_COMMIT , commit , 0 TSRMLS_CC )) {
27
+ RETURN_FALSE ;
32
28
}
33
-
34
- PHP_GIT2_V (result , commit ) = commit ;
35
- result -> type = PHP_GIT2_TYPE_COMMIT ;
36
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
37
- result -> should_free_v = 0 ;
38
-
39
- ZVAL_RESOURCE (return_value , result -> resource_id );
29
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (_result ));
40
30
}
41
31
/* }}} */
42
32
@@ -64,102 +54,103 @@ PHP_FUNCTION(git_commit_author)
64
54
/* }}} */
65
55
66
56
/* {{{ proto resource git_commit_tree(resource $commit)
67
- */
57
+ */
68
58
PHP_FUNCTION (git_commit_tree )
69
59
{
70
- zval * repository ;
71
- php_git2_t * git2 , * result ;
72
- git_commit * commit ;
73
- git_tree * tree ;
74
- int error ;
60
+ php_git2_t * result = NULL , * _commit = NULL ;
61
+ git_tree * tree_out = NULL ;
62
+ zval * commit = NULL ;
63
+ int error = 0 ;
75
64
76
65
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
77
66
"r" , & commit ) == FAILURE ) {
78
67
return ;
79
68
}
80
69
81
- ZEND_FETCH_RESOURCE (git2 , php_git2_t * , & commit , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
82
-
83
- PHP_GIT2_MAKE_RESOURCE (result );
84
- error = git_commit_tree (& tree , PHP_GIT2_V (git2 , commit ));
70
+ ZEND_FETCH_RESOURCE (_commit , php_git2_t * , & commit , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
71
+ error = git_commit_tree (& tree_out , PHP_GIT2_V (_commit , commit ));
85
72
if (php_git2_check_error (error , "git_commit_tree" TSRMLS_CC )) {
86
- RETURN_FALSE
73
+ RETURN_FALSE ;
87
74
}
88
-
89
- PHP_GIT2_V (result , tree ) = tree ;
90
- result -> type = PHP_GIT2_TYPE_TREE ;
91
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
92
- result -> should_free_v = 0 ;
93
-
94
- ZVAL_RESOURCE (return_value , result -> resource_id );
75
+ if (php_git2_make_resource (& result , PHP_GIT2_TYPE_TREE , tree_out , 1 TSRMLS_CC )) {
76
+ RETURN_FALSE ;
77
+ }
78
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (result ));
95
79
}
80
+ /* }}} */
96
81
97
- /* {{{ proto resource git_commit_lookup_prefix(repo, id, len)
98
- */
82
+ /* {{{ proto long git_commit_lookup_prefix(resource $ repo, string $ id, long $ len)
83
+ */
99
84
PHP_FUNCTION (git_commit_lookup_prefix )
100
85
{
101
- zval * repo ;
102
- php_git2_t * _repo ;
103
- char * id = {0 };
104
- int id_len ;
105
- long len ;
106
-
107
- /* TODO(chobie): implement this */
108
- php_error_docref (NULL TSRMLS_CC , E_WARNING , "git_commit_lookup_prefix not implemented yet" );
109
- return ;
86
+ int result = 0 , id_len = 0 , error = 0 ;
87
+ git_commit * commit = NULL ;
88
+ zval * repo = NULL ;
89
+ php_git2_t * _repo = NULL , * _result = NULL ;
90
+ char * id = NULL ;
91
+ git_oid __id = {0 };
92
+ long len = 0 ;
110
93
111
94
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
112
95
"rsl" , & repo , & id , & id_len , & len ) == FAILURE ) {
113
96
return ;
114
97
}
98
+
115
99
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
100
+ if (git_oid_fromstrn (& __id , id , id_len )) {
101
+ RETURN_FALSE ;
102
+ }
103
+ result = git_commit_lookup_prefix (& commit , PHP_GIT2_V (_repo , repository ), & __id , len );
104
+ if (php_git2_make_resource (& _result , PHP_GIT2_TYPE_COMMIT , commit , 0 TSRMLS_CC )) {
105
+ RETURN_FALSE ;
106
+ }
107
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (_result ));
116
108
}
109
+ /* }}} */
117
110
118
- /* {{{ proto resource git_commit_id(commit)
119
- */
111
+ /* {{{ proto resource git_commit_id(resource $ commit)
112
+ */
120
113
PHP_FUNCTION (git_commit_id )
121
114
{
122
- zval * commit ;
123
- php_git2_t * _commit ;
124
- char out [ GIT2_OID_HEXSIZE ] = { 0 } ;
125
- const git_oid * id ;
115
+ const git_oid * result = NULL ;
116
+ zval * commit = NULL ;
117
+ php_git2_t * _commit = NULL ;
118
+ char __result [ GIT2_OID_HEXSIZE ] = { 0 } ;
126
119
127
120
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
128
121
"r" , & commit ) == FAILURE ) {
129
122
return ;
130
123
}
131
- ZEND_FETCH_RESOURCE (_commit , php_git2_t * , & commit , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
132
-
133
- id = git_blob_id (PHP_GIT2_V (_commit , commit ));
134
124
135
- git_oid_fmt (out , id );
136
- RETURN_STRING (out , 1 );
125
+ ZEND_FETCH_RESOURCE (_commit , php_git2_t * , & commit , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
126
+ result = git_commit_id (PHP_GIT2_V (_commit , commit ));
127
+ git_oid_fmt (__result , result );
128
+ RETURN_STRING (__result , 1 );
137
129
}
130
+ /* }}} */
138
131
139
- /* {{{ proto resource git_commit_owner(commit)
140
- */
132
+ /* {{{ proto resource git_commit_owner(resource $ commit)
133
+ */
141
134
PHP_FUNCTION (git_commit_owner )
142
135
{
143
- zval * commit ;
144
- php_git2_t * _commit , * result ;
145
- git_repository * repository ;
136
+ git_repository * result = NULL ;
137
+ zval * commit = NULL ;
138
+ php_git2_t * _commit = NULL , * __result = NULL ;
146
139
147
140
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
148
141
"r" , & commit ) == FAILURE ) {
149
142
return ;
150
143
}
151
- ZEND_FETCH_RESOURCE (_commit , php_git2_t * , & commit , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
152
-
153
- PHP_GIT2_MAKE_RESOURCE (result );
154
- repository = git_commit_owner (PHP_GIT2_V (_commit , commit ));
155
-
156
- PHP_GIT2_V (result , repository ) = repository ;
157
- result -> type = PHP_GIT2_TYPE_REPOSITORY ;
158
- result -> resource_id = PHP_GIT2_LIST_INSERT (result , git2_resource_handle );
159
- result -> should_free_v = 0 ;
160
144
161
- ZVAL_RESOURCE (return_value , result -> resource_id );
145
+ ZEND_FETCH_RESOURCE (_commit , php_git2_t * , & commit , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
146
+ result = git_commit_owner (PHP_GIT2_V (_commit , commit ));
147
+ if (php_git2_make_resource (& __result , PHP_GIT2_TYPE_COMMIT , result , 1 TSRMLS_CC )) {
148
+ RETURN_FALSE ;
149
+ }
150
+ ZVAL_RESOURCE (return_value , GIT2_RVAL_P (__result ));
162
151
}
152
+ /* }}} */
153
+
163
154
164
155
/* {{{ proto resource git_commit_message_encoding(commit)
165
156
*/
@@ -177,6 +168,7 @@ PHP_FUNCTION(git_commit_message_encoding)
177
168
encoding = git_commit_message_encoding (PHP_GIT2_V (_commit , commit ));
178
169
RETURN_STRING (encoding , 1 );
179
170
}
171
+ /* }}} */
180
172
181
173
/* {{{ proto resource git_commit_message(commit)
182
174
*/
@@ -194,6 +186,7 @@ PHP_FUNCTION(git_commit_message)
194
186
message = git_commit_message (PHP_GIT2_V (_commit , commit ));
195
187
RETURN_STRING (message , 1 );
196
188
}
189
+ /* }}} */
197
190
198
191
/* {{{ proto resource git_commit_message_raw(commit)
199
192
*/
@@ -212,6 +205,7 @@ PHP_FUNCTION(git_commit_message_raw)
212
205
message = git_commit_message_raw (PHP_GIT2_V (_commit , commit ));
213
206
RETURN_STRING (message , 1 );
214
207
}
208
+ /* }}} */
215
209
216
210
/* {{{ proto resource git_commit_time(commit)
217
211
*/
@@ -231,6 +225,7 @@ PHP_FUNCTION(git_commit_time)
231
225
/* NOTE(chobie) should this return as a string? */
232
226
RETURN_LONG (time );
233
227
}
228
+ /* }}} */
234
229
235
230
/* {{{ proto long git_commit_time_offset(commit)
236
231
*/
@@ -248,6 +243,7 @@ PHP_FUNCTION(git_commit_time_offset)
248
243
result = git_commit_time_offset (PHP_GIT2_V (_commit , commit ));
249
244
RETURN_LONG (result );
250
245
}
246
+ /* }}} */
251
247
252
248
/* {{{ proto resource git_commit_committer(commit)
253
249
*/
@@ -268,6 +264,7 @@ PHP_FUNCTION(git_commit_committer)
268
264
php_git2_signature_to_array (committer , & result TSRMLS_CC );
269
265
RETURN_ZVAL (result , 0 , 1 );
270
266
}
267
+ /* }}} */
271
268
272
269
/* {{{ proto resource git_commit_raw_header(commit)
273
270
*/
@@ -286,6 +283,7 @@ PHP_FUNCTION(git_commit_raw_header)
286
283
287
284
RETURN_STRING (header , 1 );
288
285
}
286
+ /* }}} */
289
287
290
288
/* {{{ proto resource git_commit_tree_id(commit)
291
289
*/
@@ -306,6 +304,7 @@ PHP_FUNCTION(git_commit_tree_id)
306
304
git_oid_fmt (out , id );
307
305
RETURN_STRING (out , 1 );
308
306
}
307
+ /* }}} */
309
308
310
309
/* {{{ proto resource git_commit_parentcount(commit)
311
310
*/
@@ -324,6 +323,7 @@ PHP_FUNCTION(git_commit_parentcount)
324
323
count = git_commit_parentcount (PHP_GIT2_V (_commit , commit ));
325
324
RETURN_LONG (count );
326
325
}
326
+ /* }}} */
327
327
328
328
/* {{{ proto resource git_commit_parent(commit, n)
329
329
*/
@@ -353,6 +353,7 @@ PHP_FUNCTION(git_commit_parent)
353
353
354
354
ZVAL_RESOURCE (return_value , result -> resource_id );
355
355
}
356
+ /* }}} */
356
357
357
358
/* {{{ proto resource git_commit_parent_id(commit, n)
358
359
*/
@@ -374,6 +375,7 @@ PHP_FUNCTION(git_commit_parent_id)
374
375
375
376
RETURN_STRING (out , 1 );
376
377
}
378
+ /* }}} */
377
379
378
380
/* {{{ proto resource git_commit_nth_gen_ancestor(commit, n)
379
381
*/
@@ -405,6 +407,7 @@ PHP_FUNCTION(git_commit_nth_gen_ancestor)
405
407
ZVAL_RESOURCE (return_value , result -> resource_id );
406
408
407
409
}
410
+ /* }}} */
408
411
409
412
/* {{{ proto resource git_commit_create(
410
413
resource $repo, string $update_ref, array $author, array $committer,
0 commit comments