Skip to content

Commit fafa8b0

Browse files
committed
added Git\Repository::open2($git_dir,$git_object_directory,$git_index_file, $git_work_tree);
1 parent 21fa246 commit fafa8b0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/repository.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_get_references, 0, 0, 1)
8484
ZEND_ARG_INFO(0, flag)
8585
ZEND_END_ARG_INFO()
8686

87+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_open2, 0, 0, 4)
88+
ZEND_ARG_INFO(0, git_dir)
89+
ZEND_ARG_INFO(0, git_object_directory)
90+
ZEND_ARG_INFO(0, git_index_file)
91+
ZEND_ARG_INFO(0, git_work_tree)
92+
ZEND_END_ARG_INFO()
93+
8794
static void php_git_repository_free_storage(php_git_repository_t *obj TSRMLS_DC)
8895
{
8996
// if added some backend. free backend before free zend_object.
@@ -601,6 +608,40 @@ PHP_METHOD(git_repository, open3)
601608
}
602609
}
603610

611+
PHP_METHOD(git_repository, open2)
612+
{
613+
php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
614+
char *git_dir;
615+
char *git_object_directory;
616+
char *git_index_file;
617+
char *git_work_tree;
618+
int git_dir_len = 0;
619+
int git_object_directory_len = 0;
620+
int git_index_file_len = 0;
621+
int git_work_tree_len = 0;
622+
git_repository *repository;
623+
624+
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
625+
"ssss", &git_dir, &git_dir_len, &git_object_directory, &git_object_directory_len, &git_index_file, &git_index_file_len, &git_work_tree, &git_work_tree_len) == FAILURE){
626+
return;
627+
}
628+
629+
if(this->repository != NULL){
630+
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "repository busy");
631+
return;
632+
}
633+
634+
int ret = git_repository_open2(&repository,git_dir, git_object_directory, git_index_file, git_work_tree);
635+
if(ret != GIT_SUCCESS){
636+
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't open specified directories");
637+
RETURN_FALSE;
638+
}
639+
640+
add_property_string_ex(getThis(), "path",sizeof("path"),(char *)git_dir, 1 TSRMLS_CC);
641+
this->repository = repository;
642+
RETURN_TRUE;
643+
}
644+
604645

605646
PHPAPI function_entry php_git_repository_methods[] = {
606647
PHP_ME(git_repository, __construct, arginfo_git_construct, ZEND_ACC_PUBLIC)
@@ -614,6 +655,7 @@ PHPAPI function_entry php_git_repository_methods[] = {
614655
PHP_ME(git_repository, addBackend, arginfo_git_add_backend, ZEND_ACC_PUBLIC)
615656
PHP_ME(git_repository, addAlternate, arginfo_git_add_alternate, ZEND_ACC_PUBLIC)
616657
PHP_ME(git_repository, open3, arginfo_git_open3, ZEND_ACC_PUBLIC)
658+
PHP_ME(git_repository, open2, arginfo_git_open2, ZEND_ACC_PUBLIC)
617659
PHP_ME(git_repository, getReferences, arginfo_git_get_references, ZEND_ACC_PUBLIC)
618660
{NULL, NULL, NULL}
619661
};

0 commit comments

Comments
 (0)