|
| 1 | +#include "php_git2.h" |
| 2 | +#include "php_git2_priv.h" |
| 3 | +#include "attr.h" |
| 4 | + |
| 5 | +/* {{{ proto resource git_attr_value(string $attr) |
| 6 | + */ |
| 7 | +PHP_FUNCTION(git_attr_value) |
| 8 | +{ |
| 9 | + git_attr_t *result = NULL; |
| 10 | + char *attr = NULL; |
| 11 | + int attr_len = 0; |
| 12 | + |
| 13 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 14 | + "s", &attr, &attr_len) == FAILURE) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + result = git_attr_value(attr); |
| 19 | + /* TODO(chobie): implement this */ |
| 20 | +} |
| 21 | +/* }}} */ |
| 22 | + |
| 23 | +/* {{{ proto resource git_attr_get(resource $repo, long $flags, string $path, string $name) |
| 24 | + */ |
| 25 | +PHP_FUNCTION(git_attr_get) |
| 26 | +{ |
| 27 | + php_git2_t *result = NULL, *_repo = NULL; |
| 28 | + char *value_out = NULL, *path = NULL, *name = NULL; |
| 29 | + zval *repo = NULL; |
| 30 | + long flags = 0; |
| 31 | + int path_len = 0, name_len = 0, error = 0; |
| 32 | + |
| 33 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 34 | + "rlss", &repo, &flags, &path, &path_len, &name, &name_len) == FAILURE) { |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 39 | + error = git_attr_get(&value_out, PHP_GIT2_V(_repo, repository), flags, path, name); |
| 40 | + if (php_git2_check_error(error, "git_attr_get" TSRMLS_CC)) { |
| 41 | + RETURN_FALSE; |
| 42 | + } |
| 43 | + RETURN_STRING(value_out, 1); |
| 44 | +} |
| 45 | +/* }}} */ |
| 46 | + |
| 47 | +/* {{{ proto resource git_attr_get_many(resource $repo, long $flags, string $path, long $num_attr, string $names) |
| 48 | + */ |
| 49 | +PHP_FUNCTION(git_attr_get_many) |
| 50 | +{ |
| 51 | + php_git2_t *result = NULL, *_repo = NULL; |
| 52 | + char *values_out = NULL, *path = NULL, *names = NULL; |
| 53 | + zval *repo = NULL; |
| 54 | + long flags = 0, num_attr = 0; |
| 55 | + int path_len = 0, names_len = 0, error = 0; |
| 56 | + |
| 57 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 58 | + "rlsls", &repo, &flags, &path, &path_len, &num_attr, &names, &names_len) == FAILURE) { |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 63 | + error = git_attr_get_many(&values_out, PHP_GIT2_V(_repo, repository), flags, path, num_attr, names); |
| 64 | + if (php_git2_check_error(error, "git_attr_get_many" TSRMLS_CC)) { |
| 65 | + RETURN_FALSE; |
| 66 | + } |
| 67 | + RETURN_STRING(values_out, 1); |
| 68 | +} |
| 69 | +/* }}} */ |
| 70 | + |
| 71 | +/* {{{ proto long git_attr_foreach(resource $repo, long $flags, string $path, Callable $callback, $payload) |
| 72 | + */ |
| 73 | +PHP_FUNCTION(git_attr_foreach) |
| 74 | +{ |
| 75 | + int result = 0, path_len = 0, error = 0; |
| 76 | + zval *repo = NULL, *callback = NULL, *payload = NULL; |
| 77 | + php_git2_t *_repo = NULL; |
| 78 | + long flags = 0; |
| 79 | + char *path = NULL; |
| 80 | + zend_fcall_info fci = empty_fcall_info; |
| 81 | + zend_fcall_info_cache fcc = empty_fcall_info_cache; |
| 82 | + php_git2_cb_t *cb = NULL; |
| 83 | + |
| 84 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 85 | + "rlsfz", &repo, &flags, &path, &path_len, &fci, &fcc, &payload) == FAILURE) { |
| 86 | + return; |
| 87 | + } |
| 88 | + |
| 89 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 90 | + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { |
| 91 | + RETURN_FALSE; |
| 92 | + } |
| 93 | + //result = git_attr_foreach(PHP_GIT2_V(_repo, repository), flags, path, <CHANGEME>, cb); |
| 94 | + php_git2_cb_free(cb); |
| 95 | + RETURN_LONG(result); |
| 96 | +} |
| 97 | +/* }}} */ |
| 98 | + |
| 99 | +/* {{{ proto void git_attr_cache_flush(resource $repo) |
| 100 | + */ |
| 101 | +PHP_FUNCTION(git_attr_cache_flush) |
| 102 | +{ |
| 103 | + zval *repo = NULL; |
| 104 | + php_git2_t *_repo = NULL; |
| 105 | + |
| 106 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 107 | + "r", &repo) == FAILURE) { |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 112 | + git_attr_cache_flush(PHP_GIT2_V(_repo, repository)); |
| 113 | +} |
| 114 | +/* }}} */ |
| 115 | + |
| 116 | +/* {{{ proto long git_attr_add_macro(resource $repo, string $name, string $values) |
| 117 | + */ |
| 118 | +PHP_FUNCTION(git_attr_add_macro) |
| 119 | +{ |
| 120 | + int result = 0, name_len = 0, values_len = 0, error = 0; |
| 121 | + zval *repo = NULL; |
| 122 | + php_git2_t *_repo = NULL; |
| 123 | + char *name = NULL, *values = NULL; |
| 124 | + |
| 125 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 126 | + "rss", &repo, &name, &name_len, &values, &values_len) == FAILURE) { |
| 127 | + return; |
| 128 | + } |
| 129 | + |
| 130 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 131 | + result = git_attr_add_macro(PHP_GIT2_V(_repo, repository), name, values); |
| 132 | + RETURN_LONG(result); |
| 133 | +} |
| 134 | +/* }}} */ |
| 135 | + |
0 commit comments