Skip to content

Commit 6a957b7

Browse files
committed
added Git2\Remoete class.but acutually it can instanciate only.
1 parent 36c0b21 commit 6a957b7

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

Diff for: config.m4

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ if test $PHP_GIT2 != "no"; then
4242
index.c \
4343
index_entry.c \
4444
config.c \
45+
remote.c \
4546
, $ext_shared)
4647

4748
ifdef([PHP_ADD_EXTENSION_DEP],

Diff for: git2.c

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern void php_git2_signature_init(TSRMLS_D);
3333
extern void php_git2_walker_init(TSRMLS_D);
3434
extern void php_git2_reference_init(TSRMLS_D);
3535
extern void php_git2_config_init(TSRMLS_D);
36+
extern void php_git2_remote_init(TSRMLS_D);
3637

3738

3839
int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...)
@@ -178,6 +179,7 @@ PHP_MINIT_FUNCTION(git2)
178179
php_git2_index_entry_init(TSRMLS_C);
179180
php_git2_index_init(TSRMLS_C);
180181
php_git2_config_init(TSRMLS_C);
182+
php_git2_remote_init(TSRMLS_C);
181183

182184
return SUCCESS;
183185
}

Diff for: php_git2.h

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extern PHPAPI zend_class_entry *git2_reference_class_entry;
5555
extern PHPAPI zend_class_entry *git2_index_class_entry;
5656
extern PHPAPI zend_class_entry *git2_index_entry_class_entry;
5757
extern PHPAPI zend_class_entry *git2_config_class_entry;
58+
extern PHPAPI zend_class_entry *git2_remote_class_entry;
5859

5960
typedef struct{
6061
zend_object zo;
@@ -121,6 +122,11 @@ typedef struct{
121122
git_config *config;
122123
} php_git2_config;
123124

125+
typedef struct{
126+
zend_object zo;
127+
git_remote *remote;
128+
} php_git2_remote;
129+
124130

125131
# define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC);
126132

Diff for: remote.c

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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_remote_class_entry;
28+
29+
static void php_git2_remote_free_storage(php_git2_remote *object TSRMLS_DC)
30+
{
31+
if (object->remote != NULL) {
32+
free(object->remote);
33+
object->remote = NULL;
34+
}
35+
zend_object_std_dtor(&object->zo TSRMLS_CC);
36+
efree(object);
37+
}
38+
39+
zend_object_value php_git2_remote_new(zend_class_entry *ce TSRMLS_DC)
40+
{
41+
zend_object_value retval;
42+
43+
PHP_GIT2_STD_CREATE_OBJECT(php_git2_remote);
44+
return retval;
45+
}
46+
47+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_remote___construct, 0,0,2)
48+
ZEND_ARG_INFO(0, repository)
49+
ZEND_ARG_INFO(0, url)
50+
ZEND_END_ARG_INFO()
51+
52+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_remote_connect, 0,0,1)
53+
ZEND_ARG_INFO(0, direction)
54+
ZEND_END_ARG_INFO()
55+
56+
/*
57+
{{{ proto: Git2\Remote::__construct(Git2\Repository $repository, string $url)
58+
*/
59+
PHP_METHOD(git2_remote, __construct)
60+
{
61+
char *path;
62+
git_config *config;
63+
int error, path_len = 0;
64+
zval *repository;
65+
php_git2_repository *m_repository;
66+
php_git2_remote *m_remote;
67+
git_remote *remote;
68+
69+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
70+
"Os", &repository,git2_repository_class_entry, &path, &path_len) == FAILURE) {
71+
return;
72+
}
73+
74+
m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository);
75+
m_remote = PHP_GIT2_GET_OBJECT(php_git2_remote, getThis());
76+
if (git_remote_valid_url(path)) {
77+
error = git_remote_new(
78+
&remote,
79+
m_repository->repository,
80+
path,
81+
NULL
82+
);
83+
} else {
84+
error = git_remote_load(&remote,m_repository->repository, path);
85+
}
86+
m_remote->remote = remote;
87+
}
88+
/* }}} */
89+
90+
/*
91+
{{{ proto: Git2\Remote::connect(int type)
92+
*/
93+
PHP_METHOD(git2_remote, connect)
94+
{
95+
php_git2_remote *m_remote;
96+
int error = 0;
97+
long direction = 0;
98+
99+
m_remote = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis());
100+
101+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
102+
"l", &direction) == FAILURE) {
103+
return;
104+
}
105+
106+
if (direction == 0) {
107+
direction = GIT_DIR_FETCH;
108+
}
109+
110+
error = git_remote_connect(m_remote->remote, direction);
111+
}
112+
/* }}} */
113+
114+
static zend_function_entry php_git2_remote_methods[] = {
115+
PHP_ME(git2_remote, __construct, arginfo_git2_remote___construct, ZEND_ACC_PUBLIC)
116+
PHP_ME(git2_remote, connect, arginfo_git2_remote_connect, ZEND_ACC_PUBLIC)
117+
{NULL,NULL,NULL}
118+
};
119+
120+
void php_git2_remote_init(TSRMLS_D)
121+
{
122+
zend_class_entry ce;
123+
124+
INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Remote", php_git2_remote_methods);
125+
git2_remote_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
126+
git2_remote_class_entry->create_object = php_git2_remote_new;
127+
}

0 commit comments

Comments
 (0)