Skip to content

Commit 7a1a21d

Browse files
committed
wip
1 parent 046d060 commit 7a1a21d

25 files changed

+4956
-22
lines changed

.gitmodules

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[submodule "libgit2"]
22
path = libgit2
3-
url = https://github.com/libgit2/libgit2.git
3+
url = https://github.com/libgit2/libgit2.git
4+
ignore = dirty

blob.c

+269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
#include "php_git2.h"
2+
#include "php_git2_priv.h"
3+
#include "blob.h"
4+
5+
/* {{{ proto resource git_blob_create_frombuffer(resource $repository, string $buffer)
6+
*/
7+
PHP_FUNCTION(git_blob_create_frombuffer)
8+
{
9+
zval *repository;
10+
php_git2_t *git2;
11+
char *buffer;
12+
int buffer_len;
13+
int error;
14+
git_oid id;
15+
char out[41] = {0};
16+
17+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
18+
"rs", &repository, &buffer, &buffer_len) == FAILURE) {
19+
return;
20+
}
21+
22+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
23+
24+
error = git_blob_create_frombuffer(&id, PHP_GIT2_V(git2, repository), buffer, buffer_len);
25+
if (php_git2_check_error(error, "git_blob_create_frombuffer" TSRMLS_CC)) {
26+
RETURN_FALSE
27+
}
28+
29+
git_oid_fmt(out, &id);
30+
RETURN_STRING(out, 1);
31+
}
32+
33+
/* {{{ proto resource git_blob_create_fromchunks(resource $repository, string $hintpath, Callable $callback, mixed payload)
34+
*/
35+
PHP_FUNCTION(git_blob_create_fromchunks)
36+
{
37+
}
38+
39+
/* {{{ proto resource git_blob_create_fromdisk(resource $repository, string $path)
40+
*/
41+
PHP_FUNCTION(git_blob_create_fromdisk)
42+
{
43+
zval *repository;
44+
php_git2_t *git2;
45+
char *path;
46+
int path_len;
47+
int error;
48+
git_oid id;
49+
char out[41] = {0};
50+
51+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
52+
"rs", &repository, &path, &path_len) == FAILURE) {
53+
return;
54+
}
55+
56+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
57+
58+
error = git_blob_create_fromdisk(&id, PHP_GIT2_V(git2, repository), path);
59+
if (php_git2_check_error(error, "git_blob_create_fromdisk" TSRMLS_CC)) {
60+
RETURN_FALSE
61+
}
62+
63+
git_oid_fmt(out, &id);
64+
RETURN_STRING(out, 1);
65+
}
66+
67+
/* {{{ proto resource git_blob_create_fromworkdir(resource $repository, string $relative_path)
68+
*/
69+
PHP_FUNCTION(git_blob_create_fromworkdir)
70+
{
71+
zval *repository;
72+
php_git2_t *git2;
73+
char *path;
74+
int path_len;
75+
int error;
76+
git_oid id;
77+
char out[41] = {0};
78+
79+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
80+
"rs", &repository, &path, &path_len) == FAILURE) {
81+
return;
82+
}
83+
84+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
85+
86+
error = git_blob_create_fromworkdir(&id, PHP_GIT2_V(git2, repository), path);
87+
if (php_git2_check_error(error, "git_blob_create_fromdisk" TSRMLS_CC)) {
88+
RETURN_FALSE
89+
}
90+
91+
git_oid_fmt(out, &id);
92+
RETURN_STRING(out, 1);
93+
}
94+
95+
/* {{{ proto resource git_blob_filtered_content($blob, $as_path, $check_for_binary_data)
96+
*/
97+
PHP_FUNCTION(git_blob_filtered_content)
98+
{
99+
}
100+
101+
/* {{{ proto resource git_blob_free(resource $blob)
102+
*/
103+
PHP_FUNCTION(git_blob_free)
104+
{
105+
zval *blob;
106+
php_git2_t *git2;
107+
108+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
109+
"r", &blob) == FAILURE) {
110+
return;
111+
}
112+
113+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
114+
if (git2->should_free_v) {
115+
git_blob_free(PHP_GIT2_V(git2, blob));
116+
git2->should_free_v = 0;
117+
}
118+
zval_ptr_dtor(&blob);
119+
}
120+
121+
/* {{{ proto resource git_blob_id(resource $blob)
122+
*/
123+
PHP_FUNCTION(git_blob_id)
124+
{
125+
zval *blob;
126+
php_git2_t *git2;
127+
char out[41] = {0};
128+
const git_oid *id;
129+
130+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
131+
"r", &blob) == FAILURE) {
132+
return;
133+
}
134+
135+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
136+
id = git_blob_id(PHP_GIT2_V(git2, blob));
137+
138+
git_oid_fmt(out, id);
139+
RETURN_STRING(out, 1);
140+
}
141+
142+
/* {{{ proto resource git_blob_is_binary(resource $blob)
143+
*/
144+
PHP_FUNCTION(git_blob_is_binary)
145+
{
146+
zval *blob;
147+
php_git2_t *git2;
148+
int result;
149+
150+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
151+
"r", &blob) == FAILURE) {
152+
return;
153+
}
154+
155+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
156+
result = git_blob_is_binary(PHP_GIT2_V(git2, blob));
157+
RETURN_BOOL(result);
158+
}
159+
160+
/* {{{ proto resource git_blob_lookup(resource $repository, string $oid)
161+
*/
162+
PHP_FUNCTION(git_blob_lookup)
163+
{
164+
zval *repository;
165+
php_git2_t *git2, *result;
166+
git_blob *blob;
167+
char *hash;
168+
int hash_len;
169+
int error;
170+
git_oid id;
171+
172+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
173+
"rs", &repository, &hash, &hash_len) == FAILURE) {
174+
return;
175+
}
176+
177+
if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) {
178+
return;
179+
}
180+
181+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
182+
183+
PHP_GIT2_MAKE_RESOURCE(result);
184+
error = git_blob_lookup(&blob, PHP_GIT2_V(git2, repository), &id);
185+
if (php_git2_check_error(error, "git_blob_lookup" TSRMLS_CC)) {
186+
RETURN_FALSE
187+
}
188+
189+
PHP_GIT2_V(result, blob) = blob;
190+
result->type = PHP_GIT2_TYPE_BLOB;
191+
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
192+
result->should_free_v = 0;
193+
194+
ZVAL_RESOURCE(return_value, result->resource_id);
195+
}
196+
197+
/* {{{ proto resource git_blob_lookup_prefix(resource $blob, string $oid)
198+
*/
199+
PHP_FUNCTION(git_blob_lookup_prefix)
200+
{
201+
}
202+
203+
/* {{{ proto resource git_blob_owner(resource $blob, string $oid)
204+
*/
205+
PHP_FUNCTION(git_blob_owner)
206+
{
207+
zval *blob;
208+
php_git2_t *git2, *result;
209+
git_repository *repository;
210+
211+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
212+
"r", &blob) == FAILURE) {
213+
return;
214+
}
215+
216+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
217+
218+
PHP_GIT2_MAKE_RESOURCE(result);
219+
repository = git_blob_owner(PHP_GIT2_V(git2, blob));
220+
221+
PHP_GIT2_V(result, repository) = repository;
222+
result->type = PHP_GIT2_TYPE_REPOSITORY;
223+
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
224+
result->should_free_v = 0;
225+
226+
ZVAL_RESOURCE(return_value, result->resource_id);
227+
}
228+
229+
/* {{{ proto resource git_blob_rawcontent(resource $blob)
230+
*/
231+
PHP_FUNCTION(git_blob_rawcontent)
232+
{
233+
zval *blob;
234+
php_git2_t *git2;
235+
const char *buffer = NULL;
236+
git_off_t size;
237+
238+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
239+
"r", &blob) == FAILURE) {
240+
return;
241+
}
242+
243+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
244+
245+
buffer = git_blob_rawcontent(PHP_GIT2_V(git2, blob));
246+
if (buffer == NULL) {
247+
RETURN_FALSE;
248+
}
249+
size = git_blob_rawsize(PHP_GIT2_V(git2, blob));
250+
RETURN_STRINGL(buffer, size, 1);
251+
}
252+
253+
/* {{{ proto resource git_blob_rawsize(resource $blob, string $oid)
254+
*/
255+
PHP_FUNCTION(git_blob_rawsize)
256+
{
257+
zval *blob;
258+
php_git2_t *git2;
259+
git_off_t size;
260+
261+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
262+
"r", &blob) == FAILURE) {
263+
return;
264+
}
265+
266+
ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
267+
size = git_blob_rawsize(PHP_GIT2_V(git2, blob));
268+
RETURN_LONG(size);
269+
}

0 commit comments

Comments
 (0)