-
Notifications
You must be signed in to change notification settings - Fork 78
/
attr.c
138 lines (119 loc) · 3.85 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
#include "php_git2.h"
#include "php_git2_priv.h"
#include "attr.h"
/* {{{ proto resource git_attr_value(string $attr)
*/
PHP_FUNCTION(git_attr_value)
{
git_attr_t result;
char *attr = NULL;
int attr_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s", &attr, &attr_len) == FAILURE) {
return;
}
result = git_attr_value(attr);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto resource git_attr_get(resource $repo, long $flags, string $path, string $name)
*/
PHP_FUNCTION(git_attr_get)
{
php_git2_t *_repo = NULL;
char *value_out = NULL, *path = NULL, *name = NULL;
zval *repo = NULL;
long flags = 0;
int path_len = 0, name_len = 0, error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rlss", &repo, &flags, &path, &path_len, &name, &name_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
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, 1);
}
/* }}} */
/* {{{ proto resource git_attr_get_many(resource $repo, long $flags, string $path, long $num_attr, string $names)
*/
PHP_FUNCTION(git_attr_get_many)
{
php_git2_t *_repo = NULL;
char *values_out = NULL, *path = NULL;
zval *repo = NULL, *names = NULL;
long flags = 0, num_attr = 0;
int path_len = 0, error = 0;
/* TODO(chobie): write array to const char** conversion */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rlsla", &repo, &flags, &path, &path_len, &num_attr, &names) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
/* TODO(chobie): emalloc values_out */
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, 1);
}
/* }}} */
/* {{{ proto long git_attr_foreach(resource $repo, long $flags, string $path, Callable $callback, $payload)
*/
PHP_FUNCTION(git_attr_foreach)
{
int result = 0, path_len = 0;
zval *repo = NULL, *payload = NULL;
php_git2_t *_repo = NULL;
long flags = 0;
char *path = NULL;
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
php_git2_cb_t *cb = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rlsfz", &repo, &flags, &path, &path_len, &fci, &fcc, &payload) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {
RETURN_FALSE;
}
// TODO(chobie): implement this
//result = git_attr_foreach(PHP_GIT2_V(_repo, repository), flags, path, <CHANGEME>, cb);
php_git2_cb_free(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;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
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 = 0, name_len = 0, values_len = 0;
zval *repo = NULL;
php_git2_t *_repo = NULL;
char *name = NULL, *values = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rss", &repo, &name, &name_len, &values, &values_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_attr_add_macro(PHP_GIT2_V(_repo, repository), name, values);
RETURN_LONG(result);
}
/* }}} */