Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 202 lines (169 sloc) 5.363 kB
79f3676 @chobie for now, added Git2\Index
chobie authored
1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010 - 2012 Shuhei Tanuma
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #include "php_git2.h"
a375308 @chobie for now, implemented iterator feature to Git2\Index
chobie authored
26 #include <spl/spl_array.h>
27 #include <zend_interfaces.h>
79f3676 @chobie for now, added Git2\Index
chobie authored
28
29 PHPAPI zend_class_entry *git2_index_class_entry;
30
31 static void php_git2_index_free_storage(php_git2_index *object TSRMLS_DC)
32 {
33 if (object->index != NULL) {
34 object->index = NULL;
35 }
36 zend_object_std_dtor(&object->zo TSRMLS_CC);
37 efree(object);
38 }
39
40 zend_object_value php_git2_index_new(zend_class_entry *ce TSRMLS_DC)
41 {
42 zend_object_value retval;
43
44 PHP_GIT2_STD_CREATE_OBJECT(php_git2_index);
45 return retval;
46 }
47
48 ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_index___construct, 0,0,1)
49 ZEND_ARG_INFO(0, entry)
50 ZEND_END_ARG_INFO()
51
52 /*
53 {{{ proto: Git2\Index::__construct(string $path)
54 */
55 PHP_METHOD(git2_index, __construct)
56 {
57 char *path;
58 git_index *index;
59 int error, path_len = 0;
60 php_git2_index *m_index;
61
62 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
63 "s", &path, &path_len) == FAILURE) {
64 return;
65 }
66
67 error = git_index_open(&index, path);
68 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
69 m_index->index = index;
70 }
71 /* }}} */
72
73
e057413 @chobie added Git2\IndexEntry
chobie authored
74 /*
75 {{{ proto: Git2\Index::count()
76 */
77 PHP_METHOD(git2_index, count)
78 {
79 php_git2_index *m_index;
80
81 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
82 RETURN_LONG(git_index_entrycount(m_index->index));
83 }
84 /* }}} */
85
86 /*
87 {{{ proto: Git2\Index::writeTree()
88 */
89 PHP_METHOD(git2_index, writeTree)
90 {
91 php_git2_index *m_index;
92 git_oid tree_oid;
93 char oid_out[GIT_OID_HEXSZ] = {0};
94 int error = 0;
95
96 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
97 error = git_tree_create_fromindex(&tree_oid, m_index->index);
98
99 git_oid_fmt(oid_out, &tree_oid);
100 RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1);
101 }
102 /* }}} */
103
104
79f3676 @chobie for now, added Git2\Index
chobie authored
105
a375308 @chobie for now, implemented iterator feature to Git2\Index
chobie authored
106 /* Iterator Implementation */
107
108 /*
109 {{{ proto: Git2\Tree::current()
110 */
111 PHP_METHOD(git2_index, current)
112 {
113 php_git2_index *m_index;
114 const git_index_entry *entry;
115 zval *z_entry;
116
117 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
118 entry = git_index_get(m_index->index, m_index->offset);
119 if (entry == NULL) {
120 zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
121 "specified offset does not exist. %d");
122 RETURN_FALSE;
123 }
e057413 @chobie added Git2\IndexEntry
chobie authored
124
919186b @chobie fixed compiler warnings
chobie authored
125 php_git2_create_index_entry(&z_entry, (git_index_entry *)entry TSRMLS_CC);
e057413 @chobie added Git2\IndexEntry
chobie authored
126 RETURN_ZVAL(z_entry, 0, 1);
a375308 @chobie for now, implemented iterator feature to Git2\Index
chobie authored
127 }
128
129 /*
130 {{{ proto: Git2\Tree::key()
131 */
132 PHP_METHOD(git2_index, key)
133 {
134 php_git2_index *m_index;
135
136 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
137 RETURN_LONG(m_index->offset);
138 }
139
140 /*
141 {{{ proto: Git2\Tree::valid()
142 */
143 PHP_METHOD(git2_index, next)
144 {
145 php_git2_index *m_index;
146
147 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
148 m_index->offset++;
149 }
150
151 /*
152 {{{ proto: Git2\Tree::rewind()
153 */
154 PHP_METHOD(git2_index, rewind)
155 {
156 php_git2_index *m_index;
157
158 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
159 m_index->offset = 0;
160 }
161
162 /*
163 {{{ proto: Git2\Index::valid()
164 */
165 PHP_METHOD(git2_index, valid)
166 {
167 php_git2_index *m_index;
168 int entry_count = 0;
169
170 m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
171 entry_count = git_index_entrycount(m_index->index);
a18e511 @chobie fix several compile warnings
chobie authored
172 if (m_index->offset < entry_count) {
a375308 @chobie for now, implemented iterator feature to Git2\Index
chobie authored
173 RETURN_TRUE;
174 } else {
175 RETURN_FALSE;
176 }
177 }
178 /* }}} */
179
180
79f3676 @chobie for now, added Git2\Index
chobie authored
181 static zend_function_entry php_git2_index_methods[] = {
a2571fa @chobie added ZEND_ACC_CTOR
chobie authored
182 PHP_ME(git2_index, __construct, arginfo_git2_index___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
e057413 @chobie added Git2\IndexEntry
chobie authored
183 PHP_ME(git2_index, count, NULL, ZEND_ACC_PUBLIC)
a375308 @chobie for now, implemented iterator feature to Git2\Index
chobie authored
184 /* Iterator Implementation */
185 PHP_ME(git2_index, current, NULL, ZEND_ACC_PUBLIC)
186 PHP_ME(git2_index, key, NULL, ZEND_ACC_PUBLIC)
187 PHP_ME(git2_index, next, NULL, ZEND_ACC_PUBLIC)
188 PHP_ME(git2_index, rewind, NULL, ZEND_ACC_PUBLIC)
189 PHP_ME(git2_index, valid, NULL, ZEND_ACC_PUBLIC)
e057413 @chobie added Git2\IndexEntry
chobie authored
190 PHP_ME(git2_index, writeTree, NULL, ZEND_ACC_PUBLIC)
79f3676 @chobie for now, added Git2\Index
chobie authored
191 {NULL,NULL,NULL}
192 };
193
194 void php_git2_index_init(TSRMLS_D)
195 {
196 zend_class_entry ce;
197
198 INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Index", php_git2_index_methods);
199 git2_index_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
200 git2_index_class_entry->create_object = php_git2_index_new;
a375308 @chobie for now, implemented iterator feature to Git2\Index
chobie authored
201 zend_class_implements(git2_index_class_entry TSRMLS_CC, 1, spl_ce_Iterator);
79f3676 @chobie for now, added Git2\Index
chobie authored
202 }
Something went wrong with that request. Please try again.