Skip to content

Commit 79f3676

Browse files
committed
for now, added Git2\Index
1 parent 5ae8d60 commit 79f3676

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ if test $PHP_GIT2 != "no"; then
3939
signature.c \
4040
walker.c \
4141
reference.c \
42+
index.c \
4243
, $ext_shared)
4344

4445
ifdef([PHP_ADD_EXTENSION_DEP],

git2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ PHP_MINIT_FUNCTION(git2)
174174
php_git2_signature_init(TSRMLS_C);
175175
php_git2_walker_init(TSRMLS_C);
176176
php_git2_reference_init(TSRMLS_C);
177+
php_git2_index_init(TSRMLS_C);
177178

178179
return SUCCESS;
179180
}

index.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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"
26+
27+
PHPAPI zend_class_entry *git2_index_class_entry;
28+
29+
static void php_git2_index_free_storage(php_git2_index *object TSRMLS_DC)
30+
{
31+
if (object->index != NULL) {
32+
object->index = NULL;
33+
}
34+
zend_object_std_dtor(&object->zo TSRMLS_CC);
35+
efree(object);
36+
}
37+
38+
zend_object_value php_git2_index_new(zend_class_entry *ce TSRMLS_DC)
39+
{
40+
zend_object_value retval;
41+
42+
PHP_GIT2_STD_CREATE_OBJECT(php_git2_index);
43+
return retval;
44+
}
45+
46+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_index___construct, 0,0,1)
47+
ZEND_ARG_INFO(0, entry)
48+
ZEND_END_ARG_INFO()
49+
50+
/*
51+
{{{ proto: Git2\Index::__construct(string $path)
52+
*/
53+
PHP_METHOD(git2_index, __construct)
54+
{
55+
char *path;
56+
git_index *index;
57+
int error, path_len = 0;
58+
php_git2_index *m_index;
59+
60+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
61+
"s", &path, &path_len) == FAILURE) {
62+
return;
63+
}
64+
65+
error = git_index_open(&index, path);
66+
m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis());
67+
m_index->index = index;
68+
}
69+
/* }}} */
70+
71+
72+
73+
static zend_function_entry php_git2_index_methods[] = {
74+
PHP_ME(git2_index, __construct, arginfo_git2_index___construct, ZEND_ACC_PUBLIC)
75+
{NULL,NULL,NULL}
76+
};
77+
78+
void php_git2_index_init(TSRMLS_D)
79+
{
80+
zend_class_entry ce;
81+
82+
INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Index", php_git2_index_methods);
83+
git2_index_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
84+
git2_index_class_entry->create_object = php_git2_index_new;
85+
}

php_git2.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern PHPAPI zend_class_entry *git2_tree_entry_class_entry;
5252
extern PHPAPI zend_class_entry *git2_signature_class_entry;
5353
extern PHPAPI zend_class_entry *git2_walker_class_entry;
5454
extern PHPAPI zend_class_entry *git2_reference_class_entry;
55+
extern PHPAPI zend_class_entry *git2_index_class_entry;
5556

5657
typedef struct{
5758
zend_object zo;
@@ -102,6 +103,11 @@ typedef struct{
102103
git_repository *repository;
103104
} php_git2_walker;
104105

106+
typedef struct{
107+
zend_object zo;
108+
git_index *index;
109+
} php_git2_index;
110+
105111

106112
# define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC);
107113

0 commit comments

Comments
 (0)