Skip to content

Commit d9969f5

Browse files
committed
add stub codes
1 parent 93c4250 commit d9969f5

8 files changed

+662
-2
lines changed

blame.c

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+

blame.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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_BLAME_H
27+
#define PHP_GIT2_BLAME_H
28+
29+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_get_hunk_count, 0, 0, 1)
30+
ZEND_ARG_INFO(0, blame)
31+
ZEND_END_ARG_INFO()
32+
33+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_get_hunk_byindex, 0, 0, 2)
34+
ZEND_ARG_INFO(0, blame)
35+
ZEND_ARG_INFO(0, index)
36+
ZEND_END_ARG_INFO()
37+
38+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_get_hunk_byline, 0, 0, 2)
39+
ZEND_ARG_INFO(0, blame)
40+
ZEND_ARG_INFO(0, lineno)
41+
ZEND_END_ARG_INFO()
42+
43+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_file, 0, 0, 3)
44+
ZEND_ARG_INFO(0, repo)
45+
ZEND_ARG_INFO(0, path)
46+
ZEND_ARG_INFO(0, options)
47+
ZEND_END_ARG_INFO()
48+
49+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_buffer, 0, 0, 3)
50+
ZEND_ARG_INFO(0, reference)
51+
ZEND_ARG_INFO(0, buffer)
52+
ZEND_ARG_INFO(0, buffer_len)
53+
ZEND_END_ARG_INFO()
54+
55+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_free, 0, 0, 1)
56+
ZEND_ARG_INFO(0, blame)
57+
ZEND_END_ARG_INFO()
58+
59+
/* {{{ proto resource git_blame_get_hunk_count(blame)
60+
*/
61+
PHP_FUNCTION(git_blame_get_hunk_count);
62+
63+
/* {{{ proto resource git_blame_get_hunk_byindex(blame, index)
64+
*/
65+
PHP_FUNCTION(git_blame_get_hunk_byindex);
66+
67+
/* {{{ proto resource git_blame_get_hunk_byline(blame, lineno)
68+
*/
69+
PHP_FUNCTION(git_blame_get_hunk_byline);
70+
71+
/* {{{ proto resource git_blame_file(repo, path, options)
72+
*/
73+
PHP_FUNCTION(git_blame_file);
74+
75+
/* {{{ proto resource git_blame_buffer(reference, buffer, buffer_len)
76+
*/
77+
PHP_FUNCTION(git_blame_buffer);
78+
79+
/* {{{ proto void git_blame_free(blame)
80+
*/
81+
PHP_FUNCTION(git_blame_free);
82+
83+
#endif

config.m4

+1-1
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, $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, $ext_shared)
1111
PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include])
1212

1313
# for now

ng.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public function isCallbacker()
9393
if (preg_match("/callback$/", $arg->getType())) {
9494
return true;
9595
}
96+
if (preg_match("/packbuilder_progress/", $arg->getType())) {
97+
return true;
98+
}
9699
}
97100

98101
return false;
@@ -153,7 +156,16 @@ public function getType()
153156

154157
public function isCallback()
155158
{
156-
return preg_match("/_cb$/", $this->type);
159+
if (preg_match("/_cb$/", $this->getType())) {
160+
return true;
161+
}
162+
if (preg_match("/callback$/", $this->getType())) {
163+
return true;
164+
}
165+
if (preg_match("/packbuilder_progress/", $this->getType())) {
166+
return true;
167+
}
168+
return false;
157169
}
158170

159171
public function getPtr()
@@ -375,6 +387,8 @@ public function shouldResource(Arg $arg)
375387
"struct git_odb",
376388
"git_reflog",
377389
"git_reflog_entry",
390+
"git_blame",
391+
"git_packbuilder",
378392
);
379393
}
380394

0 commit comments

Comments
 (0)