|
| 1 | +#include "php_git2.h" |
| 2 | +#include "php_git2_priv.h" |
| 3 | +#include "reflog.h" |
| 4 | + |
| 5 | +/* {{{ proto resource git_reflog_read(resource $repo, string $name) |
| 6 | + */ |
| 7 | +PHP_FUNCTION(git_reflog_read) |
| 8 | +{ |
| 9 | + php_git2_t *result = NULL, *_repo = NULL; |
| 10 | + git_reflog *out = NULL; |
| 11 | + zval *repo = NULL; |
| 12 | + char *name = NULL; |
| 13 | + int name_len = 0, error = 0; |
| 14 | + |
| 15 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 16 | + "rs", &repo, &name, &name_len) == FAILURE) { |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 21 | + error = git_reflog_read(&out, PHP_GIT2_V(_repo, repository), name); |
| 22 | + if (php_git2_check_error(error, "git_reflog_read" TSRMLS_CC)) { |
| 23 | + RETURN_FALSE; |
| 24 | + } |
| 25 | + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFLOG, out, 1 TSRMLS_CC)) { |
| 26 | + RETURN_FALSE; |
| 27 | + } |
| 28 | + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); |
| 29 | +} |
| 30 | +/* }}} */ |
| 31 | + |
| 32 | +/* {{{ proto long git_reflog_write(resource $reflog) |
| 33 | + */ |
| 34 | +PHP_FUNCTION(git_reflog_write) |
| 35 | +{ |
| 36 | + int result = 0, error = 0; |
| 37 | + zval *reflog = NULL; |
| 38 | + php_git2_t *_reflog = NULL; |
| 39 | + |
| 40 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 41 | + "r", &reflog) == FAILURE) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 46 | + result = git_reflog_write(PHP_GIT2_V(_reflog, reflog)); |
| 47 | + RETURN_LONG(result); |
| 48 | +} |
| 49 | +/* }}} */ |
| 50 | + |
| 51 | +/* {{{ proto long git_reflog_append(resource $reflog, string $id, array $committer, string $msg) |
| 52 | + */ |
| 53 | +PHP_FUNCTION(git_reflog_append) |
| 54 | +{ |
| 55 | + int result = 0, id_len = 0, msg_len = 0, error = 0; |
| 56 | + zval *reflog = NULL, *committer = NULL; |
| 57 | + php_git2_t *_reflog = NULL; |
| 58 | + char *id = NULL, *msg = NULL; |
| 59 | + git_oid __id = {0}; |
| 60 | + |
| 61 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 62 | + "rsas", &reflog, &id, &id_len, &committer, &msg, &msg_len) == FAILURE) { |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 67 | + if (git_oid_fromstrn(&__id, id, id_len)) { |
| 68 | + RETURN_FALSE; |
| 69 | + } |
| 70 | + result = git_reflog_append(PHP_GIT2_V(_reflog, reflog), &__id, committer, msg); |
| 71 | + RETURN_LONG(result); |
| 72 | +} |
| 73 | +/* }}} */ |
| 74 | + |
| 75 | +/* {{{ proto long git_reflog_append_to(resource $repo, string $name, string $id, array $committer, string $msg) |
| 76 | + */ |
| 77 | +PHP_FUNCTION(git_reflog_append_to) |
| 78 | +{ |
| 79 | + int result = 0, name_len = 0, id_len = 0, msg_len = 0, error = 0; |
| 80 | + zval *repo = NULL, *committer = NULL; |
| 81 | + php_git2_t *_repo = NULL; |
| 82 | + char *name = NULL, *id = NULL, *msg = NULL; |
| 83 | + git_oid __id = {0}; |
| 84 | + |
| 85 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 86 | + "rssas", &repo, &name, &name_len, &id, &id_len, &committer, &msg, &msg_len) == FAILURE) { |
| 87 | + return; |
| 88 | + } |
| 89 | + |
| 90 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 91 | + if (git_oid_fromstrn(&__id, id, id_len)) { |
| 92 | + RETURN_FALSE; |
| 93 | + } |
| 94 | + result = git_reflog_append_to(PHP_GIT2_V(_repo, repository), name, &__id, committer, msg); |
| 95 | + RETURN_LONG(result); |
| 96 | +} |
| 97 | +/* }}} */ |
| 98 | + |
| 99 | +/* {{{ proto long git_reflog_rename(resource $repo, string $old_name, string $name) |
| 100 | + */ |
| 101 | +PHP_FUNCTION(git_reflog_rename) |
| 102 | +{ |
| 103 | + int result = 0, old_name_len = 0, name_len = 0, error = 0; |
| 104 | + zval *repo = NULL; |
| 105 | + php_git2_t *_repo = NULL; |
| 106 | + char *old_name = NULL, *name = NULL; |
| 107 | + |
| 108 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 109 | + "rss", &repo, &old_name, &old_name_len, &name, &name_len) == FAILURE) { |
| 110 | + return; |
| 111 | + } |
| 112 | + |
| 113 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 114 | + result = git_reflog_rename(PHP_GIT2_V(_repo, repository), old_name, name); |
| 115 | + RETURN_LONG(result); |
| 116 | +} |
| 117 | +/* }}} */ |
| 118 | + |
| 119 | +/* {{{ proto long git_reflog_delete(resource $repo, string $name) |
| 120 | + */ |
| 121 | +PHP_FUNCTION(git_reflog_delete) |
| 122 | +{ |
| 123 | + int result = 0, name_len = 0, error = 0; |
| 124 | + zval *repo = NULL; |
| 125 | + php_git2_t *_repo = NULL; |
| 126 | + char *name = NULL; |
| 127 | + |
| 128 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 129 | + "rs", &repo, &name, &name_len) == FAILURE) { |
| 130 | + return; |
| 131 | + } |
| 132 | + |
| 133 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 134 | + result = git_reflog_delete(PHP_GIT2_V(_repo, repository), name); |
| 135 | + RETURN_LONG(result); |
| 136 | +} |
| 137 | +/* }}} */ |
| 138 | + |
| 139 | +/* {{{ proto long git_reflog_entrycount(resource $reflog) |
| 140 | + */ |
| 141 | +PHP_FUNCTION(git_reflog_entrycount) |
| 142 | +{ |
| 143 | + size_t result = 0; |
| 144 | + zval *reflog = NULL; |
| 145 | + php_git2_t *_reflog = NULL; |
| 146 | + |
| 147 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 148 | + "r", &reflog) == FAILURE) { |
| 149 | + return; |
| 150 | + } |
| 151 | + |
| 152 | + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 153 | + result = git_reflog_entrycount(PHP_GIT2_V(_reflog, reflog)); |
| 154 | + RETURN_LONG(result); |
| 155 | +} |
| 156 | +/* }}} */ |
| 157 | + |
| 158 | +/* {{{ proto resource git_reflog_entry_byindex(resource $reflog, long $idx) |
| 159 | + */ |
| 160 | +PHP_FUNCTION(git_reflog_entry_byindex) |
| 161 | +{ |
| 162 | + const git_reflog_entry *result = NULL; |
| 163 | + zval *reflog = NULL; |
| 164 | + php_git2_t *_reflog = NULL; |
| 165 | + long idx = 0; |
| 166 | + |
| 167 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 168 | + "rl", &reflog, &idx) == FAILURE) { |
| 169 | + return; |
| 170 | + } |
| 171 | + |
| 172 | + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 173 | + result = git_reflog_entry_byindex(PHP_GIT2_V(_reflog, reflog), idx); |
| 174 | + /* TODO(chobie): implement this */ |
| 175 | +} |
| 176 | +/* }}} */ |
| 177 | + |
| 178 | +/* {{{ proto long git_reflog_drop(resource $reflog, long $idx, long $rewrite_previous_entry) |
| 179 | + */ |
| 180 | +PHP_FUNCTION(git_reflog_drop) |
| 181 | +{ |
| 182 | + int result = 0, error = 0; |
| 183 | + zval *reflog = NULL; |
| 184 | + php_git2_t *_reflog = NULL; |
| 185 | + long idx = 0, rewrite_previous_entry = 0; |
| 186 | + |
| 187 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 188 | + "rll", &reflog, &idx, &rewrite_previous_entry) == FAILURE) { |
| 189 | + return; |
| 190 | + } |
| 191 | + |
| 192 | + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 193 | + result = git_reflog_drop(PHP_GIT2_V(_reflog, reflog), idx, rewrite_previous_entry); |
| 194 | + RETURN_LONG(result); |
| 195 | +} |
| 196 | +/* }}} */ |
| 197 | + |
| 198 | +/* {{{ proto resource git_reflog_entry_id_old(resource $entry) |
| 199 | + */ |
| 200 | +PHP_FUNCTION(git_reflog_entry_id_old) |
| 201 | +{ |
| 202 | + const git_oid *result = NULL; |
| 203 | + zval *entry = NULL; |
| 204 | + php_git2_t *_entry = NULL; |
| 205 | + char __result[GIT2_OID_HEXSIZE] = {0}; |
| 206 | + |
| 207 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 208 | + "r", &entry) == FAILURE) { |
| 209 | + return; |
| 210 | + } |
| 211 | + |
| 212 | + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 213 | + result = git_reflog_entry_id_old(PHP_GIT2_V(_entry, reflog_entry)); |
| 214 | + git_oid_fmt(__result, result); |
| 215 | + RETURN_STRING(__result, 1); |
| 216 | +} |
| 217 | +/* }}} */ |
| 218 | + |
| 219 | +/* {{{ proto resource git_reflog_entry_id_new(resource $entry) |
| 220 | + */ |
| 221 | +PHP_FUNCTION(git_reflog_entry_id_new) |
| 222 | +{ |
| 223 | + const git_oid *result = NULL; |
| 224 | + zval *entry = NULL; |
| 225 | + php_git2_t *_entry = NULL; |
| 226 | + char __result[GIT2_OID_HEXSIZE] = {0}; |
| 227 | + |
| 228 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 229 | + "r", &entry) == FAILURE) { |
| 230 | + return; |
| 231 | + } |
| 232 | + |
| 233 | + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 234 | + result = git_reflog_entry_id_new(PHP_GIT2_V(_entry, reflog_entry)); |
| 235 | + git_oid_fmt(__result, result); |
| 236 | + RETURN_STRING(__result, 1); |
| 237 | +} |
| 238 | +/* }}} */ |
| 239 | + |
| 240 | +/* {{{ proto array git_reflog_entry_committer(resource $entry) |
| 241 | + */ |
| 242 | +PHP_FUNCTION(git_reflog_entry_committer) |
| 243 | +{ |
| 244 | + const git_signature *result = NULL; |
| 245 | + zval *__result = NULL, *entry = NULL; |
| 246 | + php_git2_t *_entry = NULL; |
| 247 | + |
| 248 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 249 | + "r", &entry) == FAILURE) { |
| 250 | + return; |
| 251 | + } |
| 252 | + |
| 253 | + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 254 | + result = git_reflog_entry_committer(PHP_GIT2_V(_entry, reflog_entry)); |
| 255 | + php_git2_signature_to_array(result, &__result TSRMLS_CC); |
| 256 | + RETURN_ZVAL(__result, 0, 1); |
| 257 | +} |
| 258 | +/* }}} */ |
| 259 | + |
| 260 | +/* {{{ proto string git_reflog_entry_message(resource $entry) |
| 261 | + */ |
| 262 | +PHP_FUNCTION(git_reflog_entry_message) |
| 263 | +{ |
| 264 | + const char *result = NULL; |
| 265 | + zval *entry = NULL; |
| 266 | + php_git2_t *_entry = NULL; |
| 267 | + |
| 268 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 269 | + "r", &entry) == FAILURE) { |
| 270 | + return; |
| 271 | + } |
| 272 | + |
| 273 | + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 274 | + result = git_reflog_entry_message(PHP_GIT2_V(_entry, reflog_entry)); |
| 275 | + RETURN_STRING(result, 1); |
| 276 | +} |
| 277 | +/* }}} */ |
| 278 | + |
| 279 | +/* {{{ proto void git_reflog_free(resource $reflog) |
| 280 | + */ |
| 281 | +PHP_FUNCTION(git_reflog_free) |
| 282 | +{ |
| 283 | + zval *reflog = NULL; |
| 284 | + php_git2_t *_reflog = NULL; |
| 285 | + |
| 286 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 287 | + "r", &reflog) == FAILURE) { |
| 288 | + return; |
| 289 | + } |
| 290 | + |
| 291 | + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 292 | + if (GIT2_SHOULD_FREE(_reflog)) { |
| 293 | + git_reflog_free(PHP_GIT2_V(_reflog, reflog)); |
| 294 | + GIT2_SHOULD_FREE(_reflog) = 0; |
| 295 | + }; |
| 296 | + zval_ptr_dtor(&reflog); |
| 297 | +} |
| 298 | +/* }}} */ |
| 299 | + |
0 commit comments