Skip to content

Commit 152812c

Browse files
committedJan 13, 2014
improve message
1 parent ceff015 commit 152812c

File tree

3 files changed

+57
-78
lines changed

3 files changed

+57
-78
lines changed
 

‎attr.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ PHP_FUNCTION(git_attr_get)
4949
PHP_FUNCTION(git_attr_get_many)
5050
{
5151
php_git2_t *result = NULL, *_repo = NULL;
52-
char *values_out = NULL, *path = NULL, *names = NULL;
53-
zval *repo = NULL;
52+
char *values_out = NULL, *path = NULL;
53+
zval *repo = NULL, *names = NULL;
5454
long flags = 0, num_attr = 0;
55-
int path_len = 0, names_len = 0, error = 0;
56-
55+
int path_len = 0, error = 0;
56+
57+
/* TODO(chobie): write array to const char** conversion */
5758
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
58-
"rlsls", &repo, &flags, &path, &path_len, &num_attr, &names, &names_len) == FAILURE) {
59+
"rlsla", &repo, &flags, &path, &path_len, &num_attr, &names) == FAILURE) {
5960
return;
6061
}
6162

6263
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
64+
/* TODO(chobie): emalloc values_out */
6365
error = git_attr_get_many(&values_out, PHP_GIT2_V(_repo, repository), flags, path, num_attr, names);
6466
if (php_git2_check_error(error, "git_attr_get_many" TSRMLS_CC)) {
6567
RETURN_FALSE;

‎branch.c

+41-63
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
*/
77
PHP_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
*/
6458
PHP_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
*/
9586
PHP_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
*/
126113
PHP_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
*/
146134
PHP_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
*/
178163
PHP_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
*/
211191
PHP_FUNCTION(git_branch_name)
@@ -234,10 +214,9 @@ PHP_FUNCTION(git_branch_name)
234214
*/
235215
PHP_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
*/
264242
PHP_FUNCTION(git_branch_upstream_name)

‎message.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22
#include "php_git2_priv.h"
33
#include "message.h"
44

5-
/* {{{ proto resource git_message_prettify(long $out_size, string $message, long $strip_comments)
5+
/* {{{ proto resource git_message_prettify(string $message, long $strip_comments)
66
*/
77
PHP_FUNCTION(git_message_prettify)
88
{
99
php_git2_t *result = NULL;
10-
char out = NULL, *message = NULL;
10+
char *out = NULL, *message = NULL;
1111
long out_size = 0, strip_comments = 0;
1212
int message_len = 0, error = 0;
13-
13+
1414
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
15-
"lsl", &out_size, &message, &message_len, &strip_comments) == FAILURE) {
15+
"sl", &message, &message_len, &strip_comments) == FAILURE) {
1616
return;
1717
}
18-
19-
error = git_message_prettify(&out, out_size, message, strip_comments);
20-
if (php_git2_check_error(error, "git_message_prettify" TSRMLS_CC)) {
21-
RETURN_FALSE;
22-
}
23-
RETURN_STRING(out, 1);
18+
19+
out_size = git_message_prettify(NULL, NULL, message, strip_comments);
20+
out = (char*)emalloc(sizeof(char) * out_size);
21+
error = git_message_prettify(out, out_size, message, strip_comments);
22+
RETURN_STRING(out, 0);
2423
}
2524
/* }}} */
2625

0 commit comments

Comments
 (0)
Please sign in to comment.