|
| 1 | +#include "php_git2.h" |
| 2 | +#include "php_git2_priv.h" |
| 3 | +#include "blame.h" |
| 4 | + |
| 5 | +/* {{{ proto long git_blame_get_hunk_count(resource $blame) |
| 6 | + */ |
| 7 | +PHP_FUNCTION(git_blame_get_hunk_count) |
| 8 | +{ |
| 9 | + uint32_t result = 0; |
| 10 | + zval *blame = NULL; |
| 11 | + php_git2_t *_blame = NULL; |
| 12 | + |
| 13 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 14 | + "r", &blame) == FAILURE) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 19 | + result = git_blame_get_hunk_count(PHP_GIT2_V(_blame, blame)); |
| 20 | + RETURN_LONG(result); |
| 21 | +} |
| 22 | +/* }}} */ |
| 23 | + |
| 24 | +/* {{{ proto resource git_blame_get_hunk_byindex(resource $blame, long $index) |
| 25 | + */ |
| 26 | +PHP_FUNCTION(git_blame_get_hunk_byindex) |
| 27 | +{ |
| 28 | + const git_blame_hunk *result = NULL; |
| 29 | + zval *blame = NULL; |
| 30 | + php_git2_t *_blame = NULL; |
| 31 | + long index = 0; |
| 32 | + |
| 33 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 34 | + "rl", &blame, &index) == FAILURE) { |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 39 | + result = git_blame_get_hunk_byindex(PHP_GIT2_V(_blame, blame), index); |
| 40 | + /* TODO(chobie): implement this */ |
| 41 | +} |
| 42 | +/* }}} */ |
| 43 | + |
| 44 | +/* {{{ proto resource git_blame_get_hunk_byline(resource $blame, long $lineno) |
| 45 | + */ |
| 46 | +PHP_FUNCTION(git_blame_get_hunk_byline) |
| 47 | +{ |
| 48 | + const git_blame_hunk *result = NULL; |
| 49 | + zval *blame = NULL; |
| 50 | + php_git2_t *_blame = NULL; |
| 51 | + long lineno = 0; |
| 52 | + |
| 53 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 54 | + "rl", &blame, &lineno) == FAILURE) { |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 59 | + result = git_blame_get_hunk_byline(PHP_GIT2_V(_blame, blame), lineno); |
| 60 | + /* TODO(chobie): implement this */ |
| 61 | +} |
| 62 | +/* }}} */ |
| 63 | + |
| 64 | +/* {{{ proto resource git_blame_file(resource $repo, string $path, $options) |
| 65 | + */ |
| 66 | +PHP_FUNCTION(git_blame_file) |
| 67 | +{ |
| 68 | + php_git2_t *result = NULL, *_repo = NULL; |
| 69 | + git_blame *out = NULL; |
| 70 | + zval *repo = NULL, *options = NULL; |
| 71 | + char *path = NULL; |
| 72 | + int path_len = 0, error = 0; |
| 73 | + |
| 74 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 75 | + "rs<git_blame_options>", &repo, &path, &path_len, &options) == FAILURE) { |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 80 | + error = git_blame_file(&out, PHP_GIT2_V(_repo, repository), path, options); |
| 81 | + if (php_git2_check_error(error, "git_blame_file" TSRMLS_CC)) { |
| 82 | + RETURN_FALSE; |
| 83 | + } |
| 84 | + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BLAME, out, 1 TSRMLS_CC)) { |
| 85 | + RETURN_FALSE; |
| 86 | + } |
| 87 | + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); |
| 88 | +} |
| 89 | +/* }}} */ |
| 90 | + |
| 91 | +/* {{{ proto resource git_blame_buffer(resource $reference, string $buffer) |
| 92 | + */ |
| 93 | +PHP_FUNCTION(git_blame_buffer) |
| 94 | +{ |
| 95 | + php_git2_t *result = NULL, *_reference = NULL; |
| 96 | + git_blame *out = NULL; |
| 97 | + zval *reference = NULL; |
| 98 | + char *buffer = NULL; |
| 99 | + int buffer_len = 0, error = 0; |
| 100 | + |
| 101 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 102 | + "rs", &reference, &buffer, &buffer_len) == FAILURE) { |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + ZEND_FETCH_RESOURCE(_reference, php_git2_t*, &reference, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 107 | + error = git_blame_buffer(&out, PHP_GIT2_V(_reference, blame), buffer, buffer_len); |
| 108 | + if (php_git2_check_error(error, "git_blame_buffer" TSRMLS_CC)) { |
| 109 | + RETURN_FALSE; |
| 110 | + } |
| 111 | + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BLAME, out, 1 TSRMLS_CC)) { |
| 112 | + RETURN_FALSE; |
| 113 | + } |
| 114 | + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); |
| 115 | +} |
| 116 | +/* }}} */ |
| 117 | + |
| 118 | +/* {{{ proto void git_blame_free(resource $blame) |
| 119 | + */ |
| 120 | +PHP_FUNCTION(git_blame_free) |
| 121 | +{ |
| 122 | + zval *blame = NULL; |
| 123 | + php_git2_t *_blame = NULL; |
| 124 | + |
| 125 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
| 126 | + "r", &blame) == FAILURE) { |
| 127 | + return; |
| 128 | + } |
| 129 | + |
| 130 | + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
| 131 | + if (GIT2_SHOULD_FREE(_blame)) { |
| 132 | + git_blame_free(PHP_GIT2_V(_blame, blame)); |
| 133 | + GIT2_SHOULD_FREE(_blame) = 0; |
| 134 | + }; |
| 135 | + zval_ptr_dtor(&blame); |
| 136 | +} |
| 137 | +/* }}} */ |
| 138 | + |
0 commit comments