Skip to content

Commit 2316783

Browse files
committed
[remote, transport] improve several functions
1 parent ed1e8cf commit 2316783

File tree

5 files changed

+213
-153
lines changed

5 files changed

+213
-153
lines changed

Diff for: ng.php

+2
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ public function shouldResource(Arg $arg)
360360
"git_reference_iterator",
361361
"git_config_iterator",
362362
"git_index_conflict_iterator",
363+
"git_transport*",
364+
"git_transport"
363365
);
364366
}
365367

Diff for: php_git2.c

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v
215215
case PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR:
216216
PHP_GIT2_V(result, index_conflict_iterator) = (git_index_conflict_iterator*)resource;
217217
break;
218+
case PHP_GIT2_TYPE_SMART_SUBTRANSPORT:
219+
PHP_GIT2_V(result, smart_subtransport) = (git_smart_subtransport*)resource;
218220
default:
219221
php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug.");
220222
}

Diff for: php_git2.h

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ enum php_git2_resource_type {
111111
PHP_GIT2_TYPE_FILTER_SOURCE,
112112
PHP_GIT2_TYPE_DIFF_LINE,
113113
PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR,
114+
PHP_GIT2_TYPE_SMART_SUBTRANSPORT,
114115
};
115116

116117
typedef struct php_git2_t {
@@ -149,6 +150,7 @@ typedef struct php_git2_t {
149150
git_filter_source *filter_source;
150151
git_diff_line *diff_line;
151152
git_index_conflict_iterator *index_conflict_iterator;
153+
git_smart_subtransport *smart_subtransport;
152154
} v;
153155
int should_free_v;
154156
int resource_id;

Diff for: remote.c

+53-79
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
*/
77
PHP_FUNCTION(git_remote_create)
88
{
9-
php_git2_t *result = NULL;
9+
php_git2_t *result = NULL, *_repo = NULL;
1010
git_remote *out = NULL;
1111
zval *repo = NULL;
12-
php_git2_t *_repo = NULL;
13-
char *name = NULL;
14-
int name_len = 0;
15-
char *url = NULL;
16-
int url_len = 0;
17-
int error = 0;
12+
char *name = NULL, *url = NULL;
13+
int name_len = 0, url_len = 0, error = 0;
1814

1915
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
2016
"rss", &repo, &name, &name_len, &url, &url_len) == FAILURE) {
@@ -26,12 +22,10 @@ PHP_FUNCTION(git_remote_create)
2622
if (php_git2_check_error(error, "git_remote_create" TSRMLS_CC)) {
2723
RETURN_FALSE;
2824
}
29-
PHP_GIT2_MAKE_RESOURCE(result);
30-
PHP_GIT2_V(result, remote) = out;
31-
result->type = PHP_GIT2_TYPE_REMOTE;
32-
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
33-
result->should_free_v = 0;
34-
ZVAL_RESOURCE(return_value, result->resource_id);
25+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) {
26+
RETURN_FALSE;
27+
}
28+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
3529
}
3630
/* }}} */
3731

@@ -40,17 +34,11 @@ PHP_FUNCTION(git_remote_create)
4034
*/
4135
PHP_FUNCTION(git_remote_create_with_fetchspec)
4236
{
43-
php_git2_t *result = NULL;
37+
php_git2_t *result = NULL, *_repo = NULL;
4438
git_remote *out = NULL;
4539
zval *repo = NULL;
46-
php_git2_t *_repo = NULL;
47-
char *name = NULL;
48-
int name_len = 0;
49-
char *url = NULL;
50-
int url_len = 0;
51-
char *fetch = NULL;
52-
int fetch_len = 0;
53-
int error = 0;
40+
char *name = NULL, *url = NULL, *fetch = NULL;
41+
int name_len = 0, url_len = 0, fetch_len = 0, error = 0;
5442

5543
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
5644
"rsss", &repo, &name, &name_len, &url, &url_len, &fetch, &fetch_len) == FAILURE) {
@@ -62,29 +50,24 @@ PHP_FUNCTION(git_remote_create_with_fetchspec)
6250
if (php_git2_check_error(error, "git_remote_create_with_fetchspec" TSRMLS_CC)) {
6351
RETURN_FALSE;
6452
}
65-
PHP_GIT2_MAKE_RESOURCE(result);
66-
PHP_GIT2_V(result, remote) = out;
67-
result->type = PHP_GIT2_TYPE_REMOTE;
68-
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
69-
result->should_free_v = 0;
70-
ZVAL_RESOURCE(return_value, result->resource_id);
53+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) {
54+
RETURN_FALSE;
55+
}
56+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
7157
}
7258
/* }}} */
7359

7460

61+
7562
/* {{{ proto resource git_remote_create_inmemory(resource $repo, string $fetch, string $url)
7663
*/
7764
PHP_FUNCTION(git_remote_create_inmemory)
7865
{
79-
php_git2_t *result = NULL;
66+
php_git2_t *result = NULL, *_repo = NULL;
8067
git_remote *out = NULL;
8168
zval *repo = NULL;
82-
php_git2_t *_repo = NULL;
83-
char *fetch = NULL;
84-
int fetch_len = 0;
85-
char *url = NULL;
86-
int url_len = 0;
87-
int error = 0;
69+
char *fetch = NULL, *url = NULL;
70+
int fetch_len = 0, url_len = 0, error = 0;
8871

8972
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
9073
"rss", &repo, &fetch, &fetch_len, &url, &url_len) == FAILURE) {
@@ -96,26 +79,22 @@ PHP_FUNCTION(git_remote_create_inmemory)
9679
if (php_git2_check_error(error, "git_remote_create_inmemory" TSRMLS_CC)) {
9780
RETURN_FALSE;
9881
}
99-
PHP_GIT2_MAKE_RESOURCE(result);
100-
PHP_GIT2_V(result, remote) = out;
101-
result->type = PHP_GIT2_TYPE_REMOTE;
102-
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
103-
result->should_free_v = 0;
104-
ZVAL_RESOURCE(return_value, result->resource_id);
82+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) {
83+
RETURN_FALSE;
84+
}
85+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
10586
}
10687
/* }}} */
10788

10889
/* {{{ proto resource git_remote_load(resource $repo, string $name)
10990
*/
11091
PHP_FUNCTION(git_remote_load)
11192
{
112-
php_git2_t *result = NULL;
93+
php_git2_t *result = NULL, *_repo = NULL;
11394
git_remote *out = NULL;
11495
zval *repo = NULL;
115-
php_git2_t *_repo = NULL;
11696
char *name = NULL;
117-
int name_len = 0;
118-
int error = 0;
97+
int name_len = 0, error = 0;
11998

12099
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
121100
"rs", &repo, &name, &name_len) == FAILURE) {
@@ -127,15 +106,14 @@ PHP_FUNCTION(git_remote_load)
127106
if (php_git2_check_error(error, "git_remote_load" TSRMLS_CC)) {
128107
RETURN_FALSE;
129108
}
130-
PHP_GIT2_MAKE_RESOURCE(result);
131-
PHP_GIT2_V(result, remote) = out;
132-
result->type = PHP_GIT2_TYPE_REMOTE;
133-
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
134-
result->should_free_v = 0;
135-
ZVAL_RESOURCE(return_value, result->resource_id);
109+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) {
110+
RETURN_FALSE;
111+
}
112+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
136113
}
137114
/* }}} */
138115

116+
139117
/* {{{ proto long git_remote_save(resource $remote)
140118
*/
141119
PHP_FUNCTION(git_remote_save)
@@ -156,15 +134,13 @@ PHP_FUNCTION(git_remote_save)
156134
}
157135
/* }}} */
158136

159-
160137
/* {{{ proto resource git_remote_owner(resource $remote)
161138
*/
162139
PHP_FUNCTION(git_remote_owner)
163140
{
164141
git_repository *result = NULL;
165142
zval *remote = NULL;
166-
php_git2_t *_remote = NULL;
167-
php_git2_t *__result = NULL;
143+
php_git2_t *_remote = NULL, *__result = NULL;
168144

169145
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
170146
"r", &remote) == FAILURE) {
@@ -173,12 +149,10 @@ PHP_FUNCTION(git_remote_owner)
173149

174150
ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
175151
result = git_remote_owner(PHP_GIT2_V(_remote, remote));
176-
PHP_GIT2_MAKE_RESOURCE(__result);
177-
PHP_GIT2_V(__result, remote) = remote;
178-
__result->type = PHP_GIT2_TYPE_REPOSITORY;
179-
__result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
180-
__result->should_free_v = 0;
181-
ZVAL_RESOURCE(return_value, __result->resource_id);
152+
if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_REMOTE, result, 1 TSRMLS_CC)) {
153+
RETURN_FALSE;
154+
}
155+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result));
182156
}
183157
/* }}} */
184158

@@ -820,43 +794,43 @@ PHP_FUNCTION(git_remote_stats)
820794
/* }}} */
821795

822796

823-
/* {{{ proto resource git_remote_autotag(remote)
824-
*/
797+
/* {{{ proto resource git_remote_autotag(resource $remote)
798+
*/
825799
PHP_FUNCTION(git_remote_autotag)
826800
{
827-
zval *remote;
828-
php_git2_t *_remote;
829-
830-
/* TODO(chobie): implement this */
831-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_autotag not implemented yet");
832-
return;
801+
git_remote_autotag_option_t *result = NULL;
802+
zval *remote = NULL;
803+
php_git2_t *_remote = NULL;
833804

834805
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
835806
"r", &remote) == FAILURE) {
836807
return;
837808
}
809+
838810
ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
811+
result = git_remote_autotag(PHP_GIT2_V(_remote, remote));
812+
/* TODO(chobie): implement this */
839813
}
814+
/* }}} */
840815

841-
/* {{{ proto void git_remote_set_autotag(remote, value)
842-
*/
816+
/* {{{ proto void git_remote_set_autotag(resource $remote, $value)
817+
*/
843818
PHP_FUNCTION(git_remote_set_autotag)
844819
{
845-
zval *remote;
846-
php_git2_t *_remote;
847-
zval *value;
848-
php_git2_t *_value;
849-
850-
/* TODO(chobie): implement this */
851-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_autotag not implemented yet");
852-
return;
820+
zval *remote = NULL, *value = NULL;
821+
php_git2_t *_remote = NULL;
853822

823+
/* TODO(chobie):impelement this */
854824
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
855-
"rr", &remote, &value) == FAILURE) {
825+
"r<git_remote_autotag_option_t>", &remote, &value) == FAILURE) {
856826
return;
857827
}
828+
858829
ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
830+
git_remote_set_autotag(PHP_GIT2_V(_remote, remote), value);
859831
}
832+
/* }}} */
833+
860834

861835
/* {{{ proto long git_remote_rename(remote, new_name, callback, payload)
862836
*/

0 commit comments

Comments
 (0)