Skip to content

Commit 93fe1a6

Browse files
committed
added Git2\TreeEntry isSubmodule, isBlob, isTree methods
1 parent 6a957b7 commit 93fe1a6

10 files changed

+134
-0
lines changed

Diff for: tests/006-02-tree_entry_is_blob.phpt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Check for Git2\TreeEntry::construct
3+
--SKIPIF--
4+
<?php if (!extension_loaded("git2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$path = __DIR__ . '/fixtures/testrepo.git';
8+
$repo = new Git2\Repository($path);
9+
10+
$tree = $repo->lookup("199e7c128125a430899fc5c1c0bd08699c9a5692");
11+
foreach ($tree as $entry) {
12+
if ($entry->isBlob()) {
13+
echo "OK" . PHP_EOL;
14+
} else {
15+
echo "FAIL" . PHP_EOL;
16+
}
17+
}
18+
--EXPECT--
19+
OK

Diff for: tests/fixtures/init.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
$repo = new Git2\Repository(__DIR__ . "/fixtures/testrepo.git");
3+
$oids = array();
4+
$oids[] = $repo->write("Hello World",3);
5+
$oids[] = $repo->write("Hello Chobie",3);
6+
$oids[] = $repo->write("this is chobie",3);
7+
$oids[] = $repo->write("moe is Japanese word",3);
8+
9+
foreach ($oids as $oid) {
10+
echo $oid . PHP_EOL;
11+
}
12+
13+
/*
14+
e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
15+
a08e8505259a0ab4474ca79ba92bd7912b5a32c3
16+
87cef34f1a5c8d386418e9fa3e8948ef7322a007
17+
ca06beddccb5d9eb9bf4787ef42407a438b3abf1
18+
*/
19+
20+
$builder = new Git2\TreeBuilder();
21+
$builder->insert(new Git2\TreeEntry(array(
22+
"name" => "README",
23+
"oid" => "e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689",
24+
"attributes" => 33188,
25+
)));
26+
$oid = $builder->write($repo);
27+
echo $oid . PHP_EOL;
28+
/*
29+
199e7c128125a430899fc5c1c0bd08699c9a5692
30+
*/
31+
32+
$builder = new Git2\TreeBuilder();
33+
$i = 0;
34+
$builder->insert(new Git2\TreeEntry(array(
35+
"name" => "$i",
36+
"oid" => "e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689",
37+
"attributes" => 33188,
38+
)));
39+
$oid = $builder->write($repo);
40+
echo $oid . PHP_EOL;
41+
42+
/*
43+
2c83838315fd649b17e968e96e9d4543c9efd1e9
44+
*/
45+
46+
$builder = new Git2\TreeBuilder();
47+
for($i = 0;$i<1000;$i++){
48+
$builder->insert(new Git2\TreeEntry(array(
49+
"name" => "$i",
50+
"oid" => "e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689",
51+
"attributes" => 33188,
52+
)));
53+
}
54+
$oid = $builder->write($repo);
55+
echo $oid . PHP_EOL;
56+
// 74edf90112fadb1c0ea2dc48352e0ed4ead2e1cf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Diff for: tree_entry.c

+59
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,69 @@ PHP_METHOD(git2_tree_entry, __construct)
8585
}
8686
/* }}} */
8787

88+
/*
89+
{{{ proto: Git2\TreeEntry::isTree()
90+
*/
91+
PHP_METHOD(git2_tree_entry, isTree)
92+
{
93+
zval *value;
94+
long attribute = 0;
95+
96+
value = zend_read_property(git2_tree_entry_class_entry, getThis(), "attributes", sizeof("attributes")-1, 0 TSRMLS_CC);
97+
attribute = Z_LVAL_P(value);
98+
99+
if(attribute & 040000){
100+
RETURN_TRUE;
101+
}else{
102+
RETURN_FALSE;
103+
}
104+
}
105+
/* }}} */
106+
107+
/*
108+
{{{ proto: Git2\TreeEntry::isBlob()
109+
*/
110+
PHP_METHOD(git2_tree_entry, isBlob)
111+
{
112+
zval *value;
113+
long attribute = 0;
114+
115+
value = zend_read_property(git2_tree_entry_class_entry, getThis(), "attributes", sizeof("attributes")-1, 0 TSRMLS_CC);
116+
attribute = Z_LVAL_P(value);
117+
118+
if(!(attribute & 040000) && attribute != 0160000){
119+
RETURN_TRUE;
120+
}else{
121+
RETURN_FALSE;
122+
}
123+
}
124+
/* }}} */
125+
126+
/*
127+
{{{ proto: Git2\TreeEntry::isSubmodule()
128+
*/
129+
PHP_METHOD(git2_tree_entry, isSubmodule)
130+
{
131+
zval *value;
132+
long attribute = 0;
133+
134+
value = zend_read_property(git2_tree_entry_class_entry, getThis(), "attributes", sizeof("attributes")-1, 0 TSRMLS_CC);
135+
attribute = Z_LVAL_P(value);
136+
137+
if(attribute == 0160000){
138+
RETURN_TRUE;
139+
}else{
140+
RETURN_FALSE;
141+
}
142+
}
143+
/* }}} */
88144

89145

90146
static zend_function_entry php_git2_tree_entry_methods[] = {
91147
PHP_ME(git2_tree_entry, __construct, arginfo_git2_tree_entry___construct, ZEND_ACC_PUBLIC)
148+
PHP_ME(git2_tree_entry, isTree, NULL, ZEND_ACC_PUBLIC)
149+
PHP_ME(git2_tree_entry, isBlob, NULL, ZEND_ACC_PUBLIC)
150+
PHP_ME(git2_tree_entry, isSubmodule, NULL, ZEND_ACC_PUBLIC)
92151
{NULL,NULL,NULL}
93152
};
94153

0 commit comments

Comments
 (0)