-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathattr.c
165 lines (133 loc) · 4.05 KB
/
attr.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
#include "php_git2.h"
#include "php_git2_priv.h"
#include "attr.h"
/* {{{ proto long git_attr_value(string $attr)
*/
PHP_FUNCTION(git_attr_value)
{
git_attr_t result;
char *attr = NULL;
size_t attr_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &attr, &attr_len) == FAILURE) {
return;
}
result = git_attr_value(attr);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto string git_attr_get(resource $repo, long $flags, string $path, string $name)
*/
PHP_FUNCTION(git_attr_get)
{
const char *value_out = NULL;
zval *repo = NULL;
php_git2_t *_repo = NULL;
zend_long flags;
char *path = NULL, *name = NULL;
size_t path_len, name_len;
int error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rlss", &repo, &flags, &path, &path_len, &name, &name_len) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_attr_get(&value_out, PHP_GIT2_V(_repo, repository), flags, path, name);
if (php_git2_check_error(error, "git_attr_get" TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_STRING(value_out);
}
/* }}} */
/* {{{ proto string git_attr_get_many(resource $repo, long $flags, string $path, long $num_attr, string $names)
*/
PHP_FUNCTION(git_attr_get_many)
{
const char *values_out = NULL;
zval *repo = NULL;
const char **names = NULL;
php_git2_t *_repo = NULL;
zend_long flags, num_attr;
char *path = NULL;
size_t path_len;
int error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rlsla", &repo, &flags, &path, &path_len, &num_attr, &names) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_attr_get_many(&values_out, PHP_GIT2_V(_repo, repository), flags, path, num_attr, names);
if (php_git2_check_error(error, "git_attr_get_many" TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_STRING(values_out);
}
/* }}} */
/* {{{ proto long git_attr_foreach(resource $repo, long $flags, string $path, Callable $callback, void $payload)
*/
PHP_FUNCTION(git_attr_foreach)
{
int result;
zval *repo = NULL, *payload = NULL;
php_git2_t *_repo = NULL;
zend_long flags;
char *path = NULL;
size_t path_len;
zend_fcall_info callback_fci = empty_fcall_info;
zend_fcall_info_cache callback_fcc = empty_fcall_info_cache;
php_git2_cb_t *callback_cb = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rlsfz", &repo, &flags, &path, &path_len, &callback_fci, &callback_fcc, &payload) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
if (php_git2_cb_init(&callback_cb, &callback_fci, &callback_fcc, payload TSRMLS_CC)) {
RETURN_FALSE;
}
result = git_attr_foreach(PHP_GIT2_V(_repo, repository), flags, path, php_git2_git_attr_foreach_cb, callback_cb);
php_git2_cb_free(callback_cb);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto void git_attr_cache_flush(resource $repo)
*/
PHP_FUNCTION(git_attr_cache_flush)
{
zval *repo = NULL;
php_git2_t *_repo = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &repo) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
git_attr_cache_flush(PHP_GIT2_V(_repo, repository));
}
/* }}} */
/* {{{ proto long git_attr_add_macro(resource $repo, string $name, string $values)
*/
PHP_FUNCTION(git_attr_add_macro)
{
int result;
zval *repo = NULL;
php_git2_t *_repo = NULL;
char *name = NULL, *values = NULL;
size_t name_len, values_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rss", &repo, &name, &name_len, &values, &values_len) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
result = git_attr_add_macro(PHP_GIT2_V(_repo, repository), name, values);
RETURN_LONG(result);
}
/* }}} */