Skip to content

Commit ceff015

Browse files
committed
add attr
1 parent 30871d9 commit ceff015

File tree

4 files changed

+235
-1
lines changed

4 files changed

+235
-1
lines changed

attr.c

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+

attr.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* PHP Libgit2 Extension
3+
*
4+
* https://github.com/libgit2/php-git
5+
*
6+
* Copyright 2014 Shuhei Tanuma. All rights reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef PHP_GIT2_ATTR_H
27+
#define PHP_GIT2_ATTR_H
28+
29+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_value, 0, 0, 1)
30+
ZEND_ARG_INFO(0, attr)
31+
ZEND_END_ARG_INFO()
32+
33+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_get, 0, 0, 4)
34+
ZEND_ARG_INFO(0, repo)
35+
ZEND_ARG_INFO(0, flags)
36+
ZEND_ARG_INFO(0, path)
37+
ZEND_ARG_INFO(0, name)
38+
ZEND_END_ARG_INFO()
39+
40+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_get_many, 0, 0, 5)
41+
ZEND_ARG_INFO(0, repo)
42+
ZEND_ARG_INFO(0, flags)
43+
ZEND_ARG_INFO(0, path)
44+
ZEND_ARG_INFO(0, num_attr)
45+
ZEND_ARG_INFO(0, names)
46+
ZEND_END_ARG_INFO()
47+
48+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_foreach, 0, 0, 5)
49+
ZEND_ARG_INFO(0, repo)
50+
ZEND_ARG_INFO(0, flags)
51+
ZEND_ARG_INFO(0, path)
52+
ZEND_ARG_INFO(0, callback)
53+
ZEND_ARG_INFO(0, payload)
54+
ZEND_END_ARG_INFO()
55+
56+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_cache_flush, 0, 0, 1)
57+
ZEND_ARG_INFO(0, repo)
58+
ZEND_END_ARG_INFO()
59+
60+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_add_macro, 0, 0, 3)
61+
ZEND_ARG_INFO(0, repo)
62+
ZEND_ARG_INFO(0, name)
63+
ZEND_ARG_INFO(0, values)
64+
ZEND_END_ARG_INFO()
65+
66+
/* {{{ proto resource git_attr_value(attr)
67+
*/
68+
PHP_FUNCTION(git_attr_value);
69+
70+
/* {{{ proto resource git_attr_get(repo, flags, path, name)
71+
*/
72+
PHP_FUNCTION(git_attr_get);
73+
74+
/* {{{ proto resource git_attr_get_many(repo, flags, path, num_attr, names)
75+
*/
76+
PHP_FUNCTION(git_attr_get_many);
77+
78+
/* {{{ proto long git_attr_foreach(repo, flags, path, callback, payload)
79+
*/
80+
PHP_FUNCTION(git_attr_foreach);
81+
82+
/* {{{ proto void git_attr_cache_flush(repo)
83+
*/
84+
PHP_FUNCTION(git_attr_cache_flush);
85+
86+
/* {{{ proto long git_attr_add_macro(repo, name, values)
87+
*/
88+
PHP_FUNCTION(git_attr_add_macro);
89+
90+
#endif

config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support,
77
if test $PHP_GIT2 != "no"; then
88
PHP_SUBST(GIT2_SHARED_LIBADD)
99

10-
PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c reset.c message.c submodule.c, $ext_shared)
10+
PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c, $ext_shared)
1111
PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include])
1212

1313
# for now

php_git2.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "reset.h"
6262
#include "message.h"
6363
#include "submodule.h"
64+
#include "attr.h"
6465

6566
int git2_resource_handle;
6667

@@ -843,6 +844,14 @@ static zend_function_entry php_git2_functions[] = {
843844
PHP_FE(git_submodule_status, arginfo_git_submodule_status)
844845
PHP_FE(git_submodule_location, arginfo_git_submodule_location)
845846

847+
/* attr */
848+
PHP_FE(git_attr_value, arginfo_git_attr_value)
849+
PHP_FE(git_attr_get, arginfo_git_attr_get)
850+
PHP_FE(git_attr_get_many, arginfo_git_attr_get_many)
851+
PHP_FE(git_attr_foreach, arginfo_git_attr_foreach)
852+
PHP_FE(git_attr_cache_flush, arginfo_git_attr_cache_flush)
853+
PHP_FE(git_attr_add_macro, arginfo_git_attr_add_macro)
854+
846855
/* misc */
847856
PHP_FE(git_resource_type, arginfo_git_resource_type)
848857
PHP_FE_END

0 commit comments

Comments
 (0)