|
2 | 2 | #include "php_git2_priv.h" |
3 | 3 | #include "push.h" |
4 | 4 |
|
| 5 | +static int php_git2_push_status_foreach_cb(const char *ref, const char *msg, void *data) |
| 6 | +{ |
| 7 | + fprintf(stderr, "ref: %s\n", ref); |
| 8 | + fprintf(stderr, "msg: %s\n", msg); |
| 9 | + return 0; |
| 10 | +} |
| 11 | + |
5 | 12 | /* {{{ proto resource git_push_new(resource $remote) |
6 | 13 | */ |
7 | 14 | PHP_FUNCTION(git_push_new) |
@@ -54,25 +61,34 @@ PHP_FUNCTION(git_push_set_callbacks) |
54 | 61 | int result = 0, error = 0; |
55 | 62 | zval *push = NULL, *pack_progress_cb = NULL, *pack_progress_cb_payload = NULL, *transfer_progress_cb = NULL, *transfer_progress_cb_payload = NULL; |
56 | 63 | php_git2_t *_push = NULL; |
57 | | - zend_fcall_info fci = empty_fcall_info; |
58 | | - zend_fcall_info_cache fcc = empty_fcall_info_cache; |
59 | | - php_git2_cb_t *cb = NULL; |
| 64 | + zend_fcall_info pack_fci = empty_fcall_info; |
| 65 | + zend_fcall_info_cache pack_fcc = empty_fcall_info_cache; |
| 66 | + zend_fcall_info transfer_fci = empty_fcall_info; |
| 67 | + zend_fcall_info_cache transfer_fcc = empty_fcall_info_cache; |
| 68 | + php_git2_cb_t *pack_cb = NULL; |
| 69 | + php_git2_cb_t *transfer_cb = NULL; |
60 | 70 |
|
61 | 71 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
62 | | - "rfz<git_push_transfer_progress>z", &push, &fci, &fcc, &pack_progress_cb_payload, &transfer_progress_cb, &transfer_progress_cb_payload) == FAILURE) { |
| 72 | + "rfzfz", &push, &pack_fci, &pack_fcc, &pack_progress_cb_payload, &transfer_fci, &transfer_fcc, &transfer_progress_cb_payload) == FAILURE) { |
63 | 73 | return; |
64 | 74 | } |
65 | | - |
| 75 | + |
66 | 76 | ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
67 | | -// if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { |
68 | | -// RETURN_FALSE; |
69 | | -// } |
70 | | - //result = git_push_set_callbacks(PHP_GIT2_V(_push, push), <CHANGEME>, cb, transfer_progress_cb, cb); |
71 | | - php_git2_cb_free(cb); |
| 77 | + if (php_git2_cb_init(&pack_cb, &pack_fci, &pack_fcc, pack_progress_cb_payload TSRMLS_CC)) { |
| 78 | + RETURN_FALSE; |
| 79 | + } |
| 80 | + if (php_git2_cb_init(&transfer_cb, &transfer_fci, &transfer_fcc, transfer_progress_cb_payload TSRMLS_CC)) { |
| 81 | + RETURN_FALSE; |
| 82 | + } |
| 83 | + result = git_push_set_callbacks(PHP_GIT2_V(_push, push), NULL, pack_cb, NULL, transfer_cb); |
| 84 | + php_git2_cb_free(pack_cb); |
| 85 | + php_git2_cb_free(transfer_cb); |
72 | 86 | RETURN_LONG(result); |
73 | 87 | } |
74 | 88 | /* }}} */ |
75 | 89 |
|
| 90 | + |
| 91 | + |
76 | 92 | /* {{{ proto long git_push_add_refspec(resource $push, string $refspec) |
77 | 93 | */ |
78 | 94 | PHP_FUNCTION(git_push_add_refspec) |
@@ -150,22 +166,28 @@ PHP_FUNCTION(git_push_unpack_ok) |
150 | 166 | } |
151 | 167 | /* }}} */ |
152 | 168 |
|
153 | | -/* {{{ proto long git_push_status_foreach(resource $push, string $ref, string $msg, $data), $data) |
| 169 | +/* {{{ proto long git_push_status_foreach(resource $push, Callable callback, mixed $payload) |
154 | 170 | */ |
155 | 171 | PHP_FUNCTION(git_push_status_foreach) |
156 | 172 | { |
157 | | - int result = 0, ref_len = 0, msg_len = 0, error = 0; |
158 | | - zval *push = NULL; |
| 173 | + int result = 0; |
| 174 | + zval *push = NULL, *payload = NULL; |
159 | 175 | php_git2_t *_push = NULL; |
160 | | - char *ref = NULL, *msg = NULL; |
161 | | - |
162 | | -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
163 | | -// "rss<void><void>", &push, &ref, &ref_len, &msg, &msg_len, &data, &data) == FAILURE) { |
164 | | -// return; |
165 | | -// } |
| 176 | + zend_fcall_info fci = empty_fcall_info; |
| 177 | + zend_fcall_info_cache fcc = empty_fcall_info_cache; |
| 178 | + php_git2_cb_t *cb = NULL; |
| 179 | + |
| 180 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 181 | + "rfz", &push, &fci, &fcc, &payload) == FAILURE) { |
| 182 | + return; |
| 183 | + } |
166 | 184 |
|
167 | 185 | ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
168 | | - //result = git_push_status_foreach(PHP_GIT2_V(_push, push), ref, msg, data); |
| 186 | + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { |
| 187 | + RETURN_FALSE; |
| 188 | + } |
| 189 | + result = git_push_status_foreach(PHP_GIT2_V(_push, push), php_git2_push_status_foreach_cb, cb); |
| 190 | + php_git2_cb_free(cb); |
169 | 191 | RETURN_LONG(result); |
170 | 192 | } |
171 | 193 | /* }}} */ |
|
0 commit comments