-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathblame.c
203 lines (162 loc) · 4.73 KB
/
blame.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "php_git2.h"
#include "php_git2_priv.h"
#include "blame.h"
/* {{{ proto long git_blame_get_hunk_count(resource $blame)
*/
PHP_FUNCTION(git_blame_get_hunk_count)
{
uint32_t result;
zval *blame = NULL;
php_git2_t *_blame = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &blame) == FAILURE) {
return;
}
if ((_blame = (php_git2_t *) zend_fetch_resource(Z_RES_P(blame), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
result = git_blame_get_hunk_count(PHP_GIT2_V(_blame, blame));
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto array git_blame_get_hunk_byindex(resource $blame, long $index)
*/
PHP_FUNCTION(git_blame_get_hunk_byindex)
{
const git_blame_hunk *result = NULL;
zval *blame = NULL;
php_git2_t *_blame = NULL;
zend_long index;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rl", &blame, &index) == FAILURE) {
return;
}
if ((_blame = (php_git2_t *) zend_fetch_resource(Z_RES_P(blame), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
result = git_blame_get_hunk_byindex(PHP_GIT2_V(_blame, blame), index);
if (result == NULL) {
RETURN_FALSE;
}
array_init(return_value);
php_git2_git_blame_hunk_to_array(result, return_value TSRMLS_CC);
RETVAL_ARR(Z_ARRVAL_P(return_value));
}
/* }}} */
/* {{{ proto array git_blame_get_hunk_byline(resource $blame, long $lineno)
*/
PHP_FUNCTION(git_blame_get_hunk_byline)
{
const git_blame_hunk *result = NULL;
zval *blame = NULL;
php_git2_t *_blame = NULL;
zend_long lineno;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rl", &blame, &lineno) == FAILURE) {
return;
}
if ((_blame = (php_git2_t *) zend_fetch_resource(Z_RES_P(blame), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
result = git_blame_get_hunk_byline(PHP_GIT2_V(_blame, blame), lineno);
if (result == NULL) {
RETURN_FALSE;
}
array_init(return_value);
php_git2_git_blame_hunk_to_array(result, return_value TSRMLS_CC);
RETVAL_ARR(Z_ARRVAL_P(return_value));
}
/* }}} */
/* {{{ proto resource git_blame_file(resource $repo, string $path, array $options)
*/
PHP_FUNCTION(git_blame_file)
{
php_git2_t *result = NULL, *_repo = NULL;
git_blame *out = NULL;
zval *repo = NULL, *options = NULL;
char *path = NULL;
size_t path_len;
git_blame_options _options = {0};
int should_free = 0, error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs|a", &repo, &path, &path_len, &options) == FAILURE) {
return;
}
if (options != NULL) {
php_git2_array_to_git_blame_options(&_options, options TSRMLS_CC);
should_free = 1;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_blame_file(&out, PHP_GIT2_V(_repo, repository), path, &_options);
if (php_git2_check_error(error, "git_blame_file" TSRMLS_CC)) {
RETURN_FALSE;
}
if (should_free) {
php_git2_git_blame_options_free(&_options TSRMLS_CC);
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BLAME, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_RES(GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_blame_buffer(resource $reference, string $buffer)
*/
PHP_FUNCTION(git_blame_buffer)
{
php_git2_t *result = NULL, *_reference = NULL;
git_blame *out = NULL;
zval *reference = NULL;
char *buffer = NULL;
size_t buffer_len;
int error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs", &reference, &buffer, &buffer_len) == FAILURE) {
return;
}
if ((_reference = (php_git2_t *) zend_fetch_resource(Z_RES_P(reference), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_blame_buffer(&out, PHP_GIT2_V(_reference, blame), buffer, buffer_len);
if (php_git2_check_error(error, "git_blame_buffer" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BLAME, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_RES(GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto void git_blame_free(resource $blame)
*/
PHP_FUNCTION(git_blame_free)
{
zval *blame = NULL;
php_git2_t *_blame = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &blame) == FAILURE) {
return;
}
if ((_blame = (php_git2_t *) zend_fetch_resource(Z_RES_P(blame), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
// todo rework
if (0 /* GIT2_SHOULD_FREE(_blame) */) {
git_blame_free(PHP_GIT2_V(_blame, blame));
GIT2_SHOULD_FREE(_blame) = 0;
}
//zval_ptr_dtor(blame);
}
/* }}} */
/* {{{ proto array git_blame_options_new()
*/
PHP_FUNCTION(git_blame_options_new)
{
zval *result;
git_blame_options options = GIT_BLAME_OPTIONS_INIT;
php_git2_git_blame_options_to_array(&options, result TSRMLS_CC);
RETURN_ZVAL(result, 0, 1);
}
/* }}} */