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