From 1cf68604eeceb639be67872ac19945c94103b4a1 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 24 Sep 2012 22:03:06 +0900 Subject: [PATCH 001/136] reference: fix #36 add Git2\Reference::create method now, you can create a branch like this. ```` $repo = new Git2\Repository(".git"); $branch_name = "refs/heads/feature/create_branch"; $oid_or_symbolic_ref = "b4fd0a854ae8a6a02c89ab08e3e2f41bd4832ff1"; $force = false; $ref = Git2\Reference::create($repo, $branch_name, $oid_or_symbolic_ref, $force); ```` this API throws \RuntimeException when failed. --- reference.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/reference.c b/reference.c index 462ced95b5..cfc3b78a3b 100644 --- a/reference.c +++ b/reference.c @@ -43,6 +43,13 @@ zend_object_value php_git2_reference_new(zend_class_entry *ce TSRMLS_DC) return retval; } +ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_reference_create, 0,0,4) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_reference_lookup, 0,0,2) ZEND_ARG_INFO(0, repository) ZEND_ARG_INFO(0, path) @@ -162,6 +169,50 @@ PHP_METHOD(git2_reference, resolve) /* }}} */ +/* +{{{ proto: Git2\Reference::create(Git2\Repository $repo, string $name, string $oid_or_symbolic_ref[, bool $force = false]) +*/ +PHP_METHOD(git2_reference, create) +{ + zval *repository = NULL; + php_git2_repository *m_repository; + php_git2_reference *m_reference; + char *name, *target; + int error = 0, target_len = 0, name_len = 0; + zend_bool force = 0; + git_reference *ref; + git_oid oid; + zval *object; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "Oss|b", &repository, git2_repository_class_entry, &name, &name_len, &target, &target_len, &force) == FAILURE) { + return; + } + + m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); + + if (git_oid_fromstr(&oid, target) == GIT_OK) { + error = git_reference_create_oid(&ref, m_repository->repository, name, &oid, (int)force); + } else { + error = git_reference_create_symbolic(&ref, m_repository->repository, name, target, (int)force); + } + + if (error != GIT_OK) { + const git_error *err; + + err = giterr_last(); + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Git2\\Refernce::create failed: %s (%d)", err->message, err->klass); + } + + MAKE_STD_ZVAL(object); + object_init_ex(object, git2_reference_class_entry); + m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, object); + m_reference->reference = ref; + + RETURN_ZVAL(object, 0, 1); +} +/* }}} */ + typedef struct { unsigned int type; @@ -264,6 +315,7 @@ static zend_function_entry php_git2_reference_methods[] = { PHP_ME(git2_reference, getName, NULL, ZEND_ACC_PUBLIC) PHP_ME(git2_reference, getBaseName,NULL,ZEND_ACC_PUBLIC) PHP_ME(git2_reference, resolve, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git2_reference, create, arginfo_git2_reference_create, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(git2_reference, each, arginfo_git2_reference_each, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) #ifdef lookup #undef lookup From 351b3c0cd67eb8e4bb023b9b087217bbe8b3a885 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 27 Sep 2012 22:22:04 +0900 Subject: [PATCH 002/136] update libgit2 --- git2.c | 2 +- libgit2 | 2 +- php_git2.h | 2 +- repository.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/git2.c b/git2.c index 2c5c9600f6..a40cb47ea1 100644 --- a/git2.c +++ b/git2.c @@ -145,7 +145,7 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ object_init_ex(m_entry, git2_tree_entry_class_entry); add_property_stringl_ex(m_entry, "name", sizeof("name"), (const char *)entry_name, strlen(entry_name), 1 TSRMLS_CC); add_property_stringl_ex(m_entry, "oid", sizeof("oid"), (const char *)entry_oid, strlen(entry_oid), 1 TSRMLS_CC); - add_property_long_ex(m_entry, "attributes", sizeof("attributes"), git_tree_entry_attributes(entry) TSRMLS_CC); + add_property_long_ex(m_entry, "attributes", sizeof("attributes"), git_tree_entry_filemode(entry) TSRMLS_CC); add_next_index_zval(m_array, m_entry); } diff --git a/libgit2 b/libgit2 index e4607392b5..5942bd18bf 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit e4607392b5cbdcaf6a5dc810ca77b5dd1afcb147 +Subproject commit 5942bd18bf557cc70873009c4303a421c83f0129 diff --git a/php_git2.h b/php_git2.h index 19b304220d..cb82c99080 100644 --- a/php_git2.h +++ b/php_git2.h @@ -281,7 +281,7 @@ static inline void create_tree_entry_from_entry(zval **object, git_tree_entry *e add_property_string(*object, "name", (char *)git_tree_entry_name(entry), 1); add_property_string(*object, "oid", buf, 1); - add_property_long(*object, "attributes", git_tree_entry_attributes(entry)); + add_property_long(*object, "attributes", git_tree_entry_filemode(entry)); } static inline void php_git2_create_index_entry(zval **object, git_index_entry *entry TSRMLS_DC) diff --git a/repository.c b/repository.c index cb77cd19a3..c0e7c57f99 100644 --- a/repository.c +++ b/repository.c @@ -86,6 +86,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_lookup, 0,0,1) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_checkout, 0,0,0) +ZEND_END_ARG_INFO() + static int php_git2_repository_initialize(zval *object, git_repository *repository TSRMLS_DC) { zval *odb; @@ -497,6 +500,33 @@ PHP_METHOD(git2_repository, hash) /* }}} */ +/* +{{{ proto: Git2\Repository::checkout(Git2\Tree $tree[, int $opts, zval $stats) + TODO: implement this +*/ +PHP_METHOD(git2_repository, checkout) +{ +/* + php_git2_repository *m_repository; + php_git2_tree *m_tree; + zval *tree; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "O", &tree, git2_tree_class_entry) == FAILURE) { + return; + } + + m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); + m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, tree); + + error = git_checkout_tree(m_repository->repository, m_tree->tree, NULL, NULL); + RETURN_LONG(error); +*/ +} +/* }}} */ + + static zend_function_entry php_git2_repository_methods[] = { PHP_ME(git2_repository, __construct, arginfo_git2_repository___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_ME(git2_repository, isEmpty, NULL, ZEND_ACC_PUBLIC) @@ -511,6 +541,7 @@ static zend_function_entry php_git2_repository_methods[] = { PHP_ME(git2_repository, hash, arginfo_git2_repository_hash, ZEND_ACC_PUBLIC) PHP_ME(git2_repository, write, arginfo_git2_repository_write, ZEND_ACC_PUBLIC) PHP_ME(git2_repository, getMergeBase,arginfo_git2_repository_get_merge_base,ZEND_ACC_PUBLIC) + PHP_ME(git2_repository, checkout, arginfo_git2_repository_checkout, ZEND_ACC_PUBLIC) #ifdef lookup #undef lookup #endif From eb8cd9bedd301c4f6865ff05f50598bfcf306cda Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 12 Nov 2012 00:33:15 +0900 Subject: [PATCH 003/136] update libgit2 --- config.c | 32 ++++++++++++++++++-------------- libgit2 | 2 +- remote.c | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/config.c b/config.c index 715851b350..09d0eae601 100644 --- a/config.c +++ b/config.c @@ -209,10 +209,10 @@ static int php_git2_config_resolve(zval **result, const char *var_name, zval *m_ return error; } -static int php_git2_config_foreach(const char *var_name, const char *value, void *payload) +static int php_git2_config_foreach(const git_config_entry * entry, void *payload) { HashTable *hash; - zval *entry, **target_offset; + zval *zentry, **target_offset; const char *config_value; char *current_key, *tmp_value, *savedptr, *k; php_git2_config_foreach_t *opaque = (php_git2_config_foreach_t *)payload; @@ -220,9 +220,9 @@ static int php_git2_config_foreach(const char *var_name, const char *value, void hash = Z_ARRVAL_P(opaque->result); - error = git_config_get_string(&config_value, opaque->config, var_name); + error = git_config_get_string(&config_value, opaque->config, entry->name); - tmp_value = estrdup(var_name); + tmp_value = estrdup(entry->name); current_key = php_strtok_r(tmp_value, ".", &savedptr); while (current_key != NULL) { k = current_key; @@ -234,20 +234,24 @@ static int php_git2_config_foreach(const char *var_name, const char *value, void hash = Z_ARRVAL_P(*target_offset); } } else { - MAKE_STD_ZVAL(entry); - array_init(entry); - zend_hash_add(hash, k, strlen(k)+1, (void **)&entry, sizeof(entry), NULL); - hash = Z_ARRVAL_P(entry); + MAKE_STD_ZVAL(zentry); + array_init(zentry); + zend_hash_add(hash, k, strlen(k)+1, (void **)&zentry, sizeof(zentry), NULL); + hash = Z_ARRVAL_P(zentry); } } } if (k != NULL) { - MAKE_STD_ZVAL(entry); - ZVAL_STRING(entry, config_value, 1); - zend_hash_add(hash, k, strlen(k)+1, (void **)&entry, sizeof(entry), NULL); - Z_ADDREF_P(entry); - zval_ptr_dtor(&entry); + MAKE_STD_ZVAL(zentry); + if (config_value) { + ZVAL_STRING(zentry, config_value, 1); + } else { + ZVAL_NULL(zentry); + } + zend_hash_add(hash, k, strlen(k)+1, (void **)&zentry, sizeof(zentry), NULL); + Z_ADDREF_P(zentry); + zval_ptr_dtor(&zentry); } efree(tmp_value); @@ -273,7 +277,7 @@ static int php_git2_config_reload(zval *object, unsigned short dtor TSRMLS_DC) payload.config = m_config->config; payload.result = entry; - error = git_config_foreach(m_config->config,&php_git2_config_foreach,&payload); + error = git_config_foreach(m_config->config, &php_git2_config_foreach, &payload); add_property_zval(object, "configs", entry); if (dtor == 1) { zval_ptr_dtor(&entry); diff --git a/libgit2 b/libgit2 index 5942bd18bf..d18713fb4a 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit 5942bd18bf557cc70873009c4303a421c83f0129 +Subproject commit d18713fb4ad1ba3d18a75272e1c1c3eb45715aba diff --git a/remote.c b/remote.c index 35416ec8fc..4b81e7be62 100644 --- a/remote.c +++ b/remote.c @@ -125,7 +125,7 @@ PHP_METHOD(git2_remote, fetch) { php_git2_remote *m_remote; git_indexer *idx = NULL; - git_indexer_stats stats; + git_transfer_progress stats; char *packname = NULL; int error = 0; long direction = 0; From b28d1452f11cece0ed8d6370723251247b1d5d6f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 12 Nov 2012 01:02:05 +0900 Subject: [PATCH 004/136] repository: temporary add tree diff feature. proto: Git2\Repository::diff(Git2\Tree $a, Git2\Tree $b, $options = NULL) this will generate `git diff --name-status` format string like this. ```` A 008-02/refs/heads/.gitkeep A 008-02/refs/heads/master D init.php D testrepo.git/HEAD ```` --- repository.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/repository.c b/repository.c index c0e7c57f99..04ef7adb06 100644 --- a/repository.c +++ b/repository.c @@ -23,6 +23,7 @@ */ #include "php_git2.h" +#include "ext/standard/php_smart_str.h" PHPAPI zend_class_entry *git2_repository_class_entry; void php_git2_repository_init(TSRMLS_D); @@ -527,6 +528,52 @@ PHP_METHOD(git2_repository, checkout) /* }}} */ +static int printer( + void *data, + const git_diff_delta *delta, + const git_diff_range *range, + char usage, + const char *line, + size_t line_len) +{ + smart_str *string = (smart_str*)data; + + smart_str_appendl(string, line, strlen(line)); + return 0; +} + +/* +{{{ proto: Git2\Repository::diff(Git2\Tree $a, Git2\Tree $b, $options = NULL) + Experimental +*/ +PHP_METHOD(git2_repository, diff) +{ + zval *old, *new; + php_git2_tree *m_old, *m_new; + php_git2_repository *m_repository; + git_diff_list *list; + smart_str string = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "OO", &old, git2_tree_class_entry, &new, git2_tree_class_entry) == FAILURE) { + return; + } + + m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); + m_old = PHP_GIT2_GET_OBJECT(php_git2_tree, old); + m_new = PHP_GIT2_GET_OBJECT(php_git2_tree, new); + + git_diff_tree_to_tree(m_repository->repository, NULL, m_old->tree, m_new->tree, &list); + + git_diff_print_compact(list, &string, printer); + smart_str_0(&string); + git_diff_list_free(list); + + RETVAL_STRING(string.c, 0); +} +/* }}} */ + + static zend_function_entry php_git2_repository_methods[] = { PHP_ME(git2_repository, __construct, arginfo_git2_repository___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_ME(git2_repository, isEmpty, NULL, ZEND_ACC_PUBLIC) @@ -542,6 +589,7 @@ static zend_function_entry php_git2_repository_methods[] = { PHP_ME(git2_repository, write, arginfo_git2_repository_write, ZEND_ACC_PUBLIC) PHP_ME(git2_repository, getMergeBase,arginfo_git2_repository_get_merge_base,ZEND_ACC_PUBLIC) PHP_ME(git2_repository, checkout, arginfo_git2_repository_checkout, ZEND_ACC_PUBLIC) + PHP_ME(git2_repository, diff, NULL, ZEND_ACC_PUBLIC) #ifdef lookup #undef lookup #endif From 8f8627b0219d61cf13c4582b1d6d5a157e0ca0ce Mon Sep 17 00:00:00 2001 From: Alex White Date: Fri, 22 Feb 2013 11:33:37 +0000 Subject: [PATCH 005/136] - Fix tor the "undefined symbol: git_index_get in Unknown on line 0" error for the php module --- index.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.c b/index.c index 1835c0e8e3..e3c45c77ef 100644 --- a/index.c +++ b/index.c @@ -94,7 +94,7 @@ PHP_METHOD(git2_index, writeTree) int error = 0; m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - error = git_tree_create_fromindex(&tree_oid, m_index->index); + error = git_index_write_tree(&tree_oid, m_index->index); git_oid_fmt(oid_out, &tree_oid); RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1); @@ -115,7 +115,7 @@ PHP_METHOD(git2_index, current) zval *z_entry; m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - entry = git_index_get(m_index->index, m_index->offset); + entry = git_index_get_byindex(m_index->index, m_index->offset); if (entry == NULL) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "specified offset does not exist. %d"); @@ -199,4 +199,4 @@ void php_git2_index_init(TSRMLS_D) git2_index_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git2_index_class_entry->create_object = php_git2_index_new; zend_class_implements(git2_index_class_entry TSRMLS_CC, 1, spl_ce_Iterator); -} \ No newline at end of file +} From 8a1a658b42860336eb6a58f494e61940ce430a1f Mon Sep 17 00:00:00 2001 From: Christophe Robin Date: Thu, 8 Aug 2013 14:55:49 +0900 Subject: [PATCH 006/136] Updated libgit2 reference to 0.19.0 --- .gitignore | 1 + libgit2 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a0c67a7fdc..312104bff7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ tests/*.log tests/*.diff tests/*.exp tests/*.out +tests/mock # ignore phpized files Makefile.global diff --git a/libgit2 b/libgit2 index d18713fb4a..eddc1f1ed7 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit d18713fb4ad1ba3d18a75272e1c1c3eb45715aba +Subproject commit eddc1f1ed78898a4ca41480045b1d0d5b075e773 From 1c691c4f4bdc25eb25be2bcca991be22fa13e1cd Mon Sep 17 00:00:00 2001 From: Christophe Robin Date: Thu, 8 Aug 2013 16:37:14 +0900 Subject: [PATCH 007/136] Ported library to libgit 0.19.0 --- config.c | 2 +- php_git2.h | 1 + reference.c | 19 +++++++++---------- remote.c | 20 ++++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/config.c b/config.c index 09d0eae601..d4e625d60e 100644 --- a/config.c +++ b/config.c @@ -430,7 +430,7 @@ PHP_METHOD(git2_config, delete) } m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); - git_config_delete(m_config->config, key); + git_config_delete_entry(m_config->config, key); php_git2_config_reload(getThis(), 0 TSRMLS_CC); } /* }}} */ diff --git a/php_git2.h b/php_git2.h index cb82c99080..589caa1417 100644 --- a/php_git2.h +++ b/php_git2.h @@ -41,6 +41,7 @@ # include # include # include +# include extern zend_module_entry git2_module_entry; diff --git a/reference.c b/reference.c index cfc3b78a3b..4f91939be2 100644 --- a/reference.c +++ b/reference.c @@ -99,18 +99,17 @@ PHP_METHOD(git2_reference, lookup) PHP_METHOD(git2_reference, getTarget) { php_git2_reference *m_reference; - + const git_oid *oid; + char oid_out[GIT_OID_HEXSZ] = {0}; + m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); - + if (git_reference_type(m_reference->reference) == GIT_REF_OID) { - const git_oid *oid; - char oid_out[GIT_OID_HEXSZ] = {0}; - - oid = git_reference_oid(m_reference->reference); + oid = git_reference_target(m_reference->reference); git_oid_fmt(oid_out, oid); RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1); } else { - RETVAL_STRING(git_reference_target(m_reference->reference),1); + RETVAL_STRING(git_reference_symbolic_target(m_reference->reference), 1); } } /* }}} */ @@ -192,9 +191,9 @@ PHP_METHOD(git2_reference, create) m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); if (git_oid_fromstr(&oid, target) == GIT_OK) { - error = git_reference_create_oid(&ref, m_repository->repository, name, &oid, (int)force); + error = git_reference_create(&ref, m_repository->repository, name, &oid, (int)force); } else { - error = git_reference_create_symbolic(&ref, m_repository->repository, name, target, (int)force); + error = git_reference_symbolic_create(&ref, m_repository->repository, name, target, (int)force); } if (error != GIT_OK) { @@ -303,7 +302,7 @@ PHP_METHOD(git2_reference, each) MAKE_STD_ZVAL(opaque.result); array_init(opaque.result); - git_reference_foreach(m_repository->repository, list_flags, &php_git2_ref_foreach_cb, (void *)&opaque); + git_reference_foreach(m_repository->repository, &php_git2_ref_foreach_cb, (void *)&opaque); RETVAL_ZVAL(opaque.result,0,1); } diff --git a/remote.c b/remote.c index 4b81e7be62..964b2defe4 100644 --- a/remote.c +++ b/remote.c @@ -88,7 +88,7 @@ PHP_METHOD(git2_remote, __construct) /* }}} */ -static int php_git2_rename_packfile(char *packname, git_indexer *idx) +static int php_git2_rename_packfile(char *packname, git_indexer_stream *idx) { char path[GIT_PATH_MAX], oid[GIT_OID_HEXSZ + 1], *slash; int ret; @@ -101,7 +101,7 @@ static int php_git2_rename_packfile(char *packname, git_indexer *idx) } memset(oid, 0x0, sizeof(oid)); - git_oid_fmt(oid, git_indexer_hash(idx)); + git_oid_fmt(oid, git_indexer_stream_hash(idx)); ret = sprintf(slash + 1, "pack-%s.pack", oid); if(ret < 0) { return -2; @@ -124,7 +124,7 @@ static int show_ref__cb(git_remote_head *head, void *payload) PHP_METHOD(git2_remote, fetch) { php_git2_remote *m_remote; - git_indexer *idx = NULL; + git_indexer_stream *idx = NULL; git_transfer_progress stats; char *packname = NULL; int error = 0; @@ -138,31 +138,31 @@ PHP_METHOD(git2_remote, fetch) return; } */ - direction = GIT_DIR_FETCH; + direction = GIT_DIRECTION_FETCH; error = git_remote_connect(m_remote->remote, direction); error = git_remote_ls(m_remote->remote, &show_ref__cb, NULL); //error = git_remote_download(&packname, m_remote->remote); - if (packname != NULL) { + /*if (packname != NULL) { // Create a new instance indexer - error = git_indexer_new(&idx, packname); + error = git_indexer_stream_new(&idx, packname); PHP_GIT2_EXCEPTION_CHECK(error); - error = git_indexer_run(idx, &stats); + error = git_indexer_stream_run(idx, &stats); PHP_GIT2_EXCEPTION_CHECK(error); - error = git_indexer_write(idx); + error = git_indexer_stream_write(idx); PHP_GIT2_EXCEPTION_CHECK(error); error = php_git2_rename_packfile(packname, idx); PHP_GIT2_EXCEPTION_CHECK(error); - } + }*/ //error = git_remote_update_tips(m_remote->remote); PHP_GIT2_EXCEPTION_CHECK(error); - free(packname); + //free(packname); git_indexer_free(idx); } /* }}} */ From 8f7a7b2c49cc5b3555f8eeb5e598c247141c5ba7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 10 Jan 2014 11:24:04 +0900 Subject: [PATCH 008/136] remove OOP interfaces --- backend.c | 332 ---------- blob.c | 166 ----- commit.c | 490 -------------- config.c | 458 ------------- git2.c | 281 -------- index.c | 202 ------ index_entry.c | 72 -- odb.c | 221 ------- odb_object.c | 137 ---- php_git2.h | 329 ---------- reference.c | 336 ---------- remote.c | 183 ------ repository.c | 613 ------------------ signature.c | 129 ---- tag.c | 114 ---- tests/000-load_extension.phpt | 9 - tests/001-01-repository_construct.phpt | 17 - tests/001-02-repository_is_empty.phpt | 14 - tests/001-03-repository_is_bare.phpt | 14 - tests/001-04-repository-get_path.phpt | 15 - tests/001-05-repository_get_workdir.phpt | 14 - tests/001-06-repository_init.phpt | 89 --- tests/001-07-repository_head_detached.phpt | 15 - tests/001-08-repository_head_orphen.phpt | 15 - tests/001-09-repository_discover.phpt | 15 - tests/001-0a-repository_exists.phpt | 23 - tests/001-0b-repository_write.phpt | 22 - tests/001-0c-repository_hash.phpt | 23 - tests/002-01-commit_construct.phpt | 16 - tests/002-02-commit_parent_count.phpt | 12 - tests/002-03-commit_get_message.phpt | 12 - tests/002-04-commit_get_message_encoding.phpt | 12 - tests/002-05-commit_get_author.phpt | 18 - tests/002-06-commit_get_committer.phpt | 18 - tests/002-07-commit_create.phpt | 50 -- tests/002-08-commit_get_parent_count.phpt | 24 - tests/002-09-commit_get_parent.phpt | 19 - tests/003-01-tree_construct.phpt | 16 - tests/003-02-tree_iterate.phpt | 18 - tests/003-03-tree_get_subtree.phpt | 45 -- tests/003-04-tree_get_entry_by_name.phpt | 20 - tests/004-01-blob_construct.phpt | 16 - tests/004-02-blob___to_string.phpt | 16 - tests/004-03-blob_create.phpt | 17 - tests/004-04-blob_get_size.phpt | 12 - tests/005-01-signature___construct.phpt | 19 - tests/006-01-tree_entry___construct.phpt | 19 - tests/006-02-tree_entry_is_blob.phpt | 19 - tests/007-01-tree_builder___construct.phpt | 13 - tests/007-02-tree_builder_write.phpt | 32 - tests/008-01-walker___construct.phpt | 16 - tests/008-02-walker_itrate.phpt | 49 -- tests/009-01-reference_lookup.phpt | 14 - tests/009-02-reference_resolve.phpt | 19 - tests/00a-01-config___construct.phpt | 11 - tests/00a-02-config_get.phpt | 23 - tests/00a-03-config_store.phpt | 44 -- tests/00a-04-config_delete.phpt | 22 - tests/00a-05-config_dimension_get.phpt | 23 - tests/00a-06-config_dimension_set.phpt | 44 -- tests/00b-01-odb_hash.phpt | 23 - tests/00b-02-odb_exists.phpt | 23 - tests/00b-03-odb_write.phpt | 22 - tests/00b-04-odb_read.phpt | 28 - tests/fixtures/init.php | 56 -- tests/fixtures/testrepo.git/HEAD | 1 - tests/fixtures/testrepo.git/config | 5 - tests/fixtures/testrepo.git/description | 1 - tests/fixtures/testrepo.git/info/exclude | 6 - .../19/9e7c128125a430899fc5c1c0bd08699c9a5692 | Bin 51 -> 0 bytes .../2c/83838315fd649b17e968e96e9d4543c9efd1e9 | Bin 46 -> 0 bytes .../5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 | Bin 27 -> 0 bytes .../74/edf90112fadb1c0ea2dc48352e0ed4ead2e1cf | Bin 2399 -> 0 bytes .../87/cef34f1a5c8d386418e9fa3e8948ef7322a007 | Bin 28 -> 0 bytes .../a0/8e8505259a0ab4474ca79ba92bd7912b5a32c3 | Bin 28 -> 0 bytes .../ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 | Bin 36 -> 0 bytes .../fixtures/testrepo.git/refs/heads/.gitkeep | 0 tests/mock/001-01/HEAD | 1 - tests/mock/001-01/config | 7 - tests/mock/001-01/description | 1 - tests/mock/001-01/hooks/applypatch-msg.sample | 15 - tests/mock/001-01/hooks/commit-msg.sample | 24 - tests/mock/001-01/hooks/post-commit.sample | 8 - tests/mock/001-01/hooks/post-receive.sample | 15 - tests/mock/001-01/hooks/post-update.sample | 8 - tests/mock/001-01/hooks/pre-applypatch.sample | 14 - tests/mock/001-01/hooks/pre-commit.sample | 46 -- tests/mock/001-01/hooks/pre-rebase.sample | 169 ----- .../001-01/hooks/prepare-commit-msg.sample | 36 - tests/mock/001-01/hooks/update.sample | 128 ---- tests/mock/001-01/info/exclude | 6 - .../55/7db03de997c86a4a028e1ebd3a1ceb225be238 | Bin 28 -> 0 bytes .../67/dc4302383b2715f4e0b8c41840eb05b1873697 | Bin 51 -> 0 bytes .../ab/68c54212af15d3545c41057e3a8f2f9ff6fd0d | Bin 132 -> 0 bytes tests/mock/001-01/packed-refs | 2 - tests/mock/001-01/refs/heads/.gitkeep | 0 tests/mock/001-02/HEAD | 1 - tests/mock/001-02/config | 7 - tests/mock/001-02/description | 1 - tests/mock/001-02/hooks/applypatch-msg.sample | 15 - tests/mock/001-02/hooks/commit-msg.sample | 24 - tests/mock/001-02/hooks/post-commit.sample | 8 - tests/mock/001-02/hooks/post-receive.sample | 15 - tests/mock/001-02/hooks/post-update.sample | 8 - tests/mock/001-02/hooks/pre-applypatch.sample | 14 - tests/mock/001-02/hooks/pre-commit.sample | 46 -- tests/mock/001-02/hooks/pre-rebase.sample | 169 ----- .../001-02/hooks/prepare-commit-msg.sample | 36 - tests/mock/001-02/hooks/update.sample | 128 ---- tests/mock/001-02/info/exclude | 6 - tests/mock/001-02/objects/info/.gitkeep | 0 tests/mock/001-02/objects/pack/.gitkeep | 0 tests/mock/001-02/packed-refs | 2 - tests/mock/001-02/refs/heads/.gitkeep | 0 tests/mock/001-07/detached/HEAD | 1 - tests/mock/001-07/detached/config | 7 - tests/mock/001-07/detached/description | 1 - .../detached/hooks/applypatch-msg.sample | 15 - .../001-07/detached/hooks/commit-msg.sample | 24 - .../001-07/detached/hooks/post-commit.sample | 8 - .../001-07/detached/hooks/post-receive.sample | 15 - .../001-07/detached/hooks/post-update.sample | 8 - .../detached/hooks/pre-applypatch.sample | 14 - .../001-07/detached/hooks/pre-commit.sample | 46 -- .../001-07/detached/hooks/pre-rebase.sample | 169 ----- .../detached/hooks/prepare-commit-msg.sample | 36 - .../mock/001-07/detached/hooks/update.sample | 128 ---- tests/mock/001-07/detached/info/exclude | 6 - .../66/d2a2155270b1021c0fdc764c34e13801bd4ae4 | Bin 140 -> 0 bytes .../73/cfa43b65a81d3094e9e09cd05b3710368fc304 | Bin 51 -> 0 bytes .../c0/328dd7e4af62d858ad174db4e95871fa9f7b8f | Bin 36 -> 0 bytes tests/mock/001-07/detached/packed-refs | 1 - .../mock/001-07/detached/refs/heads/.gitkeep | 0 tests/mock/001-08/orphaned/HEAD | 1 - tests/mock/001-08/orphaned/config | 7 - tests/mock/001-08/orphaned/description | 1 - .../orphaned/hooks/applypatch-msg.sample | 15 - .../001-08/orphaned/hooks/commit-msg.sample | 24 - .../001-08/orphaned/hooks/post-commit.sample | 8 - .../001-08/orphaned/hooks/post-receive.sample | 15 - .../001-08/orphaned/hooks/post-update.sample | 8 - .../orphaned/hooks/pre-applypatch.sample | 14 - .../001-08/orphaned/hooks/pre-commit.sample | 46 -- .../001-08/orphaned/hooks/pre-rebase.sample | 169 ----- .../orphaned/hooks/prepare-commit-msg.sample | 36 - .../mock/001-08/orphaned/hooks/update.sample | 128 ---- tests/mock/001-08/orphaned/info/exclude | 6 - .../66/d2a2155270b1021c0fdc764c34e13801bd4ae4 | Bin 140 -> 0 bytes .../73/cfa43b65a81d3094e9e09cd05b3710368fc304 | Bin 51 -> 0 bytes .../c0/328dd7e4af62d858ad174db4e95871fa9f7b8f | Bin 36 -> 0 bytes tests/mock/001-08/orphaned/packed-refs | 1 - .../mock/001-08/orphaned/refs/heads/.gitkeep | 0 tests/mock/003-03/COMMIT_EDITMSG | 1 - tests/mock/003-03/HEAD | 1 - tests/mock/003-03/config | 6 - tests/mock/003-03/description | 1 - tests/mock/003-03/hooks/applypatch-msg.sample | 15 - tests/mock/003-03/hooks/commit-msg.sample | 24 - tests/mock/003-03/hooks/post-commit.sample | 8 - tests/mock/003-03/hooks/post-receive.sample | 15 - tests/mock/003-03/hooks/post-update.sample | 8 - tests/mock/003-03/hooks/pre-applypatch.sample | 14 - tests/mock/003-03/hooks/pre-commit.sample | 46 -- tests/mock/003-03/hooks/pre-rebase.sample | 169 ----- .../003-03/hooks/prepare-commit-msg.sample | 36 - tests/mock/003-03/hooks/update.sample | 128 ---- tests/mock/003-03/index | Bin 120 -> 0 bytes tests/mock/003-03/info/exclude | 6 - tests/mock/003-03/logs/HEAD | 1 - tests/mock/003-03/logs/refs/heads/master | 1 - .../45/1cad1f3affaf6e3159c7c85d9ce9a21e21993d | Bin 43 -> 0 bytes .../83/32251b41aef6ef2f6ef3624e7879affc4fdc70 | Bin 44 -> 0 bytes .../97/eb5a985ce4329e30ce5893339dc2aeba72c3ef | Bin 43 -> 0 bytes .../a2/c260d5a5c3a4b9f4247433b89dd0069fce423f | Bin 43 -> 0 bytes .../aa/657721abe75c346c59e483c40bed53224c8988 | Bin 44 -> 0 bytes .../bc/2b542422510d8b23eae97ede32dc2d5fa13c90 | Bin 43 -> 0 bytes .../cb/50e7dc3b7b52daf18d8bd62e158467236f47bb | Bin 140 -> 0 bytes .../d5/64d0bc3dd917926892c55e3706cc116d5b165e | Bin 53 -> 0 bytes .../e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | Bin 15 -> 0 bytes tests/mock/003-03/refs/heads/master | 1 - tests/mock/008-02/COMMIT_EDITMSG | 1 - tests/mock/008-02/HEAD | 1 - tests/mock/008-02/config | 7 - tests/mock/008-02/description | 1 - tests/mock/008-02/index | Bin 104 -> 0 bytes tests/mock/008-02/info/exclude | 6 - tests/mock/008-02/logs/HEAD | 4 - tests/mock/008-02/logs/refs/heads/master | 4 - .../23/ea9dd670731cabbf02dc9c9380a1f055521137 | Bin 42 -> 0 bytes .../44/e3736675973ddffc3d66dc939adc958df45561 | Bin 54 -> 0 bytes .../55/7db03de997c86a4a028e1ebd3a1ceb225be238 | Bin 28 -> 0 bytes .../6e/20138dc38f9f626107f1cd3ef0f9838c43defe | 1 - .../7f/ce1026cb624448e5a8cf8752bd5e19d8f2cb1f | 2 - .../9b/b8c853c9ea27609a6bdc48b78cd26a320daf7d | Bin 165 -> 0 bytes .../ab/fa0158df5ca98f9f39aeb3adee8cd663e02ac5 | Bin 54 -> 0 bytes .../c1/a938374fb2738d149467cfb15e5ad90c378613 | Bin 54 -> 0 bytes .../c7/b75609c9063bbe0a9d385eb2479a4f45115e27 | Bin 53 -> 0 bytes .../d0/058326846c074ddcb67170cde54d5d36c7f2f5 | Bin 54 -> 0 bytes .../db/78f3594ec0683f5d857ef731df0d860f14f2b2 | Bin 54 -> 0 bytes .../f5/34deb63f967cddd4bd440d05d3f6f075e55fca | Bin 29 -> 0 bytes .../ff/c6c773865c1342db9cd5df5777fc91ddeb8a4d | Bin 132 -> 0 bytes tests/mock/008-02/refs/heads/.gitkeep | 0 tests/mock/008-02/refs/heads/master | 1 - tree.c | 306 --------- tree_builder.c | 193 ------ tree_entry.c | 165 ----- walker.c | 414 ------------ 207 files changed, 8726 deletions(-) delete mode 100644 backend.c delete mode 100644 blob.c delete mode 100644 commit.c delete mode 100644 config.c delete mode 100644 git2.c delete mode 100644 index.c delete mode 100644 index_entry.c delete mode 100644 odb.c delete mode 100644 odb_object.c delete mode 100644 php_git2.h delete mode 100644 reference.c delete mode 100644 remote.c delete mode 100644 repository.c delete mode 100644 signature.c delete mode 100644 tag.c delete mode 100644 tests/000-load_extension.phpt delete mode 100644 tests/001-01-repository_construct.phpt delete mode 100644 tests/001-02-repository_is_empty.phpt delete mode 100644 tests/001-03-repository_is_bare.phpt delete mode 100644 tests/001-04-repository-get_path.phpt delete mode 100644 tests/001-05-repository_get_workdir.phpt delete mode 100644 tests/001-06-repository_init.phpt delete mode 100644 tests/001-07-repository_head_detached.phpt delete mode 100644 tests/001-08-repository_head_orphen.phpt delete mode 100644 tests/001-09-repository_discover.phpt delete mode 100644 tests/001-0a-repository_exists.phpt delete mode 100644 tests/001-0b-repository_write.phpt delete mode 100644 tests/001-0c-repository_hash.phpt delete mode 100644 tests/002-01-commit_construct.phpt delete mode 100644 tests/002-02-commit_parent_count.phpt delete mode 100644 tests/002-03-commit_get_message.phpt delete mode 100644 tests/002-04-commit_get_message_encoding.phpt delete mode 100644 tests/002-05-commit_get_author.phpt delete mode 100644 tests/002-06-commit_get_committer.phpt delete mode 100644 tests/002-07-commit_create.phpt delete mode 100644 tests/002-08-commit_get_parent_count.phpt delete mode 100644 tests/002-09-commit_get_parent.phpt delete mode 100644 tests/003-01-tree_construct.phpt delete mode 100644 tests/003-02-tree_iterate.phpt delete mode 100644 tests/003-03-tree_get_subtree.phpt delete mode 100644 tests/003-04-tree_get_entry_by_name.phpt delete mode 100644 tests/004-01-blob_construct.phpt delete mode 100644 tests/004-02-blob___to_string.phpt delete mode 100644 tests/004-03-blob_create.phpt delete mode 100644 tests/004-04-blob_get_size.phpt delete mode 100644 tests/005-01-signature___construct.phpt delete mode 100644 tests/006-01-tree_entry___construct.phpt delete mode 100644 tests/006-02-tree_entry_is_blob.phpt delete mode 100644 tests/007-01-tree_builder___construct.phpt delete mode 100644 tests/007-02-tree_builder_write.phpt delete mode 100644 tests/008-01-walker___construct.phpt delete mode 100644 tests/008-02-walker_itrate.phpt delete mode 100644 tests/009-01-reference_lookup.phpt delete mode 100644 tests/009-02-reference_resolve.phpt delete mode 100644 tests/00a-01-config___construct.phpt delete mode 100644 tests/00a-02-config_get.phpt delete mode 100644 tests/00a-03-config_store.phpt delete mode 100644 tests/00a-04-config_delete.phpt delete mode 100644 tests/00a-05-config_dimension_get.phpt delete mode 100644 tests/00a-06-config_dimension_set.phpt delete mode 100644 tests/00b-01-odb_hash.phpt delete mode 100644 tests/00b-02-odb_exists.phpt delete mode 100644 tests/00b-03-odb_write.phpt delete mode 100644 tests/00b-04-odb_read.phpt delete mode 100644 tests/fixtures/init.php delete mode 100644 tests/fixtures/testrepo.git/HEAD delete mode 100644 tests/fixtures/testrepo.git/config delete mode 100644 tests/fixtures/testrepo.git/description delete mode 100644 tests/fixtures/testrepo.git/info/exclude delete mode 100644 tests/fixtures/testrepo.git/objects/19/9e7c128125a430899fc5c1c0bd08699c9a5692 delete mode 100644 tests/fixtures/testrepo.git/objects/2c/83838315fd649b17e968e96e9d4543c9efd1e9 delete mode 100644 tests/fixtures/testrepo.git/objects/5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 delete mode 100644 tests/fixtures/testrepo.git/objects/74/edf90112fadb1c0ea2dc48352e0ed4ead2e1cf delete mode 100644 tests/fixtures/testrepo.git/objects/87/cef34f1a5c8d386418e9fa3e8948ef7322a007 delete mode 100644 tests/fixtures/testrepo.git/objects/a0/8e8505259a0ab4474ca79ba92bd7912b5a32c3 delete mode 100644 tests/fixtures/testrepo.git/objects/ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 delete mode 100644 tests/fixtures/testrepo.git/refs/heads/.gitkeep delete mode 100644 tests/mock/001-01/HEAD delete mode 100644 tests/mock/001-01/config delete mode 100644 tests/mock/001-01/description delete mode 100755 tests/mock/001-01/hooks/applypatch-msg.sample delete mode 100755 tests/mock/001-01/hooks/commit-msg.sample delete mode 100755 tests/mock/001-01/hooks/post-commit.sample delete mode 100755 tests/mock/001-01/hooks/post-receive.sample delete mode 100755 tests/mock/001-01/hooks/post-update.sample delete mode 100755 tests/mock/001-01/hooks/pre-applypatch.sample delete mode 100755 tests/mock/001-01/hooks/pre-commit.sample delete mode 100755 tests/mock/001-01/hooks/pre-rebase.sample delete mode 100755 tests/mock/001-01/hooks/prepare-commit-msg.sample delete mode 100755 tests/mock/001-01/hooks/update.sample delete mode 100644 tests/mock/001-01/info/exclude delete mode 100644 tests/mock/001-01/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238 delete mode 100644 tests/mock/001-01/objects/67/dc4302383b2715f4e0b8c41840eb05b1873697 delete mode 100644 tests/mock/001-01/objects/ab/68c54212af15d3545c41057e3a8f2f9ff6fd0d delete mode 100644 tests/mock/001-01/packed-refs delete mode 100644 tests/mock/001-01/refs/heads/.gitkeep delete mode 100644 tests/mock/001-02/HEAD delete mode 100644 tests/mock/001-02/config delete mode 100644 tests/mock/001-02/description delete mode 100755 tests/mock/001-02/hooks/applypatch-msg.sample delete mode 100755 tests/mock/001-02/hooks/commit-msg.sample delete mode 100755 tests/mock/001-02/hooks/post-commit.sample delete mode 100755 tests/mock/001-02/hooks/post-receive.sample delete mode 100755 tests/mock/001-02/hooks/post-update.sample delete mode 100755 tests/mock/001-02/hooks/pre-applypatch.sample delete mode 100755 tests/mock/001-02/hooks/pre-commit.sample delete mode 100755 tests/mock/001-02/hooks/pre-rebase.sample delete mode 100755 tests/mock/001-02/hooks/prepare-commit-msg.sample delete mode 100755 tests/mock/001-02/hooks/update.sample delete mode 100644 tests/mock/001-02/info/exclude delete mode 100644 tests/mock/001-02/objects/info/.gitkeep delete mode 100644 tests/mock/001-02/objects/pack/.gitkeep delete mode 100644 tests/mock/001-02/packed-refs delete mode 100644 tests/mock/001-02/refs/heads/.gitkeep delete mode 100644 tests/mock/001-07/detached/HEAD delete mode 100644 tests/mock/001-07/detached/config delete mode 100644 tests/mock/001-07/detached/description delete mode 100755 tests/mock/001-07/detached/hooks/applypatch-msg.sample delete mode 100755 tests/mock/001-07/detached/hooks/commit-msg.sample delete mode 100755 tests/mock/001-07/detached/hooks/post-commit.sample delete mode 100755 tests/mock/001-07/detached/hooks/post-receive.sample delete mode 100755 tests/mock/001-07/detached/hooks/post-update.sample delete mode 100755 tests/mock/001-07/detached/hooks/pre-applypatch.sample delete mode 100755 tests/mock/001-07/detached/hooks/pre-commit.sample delete mode 100755 tests/mock/001-07/detached/hooks/pre-rebase.sample delete mode 100755 tests/mock/001-07/detached/hooks/prepare-commit-msg.sample delete mode 100755 tests/mock/001-07/detached/hooks/update.sample delete mode 100644 tests/mock/001-07/detached/info/exclude delete mode 100644 tests/mock/001-07/detached/objects/66/d2a2155270b1021c0fdc764c34e13801bd4ae4 delete mode 100644 tests/mock/001-07/detached/objects/73/cfa43b65a81d3094e9e09cd05b3710368fc304 delete mode 100644 tests/mock/001-07/detached/objects/c0/328dd7e4af62d858ad174db4e95871fa9f7b8f delete mode 100644 tests/mock/001-07/detached/packed-refs delete mode 100644 tests/mock/001-07/detached/refs/heads/.gitkeep delete mode 100644 tests/mock/001-08/orphaned/HEAD delete mode 100644 tests/mock/001-08/orphaned/config delete mode 100644 tests/mock/001-08/orphaned/description delete mode 100755 tests/mock/001-08/orphaned/hooks/applypatch-msg.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/commit-msg.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/post-commit.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/post-receive.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/post-update.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/pre-applypatch.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/pre-commit.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/pre-rebase.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/prepare-commit-msg.sample delete mode 100755 tests/mock/001-08/orphaned/hooks/update.sample delete mode 100644 tests/mock/001-08/orphaned/info/exclude delete mode 100644 tests/mock/001-08/orphaned/objects/66/d2a2155270b1021c0fdc764c34e13801bd4ae4 delete mode 100644 tests/mock/001-08/orphaned/objects/73/cfa43b65a81d3094e9e09cd05b3710368fc304 delete mode 100644 tests/mock/001-08/orphaned/objects/c0/328dd7e4af62d858ad174db4e95871fa9f7b8f delete mode 100644 tests/mock/001-08/orphaned/packed-refs delete mode 100644 tests/mock/001-08/orphaned/refs/heads/.gitkeep delete mode 100644 tests/mock/003-03/COMMIT_EDITMSG delete mode 100644 tests/mock/003-03/HEAD delete mode 100644 tests/mock/003-03/config delete mode 100644 tests/mock/003-03/description delete mode 100755 tests/mock/003-03/hooks/applypatch-msg.sample delete mode 100755 tests/mock/003-03/hooks/commit-msg.sample delete mode 100755 tests/mock/003-03/hooks/post-commit.sample delete mode 100755 tests/mock/003-03/hooks/post-receive.sample delete mode 100755 tests/mock/003-03/hooks/post-update.sample delete mode 100755 tests/mock/003-03/hooks/pre-applypatch.sample delete mode 100755 tests/mock/003-03/hooks/pre-commit.sample delete mode 100755 tests/mock/003-03/hooks/pre-rebase.sample delete mode 100755 tests/mock/003-03/hooks/prepare-commit-msg.sample delete mode 100755 tests/mock/003-03/hooks/update.sample delete mode 100644 tests/mock/003-03/index delete mode 100644 tests/mock/003-03/info/exclude delete mode 100644 tests/mock/003-03/logs/HEAD delete mode 100644 tests/mock/003-03/logs/refs/heads/master delete mode 100644 tests/mock/003-03/objects/45/1cad1f3affaf6e3159c7c85d9ce9a21e21993d delete mode 100644 tests/mock/003-03/objects/83/32251b41aef6ef2f6ef3624e7879affc4fdc70 delete mode 100644 tests/mock/003-03/objects/97/eb5a985ce4329e30ce5893339dc2aeba72c3ef delete mode 100644 tests/mock/003-03/objects/a2/c260d5a5c3a4b9f4247433b89dd0069fce423f delete mode 100644 tests/mock/003-03/objects/aa/657721abe75c346c59e483c40bed53224c8988 delete mode 100644 tests/mock/003-03/objects/bc/2b542422510d8b23eae97ede32dc2d5fa13c90 delete mode 100644 tests/mock/003-03/objects/cb/50e7dc3b7b52daf18d8bd62e158467236f47bb delete mode 100644 tests/mock/003-03/objects/d5/64d0bc3dd917926892c55e3706cc116d5b165e delete mode 100644 tests/mock/003-03/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 delete mode 100644 tests/mock/003-03/refs/heads/master delete mode 100644 tests/mock/008-02/COMMIT_EDITMSG delete mode 100644 tests/mock/008-02/HEAD delete mode 100644 tests/mock/008-02/config delete mode 100644 tests/mock/008-02/description delete mode 100644 tests/mock/008-02/index delete mode 100644 tests/mock/008-02/info/exclude delete mode 100644 tests/mock/008-02/logs/HEAD delete mode 100644 tests/mock/008-02/logs/refs/heads/master delete mode 100644 tests/mock/008-02/objects/23/ea9dd670731cabbf02dc9c9380a1f055521137 delete mode 100644 tests/mock/008-02/objects/44/e3736675973ddffc3d66dc939adc958df45561 delete mode 100644 tests/mock/008-02/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238 delete mode 100644 tests/mock/008-02/objects/6e/20138dc38f9f626107f1cd3ef0f9838c43defe delete mode 100644 tests/mock/008-02/objects/7f/ce1026cb624448e5a8cf8752bd5e19d8f2cb1f delete mode 100644 tests/mock/008-02/objects/9b/b8c853c9ea27609a6bdc48b78cd26a320daf7d delete mode 100644 tests/mock/008-02/objects/ab/fa0158df5ca98f9f39aeb3adee8cd663e02ac5 delete mode 100644 tests/mock/008-02/objects/c1/a938374fb2738d149467cfb15e5ad90c378613 delete mode 100644 tests/mock/008-02/objects/c7/b75609c9063bbe0a9d385eb2479a4f45115e27 delete mode 100644 tests/mock/008-02/objects/d0/058326846c074ddcb67170cde54d5d36c7f2f5 delete mode 100644 tests/mock/008-02/objects/db/78f3594ec0683f5d857ef731df0d860f14f2b2 delete mode 100644 tests/mock/008-02/objects/f5/34deb63f967cddd4bd440d05d3f6f075e55fca delete mode 100644 tests/mock/008-02/objects/ff/c6c773865c1342db9cd5df5777fc91ddeb8a4d delete mode 100644 tests/mock/008-02/refs/heads/.gitkeep delete mode 100644 tests/mock/008-02/refs/heads/master delete mode 100644 tree.c delete mode 100644 tree_builder.c delete mode 100644 tree_entry.c delete mode 100644 walker.c diff --git a/backend.c b/backend.c deleted file mode 100644 index 593a93f2e4..0000000000 --- a/backend.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" -#include - -PHPAPI zend_class_entry *git2_backend_class_entry; -static zend_object_handlers git2_backend_object_handlers; - -static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid) -{ - TSRMLS_FETCH(); - zval *retval, *param; - php_git2_backend_internal *m_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - int result = -1; - - MAKE_STD_ZVAL(param); - git_oid_fmt(out, oid); - ZVAL_STRING(param, out, 1); - m_backend = (php_git2_backend_internal*)_backend; - - zend_call_method_with_1_params(&m_backend->self, Z_OBJCE_P(m_backend->self), NULL, "exists", &retval, param); - - if (Z_BVAL_P(retval)) { - result = GIT_OK; - } - - zval_ptr_dtor(¶m); - zval_ptr_dtor(&retval); - - return (result == GIT_OK); -} - -static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type) -{ - zval *z_id, *z_buffer, *z_size, *z_type, *retval; - int error = GIT_ERROR; - char t_id[GIT_OID_HEXSZ] = {0}; - php_git2_backend_internal *backend; - - MAKE_STD_ZVAL(z_id); - MAKE_STD_ZVAL(z_buffer); - MAKE_STD_ZVAL(z_size); - MAKE_STD_ZVAL(z_type); - backend = (php_git2_backend_internal *)_backend; - - git_oid_fmt(t_id, id); - ZVAL_STRINGL(z_id, t_id, GIT_OID_HEXSZ,1); - ZVAL_STRINGL(z_buffer, buffer, size, 1); - ZVAL_LONG(z_size, size); - ZVAL_LONG(z_type, type); - - php_git2_call_user_function_v(&retval, backend->self, "write", sizeof("write")-1,4,z_id,z_buffer,z_size,z_type); - - zval_ptr_dtor(&z_id); - zval_ptr_dtor(&z_buffer); - zval_ptr_dtor(&z_size); - zval_ptr_dtor(&z_type); - - if (Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)) { - error = GIT_OK; - } - zval_ptr_dtor(&retval); - - return error; -} - -static int php_git2_backend_read(void **buffer,size_t *size, git_otype *type, git_odb_backend *_backend, const git_oid *id) -{ - TSRMLS_FETCH(); - zval *retval, *z_oid, *z_type = NULL; - php_git2_backend_internal *m_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - int result = GIT_ERROR; - - MAKE_STD_ZVAL(z_oid); - MAKE_STD_ZVAL(z_type); - git_oid_fmt(out, id); - - ZVAL_STRING(z_oid, out, 1); - ZVAL_LONG(z_type, (long)type); - m_backend = (php_git2_backend_internal*)_backend; - - zend_call_method_with_2_params(&m_backend->self, Z_OBJCE_P(m_backend->self), NULL, "read", &retval, z_oid, z_type); - if (Z_TYPE_P(retval) == IS_ARRAY) { - HashTable *hash; - zval **value_pp, *data, *z_size; - - hash = Z_ARRVAL_P(retval); - - if (zend_hash_find(hash,"data",sizeof("data"),(void **)&value_pp) != FAILURE) { - data = *value_pp; - } - - if (zend_hash_find(hash,"size",sizeof("size"),(void **)&value_pp) != FAILURE) { - z_size = *value_pp; - } - - *buffer = estrndup(Z_STRVAL_P(data),Z_STRLEN_P(data)); - *size = Z_LVAL_P(z_size); - - } - zval_ptr_dtor(&z_oid); - zval_ptr_dtor(&z_type); - zval_ptr_dtor(&retval); - - return result; -} - - -static int php_git2_backend_read_header(size_t *size, git_otype *type, git_odb_backend *_backend, const git_oid *id) -{ - TSRMLS_FETCH(); - zval *retval, *z_oid, *z_type; - php_git2_backend_internal *m_backend; - char out[GIT_OID_HEXSZ] = {0}; - int result = GIT_ERROR; - - MAKE_STD_ZVAL(z_oid); - MAKE_STD_ZVAL(z_type); - git_oid_fmt(out, id); - ZVAL_STRING(z_oid, out, 1); - m_backend = (php_git2_backend_internal*)_backend; - - zend_call_method_with_2_params(&m_backend->self, Z_OBJCE_P(m_backend->self), NULL, "readHeader", &retval, z_oid, z_type); - if (Z_TYPE_P(retval) == IS_ARRAY) { - HashTable *hash; - zval **value_pp, *data, *z_size; - - hash = Z_ARRVAL_P(retval); - - if (zend_hash_find(hash,"data",sizeof("data"),(void **)&value_pp) != FAILURE) { - data = *value_pp; - } - - if (zend_hash_find(hash,"size",sizeof("size"),(void **)&value_pp) != FAILURE) { - z_size = *value_pp; - } - - *size = Z_LVAL_P(z_size); - - } - zval_ptr_dtor(&z_oid); - zval_ptr_dtor(&z_type); - zval_ptr_dtor(&retval); - - return result; -} - -static int php_git2_backend_read_prefix(git_oid *id, void ** buffer, size_t * size, git_otype * type, struct git_odb_backend * _backend, const git_oid * oid, size_t length) -{ - TSRMLS_FETCH(); - zval *retval, *z_oid, *z_type; - php_git2_backend_internal *m_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - int result = GIT_ERROR; - - MAKE_STD_ZVAL(z_oid); - MAKE_STD_ZVAL(z_type); - git_oid_fmt(out, id); - ZVAL_STRING(z_oid, out, 1); - m_backend = (php_git2_backend_internal*)_backend; - - zend_call_method_with_2_params(&m_backend->self, Z_OBJCE_P(m_backend->self), NULL, "readPrefix", &retval, z_oid, z_type); - if (Z_TYPE_P(retval) == IS_ARRAY) { - HashTable *hash; - zval **value_pp, *data, *z_size; - - hash = Z_ARRVAL_P(retval); - - if (zend_hash_find(hash,"data",sizeof("data"),(void **)&value_pp) != FAILURE) { - data = *value_pp; - } - - if (zend_hash_find(hash,"size",sizeof("size"),(void **)&value_pp) != FAILURE) { - z_size = *value_pp; - } - - if (zend_hash_find(hash,"oid",sizeof("oid"),(void **)&value_pp) != FAILURE) { - z_oid = *value_pp; - } - - *buffer = estrndup(Z_STRVAL_P(data),Z_STRLEN_P(data)); - *size = Z_LVAL_P(z_size); - git_oid_fromstr(id, Z_STRVAL_P(z_oid)); - } - zval_ptr_dtor(&z_oid); - zval_ptr_dtor(&z_type); - zval_ptr_dtor(&retval); - - return result; -} - -static void php_git2_backend_free(struct git_odb_backend *_backend) -{ - TSRMLS_FETCH(); - zval *retval; - php_git2_backend_internal *m_backend; - m_backend = (php_git2_backend_internal*)_backend; - - zend_call_method_with_0_params(&m_backend->self, Z_OBJCE_P(m_backend->self), NULL, "free", &retval); - zval_ptr_dtor(&retval); - - zval_ptr_dtor(&m_backend->self); -} - -static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) -{ - if (object->backend != NULL) { - object->backend = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git2_backend_internal *internal; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_backend); - - /* php_git2_backend_internal free'd by odb_backend. do not use ecalloc here. */ - internal = calloc(1,sizeof(php_git2_backend_internal)); - internal->parent.read = &php_git2_backend_read; - internal->parent.read_prefix = &php_git2_backend_read_prefix; - internal->parent.read_header = &php_git2_backend_read_header; - internal->parent.write = &php_git2_backend_write; - internal->parent.exists = &php_git2_backend_exists; - internal->parent.free = &php_git2_backend_free; - - object->backend = (struct git_odb_backend*)internal; - - retval.handlers = &git2_backend_object_handlers; - - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_read, 0,0,2) - ZEND_ARG_INFO(0, oid) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_read_prefix, 0,0,2) - ZEND_ARG_INFO(0, oid) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_read_header, 0,0,2) - ZEND_ARG_INFO(0, oid) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_write, 0,0,4) - ZEND_ARG_INFO(0, oid) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, size) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_exists, 0,0,1) - ZEND_ARG_INFO(0, oid) -ZEND_END_ARG_INFO() - - -/* -{{{ proto: Git2\Backend::__construct() -*/ -PHP_METHOD(git2_backend, __construct) -{ - php_git2_backend *m_backend; - php_git2_backend_internal * m_internal; - m_backend = PHP_GIT2_GET_OBJECT(php_git2_backend, getThis()); - - m_internal = (php_git2_backend_internal*)m_backend->backend; - - /* i'd like to move below line to php_git2_backend_new but i don't have a good idea */ - m_internal->self = getThis(); - Z_ADDREF_P(m_internal->self); -} -/* }}} */ - -static zend_function_entry php_git2_backend_methods[] = { - PHP_ME(git2_backend, __construct, NULL, ZEND_ACC_PUBLIC) - /* int (* read)(void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *); */ - PHP_ABSTRACT_ME(git2_backend, read, arginfo_git2_backend_read) - /* int (* read_prefix)(git_oid *,void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *,unsigned int); */ - PHP_ABSTRACT_ME(git2_backend, readPrefix, arginfo_git2_backend_read_prefix) - /* int (* read_header)(size_t *, git_otype *,struct git_odb_backend *,const git_oid *); */ - PHP_ABSTRACT_ME(git2_backend, readHeader, arginfo_git2_backend_read_header) - /* int (* write)(git_oid *,struct git_odb_backend *,const void *,size_t,git_otype); */ - PHP_ABSTRACT_ME(git2_backend, write, arginfo_git2_backend_write) - /* int (* exists)(struct git_odb_backend *,const git_oid *); */ - PHP_ABSTRACT_ME(git2_backend, exists, arginfo_git2_backend_exists) - /* void (* free)(struct git_odb_backend *); */ - PHP_ABSTRACT_ME(git2_backend, free, NULL) - {NULL,NULL,NULL} -}; - -void php_git2_backend_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Backend", php_git2_backend_methods); - git2_backend_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_backend_class_entry->create_object = php_git2_backend_new; - - memcpy(&git2_backend_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - git2_backend_object_handlers.clone_obj = NULL; -} \ No newline at end of file diff --git a/blob.c b/blob.c deleted file mode 100644 index bf0b98d6e6..0000000000 --- a/blob.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_blob_class_entry; - -static void php_git2_blob_free_storage(php_git2_blob *object TSRMLS_DC) -{ - if (object->blob != NULL) { - git_blob_free(object->blob); - object->blob = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_blob_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_blob); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_blob_create, 0,0,2) - ZEND_ARG_INFO(0, repository) - ZEND_ARG_INFO(0, contents) -ZEND_END_ARG_INFO() - - -/* -{{{ proto: Git2\Blob::getContent() -*/ -PHP_METHOD(git2_blob, getContent) -{ - php_git2_blob *m_blob; - - m_blob = PHP_GIT2_GET_OBJECT(php_git2_blob, getThis()); - - if (m_blob != NULL) { - if (m_blob->blob == NULL) { - RETURN_FALSE; - } - - RETURN_STRINGL(git_blob_rawcontent(m_blob->blob), git_blob_rawsize(m_blob->blob),1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* -{{{ proto: Git2\Blob::getSize() -*/ -PHP_METHOD(git2_blob, getSize) -{ - php_git2_blob *m_blob; - - m_blob = PHP_GIT2_GET_OBJECT(php_git2_blob, getThis()); - - if (m_blob != NULL) { - if (m_blob->blob == NULL) { - RETURN_FALSE; - } - - RETURN_LONG(git_blob_rawsize(m_blob->blob)); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Blob::__toString() -*/ -PHP_METHOD(git2_blob, __toString) -{ - php_git2_blob *m_blob; - - m_blob = PHP_GIT2_GET_OBJECT(php_git2_blob, getThis()); - - if (m_blob != NULL) { - if (m_blob->blob == NULL) { - RETURN_FALSE; - } - - RETURN_STRINGL(git_blob_rawcontent(m_blob->blob), git_blob_rawsize(m_blob->blob),1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Blob::create(Git2\Repository $repository, string $contents) -*/ -PHP_METHOD(git2_blob, create) -{ - char *contents; - int contents_len, error = 0; - zval *repository; - php_git2_repository *m_repository; - char oid_out[GIT_OID_HEXSZ] = {0}; - git_oid oid; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "Os", &repository, git2_repository_class_entry, &contents, &contents_len) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - - if (m_repository != NULL) { - if (m_repository->repository == NULL) { - RETURN_FALSE; - } - - error = git_blob_create_frombuffer(&oid, m_repository->repository, contents, contents_len); - git_oid_fmt(oid_out, &oid); - RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -static zend_function_entry php_git2_blob_methods[] = { - PHP_ME(git2_blob, getContent, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_blob, getSize, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_blob, __toString, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_blob, create, arginfo_git2_blob_create, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - {NULL,NULL,NULL} -}; - -void php_git2_blob_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Blob", php_git2_blob_methods); - git2_blob_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_blob_class_entry->create_object = php_git2_blob_new; -} \ No newline at end of file diff --git a/commit.c b/commit.c deleted file mode 100644 index 23b7656895..0000000000 --- a/commit.c +++ /dev/null @@ -1,490 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_commit_class_entry; - -static void php_git2_commit_free_storage(php_git2_commit *object TSRMLS_DC) -{ - if (object->commit != NULL) { - git_commit_free(object->commit); - object->commit = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_commit_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_commit); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_commit_create, 0,0,2) - ZEND_ARG_INFO(0, repository) - ZEND_ARG_INFO(0, data) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_commit_get_parent, 0,0,1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\Commit::getMessage() -*/ -PHP_METHOD(git2_commit, getMessage) -{ - php_git2_commit *m_commit; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - RETURN_STRING(git_commit_message(m_commit->commit),1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::getMessageEncoding() -*/ -PHP_METHOD(git2_commit, getMessageEncoding) -{ - const char *encoding; - php_git2_commit *m_commit; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - encoding = git_commit_message_encoding(m_commit->commit); - if (encoding != NULL) { - RETURN_STRING(encoding,1); - } else { - RETURN_STRING("UTF-8",1); - } - } - RETURN_FALSE; -} -/* }}} */ - - -/* -{{{ proto: Git2\Commit::parentCount() -*/ -PHP_METHOD(git2_commit, parentCount) -{ - unsigned int parent_count = 0; - php_git2_commit *m_commit; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - parent_count = git_commit_parentcount(m_commit->commit); - RETURN_LONG(parent_count); - } - RETURN_FALSE; -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::getAuthor() -*/ -PHP_METHOD(git2_commit, getAuthor) -{ - php_git2_commit *m_commit; - zval *z_signature; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - php_git2_create_signature_from_commit(&z_signature, m_commit->commit, 0 TSRMLS_CC); - RETVAL_ZVAL(z_signature, 0, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::getCommitter() -*/ -PHP_METHOD(git2_commit, getCommitter) -{ - php_git2_commit *m_commit; - zval *z_signature; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - php_git2_create_signature_from_commit(&z_signature, m_commit->commit,1 TSRMLS_CC); - RETVAL_ZVAL(z_signature, 0, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::getOid() -*/ -PHP_METHOD(git2_commit, getOid) -{ - php_git2_commit *m_commit; - char oid_out[GIT_OID_HEXSZ] = {0}; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - git_oid_fmt(oid_out, git_commit_id(m_commit->commit)); - RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::create(Git2\Repository $repo, array $data) -*/ -PHP_METHOD(git2_commit, create) -{ - php_git2_tree *m_tree; - php_git2_signature *m_author,*m_committer; - php_git2_repository *m_repository; - zval *repository, **element, *z_parents, *z_tree, *z_author, *z_committer, *z_array, **value_pp = NULL; - HashTable *hash; - const git_commit **parents = NULL; - git_commit **free_list = NULL; - git_tree *tree; - git_oid commit_oid; - char *message, *encoding, *ref, oid_out[GIT_OID_HEXSZ]; - int parent_count, i, error = 0; - HashPosition pos; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "Oa", &repository, git2_repository_class_entry,&z_array) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - - hash = Z_ARRVAL_P(z_array); - if (zend_hash_find(hash,"author",sizeof("author"),(void **)&value_pp) != FAILURE) { - z_author = *value_pp; - m_author = PHP_GIT2_GET_OBJECT(php_git2_signature,z_author); - } else { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"key 'author' required"); - return; - } - - if (zend_hash_find(hash,"committer",sizeof("committer"),(void **)&value_pp) != FAILURE) { - z_committer = *value_pp; - m_committer = PHP_GIT2_GET_OBJECT(php_git2_signature,z_committer); - } else { - z_committer = z_author; - m_committer = PHP_GIT2_GET_OBJECT(php_git2_signature,z_committer); - } - - if (zend_hash_find(hash,"tree",sizeof("tree"),(void **)&value_pp) != FAILURE) { - z_tree = *value_pp; - if (Z_TYPE_P(z_tree) == IS_STRING) { - git_oid oid; - error = git_oid_fromstr(&oid, Z_STRVAL_P(z_tree)); - error = git_tree_lookup(&tree, m_repository->repository,&oid); - } else { - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, z_tree); - tree = m_tree->tree; - } - } else { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"key 'tree' required"); - return; - } - - if (zend_hash_find(hash,"parents",sizeof("parents"),(void **)&value_pp) != FAILURE) { - z_parents = *value_pp; - } - - if (zend_hash_find(hash,"ref",sizeof("ref"),(void **)&value_pp) != FAILURE) { - ref = emalloc(sizeof(char)*Z_STRLEN_PP(value_pp)+1); - sprintf(ref, "%s", Z_STRVAL_PP(value_pp)); - } else { - ref = emalloc(sizeof(char)*5); - sprintf(ref,"HEAD"); - } - - if (zend_hash_find(hash,"message",sizeof("message"),(void **)&value_pp) != FAILURE) { - message = Z_STRVAL_PP(value_pp); - } else { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"key 'message' required"); - return; - } - - if (zend_hash_find(hash,"encoding",sizeof("encoding"),(void **)&value_pp) != FAILURE) { - encoding = emalloc(sizeof(char)*Z_STRLEN_PP(value_pp)+1); - sprintf(encoding, "%s",Z_STRVAL_PP(value_pp)); - } else { - encoding = emalloc(sizeof(char)*6); - sprintf(encoding,"UTF-8"); - } - - parent_count = zend_hash_num_elements(Z_ARRVAL_P(z_parents)); - parents = emalloc(parent_count * sizeof(void *)); - free_list = emalloc(parent_count * sizeof(void *)); - - for(i = 0, zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(z_parents), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(z_parents), (void **)&element, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_P(z_parents), &pos) - ) { - git_commit *parent = NULL; - git_commit *free_ptr = NULL; - - if (Z_TYPE_PP(element) == IS_STRING) { - git_oid oid; - error = git_oid_fromstr(&oid, Z_STRVAL_PP(element)); - git_commit_lookup(&parent, m_repository->repository,&oid); - - free_ptr = parent; - } else { - php_git2_commit *m_commit; - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, *element); - parent = m_commit->commit; - } - - parents[i] = parent; - free_list[i] = free_ptr; - i++; - } - - error = git_commit_create( - &commit_oid, - m_repository->repository, - ref, - m_author->signature, - m_committer->signature, - encoding, - message, - tree, - parent_count, - parents - ); - - git_oid_fmt(oid_out, &commit_oid); - RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1); - - for (i =0; i < parent_count; ++i) { - git_object_free((git_object *)free_list[i]); - } - efree(ref); - efree(parents); - efree(free_list); - efree(encoding); -} -/* }}} */ - - -/* -{{{ proto: Git2\Commit::getTree() -*/ -PHP_METHOD(git2_commit, getTree) -{ - php_git2_commit *m_commit; - const git_oid *oid; - git_otype type = GIT_OBJ_TREE; - git_object *object; - zval *result; - int error = 0; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - oid = git_commit_tree_oid(m_commit->commit); - error = git_object_lookup(&object, git_object_owner((git_object *)m_commit->commit), oid, type); - result = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), object TSRMLS_CC); - RETVAL_ZVAL(result,0,1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::getParents() -*/ -PHP_METHOD(git2_commit, getParents) -{ - php_git2_commit *m_commit; - unsigned int parent_count = 0; - int error, i = 0; - zval *result; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - parent_count = git_commit_parentcount(m_commit->commit); - MAKE_STD_ZVAL(result); - array_init(result); - for (i = 0; i < parent_count; i++) { - git_commit *parent = NULL; - zval *tmp = NULL; - - error = git_commit_parent(&parent, m_commit->commit, i); - if (error == GIT_OK) { - tmp = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), (git_object*)parent TSRMLS_CC); - add_next_index_zval(result, tmp); - } - } - - RETVAL_ZVAL(result,0,1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::getParent([int index]) -*/ -PHP_METHOD(git2_commit, getParent) -{ - php_git2_commit *m_commit; - unsigned int parent_count = 0; - int error = 0; - long index = 0; - zval *result; - git_commit *parent = NULL; - - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|l", &index) == FAILURE) { - return; - } - - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - parent_count = git_commit_parentcount(m_commit->commit); - if (index > (parent_count-1) || index < 0) { - /* @todo: throws invalidargument exception */ - RETURN_FALSE; - } - - error = git_commit_parent(&parent, m_commit->commit, (unsigned int)index); - if (error == GIT_OK) { - result = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), (git_object*)parent TSRMLS_CC); - RETVAL_ZVAL(result,0,1); - } - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Commit::getParentCount() -*/ -PHP_METHOD(git2_commit, getParentCount) -{ - php_git2_commit *m_commit; - unsigned int parent_count = 0; - - m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); - - if (m_commit != NULL) { - if (m_commit->commit == NULL) { - RETURN_FALSE; - } - - parent_count = git_commit_parentcount(m_commit->commit); - RETURN_LONG(parent_count); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -static zend_function_entry php_git2_commit_methods[] = { - PHP_ME(git2_commit, getMessage, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getMessageEncoding, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, parentCount, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getAuthor, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getCommitter, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getOid, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getTree, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getParentCount, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getParent, arginfo_git2_commit_get_parent, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, getParents, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_commit, create, arginfo_git2_commit_create, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_commit_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Commit", php_git2_commit_methods); - git2_commit_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_commit_class_entry->create_object = php_git2_commit_new; -} diff --git a/config.c b/config.c deleted file mode 100644 index d4e625d60e..0000000000 --- a/config.c +++ /dev/null @@ -1,458 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" -#include -#include - -PHPAPI zend_class_entry *git2_config_class_entry; -static zend_object_handlers git2_config_object_handlers; - -static void php_git2_config_free_storage(php_git2_config *object TSRMLS_DC) -{ - if (object->config != NULL) { - free(object->config); - object->config = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - - -/* @todo refactoring */ -static int php_git2_config_has_dimension(zval *object, zval *member, int check_empty TSRMLS_DC) -{ - zend_object_handlers *standard; - zval *entry, **target_offset; - char *current_key, *tmp_value, *savedptr, *k; - - entry = zend_read_property(git2_config_class_entry, object,"configs",sizeof("configs")-1, 0 TSRMLS_CC); - - if (Z_STRLEN_P(member) < 1) { - return 0; - } - - tmp_value = estrdup(Z_STRVAL_P(member)); - current_key = php_strtok_r(tmp_value, ".", &savedptr); - while (current_key != NULL) { - k = current_key; - current_key = php_strtok_r(NULL, ".", &savedptr); - - if (current_key != NULL && k != NULL) { - if (zend_hash_exists(Z_ARRVAL_P(entry), k, strlen(k)+1)) { - if (zend_hash_find(Z_ARRVAL_P(entry), k, strlen(k)+1, (void **)&target_offset) == SUCCESS) { - entry = *target_offset; - } - } else { - target_offset = NULL; - } - } else { - if (k != NULL) { - if (zend_hash_find(Z_ARRVAL_P(entry), k, strlen(k)+1, (void **)&target_offset) != SUCCESS) { - target_offset = NULL; - } - } - } - } - efree(tmp_value); - - if (target_offset != NULL) { - return 1; - } else { - return 0; - } - - standard = zend_get_std_object_handlers(); - return standard->has_dimension(object, member, check_empty TSRMLS_CC); -} - -/* @todo refactoring */ -static zval* php_git2_config_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) -{ - zval *entry, *tmp_result, **target_offset; - char *current_key, *tmp_value, *savedptr, *k; - - entry = zend_read_property(git2_config_class_entry, object,"configs",sizeof("configs")-1, 0 TSRMLS_CC); - - if (Z_STRLEN_P(offset) < 1) { - return 0; - } - - tmp_value = estrdup(Z_STRVAL_P(offset)); - current_key = php_strtok_r(tmp_value, ".", &savedptr); - while (current_key != NULL) { - k = current_key; - current_key = php_strtok_r(NULL, ".", &savedptr); - - if (current_key != NULL && k != NULL) { - if (zend_hash_exists(Z_ARRVAL_P(entry), k, strlen(k)+1)) { - if (zend_hash_find(Z_ARRVAL_P(entry), k, strlen(k)+1, (void **)&target_offset) == SUCCESS) { - entry = *target_offset; - } - } else { - target_offset = NULL; - } - } else { - if (k != NULL) { - if (zend_hash_find(Z_ARRVAL_P(entry), k, strlen(k)+1, (void **)&target_offset) != SUCCESS) { - target_offset = NULL; - } - } - } - } - efree(tmp_value); - - if (target_offset != NULL) { - tmp_result = *target_offset; - } else { - tmp_result = 0; - } - return tmp_result; -} - - -zend_object_value php_git2_config_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_config); - retval.handlers = &git2_config_object_handlers; - return retval; -} - - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_config___construct, 0,0,1) - ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_config_get, 0,0,1) - ZEND_ARG_INFO(0, get) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_config_store, 0,0,2) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_config_delete, 0,0,1) - ZEND_ARG_INFO(0, key) -ZEND_END_ARG_INFO() - -typedef struct{ - zval *result; - git_config *config; -} php_git2_config_foreach_t; - -static int php_git2_config_resolve(zval **result, const char *var_name, zval *m_config) -{ - TSRMLS_FETCH(); - zval *entry, *tmp_result, **target_offset; - char *current_key, *tmp_value, *savedptr, *k; - int error = 0; - - entry = zend_read_property(git2_config_class_entry, m_config,"configs",sizeof("configs")-1, 0 TSRMLS_CC); - - tmp_value = estrdup(var_name); - current_key = php_strtok_r(tmp_value, ".", &savedptr); - while (current_key != NULL) { - k = current_key; - current_key = php_strtok_r(NULL, ".", &savedptr); - - if (current_key != NULL && k != NULL) { - if (zend_hash_exists(Z_ARRVAL_P(entry), k, strlen(k)+1)) { - if (zend_hash_find(Z_ARRVAL_P(entry), k, strlen(k)+1, (void **)&target_offset) == SUCCESS) { - entry = *target_offset; - } - } else { - target_offset = NULL; - } - } else { - if (k != NULL) { - if (zend_hash_find(Z_ARRVAL_P(entry), k, strlen(k)+1, (void **)&target_offset) != SUCCESS) { - target_offset = NULL; - } - } - } - } - efree(tmp_value); - - if (target_offset != NULL) { - MAKE_STD_ZVAL(tmp_result); - ZVAL_ZVAL(tmp_result, *target_offset,1,0); - } else { - MAKE_STD_ZVAL(tmp_result); - ZVAL_NULL(tmp_result); - } - *result = tmp_result; - - return error; -} - -static int php_git2_config_foreach(const git_config_entry * entry, void *payload) -{ - HashTable *hash; - zval *zentry, **target_offset; - const char *config_value; - char *current_key, *tmp_value, *savedptr, *k; - php_git2_config_foreach_t *opaque = (php_git2_config_foreach_t *)payload; - int error = 0; - - hash = Z_ARRVAL_P(opaque->result); - - error = git_config_get_string(&config_value, opaque->config, entry->name); - - tmp_value = estrdup(entry->name); - current_key = php_strtok_r(tmp_value, ".", &savedptr); - while (current_key != NULL) { - k = current_key; - current_key = php_strtok_r(NULL, ".", &savedptr); - - if (current_key != NULL) { - if (zend_hash_exists(hash, k, strlen(k)+1)) { - if (zend_hash_find(hash,k, strlen(k)+1, (void **)&target_offset) == SUCCESS) { - hash = Z_ARRVAL_P(*target_offset); - } - } else { - MAKE_STD_ZVAL(zentry); - array_init(zentry); - zend_hash_add(hash, k, strlen(k)+1, (void **)&zentry, sizeof(zentry), NULL); - hash = Z_ARRVAL_P(zentry); - } - } - } - - if (k != NULL) { - MAKE_STD_ZVAL(zentry); - if (config_value) { - ZVAL_STRING(zentry, config_value, 1); - } else { - ZVAL_NULL(zentry); - } - zend_hash_add(hash, k, strlen(k)+1, (void **)&zentry, sizeof(zentry), NULL); - Z_ADDREF_P(zentry); - zval_ptr_dtor(&zentry); - } - efree(tmp_value); - - return GIT_OK; -} - -static int php_git2_config_reload(zval *object, unsigned short dtor TSRMLS_DC) -{ - zval *entry; - php_git2_config_foreach_t payload; - php_git2_config *m_config; - int error = 0; - - m_config = PHP_GIT2_GET_OBJECT(php_git2_config, object); - entry = zend_read_property(git2_config_class_entry, object,"configs",sizeof("configs")-1, 1 TSRMLS_CC); - if (entry != NULL) { - zval_ptr_dtor(&entry); - entry = NULL; - } - - MAKE_STD_ZVAL(entry); - array_init(entry); - - payload.config = m_config->config; - payload.result = entry; - error = git_config_foreach(m_config->config, &php_git2_config_foreach, &payload); - add_property_zval(object, "configs", entry); - if (dtor == 1) { - zval_ptr_dtor(&entry); - } - - return 0; -} - -static void php_git2_config_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) -{ - char *key; - int error = 0; - php_git2_config *m_config; - - m_config = PHP_GIT2_GET_OBJECT(php_git2_config, object); - key = Z_STRVAL_P(offset); - - switch (Z_TYPE_P(value)) { - case IS_STRING: - error = git_config_set_string(m_config->config, key, Z_STRVAL_P(value)); - break; - case IS_BOOL: - error = git_config_set_bool(m_config->config, key, Z_BVAL_P(value)); - break; - case IS_LONG: - error = git_config_set_int32(m_config->config, key, Z_LVAL_P(value)); - break; - default: - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "Git2\\Config::store must pass string or bool or long value"); - return; - } - - php_git2_config_reload(object,0 TSRMLS_CC); -} - - -/* -{{{ proto: Git2\Config::__construct(string $path) -*/ -PHP_METHOD(git2_config, __construct) -{ - char *path; - git_config *config; - int error, path_len = 0; - php_git2_config *m_config; - - /* @todo: supports array for reading multiple configs */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE) { - return; - } - - error = git_config_open_ondisk(&config, path); - - /* @todo: automatic convert types */ - m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); - m_config->config = config; - - php_git2_config_reload(getThis(), 1 TSRMLS_CC); - /** - * @todo: support global config - * php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC); - */ -} -/* }}} */ - -/* -{{{ proto: Git2\Config::get(string $key) -*/ -PHP_METHOD(git2_config, get) -{ - char *key; - int key_len = 0; - zval *result; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &key, &key_len) == FAILURE) { - return; - } - - if (key_len < 1) { - RETURN_FALSE; - } - - php_git2_config_resolve(&result, (const char *)key, getThis()); - RETVAL_ZVAL(result,0,1); -} -/* }}} */ - - -/* -{{{ proto: Git2\Config::store(string $key, mixed $value) -*/ -PHP_METHOD(git2_config, store) -{ - char *key; - int error, key_len = 0; - zval *value; - php_git2_config *m_config; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sz", &key, &key_len, &value) == FAILURE) { - return; - } - - if (key_len < 1) { - RETURN_FALSE; - } - - m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); - - switch (Z_TYPE_P(value)) { - case IS_STRING: - error = git_config_set_string(m_config->config, key, Z_STRVAL_P(value)); - break; - case IS_BOOL: - error = git_config_set_bool(m_config->config, key, Z_BVAL_P(value)); - break; - case IS_LONG: - error = git_config_set_int32(m_config->config, key, Z_LVAL_P(value)); - break; - default: - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "Git2\\Config::store must pass string or bool or long value"); - RETURN_FALSE; - } - - php_git2_config_reload(getThis(),0 TSRMLS_CC); -} -/* }}} */ - - -/* -{{{ proto: Git2\Config::delete(string $key) -*/ -PHP_METHOD(git2_config, delete) -{ - char *key; - int key_len = 0; - php_git2_config *m_config; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &key, &key_len) == FAILURE) { - return; - } - - if (key_len < 1) { - RETURN_FALSE; - } - - m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); - git_config_delete_entry(m_config->config, key); - php_git2_config_reload(getThis(), 0 TSRMLS_CC); -} -/* }}} */ - -static zend_function_entry php_git2_config_methods[] = { - PHP_ME(git2_config, __construct, arginfo_git2_config___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(git2_config, get, arginfo_git2_config_get, ZEND_ACC_PUBLIC) - PHP_ME(git2_config, store, arginfo_git2_config_store, ZEND_ACC_PUBLIC) - PHP_ME(git2_config, delete, arginfo_git2_config_delete, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_config_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Config", php_git2_config_methods); - git2_config_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_config_class_entry->create_object = php_git2_config_new; - memcpy(&git2_config_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - - git2_config_object_handlers.read_dimension = php_git2_config_read_dimension; - git2_config_object_handlers.has_dimension = php_git2_config_has_dimension; - git2_config_object_handlers.write_dimension = php_git2_config_write_dimension; -} \ No newline at end of file diff --git a/git2.c b/git2.c deleted file mode 100644 index a40cb47ea1..0000000000 --- a/git2.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" -#include "ext/standard/info.h" - -void php_git2_repository_init(TSRMLS_D); -void php_git2_commit_init(TSRMLS_D); -void php_git2_blob_init(TSRMLS_D); -void php_git2_tree_init(TSRMLS_D); -void php_git2_tree_builder_init(TSRMLS_D); -void php_git2_signature_init(TSRMLS_D); -void php_git2_walker_init(TSRMLS_D); -void php_git2_reference_init(TSRMLS_D); -void php_git2_config_init(TSRMLS_D); -void php_git2_remote_init(TSRMLS_D); -void php_git2_tag_init(TSRMLS_D); -void php_git2_odb_init(TSRMLS_D); -void php_git2_odb_object_init(TSRMLS_D); -void php_git2_tree_entry_init(TSRMLS_D); -void php_git2_index_entry_init(TSRMLS_D); -void php_git2_backend_init(TSRMLS_D); -void php_git2_index_init(TSRMLS_D); - -int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...) -{ - va_list ap; - size_t i; - int error = 0; - zval **params, *method_name, *ret= NULL; - TSRMLS_FETCH(); - - if (param_count > 0) { - params = emalloc(sizeof(zval**) * param_count); - va_start(ap, param_count); - for (i = 0; i < param_count; i ++) { - params[i] = va_arg(ap, zval*); - } - va_end(ap); - } else { - params = NULL; - } - - MAKE_STD_ZVAL(ret); - MAKE_STD_ZVAL(method_name); - - ZVAL_NULL(ret); - ZVAL_STRINGL(method_name, method, method_len, 1); - - error = call_user_function(NULL, &obj, method_name, ret, param_count, params TSRMLS_CC); - - if (param_count > 0) { - for (i = 0; i < param_count; i++) { - if (params[i] != NULL) { - zval_ptr_dtor(¶ms[i]); - } - } - efree(params); - params = NULL; - } - *retval = ret; - zval_ptr_dtor(&method_name); - - return error; -} - -zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_DC) -{ - zval *result = NULL; - MAKE_STD_ZVAL(result); - - switch (git_object_type(object)) { - case GIT_OBJ_TAG: { - php_git2_tag *m_obj = NULL; - - object_init_ex(result, git2_tag_class_entry); - m_obj = PHP_GIT2_GET_OBJECT(php_git2_tag, result); - m_obj->tag = (git_tag*)object; - break; - } - case GIT_OBJ_COMMIT: { - php_git2_commit *m_obj = NULL; - - object_init_ex(result, git2_commit_class_entry); - m_obj = PHP_GIT2_GET_OBJECT(php_git2_commit, result); - m_obj->commit = (git_commit*)object; - break; - } - case GIT_OBJ_BLOB: { - php_git2_blob *m_obj = NULL; - - object_init_ex(result, git2_blob_class_entry); - m_obj = PHP_GIT2_GET_OBJECT(php_git2_blob, result); - m_obj->blob = (git_blob*)object; - break; - } - case GIT_OBJ_TREE: { - php_git2_tree *m_obj = NULL; - unsigned int numbers = 0; - int i = 0; - zval *m_array; - - object_init_ex(result, git2_tree_class_entry); - m_obj = PHP_GIT2_GET_OBJECT(php_git2_tree, result); - m_obj->tree = (git_tree*)object; - m_obj->repository = repository; - numbers = git_tree_entrycount(m_obj->tree); - MAKE_STD_ZVAL(m_array); - array_init(m_array); - - for (i = 0;i < numbers; i++) { - const char *entry_name = {0}; - char entry_oid[GIT_OID_HEXSZ+1] = {0}; - const git_tree_entry *entry; - const git_oid *oid = NULL; - zval *m_entry = NULL; - - entry = git_tree_entry_byindex(m_obj->tree, i); - entry_name = git_tree_entry_name(entry); - oid = git_tree_entry_id(entry); - git_oid_fmt(entry_oid, oid); - - MAKE_STD_ZVAL(m_entry); - object_init_ex(m_entry, git2_tree_entry_class_entry); - add_property_stringl_ex(m_entry, "name", sizeof("name"), (const char *)entry_name, strlen(entry_name), 1 TSRMLS_CC); - add_property_stringl_ex(m_entry, "oid", sizeof("oid"), (const char *)entry_oid, strlen(entry_oid), 1 TSRMLS_CC); - add_property_long_ex(m_entry, "attributes", sizeof("attributes"), git_tree_entry_filemode(entry) TSRMLS_CC); - add_next_index_zval(m_array, m_entry); - } - - add_property_zval_ex(result, "entries",sizeof("entries"),m_array TSRMLS_CC); - zval_ptr_dtor(&m_array); - - break; - } - case GIT_OBJ_BAD: - case GIT_OBJ_ANY: - case GIT_OBJ__EXT1: - case GIT_OBJ__EXT2: - case GIT_OBJ_OFS_DELTA: - case GIT_OBJ_REF_DELTA: - default: - break; - } - - return result; -} - -zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC) -{ - zval **data; - char *key; - int length; - - zend_mangle_property_name(&key,&length,"*",1,name,name_length,0); - if (zend_hash_find(Z_OBJPROP_P(object),key,length,(void **)&data) != SUCCESS) { - data = NULL; - } - - efree(key); - return *data; -} - -int php_git2_add_protected_property_string_ex(zval *object, char *name, int name_length, char *data, zend_bool duplicate TSRMLS_DC) -{ - zval *tmp; - char *key; - int length; - - MAKE_STD_ZVAL(tmp); - ZVAL_STRING(tmp,data,duplicate); - zend_mangle_property_name(&key, &length, "*",1,name,name_length,0); - zend_hash_update(Z_OBJPROP_P(object),key,length,&tmp,sizeof(zval *),NULL); - efree(key); - - return SUCCESS; -} - -int php_git2_add_protected_property_zval_ex(zval *object, char *name, int name_length, zval *data, zend_bool duplicate TSRMLS_DC) -{ - zval *tmp; - char *key; - int length; - - MAKE_STD_ZVAL(tmp); - ZVAL_ZVAL(tmp,data,duplicate,0); - - zend_mangle_property_name(&key, &length, "*",1,name,name_length,0); - zend_hash_update(Z_OBJPROP_P(object),key,length,&tmp,sizeof(zval *),NULL); - efree(key); - - return SUCCESS; -} - - -PHP_MINIT_FUNCTION(git2) -{ - php_git2_repository_init(TSRMLS_C); - php_git2_commit_init(TSRMLS_C); - php_git2_blob_init(TSRMLS_C); - php_git2_tree_init(TSRMLS_C); - php_git2_tree_builder_init(TSRMLS_C); - php_git2_tree_entry_init(TSRMLS_C); - php_git2_signature_init(TSRMLS_C); - php_git2_walker_init(TSRMLS_C); - php_git2_reference_init(TSRMLS_C); - php_git2_index_entry_init(TSRMLS_C); - php_git2_index_init(TSRMLS_C); - php_git2_config_init(TSRMLS_C); - php_git2_remote_init(TSRMLS_C); - php_git2_tag_init(TSRMLS_C); - php_git2_odb_init(TSRMLS_C); - php_git2_odb_object_init(TSRMLS_C); - php_git2_backend_init(TSRMLS_C); - - return SUCCESS; -} - -PHP_MINFO_FUNCTION(git2) -{ - php_printf("PHP libgit2 Extension\n"); - php_info_print_table_start(); - php_info_print_table_row(2,"Version", PHP_GIT2_EXTVER "-dev"); - php_info_print_table_row(2,"libgit2 version", LIBGIT2_VERSION); - php_info_print_table_end(); -} - -PHP_RINIT_FUNCTION(git2) -{ - git_threads_init(); - - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(git2) -{ - git_threads_shutdown(); - return SUCCESS; -} - -zend_module_entry git2_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 - STANDARD_MODULE_HEADER, -#endif - PHP_GIT2_EXTNAME, - NULL, /* Functions */ - PHP_MINIT(git2), /* MINIT */ - NULL, /* MSHUTDOWN */ - PHP_RINIT(git2), /* RINIT */ - PHP_RSHUTDOWN(git2),/* RSHUTDOWN */ - PHP_MINFO(git2), /* MFINFO */ -#if ZEND_MODULE_API_NO >= 20010901 - PHP_GIT2_EXTVER, -#endif - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_GIT2 -ZEND_GET_MODULE(git2) -#endif \ No newline at end of file diff --git a/index.c b/index.c deleted file mode 100644 index e3c45c77ef..0000000000 --- a/index.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" -#include -#include - -PHPAPI zend_class_entry *git2_index_class_entry; - -static void php_git2_index_free_storage(php_git2_index *object TSRMLS_DC) -{ - if (object->index != NULL) { - object->index = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_index_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_index); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_index___construct, 0,0,1) - ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\Index::__construct(string $path) -*/ -PHP_METHOD(git2_index, __construct) -{ - char *path; - git_index *index; - int error, path_len = 0; - php_git2_index *m_index; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE) { - return; - } - - error = git_index_open(&index, path); - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - m_index->index = index; -} -/* }}} */ - - -/* -{{{ proto: Git2\Index::count() -*/ -PHP_METHOD(git2_index, count) -{ - php_git2_index *m_index; - - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - RETURN_LONG(git_index_entrycount(m_index->index)); -} -/* }}} */ - -/* -{{{ proto: Git2\Index::writeTree() -*/ -PHP_METHOD(git2_index, writeTree) -{ - php_git2_index *m_index; - git_oid tree_oid; - char oid_out[GIT_OID_HEXSZ] = {0}; - int error = 0; - - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - error = git_index_write_tree(&tree_oid, m_index->index); - - git_oid_fmt(oid_out, &tree_oid); - RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1); -} -/* }}} */ - - - -/* Iterator Implementation */ - -/* -{{{ proto: Git2\Tree::current() -*/ -PHP_METHOD(git2_index, current) -{ - php_git2_index *m_index; - const git_index_entry *entry; - zval *z_entry; - - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - entry = git_index_get_byindex(m_index->index, m_index->offset); - if (entry == NULL) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified offset does not exist. %d"); - RETURN_FALSE; - } - - php_git2_create_index_entry(&z_entry, (git_index_entry *)entry TSRMLS_CC); - RETURN_ZVAL(z_entry, 0, 1); -} - -/* -{{{ proto: Git2\Tree::key() -*/ -PHP_METHOD(git2_index, key) -{ - php_git2_index *m_index; - - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - RETURN_LONG(m_index->offset); -} - -/* -{{{ proto: Git2\Tree::valid() -*/ -PHP_METHOD(git2_index, next) -{ - php_git2_index *m_index; - - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - m_index->offset++; -} - -/* -{{{ proto: Git2\Tree::rewind() -*/ -PHP_METHOD(git2_index, rewind) -{ - php_git2_index *m_index; - - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - m_index->offset = 0; -} - -/* -{{{ proto: Git2\Index::valid() -*/ -PHP_METHOD(git2_index, valid) -{ - php_git2_index *m_index; - int entry_count = 0; - - m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); - entry_count = git_index_entrycount(m_index->index); - if (m_index->offset < entry_count) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -static zend_function_entry php_git2_index_methods[] = { - PHP_ME(git2_index, __construct, arginfo_git2_index___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(git2_index, count, NULL, ZEND_ACC_PUBLIC) - /* Iterator Implementation */ - PHP_ME(git2_index, current, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_index, key, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_index, next, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_index, rewind, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_index, valid, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_index, writeTree, NULL, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_index_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Index", php_git2_index_methods); - git2_index_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_index_class_entry->create_object = php_git2_index_new; - zend_class_implements(git2_index_class_entry TSRMLS_CC, 1, spl_ce_Iterator); -} diff --git a/index_entry.c b/index_entry.c deleted file mode 100644 index 0579a9a61c..0000000000 --- a/index_entry.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_index_entry_class_entry; - -static void php_git2_index_entry_free_storage(php_git2_index_entry *object TSRMLS_DC) -{ - if (object->entry != NULL) { - free(object->entry); - object->entry = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_index_entry_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_index_entry); - return retval; -} - -static zend_function_entry php_git2_index_entry_methods[] = { - {NULL,NULL,NULL} -}; - -void php_git2_index_entry_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "IndexEntry", php_git2_index_entry_methods); - git2_index_entry_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_index_entry_class_entry->create_object = php_git2_index_entry_new; - - zend_declare_property_null(git2_index_entry_class_entry, "path", sizeof("path")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "oid", sizeof("oid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "dev", sizeof("dev")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "ino", sizeof("ino")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "mode", sizeof("mode")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "uid", sizeof("uid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "gid", sizeof("gid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "file_size", sizeof("file_size")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "flags", sizeof("flags")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "flags_extended", sizeof("flags_extended")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "mtime", sizeof("mtime")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_index_entry_class_entry, "ctime", sizeof("ctime")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - -} \ No newline at end of file diff --git a/odb.c b/odb.c deleted file mode 100644 index b91475026b..0000000000 --- a/odb.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_odb_class_entry; -static zend_object_handlers git2_odb_object_handlers; - -static void php_git2_odb_free_storage(php_git2_odb *object TSRMLS_DC) -{ - if (object->odb != NULL) { - git_odb_free(object->odb); - object->odb = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_odb_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_odb); - retval.handlers = &git2_odb_object_handlers; - return retval; -} - - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_odb_hash, 0,0,2) - ZEND_ARG_INFO(0, contents) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_odb_write, 0,0,2) - ZEND_ARG_INFO(0, contents) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_odb_exists, 0,0,1) - ZEND_ARG_INFO(0, oid) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_odb_read, 0,0,1) - ZEND_ARG_INFO(0, oid) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_odb_add_alternate, 0,0,2) - ZEND_ARG_INFO(0, backend) - ZEND_ARG_INFO(0, priority) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_odb_add_backend, 0,0,2) - ZEND_ARG_INFO(0, backend) - ZEND_ARG_INFO(0, priority) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\ODB::hash(string $contents, int $type) -*/ -PHP_METHOD(git2_odb, hash) -{ - char *contents; - int contents_len = 0; - long type = 0; - git_oid oid; - char oid_out[GIT_OID_HEXSZ+1]; - int error = 0; - php_git2_odb *m_odb; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sl", &contents, &contents_len, &type) == FAILURE) { - return; - } - m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); - - error = git_odb_hash(&oid, contents,contents_len, type); - PHP_GIT2_EXCEPTION_CHECK(error); - - git_oid_fmt(oid_out, &oid); - RETURN_STRINGL(oid_out,GIT_OID_HEXSZ,1); -} -/* }}} */ - -/* -{{{ proto: Git2\ODB::write(string $contents, int $type) -*/ -PHP_METHOD(git2_odb, write) -{ - char *contents; - int contents_len = 0; - long type = 0; - git_odb_stream *stream; - git_oid oid; - char oid_out[GIT_OID_HEXSZ+1]; - int error = 0; - php_git2_odb *m_odb; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sl", &contents, &contents_len, &type) == FAILURE) { - return; - } - m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); - - error = git_odb_open_wstream(&stream, m_odb->odb, contents_len, (git_otype)type); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = stream->write(stream, contents, contents_len); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = stream->finalize_write(&oid, stream); - PHP_GIT2_EXCEPTION_CHECK(error); - - git_oid_fmt(oid_out, &oid); - RETURN_STRINGL(oid_out,GIT_OID_HEXSZ,1); -} -/* }}} */ - -/* -{{{ proto: Git2\ODB::exists($oid) -*/ -PHP_METHOD(git2_odb, exists) -{ - char *hash; - int hash_len = 0; - git_oid id; - php_git2_odb *m_odb; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE) { - return; - } - - m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); - - if (git_oid_fromstr(&id, hash) != GIT_OK) { - RETURN_FALSE; - } - - if (git_odb_exists(m_odb->odb, &id) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\ODB::read($oid) -*/ -PHP_METHOD(git2_odb, read) -{ - char *hash; - int error, hash_len = 0; - git_oid id; - git_odb_object *object; - zval *raw; - php_git2_odb *m_odb; - php_git2_odb_object *m_odb_object; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE) { - return; - } - - m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); - if (git_oid_fromstr(&id, hash) != GIT_OK) { - RETURN_FALSE; - } - - error = git_odb_read(&object,m_odb->odb, &id); - PHP_GIT2_EXCEPTION_CHECK(error); - - MAKE_STD_ZVAL(raw); - object_init_ex(raw, git2_odb_object_class_entry); - m_odb_object = PHP_GIT2_GET_OBJECT(php_git2_odb_object, raw); - m_odb_object->object = object; - - RETVAL_ZVAL(raw, 0, 1); -} -/* }}} */ - -static zend_function_entry php_git2_odb_methods[] = { - PHP_ME(git2_odb, hash, arginfo_git2_odb_hash, ZEND_ACC_PUBLIC) - PHP_ME(git2_odb, write, arginfo_git2_odb_write, ZEND_ACC_PUBLIC) - PHP_ME(git2_odb, exists, arginfo_git2_odb_exists, ZEND_ACC_PUBLIC) - PHP_ME(git2_odb, read, arginfo_git2_odb_read, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_odb_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "ODB", php_git2_odb_methods); - git2_odb_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_odb_class_entry->create_object = php_git2_odb_new; - - memcpy(&git2_odb_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - git2_odb_object_handlers.clone_obj = NULL; -} \ No newline at end of file diff --git a/odb_object.c b/odb_object.c deleted file mode 100644 index 2760630872..0000000000 --- a/odb_object.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_odb_object_class_entry; -static zend_object_handlers git2_odb_object_object_handlers; - -static void php_git2_odb_object_free_storage(php_git2_odb_object *object TSRMLS_DC) -{ - if (object->object != NULL) { - git_odb_object_free(object->object); - object->object = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_odb_object_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_odb_object); - retval.handlers = &git2_odb_object_object_handlers; - return retval; -} - -static int php_git2_odb_object_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) -{ - zend_class_entry *ce; - php_git2_odb_object *m_raw; - - switch (type) { - case IS_STRING: - m_raw = PHP_GIT2_GET_OBJECT(php_git2_odb_object, readobj); - INIT_PZVAL(writeobj); - ZVAL_STRINGL(writeobj,git_odb_object_data(m_raw->object),git_odb_object_size(m_raw->object),1); - return SUCCESS; - case IS_BOOL: - INIT_PZVAL(writeobj); - ZVAL_BOOL(writeobj, 1); - return SUCCESS; - case IS_LONG: - ce = Z_OBJCE_P(readobj); - zend_error(E_NOTICE, "Object of class %s could not be converted to int", ce->name); - INIT_PZVAL(writeobj); - if (readobj == writeobj) { - zval_dtor(readobj); - } - ZVAL_LONG(writeobj, 1); - return SUCCESS; - case IS_DOUBLE: - ce = Z_OBJCE_P(readobj); - zend_error(E_NOTICE, "Object of class %s could not be converted to double", ce->name); - INIT_PZVAL(writeobj); - if (readobj == writeobj) { - zval_dtor(readobj); - } - ZVAL_DOUBLE(writeobj, 1); - return SUCCESS; - default: - INIT_PZVAL(writeobj); - Z_TYPE_P(writeobj) = IS_NULL; - break; - } - return FAILURE; -} - - -/* -{{{ proto: Git2\raw::getContent() -*/ -PHP_METHOD(git2_odb_object, getContent) -{ - php_git2_odb_object *m_raw; - - m_raw = PHP_GIT2_GET_OBJECT(php_git2_odb_object,getThis()); - RETVAL_STRINGL(git_odb_object_data(m_raw->object),git_odb_object_size(m_raw->object),1); -} -/* }}} */ - - -/* -{{{ proto: Git2\raw::getType() -*/ -PHP_METHOD(git2_odb_object, getType) -{ - php_git2_odb_object *m_raw; - git_otype type; - - m_raw = PHP_GIT2_GET_OBJECT(php_git2_odb_object,getThis()); - - type = git_odb_object_type(m_raw->object); - RETURN_LONG(type); -} -/* }}} */ - - -static zend_function_entry php_git2_odb_object_methods[] = { - PHP_ME(git2_odb_object, getContent, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_odb_object, getType, NULL, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_odb_object_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "ODBObject", php_git2_odb_object_methods); - git2_odb_object_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_odb_object_class_entry->create_object = php_git2_odb_object_new; - - memcpy(&git2_odb_object_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - git2_odb_object_object_handlers.clone_obj = NULL; - git2_odb_object_object_handlers.cast_object = php_git2_odb_object_cast_object_tostring; -} \ No newline at end of file diff --git a/php_git2.h b/php_git2.h deleted file mode 100644 index 589caa1417..0000000000 --- a/php_git2.h +++ /dev/null @@ -1,329 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef PHP_GIT2_H -# define PHP_GIT2_H - -# define PHP_GIT2_EXTNAME "git2" -# define PHP_GIT2_EXTVER "0.2.1" - -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -# include "php.h" -# include "Zend/zend_interfaces.h" -# include "Zend/zend_exceptions.h" -# include "ext/spl/spl_exceptions.h" -# include "ext/standard/php_string.h" -# include -# include -# include -# include -# include - -extern zend_module_entry git2_module_entry; - -# define phpext_git2_ptr &git_module_entry; -# define PHP_GIT2_NS "Git2" - -extern PHPAPI zend_class_entry *git2_repository_class_entry; -extern PHPAPI zend_class_entry *git2_commit_class_entry; -extern PHPAPI zend_class_entry *git2_blob_class_entry; -extern PHPAPI zend_class_entry *git2_tree_class_entry; -extern PHPAPI zend_class_entry *git2_tree_builder_class_entry; -extern PHPAPI zend_class_entry *git2_tree_entry_class_entry; -extern PHPAPI zend_class_entry *git2_signature_class_entry; -extern PHPAPI zend_class_entry *git2_walker_class_entry; -extern PHPAPI zend_class_entry *git2_reference_class_entry; -extern PHPAPI zend_class_entry *git2_index_class_entry; -extern PHPAPI zend_class_entry *git2_index_entry_class_entry; -extern PHPAPI zend_class_entry *git2_config_class_entry; -extern PHPAPI zend_class_entry *git2_remote_class_entry; -extern PHPAPI zend_class_entry *git2_tag_class_entry; -extern PHPAPI zend_class_entry *git2_odb_class_entry; -extern PHPAPI zend_class_entry *git2_odb_object_class_entry; -extern PHPAPI zend_class_entry *git2_backend_class_entry; - -typedef struct{ - zend_object zo; - git_repository *repository; -} php_git2_repository; - -typedef struct{ - zend_object zo; - git_commit *commit; -} php_git2_commit; - -typedef struct{ - zend_object zo; - git_blob *blob; -} php_git2_blob; - -typedef struct{ - zend_object zo; - git_tree *tree; - unsigned int offset; - git_repository *repository; -} php_git2_tree; - -typedef struct{ - zend_object zo; - git_tree_entry *entry; -} php_git2_tree_entry; - -typedef struct{ - zend_object zo; - git_treebuilder *builder; -} php_git2_tree_builder; - -typedef struct{ - zend_object zo; - git_signature *signature; -} php_git2_signature; - -typedef struct{ - zend_object zo; - git_reference *reference; -} php_git2_reference; - -typedef struct php_git2_vector{ - size_t _alloc_size; - size_t length; - void **contents; -} php_git2_vector; - -typedef struct{ - zend_object zo; - git_revwalk *walker; - git_oid *current; - php_git2_vector vector; - git_repository *repository; - int dirty; -} php_git2_walker; - -typedef struct{ - zend_object zo; - git_index *index; - unsigned int offset; -} php_git2_index; - -typedef struct{ - zend_object zo; - git_index_entry *entry; -} php_git2_index_entry; - -typedef struct{ - zend_object zo; - git_config *config; -} php_git2_config; - -typedef struct{ - zend_object zo; - git_remote *remote; -} php_git2_remote; - -typedef struct{ - zend_object zo; - git_tag *tag; -} php_git2_tag; - -typedef struct{ - zend_object zo; - git_odb *odb; -} php_git2_odb; - -typedef struct{ - zend_object zo; - git_odb_object *object; -} php_git2_odb_object; - -typedef struct{ - zend_object zo; - struct git_odb_backend *backend; -} php_git2_backend; - -typedef struct{ - git_odb_backend parent; - zval *self; -} php_git2_backend_internal; - - -# define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); - -# if ZEND_MODULE_API_NO >= 20100525 -# define PHP_GIT2_STD_CREATE_OBJECT(STRUCT_NAME) \ - STRUCT_NAME *object;\ - \ - object = ecalloc(1, sizeof(*object));\ - zend_object_std_init(&object->zo, ce TSRMLS_CC);\ - object_properties_init(&object->zo, ce);\ - \ - retval.handle = zend_objects_store_put(object,\ - (zend_objects_store_dtor_t)zend_objects_destroy_object,\ - (zend_objects_free_object_storage_t) STRUCT_NAME##_free_storage ,\ - NULL TSRMLS_CC);\ - retval.handlers = zend_get_std_object_handlers(); -# else -# define PHP_GIT2_STD_CREATE_OBJECT(STRUCT_NAME) \ - STRUCT_NAME *object;\ - zval *tmp = NULL;\ - \ - object = ecalloc(1, sizeof(*object));\ - zend_object_std_init(&object->zo, ce TSRMLS_CC);\ - zend_hash_copy(object->zo.properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); \ - \ - retval.handle = zend_objects_store_put(object,\ - (zend_objects_store_dtor_t)zend_objects_destroy_object,\ - (zend_objects_free_object_storage_t) STRUCT_NAME##_free_storage ,\ - NULL TSRMLS_CC);\ - retval.handlers = zend_get_std_object_handlers(); -# endif - - -extern zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); -extern int php_git2_add_protected_property_string_ex(zval *object, char *name, int name_length, char *data, zend_bool duplicate TSRMLS_DC); -extern int php_git2_add_protected_property_zval_ex(zval *object, char *name, int name_length, zval *data, zend_bool duplicate TSRMLS_DC); -extern zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_DC); -extern int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...); - -extern inline void php_git2_create_signature(zval *object, char *name, int name_len, char *email, int email_len, zval *date TSRMLS_DC); - -static zval* php_git2_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) -{ -#if PHP_VERSION_ID <= 50304 - Z_TYPE_P(object) = IS_OBJECT; - object_init_ex(object, pce); - Z_SET_REFCOUNT_P(object, 1); - Z_UNSET_ISREF_P(object); - return object; -#else - return php_date_instantiate(pce, object TSRMLS_CC); -#endif -} - -static void inline php_git2_create_signature_from_commit(zval **object, git_commit *commit, int type TSRMLS_DC) -{ - zval *ret, *date; - char time_str[12] = {0}; - const git_signature *author; - php_git2_signature *m_signature; - - if (type == 0) { - author = git_commit_author(commit); - } else { - author = git_commit_committer(commit); - } - - MAKE_STD_ZVAL(ret); - MAKE_STD_ZVAL(date); - - object_init_ex(ret,git2_signature_class_entry); - m_signature = PHP_GIT2_GET_OBJECT(php_git2_signature, ret); - add_property_string_ex(ret,"name",sizeof("name"), author->name,1 TSRMLS_CC); - add_property_string_ex(ret,"email",sizeof("email"),author->email,1 TSRMLS_CC); - - php_git2_date_instantiate(php_date_get_date_ce(), date TSRMLS_CC); - snprintf(time_str,12,"%c%ld",'@',author->when.time); - -#if PHP_VERSION_ID <= 50304 - { - zval *tmp; - - MAKE_STD_ZVAL(tmp); - ZVAL_STRING(tmp, time_str,1); - zend_call_method_with_1_params(&date, php_date_get_date_ce(), NULL, "__construct", NULL, tmp); - zval_ptr_dtor(&tmp); - } -#else - php_date_initialize(zend_object_store_get_object(date TSRMLS_CC), time_str, strlen(time_str), NULL, NULL, 0 TSRMLS_CC); -#endif - - add_property_zval(ret,"time",date); - zval_ptr_dtor(&date); - *object = ret; -} - -static inline void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repository *repository) -{ - TSRMLS_FETCH(); - char buf[GIT_OID_HEXSZ+1] = {0}; - const git_oid *oid; - php_git2_tree_entry *m_entry; - - MAKE_STD_ZVAL(*object); - object_init_ex(*object, git2_tree_entry_class_entry); - m_entry = PHP_GIT2_GET_OBJECT(php_git2_tree_entry, *object); - - m_entry->entry = entry; - oid = git_tree_entry_id(entry); - git_oid_tostr(buf,GIT_OID_HEXSZ+1,oid); - - add_property_string(*object, "name", (char *)git_tree_entry_name(entry), 1); - add_property_string(*object, "oid", buf, 1); - add_property_long(*object, "attributes", git_tree_entry_filemode(entry)); -} - -static inline void php_git2_create_index_entry(zval **object, git_index_entry *entry TSRMLS_DC) -{ - zval *tmp = NULL; - char oid_out[GIT_OID_HEXSZ] = {0}; - - MAKE_STD_ZVAL(tmp); - object_init_ex(tmp, git2_index_entry_class_entry); - git_oid_fmt(oid_out, &entry->oid); - - add_property_string_ex(tmp, "path", sizeof("path"), entry->path, 1 TSRMLS_CC); - add_property_stringl_ex(tmp, "oid", sizeof("oid"), oid_out,GIT_OID_HEXSZ, 1 TSRMLS_CC); - add_property_long(tmp, "dev", entry->dev); - add_property_long(tmp, "ino", entry->ino); - add_property_long(tmp, "mode", entry->mode); - add_property_long(tmp, "uid", entry->uid); - add_property_long(tmp, "gid", entry->gid); - add_property_long(tmp, "file_size", entry->file_size); - add_property_long(tmp, "flags", entry->flags); - add_property_long(tmp, "flags_extended", entry->flags_extended); - add_property_long(tmp, "ctime", entry->ctime.seconds); - add_property_long(tmp, "mtime", entry->mtime.seconds); - - *object = tmp; -} - -#define PHP_GIT2_EXCEPTION_CHECK(errorcode) \ - if (errorcode < 0) { \ - zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%d\n(error code %d) at %s:%d", giterr_last(), errorcode, __FILE__, __LINE__); \ - giterr_clear(); \ - return; \ - } \ - -static inline void php_git2_exception_check(int errorcode TSRMLS_DC) -{ - if (errorcode < 0) { - zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%d\n(error code %d)", giterr_last(), errorcode); - giterr_clear(); - return; - } -} - -#endif /* PHP_GIT2_H */ diff --git a/reference.c b/reference.c deleted file mode 100644 index 4f91939be2..0000000000 --- a/reference.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_reference_class_entry; - -static void php_git2_reference_free_storage(php_git2_reference *object TSRMLS_DC) -{ - if (object->reference != NULL) { - object->reference = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_reference_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_reference); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_reference_create, 0,0,4) - ZEND_ARG_INFO(0, repository) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, target) - ZEND_ARG_INFO(0, force) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_reference_lookup, 0,0,2) - ZEND_ARG_INFO(0, repository) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_reference_each, 0,0,2) - ZEND_ARG_INFO(0, repository) - ZEND_ARG_INFO(0, filter) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\Reference::lookup(Git2\Repository $repo, string $path) -*/ -PHP_METHOD(git2_reference, lookup) -{ - char *path; - int error, path_len = 0; - git_reference *ref; - zval *repository, *object; - php_git2_repository *m_repository; - php_git2_reference *m_reference; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "Os", &repository, git2_repository_class_entry, &path, &path_len) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - - error = git_reference_lookup(&ref, m_repository->repository, path); - if (error == GIT_ENOTFOUND) { - RETURN_FALSE; - } - - MAKE_STD_ZVAL(object); - object_init_ex(object,git2_reference_class_entry); - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, object); - m_reference->reference = ref; - - RETURN_ZVAL(object,0,1); -} -/* }}} */ - -/* -{{{ proto: Git2\Reference::getTarget() -*/ -PHP_METHOD(git2_reference, getTarget) -{ - php_git2_reference *m_reference; - const git_oid *oid; - char oid_out[GIT_OID_HEXSZ] = {0}; - - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); - - if (git_reference_type(m_reference->reference) == GIT_REF_OID) { - oid = git_reference_target(m_reference->reference); - git_oid_fmt(oid_out, oid); - RETVAL_STRINGL(oid_out,GIT_OID_HEXSZ,1); - } else { - RETVAL_STRING(git_reference_symbolic_target(m_reference->reference), 1); - } -} -/* }}} */ - -/* -{{{ proto: Git2\Reference::getName() -*/ -PHP_METHOD(git2_reference, getName) -{ - php_git2_reference *m_reference; - - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); - - RETVAL_STRING(git_reference_name(m_reference->reference),1); -} -/* }}} */ - -/* -{{{ proto: Git2\Reference::getBaseName() -*/ -PHP_METHOD(git2_reference, getBaseName) -{ - char *basename = NULL; - const char *name = NULL; - php_git2_reference *m_reference; - size_t len; - - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); - - name = git_reference_name(m_reference->reference); - php_basename(name, strlen(name), NULL, 0, &basename, &len TSRMLS_CC); - RETVAL_STRINGL(basename, len, 0); -} -/* }}} */ - -/* -{{{ proto: Git2\Reference::resolve() -*/ -PHP_METHOD(git2_reference, resolve) -{ - git_reference *resolved; - php_git2_reference *m_reference; - zval *object; - int error; - - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); - error = git_reference_resolve(&resolved, m_reference->reference); - - MAKE_STD_ZVAL(object); - object_init_ex(object, git2_reference_class_entry); - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, object); - m_reference->reference = resolved; - - RETURN_ZVAL(object, 0, 1); -} -/* }}} */ - - -/* -{{{ proto: Git2\Reference::create(Git2\Repository $repo, string $name, string $oid_or_symbolic_ref[, bool $force = false]) -*/ -PHP_METHOD(git2_reference, create) -{ - zval *repository = NULL; - php_git2_repository *m_repository; - php_git2_reference *m_reference; - char *name, *target; - int error = 0, target_len = 0, name_len = 0; - zend_bool force = 0; - git_reference *ref; - git_oid oid; - zval *object; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "Oss|b", &repository, git2_repository_class_entry, &name, &name_len, &target, &target_len, &force) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - - if (git_oid_fromstr(&oid, target) == GIT_OK) { - error = git_reference_create(&ref, m_repository->repository, name, &oid, (int)force); - } else { - error = git_reference_symbolic_create(&ref, m_repository->repository, name, target, (int)force); - } - - if (error != GIT_OK) { - const git_error *err; - - err = giterr_last(); - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Git2\\Refernce::create failed: %s (%d)", err->message, err->klass); - } - - MAKE_STD_ZVAL(object); - object_init_ex(object, git2_reference_class_entry); - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, object); - m_reference->reference = ref; - - RETURN_ZVAL(object, 0, 1); -} -/* }}} */ - - -typedef struct { - unsigned int type; - git_repository *repository; - zval *result; - zend_fcall_info *fci; - zend_fcall_info_cache *fci_cache; -} php_git2_ref_foreach_cb_t; - -static int php_git2_ref_foreach_cb(const char *name, void *opaque) -{ - TSRMLS_FETCH(); - zval *ref; - git_reference *reference; - php_git2_ref_foreach_cb_t *payload; - php_git2_reference *m_reference; - - payload = (php_git2_ref_foreach_cb_t *)opaque; - git_reference_lookup(&reference, payload->repository,name); - - MAKE_STD_ZVAL(ref); - object_init_ex(ref, git2_reference_class_entry); - m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, ref); - m_reference->reference = reference; - - if (payload->type == 0) { - add_next_index_zval(payload->result, ref); - } else { - zval *str, *result, *params = NULL; - MAKE_STD_ZVAL(params); - MAKE_STD_ZVAL(str); - ZVAL_STRING(str, name, 1); - array_init(params); - add_next_index_zval(params, str); - - zend_fcall_info_args(payload->fci, params TSRMLS_CC); - payload->fci->retval_ptr_ptr = &result; - - if (zend_call_function(payload->fci, payload->fci_cache TSRMLS_CC) == SUCCESS && - payload->fci->retval_ptr_ptr && *payload->fci->retval_ptr_ptr) { - } - - if (Z_BVAL_PP(payload->fci->retval_ptr_ptr)) { - add_next_index_zval(payload->result, ref); - } else { - zval_ptr_dtor(&ref); - } - - zend_fcall_info_args_clear(payload->fci, 1); - zval_ptr_dtor(&str); - zval_ptr_dtor(&result); - zval_ptr_dtor(¶ms); - - } - - return GIT_OK; -} - -/* -{{{ proto: Git2\Reference::each(Git2\Repository $repository [,int filter[, Callable $callback]]) -*/ -PHP_METHOD(git2_reference, each) -{ - zval *repository = NULL; - php_git2_repository *m_repository; - char *filter; - php_git2_ref_foreach_cb_t opaque; - int filter_len = 0; - unsigned int list_flags = GIT_REF_LISTALL; - zend_fcall_info fci = { - 0,NULL,NULL,NULL,NULL,0,NULL,NULL - }; - zend_fcall_info_cache fci_cache; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "O|sf", &repository, git2_repository_class_entry, &filter, &filter_len, &fci, &fci_cache) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - opaque.type = 0; - if (fci.size != 0) { - opaque.type = 1; - opaque.fci = &fci; - opaque.fci_cache = &fci_cache; - } - opaque.repository = m_repository->repository; - MAKE_STD_ZVAL(opaque.result); - array_init(opaque.result); - - git_reference_foreach(m_repository->repository, &php_git2_ref_foreach_cb, (void *)&opaque); - - RETVAL_ZVAL(opaque.result,0,1); -} -/* }}} */ - - -static zend_function_entry php_git2_reference_methods[] = { - PHP_ME(git2_reference, getTarget, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_reference, getName, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_reference, getBaseName,NULL,ZEND_ACC_PUBLIC) - PHP_ME(git2_reference, resolve, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_reference, create, arginfo_git2_reference_create, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(git2_reference, each, arginfo_git2_reference_each, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) -#ifdef lookup -#undef lookup -#endif - PHP_ME(git2_reference, lookup, arginfo_git2_reference_lookup, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) -#ifndef lookup -#define lookup php_lookup -#endif - {NULL,NULL,NULL} -}; - -void php_git2_reference_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Reference", php_git2_reference_methods); - git2_reference_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_reference_class_entry->create_object = php_git2_reference_new; -} \ No newline at end of file diff --git a/remote.c b/remote.c deleted file mode 100644 index 964b2defe4..0000000000 --- a/remote.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_remote_class_entry; - -static void php_git2_remote_free_storage(php_git2_remote *object TSRMLS_DC) -{ - if (object->remote != NULL) { - free(object->remote); - object->remote = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_remote_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_remote); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_remote___construct, 0,0,2) - ZEND_ARG_INFO(0, repository) - ZEND_ARG_INFO(0, url) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_remote_fetch, 0,0,1) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\Remote::__construct(Git2\Repository $repository, string $url) -*/ -PHP_METHOD(git2_remote, __construct) -{ - char *path; - int error, path_len = 0; - zval *repository; - php_git2_repository *m_repository; - php_git2_remote *m_remote; - git_remote *remote; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "Os", &repository,git2_repository_class_entry, &path, &path_len) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - m_remote = PHP_GIT2_GET_OBJECT(php_git2_remote, getThis()); - if (git_remote_valid_url(path)) { -/* TODO - error = git_remote_new( - &remote, - m_repository->repository, - path, - NULL - ); - */ - } else { - error = git_remote_load(&remote,m_repository->repository, path); - } - m_remote->remote = remote; -} -/* }}} */ - - -static int php_git2_rename_packfile(char *packname, git_indexer_stream *idx) -{ - char path[GIT_PATH_MAX], oid[GIT_OID_HEXSZ + 1], *slash; - int ret; - - strcpy(path,packname); - slash = strrchr(path, '/'); - - if (!slash) { - return -1; - } - - memset(oid, 0x0, sizeof(oid)); - git_oid_fmt(oid, git_indexer_stream_hash(idx)); - ret = sprintf(slash + 1, "pack-%s.pack", oid); - if(ret < 0) { - return -2; - } - - return rename(packname, path); -} - -static int show_ref__cb(git_remote_head *head, void *payload) -{ - char oid[GIT_OID_HEXSZ + 1] = {0}; - git_oid_fmt(oid, &head->oid); - printf("%s\t%s\n", oid, head->name); - return GIT_OK; -} - -/* -{{{ proto: Git2\Remote::fetch() -*/ -PHP_METHOD(git2_remote, fetch) -{ - php_git2_remote *m_remote; - git_indexer_stream *idx = NULL; - git_transfer_progress stats; - char *packname = NULL; - int error = 0; - long direction = 0; - - m_remote = PHP_GIT2_GET_OBJECT(php_git2_remote, getThis()); - -/* - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &direction) == FAILURE) { - return; - } -*/ - direction = GIT_DIRECTION_FETCH; - - error = git_remote_connect(m_remote->remote, direction); - error = git_remote_ls(m_remote->remote, &show_ref__cb, NULL); - //error = git_remote_download(&packname, m_remote->remote); - - /*if (packname != NULL) { - // Create a new instance indexer - error = git_indexer_stream_new(&idx, packname); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = git_indexer_stream_run(idx, &stats); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = git_indexer_stream_write(idx); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = php_git2_rename_packfile(packname, idx); - PHP_GIT2_EXCEPTION_CHECK(error); - }*/ - - //error = git_remote_update_tips(m_remote->remote); - PHP_GIT2_EXCEPTION_CHECK(error); - - //free(packname); - git_indexer_free(idx); -} -/* }}} */ - -static zend_function_entry php_git2_remote_methods[] = { - PHP_ME(git2_remote, __construct, arginfo_git2_remote___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(git2_remote, fetch, arginfo_git2_remote_fetch, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_remote_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Remote", php_git2_remote_methods); - git2_remote_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_remote_class_entry->create_object = php_git2_remote_new; -} \ No newline at end of file diff --git a/repository.c b/repository.c deleted file mode 100644 index 04ef7adb06..0000000000 --- a/repository.c +++ /dev/null @@ -1,613 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" -#include "ext/standard/php_smart_str.h" - -PHPAPI zend_class_entry *git2_repository_class_entry; -void php_git2_repository_init(TSRMLS_D); -static zend_object_handlers git2_repository_object_handlers; - -static void php_git2_repository_free_storage(php_git2_repository *object TSRMLS_DC) -{ - if (object->repository != NULL) { - git_repository_free(object->repository); - object->repository = NULL; - } - - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_repository_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_repository); - retval.handlers = &git2_repository_object_handlers; - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository___construct, 0,0,1) - ZEND_ARG_INFO(0, repository_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_init, 0,0,1) - ZEND_ARG_INFO(0, isBare) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_discover, 0,0,3) - ZEND_ARG_INFO(0, path) - ZEND_ARG_INFO(0, across_fs) - ZEND_ARG_INFO(0, ceiling_dirs) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_exists, 0,0,1) - ZEND_ARG_INFO(0, exists) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_write, 0,0,2) - ZEND_ARG_INFO(0, contents) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_hash, 0,0,2) - ZEND_ARG_INFO(0, contents) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_get_merge_base, 0,0,2) - ZEND_ARG_INFO(0, one) - ZEND_ARG_INFO(0, two) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_lookup, 0,0,1) - ZEND_ARG_INFO(0, lookup) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_checkout, 0,0,0) -ZEND_END_ARG_INFO() - -static int php_git2_repository_initialize(zval *object, git_repository *repository TSRMLS_DC) -{ - zval *odb; - php_git2_repository *m_repository; - php_git2_odb *m_odb; - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, object); - m_repository->repository = repository; - - MAKE_STD_ZVAL(odb); - object_init_ex(odb,git2_odb_class_entry); - m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, odb); - git_repository_odb(&m_odb->odb,repository); - - add_property_string(object, "path", git_repository_path(repository),1); - add_property_zval(object, "odb", odb); - zval_ptr_dtor(&odb); - - return 0; -} - -/* -{{{ proto: Git2\Repository::__construct(string $path) -*/ -PHP_METHOD(git2_repository, __construct) -{ - const char *repository_path = NULL; - int repository_path_len, ret = 0; - git_repository *repository; - php_git2_repository *m_repository; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|s", &repository_path, &repository_path_len) == FAILURE) { - return; - } - - if (repository_path_len > 0) { - ret = git_repository_open(&repository, repository_path); - PHP_GIT2_EXCEPTION_CHECK(ret); - - php_git2_repository_initialize(getThis(), repository TSRMLS_CC); - } else { - m_repository->repository = NULL; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::isEmpty() -*/ -PHP_METHOD(git2_repository, isEmpty) -{ - php_git2_repository *m_repository; - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (m_repository->repository != NULL) { - if (git_repository_is_empty(m_repository->repository)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } - } else { - /* @todo: throws an exectpion */ - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::isBare() -*/ -PHP_METHOD(git2_repository, isBare) -{ - php_git2_repository *m_repository; - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (m_repository->repository != NULL) { - if (git_repository_is_bare(m_repository->repository) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } - } else { - /* @todo: throws an exectpion */ - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::getPath() -*/ -PHP_METHOD(git2_repository, getPath) -{ - php_git2_repository *m_repository; - const char *path = NULL; - zval *m_path = NULL; - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (m_repository->repository != NULL) { - path = git_repository_path(m_repository->repository); - if (path != NULL) { - MAKE_STD_ZVAL(m_path); - ZVAL_STRING(m_path, path, 1); - RETVAL_ZVAL(m_path,0,1); - } - } else { - /* @todo: throws an exectpion */ - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::getWorkdir() -*/ -PHP_METHOD(git2_repository, getWorkdir) -{ - php_git2_repository *m_repository; - const char *path = NULL; - zval *m_path = NULL; - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (m_repository->repository != NULL) { - path = git_repository_workdir(m_repository->repository); - if (path != NULL) { - MAKE_STD_ZVAL(m_path); - ZVAL_STRING(m_path, path, 1); - RETVAL_ZVAL(m_path,0,1); - } - } else { - /* @todo: throws an exectpion */ - } -} -/* }}} */ - - -/* -{{{ proto: Git2\Repository::init(string $path [, bool isBare]) -*/ -PHP_METHOD(git2_repository, init) -{ - char *path; - int ret, path_len = 0; - zend_bool is_bare = 0; - git_repository *repository; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s|b", &path, &path_len, &is_bare) == FAILURE) { - return; - } - - ret = git_repository_init(&repository, path, is_bare); - if (ret == GIT_OK) { - zval *object; - - MAKE_STD_ZVAL(object); - object_init_ex(object, git2_repository_class_entry); - php_git2_repository_initialize(object, repository TSRMLS_CC); - - RETVAL_ZVAL(object,0,1); - } else { - php_git2_exception_check(ret TSRMLS_CC); - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::headDetached() - A repository's HEAD is detached when it points directly to a commit instead of a branch. -*/ -PHP_METHOD(git2_repository, headDetached) -{ - php_git2_repository *m_repository; - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (m_repository->repository != NULL) { - if (git_repository_head_detached(m_repository->repository) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } - } else { - /* @todo: throws an exectpion */ - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::headOrphan() - An orphan branch is one named from HEAD but which doesn't exist in - the refs namespace, because it doesn't have any commit to point to. -*/ -PHP_METHOD(git2_repository, headOrphan) -{ - php_git2_repository *m_repository; - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (m_repository->repository != NULL) { - if (git_repository_head_orphan(m_repository->repository) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } - } else { - /* @todo: throws an exectpion */ - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::discover(string $path[, bool across_fs, string ceiling_dirs]) -*/ -PHP_METHOD(git2_repository, discover) -{ - char path_buffer[1024] = {0}; - size_t path_size = 1024; - zend_bool across_fs = 1; - char *start_path, *ceiling_dirs = NULL; - int start_path_len, ceiling_dirs_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s|bs", &start_path, &start_path_len, &across_fs, &ceiling_dirs, & ceiling_dirs_len) == FAILURE) { - return; - } - - if (git_repository_discover(path_buffer,path_size,(const char *)start_path,(int)across_fs, (const char *)ceiling_dirs) == GIT_OK) { - RETVAL_STRING(path_buffer, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::exists(string $sha1) -*/ -PHP_METHOD(git2_repository, exists) -{ - char *hash; - int error, hash_len = 0; - git_odb *odb; - git_oid id; - php_git2_repository *m_repository; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - error = git_repository_odb(&odb, m_repository->repository); - PHP_GIT2_EXCEPTION_CHECK(error); - - if (git_oid_fromstr(&id, hash) != GIT_OK) { - RETURN_FALSE; - } - - if (git_odb_exists(odb, &id) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* -{{{ proto: Git2\Repository::getMergeBase(string $oid_one, string $oid_two) -*/ -PHP_METHOD(git2_repository, getMergeBase) -{ - char *one, *two, oid_out[GIT_OID_HEXSZ]; - int error, one_len = 0, two_len = 0; - git_oid out, one_id, two_id; - php_git2_repository *m_repository; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ss", &one, &one_len, &two, &two_len) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - - if (git_oid_fromstrn(&one_id, one, one_len) != GIT_OK) { - RETURN_FALSE; - } - - if (git_oid_fromstrn(&two_id, two, two_len) != GIT_OK) { - RETURN_FALSE; - } - - error = git_merge_base(&out, m_repository->repository, &one_id, &two_id); - if (error == GIT_OK) { - git_oid_fmt(oid_out, &out); - RETURN_STRINGL(oid_out, GIT_OID_HEXSZ, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - - - -/* -{{{ proto: Git2\Repository::lookup(string $sha1[, int type = GIT_OBJ_ANY]) -*/ -PHP_METHOD(git2_repository, lookup) -{ - char *hash; - int error, hash_len = 0; - git_odb *odb; - git_oid id; - git_object *object; - long type = GIT_OBJ_ANY; - php_git2_repository *m_repository; - zval *result = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s|l", &hash, &hash_len, type) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - error = git_repository_odb(&odb, m_repository->repository); - PHP_GIT2_EXCEPTION_CHECK(error); - - if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { - RETURN_FALSE; - } - - if (hash_len < GIT_OID_HEXSZ) { - error = git_object_lookup_prefix(&object, m_repository->repository, &id, hash_len, (git_otype)type); - } else { - error = git_object_lookup(&object, m_repository->repository, &id, (git_otype)type); - } - - result = php_git2_object_new(m_repository->repository, object TSRMLS_CC); - RETVAL_ZVAL(result,0,1); -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::write(string $contents, int $type) -*/ -PHP_METHOD(git2_repository, write) -{ - char *contents; - int contents_len = 0; - long type = 0; - git_odb_stream *stream; - git_odb *odb; - git_oid oid; - char oid_out[GIT_OID_HEXSZ+1]; - int error = 0; - php_git2_repository *m_repository; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sl", &contents, &contents_len, &type) == FAILURE) { - return; - } - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - - error = git_repository_odb(&odb, m_repository->repository); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = git_odb_open_wstream(&stream, odb, contents_len, (git_otype)type); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = stream->write(stream, contents, contents_len); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = stream->finalize_write(&oid, stream); - PHP_GIT2_EXCEPTION_CHECK(error); - - git_oid_fmt(oid_out, &oid); - RETURN_STRINGL(oid_out,GIT_OID_HEXSZ,1); -} -/* }}} */ - -/* -{{{ proto: Git2\Repository::hash(string $contents, int $type) -*/ -PHP_METHOD(git2_repository, hash) -{ - char *contents; - int contents_len = 0; - long type = 0; - git_odb *odb; - git_oid oid; - char oid_out[GIT_OID_HEXSZ+1]; - int error = 0; - php_git2_repository *m_repository; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sl", &contents, &contents_len, &type) == FAILURE) { - return; - } - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - - error = git_repository_odb(&odb, m_repository->repository); - PHP_GIT2_EXCEPTION_CHECK(error); - - error = git_odb_hash(&oid, contents,contents_len, type); - PHP_GIT2_EXCEPTION_CHECK(error); - - git_oid_fmt(oid_out, &oid); - RETURN_STRINGL(oid_out,GIT_OID_HEXSZ,1); -} -/* }}} */ - - -/* -{{{ proto: Git2\Repository::checkout(Git2\Tree $tree[, int $opts, zval $stats) - TODO: implement this -*/ -PHP_METHOD(git2_repository, checkout) -{ -/* - php_git2_repository *m_repository; - php_git2_tree *m_tree; - zval *tree; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "O", &tree, git2_tree_class_entry) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, tree); - - error = git_checkout_tree(m_repository->repository, m_tree->tree, NULL, NULL); - RETURN_LONG(error); -*/ -} -/* }}} */ - - -static int printer( - void *data, - const git_diff_delta *delta, - const git_diff_range *range, - char usage, - const char *line, - size_t line_len) -{ - smart_str *string = (smart_str*)data; - - smart_str_appendl(string, line, strlen(line)); - return 0; -} - -/* -{{{ proto: Git2\Repository::diff(Git2\Tree $a, Git2\Tree $b, $options = NULL) - Experimental -*/ -PHP_METHOD(git2_repository, diff) -{ - zval *old, *new; - php_git2_tree *m_old, *m_new; - php_git2_repository *m_repository; - git_diff_list *list; - smart_str string = {0}; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "OO", &old, git2_tree_class_entry, &new, git2_tree_class_entry) == FAILURE) { - return; - } - - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - m_old = PHP_GIT2_GET_OBJECT(php_git2_tree, old); - m_new = PHP_GIT2_GET_OBJECT(php_git2_tree, new); - - git_diff_tree_to_tree(m_repository->repository, NULL, m_old->tree, m_new->tree, &list); - - git_diff_print_compact(list, &string, printer); - smart_str_0(&string); - git_diff_list_free(list); - - RETVAL_STRING(string.c, 0); -} -/* }}} */ - - -static zend_function_entry php_git2_repository_methods[] = { - PHP_ME(git2_repository, __construct, arginfo_git2_repository___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(git2_repository, isEmpty, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, isBare, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, getPath, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, getWorkdir, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, headDetached,NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, headOrphan, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, init, arginfo_git2_repository_init, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(git2_repository, discover, arginfo_git2_repository_discover, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(git2_repository, exists, arginfo_git2_repository_exists, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, hash, arginfo_git2_repository_hash, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, write, arginfo_git2_repository_write, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, getMergeBase,arginfo_git2_repository_get_merge_base,ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, checkout, arginfo_git2_repository_checkout, ZEND_ACC_PUBLIC) - PHP_ME(git2_repository, diff, NULL, ZEND_ACC_PUBLIC) -#ifdef lookup -#undef lookup -#endif - PHP_ME(git2_repository, lookup, arginfo_git2_repository_lookup, ZEND_ACC_PUBLIC) -#ifndef lookup -#define lookup php_lookup -#endif - {NULL,NULL,NULL} -}; - -void php_git2_repository_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Repository", php_git2_repository_methods); - git2_repository_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_repository_class_entry->create_object = php_git2_repository_new; - - memcpy(&git2_repository_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - git2_repository_object_handlers.clone_obj = NULL; -} diff --git a/signature.c b/signature.c deleted file mode 100644 index 6c8598cb2e..0000000000 --- a/signature.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" -#include -#include - -PHPAPI zend_class_entry *git2_signature_class_entry; - -inline void php_git2_create_signature(zval *object, char *name, int name_len, char *email, int email_len, zval *date TSRMLS_DC) -{ - zval *r_timestamp,*r_offset, *z_name, *z_email = NULL; - php_git2_signature *m_signature; - long timestamp, offset = 0; - int error = 0; - - MAKE_STD_ZVAL(z_name); - MAKE_STD_ZVAL(z_email); - ZVAL_STRINGL(z_name,name,name_len,1); - ZVAL_STRINGL(z_email,email,email_len,1); - - add_property_zval_ex(object, "name", sizeof("name") ,z_name TSRMLS_CC); - add_property_zval_ex(object, "email",sizeof("email"),z_email TSRMLS_CC); - add_property_zval_ex(object, "time", sizeof("time") ,date TSRMLS_CC); - - m_signature = PHP_GIT2_GET_OBJECT(php_git2_signature, object); - - error = php_git2_call_user_function_v(&r_timestamp, date, "getTimeStamp", sizeof("getTimeStamp")-1, 0); - timestamp = Z_LVAL_P(r_timestamp); - php_git2_call_user_function_v(&r_offset, date, "getOffset", sizeof("getOffset")-1, 0); - offset = Z_LVAL_P(r_offset); - - git_signature_new(&m_signature->signature, name,email,(git_time_t)timestamp,offset / 60); - - zval_ptr_dtor(&r_timestamp); - zval_ptr_dtor(&r_offset); - zval_ptr_dtor(&z_email); - zval_ptr_dtor(&z_name); -} - - -static void php_git2_signature_free_storage(php_git2_signature *object TSRMLS_DC) -{ - if (object->signature != NULL) { - git_signature_free(object->signature); - object->signature = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_signature_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_signature); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_signature___construct, 0,0,3) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, email) - ZEND_ARG_INFO(0, date) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\Signature::__construct(string $name, string $email, \DateTime $time) -*/ -PHP_METHOD(git2_signature, __construct) -{ - char *name, *email; - int name_len, email_len = 0; - zval *date = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ssz", &name, &name_len, &email, &email_len, &date) == FAILURE) { - return; - } - - if (!instanceof_function(Z_OBJCE_P(date), php_date_get_date_ce() TSRMLS_CC)) { - RETURN_FALSE; - } - - //@memo - //error = php_git2_call_user_function_v(×tamp, date, "getTimeStamp", sizeof("getTimeStamp")-1, 0); - //zval_ptr_dtor(×tamp); - php_git2_create_signature(getThis(), name, name_len, email, email_len, date TSRMLS_CC); -} -/* }}} */ - - - -static zend_function_entry php_git2_signature_methods[] = { - PHP_ME(git2_signature, __construct, arginfo_git2_signature___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - {NULL,NULL,NULL} -}; - -void php_git2_signature_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Signature", php_git2_signature_methods); - git2_signature_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_signature_class_entry->create_object = php_git2_signature_new; - zend_declare_property_null(git2_signature_class_entry, "name", sizeof("name")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_signature_class_entry, "email", sizeof("email")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_signature_class_entry, "time", sizeof("time")-1, ZEND_ACC_PUBLIC TSRMLS_CC); -} \ No newline at end of file diff --git a/tag.c b/tag.c deleted file mode 100644 index 358d935616..0000000000 --- a/tag.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_tag_class_entry; - -static void php_git2_tag_free_storage(php_git2_tag *object TSRMLS_DC) -{ - if (object->tag != NULL) { - free(object->tag); - object->tag = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_tag_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_tag); - return retval; -} - -/* -{{{ proto: Git2\Tag::getTarget() -*/ -PHP_METHOD(git2_tag, getTarget) -{ - php_git2_tag *m_tag; - git_object *object; - zval *result; - int error = 0; - - m_tag = PHP_GIT2_GET_OBJECT(php_git2_tag, getThis()); - - error = git_tag_target(&object, m_tag->tag); - if (error == GIT_OK) { - result = php_git2_object_new((git_repository*)git_object_owner((git_object*)m_tag->tag), object TSRMLS_CC); - RETVAL_ZVAL(result,0,1); - } -} -/* }}} */ - -/* -{{{ proto: Git2\Tag::getMessage() -*/ -PHP_METHOD(git2_tag, getMessage) -{ - php_git2_tag *m_tag; - const char *message; - - m_tag = PHP_GIT2_GET_OBJECT(php_git2_tag, getThis()); - message = git_tag_message(m_tag->tag); - RETURN_STRING(message,1); -} -/* }}} */ - - -/* -{{{ proto: Git2\Tag::getBaseName() -*/ -PHP_METHOD(git2_tag, getBaseName) -{ - const char *name = NULL; - char *basename = NULL; - php_git2_tag *m_tag; - size_t len; - - m_tag = PHP_GIT2_GET_OBJECT(php_git2_tag, getThis()); - - name = git_tag_name(m_tag->tag); - php_basename(name, strlen(name), NULL, 0, &basename, &len TSRMLS_CC); - RETVAL_STRINGL(basename, len, 0); -} -/* }}} */ - -static zend_function_entry php_git2_tag_methods[] = { - PHP_ME(git2_tag, getTarget, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tag, getMessage, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tag, getBaseName, NULL, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_tag_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Tag", php_git2_tag_methods); - git2_tag_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_tag_class_entry->create_object = php_git2_tag_new; -} \ No newline at end of file diff --git a/tests/000-load_extension.phpt b/tests/000-load_extension.phpt deleted file mode 100644 index f77d3d7dd6..0000000000 --- a/tests/000-load_extension.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Check for Git2 Presence ---SKIPIF-- - ---FILE-- - ---FILE-- - ---FILE-- -isEmpty()) { - echo "FAIL" . PHP_EOL; -} else { - echo "OK" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/001-03-repository_is_bare.phpt b/tests/001-03-repository_is_bare.phpt deleted file mode 100644 index 6716334cd0..0000000000 --- a/tests/001-03-repository_is_bare.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Check for Git2\Repository::isBare ---SKIPIF-- - ---FILE-- -isBare()) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/001-04-repository-get_path.phpt b/tests/001-04-repository-get_path.phpt deleted file mode 100644 index 9c3501d2c7..0000000000 --- a/tests/001-04-repository-get_path.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Check for Git2\Repository::getPath ---SKIPIF-- - ---FILE-- -getPath() == __DIR__ . "/mock/001-01/") { - /* getPath should add DIRECTORY_SEPARATOR at last */ - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/001-05-repository_get_workdir.phpt b/tests/001-05-repository_get_workdir.phpt deleted file mode 100644 index 03544f9402..0000000000 --- a/tests/001-05-repository_get_workdir.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Check for Git2\Repository::getWorkdir ---SKIPIF-- - ---FILE-- -getWorkdir() == "") { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/001-06-repository_init.phpt b/tests/001-06-repository_init.phpt deleted file mode 100644 index eddec17cb3..0000000000 --- a/tests/001-06-repository_init.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -Check for Git2\Repository::init ---SKIPIF-- - ---FILE-- - ---FILE-- -headDetached()) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/001-08-repository_head_orphen.phpt b/tests/001-08-repository_head_orphen.phpt deleted file mode 100644 index 723526fe7a..0000000000 --- a/tests/001-08-repository_head_orphen.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Check for Git2\Repository::headOrphan ---SKIPIF-- - ---FILE-- -headOrphan()) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/001-09-repository_discover.phpt b/tests/001-09-repository_discover.phpt deleted file mode 100644 index a98adb4ef3..0000000000 --- a/tests/001-09-repository_discover.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Check for Git2\Repository::discover ---SKIPIF-- - ---FILE-- - ---FILE-- -exists("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d")) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} - -if ($repo->exists("unabailablehashid00000000000000000000000")) { - echo "FAIL" . PHP_EOL; -} else { - echo "OK" . PHP_EOL; -} - ---EXPECT-- -OK -OK diff --git a/tests/001-0b-repository_write.phpt b/tests/001-0b-repository_write.phpt deleted file mode 100644 index 8d9345803d..0000000000 --- a/tests/001-0b-repository_write.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -Check for Git2\TreeBuilder::construct ---SKIPIF-- - ---FILE-- -write("Hello World", 3); -echo $oid . PHP_EOL; -echo `GIT_DIR={$path} git cat-file blob 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689` . PHP_EOL; -$blob = $repo->lookup("5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689"); -echo $blob . PHP_EOL; -`rm -rf {$path}`; ---EXPECT-- -5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 -Hello World -Hello World \ No newline at end of file diff --git a/tests/001-0c-repository_hash.phpt b/tests/001-0c-repository_hash.phpt deleted file mode 100644 index a1cb6dfed8..0000000000 --- a/tests/001-0c-repository_hash.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Check for Git2\TreeBuilder::construct ---SKIPIF-- - ---FILE-- -hash("Hello World", 3); -echo $oid . PHP_EOL; -if (!file_exists($path . "/objects/5e/5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689")) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} -`rm -rf {$path}`; ---EXPECT-- -5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 -OK \ No newline at end of file diff --git a/tests/002-01-commit_construct.phpt b/tests/002-01-commit_construct.phpt deleted file mode 100644 index 56ba20a9c7..0000000000 --- a/tests/002-01-commit_construct.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Check for Git2\Commit::construct ---SKIPIF-- - ---FILE-- -lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d"); - -if ($commit instanceof Git2\Commit) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/002-02-commit_parent_count.phpt b/tests/002-02-commit_parent_count.phpt deleted file mode 100644 index 3bb448e5a6..0000000000 --- a/tests/002-02-commit_parent_count.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Check for Git2\Commit::construct ---SKIPIF-- - ---FILE-- -lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d"); - -echo $commit->parentCount(); ---EXPECT-- -0 diff --git a/tests/002-03-commit_get_message.phpt b/tests/002-03-commit_get_message.phpt deleted file mode 100644 index be7b8c109a..0000000000 --- a/tests/002-03-commit_get_message.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Check for Git2\Commit::construct ---SKIPIF-- - ---FILE-- -lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d"); - -echo $commit->getMessage(); ---EXPECT-- -initial commit diff --git a/tests/002-04-commit_get_message_encoding.phpt b/tests/002-04-commit_get_message_encoding.phpt deleted file mode 100644 index ea811da038..0000000000 --- a/tests/002-04-commit_get_message_encoding.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Check for Git2\Commit::construct ---SKIPIF-- - ---FILE-- -lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d"); - -echo $commit->getMessageEncoding(); ---EXPECT-- -UTF-8 diff --git a/tests/002-05-commit_get_author.phpt b/tests/002-05-commit_get_author.phpt deleted file mode 100644 index 5ae5246090..0000000000 --- a/tests/002-05-commit_get_author.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Check for Git2\Commit::getAuthor ---SKIPIF-- - ---FILE-- -lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d"); - -$signature = $commit->getAuthor(); -printf("name: %s\n", $signature->name); -printf("email: %s\n", $signature->email); -printf("time: %s\n", $signature->time->format("Y-m-d H:i:s")); ---EXPECT-- -name: Shuhei Tanuma -email: shuhei.tanuma@gmail.com -time: 2012-01-17 21:50:45 \ No newline at end of file diff --git a/tests/002-06-commit_get_committer.phpt b/tests/002-06-commit_get_committer.phpt deleted file mode 100644 index 91f5e7288a..0000000000 --- a/tests/002-06-commit_get_committer.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Check for Git2\Commit::getCommitter ---SKIPIF-- - ---FILE-- -lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d"); - -$signature = $commit->getCommitter(); -printf("name: %s\n", $signature->name); -printf("email: %s\n", $signature->email); -printf("time: %s\n", $signature->time->format("Y-m-d H:i:s")); ---EXPECT-- -name: Shuhei Tanuma -email: shuhei.tanuma@gmail.com -time: 2012-01-17 21:50:45 \ No newline at end of file diff --git a/tests/002-07-commit_create.phpt b/tests/002-07-commit_create.phpt deleted file mode 100644 index 48e0cc0448..0000000000 --- a/tests/002-07-commit_create.phpt +++ /dev/null @@ -1,50 +0,0 @@ ---TEST-- -Check for Git2\Commit::getCommitter ---SKIPIF-- - ---FILE-- -write("Hello World", 3); - -$author = new Git2\Signature("Shuhei Tanuma","chobieee@gmail.com",new DateTime("@1327164747")); -$committer = new Git2\Signature("Shuhei Tanuma San","chobieee@gmail.com",new DateTime("@1327164747")); -$bld = new Git2\TreeBuilder(); -$bld->insert(new Git2\TreeEntry(array( - "name" => "README.txt", - "oid" => $oid, - "attributes" => octdec('100644'), -))); -$tree = $bld->write($repo); - -$parent = ""; -$parents = array(); -$parent = Git2\Commit::create($repo, array( - "author" => $author, - "committer" => $committer, - "message" => "Hello World", - "tree" => $tree, - "parents" => $parents, -)); - -$commit = $repo->lookup($parent); - -printf("commit_id: %s\n",$parent); -printf("author: %s\n", $commit->getAuthor()->name); -printf("email: %s\n", $commit->getAuthor()->email); -printf("time: %s\n", $commit->getAuthor()->time->getTimestamp()); -echo PHP_EOL; -printf("%s\n", $commit->getMessage()); -`rm -rf {$path}`; ---EXPECT-- -commit_id: 239442d8e6cdbd904e150e25778cc45024b60d51 -author: Shuhei Tanuma -email: chobieee@gmail.com -time: 1327164747 - -Hello World \ No newline at end of file diff --git a/tests/002-08-commit_get_parent_count.phpt b/tests/002-08-commit_get_parent_count.phpt deleted file mode 100644 index 77f145b5f4..0000000000 --- a/tests/002-08-commit_get_parent_count.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Check for Git2\Commit::getCommitter ---SKIPIF-- - ---FILE-- -lookup("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d"); - - -var_dump($commit->getParentCount()); - -$path2 = __DIR__ . '/mock/008-02'; -$repo = new Git2\Repository($path2); -$commit = $repo->lookup("6e20138dc38f9f626107f1cd3ef0f9838c43defe"); - -var_dump($commit->getParentCount()); - ---EXPECT-- -int(0) -int(1) \ No newline at end of file diff --git a/tests/002-09-commit_get_parent.phpt b/tests/002-09-commit_get_parent.phpt deleted file mode 100644 index baf34adb9e..0000000000 --- a/tests/002-09-commit_get_parent.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Check for Git2\Commit::getCommitter ---SKIPIF-- - ---FILE-- -lookup("6e20138dc38f9f626107f1cd3ef0f9838c43defe"); - -$parent = $commit->getParent(); -var_dump($parent->getOid()); -var_dump($parent->getMessage()); ---EXPECT-- -string(40) "9bb8c853c9ea27609a6bdc48b78cd26a320daf7d" -string(16) "added section 1 -" \ No newline at end of file diff --git a/tests/003-01-tree_construct.phpt b/tests/003-01-tree_construct.phpt deleted file mode 100644 index 66330f290a..0000000000 --- a/tests/003-01-tree_construct.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Check for Git2\Tree::construct ---SKIPIF-- - ---FILE-- -lookup("67dc4302383b2715f4e0b8c41840eb05b1873697"); - -if ($tree instanceof Git2\Tree) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/003-02-tree_iterate.phpt b/tests/003-02-tree_iterate.phpt deleted file mode 100644 index dc2eeb19d5..0000000000 --- a/tests/003-02-tree_iterate.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Check for Git2\Tree::construct ---SKIPIF-- - ---FILE-- -lookup("67dc4302383b2715f4e0b8c41840eb05b1873697"); - -foreach ($tree as $entry) { - echo $entry->name . PHP_EOL; - echo $entry->oid . PHP_EOL; - echo $entry->attributes . PHP_EOL; -} ---EXPECT-- -README -557db03de997c86a4a028e1ebd3a1ceb225be238 -33188 \ No newline at end of file diff --git a/tests/003-03-tree_get_subtree.phpt b/tests/003-03-tree_get_subtree.phpt deleted file mode 100644 index 2877be0f5f..0000000000 --- a/tests/003-03-tree_get_subtree.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -Check for Git2\Tree::construct ---SKIPIF-- - ---FILE-- -lookup("451cad1f3affaf6e3159c7c85d9ce9a21e21993d"); - -var_dump($tree->getSubtree("")); -var_dump($tree->getSubtree("a")); -var_dump($tree->getSubtree("a/b")); -var_dump($tree->getSubtree("a/c")); - ---EXPECT-- -bool(false) -object(Git2\Tree)#5 (1) { - ["entries"]=> - array(1) { - [0]=> - object(Git2\TreeEntry)#6 (3) { - ["name"]=> - string(1) "b" - ["oid"]=> - string(40) "a2c260d5a5c3a4b9f4247433b89dd0069fce423f" - ["attributes"]=> - int(16384) - } - } -} -object(Git2\Tree)#5 (1) { - ["entries"]=> - array(1) { - [0]=> - object(Git2\TreeEntry)#6 (3) { - ["name"]=> - string(1) "c" - ["oid"]=> - string(40) "bc2b542422510d8b23eae97ede32dc2d5fa13c90" - ["attributes"]=> - int(16384) - } - } -} -bool(false) \ No newline at end of file diff --git a/tests/003-04-tree_get_entry_by_name.phpt b/tests/003-04-tree_get_entry_by_name.phpt deleted file mode 100644 index 59cd3a203e..0000000000 --- a/tests/003-04-tree_get_entry_by_name.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Check for Git2\Tree::construct ---SKIPIF-- - ---FILE-- -lookup("67dc4302383b2715f4e0b8c41840eb05b1873697"); - -$entry = $tree->getEntryByName("README"); -var_dump($entry); ---EXPECT-- -object(Git2\TreeEntry)#5 (3) { - ["name"]=> - string(6) "README" - ["oid"]=> - string(40) "557db03de997c86a4a028e1ebd3a1ceb225be238" - ["attributes"]=> - int(33188) -} diff --git a/tests/004-01-blob_construct.phpt b/tests/004-01-blob_construct.phpt deleted file mode 100644 index 9db9188144..0000000000 --- a/tests/004-01-blob_construct.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Check for Git2\Blob::construct ---SKIPIF-- - ---FILE-- -lookup("557db03de997c86a4a028e1ebd3a1ceb225be238"); - -if ($blob instanceof Git2\Blob) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -OK diff --git a/tests/004-02-blob___to_string.phpt b/tests/004-02-blob___to_string.phpt deleted file mode 100644 index d38e738e40..0000000000 --- a/tests/004-02-blob___to_string.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Check for Git2\Blob::__toString ---SKIPIF-- - ---FILE-- -lookup("557db03de997c86a4a028e1ebd3a1ceb225be238"); - -if ($blob instanceof Git2\Blob) { - echo $blob->__toString(); -} else { - echo "FAIL" . PHP_EOL; -} ---EXPECT-- -Hello World diff --git a/tests/004-03-blob_create.phpt b/tests/004-03-blob_create.phpt deleted file mode 100644 index 64ccc61a5c..0000000000 --- a/tests/004-03-blob_create.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Check for Git2\Blob::__toString ---SKIPIF-- - ---FILE-- - ---FILE-- -lookup("557db03de997c86a4a028e1ebd3a1ceb225be238"); - -echo $blob->getSize(); ---EXPECT-- -12 \ No newline at end of file diff --git a/tests/005-01-signature___construct.phpt b/tests/005-01-signature___construct.phpt deleted file mode 100644 index 3ed85507a8..0000000000 --- a/tests/005-01-signature___construct.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Check for Git2\Signature::construct ---SKIPIF-- - ---FILE-- -name . PHP_EOL; -echo $sig->email . PHP_EOL; -echo $sig->time->format("Y-m-d H:i:s") . PHP_EOL; - ---EXPECT-- -Shuhei Tanuma -chobieee@gmail.com -2012-01-19 00:32:32 diff --git a/tests/006-01-tree_entry___construct.phpt b/tests/006-01-tree_entry___construct.phpt deleted file mode 100644 index e65779bf50..0000000000 --- a/tests/006-01-tree_entry___construct.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Check for Git2\TreeEntry::construct ---SKIPIF-- - ---FILE-- - "README.txt", - "oid" => "63542fbea05732b78711479a31557bd1b0aa2116", - "attributes" => 33188, -)); - -echo $entry->name . PHP_EOL; -echo $entry->oid . PHP_EOL; -echo $entry->attributes . PHP_EOL; ---EXPECT-- -README.txt -63542fbea05732b78711479a31557bd1b0aa2116 -33188 diff --git a/tests/006-02-tree_entry_is_blob.phpt b/tests/006-02-tree_entry_is_blob.phpt deleted file mode 100644 index 324d3c1111..0000000000 --- a/tests/006-02-tree_entry_is_blob.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Check for Git2\TreeEntry::construct ---SKIPIF-- - ---FILE-- -lookup("199e7c128125a430899fc5c1c0bd08699c9a5692"); -foreach ($tree as $entry) { - if ($entry->isBlob()) { - echo "OK" . PHP_EOL; - } else { - echo "FAIL" . PHP_EOL; - } -} ---EXPECT-- -OK \ No newline at end of file diff --git a/tests/007-01-tree_builder___construct.phpt b/tests/007-01-tree_builder___construct.phpt deleted file mode 100644 index 6d5036fa43..0000000000 --- a/tests/007-01-tree_builder___construct.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Check for Git2\TreeBuilder::construct ---SKIPIF-- - ---FILE-- - ---FILE-- -insert(new Git2\TreeEntry(array( - "name" => "README.txt", - "oid" => "63542fbea05732b78711479a31557bd1b0aa2116", - "attributes" => 33188, -))); -$oid = $bld->write($repo); -echo $oid . PHP_EOL; -if (is_file($path . "/objects/75/b9737032278849da7e57829164a1265911afda")) { - echo "PASS" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} -echo `GIT_DIR={$path} git ls-tree 75b9737032278849da7e57829164a1265911afda`; -`rm -rf {$path}`; ---EXPECT-- -75b9737032278849da7e57829164a1265911afda -PASS -100644 blob 63542fbea05732b78711479a31557bd1b0aa2116 README.txt \ No newline at end of file diff --git a/tests/008-01-walker___construct.phpt b/tests/008-01-walker___construct.phpt deleted file mode 100644 index 37b6dbef08..0000000000 --- a/tests/008-01-walker___construct.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Check for Git2\Walker::construct ---SKIPIF-- - ---FILE-- - ---FILE-- -push("6e20138dc38f9f626107f1cd3ef0f9838c43defe"); - -foreach ($walker as $oid => $commit) { - printf("oid: %s\n", $oid); - printf("message: %s\n", $commit->getMessage()); -} - -echo "==== rewind ====\n\n"; - -foreach ($walker as $oid => $commit) { - printf("oid: %s\n", $oid); - printf("message: %s\n", $commit->getMessage()); -} - ---EXPECT-- -oid: 6e20138dc38f9f626107f1cd3ef0f9838c43defe -message: added section 1 contents - -oid: 9bb8c853c9ea27609a6bdc48b78cd26a320daf7d -message: added section 1 - -oid: 7fce1026cb624448e5a8cf8752bd5e19d8f2cb1f -message: modified README - -oid: ffc6c773865c1342db9cd5df5777fc91ddeb8a4d -message: initial commit - -==== rewind ==== - -oid: 6e20138dc38f9f626107f1cd3ef0f9838c43defe -message: added section 1 contents - -oid: 9bb8c853c9ea27609a6bdc48b78cd26a320daf7d -message: added section 1 - -oid: 7fce1026cb624448e5a8cf8752bd5e19d8f2cb1f -message: modified README - -oid: ffc6c773865c1342db9cd5df5777fc91ddeb8a4d -message: initial commit \ No newline at end of file diff --git a/tests/009-01-reference_lookup.phpt b/tests/009-01-reference_lookup.phpt deleted file mode 100644 index e9d09d7c82..0000000000 --- a/tests/009-01-reference_lookup.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Check for Git2\Reference::lookup ---SKIPIF-- - ---FILE-- -getName() . PHP_EOL; -echo $ref->getTarget() . PHP_EOL; ---EXPECT-- -refs/heads/master -ab68c54212af15d3545c41057e3a8f2f9ff6fd0d \ No newline at end of file diff --git a/tests/009-02-reference_resolve.phpt b/tests/009-02-reference_resolve.phpt deleted file mode 100644 index 3ab162b0e9..0000000000 --- a/tests/009-02-reference_resolve.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Check for Git2\Reference::lookup ---SKIPIF-- - ---FILE-- -getName() . PHP_EOL; -echo $ref->getTarget() . PHP_EOL; -$resolved = $ref->resolve(); -echo $resolved->getName() . PHP_EOL; -echo $resolved->getTarget() . PHP_EOL; ---EXPECT-- -HEAD -refs/heads/master -refs/heads/master -ab68c54212af15d3545c41057e3a8f2f9ff6fd0d \ No newline at end of file diff --git a/tests/00a-01-config___construct.phpt b/tests/00a-01-config___construct.phpt deleted file mode 100644 index d30b4b0c1f..0000000000 --- a/tests/00a-01-config___construct.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Check for Git2\Config::__construct ---SKIPIF-- - ---FILE-- - ---FILE-- -get("core.repositoryformatversion") . PHP_EOL; -echo $config->get("core.filemode") . PHP_EOL; -echo $config->get("core.bare") . PHP_EOL; -echo $config->get("core.ignorecase") . PHP_EOL; -echo ($config->get("core") == array("repositoryformatversion"=>"0","filemode"=>"true","bare"=>"true","ignorecase"=>"true")) ? "OK\n" : "FAIL\n"; -echo ($config->get("") == false) ? "OK\n" : "FAIL\n"; -echo ($config->get("core.uhi") == false) ? "OK\n" : "FAIL\n"; ---EXPECT-- -0 -true -true -true -OK -OK -OK \ No newline at end of file diff --git a/tests/00a-03-config_store.phpt b/tests/00a-03-config_store.phpt deleted file mode 100644 index 15791f2963..0000000000 --- a/tests/00a-03-config_store.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -Check for Git2\Config::get ---SKIPIF-- - ---FILE-- -get("core.bare") . PHP_EOL; -echo $config->store("core.bare",false); -echo $config->get("core.bare") . PHP_EOL; -echo $config->store("core.bare",true); -echo $config->get("core.bare") . PHP_EOL; -echo $config->store("core.bare",false); -echo $config->get("core.bare") . PHP_EOL; -echo $config->store("core.bare",1); -echo $config->get("core.bare") . PHP_EOL; -echo $config->store("core.bare",0); -echo $config->get("core.bare") . PHP_EOL; -echo $config->store("core.bare","1"); -echo $config->get("core.bare") . PHP_EOL; -echo $config->store("core.bare","0"); -echo $config->get("core.bare") . PHP_EOL; -try { -$config->store("core.bare",array()); -echo "FAIL\n"; -} catch (\Exception $e) { -echo "OK\n"; -} -unlink($path); ---EXPECT-- -true -false -true -false -1 -0 -1 -0 -OK \ No newline at end of file diff --git a/tests/00a-04-config_delete.phpt b/tests/00a-04-config_delete.phpt deleted file mode 100644 index 627d15058e..0000000000 --- a/tests/00a-04-config_delete.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -Check for Git2\Config::get ---SKIPIF-- - ---FILE-- -get("core.bare") . PHP_EOL; -$config->delete("core.bare"); -var_dump($config->get("core.bare")); -//for now, recursive delete does not support. -//$config->delete("core"); -//var_dump($config->get("core")); -unlink($path); ---EXPECT-- -true -NULL \ No newline at end of file diff --git a/tests/00a-05-config_dimension_get.phpt b/tests/00a-05-config_dimension_get.phpt deleted file mode 100644 index 35e3c8c425..0000000000 --- a/tests/00a-05-config_dimension_get.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Check for Git2\Config::get ---SKIPIF-- - ---FILE-- -"0","filemode"=>"true","bare"=>"true","ignorecase"=>"true")) ? "OK\n" : "FAIL\n"; -echo ($config[""] == false) ? "OK\n" : "FAIL\n"; -echo ($config["core.uhi"] == false) ? "OK\n" : "FAIL\n"; ---EXPECT-- -0 -true -true -true -OK -OK -OK \ No newline at end of file diff --git a/tests/00a-06-config_dimension_set.phpt b/tests/00a-06-config_dimension_set.phpt deleted file mode 100644 index f8c1b04f04..0000000000 --- a/tests/00a-06-config_dimension_set.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -Check for Git2\Config dimension set ---SKIPIF-- - ---FILE-- - ---FILE-- -odb->hash("Hello World", 3); -echo $oid . PHP_EOL; -if (!file_exists($path . "/objects/5e/5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689")) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} -`rm -rf {$path}`; ---EXPECT-- -5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 -OK \ No newline at end of file diff --git a/tests/00b-02-odb_exists.phpt b/tests/00b-02-odb_exists.phpt deleted file mode 100644 index 6819adfd43..0000000000 --- a/tests/00b-02-odb_exists.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Check for Git2\ODB::exists ---SKIPIF-- - ---FILE-- -odb->exists("ab68c54212af15d3545c41057e3a8f2f9ff6fd0d")) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} - -if ($repo->odb->exists("unabailablehashid00000000000000000000000")) { - echo "FAIL" . PHP_EOL; -} else { - echo "OK" . PHP_EOL; -} - ---EXPECT-- -OK -OK diff --git a/tests/00b-03-odb_write.phpt b/tests/00b-03-odb_write.phpt deleted file mode 100644 index 7f28b9573b..0000000000 --- a/tests/00b-03-odb_write.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -Check for Git2\ODB::write ---SKIPIF-- - ---FILE-- -odb->write("Hello World", 3); -echo $oid . PHP_EOL; -echo `GIT_DIR={$path} git cat-file blob 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689` . PHP_EOL; -$blob = $repo->lookup("5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689"); -echo $blob . PHP_EOL; -`rm -rf {$path}`; ---EXPECT-- -5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 -Hello World -Hello World \ No newline at end of file diff --git a/tests/00b-04-odb_read.phpt b/tests/00b-04-odb_read.phpt deleted file mode 100644 index 1beb5a559e..0000000000 --- a/tests/00b-04-odb_read.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -Check for Git2\ODB::write ---SKIPIF-- - ---FILE-- -odb->write("Hello World", 3); -echo $oid . PHP_EOL; -echo `GIT_DIR={$path} git cat-file blob 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689` . PHP_EOL; -$odbobj = $repo->odb->read("5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689"); -if ($odbobj instanceof Git2\ODBObject) { - echo "OK" . PHP_EOL; -} else { - echo "FAIL" . PHP_EOL; -} -echo $odbobj . PHP_EOL; -`rm -rf {$path}`; ---EXPECT-- -5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 -Hello World -OK -Hello World \ No newline at end of file diff --git a/tests/fixtures/init.php b/tests/fixtures/init.php deleted file mode 100644 index 7874972c94..0000000000 --- a/tests/fixtures/init.php +++ /dev/null @@ -1,56 +0,0 @@ -write("Hello World",3); -$oids[] = $repo->write("Hello Chobie",3); -$oids[] = $repo->write("this is chobie",3); -$oids[] = $repo->write("moe is Japanese word",3); - -foreach ($oids as $oid) { - echo $oid . PHP_EOL; -} - -/* -e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 -a08e8505259a0ab4474ca79ba92bd7912b5a32c3 -87cef34f1a5c8d386418e9fa3e8948ef7322a007 -ca06beddccb5d9eb9bf4787ef42407a438b3abf1 -*/ - -$builder = new Git2\TreeBuilder(); -$builder->insert(new Git2\TreeEntry(array( - "name" => "README", - "oid" => "e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689", - "attributes" => 33188, -))); -$oid = $builder->write($repo); -echo $oid . PHP_EOL; -/* - 199e7c128125a430899fc5c1c0bd08699c9a5692 -*/ - -$builder = new Git2\TreeBuilder(); -$i = 0; -$builder->insert(new Git2\TreeEntry(array( - "name" => "$i", - "oid" => "e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689", - "attributes" => 33188, -))); -$oid = $builder->write($repo); -echo $oid . PHP_EOL; - -/* - 2c83838315fd649b17e968e96e9d4543c9efd1e9 -*/ - -$builder = new Git2\TreeBuilder(); -for($i = 0;$i<1000;$i++){ -$builder->insert(new Git2\TreeEntry(array( - "name" => "$i", - "oid" => "e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689", - "attributes" => 33188, -))); -} -$oid = $builder->write($repo); -echo $oid . PHP_EOL; -// 74edf90112fadb1c0ea2dc48352e0ed4ead2e1cf diff --git a/tests/fixtures/testrepo.git/HEAD b/tests/fixtures/testrepo.git/HEAD deleted file mode 100644 index cb089cd89a..0000000000 --- a/tests/fixtures/testrepo.git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/tests/fixtures/testrepo.git/config b/tests/fixtures/testrepo.git/config deleted file mode 100644 index c53d818dd9..0000000000 --- a/tests/fixtures/testrepo.git/config +++ /dev/null @@ -1,5 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true - ignorecase = true diff --git a/tests/fixtures/testrepo.git/description b/tests/fixtures/testrepo.git/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/fixtures/testrepo.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/fixtures/testrepo.git/info/exclude b/tests/fixtures/testrepo.git/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/fixtures/testrepo.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/fixtures/testrepo.git/objects/19/9e7c128125a430899fc5c1c0bd08699c9a5692 b/tests/fixtures/testrepo.git/objects/19/9e7c128125a430899fc5c1c0bd08699c9a5692 deleted file mode 100644 index 366d5f7413c945c32dac8ccaa51c97f425b5fc60..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 51 zcmbK&-#Ubrb&N~mbJ4kUmTZvjD)5VqjumU~Cv@kWf)E))wX-f?9G82Hh2i}+zIOnJ Ci4xKP diff --git a/tests/fixtures/testrepo.git/objects/5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 b/tests/fixtures/testrepo.git/objects/5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 deleted file mode 100644 index 8a119c8c0c3e2c12d2e55eaa5b45b9bcd5faca14..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27 jcmb5Wvq0T%Fru$S3y$Q! z!3*7ZY{9|^NLdWo(J;AH&_2?2o3Zv-=;#uNu%FX! zDMN$|LT$hO(S0^aS$CVUUzIJ=kre{B0QY>$1T{Awo_Y5a%^$7L6ISttj>PxR0s6FZoaEhELa6kH z<90R$qG{+ut6X)kjUYR{$ANiKzwVj!EzDefaCWCHDE9{_am^)mV$tFV)b~1A+ne3R zAM&Aq?sTXClue}x4S5R*I~)qw4zb#{#dH*Rhe~UCOs;s5o#^9HlSWHI>wPKBdE`p) z*IJ&=Fzrjx$RCo_c9wmwkxxC&=ZbAFwB{R==?V)!p15y959Dw$pFSf*wNguofL7nc znOUQ)`balPEK!ijy01(XW~<@6Glg$+4Y%q5W*btm)!iMGA9Cs3oO{WCym$FUoApTN zyRJ`Pdz6o&oTOdiZ6(Fc6^r*sTjXz|gNjx`WT15jZPx(*nZkhu(OcwG(EusV&blAP z8ryW_=J3g#{hHQ~I=;Vppn-GrhU|S-WT&RWu%3gN-fhWpaIvQYplYoMY^l$3e~I8y zE3zOaor{>DjU4#7OCE&|;)+A0FrY}syUeVtNY4sh2`SE(!l1zb-$U+XVK<%X7CO*x z?H#R(#Geq+D{}hw9h-XE0`$zqBmne(4ZkPHDJUsj5kuBI0IIXAKi z0>48Pcn399Gkhp1v=ZJiQXC94yyiNyO!$lEU_6M$*6u=A7m4>uJLG|m0CVIDLv<%Plkq1Sb0ndoxEVLXVHu?>PSpi@R53xN1`xi31cNE|GM z0R?stsSuUM-UGPOBN&lW$KRetB?lC1sg*3F>_An)(Hhx?ys?USjCrx}18u1_%U1nC+{Mbtbo`cAOhC^aUVelxkhF0SY>e zD-M;a4V4FlPALq&Ykc-<-^M0Sjg500J^aZRsaA1 diff --git a/tests/fixtures/testrepo.git/objects/ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 b/tests/fixtures/testrepo.git/objects/ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 deleted file mode 100644 index 89f87a6d666ebe4a8f9e21fb6bd65d84b4aadb3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 36 scmb\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/tests/mock/001-01/hooks/post-commit.sample b/tests/mock/001-01/hooks/post-commit.sample deleted file mode 100755 index 22668216a3..0000000000 --- a/tests/mock/001-01/hooks/post-commit.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script that is called after a successful -# commit is made. -# -# To enable this hook, rename this file to "post-commit". - -: Nothing diff --git a/tests/mock/001-01/hooks/post-receive.sample b/tests/mock/001-01/hooks/post-receive.sample deleted file mode 100755 index 7a83e17ab5..0000000000 --- a/tests/mock/001-01/hooks/post-receive.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script for the "post-receive" event. -# -# The "post-receive" script is run after receive-pack has accepted a pack -# and the repository has been updated. It is passed arguments in through -# stdin in the form -# -# For example: -# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master -# -# see contrib/hooks/ for a sample, or uncomment the next line and -# rename the file to "post-receive". - -#. /usr/share/doc/git-core/contrib/hooks/post-receive-email diff --git a/tests/mock/001-01/hooks/post-update.sample b/tests/mock/001-01/hooks/post-update.sample deleted file mode 100755 index ec17ec1939..0000000000 --- a/tests/mock/001-01/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/tests/mock/001-01/hooks/pre-applypatch.sample b/tests/mock/001-01/hooks/pre-applypatch.sample deleted file mode 100755 index b1f187c2e9..0000000000 --- a/tests/mock/001-01/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} -: diff --git a/tests/mock/001-01/hooks/pre-commit.sample b/tests/mock/001-01/hooks/pre-commit.sample deleted file mode 100755 index b187c4bb1f..0000000000 --- a/tests/mock/001-01/hooks/pre-commit.sample +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -# If you want to allow non-ascii filenames set this variable to true. -allownonascii=$(git config hooks.allownonascii) - -# Cross platform projects tend to avoid non-ascii filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test "$(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0')" -then - echo "Error: Attempt to add a non-ascii file name." - echo - echo "This can cause problems if you want to work" - echo "with people on other platforms." - echo - echo "To be portable it is advisable to rename the file ..." - echo - echo "If you know what you are doing you can disable this" - echo "check using:" - echo - echo " git config hooks.allownonascii true" - echo - exit 1 -fi - -exec git diff-index --check --cached $against -- diff --git a/tests/mock/001-01/hooks/pre-rebase.sample b/tests/mock/001-01/hooks/pre-rebase.sample deleted file mode 100755 index 9773ed4cb2..0000000000 --- a/tests/mock/001-01/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up-to-date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -exit 0 - -################################################################ - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". diff --git a/tests/mock/001-01/hooks/prepare-commit-msg.sample b/tests/mock/001-01/hooks/prepare-commit-msg.sample deleted file mode 100755 index f093a02ec4..0000000000 --- a/tests/mock/001-01/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first comments out the -# "Conflicts:" part of a merge commit. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -case "$2,$3" in - merge,) - /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; - -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; - - *) ;; -esac - -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" diff --git a/tests/mock/001-01/hooks/update.sample b/tests/mock/001-01/hooks/update.sample deleted file mode 100755 index 71ab04edc0..0000000000 --- a/tests/mock/001-01/hooks/update.sample +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# -# An example hook script to blocks unannotated tags from entering. -# Called by "git receive-pack" with arguments: refname sha1-old sha1-new -# -# To enable this hook, rename this file to "update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowmodifytag -# This boolean sets whether a tag may be modified after creation. By default -# it won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# hooks.denycreatebranch -# This boolean sets whether remotely creating branches will be denied -# in the repository. By default this is allowed. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "Usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --bool hooks.allowunannotated) -allowdeletebranch=$(git config --bool hooks.allowdeletebranch) -denycreatebranch=$(git config --bool hooks.denycreatebranch) -allowdeletetag=$(git config --bool hooks.allowdeletetag) -allowmodifytag=$(git config --bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero="0000000000000000000000000000000000000000" -if [ "$newrev" = "$zero" ]; then - newrev_type=delete -else - newrev_type=$(git cat-file -t $newrev) -fi - -case "$refname","$newrev_type" in - refs/tags/*,commit) - # un-annotated tag - short_refname=${refname##refs/tags/} - if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/tests/mock/001-01/info/exclude b/tests/mock/001-01/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/mock/001-01/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/mock/001-01/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238 b/tests/mock/001-01/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238 deleted file mode 100644 index 2cbc51b51fb979c066ffe2dcc2ba90f5a1dd3037..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28 kcmb4V4FlPAMD&g-A@e8|M$c#+K$0JRnj3IG5A diff --git a/tests/mock/001-01/objects/67/dc4302383b2715f4e0b8c41840eb05b1873697 b/tests/mock/001-01/objects/67/dc4302383b2715f4e0b8c41840eb05b1873697 deleted file mode 100644 index 527a79413fa02d9ad9a8daa130f35eb8127151d4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 51 zcmbN1XJbq1#@eXx<)nG(jL|18y~Z5TMCl#b*@-Z?^bPK1lw9Ev*3kl7J_k;G;O*T) mU8dCA6(lL^$)PrI#u-uUb{}*8BO&TqxrPOPE%6232|ni^@jwXx diff --git a/tests/mock/001-01/packed-refs b/tests/mock/001-01/packed-refs deleted file mode 100644 index 1fc364da10..0000000000 --- a/tests/mock/001-01/packed-refs +++ /dev/null @@ -1,2 +0,0 @@ -# pack-refs with: peeled -ab68c54212af15d3545c41057e3a8f2f9ff6fd0d refs/heads/master diff --git a/tests/mock/001-01/refs/heads/.gitkeep b/tests/mock/001-01/refs/heads/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/mock/001-02/HEAD b/tests/mock/001-02/HEAD deleted file mode 100644 index cb089cd89a..0000000000 --- a/tests/mock/001-02/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/tests/mock/001-02/config b/tests/mock/001-02/config deleted file mode 100644 index cb3402cf5d..0000000000 --- a/tests/mock/001-02/config +++ /dev/null @@ -1,7 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true - ignorecase = true -[remote "origin"] - url = /Users/chobie/src/php-git2/tests/mock/tmp diff --git a/tests/mock/001-02/description b/tests/mock/001-02/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/mock/001-02/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/mock/001-02/hooks/applypatch-msg.sample b/tests/mock/001-02/hooks/applypatch-msg.sample deleted file mode 100755 index 8b2a2fe84f..0000000000 --- a/tests/mock/001-02/hooks/applypatch-msg.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message taken by -# applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. The hook is -# allowed to edit the commit message file. -# -# To enable this hook, rename this file to "applypatch-msg". - -. git-sh-setup -test -x "$GIT_DIR/hooks/commit-msg" && - exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} -: diff --git a/tests/mock/001-02/hooks/commit-msg.sample b/tests/mock/001-02/hooks/commit-msg.sample deleted file mode 100755 index b58d1184a9..0000000000 --- a/tests/mock/001-02/hooks/commit-msg.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message. -# Called by "git commit" with one argument, the name of the file -# that has the commit message. The hook should exit with non-zero -# status after issuing an appropriate message if it wants to stop the -# commit. The hook is allowed to edit the commit message file. -# -# To enable this hook, rename this file to "commit-msg". - -# Uncomment the below to add a Signed-off-by line to the message. -# Doing this in a hook is a bad idea in general, but the prepare-commit-msg -# hook is more suited to it. -# -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/tests/mock/001-02/hooks/post-commit.sample b/tests/mock/001-02/hooks/post-commit.sample deleted file mode 100755 index 22668216a3..0000000000 --- a/tests/mock/001-02/hooks/post-commit.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script that is called after a successful -# commit is made. -# -# To enable this hook, rename this file to "post-commit". - -: Nothing diff --git a/tests/mock/001-02/hooks/post-receive.sample b/tests/mock/001-02/hooks/post-receive.sample deleted file mode 100755 index 7a83e17ab5..0000000000 --- a/tests/mock/001-02/hooks/post-receive.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script for the "post-receive" event. -# -# The "post-receive" script is run after receive-pack has accepted a pack -# and the repository has been updated. It is passed arguments in through -# stdin in the form -# -# For example: -# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master -# -# see contrib/hooks/ for a sample, or uncomment the next line and -# rename the file to "post-receive". - -#. /usr/share/doc/git-core/contrib/hooks/post-receive-email diff --git a/tests/mock/001-02/hooks/post-update.sample b/tests/mock/001-02/hooks/post-update.sample deleted file mode 100755 index ec17ec1939..0000000000 --- a/tests/mock/001-02/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/tests/mock/001-02/hooks/pre-applypatch.sample b/tests/mock/001-02/hooks/pre-applypatch.sample deleted file mode 100755 index b1f187c2e9..0000000000 --- a/tests/mock/001-02/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} -: diff --git a/tests/mock/001-02/hooks/pre-commit.sample b/tests/mock/001-02/hooks/pre-commit.sample deleted file mode 100755 index b187c4bb1f..0000000000 --- a/tests/mock/001-02/hooks/pre-commit.sample +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -# If you want to allow non-ascii filenames set this variable to true. -allownonascii=$(git config hooks.allownonascii) - -# Cross platform projects tend to avoid non-ascii filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test "$(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0')" -then - echo "Error: Attempt to add a non-ascii file name." - echo - echo "This can cause problems if you want to work" - echo "with people on other platforms." - echo - echo "To be portable it is advisable to rename the file ..." - echo - echo "If you know what you are doing you can disable this" - echo "check using:" - echo - echo " git config hooks.allownonascii true" - echo - exit 1 -fi - -exec git diff-index --check --cached $against -- diff --git a/tests/mock/001-02/hooks/pre-rebase.sample b/tests/mock/001-02/hooks/pre-rebase.sample deleted file mode 100755 index 9773ed4cb2..0000000000 --- a/tests/mock/001-02/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up-to-date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -exit 0 - -################################################################ - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". diff --git a/tests/mock/001-02/hooks/prepare-commit-msg.sample b/tests/mock/001-02/hooks/prepare-commit-msg.sample deleted file mode 100755 index f093a02ec4..0000000000 --- a/tests/mock/001-02/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first comments out the -# "Conflicts:" part of a merge commit. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -case "$2,$3" in - merge,) - /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; - -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; - - *) ;; -esac - -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" diff --git a/tests/mock/001-02/hooks/update.sample b/tests/mock/001-02/hooks/update.sample deleted file mode 100755 index 71ab04edc0..0000000000 --- a/tests/mock/001-02/hooks/update.sample +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# -# An example hook script to blocks unannotated tags from entering. -# Called by "git receive-pack" with arguments: refname sha1-old sha1-new -# -# To enable this hook, rename this file to "update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowmodifytag -# This boolean sets whether a tag may be modified after creation. By default -# it won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# hooks.denycreatebranch -# This boolean sets whether remotely creating branches will be denied -# in the repository. By default this is allowed. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "Usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --bool hooks.allowunannotated) -allowdeletebranch=$(git config --bool hooks.allowdeletebranch) -denycreatebranch=$(git config --bool hooks.denycreatebranch) -allowdeletetag=$(git config --bool hooks.allowdeletetag) -allowmodifytag=$(git config --bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero="0000000000000000000000000000000000000000" -if [ "$newrev" = "$zero" ]; then - newrev_type=delete -else - newrev_type=$(git cat-file -t $newrev) -fi - -case "$refname","$newrev_type" in - refs/tags/*,commit) - # un-annotated tag - short_refname=${refname##refs/tags/} - if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/tests/mock/001-02/info/exclude b/tests/mock/001-02/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/mock/001-02/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/mock/001-02/objects/info/.gitkeep b/tests/mock/001-02/objects/info/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/mock/001-02/objects/pack/.gitkeep b/tests/mock/001-02/objects/pack/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/mock/001-02/packed-refs b/tests/mock/001-02/packed-refs deleted file mode 100644 index 1fc364da10..0000000000 --- a/tests/mock/001-02/packed-refs +++ /dev/null @@ -1,2 +0,0 @@ -# pack-refs with: peeled -ab68c54212af15d3545c41057e3a8f2f9ff6fd0d refs/heads/master diff --git a/tests/mock/001-02/refs/heads/.gitkeep b/tests/mock/001-02/refs/heads/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/mock/001-07/detached/HEAD b/tests/mock/001-07/detached/HEAD deleted file mode 100644 index 7a87492286..0000000000 --- a/tests/mock/001-07/detached/HEAD +++ /dev/null @@ -1 +0,0 @@ -66d2a2155270b1021c0fdc764c34e13801bd4ae4 diff --git a/tests/mock/001-07/detached/config b/tests/mock/001-07/detached/config deleted file mode 100644 index 07cb01e2c2..0000000000 --- a/tests/mock/001-07/detached/config +++ /dev/null @@ -1,7 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true - ignorecase = true -[remote "origin"] - url = /Users/chobie/src/php-git2/tests/mock/001-07/a diff --git a/tests/mock/001-07/detached/description b/tests/mock/001-07/detached/description deleted file mode 100644 index 498b267a8c..0000000000 --- a/tests/mock/001-07/detached/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/mock/001-07/detached/hooks/applypatch-msg.sample b/tests/mock/001-07/detached/hooks/applypatch-msg.sample deleted file mode 100755 index 8b2a2fe84f..0000000000 --- a/tests/mock/001-07/detached/hooks/applypatch-msg.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message taken by -# applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. The hook is -# allowed to edit the commit message file. -# -# To enable this hook, rename this file to "applypatch-msg". - -. git-sh-setup -test -x "$GIT_DIR/hooks/commit-msg" && - exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} -: diff --git a/tests/mock/001-07/detached/hooks/commit-msg.sample b/tests/mock/001-07/detached/hooks/commit-msg.sample deleted file mode 100755 index b58d1184a9..0000000000 --- a/tests/mock/001-07/detached/hooks/commit-msg.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message. -# Called by "git commit" with one argument, the name of the file -# that has the commit message. The hook should exit with non-zero -# status after issuing an appropriate message if it wants to stop the -# commit. The hook is allowed to edit the commit message file. -# -# To enable this hook, rename this file to "commit-msg". - -# Uncomment the below to add a Signed-off-by line to the message. -# Doing this in a hook is a bad idea in general, but the prepare-commit-msg -# hook is more suited to it. -# -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/tests/mock/001-07/detached/hooks/post-commit.sample b/tests/mock/001-07/detached/hooks/post-commit.sample deleted file mode 100755 index 22668216a3..0000000000 --- a/tests/mock/001-07/detached/hooks/post-commit.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script that is called after a successful -# commit is made. -# -# To enable this hook, rename this file to "post-commit". - -: Nothing diff --git a/tests/mock/001-07/detached/hooks/post-receive.sample b/tests/mock/001-07/detached/hooks/post-receive.sample deleted file mode 100755 index 7a83e17ab5..0000000000 --- a/tests/mock/001-07/detached/hooks/post-receive.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script for the "post-receive" event. -# -# The "post-receive" script is run after receive-pack has accepted a pack -# and the repository has been updated. It is passed arguments in through -# stdin in the form -# -# For example: -# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master -# -# see contrib/hooks/ for a sample, or uncomment the next line and -# rename the file to "post-receive". - -#. /usr/share/doc/git-core/contrib/hooks/post-receive-email diff --git a/tests/mock/001-07/detached/hooks/post-update.sample b/tests/mock/001-07/detached/hooks/post-update.sample deleted file mode 100755 index ec17ec1939..0000000000 --- a/tests/mock/001-07/detached/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/tests/mock/001-07/detached/hooks/pre-applypatch.sample b/tests/mock/001-07/detached/hooks/pre-applypatch.sample deleted file mode 100755 index b1f187c2e9..0000000000 --- a/tests/mock/001-07/detached/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} -: diff --git a/tests/mock/001-07/detached/hooks/pre-commit.sample b/tests/mock/001-07/detached/hooks/pre-commit.sample deleted file mode 100755 index b187c4bb1f..0000000000 --- a/tests/mock/001-07/detached/hooks/pre-commit.sample +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -# If you want to allow non-ascii filenames set this variable to true. -allownonascii=$(git config hooks.allownonascii) - -# Cross platform projects tend to avoid non-ascii filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test "$(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0')" -then - echo "Error: Attempt to add a non-ascii file name." - echo - echo "This can cause problems if you want to work" - echo "with people on other platforms." - echo - echo "To be portable it is advisable to rename the file ..." - echo - echo "If you know what you are doing you can disable this" - echo "check using:" - echo - echo " git config hooks.allownonascii true" - echo - exit 1 -fi - -exec git diff-index --check --cached $against -- diff --git a/tests/mock/001-07/detached/hooks/pre-rebase.sample b/tests/mock/001-07/detached/hooks/pre-rebase.sample deleted file mode 100755 index 9773ed4cb2..0000000000 --- a/tests/mock/001-07/detached/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up-to-date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -exit 0 - -################################################################ - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". diff --git a/tests/mock/001-07/detached/hooks/prepare-commit-msg.sample b/tests/mock/001-07/detached/hooks/prepare-commit-msg.sample deleted file mode 100755 index f093a02ec4..0000000000 --- a/tests/mock/001-07/detached/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first comments out the -# "Conflicts:" part of a merge commit. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -case "$2,$3" in - merge,) - /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; - -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; - - *) ;; -esac - -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" diff --git a/tests/mock/001-07/detached/hooks/update.sample b/tests/mock/001-07/detached/hooks/update.sample deleted file mode 100755 index 71ab04edc0..0000000000 --- a/tests/mock/001-07/detached/hooks/update.sample +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# -# An example hook script to blocks unannotated tags from entering. -# Called by "git receive-pack" with arguments: refname sha1-old sha1-new -# -# To enable this hook, rename this file to "update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowmodifytag -# This boolean sets whether a tag may be modified after creation. By default -# it won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# hooks.denycreatebranch -# This boolean sets whether remotely creating branches will be denied -# in the repository. By default this is allowed. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "Usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --bool hooks.allowunannotated) -allowdeletebranch=$(git config --bool hooks.allowdeletebranch) -denycreatebranch=$(git config --bool hooks.denycreatebranch) -allowdeletetag=$(git config --bool hooks.allowdeletetag) -allowmodifytag=$(git config --bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero="0000000000000000000000000000000000000000" -if [ "$newrev" = "$zero" ]; then - newrev_type=delete -else - newrev_type=$(git cat-file -t $newrev) -fi - -case "$refname","$newrev_type" in - refs/tags/*,commit) - # un-annotated tag - short_refname=${refname##refs/tags/} - if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/tests/mock/001-07/detached/info/exclude b/tests/mock/001-07/detached/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/mock/001-07/detached/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/mock/001-07/detached/objects/66/d2a2155270b1021c0fdc764c34e13801bd4ae4 b/tests/mock/001-07/detached/objects/66/d2a2155270b1021c0fdc764c34e13801bd4ae4 deleted file mode 100644 index d5a5500472e653cc2f43d689206826540d9438dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 140 zcmV;70CWF%0i}&i3c@fDMqTF=vlq(5=}!V8-a#)gO-2(iM$+lR+go}CHxJ%hd|#-g zWCiQpL7NCn6dv5uJPzz^B=o&_K_4OxGfft0bdNyT8(uZl2Dh{($#CcQS{TmDuAT0B ueHPBIF4S@XOQ+Ed8zwlSM>JdAj#d7cFj164k_b&cb;(-W*Zcs8t3jV^0X_x* diff --git a/tests/mock/001-07/detached/objects/73/cfa43b65a81d3094e9e09cd05b3710368fc304 b/tests/mock/001-07/detached/objects/73/cfa43b65a81d3094e9e09cd05b3710368fc304 deleted file mode 100644 index 1755500b6f2111ed871c09aaf3f485b41c99c322..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 51 zcmb\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/tests/mock/001-08/orphaned/hooks/post-commit.sample b/tests/mock/001-08/orphaned/hooks/post-commit.sample deleted file mode 100755 index 22668216a3..0000000000 --- a/tests/mock/001-08/orphaned/hooks/post-commit.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script that is called after a successful -# commit is made. -# -# To enable this hook, rename this file to "post-commit". - -: Nothing diff --git a/tests/mock/001-08/orphaned/hooks/post-receive.sample b/tests/mock/001-08/orphaned/hooks/post-receive.sample deleted file mode 100755 index 7a83e17ab5..0000000000 --- a/tests/mock/001-08/orphaned/hooks/post-receive.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script for the "post-receive" event. -# -# The "post-receive" script is run after receive-pack has accepted a pack -# and the repository has been updated. It is passed arguments in through -# stdin in the form -# -# For example: -# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master -# -# see contrib/hooks/ for a sample, or uncomment the next line and -# rename the file to "post-receive". - -#. /usr/share/doc/git-core/contrib/hooks/post-receive-email diff --git a/tests/mock/001-08/orphaned/hooks/post-update.sample b/tests/mock/001-08/orphaned/hooks/post-update.sample deleted file mode 100755 index ec17ec1939..0000000000 --- a/tests/mock/001-08/orphaned/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/tests/mock/001-08/orphaned/hooks/pre-applypatch.sample b/tests/mock/001-08/orphaned/hooks/pre-applypatch.sample deleted file mode 100755 index b1f187c2e9..0000000000 --- a/tests/mock/001-08/orphaned/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} -: diff --git a/tests/mock/001-08/orphaned/hooks/pre-commit.sample b/tests/mock/001-08/orphaned/hooks/pre-commit.sample deleted file mode 100755 index b187c4bb1f..0000000000 --- a/tests/mock/001-08/orphaned/hooks/pre-commit.sample +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -# If you want to allow non-ascii filenames set this variable to true. -allownonascii=$(git config hooks.allownonascii) - -# Cross platform projects tend to avoid non-ascii filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test "$(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0')" -then - echo "Error: Attempt to add a non-ascii file name." - echo - echo "This can cause problems if you want to work" - echo "with people on other platforms." - echo - echo "To be portable it is advisable to rename the file ..." - echo - echo "If you know what you are doing you can disable this" - echo "check using:" - echo - echo " git config hooks.allownonascii true" - echo - exit 1 -fi - -exec git diff-index --check --cached $against -- diff --git a/tests/mock/001-08/orphaned/hooks/pre-rebase.sample b/tests/mock/001-08/orphaned/hooks/pre-rebase.sample deleted file mode 100755 index 9773ed4cb2..0000000000 --- a/tests/mock/001-08/orphaned/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up-to-date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -exit 0 - -################################################################ - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". diff --git a/tests/mock/001-08/orphaned/hooks/prepare-commit-msg.sample b/tests/mock/001-08/orphaned/hooks/prepare-commit-msg.sample deleted file mode 100755 index f093a02ec4..0000000000 --- a/tests/mock/001-08/orphaned/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first comments out the -# "Conflicts:" part of a merge commit. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -case "$2,$3" in - merge,) - /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; - -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; - - *) ;; -esac - -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" diff --git a/tests/mock/001-08/orphaned/hooks/update.sample b/tests/mock/001-08/orphaned/hooks/update.sample deleted file mode 100755 index 71ab04edc0..0000000000 --- a/tests/mock/001-08/orphaned/hooks/update.sample +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# -# An example hook script to blocks unannotated tags from entering. -# Called by "git receive-pack" with arguments: refname sha1-old sha1-new -# -# To enable this hook, rename this file to "update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowmodifytag -# This boolean sets whether a tag may be modified after creation. By default -# it won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# hooks.denycreatebranch -# This boolean sets whether remotely creating branches will be denied -# in the repository. By default this is allowed. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "Usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --bool hooks.allowunannotated) -allowdeletebranch=$(git config --bool hooks.allowdeletebranch) -denycreatebranch=$(git config --bool hooks.denycreatebranch) -allowdeletetag=$(git config --bool hooks.allowdeletetag) -allowmodifytag=$(git config --bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero="0000000000000000000000000000000000000000" -if [ "$newrev" = "$zero" ]; then - newrev_type=delete -else - newrev_type=$(git cat-file -t $newrev) -fi - -case "$refname","$newrev_type" in - refs/tags/*,commit) - # un-annotated tag - short_refname=${refname##refs/tags/} - if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/tests/mock/001-08/orphaned/info/exclude b/tests/mock/001-08/orphaned/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/mock/001-08/orphaned/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/mock/001-08/orphaned/objects/66/d2a2155270b1021c0fdc764c34e13801bd4ae4 b/tests/mock/001-08/orphaned/objects/66/d2a2155270b1021c0fdc764c34e13801bd4ae4 deleted file mode 100644 index d5a5500472e653cc2f43d689206826540d9438dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 140 zcmV;70CWF%0i}&i3c@fDMqTF=vlq(5=}!V8-a#)gO-2(iM$+lR+go}CHxJ%hd|#-g zWCiQpL7NCn6dv5uJPzz^B=o&_K_4OxGfft0bdNyT8(uZl2Dh{($#CcQS{TmDuAT0B ueHPBIF4S@XOQ+Ed8zwlSM>JdAj#d7cFj164k_b&cb;(-W*Zcs8t3jV^0X_x* diff --git a/tests/mock/001-08/orphaned/objects/73/cfa43b65a81d3094e9e09cd05b3710368fc304 b/tests/mock/001-08/orphaned/objects/73/cfa43b65a81d3094e9e09cd05b3710368fc304 deleted file mode 100644 index 1755500b6f2111ed871c09aaf3f485b41c99c322..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 51 zcmb\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/tests/mock/003-03/hooks/post-commit.sample b/tests/mock/003-03/hooks/post-commit.sample deleted file mode 100755 index 22668216a3..0000000000 --- a/tests/mock/003-03/hooks/post-commit.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script that is called after a successful -# commit is made. -# -# To enable this hook, rename this file to "post-commit". - -: Nothing diff --git a/tests/mock/003-03/hooks/post-receive.sample b/tests/mock/003-03/hooks/post-receive.sample deleted file mode 100755 index 7a83e17ab5..0000000000 --- a/tests/mock/003-03/hooks/post-receive.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script for the "post-receive" event. -# -# The "post-receive" script is run after receive-pack has accepted a pack -# and the repository has been updated. It is passed arguments in through -# stdin in the form -# -# For example: -# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master -# -# see contrib/hooks/ for a sample, or uncomment the next line and -# rename the file to "post-receive". - -#. /usr/share/doc/git-core/contrib/hooks/post-receive-email diff --git a/tests/mock/003-03/hooks/post-update.sample b/tests/mock/003-03/hooks/post-update.sample deleted file mode 100755 index ec17ec1939..0000000000 --- a/tests/mock/003-03/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/tests/mock/003-03/hooks/pre-applypatch.sample b/tests/mock/003-03/hooks/pre-applypatch.sample deleted file mode 100755 index b1f187c2e9..0000000000 --- a/tests/mock/003-03/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} -: diff --git a/tests/mock/003-03/hooks/pre-commit.sample b/tests/mock/003-03/hooks/pre-commit.sample deleted file mode 100755 index b187c4bb1f..0000000000 --- a/tests/mock/003-03/hooks/pre-commit.sample +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 -fi - -# If you want to allow non-ascii filenames set this variable to true. -allownonascii=$(git config hooks.allownonascii) - -# Cross platform projects tend to avoid non-ascii filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test "$(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0')" -then - echo "Error: Attempt to add a non-ascii file name." - echo - echo "This can cause problems if you want to work" - echo "with people on other platforms." - echo - echo "To be portable it is advisable to rename the file ..." - echo - echo "If you know what you are doing you can disable this" - echo "check using:" - echo - echo " git config hooks.allownonascii true" - echo - exit 1 -fi - -exec git diff-index --check --cached $against -- diff --git a/tests/mock/003-03/hooks/pre-rebase.sample b/tests/mock/003-03/hooks/pre-rebase.sample deleted file mode 100755 index 9773ed4cb2..0000000000 --- a/tests/mock/003-03/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up-to-date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -exit 0 - -################################################################ - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". diff --git a/tests/mock/003-03/hooks/prepare-commit-msg.sample b/tests/mock/003-03/hooks/prepare-commit-msg.sample deleted file mode 100755 index f093a02ec4..0000000000 --- a/tests/mock/003-03/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first comments out the -# "Conflicts:" part of a merge commit. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -case "$2,$3" in - merge,) - /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; - -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$1" ;; - - *) ;; -esac - -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" diff --git a/tests/mock/003-03/hooks/update.sample b/tests/mock/003-03/hooks/update.sample deleted file mode 100755 index 71ab04edc0..0000000000 --- a/tests/mock/003-03/hooks/update.sample +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# -# An example hook script to blocks unannotated tags from entering. -# Called by "git receive-pack" with arguments: refname sha1-old sha1-new -# -# To enable this hook, rename this file to "update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowmodifytag -# This boolean sets whether a tag may be modified after creation. By default -# it won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# hooks.denycreatebranch -# This boolean sets whether remotely creating branches will be denied -# in the repository. By default this is allowed. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "Usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --bool hooks.allowunannotated) -allowdeletebranch=$(git config --bool hooks.allowdeletebranch) -denycreatebranch=$(git config --bool hooks.denycreatebranch) -allowdeletetag=$(git config --bool hooks.allowdeletetag) -allowmodifytag=$(git config --bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero="0000000000000000000000000000000000000000" -if [ "$newrev" = "$zero" ]; then - newrev_type=delete -else - newrev_type=$(git cat-file -t $newrev) -fi - -case "$refname","$newrev_type" in - refs/tags/*,commit) - # un-annotated tag - short_refname=${refname##refs/tags/} - if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/tests/mock/003-03/index b/tests/mock/003-03/index deleted file mode 100644 index f2229422a64a79fa33363c1722cec23373962bfe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 120 zcmZ?q402{*U|<4bMt|=zGa$_Xqxpd1%t58s85kOu0HwbIr9?pT&*nawz3JjLXYX#! zb>&ev4n64!p2#4QsGp>tte>Kvs-LE>m!4UYotjzzQq91?!@J=^ep%uge$|UfYZ-6t JTA;ILI{?@5BbNXG diff --git a/tests/mock/003-03/info/exclude b/tests/mock/003-03/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/mock/003-03/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/mock/003-03/logs/HEAD b/tests/mock/003-03/logs/HEAD deleted file mode 100644 index 3599cf1f61..0000000000 --- a/tests/mock/003-03/logs/HEAD +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 cb50e7dc3b7b52daf18d8bd62e158467236f47bb Shuhei Tanuma 1330345544 +0900 commit (initial): add deep directory entry diff --git a/tests/mock/003-03/logs/refs/heads/master b/tests/mock/003-03/logs/refs/heads/master deleted file mode 100644 index 3599cf1f61..0000000000 --- a/tests/mock/003-03/logs/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 cb50e7dc3b7b52daf18d8bd62e158467236f47bb Shuhei Tanuma 1330345544 +0900 commit (initial): add deep directory entry diff --git a/tests/mock/003-03/objects/45/1cad1f3affaf6e3159c7c85d9ce9a21e21993d b/tests/mock/003-03/objects/45/1cad1f3affaf6e3159c7c85d9ce9a21e21993d deleted file mode 100644 index b6fa0869db068e152accf45a5451b4ddb3239c1f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 43 zcmb)5U|`6=)aud}y7Fn)>iNfKJaMthv^(_IEaK$y&CCo}<9Lk$X4Mh5 diff --git a/tests/mock/003-03/objects/83/32251b41aef6ef2f6ef3624e7879affc4fdc70 b/tests/mock/003-03/objects/83/32251b41aef6ef2f6ef3624e7879affc4fdc70 deleted file mode 100644 index 60e0ca6a272c3ee13e2359c4a090d981e381d131..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 44 zcmb)5U|`6=)Ed(Ea{c18BQ}P!(hKyGHhsL~{JKn3wvM0Su_eDf0BThb A-2eap diff --git a/tests/mock/003-03/objects/97/eb5a985ce4329e30ce5893339dc2aeba72c3ef b/tests/mock/003-03/objects/97/eb5a985ce4329e30ce5893339dc2aeba72c3ef deleted file mode 100644 index 21a674f693876a4a25c6202ceeb0161c84c96034..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 43 zcmV+`0M!3@0V^p=O;s?mU@$QN0);e&t0@=u*xnSMlriaOoH^SW!Q5!EH~`#U46Ih| B5vKqE diff --git a/tests/mock/003-03/objects/a2/c260d5a5c3a4b9f4247433b89dd0069fce423f b/tests/mock/003-03/objects/a2/c260d5a5c3a4b9f4247433b89dd0069fce423f deleted file mode 100644 index 352f7c4ad9ba197b102f0d040ac9bab023429195..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 43 zcmb)5U|`6=)SA*}drMKvt8vfWQ|sfd-8J5|SbG13G$w{4LOi7aS4)5U|`6=)T+|v+Ag$C&vsABbMdJ{k7bMXH=MP9p2E-Y-jVM)06^go ACjbBd diff --git a/tests/mock/003-03/objects/bc/2b542422510d8b23eae97ede32dc2d5fa13c90 b/tests/mock/003-03/objects/bc/2b542422510d8b23eae97ede32dc2d5fa13c90 deleted file mode 100644 index 9d3c57746030107f006af1126f73f0fc8b31a327..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 43 zcmb)5U|`6=)GE@JrW~4iy!8IP*UxMHKCNC6^Z)pNKSqWN*}R_tX8{vS diff --git a/tests/mock/003-03/objects/cb/50e7dc3b7b52daf18d8bd62e158467236f47bb b/tests/mock/003-03/objects/cb/50e7dc3b7b52daf18d8bd62e158467236f47bb deleted file mode 100644 index a58a918a3d419be2034dd3cc463a9fcc16096c9a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 140 zcmV;70CWF%0i}&W3c@fD06pgwdlyR5P1Jyhf6xysn~e>aM&kC+-&^_xk28lEZnYML z(c(e72>9TblFLXrQ$7j05c$lPkRnT@(aGpy#AImEsdacv%OnM!G%uCl`rUER9q+G7 u7tV3)7 diff --git a/tests/mock/003-03/objects/d5/64d0bc3dd917926892c55e3706cc116d5b165e b/tests/mock/003-03/objects/d5/64d0bc3dd917926892c55e3706cc116d5b165e deleted file mode 100644 index 24279dca4468ca5ca61e5498dbfd93f0f9f09795..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53 zcmbx diff --git a/tests/mock/003-03/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests/mock/003-03/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 deleted file mode 100644 index 711223894375fe1186ac5bfffdc48fb1fa1e65cc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15 WcmbYBNMd7ZH$2$uE!{8ur diff --git a/tests/mock/008-02/info/exclude b/tests/mock/008-02/info/exclude deleted file mode 100644 index a5196d1be8..0000000000 --- a/tests/mock/008-02/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/tests/mock/008-02/logs/HEAD b/tests/mock/008-02/logs/HEAD deleted file mode 100644 index 1ca1072b1c..0000000000 --- a/tests/mock/008-02/logs/HEAD +++ /dev/null @@ -1,4 +0,0 @@ -0000000000000000000000000000000000000000 ffc6c773865c1342db9cd5df5777fc91ddeb8a4d Shuhei Tanuma 1327128850 +0900 commit (initial): initial commit -ffc6c773865c1342db9cd5df5777fc91ddeb8a4d 7fce1026cb624448e5a8cf8752bd5e19d8f2cb1f Shuhei Tanuma 1327128901 +0900 commit: modified README -7fce1026cb624448e5a8cf8752bd5e19d8f2cb1f 9bb8c853c9ea27609a6bdc48b78cd26a320daf7d Shuhei Tanuma 1327128919 +0900 commit: added section 1 -9bb8c853c9ea27609a6bdc48b78cd26a320daf7d 6e20138dc38f9f626107f1cd3ef0f9838c43defe Shuhei Tanuma 1327128937 +0900 commit: added section 1 contents diff --git a/tests/mock/008-02/logs/refs/heads/master b/tests/mock/008-02/logs/refs/heads/master deleted file mode 100644 index 1ca1072b1c..0000000000 --- a/tests/mock/008-02/logs/refs/heads/master +++ /dev/null @@ -1,4 +0,0 @@ -0000000000000000000000000000000000000000 ffc6c773865c1342db9cd5df5777fc91ddeb8a4d Shuhei Tanuma 1327128850 +0900 commit (initial): initial commit -ffc6c773865c1342db9cd5df5777fc91ddeb8a4d 7fce1026cb624448e5a8cf8752bd5e19d8f2cb1f Shuhei Tanuma 1327128901 +0900 commit: modified README -7fce1026cb624448e5a8cf8752bd5e19d8f2cb1f 9bb8c853c9ea27609a6bdc48b78cd26a320daf7d Shuhei Tanuma 1327128919 +0900 commit: added section 1 -9bb8c853c9ea27609a6bdc48b78cd26a320daf7d 6e20138dc38f9f626107f1cd3ef0f9838c43defe Shuhei Tanuma 1327128937 +0900 commit: added section 1 contents diff --git a/tests/mock/008-02/objects/23/ea9dd670731cabbf02dc9c9380a1f055521137 b/tests/mock/008-02/objects/23/ea9dd670731cabbf02dc9c9380a1f055521137 deleted file mode 100644 index 4a13a8a0bbff3c67c10d0d97ff3c76c7f6913659..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 42 zcmV+_0M-9^0ZYosPf{>4WAI4L$;np;&o9bJ(c|K>RR~T^F3HT#Q!wNL0JZiC6R;Z- A$N&HU diff --git a/tests/mock/008-02/objects/44/e3736675973ddffc3d66dc939adc958df45561 b/tests/mock/008-02/objects/44/e3736675973ddffc3d66dc939adc958df45561 deleted file mode 100644 index e2f53054761034b2bea3848ce14e2dfbd34a2089..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmbGvqdjb~o{^(lYmlNa$r(Zu6| K41+_lfGz+XWfeRC diff --git a/tests/mock/008-02/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238 b/tests/mock/008-02/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238 deleted file mode 100644 index 2cbc51b51fb979c066ffe2dcc2ba90f5a1dd3037..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28 kcmb4V4FlPAMD&g-A@e8|M$c#+K$0JRnj3IG5A diff --git a/tests/mock/008-02/objects/6e/20138dc38f9f626107f1cd3ef0f9838c43defe b/tests/mock/008-02/objects/6e/20138dc38f9f626107f1cd3ef0f9838c43defe deleted file mode 100644 index 07d587d840..0000000000 --- a/tests/mock/008-02/objects/6e/20138dc38f9f626107f1cd3ef0f9838c43defe +++ /dev/null @@ -1 +0,0 @@ -x¥ANÅ0 YçÞ#}%q'BÜ.àØ.­DÔ¦÷§úW`9o1z#½µm@œÃË8Ì@ÌHÓR#aÖ0•)‘,5Ì6³/H9t¿|Ø> Ôš%Ï(Å8Rò…SU™r¥,côÊ ©ãk¬ý€ÏõZmƒ/Þ¯Æðv>ñ1žøñÝxûyHoï0Rˆ¹ Á«/Þ»{½û‡Â±ª)œ&cë;¾;âtÁ%Pé \ No newline at end of file diff --git a/tests/mock/008-02/objects/7f/ce1026cb624448e5a8cf8752bd5e19d8f2cb1f b/tests/mock/008-02/objects/7f/ce1026cb624448e5a8cf8752bd5e19d8f2cb1f deleted file mode 100644 index 882451f2fb..0000000000 --- a/tests/mock/008-02/objects/7f/ce1026cb624448e5a8cf8752bd5e19d8f2cb1f +++ /dev/null @@ -1,2 +0,0 @@ -x¥ŽM -Â0F]ç³$ÿ“‚ˆ‚.ݨHg0­Ôôþ¯àò=>Mµ–ÚêM›S–Ò£}°ž$Zfê=*”ÄÉYvlKM+ECNE(oLSFs?ngDv+T;}&umm^nNiF0IuL z+UiSRnZa5%!FV5B3Wlf@G~_*DGASQ)k&1QBEAh=M&mBTRR#JN$y|&gyb~$2+!Re74 zt3De>HULeg=ekM$ diff --git a/tests/mock/008-02/objects/ab/fa0158df5ca98f9f39aeb3adee8cd663e02ac5 b/tests/mock/008-02/objects/ab/fa0158df5ca98f9f39aeb3adee8cd663e02ac5 deleted file mode 100644 index 9d1837dbe7dfe393a2d18cbc2a61296c0641fb40..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmV-60LlM&0ZYosPf{>3W$;MN$;np;&o9bJ(c|K>RR~T^F3HT#Q!wNzhOrcq^Ycnl M^Gb@j0K91s^4Pc=F8}}l diff --git a/tests/mock/008-02/objects/c1/a938374fb2738d149467cfb15e5ad90c378613 b/tests/mock/008-02/objects/c1/a938374fb2738d149467cfb15e5ad90c378613 deleted file mode 100644 index c15d39c37138a0f04b0815f046a21924e05fff56..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`F5i!tJU%*y`xmg_dJeb;j> M`GM9^07@bf5J#sMo&W#< diff --git a/tests/mock/008-02/objects/c7/b75609c9063bbe0a9d385eb2479a4f45115e27 b/tests/mock/008-02/objects/c7/b75609c9063bbe0a9d385eb2479a4f45115e27 deleted file mode 100644 index be01323d26a90c77d60bdb5753dc17c6aac9580e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53 zcmbmh J3|fNxEC30P6RrRN diff --git a/tests/mock/008-02/objects/d0/058326846c074ddcb67170cde54d5d36c7f2f5 b/tests/mock/008-02/objects/d0/058326846c074ddcb67170cde54d5d36c7f2f5 deleted file mode 100644 index 46c22508999ab6c549a15c3a0d9613bc279f5444..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O=0+Ia&Mdcw3@qD_PX%0UjFu> M^lAJl08QHxMODukm;e9( diff --git a/tests/mock/008-02/objects/db/78f3594ec0683f5d857ef731df0d860f14f2b2 b/tests/mock/008-02/objects/db/78f3594ec0683f5d857ef731df0d860f14f2b2 deleted file mode 100644 index 81f36856212e9e11d0edf22bea505326cc60848d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmb -#include - -PHPAPI zend_class_entry *git2_tree_class_entry; - -static void php_git2_tree_free_storage(php_git2_tree *object TSRMLS_DC) -{ - if (object->tree != NULL) { - git_tree_free(object->tree); - object->tree = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_tree_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_tree); - object->offset = 0; - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_get_subtree, 0,0,1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_get_entry_by_name, 0,0,1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - - - -/* Iterator Implementation */ - -/* -{{{ proto: Git2\Tree::current() -*/ -PHP_METHOD(git2_tree, current) -{ - php_git2_tree *m_tree; - const git_tree_entry *entry; - zval *z_entry; - - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); - entry = git_tree_entry_byindex(m_tree->tree, m_tree->offset); - if (entry == NULL) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified offset does not exist. %d"); - RETURN_FALSE; - } - create_tree_entry_from_entry(&z_entry, (git_tree_entry *)entry ,m_tree->repository); - RETURN_ZVAL(z_entry, 0, 1); -} -/* }}} */ - -/* -{{{ proto: Git2\Tree::key() -*/ -PHP_METHOD(git2_tree, key) -{ - php_git2_tree *m_tree; - - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); - RETURN_LONG(m_tree->offset); -} - -/* -{{{ proto: Git2\Tree::valid() -*/ -PHP_METHOD(git2_tree, next) -{ - php_git2_tree *m_tree; - - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); - m_tree->offset++; -} - -/* -{{{ proto: Git2\Tree::rewind() -*/ -PHP_METHOD(git2_tree, rewind) -{ - php_git2_tree *m_tree; - - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); - m_tree->offset = 0; -} - -/* -{{{ proto: Git2\Tree::valid() -*/ -PHP_METHOD(git2_tree, valid) -{ - php_git2_tree *m_tree; - int entry_count = 0; - - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); - entry_count = git_tree_entrycount(m_tree->tree); - if (m_tree->offset < entry_count) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -static int get_subtree(git_tree **result, git_tree *root, char *path) -{ - char *p, *k, *current_key, *tmp_value, *savedptr = NULL; - const git_tree_entry *entry; - git_tree *target,*tmp_result; - int error = 0; - - target = root; - p = (char *)strchr(path, '/'); - - if (p == NULL) { - entry = git_tree_entry_byname(target, path); - if (entry) { - git_otype type; - type = git_tree_entry_type((const git_tree_entry*)entry); - if (type == GIT_OBJ_TREE) { - return git_tree_lookup( - result, - git_object_owner((const git_object *)target), - git_tree_entry_id(entry) - ); - } else { - *result = NULL; - return -1; - } - } else { - return -1; - } - } - - tmp_value = estrdup(path); - current_key = php_strtok_r(tmp_value, "/", &savedptr); - - while (current_key != NULL && target != NULL) { - k = current_key; - - if (current_key != NULL && k != NULL) { - entry = git_tree_entry_byname(target, current_key); - if (entry && git_tree_entry_type((const git_tree_entry*)entry) == GIT_OBJ_TREE) { - error = git_tree_lookup( - &tmp_result, - git_object_owner((const git_object *)target), - git_tree_entry_id(entry) - ); - - if (error == GIT_OK) { - target = tmp_result; - } else { - return -1; - } - } else { - target = NULL; - current_key = NULL; - } - } else { - if (k != NULL) { - entry = git_tree_entry_byname(target, current_key); - if (entry && git_tree_entry_type((const git_tree_entry*)entry) == GIT_OBJ_TREE) { - error = git_tree_lookup( - &tmp_result, - git_object_owner((const git_object *)target), - git_object_id((const git_object *)entry) - ); - - if (error == GIT_OK) { - target = tmp_result; - } else { - return -1; - } - } else { - target = NULL; - current_key = NULL; - } - } - } - - current_key = php_strtok_r(NULL, "/", &savedptr); - } - efree(tmp_value); - - if (target && target != root) { - *result = target; - return 0; - } else { - return -1; - } -} - -/* -{{{ proto: Git2\Tree Git2\Tree::getSubtree($path) -*/ -PHP_METHOD(git2_tree, getSubtree) -{ - char *path = NULL; - int error, path_len = 0; - git_tree *subtree; - php_git2_tree *object; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE) { - return; - } - - object = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); - - /* note: this method does not use git_tree_getsubtree as that function follows dirname(3) style. - * this method returns specified subtree or false. - */ - error = get_subtree(&subtree, object->tree, path); - if (error == GIT_OK) { - zval *result; - - result = php_git2_object_new(git_object_owner((git_object *)object->tree), (git_object *)subtree TSRMLS_CC); - RETVAL_ZVAL(result, 0, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* -{{{ proto: Git2\Tree Git2\Tree::getEntryByName($name) -*/ -PHP_METHOD(git2_tree, getEntryByName) -{ - char *path = NULL; - int path_len = 0; - php_git2_tree *object; - const git_tree_entry *entry = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE) { - return; - } - - object = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); - - entry = git_tree_entry_byname(object->tree, (const char *)path); - if (entry) { - zval *result; - - create_tree_entry_from_entry(&result, (git_tree_entry *)entry ,git_object_owner((git_object *)object->tree)); - RETVAL_ZVAL(result, 0, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -static zend_function_entry php_git2_tree_methods[] = { - /* Iterator Implementation */ - PHP_ME(git2_tree, current, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree, key, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree, next, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree, rewind, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree, valid, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree, getSubtree, arginfo_git2_tree_get_subtree, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree, getEntryByName,arginfo_git2_tree_get_entry_by_name, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_tree_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Tree", php_git2_tree_methods); - git2_tree_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_tree_class_entry->create_object = php_git2_tree_new; - zend_class_implements(git2_tree_class_entry TSRMLS_CC, 1, spl_ce_Iterator); -} \ No newline at end of file diff --git a/tree_builder.c b/tree_builder.c deleted file mode 100644 index 5d395758e2..0000000000 --- a/tree_builder.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_tree_builder_class_entry; - -static void php_git2_tree_builder_free_storage(php_git2_tree_builder *object TSRMLS_DC) -{ - if (object->builder!= NULL) { - git_treebuilder_free(object->builder); - object->builder = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_tree_builder_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_tree_builder); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_builder___construct, 0,0,1) - ZEND_ARG_INFO(0, tree) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_builder_insert, 0,0,1) - ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_builder_remove, 0,0,1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\TreeBuilder::__construct([Git2\Tree $tree]) -*/ -PHP_METHOD(git2_tree_builder, __construct) -{ - git_treebuilder *builder; - zval *z_tree = NULL; - git_tree *tree = NULL; - php_git2_tree *m_tree; - php_git2_tree_builder *m_builder; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|O", &z_tree, git2_tree_class_entry) == FAILURE) { - return; - } - if (z_tree != NULL) { - m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, z_tree); - tree = m_tree->tree; - } - - git_treebuilder_create(&builder, tree); - m_builder = PHP_GIT2_GET_OBJECT(php_git2_tree_builder, getThis()); - m_builder->builder = builder; -} -/* }}} */ - -/* -{{{ proto: Git2\TreeBuilder::insert(Git2\TreeEntry $entry) -*/ -PHP_METHOD(git2_tree_builder, insert) -{ - zval *z_name, *z_oid, *z_attributes, *m_entry = NULL; - php_git2_tree_builder *m_builder; - git_oid oid; - int error = 0; - unsigned int attributes = 0; - char *name; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "O", &m_entry, git2_tree_entry_class_entry) == FAILURE) { - return; - } - - z_name = zend_read_property(git2_tree_entry_class_entry, m_entry,"name",sizeof("name")-1, 0 TSRMLS_CC); - z_oid = zend_read_property(git2_tree_entry_class_entry, m_entry,"oid",sizeof("oid")-1, 0 TSRMLS_CC); - z_attributes = zend_read_property(git2_tree_entry_class_entry, m_entry,"attributes",sizeof("attributes")-1, 0 TSRMLS_CC); - m_builder = PHP_GIT2_GET_OBJECT(php_git2_tree_builder, getThis()); - - name = Z_STRVAL_P(z_name); - attributes = (unsigned int)Z_LVAL_P(z_attributes); - - git_oid_fromstrn(&oid, Z_STRVAL_P(z_oid), Z_STRLEN_P(z_oid)); - error = git_treebuilder_insert(NULL, m_builder->builder, name, &oid, attributes); -} -/* }}} */ - -/* -{{{ proto: Git2\TreeBuilder::remove(string $name) -*/ -PHP_METHOD(git2_tree_builder, remove) -{ - char *name; - int name_len = 0; - php_git2_tree_builder *m_builder; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &name, &name_len) == FAILURE) { - return; - } - m_builder = PHP_GIT2_GET_OBJECT(php_git2_tree_builder, getThis()); - - RETURN_LONG(git_treebuilder_remove(m_builder->builder, name)); -} -/* }}} */ - -/* -{{{ proto: Git2\TreeBuilder::write() -*/ -PHP_METHOD(git2_tree_builder, write) -{ - git_oid oid; - php_git2_repository *m_repository; - php_git2_tree_builder *m_builder; - char oid_out[GIT_OID_HEXSZ+1] = {0}; - zval *repository; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "O", &repository, git2_repository_class_entry) == FAILURE) { - return; - } - - m_builder = PHP_GIT2_GET_OBJECT(php_git2_tree_builder, getThis()); - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - - error = git_treebuilder_write(&oid, m_repository->repository, m_builder->builder); - if (error != GIT_OK) { - RETURN_FALSE; - } - - git_oid_fmt(oid_out, &oid); - RETURN_STRINGL(oid_out,GIT_OID_HEXSZ,1); -} -/* }}} */ - -/* -{{{ proto: Git2\TreeBuilder::clear() -*/ -PHP_METHOD(git2_tree_builder, clear) -{ - php_git2_tree_builder *m_builder; - m_builder = PHP_GIT2_GET_OBJECT(php_git2_tree_builder, getThis()); - - git_treebuilder_clear(m_builder->builder); -} -/* }}} */ - -static zend_function_entry php_git2_tree_builder_methods[] = { - PHP_ME(git2_tree_builder, __construct, arginfo_git2_tree_builder___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(git2_tree_builder, insert, arginfo_git2_tree_builder_insert, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree_builder, remove, arginfo_git2_tree_builder_remove, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree_builder, clear, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree_builder, write, NULL, ZEND_ACC_PUBLIC) - /* @todo: filter */ - {NULL,NULL,NULL} -}; - -void php_git2_tree_builder_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "TreeBuilder", php_git2_tree_builder_methods); - git2_tree_builder_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_tree_builder_class_entry->create_object = php_git2_tree_builder_new; -} \ No newline at end of file diff --git a/tree_entry.c b/tree_entry.c deleted file mode 100644 index 4e7dd1eb4c..0000000000 --- a/tree_entry.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" - -PHPAPI zend_class_entry *git2_tree_entry_class_entry; - -static void php_git2_tree_entry_free_storage(php_git2_tree_entry *object TSRMLS_DC) -{ - if (object->entry != NULL) { - object->entry = NULL; - } - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_tree_entry_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_tree_entry); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_entry___construct, 0,0,1) - ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\TreeEntry::__construct([array $entry]) -*/ -PHP_METHOD(git2_tree_entry, __construct) -{ - zval *z_entry= NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|z", &z_entry) == FAILURE) { - return; - } - - if (z_entry != NULL) { - zval **zvalue = NULL; - zval *zvaluep = NULL; - - if (zend_hash_find(Z_ARRVAL_P(z_entry),"name",sizeof("name"),(void **)&zvalue) != FAILURE) { - zvaluep = *zvalue; - add_property_string_ex(getThis(), "name",sizeof("name"),Z_STRVAL_P(zvaluep) ,1 TSRMLS_CC); - zvalue = NULL; - zvaluep = NULL; - } - if (zend_hash_find(Z_ARRVAL_P(z_entry),"attributes",sizeof("attributes"),(void **)&zvalue) != FAILURE) { - zvaluep = *zvalue; - add_property_long_ex(getThis(), "attributes",sizeof("attributes"),Z_LVAL_P(zvaluep) TSRMLS_CC); - zvalue = NULL; - zvaluep = NULL; - } - if (zend_hash_find(Z_ARRVAL_P(z_entry),"oid",sizeof("oid"),(void **)&zvalue) != FAILURE) { - zvaluep = *zvalue; - add_property_string_ex(getThis(), "oid",sizeof("oid"),Z_STRVAL_P(zvaluep),1 TSRMLS_CC); - zvalue = NULL; - zvaluep = NULL; - } - } -} -/* }}} */ - -/* -{{{ proto: Git2\TreeEntry::isTree() -*/ -PHP_METHOD(git2_tree_entry, isTree) -{ - zval *value; - long attribute = 0; - - value = zend_read_property(git2_tree_entry_class_entry, getThis(), "attributes", sizeof("attributes")-1, 0 TSRMLS_CC); - attribute = Z_LVAL_P(value); - - if(attribute & 040000){ - RETURN_TRUE; - }else{ - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\TreeEntry::isBlob() -*/ -PHP_METHOD(git2_tree_entry, isBlob) -{ - zval *value; - long attribute = 0; - - value = zend_read_property(git2_tree_entry_class_entry, getThis(), "attributes", sizeof("attributes")-1, 0 TSRMLS_CC); - attribute = Z_LVAL_P(value); - - if(!(attribute & 040000) && attribute != 0160000){ - RETURN_TRUE; - }else{ - RETURN_FALSE; - } -} -/* }}} */ - -/* -{{{ proto: Git2\TreeEntry::isSubmodule() -*/ -PHP_METHOD(git2_tree_entry, isSubmodule) -{ - zval *value; - long attribute = 0; - - value = zend_read_property(git2_tree_entry_class_entry, getThis(), "attributes", sizeof("attributes")-1, 0 TSRMLS_CC); - attribute = Z_LVAL_P(value); - - if(attribute == 0160000){ - RETURN_TRUE; - }else{ - RETURN_FALSE; - } -} -/* }}} */ - - -static zend_function_entry php_git2_tree_entry_methods[] = { - PHP_ME(git2_tree_entry, __construct, arginfo_git2_tree_entry___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(git2_tree_entry, isTree, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree_entry, isBlob, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_tree_entry, isSubmodule, NULL, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_tree_entry_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "TreeEntry", php_git2_tree_entry_methods); - git2_tree_entry_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_tree_entry_class_entry->create_object = php_git2_tree_entry_new; - - zend_declare_property_null(git2_tree_entry_class_entry, "name", sizeof("name")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_tree_entry_class_entry, "oid", sizeof("oid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git2_tree_entry_class_entry, "attributes", sizeof("attributes")-1, ZEND_ACC_PUBLIC TSRMLS_CC); -} \ No newline at end of file diff --git a/walker.c b/walker.c deleted file mode 100644 index 22b68dcd8c..0000000000 --- a/walker.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2012 Shuhei Tanuma - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "php_git2.h" -#include -#include - -PHPAPI zend_class_entry *git2_walker_class_entry; - -static const double resize_factor = 1.75; -static const unsigned int minimum_size = 8; - -typedef struct{ - git_oid oid; - unsigned int interested; -} php_git2_revwalk_element; - -int php_git2_vector_init(php_git2_vector *v, size_t initial_size) -{ - assert(v); - memset(v, 0x0, sizeof(php_git2_vector)); - - if (initial_size == 0) { - initial_size = minimum_size; - } - - v->_alloc_size = initial_size; - v->length = 0; - - v->contents = emalloc(v->_alloc_size * sizeof(void *)); -} - -static int php_git2_resize_vector(php_git2_vector *v) -{ - v->_alloc_size = ((unsigned int)(v->_alloc_size * resize_factor)) + 1; - if (v->_alloc_size < minimum_size) - v->_alloc_size = minimum_size; - - v->contents = erealloc(v->contents, v->_alloc_size * sizeof(void *)); - - return 0; -} - -int php_git2_vector_insert(php_git2_vector *v, void *element) -{ - assert(v); - - if (v->length >= v->_alloc_size && php_git2_resize_vector(v) < 0) { - return -1; - } - - v->contents[v->length++] = element; - return 0; -} - -void php_git2_vector_clear(php_git2_vector *v) -{ - assert(v); - v->length = 0; -} - -void php_git2_vector_free(php_git2_vector *v) -{ - assert(v); - - efree(v->contents); - v->contents = NULL; - - v->length = 0; - v->_alloc_size = 0; -} - - -static void php_git2_walker_free_storage(php_git2_walker *object TSRMLS_DC) -{ - int i = 0; - if (object->walker != NULL) { - git_revwalk_free(object->walker); - object->walker = NULL; - } - if (object->current != NULL) { - efree(object->current); - object->current = NULL; - } - - for (i = 0; i < object->vector.length; i++) { - efree(object->vector.contents[i]); - } - php_git2_vector_free(&object->vector); - - /* the repository will be free'd by Git2\Repository */ - object->repository = NULL; - - zend_object_std_dtor(&object->zo TSRMLS_CC); - efree(object); -} - -zend_object_value php_git2_walker_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - - PHP_GIT2_STD_CREATE_OBJECT(php_git2_walker); - object->dirty = 0; - - object->current = emalloc(sizeof(git_oid)); - php_git2_vector_init(&object->vector, 8); - - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_walker___construct, 0,0,1) - ZEND_ARG_INFO(0, repository) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_walker_sorting, 0,0,1) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_walker_push, 0,0,1) - ZEND_ARG_INFO(0, sha) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_walker_hide, 0,0,1) - ZEND_ARG_INFO(0, sha) -ZEND_END_ARG_INFO() - -/* -{{{ proto: Git2\Walker::__construct(Git2\Repository $repo) -*/ -PHP_METHOD(git2_walker, __construct) -{ - php_git2_repository *m_repository; - php_git2_walker *m_walker; - zval *repository; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "O", &repository, git2_repository_class_entry) == FAILURE) { - return; - } - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); - - error = git_revwalk_new(&m_walker->walker, m_repository->repository); - - if (error != GIT_OK) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "can't create a Git2\\Walker instance."); - } - - m_walker->repository = m_repository->repository; -} -/* }}} */ - -/* -{{{ proto: Git2\Walker::sorting(long $mode) -*/ -PHP_METHOD(git2_walker, sorting) -{ - php_git2_walker *m_walker; - long mode = GIT_SORT_NONE; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &mode) == FAILURE) { - return; - } - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - git_revwalk_sorting(m_walker->walker, (unsigned int)mode); -} -/* }}} */ - -/* -{{{ proto: Git2\Walker::push(string $hex_sha_intersting) -*/ -PHP_METHOD(git2_walker, push) -{ - php_git2_walker *m_walker; - char *sha; - int sha_len = 0, error = 0; - php_git2_revwalk_element *elm; - - /* @todo: also supports Git2\Commit object */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &sha, &sha_len) == FAILURE) { - return; - } - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - elm = emalloc(sizeof(php_git2_revwalk_element)); - elm->interested = 1; - - git_oid_fromstrn(&elm->oid, sha, sha_len); - error = git_revwalk_push(m_walker->walker, &elm->oid); - - if (error != GIT_OK) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Git2\\Walker::push failed."); - } - - php_git2_vector_insert(&m_walker->vector, elm); -} -/* }}} */ - -/* -{{{ proto: Git2\Walker::hide(string $hex_sha_unintersting) -*/ -PHP_METHOD(git2_walker, hide) -{ - php_git2_walker *m_walker; - char *sha; - int sha_len = 0, error = 0; - git_oid oid; - php_git2_revwalk_element *elm; - - /* @todo: also supports Git2\Commit object */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &sha, &sha_len) == FAILURE) { - return; - } - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - elm = emalloc(sizeof(php_git2_revwalk_element)); - elm->interested = 0; - - git_oid_fromstrn(&elm->oid, sha, sha_len); - error = git_revwalk_hide(m_walker->walker, &elm->oid); - - if (error != GIT_OK) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Git2\\Walker::push failed."); - } - php_git2_vector_insert(&m_walker->vector, elm); -} -/* }}} */ - - -/* -{{{ proto: Git2\Walker::reset() -*/ -PHP_METHOD(git2_walker, reset) -{ - php_git2_walker *m_walker; - int i = 0; - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - git_revwalk_reset(m_walker->walker); - m_walker->dirty = 0; - - for (i = 0; i < m_walker->vector.length; i++) { - php_git2_revwalk_element *elm = m_walker->vector.contents[i]; - efree(elm); - } - - php_git2_vector_clear(&m_walker->vector); -} -/* }}} */ - - -/* Iterator Implementation */ - -/* -{{{ proto: Git2\Walker::current() -*/ -PHP_METHOD(git2_walker, current) -{ - php_git2_walker *m_walker; - zval *result; - git_object *object; - int error = 0; - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - - error = git_object_lookup(&object, m_walker->repository, m_walker->current, GIT_OBJ_COMMIT); - result = php_git2_object_new(m_walker->repository, object TSRMLS_CC); - RETVAL_ZVAL(result, 0, 1); -} - -/* -{{{ proto: Git2\Walker::key() -*/ -PHP_METHOD(git2_walker, key) -{ - char out[GIT_OID_HEXSZ] = {0}; - php_git2_walker *m_walker; - int error = 0; - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - git_oid_fmt(out, m_walker->current); - - RETURN_STRINGL(out, GIT_OID_HEXSZ, 1); -} - -/* -{{{ proto: Git2\Walker::next() -*/ -PHP_METHOD(git2_walker, next) -{ - php_git2_walker *m_walker; - int error = 0; - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - error = git_revwalk_next(m_walker->current, m_walker->walker); - m_walker->dirty = 1; - - if (error != GIT_OK) { - efree(m_walker->current); - m_walker->current = NULL; - } -} - -/* -{{{ proto: Git2\Walker::rewind() -*/ -PHP_METHOD(git2_walker, rewind) -{ - php_git2_walker *m_walker; - int i = 0, error = 0; - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - - if (m_walker->dirty) { - git_revwalk_reset(m_walker->walker); - - for (i = 0; i < m_walker->vector.length; i++) { - php_git2_revwalk_element *elm = m_walker->vector.contents[i]; - - if (elm->interested) { - error = git_revwalk_push(m_walker->walker, &elm->oid); - } else { - error = git_revwalk_hide(m_walker->walker, &elm->oid); - } - - if (error != GIT_OK) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Git2\\Walker::rewind failed. probably you pushed or hided invalied oid."); - } - } - - if (m_walker->current == NULL) { - m_walker->current = emalloc(sizeof(git_oid)); - } - - assert(m_walker->current); - error = git_revwalk_next(m_walker->current, m_walker->walker); - m_walker->dirty = 1; - } else { - error = git_revwalk_next(m_walker->current, m_walker->walker); - m_walker->dirty = 1; - - if (error != GIT_OK) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Git2\\Walker::rewind failed. probably you pushed or hided invalied oid."); - } - } - -} - -/* -{{{ proto: Git2\Walker::valid() -*/ -PHP_METHOD(git2_walker, valid) -{ - php_git2_walker *m_walker; - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - - if (m_walker->current != NULL) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -static zend_function_entry php_git2_walker_methods[] = { - PHP_ME(git2_walker, __construct, arginfo_git2_walker___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(git2_walker, sorting, arginfo_git2_walker_sorting, ZEND_ACC_PUBLIC) - PHP_ME(git2_walker, push, arginfo_git2_walker_push, ZEND_ACC_PUBLIC) - PHP_ME(git2_walker, hide, arginfo_git2_walker_hide, ZEND_ACC_PUBLIC) - PHP_ME(git2_walker, reset, NULL, ZEND_ACC_PUBLIC) - /* Iterator Implementation */ - PHP_ME(git2_walker, current, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_walker, key, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_walker, next, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_walker, rewind, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_walker, valid, NULL, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void php_git2_walker_init(TSRMLS_D) -{ - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Walker", php_git2_walker_methods); - git2_walker_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_walker_class_entry->create_object = php_git2_walker_new; - zend_class_implements(git2_walker_class_entry TSRMLS_CC, 1, spl_ce_Iterator); -} \ No newline at end of file From 046d060842470edec3654f2065dd0dd65a92f7c8 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 10 Jan 2014 11:25:40 +0900 Subject: [PATCH 009/136] update libgit2 v0.20.0 --- libgit2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgit2 b/libgit2 index eddc1f1ed7..43cb8b3242 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit eddc1f1ed78898a4ca41480045b1d0d5b075e773 +Subproject commit 43cb8b32428b1b29994874349ec22eb5372e152c From 7a1a21d50f2a6fcb386d2ec90b1aa492cf91fcd6 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 02:40:59 +0900 Subject: [PATCH 010/136] wip --- .gitmodules | 3 +- blob.c | 269 ++++++++++++++++ blob.h | 146 +++++++++ clone.c | 43 +++ clone.h | 50 +++ commit.c | 585 +++++++++++++++++++++++++++++++++++ commit.h | 200 ++++++++++++ config.m4 | 32 +- fe.php | 9 + gen.php | 202 ++++++++++++ helper.c | 18 ++ helper.h | 33 ++ php_git2.c | 295 ++++++++++++++++++ php_git2.h | 104 +++++++ php_git2_priv.h | 62 ++++ reference.c | 804 ++++++++++++++++++++++++++++++++++++++++++++++++ reference.h | 335 ++++++++++++++++++++ repository.c | 160 ++++++++++ repository.h | 77 +++++ revwalk.c | 357 +++++++++++++++++++++ revwalk.h | 166 ++++++++++ tree.c | 504 ++++++++++++++++++++++++++++++ tree.h | 183 +++++++++++ treebuilder.c | 232 ++++++++++++++ treebuilder.h | 109 +++++++ 25 files changed, 4956 insertions(+), 22 deletions(-) create mode 100644 blob.c create mode 100644 blob.h create mode 100644 clone.c create mode 100644 clone.h create mode 100644 commit.c create mode 100644 commit.h create mode 100644 fe.php create mode 100644 gen.php create mode 100644 helper.c create mode 100644 helper.h create mode 100644 php_git2.c create mode 100644 php_git2.h create mode 100644 php_git2_priv.h create mode 100644 reference.c create mode 100644 reference.h create mode 100644 repository.c create mode 100644 repository.h create mode 100644 revwalk.c create mode 100644 revwalk.h create mode 100644 tree.c create mode 100644 tree.h create mode 100644 treebuilder.c create mode 100644 treebuilder.h diff --git a/.gitmodules b/.gitmodules index 30eb68a28c..bbf4f9db34 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "libgit2"] path = libgit2 - url = https://github.com/libgit2/libgit2.git + url = https://github.com/libgit2/libgit2.git + ignore = dirty diff --git a/blob.c b/blob.c new file mode 100644 index 0000000000..c3b37ea60d --- /dev/null +++ b/blob.c @@ -0,0 +1,269 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "blob.h" + +/* {{{ proto resource git_blob_create_frombuffer(resource $repository, string $buffer) +*/ +PHP_FUNCTION(git_blob_create_frombuffer) +{ + zval *repository; + php_git2_t *git2; + char *buffer; + int buffer_len; + int error; + git_oid id; + char out[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repository, &buffer, &buffer_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_blob_create_frombuffer(&id, PHP_GIT2_V(git2, repository), buffer, buffer_len); + if (php_git2_check_error(error, "git_blob_create_frombuffer" TSRMLS_CC)) { + RETURN_FALSE + } + + git_oid_fmt(out, &id); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_blob_create_fromchunks(resource $repository, string $hintpath, Callable $callback, mixed payload) +*/ +PHP_FUNCTION(git_blob_create_fromchunks) +{ +} + +/* {{{ proto resource git_blob_create_fromdisk(resource $repository, string $path) +*/ +PHP_FUNCTION(git_blob_create_fromdisk) +{ + zval *repository; + php_git2_t *git2; + char *path; + int path_len; + int error; + git_oid id; + char out[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repository, &path, &path_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_blob_create_fromdisk(&id, PHP_GIT2_V(git2, repository), path); + if (php_git2_check_error(error, "git_blob_create_fromdisk" TSRMLS_CC)) { + RETURN_FALSE + } + + git_oid_fmt(out, &id); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_blob_create_fromworkdir(resource $repository, string $relative_path) +*/ +PHP_FUNCTION(git_blob_create_fromworkdir) +{ + zval *repository; + php_git2_t *git2; + char *path; + int path_len; + int error; + git_oid id; + char out[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repository, &path, &path_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_blob_create_fromworkdir(&id, PHP_GIT2_V(git2, repository), path); + if (php_git2_check_error(error, "git_blob_create_fromdisk" TSRMLS_CC)) { + RETURN_FALSE + } + + git_oid_fmt(out, &id); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_blob_filtered_content($blob, $as_path, $check_for_binary_data) +*/ +PHP_FUNCTION(git_blob_filtered_content) +{ +} + +/* {{{ proto resource git_blob_free(resource $blob) +*/ +PHP_FUNCTION(git_blob_free) +{ + zval *blob; + php_git2_t *git2; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blob) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git2->should_free_v) { + git_blob_free(PHP_GIT2_V(git2, blob)); + git2->should_free_v = 0; + } + zval_ptr_dtor(&blob); +} + +/* {{{ proto resource git_blob_id(resource $blob) +*/ +PHP_FUNCTION(git_blob_id) +{ + zval *blob; + php_git2_t *git2; + char out[41] = {0}; + const git_oid *id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blob) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + id = git_blob_id(PHP_GIT2_V(git2, blob)); + + git_oid_fmt(out, id); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_blob_is_binary(resource $blob) +*/ +PHP_FUNCTION(git_blob_is_binary) +{ + zval *blob; + php_git2_t *git2; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blob) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_blob_is_binary(PHP_GIT2_V(git2, blob)); + RETURN_BOOL(result); +} + +/* {{{ proto resource git_blob_lookup(resource $repository, string $oid) +*/ +PHP_FUNCTION(git_blob_lookup) +{ + zval *repository; + php_git2_t *git2, *result; + git_blob *blob; + char *hash; + int hash_len; + int error; + git_oid id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repository, &hash, &hash_len) == FAILURE) { + return; + } + + if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + PHP_GIT2_MAKE_RESOURCE(result); + error = git_blob_lookup(&blob, PHP_GIT2_V(git2, repository), &id); + if (php_git2_check_error(error, "git_blob_lookup" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_V(result, blob) = blob; + result->type = PHP_GIT2_TYPE_BLOB; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_blob_lookup_prefix(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_lookup_prefix) +{ +} + +/* {{{ proto resource git_blob_owner(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_owner) +{ + zval *blob; + php_git2_t *git2, *result; + git_repository *repository; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blob) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + PHP_GIT2_MAKE_RESOURCE(result); + repository = git_blob_owner(PHP_GIT2_V(git2, blob)); + + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_blob_rawcontent(resource $blob) +*/ +PHP_FUNCTION(git_blob_rawcontent) +{ + zval *blob; + php_git2_t *git2; + const char *buffer = NULL; + git_off_t size; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blob) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + buffer = git_blob_rawcontent(PHP_GIT2_V(git2, blob)); + if (buffer == NULL) { + RETURN_FALSE; + } + size = git_blob_rawsize(PHP_GIT2_V(git2, blob)); + RETURN_STRINGL(buffer, size, 1); +} + +/* {{{ proto resource git_blob_rawsize(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_rawsize) +{ + zval *blob; + php_git2_t *git2; + git_off_t size; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blob) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + size = git_blob_rawsize(PHP_GIT2_V(git2, blob)); + RETURN_LONG(size); +} \ No newline at end of file diff --git a/blob.h b/blob.h new file mode 100644 index 0000000000..c4b5a4a754 --- /dev/null +++ b/blob.h @@ -0,0 +1,146 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_BLOB_H +#define PHP_GIT2_BLOB_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_create_frombuffer, 0, 0, 2) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, buffer) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_create_fromchunks, 0, 0, 3) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, hintpath) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(1, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_create_fromdisk, 0, 0, 2) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_create_fromworkdir, 0, 0, 2) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, relative_path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_filtered_content, 0, 0, 2) + ZEND_ARG_INFO(0, blob) + ZEND_ARG_INFO(0, as_path) + ZEND_ARG_INFO(0, check_for_binary_data) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_free, 0, 0, 1) + ZEND_ARG_INFO(0, blob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_id, 0, 0, 1) + ZEND_ARG_INFO(0, blob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_is_binary, 0, 0, 1) + ZEND_ARG_INFO(0, blob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_lookup, 0, 0, 2) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_lookup_prefix, 0, 0, 3) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, length) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_owner, 0, 0, 1) + ZEND_ARG_INFO(0, blob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_rawcontent, 0, 0, 1) + ZEND_ARG_INFO(0, blob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_rawsize, 0, 0, 1) + ZEND_ARG_INFO(0, blob) +ZEND_END_ARG_INFO() + + +/* {{{ proto resource git_blob_create_frombuffer(resource $repository, string $buffer) +*/ +PHP_FUNCTION(git_blob_create_frombuffer); + +/* {{{ proto resource git_blob_create_fromchunks(resource $repository, string $hintpath, Callable $callback, mixed payload) +*/ +PHP_FUNCTION(git_blob_create_fromchunks); + +/* {{{ proto resource git_blob_create_fromdisk(resource $repository, string $path) +*/ +PHP_FUNCTION(git_blob_create_fromdisk); + +/* {{{ proto resource git_blob_create_fromworkdir(resource $repository, string $relative_path) +*/ +PHP_FUNCTION(git_blob_create_fromworkdir); + + +/* {{{ proto resource git_blob_filtered_content($blob, $as_path, $check_for_binary_data) +*/ +PHP_FUNCTION(git_blob_filtered_content); + +/* {{{ proto resource git_blob_free(resource $blob) +*/ +PHP_FUNCTION(git_blob_free); + +/* {{{ proto resource git_blob_id(resource $blob) +*/ +PHP_FUNCTION(git_blob_id); + +/* {{{ proto resource git_blob_is_binary(resource $blob) +*/ +PHP_FUNCTION(git_blob_is_binary); + +/* {{{ proto resource git_blob_lookup(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_lookup); + +/* {{{ proto resource git_blob_lookup_prefix(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_lookup_prefix); + +/* {{{ proto resource git_blob_owner(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_owner); + +/* {{{ proto resource git_blob_rawcontent(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_rawcontent); + +/* {{{ proto resource git_blob_rawsize(resource $blob, string $oid) +*/ +PHP_FUNCTION(git_blob_rawsize); + +#endif \ No newline at end of file diff --git a/clone.c b/clone.c new file mode 100644 index 0000000000..6bd6337883 --- /dev/null +++ b/clone.c @@ -0,0 +1,43 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "clone.h" + +/* {{{ proto resource git_clone(string $url, string $localpath[, array $options]) +*/ +PHP_FUNCTION(git_clone) +{ + char *url, *localpath; + int url_len, localpath_len; + zval *options;// = GIT_OPTIONS_INIT; + php_git2_t *git2; + git_repository *repository; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ss|a", &url, &url_len, &localpath, &localpath_len, &options) == FAILURE) { + return; + } + + /* TODO(chobie): convert options to git_clone_options */ + + error = git_clone(&repository, url, localpath, NULL); + if (php_git2_check_error(error, "git_clone" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(git2); + + PHP_GIT2_V(git2, repository) = repository; + git2->type = PHP_GIT2_TYPE_REPOSITORY; + git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); + git2->should_free_v = 1; + + ZVAL_RESOURCE(return_value, git2->resource_id); +} + +/* {{{ proto int git_clone_into(resource $repository, resource $remote, long $co_opts, string $branch) +*/ +PHP_FUNCTION(git_clone_into) +{ + /* TODO(chobie): implement this*/ +} diff --git a/clone.h b/clone.h new file mode 100644 index 0000000000..a6d759016a --- /dev/null +++ b/clone.h @@ -0,0 +1,50 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_CLONE_H +#define PHP_GIT2_CLONE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_clone, 0, 0, 3) + ZEND_ARG_INFO(0, url) + ZEND_ARG_INFO(0, localpath) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_clone_into, 0, 0, 4) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, co_opts) + ZEND_ARG_INFO(0, branch) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_clone(string $url, string $localpath[, long $options]) +*/ +PHP_FUNCTION(git_clone); + +/* {{{ proto int git_clone_into(resource $repository, resource $remote, long $co_opts, string $branch) +*/ +PHP_FUNCTION(git_clone_into); + +#endif \ No newline at end of file diff --git a/commit.c b/commit.c new file mode 100644 index 0000000000..530aa5b377 --- /dev/null +++ b/commit.c @@ -0,0 +1,585 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "commit.h" + +static zval* datetime_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) +{ +#if PHP_VERSION_ID <= 50304 + Z_TYPE_P(object) = IS_OBJECT; + object_init_ex(object, pce); + Z_SET_REFCOUNT_P(object, 1); + Z_UNSET_ISREF_P(object); + return object; +#else + return php_date_instantiate(pce, object TSRMLS_CC); +#endif +} + +/* {{{ proto resource git_commit_lookup(resource $repository, mixed $oid) +*/ +PHP_FUNCTION(git_commit_lookup) +{ + zval *repository; + php_git2_t *git2, *result; + git_commit *commit; + char *hash; + int hash_len; + int error; + git_oid id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repository, &hash, &hash_len) == FAILURE) { + return; + } + + if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + PHP_GIT2_MAKE_RESOURCE(result); + error = git_commit_lookup(&commit, PHP_GIT2_V(git2, repository), &id); + if (php_git2_check_error(error, "git_commit_lookup" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_V(result, commit) = commit; + result->type = PHP_GIT2_TYPE_COMMIT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} +/* }}} */ + +/* {{{ proto resource git_commit_author(resource $commit) +*/ +PHP_FUNCTION(git_commit_author) +{ + zval *repository; + php_git2_t *git2; + zval *commit; + git_signature *author; + zval *result, *datetime, *timezone; + php_timezone_obj *tzobj; + char time_str[12] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + author = git_commit_author(PHP_GIT2_V(git2, commit)); + + MAKE_STD_ZVAL(result); + array_init(result); + + MAKE_STD_ZVAL(datetime); + MAKE_STD_ZVAL(timezone); + + datetime_instantiate(php_date_get_date_ce(), datetime TSRMLS_CC); + snprintf(time_str,12,"%c%ld",'@', author->when.time); + + datetime_instantiate(php_date_get_timezone_ce(), timezone TSRMLS_CC); + tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone TSRMLS_CC); + tzobj->initialized = 1; + tzobj->type = TIMELIB_ZONETYPE_OFFSET; + tzobj->tzi.utc_offset = -author->when.offset; /* NOTE(chobie): probably this fine */ + + php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), NULL, 0, NULL, timezone, 0 TSRMLS_CC); + + add_assoc_string_ex(result, ZEND_STRS("name"), author->name, 1); + add_assoc_string_ex(result, ZEND_STRS("email"), author->email, 1); + add_assoc_zval_ex(result, ZEND_STRS("time"), datetime); + + zval_ptr_dtor(&timezone); + + RETURN_ZVAL(result, 0, 1); +} +/* }}} */ + +/* {{{ proto resource git_commit_tree(resource $commit) +*/ +PHP_FUNCTION(git_commit_tree) +{ + zval *repository; + php_git2_t *git2, *result; + git_commit *commit; + git_tree *tree; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + PHP_GIT2_MAKE_RESOURCE(result); + error = git_commit_tree(&tree, PHP_GIT2_V(git2, commit)); + if (php_git2_check_error(error, "git_commit_tree" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_V(result, tree) = tree; + result->type = PHP_GIT2_TYPE_TREE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_commit_lookup_prefix(repo, id, len) +*/ +PHP_FUNCTION(git_commit_lookup_prefix) +{ + zval *repo; + php_git2_t *_repo; + char *id = {0}; + int id_len; + long len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_commit_lookup_prefix not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &repo, &id, &id_len, &len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_commit_id(commit) +*/ +PHP_FUNCTION(git_commit_id) +{ + zval *commit; + php_git2_t *_commit; + char out[41] = {0}; + const git_oid *id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + id = git_blob_id(PHP_GIT2_V(_commit, commit)); + + git_oid_fmt(out, id); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_commit_owner(commit) +*/ +PHP_FUNCTION(git_commit_owner) +{ + zval *commit; + php_git2_t *_commit, *result; + git_repository *repository; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + PHP_GIT2_MAKE_RESOURCE(result); + repository = git_commit_owner(PHP_GIT2_V(_commit, commit)); + + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_commit_message_encoding(commit) +*/ +PHP_FUNCTION(git_commit_message_encoding) +{ + zval *commit; + php_git2_t *_commit; + const char *encoding; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + encoding = git_commit_message_encoding(PHP_GIT2_V(_commit, commit)); + RETURN_STRING(encoding, 1); +} + +/* {{{ proto resource git_commit_message(commit) +*/ +PHP_FUNCTION(git_commit_message) +{ + zval *commit; + php_git2_t *_commit; + const char *message; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + message = git_commit_message(PHP_GIT2_V(_commit, commit)); + RETURN_STRING(message, 1); +} + +/* {{{ proto resource git_commit_message_raw(commit) +*/ +PHP_FUNCTION(git_commit_message_raw) +{ + zval *commit; + php_git2_t *_commit; + const char *message; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + message = git_commit_message_raw(PHP_GIT2_V(_commit, commit)); + RETURN_STRING(message, 1); +} + +/* {{{ proto resource git_commit_time(commit) +*/ +PHP_FUNCTION(git_commit_time) +{ + zval *commit; + php_git2_t *_commit; + git_time_t time; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + time = git_commit_time(PHP_GIT2_V(_commit, commit)); + + /* NOTE(chobie) should this return as a string? */ + RETURN_LONG(time); +} + +/* {{{ proto long git_commit_time_offset(commit) +*/ +PHP_FUNCTION(git_commit_time_offset) +{ + zval *commit; + php_git2_t *_commit; + int result = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_commit_time_offset(PHP_GIT2_V(_commit, commit)); + RETURN_LONG(result); +} + +/* {{{ proto resource git_commit_committer(commit) +*/ +PHP_FUNCTION(git_commit_committer) +{ + zval *commit; + php_git2_t *git2; + git_signature *committer; + zval *result, *datetime, *timezone; + php_timezone_obj *tzobj; + char time_str[12] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + committer = git_commit_committer(PHP_GIT2_V(git2, commit)); + + MAKE_STD_ZVAL(result); + array_init(result); + + MAKE_STD_ZVAL(datetime); + MAKE_STD_ZVAL(timezone); + + datetime_instantiate(php_date_get_date_ce(), datetime TSRMLS_CC); + snprintf(time_str,12,"%c%ld",'@', committer->when.time); + + datetime_instantiate(php_date_get_timezone_ce(), timezone TSRMLS_CC); + tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone TSRMLS_CC); + tzobj->initialized = 1; + tzobj->type = TIMELIB_ZONETYPE_OFFSET; + tzobj->tzi.utc_offset = -committer->when.offset; /* NOTE(chobie): probably this fine */ + + php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), NULL, 0, NULL, timezone, 0 TSRMLS_CC); + + add_assoc_string_ex(result, ZEND_STRS("name"), committer->name, 1); + add_assoc_string_ex(result, ZEND_STRS("email"), committer->email, 1); + add_assoc_zval_ex(result, ZEND_STRS("time"), datetime); + + zval_ptr_dtor(&timezone); + + RETURN_ZVAL(result, 0, 1); +} + +/* {{{ proto resource git_commit_raw_header(commit) +*/ +PHP_FUNCTION(git_commit_raw_header) +{ + zval *commit; + php_git2_t *_commit; + const char *header; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + header = git_commit_raw_header(PHP_GIT2_V(_commit, commit)); + + RETURN_STRING(header, 1); +} + +/* {{{ proto resource git_commit_tree_id(commit) +*/ +PHP_FUNCTION(git_commit_tree_id) +{ + zval *commit; + php_git2_t *_commit; + char out[41] = {0}; + const git_oid *id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + id = git_commit_tree_id(PHP_GIT2_V(_commit, commit)); + + git_oid_fmt(out, id); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_commit_parentcount(commit) +*/ +PHP_FUNCTION(git_commit_parentcount) +{ + zval *commit; + php_git2_t *_commit; + unsigned long count; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &commit) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + count = git_commit_parentcount(PHP_GIT2_V(_commit, commit)); + RETURN_LONG(count); +} + +/* {{{ proto resource git_commit_parent(commit, n) +*/ +PHP_FUNCTION(git_commit_parent) +{ + zval *commit; + php_git2_t *_commit, *result; + git_commit *parent; + long n = 0; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &commit, &n) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_commit_parent(&parent, PHP_GIT2_V(_commit, commit), n); + if (php_git2_check_error(error, "git_commit_parent" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, commit) = parent; + result->type = PHP_GIT2_TYPE_COMMIT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_commit_parent_id(commit, n) +*/ +PHP_FUNCTION(git_commit_parent_id) +{ + zval *commit; + php_git2_t *_commit; + long n; + git_oid *oid; + char out[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &commit, &n) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + oid = git_commit_parent_id(PHP_GIT2_V(_commit, commit), n); + git_oid_fmt(out, oid); + + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_commit_nth_gen_ancestor(commit, n) +*/ +PHP_FUNCTION(git_commit_nth_gen_ancestor) +{ + zval *commit; + php_git2_t *_commit, *result; + git_commit *ancestor; + long n; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &commit, &n) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_commit_nth_gen_ancestor(&ancestor, PHP_GIT2_V(_commit, commit), n); + if (php_git2_check_error(error, "git_commit_nth_gen_ancestor" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, commit) = ancestor; + result->type = PHP_GIT2_TYPE_COMMIT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); + +} + +static zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC) +{ + zval *result = NULL, **element; + + if (zend_hash_find(Z_ARRVAL_P(array), name, name_len, (void**)&element) == SUCCESS) { + result = *element; + } + + return result; +} + +static void php_git2_array_to_signature(git_signature *signature, zval *author TSRMLS_DC) +{ + zval *name = NULL, *email = NULL, *time = NULL; + + name = php_git2_read_arrval(author, ZEND_STRS("name") TSRMLS_CC); + email = php_git2_read_arrval(author, ZEND_STRS("email") TSRMLS_CC); + time = php_git2_read_arrval(author, ZEND_STRS("time") TSRMLS_CC); + + signature->name = Z_STRVAL_P(name); + signature->email = Z_STRVAL_P(email); + + //instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only TSRMLS_DC); + if (time != NULL && + Z_TYPE_P(time) == IS_OBJECT && + instanceof_function_ex(Z_OBJCE_P(time), php_date_get_date_ce(), 0 TSRMLS_CC)) { + php_date_obj *date; + + date = (php_date_obj *)zend_object_store_get_object(time TSRMLS_CC); + signature->when.time = date->time->sse; + signature->when.offset = date->time->z; + } +} + +/* {{{ proto resource git_commit_create( + resource $repo, string $update_ref, array $author, array $committer, + string $message_encoding, string $message, resource $tree, array $parents) +*/ +PHP_FUNCTION(git_commit_create) +{ + zval *repo, *tree, *parents, *committer, *author, **element; + char *update_ref = {0}, *message_encoding = {0}, *message = {0}; + int update_ref_len, message_encoding_len, message_len, parent_count = 0, error = 0, i; + php_git2_t *_repo, *_author, *_committer, *_tree; + git_signature __author, __committer; + char out[41] = {0}; + git_oid oid; + const git_commit **__parents = NULL; + HashPosition pos; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsaassra", &repo, &update_ref, &update_ref_len, &author, + &committer, &message_encoding, &message_encoding_len, &message, + &message_len, &tree, &parents) == FAILURE) { + return; + } + + memset(&__author, '\0', sizeof(git_signature)); + memset(&__committer, '\0', sizeof(git_signature)); + + if (committer == NULL || Z_TYPE_P(committer) == IS_NULL) { + committer = author; + } + + php_git2_array_to_signature(&__author, author TSRMLS_CC); + php_git2_array_to_signature(&__committer, committer TSRMLS_CC); + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_tree, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + parent_count = zend_hash_num_elements(Z_ARRVAL_P(parents)); + __parents = emalloc(parent_count * sizeof(void *)); + for(i = 0, zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(parents), &pos); + zend_hash_get_current_data_ex(Z_ARRVAL_P(parents), (void **)&element, &pos) == SUCCESS; + zend_hash_move_forward_ex(Z_ARRVAL_P(parents), &pos) + ) { + git_commit *p = NULL; + git_oid parent_oid; + + if (Z_TYPE_PP(element) == IS_STRING) { + error = git_oid_fromstr(&oid, Z_STRVAL_PP(element)); + git_commit_lookup(&p, PHP_GIT2_V(_repo, repository), &oid); + } else if (Z_TYPE_PP(element) == IS_RESOURCE) { + php_git2_t *t; + ZEND_FETCH_RESOURCE(t, php_git2_t*, element, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + p = PHP_GIT2_V(t, commit); + } + + __parents[i] = p; + i++; + } + + error = git_commit_create( + &oid, + PHP_GIT2_V(_repo, repository), + update_ref, + &__author, + &__committer, + message_encoding, + message, + PHP_GIT2_V(_tree, tree), + parent_count, + __parents + ); + + efree(__parents); + + if (php_git2_check_error(error, "git_commit_create" TSRMLS_CC)) { + RETURN_FALSE + } + + git_oid_fmt(out, &oid); + RETURN_STRING(out, 1); +} \ No newline at end of file diff --git a/commit.h b/commit.h new file mode 100644 index 0000000000..fd3af615a8 --- /dev/null +++ b/commit.h @@ -0,0 +1,200 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_COMMIT_H +#define PHP_GIT2_COMMIT_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_lookup, 0, 0, 2) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_author, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_tree, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_lookup_prefix, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, len) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_id, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_owner, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_message_encoding, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_message, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_message_raw, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_time, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_time_offset, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_committer, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_raw_header, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_tree_id, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_parentcount, 0, 0, 1) + ZEND_ARG_INFO(0, commit) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_parent, 0, 0, 2) + ZEND_ARG_INFO(0, commit) + ZEND_ARG_INFO(0, n) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_parent_id, 0, 0, 2) + ZEND_ARG_INFO(0, commit) + ZEND_ARG_INFO(0, n) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_nth_gen_ancestor, 0, 0, 2) + ZEND_ARG_INFO(0, commit) + ZEND_ARG_INFO(0, n) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_create, 0, 0, 8) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, update_ref) + ZEND_ARG_INFO(0, author) + ZEND_ARG_INFO(0, committer) + ZEND_ARG_INFO(0, message_encoding) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, tree) + ZEND_ARG_INFO(0, parents) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_commit_lookup(resource $repository, mixed $oid) +*/ +PHP_FUNCTION(git_commit_lookup); + +/* {{{ proto resource git_commit_author(resource $commit) +*/ +PHP_FUNCTION(git_commit_author); + +/* {{{ proto resource git_commit_tree(resource $commit) +*/ +PHP_FUNCTION(git_commit_tree); + +/* {{{ proto resource git_commit_lookup_prefix(repo, id, len) +*/ +PHP_FUNCTION(git_commit_lookup_prefix); + +/* {{{ proto resource git_commit_id(commit) +*/ +PHP_FUNCTION(git_commit_id); + +/* {{{ proto resource git_commit_owner(commit) +*/ +PHP_FUNCTION(git_commit_owner); + +/* {{{ proto resource git_commit_message_encoding(commit) +*/ +PHP_FUNCTION(git_commit_message_encoding); + +/* {{{ proto resource git_commit_message(commit) +*/ +PHP_FUNCTION(git_commit_message); + +/* {{{ proto resource git_commit_message_raw(commit) +*/ +PHP_FUNCTION(git_commit_message_raw); + +/* {{{ proto resource git_commit_time(commit) +*/ +PHP_FUNCTION(git_commit_time); + +/* {{{ proto long git_commit_time_offset(commit) +*/ +PHP_FUNCTION(git_commit_time_offset); + +/* {{{ proto resource git_commit_committer(commit) +*/ +PHP_FUNCTION(git_commit_committer); + +/* {{{ proto resource git_commit_raw_header(commit) +*/ +PHP_FUNCTION(git_commit_raw_header); + +/* {{{ proto resource git_commit_tree(commit) +*/ +PHP_FUNCTION(git_commit_tree); + +/* {{{ proto resource git_commit_tree_id(commit) +*/ +PHP_FUNCTION(git_commit_tree_id); + +/* {{{ proto resource git_commit_parentcount(commit) +*/ +PHP_FUNCTION(git_commit_parentcount); + +/* {{{ proto resource git_commit_parent(commit, n) +*/ +PHP_FUNCTION(git_commit_parent); + +/* {{{ proto resource git_commit_parent_id(commit, n) +*/ +PHP_FUNCTION(git_commit_parent_id); + +/* {{{ proto resource git_commit_nth_gen_ancestor(commit, n) +*/ +PHP_FUNCTION(git_commit_nth_gen_ancestor); + +/* {{{ proto resource git_commit_create( + resource $repo, string $update_ref, array $author, array $committer, + string $message_encoding, string $message, resource $tree, array $parents) +*/ +PHP_FUNCTION(git_commit_create); + +#endif \ No newline at end of file diff --git a/config.m4 b/config.m4 index 827e609975..54a6021758 100644 --- a/config.m4 +++ b/config.m4 @@ -1,38 +1,28 @@ PHP_ARG_ENABLE(git2, Whether to enable the "git2" extension, [ --enable-git2 Enable "php-git2" extension support]) +PHP_ARG_ENABLE(git2-debug, for git2 debug support, + [ --enable-git2-debug Enable git2 debug support], no, no) + if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, git2.c \ - repository.c \ - commit.c \ - blob.c \ - tree.c \ - tree_builder.c \ - tree_entry.c \ - signature.c \ - walker.c \ - reference.c \ - index.c \ - index_entry.c \ - config.c \ - remote.c \ - tag.c \ - odb.c \ - odb_object.c \ - backend.c \ - , $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) + # for now CFLAGS=" $CFLAGS -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Winline -Wunused-macros -Wredundant-decls -Wstrict-aliasing=2 -Wswitch-enum -Wdeclaration-after-statement" + + if test "$PHP_GIT2_DEBUG" != "no"; then + CFLAGS="-g -O0 $CFLAGS" + fi + PHP_ADD_LIBPATH($ext_srcdir/libgit2/build, GIT2_SHARED_LIBADD) PHP_ADD_LIBRARY(git2,, GIT2_SHARED_LIBADD) PHP_SUBST([CFLAGS]) ifdef([PHP_ADD_EXTENSION_DEP], [ - PHP_ADD_EXTENSION_DEP(git, spl, true) + PHP_ADD_EXTENSION_DEP(git2, spl, true) ]) - fi diff --git a/fe.php b/fe.php new file mode 100644 index 0000000000..da2f61e4e7 --- /dev/null +++ b/fe.php @@ -0,0 +1,9 @@ +.h (0|1) [filter] > target.h or target.c + +$data = file_get_contents($_SERVER['argv'][1]); + +$table = array(); +$buffer = ""; +if (preg_match_all("/GIT_EXTERN\((.+?)\)\s*([a-zA-Z0-9_-]+)\((.+?)\);/s", $data, $match)) { + + for ($i = 0; $i < count($match[0]); $i++) { + $tmp = array( + "args" => array(), + ); + + $list = array_map("trim", explode(",", $match[3][$i])); + + $tmp['name'] = $match[2][$i]; + $tmp['retval'] = $match[1][$i]; + + $d = count($list); + if (preg_match("/\*\*/", $list[0])) { + $d--; + } + + if (isset($_SERVER['argv'][3]) && !preg_match("/{$_SERVER['argv'][3]}/", $match[2][$i])) { + continue; + } + + $match[3][$i] = trim(preg_replace("/\r?\n/", "", $match[3][$i])); + $match[3][$i] = trim(preg_replace("/\t/", " ", $match[3][$i])); + + if ($_SERVER['argv'][2] == "0") { + $buffer .= "ZEND_BEGIN_ARG_INFO_EX(arginfo_{$match[2][$i]}, 0, 0, $d)\n"; + } + + $o = 0; + foreach ($list as $l) { + $b = array_map(function($l){return trim($l, " *");}, explode(" ", $l)); + $type = substr($l, 0, strrpos($l, " ")); + + $n = array_pop($b); + $b = array_pop($b); + + if ($o == 0 && (preg_match("/(\*\*|out)/", $l) || preg_match("/(write|create|new)/", $match[2][$i]))) { + $w = 1; + $tmp['retval'] = "resource"; + }else { + $w = 0; + } + + if (!$w) { + $tmp['args'][] = array( + "write" => $w, + "name" => $n, + "type" => $type, + ); + if ($_SERVER['argv'][2] == "0") { + $buffer .= "\tZEND_ARG_INFO(0, $n)\n"; + } + } + + $o++; + } + + if ($_SERVER['argv'][2] == "0") { + $buffer .= "ZEND_END_ARG_INFO()\n"; + $buffer .= "\n"; + + } + + $table[] = $tmp; + } +} + +if ($_SERVER['argv'][2] == "1") { + $buffer .= '#include "php_git2.h"' . "\n"; + $buffer .= '#include "php_git2_priv.h"' . "\n"; + $buffer .= '#include ".h"' . "\n"; +} + + +foreach ($table as $func) { + $ret = getReturnType($func['retval']); + + $t = array(); + foreach ($func['args'] as $a) { + $t[] = $a['name']; + } + $sig = join(", ", $t); + + $buffer .= "/* {{{ proto $ret {$func['name']}($sig)\n"; + $buffer .= "*/\n"; + + if ($_SERVER['argv'][2] == "0") { + $buffer .= "PHP_FUNCTION({$func['name']});\n"; + $buffer .= "\n"; + } else { + $buffer .= "PHP_FUNCTION({$func['name']})\n"; + $buffer .= "{\n"; + $buffer .= getDeclarations($func); + + $buffer .= "\t/* TODO(chobie): implement this */\n"; + $buffer .= "\tphp_error_docref(NULL TSRMLS_CC, E_WARNING, " . '"' . "{$func['name']} not implemented yet" . '"' . ");\n"; + $buffer .= "\treturn;\n\n"; + + $buffer .= "\tif (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,\n"; + $buffer .= "\t\t" . sprintf('"%s", %s) == FAILURE) {%s', getParseStr($func), getParseStr2($func), "\n"); + $buffer .= "\t\treturn;\n"; + $buffer .= "\t}\n"; + if (hasResource($func)) { + $t = $func['args'][0]; + $buffer .= "\tZEND_FETCH_RESOURCE(_{$t['name']}, php_git2_t*, &{$t['name']}, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);\n"; + } + $buffer .= "}\n"; + $buffer .= "\n"; + } +} + +echo $buffer; + + +function hasResource($func) +{ + $result = false; + foreach ($func['args'] as $arg) { + if (preg_match("/char/", $arg['type'])) { + } else if (preg_match("/git_oid/", $arg['type'])) { + } else if (preg_match("/git_/", $arg['type'])) { + $result = true; + } + } + return $result; +} + +function getDeclarations($func) +{ + $result = array(); + foreach ($func['args'] as $arg) { + if (preg_match("/char/", $arg['type'])) { + $result[] = "\tchar *" . $arg['name'] . " = {0};"; + $result[] = "\tint " . $arg['name'] . "_len;"; + } else if (preg_match("/int/", $arg['type'])) { + $result[] = "\tlong " . $arg['name'] . ";"; + } else if (preg_match("/git_oid/", $arg['type'])) { + $result[] = "\tchar *" . $arg['name'] . " = {0};"; + $result[] = "\tint " . $arg['name'] . "_len;"; + } else if (preg_match("/git_/", $arg['type'])) { + $result[] = "\tzval *" . $arg['name'] . ";"; + $result[] = "\tphp_git2_t *_" . $arg['name'] . ";"; + } + } + $result[] = ""; + $result[] = ""; + + return join("\n", $result); +} + +function getParseStr($func) +{ + $result = array(); + foreach ($func['args'] as $arg) { + if (preg_match("/char/", $arg['type'])) { + $result[] = "s"; + } else if (preg_match("/git_oid/", $arg['type'])) { + $result[] = "s"; + } else if (preg_match("/int/", $arg['type'])) { + $result[] = "l"; + } else if (preg_match("/git_/", $arg['type'])) { + $result[] = "r"; + } + } + + return join("", $result); +} + +function getParseStr2($func) +{ + $result = array(); + foreach ($func['args'] as $arg) { + $result[] = "&" . $arg['name']; + if (preg_match("/char/", $arg['type'])) { + $result[] = "&" . $arg['name'] . "_len"; + } else if (preg_match("/git_oid/", $arg['type'])) { + $result[] = "&" . $arg['name'] . "_len"; + } + } + + return join(", ", $result); +} + +function getReturnType($name) +{ + switch($name) { + case "int": + return "long"; + case "void": + return "void"; + default: + return "resource"; + } +} \ No newline at end of file diff --git a/helper.c b/helper.c new file mode 100644 index 0000000000..b91f0313b6 --- /dev/null +++ b/helper.c @@ -0,0 +1,18 @@ +#include "php_git2.h" +#include "helper.h" + +int php_git2_check_error(int error_code, const char *action TSRMLS_DC) +{ + int result = 0; + const git_error * error; + if (!error_code) { + return result; + } + + error = giterr_last(); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "WARNING %d %s - %s", + error_code, action, (error && error->message) ? error->message : "???"); + + result = 1; + return result; +} diff --git a/helper.h b/helper.h new file mode 100644 index 0000000000..dd6765b7b0 --- /dev/null +++ b/helper.h @@ -0,0 +1,33 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_HELPER_H +#define PHP_GIT2_HELPER_H + +/* NOTE(chobie): all functions should have `php_git2_` prefix */ + +int php_git2_check_error(int error_code, const char *action TSRMLS_DC); + +#endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c new file mode 100644 index 0000000000..787b5f66f6 --- /dev/null +++ b/php_git2.c @@ -0,0 +1,295 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "repository.h" +#include "commit.h" +#include "tree.h" +#include "clone.h" +#include "blob.h" +#include "revwalk.h" +#include "treebuilder.h" +#include "reference.h" + +int git2_resource_handle; + +void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) +{ + php_git2_t *resource = (php_git2_t *)rsrc->ptr; + if (resource->should_free_v) { + switch (resource->type) { + case PHP_GIT2_TYPE_REPOSITORY: + git_repository_free(PHP_GIT2_V(resource, repository)); + break; + case PHP_GIT2_TYPE_COMMIT: + git_commit_free(PHP_GIT2_V(resource, commit)); + break; + case PHP_GIT2_TYPE_TREE: + git_tree_free(PHP_GIT2_V(resource, tree)); + break; + case PHP_GIT2_TYPE_TREE_ENTRY: + git_tree_entry_free(PHP_GIT2_V(resource, tree_entry)); + break; + case PHP_GIT2_TYPE_BLOB: + git_blob_free(PHP_GIT2_V(resource, blob)); + case PHP_GIT2_TYPE_REVWALK: + git_revwalk_free(PHP_GIT2_V(resource, revwalk)); + case PHP_GIT2_TYPE_TREEBUILDER: + git_treebuilder_free(PHP_GIT2_V(resource, treebuilder)); + case PHP_GIT2_TYPE_REFERENCE: + git_reference_free(PHP_GIT2_V(resource, reference)); + default: + break; + } + } + + efree(resource); +} + +ZEND_DECLARE_MODULE_GLOBALS(git2); + +static zend_class_entry *php_git2_get_exception_base(TSRMLS_D) +{ +#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2) + return zend_exception_get_default(); +#else + return zend_exception_get_default(TSRMLS_C); +#endif +} + +static zend_function_entry php_git2_functions[] = { + PHP_FE(git_repository_new, arginfo_git_repository_new) + PHP_FE(git_repository_init, arginfo_git_repository_init) + PHP_FE(git_repository_open_bare, arginfo_git_repository_open_bare) + PHP_FE(git_repository_open, arginfo_git_repository_open) + PHP_FE(git_repository_get_namespace, arginfo_git_repository_get_namespace) + PHP_FE(git_repository_workdir, arginfo_git_repository_workdir) + + PHP_FE(git_clone, arginfo_git_clone) + + /* reference */ + PHP_FE(git_reference_lookup, arginfo_git_reference_lookup) + PHP_FE(git_reference_name_to_id, arginfo_git_reference_name_to_id) + PHP_FE(git_reference_dwim, arginfo_git_reference_dwim) + PHP_FE(git_reference_symbolic_create, arginfo_git_reference_symbolic_create) + PHP_FE(git_reference_create, arginfo_git_reference_create) + PHP_FE(git_reference_target, arginfo_git_reference_target) + PHP_FE(git_reference_target_peel, arginfo_git_reference_target_peel) + PHP_FE(git_reference_symbolic_target, arginfo_git_reference_symbolic_target) + PHP_FE(git_reference_type, arginfo_git_reference_type) + PHP_FE(git_reference_name, arginfo_git_reference_name) + PHP_FE(git_reference_resolve, arginfo_git_reference_resolve) + PHP_FE(git_reference_owner, arginfo_git_reference_owner) + PHP_FE(git_reference_symbolic_set_target, arginfo_git_reference_symbolic_set_target) + PHP_FE(git_reference_set_target, arginfo_git_reference_set_target) + PHP_FE(git_reference_rename, arginfo_git_reference_rename) + PHP_FE(git_reference_delete, arginfo_git_reference_delete) + PHP_FE(git_reference_list, arginfo_git_reference_list) + PHP_FE(git_reference_foreach, arginfo_git_reference_foreach) + PHP_FE(git_reference_foreach_name, arginfo_git_reference_foreach_name) + PHP_FE(git_reference_free, arginfo_git_reference_free) + PHP_FE(git_reference_cmp, arginfo_git_reference_cmp) + PHP_FE(git_reference_iterator_new, arginfo_git_reference_iterator_new) + PHP_FE(git_reference_iterator_glob_new, arginfo_git_reference_iterator_glob_new) + PHP_FE(git_reference_next, arginfo_git_reference_next) + PHP_FE(git_reference_next_name, arginfo_git_reference_next_name) + PHP_FE(git_reference_iterator_free, arginfo_git_reference_iterator_free) + PHP_FE(git_reference_foreach_glob, arginfo_git_reference_foreach_glob) + PHP_FE(git_reference_has_log, arginfo_git_reference_has_log) + PHP_FE(git_reference_is_branch, arginfo_git_reference_is_branch) + PHP_FE(git_reference_is_remote, arginfo_git_reference_is_remote) + PHP_FE(git_reference_is_tag, arginfo_git_reference_is_tag) + PHP_FE(git_reference_normalize_name, arginfo_git_reference_normalize_name) + PHP_FE(git_reference_peel, arginfo_git_reference_peel) + PHP_FE(git_reference_is_valid_name, arginfo_git_reference_is_valid_name) + PHP_FE(git_reference_shorthand, arginfo_git_reference_shorthand) + + /* commit */ + PHP_FE(git_commit_lookup, arginfo_git_commit_lookup) + PHP_FE(git_commit_author, arginfo_git_commit_author) + PHP_FE(git_commit_tree, arginfo_git_commit_tree) + PHP_FE(git_commit_lookup_prefix, arginfo_git_commit_lookup_prefix) + PHP_FE(git_commit_id, arginfo_git_commit_id) + PHP_FE(git_commit_owner, arginfo_git_commit_owner) + PHP_FE(git_commit_message_encoding, arginfo_git_commit_message_encoding) + PHP_FE(git_commit_message, arginfo_git_commit_message) + PHP_FE(git_commit_message_raw, arginfo_git_commit_message_raw) + PHP_FE(git_commit_time, arginfo_git_commit_time) + PHP_FE(git_commit_time_offset, arginfo_git_commit_time_offset) + PHP_FE(git_commit_committer, arginfo_git_commit_committer) + PHP_FE(git_commit_raw_header, arginfo_git_commit_raw_header) + PHP_FE(git_commit_tree_id, arginfo_git_commit_tree_id) + PHP_FE(git_commit_parentcount, arginfo_git_commit_parentcount) + PHP_FE(git_commit_parent, arginfo_git_commit_parent) + PHP_FE(git_commit_parent_id, arginfo_git_commit_parent_id) + PHP_FE(git_commit_nth_gen_ancestor, arginfo_git_commit_nth_gen_ancestor) + PHP_FE(git_commit_create, arginfo_git_commit_create) + + /* tree */ + PHP_FE(git_tree_free, arginfo_git_tree_free) + PHP_FE(git_tree_id, arginfo_git_tree_id) + PHP_FE(git_tree_lookup, arginfo_git_tree_lookup) + PHP_FE(git_tree_owner, arginfo_git_tree_owner) + PHP_FE(git_tree_walk, arginfo_git_tree_walk) + + PHP_FE(git_tree_entry_byoid, arginfo_git_tree_entry_byoid) + PHP_FE(git_tree_entry_byindex, arginfo_git_tree_entry_byindex) + PHP_FE(git_tree_entry_byname, arginfo_git_tree_entry_byname) + PHP_FE(git_tree_entry_bypath, arginfo_git_tree_entry_bypath) + PHP_FE(git_tree_entry_id, arginfo_git_tree_entry_id) + PHP_FE(git_tree_entry_name, arginfo_git_tree_entry_name) + PHP_FE(git_tree_entry_type, arginfo_git_tree_entry_type) + PHP_FE(git_tree_entrycount, arginfo_git_tree_entrycount) + PHP_FE(git_tree_entry_filemode, arginfo_git_tree_entry_filemode) + PHP_FE(git_tree_entry_filemode_raw, arginfo_git_tree_entry_filemode_raw) + PHP_FE(git_tree_entry_cmp, arginfo_git_tree_entry_cmp) + PHP_FE(git_tree_entry_free, arginfo_git_tree_entry_free) + PHP_FE(git_tree_entry_dup, arginfo_git_tree_entry_dup) + + /* treebuilder */ + PHP_FE(git_treebuilder_create, arginfo_git_treebuilder_create) + PHP_FE(git_treebuilder_clear, arginfo_git_treebuilder_clear) + PHP_FE(git_treebuilder_entrycount, arginfo_git_treebuilder_entrycount) + PHP_FE(git_treebuilder_free, arginfo_git_treebuilder_free) + PHP_FE(git_treebuilder_get, arginfo_git_treebuilder_get) + PHP_FE(git_treebuilder_insert, arginfo_git_treebuilder_insert) + PHP_FE(git_treebuilder_remove, arginfo_git_treebuilder_remove) + PHP_FE(git_treebuilder_filter, arginfo_git_treebuilder_filter) + PHP_FE(git_treebuilder_write, arginfo_git_treebuilder_write) + + /* blob */ + PHP_FE(git_blob_create_frombuffer, arginfo_git_blob_create_frombuffer) + PHP_FE(git_blob_create_fromchunks, arginfo_git_blob_create_fromchunks) + PHP_FE(git_blob_create_fromdisk, arginfo_git_blob_create_fromdisk) + PHP_FE(git_blob_create_fromworkdir, arginfo_git_blob_create_fromworkdir) + PHP_FE(git_blob_filtered_content, arginfo_git_blob_filtered_content) + PHP_FE(git_blob_free, arginfo_git_blob_free) + PHP_FE(git_blob_id, arginfo_git_blob_id) + PHP_FE(git_blob_is_binary, arginfo_git_blob_is_binary) + PHP_FE(git_blob_lookup, arginfo_git_blob_lookup) + PHP_FE(git_blob_lookup_prefix, arginfo_git_blob_lookup_prefix) + PHP_FE(git_blob_owner, arginfo_git_blob_owner) + PHP_FE(git_blob_rawcontent, arginfo_git_blob_rawcontent) + PHP_FE(git_blob_rawsize, arginfo_git_blob_rawsize) + + /* revwalk */ + PHP_FE(git_revwalk_new, arginfo_git_revwalk_new) + PHP_FE(git_revwalk_reset, arginfo_git_revwalk_reset) + PHP_FE(git_revwalk_push, arginfo_git_revwalk_push) + PHP_FE(git_revwalk_push_glob, arginfo_git_revwalk_push_glob) + PHP_FE(git_revwalk_push_head, arginfo_git_revwalk_push_head) + PHP_FE(git_revwalk_hide, arginfo_git_revwalk_hide) + PHP_FE(git_revwalk_hide_glob, arginfo_git_revwalk_hide_glob) + PHP_FE(git_revwalk_hide_head, arginfo_git_revwalk_hide_head) + PHP_FE(git_revwalk_push_ref, arginfo_git_revwalk_push_ref) + PHP_FE(git_revwalk_hide_ref, arginfo_git_revwalk_hide_ref) + PHP_FE(git_revwalk_next, arginfo_git_revwalk_next) + PHP_FE(git_revwalk_sorting, arginfo_git_revwalk_sorting) + PHP_FE(git_revwalk_push_range, arginfo_git_revwalk_push_range) + PHP_FE(git_revwalk_simplify_first_parent, arginfo_git_revwalk_simplify_first_parent) + PHP_FE(git_revwalk_free, arginfo_git_revwalk_free) + PHP_FE(git_revwalk_repository, arginfo_git_revwalk_repository) + + PHP_FE_END +}; + +PHP_MINFO_FUNCTION(git2) +{ + char buf[32] = {0}; + int major, minor, rev; + + php_printf("PHP Git2 Extension\n"); + + git_libgit2_version(&major, &minor, &rev); + snprintf(buf, 32, "%d.%d.%d", major, minor, rev); + + php_info_print_table_start(); + php_info_print_table_header(2, "Git2 Support", "enabled"); + php_info_print_table_end(); +} + +PHP_INI_BEGIN() + STD_PHP_INI_BOOLEAN("git2.dummy", "1", PHP_INI_ALL, OnUpdateLong, dummy, zend_git2_globals, git2_globals) +PHP_INI_END() + +static PHP_GINIT_FUNCTION(git2) +{ +} + +static PHP_GSHUTDOWN_FUNCTION(git2) +{ +} + +PHP_MINIT_FUNCTION(git2) +{ + REGISTER_INI_ENTRIES(); + + git2_resource_handle = zend_register_list_destructors_ex(destruct_git2, NULL, PHP_GIT2_RESOURCE_NAME, module_number); + return SUCCESS; +} + +PHP_RINIT_FUNCTION(git2) +{ + git_threads_init(); + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(git2) +{ + UNREGISTER_INI_ENTRIES(); + return SUCCESS; +} + +PHP_RSHUTDOWN_FUNCTION(git2) +{ + git_threads_shutdown(); + return SUCCESS; +} + +zend_module_entry git2_module_entry = { +#if ZEND_MODULE_API_NO >= 20010901 + STANDARD_MODULE_HEADER, +#endif + PHP_GIT2_EXTNAME, + php_git2_functions, /* Functions */ + PHP_MINIT(git2), /* MINIT */ + PHP_MSHUTDOWN(git2), /* MSHUTDOWN */ + PHP_RINIT(git2), /* RINIT */ + PHP_RSHUTDOWN(git2), /* RSHUTDOWN */ + PHP_MINFO(git2), /* MINFO */ +#if ZEND_MODULE_API_NO >= 20010901 + PHP_GIT2_EXTVER, +#endif + PHP_MODULE_GLOBALS(git2), + PHP_GINIT(git2), + PHP_GSHUTDOWN(git2), + NULL, + STANDARD_MODULE_PROPERTIES_EX +}; + +#ifdef COMPILE_DL_GIT2 +ZEND_GET_MODULE(git2) +#endif \ No newline at end of file diff --git a/php_git2.h b/php_git2.h new file mode 100644 index 0000000000..1128ba472b --- /dev/null +++ b/php_git2.h @@ -0,0 +1,104 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_H +#define PHP_GIT2_H + +#define PHP_GIT2_EXTNAME "git2" +#define PHP_GIT2_EXTVER "0.2.0" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "zend.h" +#include "zend_interfaces.h" +#include "zend_exceptions.h" +#include "ext/standard/php_smart_str.h" +#include "ext/spl/spl_exceptions.h" +#include "ext/standard/php_var.h" +#include "ext/standard/php_string.h" +#include "ext/standard/php_incomplete_class.h" +#include "ext/standard/info.h" +#include "ext/standard/php_array.h" +#include "limits.h" + +#include "git2.h" + +#include "date/php_date.h" + +#include + +/* Define the entry point symbol + * Zend will use when loading this module + */ +extern zend_module_entry git2_module_entry; +#define phpext_git2_ptr &git2_module_entry + +ZEND_BEGIN_MODULE_GLOBALS(git2) + long dummy; +ZEND_END_MODULE_GLOBALS(git2) + +ZEND_EXTERN_MODULE_GLOBALS(git2) + +#ifdef ZTS +#define GIT2G(v) TSRMG(git2_globals_id, zend_git2_globals *, v) +#else +#define GIT2G(v) (git2_globals.v) +#endif + +#define PHP_GIT2_RESOURCE_NAME "git2" + +enum php_git2_resource_type { + PHP_GIT2_TYPE_REPOSITORY, + PHP_GIT2_TYPE_COMMIT, + PHP_GIT2_TYPE_TREE, + PHP_GIT2_TYPE_TREE_ENTRY, + PHP_GIT2_TYPE_BLOB, + PHP_GIT2_TYPE_REVWALK, + PHP_GIT2_TYPE_TREEBUILDER, + PHP_GIT2_TYPE_REFERENCE, +}; + +typedef struct php_git2_t { + enum php_git2_resource_type type; + union { + git_repository *repository; + git_commit *commit; + git_tree *tree; + git_tree_entry *tree_entry; + git_blob *blob; + git_revwalk *revwalk; + git_treebuilder *treebuilder; + git_reference *reference; + } v; + int should_free_v; + int resource_id; + int mutable; +} php_git2_t; + +#endif /* PHP_GIT2_H */ \ No newline at end of file diff --git a/php_git2_priv.h b/php_git2_priv.h new file mode 100644 index 0000000000..2749584e11 --- /dev/null +++ b/php_git2_priv.h @@ -0,0 +1,62 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_PRIV_H +#define PHP_GIT2_PRIV_H + +extern int git2_resource_handle; + +#if PHP_VERSION_ID>=50399 +#define PHP_GIT2_LIST_INSERT(type, handle) zend_list_insert(type, handle TSRMLS_CC) +#else +#define PHP_GIT2_LIST_INSERT(type, handle) zend_list_insert(type, handle) +#endif + +#define PHP_GIT2_V(git2, type) git2->v.type + +#define PHP_GIT2_MAKE_RESOURCE(val) \ +do {\ + val = (php_git2_t *)emalloc(sizeof(php_git2_t));\ + if (!val) {\ + php_error_docref(NULL TSRMLS_CC, E_ERROR, "emalloc failed");\ + RETURN_FALSE;\ + }\ + val->should_free_v = 0;\ + val->type = 0;\ + val->mutable = 0;\ +} while (0);\ + + +#define PHP_GIT2_MAKE_RESOURCE_NOCHECK(val) \ +do {\ + val = (php_git2_t *)emalloc(sizeof(php_git2_t));\ + val->should_free_v = 0;\ + val->type = 0;\ + val->mutable = 0;\ +} while (0);\ + +#include "helper.h" + +#endif \ No newline at end of file diff --git a/reference.c b/reference.c new file mode 100644 index 0000000000..99447eee68 --- /dev/null +++ b/reference.c @@ -0,0 +1,804 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "reference.h" + +/* {{{ proto resource git_reference_lookup(repo, name) +*/ +PHP_FUNCTION(git_reference_lookup) +{ + zval *repo; + php_git2_t *_repo, *result; + char *name = {0}; + int name_len; + git_reference *out; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &name, &name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_reference_lookup(&out, PHP_GIT2_V(_repo, repository), name); + if (php_git2_check_error(error, "git_reference_lookup" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_name_to_id(repo, name) +*/ +PHP_FUNCTION(git_reference_name_to_id) +{ + zval *repo; + php_git2_t *_repo; + char *name = {0}; + int name_len; + git_oid id; + char out[41] = {0}; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_name_to_id(&id, PHP_GIT2_V(_repo, repository), name); + if (php_git2_check_error(error, "git_reference_lookup" TSRMLS_CC)) { + RETURN_FALSE + } + + git_oid_fmt(out, &id); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_reference_dwim(repo, shorthand) +*/ +PHP_FUNCTION(git_reference_dwim) +{ + zval *repo; + php_git2_t *_repo, *result; + char *shorthand = {0}; + int shorthand_len; + git_reference *out; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &shorthand, &shorthand_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_dwim(&out, PHP_GIT2_V(_repo, repository), shorthand); + if (php_git2_check_error(error, "git_reference_dwim" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_symbolic_create(repo, name, target, force) +*/ +PHP_FUNCTION(git_reference_symbolic_create) +{ + zval *repo; + php_git2_t *_repo, *result; + char *name = {0}; + int name_len; + char *target = {0}; + int target_len; + long force = 0; + int error; + git_reference *out; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rssl", &repo, &name, &name_len, &target, &target_len, &force) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_symbolic_create(&out, PHP_GIT2_V(_repo, repository), name, target, force); + if (php_git2_check_error(error, "git_reference_lookup" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_create(repo, name, id, force) +*/ +PHP_FUNCTION(git_reference_create) +{ + zval *repo; + php_git2_t *_repo, *result; + char *name = {0}; + int name_len; + char *id = {0}; + int id_len; + long force = 0; + git_reference *out; + git_oid oid; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rssl", &repo, &name, &name_len, &id, &id_len, &force) == FAILURE) { + return; + } + if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_create(&out, PHP_GIT2_V(_repo, repository), name, &oid, force); + if (php_git2_check_error(error, "git_reference_lookup" TSRMLS_CC)) { + RETURN_FALSE; + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_target(ref) +*/ +PHP_FUNCTION(git_reference_target) +{ + zval *ref; + php_git2_t *_ref, *result; + const git_reference *out = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + out = git_reference_target(PHP_GIT2_V(_ref, reference)); + if (out = NULL) { + RETURN_FALSE; + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_target_peel(ref) +*/ +PHP_FUNCTION(git_reference_target_peel) +{ + zval *ref; + php_git2_t *_ref; + git_oid *oid; + char out[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + oid = git_reference_target_peel(PHP_GIT2_V(_ref, reference)); + + git_oid_fmt(out, oid); + RETURN_STRING(out, 1); +} + +/* {{{ proto resource git_reference_symbolic_target(ref) +*/ +PHP_FUNCTION(git_reference_symbolic_target) +{ + zval *ref; + php_git2_t *_ref; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_symbolic_target not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_reference_type(ref) +*/ +PHP_FUNCTION(git_reference_type) +{ + zval *ref; + php_git2_t *_ref; + git_ref_t type; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + type = git_tree_entry_type(PHP_GIT2_V(_ref, reference)); + + RETURN_LONG(type); +} + +/* {{{ proto resource git_reference_name(ref) +*/ +PHP_FUNCTION(git_reference_name) +{ + zval *ref; + php_git2_t *_ref; + const char *name; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + name = git_reference_name(PHP_GIT2_V(_ref, reference)); + + RETURN_STRING(name, 1); +} + +/* {{{ proto resource git_reference_resolve(ref) +*/ +PHP_FUNCTION(git_reference_resolve) +{ + zval *ref; + php_git2_t *_ref, *result; + git_reference *out; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_reference_resolve(&out, PHP_GIT2_V(_ref, reference)); + if (php_git2_check_error(error, "git_reference_resolve" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_owner(ref) +*/ +PHP_FUNCTION(git_reference_owner) +{ + zval *ref; + php_git2_t *_ref, *result; + git_repository *repository; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + + PHP_GIT2_MAKE_RESOURCE(result); + repository = git_reference_owner(PHP_GIT2_V(_ref, reference)); + + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_symbolic_set_target(ref, target) +*/ +PHP_FUNCTION(git_reference_symbolic_set_target) +{ + zval *ref; + php_git2_t *_ref, *result; + char *target = {0}; + int target_len; + git_reference *out; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &ref, &target, &target_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_symbolic_set_target(&out, PHP_GIT2_V(_ref, reference), target); + if (php_git2_check_error(error, "git_reference_symbolic_set_target" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_set_target(ref, id) +*/ +PHP_FUNCTION(git_reference_set_target) +{ + zval *ref; + php_git2_t *_ref, *result; + char *id = {0}; + int id_len; + git_oid oid; + int error; + git_reference *out; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &ref, &id, &id_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { + return; + } + error = git_reference_set_target(&out, PHP_GIT2_V(_ref, reference), &oid); + if (php_git2_check_error(error, "git_reference_set_target" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_reference_rename(ref, new_name, force) +*/ +PHP_FUNCTION(git_reference_rename) +{ + zval *ref; + php_git2_t *_ref, *result; + char *new_name = {0}; + int new_name_len; + long force = 0; + git_reference *out; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &ref, &new_name, &new_name_len, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_rename(&out, PHP_GIT2_V(_ref, reference), new_name, force); + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto long git_reference_delete(ref) +*/ +PHP_FUNCTION(git_reference_delete) +{ + zval *ref; + php_git2_t *_ref; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_delete(PHP_GIT2_V(_ref, reference)); + if (php_git2_check_error(error, "git_reference_delete" TSRMLS_CC)) { + RETURN_FALSE + } + zval_ptr_dtor(&ref); +} + +/* {{{ proto long git_reference_list(repo) +*/ +PHP_FUNCTION(git_reference_list) +{ + zval *repo; + php_git2_t *_repo; + git_strarray list; + zval *result; + int error, i; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_reference_list(&list, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_reference_list" TSRMLS_CC)) { + RETURN_FALSE + } + + MAKE_STD_ZVAL(result); + array_init(result); + for (i = 0; i < list.count; i++) { + add_next_index_string(result, list.strings[i], 1); + } + git_strarray_free(&list); + + RETURN_ZVAL(result, 0, 1); +} + +/* {{{ proto long git_reference_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_reference_foreach) +{ + zval *repo; + php_git2_t *_repo; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_foreach not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &repo, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_reference_foreach_name(repo, callback, payload) +*/ +PHP_FUNCTION(git_reference_foreach_name) +{ + zval *repo; + php_git2_t *_repo; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_foreach_name not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &repo, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_reference_free(ref) +*/ +PHP_FUNCTION(git_reference_free) +{ + zval *ref; + php_git2_t *_ref; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_ref->should_free_v) { + git_reference_free(PHP_GIT2_V(_ref, reference)); + _ref->should_free_v = 0; + } + zval_ptr_dtor(&ref); +} + +/* {{{ proto long git_reference_cmp(ref1, ref2) +*/ +PHP_FUNCTION(git_reference_cmp) +{ + zval *e1, *e2; + php_git2_t *g_e1, *g_e2; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &e1, &e2) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(g_e1, php_git2_t*, &e1, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(g_e2, php_git2_t*, &e2, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + result = git_reference_cmp(PHP_GIT2_V(g_e1, reference), PHP_GIT2_V(g_e2, reference)); + RETURN_LONG(result); +} + +/* {{{ proto resource git_reference_iterator_new(repo) +*/ +PHP_FUNCTION(git_reference_iterator_new) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_iterator_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_reference_iterator_glob_new(repo, glob) +*/ +PHP_FUNCTION(git_reference_iterator_glob_new) +{ + zval *repo; + php_git2_t *_repo; + char *glob = {0}; + int glob_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_iterator_glob_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &glob, &glob_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_reference_next(iter) +*/ +PHP_FUNCTION(git_reference_next) +{ + zval *iter; + php_git2_t *_iter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_next not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &iter) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_reference_next_name(iter) +*/ +PHP_FUNCTION(git_reference_next_name) +{ + zval *iter; + php_git2_t *_iter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_next_name not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &iter) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_reference_iterator_free(iter) +*/ +PHP_FUNCTION(git_reference_iterator_free) +{ + zval *iter; + php_git2_t *_iter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_iterator_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &iter) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_reference_foreach_glob(repo, glob, callback, payload) +*/ +PHP_FUNCTION(git_reference_foreach_glob) +{ + zval *repo; + php_git2_t *_repo; + char *glob = {0}; + int glob_len; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_foreach_glob not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrz", &repo, &glob, &glob_len, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_reference_has_log(ref) +*/ +PHP_FUNCTION(git_reference_has_log) +{ + zval *ref; + php_git2_t *_ref; + int has = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + has = git_reference_has_log(PHP_GIT2_V(_ref, reference)); + + RETURN_LONG(has); +} + +/* {{{ proto long git_reference_is_branch(ref) +*/ +PHP_FUNCTION(git_reference_is_branch) +{ + zval *ref; + php_git2_t *_ref; + int is_branch = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + is_branch = git_reference_is_branch(PHP_GIT2_V(_ref, reference)); + + RETURN_LONG(is_branch); +} + +/* {{{ proto long git_reference_is_remote(ref) +*/ +PHP_FUNCTION(git_reference_is_remote) +{ + zval *ref; + php_git2_t *_ref; + int is_remote = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + is_remote = git_reference_is_remote(PHP_GIT2_V(_ref, reference)); + RETURN_LONG(is_remote); +} + +/* {{{ proto long git_reference_is_tag(ref) +*/ +PHP_FUNCTION(git_reference_is_tag) +{ + zval *ref; + php_git2_t *_ref; + int is_tag = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + is_tag = git_reference_is_tag(PHP_GIT2_V(_ref, reference)); + RETURN_LONG(is_tag); +} + +/* {{{ proto resource git_reference_normalize_name(name, flags) +*/ +PHP_FUNCTION(git_reference_normalize_name) +{ + char *name = {0}; + int name_len; + long flags; + char buffer[512] = {0}; + size_t buffer_sz = 512; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sl", &name, &name_len, &flags) == FAILURE) { + return; + } + error = git_reference_normalize_name(buffer, buffer_sz, name, flags); + if (php_git2_check_error(error, "git_reference_normalize_name" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_STRING(buffer, 1); +} + +/* {{{ proto resource git_reference_peel(ref, type) +*/ +PHP_FUNCTION(git_reference_peel) +{ + zval *ref; + php_git2_t *_ref; + zval *type; + php_git2_t *_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_peel not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &ref, &type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_reference_is_valid_name(refname) +*/ +PHP_FUNCTION(git_reference_is_valid_name) +{ + char *refname = {0}; + int refname_len; + int acceptable = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &refname, &refname_len) == FAILURE) { + return; + } + acceptable = git_reference_is_valid_name(refname); + RETURN_BOOL(acceptable); +} + +/* {{{ proto resource git_reference_shorthand(ref) +*/ +PHP_FUNCTION(git_reference_shorthand) +{ + zval *ref; + php_git2_t *_ref; + const char *name; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + name = git_reference_shorthand(PHP_GIT2_V(_ref, reference)); + RETURN_STRING(name, 1); +} + diff --git a/reference.h b/reference.h new file mode 100644 index 0000000000..22597db64d --- /dev/null +++ b/reference.h @@ -0,0 +1,335 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_REFERENCE_H +#define PHP_GIT2_REFERENCE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_lookup, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_name_to_id, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_dwim, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, shorthand) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_symbolic_create, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_create, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_target, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_target_peel, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_symbolic_target, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_type, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_name, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_resolve, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_owner, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_symbolic_set_target, 0, 0, 2) + ZEND_ARG_INFO(0, ref) + ZEND_ARG_INFO(0, target) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_set_target, 0, 0, 2) + ZEND_ARG_INFO(0, ref) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_rename, 0, 0, 3) + ZEND_ARG_INFO(0, ref) + ZEND_ARG_INFO(0, new_name) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_delete, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_list, 0, 0, 2) + ZEND_ARG_INFO(0, array) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_foreach_name, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_free, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_cmp, 0, 0, 2) + ZEND_ARG_INFO(0, ref1) + ZEND_ARG_INFO(0, ref2) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_iterator_new, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_iterator_glob_new, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, glob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_next, 0, 0, 1) + ZEND_ARG_INFO(0, iter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_next_name, 0, 0, 1) + ZEND_ARG_INFO(0, iter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_iterator_free, 0, 0, 1) + ZEND_ARG_INFO(0, iter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_foreach_glob, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, glob) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_has_log, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_is_branch, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_is_remote, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_is_tag, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_normalize_name, 0, 0, 4) + ZEND_ARG_INFO(0, buffer_size) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_peel, 0, 0, 2) + ZEND_ARG_INFO(0, ref) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_is_valid_name, 0, 0, 1) + ZEND_ARG_INFO(0, refname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_shorthand, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_reference_lookup(repo, name) +*/ +PHP_FUNCTION(git_reference_lookup); + +/* {{{ proto resource git_reference_name_to_id(repo, name) +*/ +PHP_FUNCTION(git_reference_name_to_id); + +/* {{{ proto resource git_reference_dwim(repo, shorthand) +*/ +PHP_FUNCTION(git_reference_dwim); + +/* {{{ proto resource git_reference_symbolic_create(repo, name, target, force) +*/ +PHP_FUNCTION(git_reference_symbolic_create); + +/* {{{ proto resource git_reference_create(repo, name, id, force) +*/ +PHP_FUNCTION(git_reference_create); + +/* {{{ proto resource git_reference_target(ref) +*/ +PHP_FUNCTION(git_reference_target); + +/* {{{ proto resource git_reference_target_peel(ref) +*/ +PHP_FUNCTION(git_reference_target_peel); + +/* {{{ proto resource git_reference_symbolic_target(ref) +*/ +PHP_FUNCTION(git_reference_symbolic_target); + +/* {{{ proto resource git_reference_type(ref) +*/ +PHP_FUNCTION(git_reference_type); + +/* {{{ proto resource git_reference_name(ref) +*/ +PHP_FUNCTION(git_reference_name); + +/* {{{ proto resource git_reference_resolve(ref) +*/ +PHP_FUNCTION(git_reference_resolve); + +/* {{{ proto resource git_reference_owner(ref) +*/ +PHP_FUNCTION(git_reference_owner); + +/* {{{ proto resource git_reference_symbolic_set_target(ref, target) +*/ +PHP_FUNCTION(git_reference_symbolic_set_target); + +/* {{{ proto resource git_reference_set_target(ref, id) +*/ +PHP_FUNCTION(git_reference_set_target); + +/* {{{ proto resource git_reference_rename(ref, new_name, force) +*/ +PHP_FUNCTION(git_reference_rename); + +/* {{{ proto long git_reference_delete(ref) +*/ +PHP_FUNCTION(git_reference_delete); + +/* {{{ proto long git_reference_list(array, repo) +*/ +PHP_FUNCTION(git_reference_list); + +/* {{{ proto long git_reference_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_reference_foreach); + +/* {{{ proto long git_reference_foreach_name(repo, callback, payload) +*/ +PHP_FUNCTION(git_reference_foreach_name); + +/* {{{ proto void git_reference_free(ref) +*/ +PHP_FUNCTION(git_reference_free); + +/* {{{ proto long git_reference_cmp(ref1, ref2) +*/ +PHP_FUNCTION(git_reference_cmp); + +/* {{{ proto resource git_reference_iterator_new(repo) +*/ +PHP_FUNCTION(git_reference_iterator_new); + +/* {{{ proto resource git_reference_iterator_glob_new(repo, glob) +*/ +PHP_FUNCTION(git_reference_iterator_glob_new); + +/* {{{ proto resource git_reference_next(iter) +*/ +PHP_FUNCTION(git_reference_next); + +/* {{{ proto resource git_reference_next_name(iter) +*/ +PHP_FUNCTION(git_reference_next_name); + +/* {{{ proto void git_reference_iterator_free(iter) +*/ +PHP_FUNCTION(git_reference_iterator_free); + +/* {{{ proto long git_reference_foreach_glob(repo, glob, callback, payload) +*/ +PHP_FUNCTION(git_reference_foreach_glob); + +/* {{{ proto long git_reference_has_log(ref) +*/ +PHP_FUNCTION(git_reference_has_log); + +/* {{{ proto long git_reference_is_branch(ref) +*/ +PHP_FUNCTION(git_reference_is_branch); + +/* {{{ proto long git_reference_is_remote(ref) +*/ +PHP_FUNCTION(git_reference_is_remote); + +/* {{{ proto long git_reference_is_tag(ref) +*/ +PHP_FUNCTION(git_reference_is_tag); + +/* {{{ proto resource git_reference_normalize_name(buffer_size, name, flags) +*/ +PHP_FUNCTION(git_reference_normalize_name); + +/* {{{ proto resource git_reference_peel(ref, type) +*/ +PHP_FUNCTION(git_reference_peel); + +/* {{{ proto long git_reference_is_valid_name(refname) +*/ +PHP_FUNCTION(git_reference_is_valid_name); + +/* {{{ proto resource git_reference_shorthand(ref) +*/ +PHP_FUNCTION(git_reference_shorthand); + +#endif \ No newline at end of file diff --git a/repository.c b/repository.c new file mode 100644 index 0000000000..ba81e1a25d --- /dev/null +++ b/repository.c @@ -0,0 +1,160 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "repository.h" + +/* {{{ proto resource git_repository_new() +*/ +PHP_FUNCTION(git_repository_new) +{ +// git_repository *repository; +// int error; +// php_git2_t *git2; +// +// error = git_repository_new(&repository); +// if (php_git2_check_error(error, "git_repository_new" TSRMLS_CC)) { +// RETURN_FALSE +// } +// +// PHP_GIT2_MAKE_RESOURCE(git2); +// +// git2->type = PHP_GIT2_TYPE_REPOSITORY; +// git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); +// git2->should_free_v = 0; +// +// ZVAL_RESOURCE(return_value, git2->resource_id); +} + +/* {{{ proto resource git_repository_init(string $path, long is_bare = 0) +*/ +PHP_FUNCTION(git_repository_init) +{ + git_repository *repository; + int error; + php_git2_t *git2; + char *path; + int path_len, is_bare = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s|l", &path, &path_len, &is_bare) == FAILURE) { + return; + } + + error = git_repository_init(&repository, path, is_bare); + if (php_git2_check_error(error, "git_repository_init" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(git2); + PHP_GIT2_V(git2, repository) = repository; + git2->type = PHP_GIT2_TYPE_REPOSITORY; + git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); + git2->should_free_v = 1; + + ZVAL_RESOURCE(return_value, git2->resource_id); +} + +/* {{{ proto resource git_repository_open(string $path) +*/ +PHP_FUNCTION(git_repository_open_bare) +{ + char *path; + int path_len; + git_repository *repository; + int error = 0; + php_git2_t *git2; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &path, &path_len) == FAILURE) { + return; + } + + error = git_repository_open_bare(&repository, path); + if (php_git2_check_error(error, "git_repository_open_bare" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(git2); + PHP_GIT2_V(git2, repository) = repository; + git2->type = PHP_GIT2_TYPE_REPOSITORY; + git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); + git2->should_free_v = 1; + + ZVAL_RESOURCE(return_value, git2->resource_id); +} + +/* {{{ proto resource git_repository_open(string $path) +*/ +PHP_FUNCTION(git_repository_open) +{ + char *path; + int path_len; + git_repository *repository; + int error = 0; + php_git2_t *git2; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &path, &path_len) == FAILURE) { + return; + } + + PHP_GIT2_MAKE_RESOURCE(git2); + error = git_repository_open(&repository, path); + if (php_git2_check_error(error, "git_repository_open" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_V(git2, repository) = repository; + git2->type = PHP_GIT2_TYPE_REPOSITORY; + git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); + git2->should_free_v = 1; + + ZVAL_RESOURCE(return_value, git2->resource_id); +} +/* }}} */ + +/* {{{ proto string git_repository_get_namespace(resource $repository) +*/ +PHP_FUNCTION(git_repository_get_namespace) +{ + zval *repository; + php_git2_t *git2; + const char *ns; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repository) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ns = git_repository_get_namespace(PHP_GIT2_V(git2, repository)); + if (ns != NULL) { + RETURN_STRING(ns, 1); + } else { + RETURN_STRING("", 1); + } +} +/* }}} */ + +/* {{{ proto string git_repository_workdir(resource $repository) +*/ +PHP_FUNCTION(git_repository_workdir) +{ + zval *repository; + php_git2_t *git2; + const char *workdir; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repository) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + workdir = git_repository_workdir(PHP_GIT2_V(git2, repository)); + + if (workdir != NULL) { + RETURN_STRING(workdir, 1); + } else { + RETURN_STRING("", 1); + } +} +/* }}} */ \ No newline at end of file diff --git a/repository.h b/repository.h new file mode 100644 index 0000000000..6ca665e0ce --- /dev/null +++ b/repository.h @@ -0,0 +1,77 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_REPOSITORY_H +#define PHP_GIT2_REPOSITORY_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_new, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_init, 0, 0, 1) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, is_bare) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_open_bare, 0, 0, 1) + ZEND_ARG_INFO(0, bare_path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_open, 0, 0, 1) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_get_namespace, 0, 0, 1) + ZEND_ARG_INFO(0, repository) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_workdir, 0, 0, 1) + ZEND_ARG_INFO(0, repository) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_repository_new() +*/ +PHP_FUNCTION(git_repository_new); + +/* {{{ proto resource git_repository_init(string $path, long is_bare = 0) +*/ +PHP_FUNCTION(git_repository_init); + +/* {{{ proto resource git_repository_open(string $path) +*/ +PHP_FUNCTION(git_repository_open_bare); + +/* {{{ proto resource git_repository_open(string $path) +*/ +PHP_FUNCTION(git_repository_open); + +/* {{{ proto string git_repository_get_namespace(resource $repository) +*/ +PHP_FUNCTION(git_repository_get_namespace); + +/* {{{ proto string git_repository_workdir(resource $repository) +*/ +PHP_FUNCTION(git_repository_workdir); + +#endif \ No newline at end of file diff --git a/revwalk.c b/revwalk.c new file mode 100644 index 0000000000..8252c57017 --- /dev/null +++ b/revwalk.c @@ -0,0 +1,357 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "revwalk.h" + +/* {{{ proto resource git_revwalk_new(repo) +*/ +PHP_FUNCTION(git_revwalk_new) +{ + zval *repo; + php_git2_t *_repo, *result; + git_revwalk *walker; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_revwalk_new(&walker, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_revwalk_new" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, revwalk) = walker; + result->type = PHP_GIT2_TYPE_REVWALK; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto void git_revwalk_reset(walker) +*/ +PHP_FUNCTION(git_revwalk_reset) +{ + zval *walker; + php_git2_t *_walker; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &walker) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walker, php_git2_t*, &walker, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + git_revwalk_reset(PHP_GIT2_V(_walker, revwalk)); +} + +/* {{{ proto long git_revwalk_push(walk, id) +*/ +PHP_FUNCTION(git_revwalk_push) +{ + zval *walk; + php_git2_t *_walk; + char *id = {0}; + int id_len; + git_oid oid; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &walk, &id, &id_len) == FAILURE) { + return; + } + + if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { + return; + } + + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_revwalk_push(PHP_GIT2_V(_walk, revwalk), &oid); + + if (php_git2_check_error(error, "git_revwalk_push" TSRMLS_CC)) { + RETURN_FALSE; + } else { + RETURN_TRUE; + } +} + +/* {{{ proto long git_revwalk_push_glob(walk, glob) +*/ +PHP_FUNCTION(git_revwalk_push_glob) +{ + zval *walk; + php_git2_t *_walk; + char *glob = {0}; + int glob_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_push_glob not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &walk, &glob, &glob_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_revwalk_push_head(walk) +*/ +PHP_FUNCTION(git_revwalk_push_head) +{ + zval *walk; + php_git2_t *_walk; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &walk) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_revwalk_push_head(PHP_GIT2_V(_walk, revwalk)); + if (php_git2_check_error(error, "git_revwalk_push_head" TSRMLS_CC)) { + RETURN_FALSE; + } else { + RETURN_TRUE; + } +} + +/* {{{ proto long git_revwalk_hide(walk, commit_id) +*/ +PHP_FUNCTION(git_revwalk_hide) +{ + zval *walk; + php_git2_t *_walk; + char *commit_id = {0}; + int commit_id_len; + git_oid oid; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &walk, &commit_id, &commit_id_len) == FAILURE) { + return; + } + if (git_oid_fromstrn(&oid, commit_id, commit_id_len) != GIT_OK) { + return; + } + + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_revwalk_hide(PHP_GIT2_V(_walk, revwalk), &oid); + + if (php_git2_check_error(error, "git_revwalk_hide" TSRMLS_CC)) { + RETURN_FALSE; + } else { + RETURN_TRUE; + } + +} + +/* {{{ proto long git_revwalk_hide_glob(walk, glob) +*/ +PHP_FUNCTION(git_revwalk_hide_glob) +{ + zval *walk; + php_git2_t *_walk; + char *glob = {0}; + int glob_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_hide_glob not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &walk, &glob, &glob_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_revwalk_hide_head(walk) +*/ +PHP_FUNCTION(git_revwalk_hide_head) +{ + zval *walk; + php_git2_t *_walk; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &walk) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_revwalk_hide_head(PHP_GIT2_V(_walk, revwalk)); + if (php_git2_check_error(error, "git_revwalk_hide_head" TSRMLS_CC)) { + RETURN_FALSE; + } else { + RETURN_TRUE; + } +} + +/* {{{ proto long git_revwalk_push_ref(walk, refname) +*/ +PHP_FUNCTION(git_revwalk_push_ref) +{ + zval *walk; + php_git2_t *_walk; + char *refname = {0}; + int refname_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_push_ref not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &walk, &refname, &refname_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_revwalk_hide_ref(walk, refname) +*/ +PHP_FUNCTION(git_revwalk_hide_ref) +{ + zval *walk; + php_git2_t *_walk; + char *refname = {0}; + int refname_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_hide_ref not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &walk, &refname, &refname_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto string git_revwalk_next(walk) +*/ +PHP_FUNCTION(git_revwalk_next) +{ + zval *walk; + php_git2_t *_walk; + git_oid id = {0}; + char out[41] = {0}; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &walk) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_revwalk_next(&id, PHP_GIT2_V(_walk, revwalk)); + + if (error == GIT_ITEROVER) { + RETURN_FALSE; + } + + git_oid_fmt(out, &id); + RETURN_STRING(out, 1); +} + +/* {{{ proto void git_revwalk_sorting(walk, sort_mode) +*/ +PHP_FUNCTION(git_revwalk_sorting) +{ + zval *walk; + php_git2_t *_walk; + long sort_mode = GIT_SORT_NONE; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &walk, &sort_mode) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + git_revwalk_sorting(PHP_GIT2_V(_walk, revwalk), sort_mode); +} + +/* {{{ proto long git_revwalk_push_range(walk, range) +*/ +PHP_FUNCTION(git_revwalk_push_range) +{ + zval *walk; + php_git2_t *_walk; + char *range = {0}; + int range_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_push_range not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &walk, &range, &range_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_revwalk_simplify_first_parent(walk) +*/ +PHP_FUNCTION(git_revwalk_simplify_first_parent) +{ + zval *walk; + php_git2_t *_walk; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &walk) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_revwalk_simplify_first_parent(PHP_GIT2_V(_walk, revwalk)); +} + +/* {{{ proto void git_revwalk_free(walk) +*/ +PHP_FUNCTION(git_revwalk_free) +{ + zval *walk; + php_git2_t *_walk; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &walk) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + if (_walk->should_free_v) { + git_revwalk_free(PHP_GIT2_V(_walk, revwalk)); + } + zval_ptr_dtor(&walk); +} + +/* {{{ proto resource git_revwalk_repository(walk) +*/ +PHP_FUNCTION(git_revwalk_repository) +{ + zval *walk; + php_git2_t *_walk, *result; + git_repository *repository; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &walk) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + repository = git_revwalk_repository(PHP_GIT2_V(_walk, revwalk)); + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + diff --git a/revwalk.h b/revwalk.h new file mode 100644 index 0000000000..ef9a7b6eac --- /dev/null +++ b/revwalk.h @@ -0,0 +1,166 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_REVWALK_H +#define PHP_GIT2_REVWALK_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_new, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_reset, 0, 0, 1) + ZEND_ARG_INFO(0, walker) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_push, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_push_glob, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, glob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_push_head, 0, 0, 1) + ZEND_ARG_INFO(0, walk) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_hide, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, commit_id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_hide_glob, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, glob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_hide_head, 0, 0, 1) + ZEND_ARG_INFO(0, walk) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_push_ref, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, refname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_hide_ref, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, refname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_next, 0, 0, 2) + ZEND_ARG_INFO(0, walk) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_sorting, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, sort_mode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_push_range, 0, 0, 2) + ZEND_ARG_INFO(0, walk) + ZEND_ARG_INFO(0, range) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_simplify_first_parent, 0, 0, 1) + ZEND_ARG_INFO(0, walk) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_free, 0, 0, 1) + ZEND_ARG_INFO(0, walk) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revwalk_repository, 0, 0, 1) + ZEND_ARG_INFO(0, walk) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_revwalk_new(repo) +*/ +PHP_FUNCTION(git_revwalk_new); + +/* {{{ proto void git_revwalk_reset(walker) +*/ +PHP_FUNCTION(git_revwalk_reset); + +/* {{{ proto long git_revwalk_push(walk, id) +*/ +PHP_FUNCTION(git_revwalk_push); + +/* {{{ proto long git_revwalk_push_glob(walk, glob) +*/ +PHP_FUNCTION(git_revwalk_push_glob); + +/* {{{ proto long git_revwalk_push_head(walk) +*/ +PHP_FUNCTION(git_revwalk_push_head); + +/* {{{ proto long git_revwalk_hide(walk, commit_id) +*/ +PHP_FUNCTION(git_revwalk_hide); + +/* {{{ proto long git_revwalk_hide_glob(walk, glob) +*/ +PHP_FUNCTION(git_revwalk_hide_glob); + +/* {{{ proto long git_revwalk_hide_head(walk) +*/ +PHP_FUNCTION(git_revwalk_hide_head); + +/* {{{ proto long git_revwalk_push_ref(walk, refname) +*/ +PHP_FUNCTION(git_revwalk_push_ref); + +/* {{{ proto long git_revwalk_hide_ref(walk, refname) +*/ +PHP_FUNCTION(git_revwalk_hide_ref); + +/* {{{ proto long git_revwalk_next(walk) +*/ +PHP_FUNCTION(git_revwalk_next); + +/* {{{ proto void git_revwalk_sorting(walk, sort_mode) +*/ +PHP_FUNCTION(git_revwalk_sorting); + +/* {{{ proto long git_revwalk_push_range(walk, range) +*/ +PHP_FUNCTION(git_revwalk_push_range); + +/* {{{ proto void git_revwalk_simplify_first_parent(walk) +*/ +PHP_FUNCTION(git_revwalk_simplify_first_parent); + +/* {{{ proto void git_revwalk_free(walk) +*/ +PHP_FUNCTION(git_revwalk_free); + +/* {{{ proto resource git_revwalk_repository(walk) +*/ +PHP_FUNCTION(git_revwalk_repository); + + +#endif \ No newline at end of file diff --git a/tree.c b/tree.c new file mode 100644 index 0000000000..adbc5981a7 --- /dev/null +++ b/tree.c @@ -0,0 +1,504 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "tree.h" + +/* {{{ proto resource git_tree_entry_byindex(resource $tree, string $name) +*/ +PHP_FUNCTION(git_tree_entry_byindex) +{ + zval *tree; + php_git2_t *git2, *result; + long index; + const git_tree_entry *entry; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &tree, &index) == FAILURE) { + return; + } + + PHP_GIT2_MAKE_RESOURCE(result); + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + entry = git_tree_entry_byindex(PHP_GIT2_V(git2, tree), index); + + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_tree_entry_byoid(resource $tree, string $oid) +*/ +PHP_FUNCTION(git_tree_entry_byoid) +{ + zval *tree; + php_git2_t *git2, *result; + char *hash; + int hash_len; + git_oid id; + const git_tree_entry *entry; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &tree, &hash, &hash_len) == FAILURE) { + return; + } + + if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { + return; + } + + PHP_GIT2_MAKE_RESOURCE(result); + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + entry = git_tree_entry_byoid(PHP_GIT2_V(git2, tree), &id); + + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + + +/* {{{ proto resource git_tree_entry_byname(resource $tree, string $name) +*/ +PHP_FUNCTION(git_tree_entry_byname) +{ + zval *tree; + php_git2_t *git2, *result; + char *name; + int name_len; + const git_tree_entry *entry; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &tree, &name, &name_len) == FAILURE) { + return; + } + + PHP_GIT2_MAKE_RESOURCE(result); + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + entry = git_tree_entry_byname(PHP_GIT2_V(git2, tree), name); + + + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto array git_tree_entry_bypath(resource $tree, string $path) +*/ +PHP_FUNCTION(git_tree_entry_bypath) +{ + zval *tree; + php_git2_t *git2, *result; + char *path; + int path_len; + const git_tree_entry *entry; + int error; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &tree, &path, &path_len) == FAILURE) { + return; + } + + PHP_GIT2_MAKE_RESOURCE(result); + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_tree_entry_bypath(&entry, PHP_GIT2_V(git2, tree), path); + + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto string git_tree_entry_id(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_id) +{ + zval *tree_entry; + php_git2_t *git2; + char out[41] = {0}; + + const git_oid *id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree_entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + id = git_tree_entry_id(PHP_GIT2_V(git2, tree_entry)); + + git_oid_fmt(out, id); + RETURN_STRING(out, 1); +} + + +/* {{{ proto long git_tree_entry_type(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_type) +{ + zval *tree; + php_git2_t *git2; + git_otype type; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + type = git_tree_entry_type(PHP_GIT2_V(git2, tree)); + + RETURN_LONG(type); +} + +/* {{{ proto string git_tree_entry_name(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_name) +{ + zval *tree_entry; + php_git2_t *git2; + const char *name; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree_entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + name = git_tree_entry_name(PHP_GIT2_V(git2, tree_entry)); + + RETURN_STRING(name, 1); +} + +/* {{{ proto long git_tree_entry_count(resource $tree) +*/ +PHP_FUNCTION(git_tree_entrycount) +{ + zval *tree; + php_git2_t *git2; + size_t count; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + count = git_tree_entrycount(PHP_GIT2_V(git2, tree)); + + RETURN_LONG(count); +} + +/* {{{ proto long git_tree_entry_filemode(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_filemode) +{ + zval *tree_entry; + php_git2_t *git2; + git_filemode_t filemode; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree_entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + filemode = git_tree_entry_filemode(PHP_GIT2_V(git2, tree_entry)); + + RETURN_LONG(filemode); +} + +/* {{{ proto long git_tree_entry_filemode_raw(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_filemode_raw) +{ + zval *tree_entry; + php_git2_t *git2; + git_filemode_t filemode; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree_entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + filemode = git_tree_entry_filemode_raw(PHP_GIT2_V(git2, tree_entry)); + + RETURN_LONG(filemode); +} + +/* {{{ proto bool git_tree_entry_cmp(resource $e1, resource $e2) +*/ +PHP_FUNCTION(git_tree_entry_cmp) +{ + zval *e1, *e2; + php_git2_t *g_e1, *g_e2; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &e1, &e2) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(g_e1, php_git2_t*, &e1, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(g_e2, php_git2_t*, &e2, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + result = git_tree_entry_cmp(PHP_GIT2_V(g_e1, tree_entry), PHP_GIT2_V(g_e2, tree_entry)); + RETURN_LONG(result); +} + + +/* {{{ proto void git_tree_free(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_free) +{ + zval *tree; + php_git2_t *git2; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git2->should_free_v) { + git_tree_free(PHP_GIT2_V(git2, tree)); + git2->should_free_v = 0; + } + + zval_ptr_dtor(&tree); +} + +/* {{{ proto void git_tree_entry_free(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_free) +{ + zval *tree_entry; + php_git2_t *git2; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree_entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git2->should_free_v) { + git_tree_entry_free(PHP_GIT2_V(git2, tree_entry)); + git2->should_free_v = 0; + } + + zval_ptr_dtor(&tree_entry); +} + +/* {{{ proto resource git_tree_entry_dup(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_dup) +{ + zval *tree_entry; + php_git2_t *git2, *result; + git_tree_entry *entry; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree_entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + entry = git_tree_entry_dup(PHP_GIT2_V(git2, tree_entry)); + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto string git_tree_id(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_id) +{ + zval *tree; + php_git2_t *git2; + char out[41] = {0}; + + const git_oid *id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + id = git_tree_id(PHP_GIT2_V(git2, tree)); + + git_oid_fmt(out, id); + RETURN_STRING(out, 1); +} + + +/* {{{ proto resource git_tree_lookup(resource $repository, mixed $oid) +*/ +PHP_FUNCTION(git_tree_lookup) +{ + zval *repository; + php_git2_t *git2, *result; + git_tree *tree; + char *hash; + int hash_len; + int error; + git_oid id; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repository, &hash, &hash_len) == FAILURE) { + return; + } + + if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + PHP_GIT2_MAKE_RESOURCE(result); + error = git_tree_lookup(&tree, PHP_GIT2_V(git2, repository), &id); + if (php_git2_check_error(error, "git_commit_lookup" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_V(result, tree) = tree; + result->type = PHP_GIT2_TYPE_TREE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} +/* }}} */ + +/* {{{ proto resource git_tree_owner(resource $tree) +*/ +PHP_FUNCTION(git_tree_owner) +{ + zval *tree; + php_git2_t *git2, *result; + git_repository *repository; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tree) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + PHP_GIT2_MAKE_RESOURCE(result); + repository = git_tree_owner(PHP_GIT2_V(git2, tree)); + + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} +/* }}} */ + +typedef struct tree_walk_cb_t { + zval *payload; + zend_fcall_info *fci; + zend_fcall_info_cache *fcc; +#ifdef ZTS + void ***tsrmls; +#endif +}; + +static int tree_walk_cb(const char *root, const git_tree_entry *entry, void *payload) +{ + php_git2_t *result; + zval **params[3], *param_root, *param_rsrc, *retval_ptr = NULL; + struct tree_walk_cb_t *p = (struct tree_walk_cb_t*)payload; +#ifdef ZTS + void ***tsrm_ls = p->tsrmls; +#endif + + MAKE_STD_ZVAL(param_root); + ZVAL_STRING(param_root, root, 1); + MAKE_STD_ZVAL(param_rsrc); + //MAKE_STD_ZVAL(retval_ptr); + + PHP_GIT2_MAKE_RESOURCE_NOCHECK(result); + + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(param_rsrc, result->resource_id); + + params[0] = ¶m_root; + params[1] = ¶m_rsrc; + params[2] = &p->payload; + + if (ZEND_FCI_INITIALIZED(*p->fci)) { + p->fci->params = params; + p->fci->retval_ptr_ptr = &retval_ptr; + p->fci->param_count = 3; + p->fci->no_separation = 1; + + if (zend_call_function(p->fci, p->fcc TSRMLS_CC) != SUCCESS) { + } + + zend_fcall_info_args_clear(p->fci, 0); + } + + zval_ptr_dtor(¶m_root); + zval_ptr_dtor(¶m_rsrc); + zval_ptr_dtor(&retval_ptr); + + zend_list_delete(result->resource_id); + + return 1; +} + +/* {{{ proto void git_tree_walk(resource $tree, long $mode, Callable $callback, mixed &$payload) +*/ +PHP_FUNCTION(git_tree_walk) +{ + zval *tree, *payload; + php_git2_t *git2, *result; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + long mode; + struct tree_walk_cb_t *cb; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlf|z", &tree, &mode, &fci, &fcc, &payload) == FAILURE) { + return; + } + + cb = (struct tree_walk_cb_t*)emalloc(sizeof(struct tree_walk_cb_t)); + cb->payload = payload; +#ifdef ZTS + cb->tsrmls = TSRMLS_C; +#endif + cb->fci = &fci; + cb->fcc = &fcc; + + ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_tree_walk(PHP_GIT2_V(git2, tree), mode, tree_walk_cb, cb); + + efree(cb); +} +/* }}} */ diff --git a/tree.h b/tree.h new file mode 100644 index 0000000000..30b9d3f412 --- /dev/null +++ b/tree.h @@ -0,0 +1,183 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_TREE_H +#define PHP_GIT2_TREE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_byoid, 0, 0, 2) + ZEND_ARG_INFO(0, tree) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_byindex, 0, 0, 2) + ZEND_ARG_INFO(0, tree) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_byname, 0, 0, 2) + ZEND_ARG_INFO(0, tree) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_bypath, 0, 0, 2) + ZEND_ARG_INFO(0, tree) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_id, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_name, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entrycount, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_type, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_filemode, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_filemode_raw, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_cmp, 0, 0, 2) + ZEND_ARG_INFO(0, e1) + ZEND_ARG_INFO(0, e2) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_free, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_free, 0, 0, 1) + ZEND_ARG_INFO(0, tree) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_dup, 0, 0, 1) + ZEND_ARG_INFO(0, tree_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_id, 0, 0, 1) + ZEND_ARG_INFO(0, tree) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_lookup, 0, 0, 2) + ZEND_ARG_INFO(0, repository) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_owner, 0, 0, 1) + ZEND_ARG_INFO(0, tree) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_walk, 0, 0, 4) + ZEND_ARG_INFO(0, tree) + ZEND_ARG_INFO(0, mode) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(1, payload) +ZEND_END_ARG_INFO() + + +/* {{{ proto array git_tree_entry_byoid(resource $tree, string $oid) +*/ +PHP_FUNCTION(git_tree_entry_byoid); + +/* {{{ proto array git_tree_entry_byindex(resource $tree, long $index) +*/ +PHP_FUNCTION(git_tree_entry_byindex); + +/* {{{ proto array git_tree_entry_byname(resource $tree, string $name) +*/ +PHP_FUNCTION(git_tree_entry_byname); + +/* {{{ proto array git_tree_entry_bypath(resource $tree, string $path) +*/ +PHP_FUNCTION(git_tree_entry_bypath); + +/* {{{ proto string git_tree_entry_id(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_id); + +/* {{{ proto string git_tree_entry_name(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_name); + +/* {{{ proto long git_tree_entrycount(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entrycount); + +/* {{{ proto long git_tree_entry_type(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_type); + +/* {{{ proto long git_tree_entry_filemode(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_filemode); + +/* {{{ proto long git_tree_entry_filemode_raw(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_filemode_raw); + +/* {{{ proto long git_tree_entry_cmp(resource $e1, resource $e2) +*/ +PHP_FUNCTION(git_tree_entry_cmp); + +/* {{{ proto void git_tree_entry_free(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_free); + +/* {{{ proto void git_tree_free(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_free); + +/* {{{ proto resource git_tree_entry_dup(resource $tree_entry) +*/ +PHP_FUNCTION(git_tree_entry_dup); + +/* {{{ proto string git_tree_id(resource $tree) +*/ +PHP_FUNCTION(git_tree_id); + +/* {{{ proto resource git_tree_lookup(resource $repository, string id) +*/ +PHP_FUNCTION(git_tree_lookup); + +/* {{{ proto resource git_tree_owner(resource $tree) +*/ +PHP_FUNCTION(git_tree_owner); + +/* {{{ proto resource git_tree_walk(resource $tree, long $mode, Callable $callback, mixed $payload) +*/ +PHP_FUNCTION(git_tree_walk); + +#endif \ No newline at end of file diff --git a/treebuilder.c b/treebuilder.c new file mode 100644 index 0000000000..86c0e2c38b --- /dev/null +++ b/treebuilder.c @@ -0,0 +1,232 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "revwalk.h" + +/* {{{ proto resource git_treebuilder_create([resource $source]) +*/ +PHP_FUNCTION(git_treebuilder_create) +{ + zval *source = NULL; + php_git2_t *_source, *result; + git_treebuilder *builder; + git_tree *tree = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "|r", &source) == FAILURE) { + return; + } + + if (source != NULL) { + ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + tree = PHP_GIT2_V(_source, tree); + } + + error = git_treebuilder_create(&builder, tree); + if (php_git2_check_error(error, "git_treebuilder_create" TSRMLS_CC)) { + RETURN_FALSE; + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, treebuilder) = builder; + result->type = PHP_GIT2_TYPE_TREEBUILDER; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto void git_treebuilder_clear(bld) +*/ +PHP_FUNCTION(git_treebuilder_clear) +{ + zval *bld; + php_git2_t *_bld; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &bld) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_treebuilder_clear(PHP_GIT2_V(_bld, treebuilder)); +} + +/* {{{ proto resource git_treebuilder_entrycount(bld) +*/ +PHP_FUNCTION(git_treebuilder_entrycount) +{ + zval *bld; + php_git2_t *_bld; + int count; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &bld) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + count = git_treebuilder_entrycount(PHP_GIT2_V(_bld, treebuilder)); + RETURN_LONG(count); +} + +/* {{{ proto void git_treebuilder_free(bld) +*/ +PHP_FUNCTION(git_treebuilder_free) +{ + zval *bld; + php_git2_t *_bld; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &bld) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + git_treebuilder_free(PHP_GIT2_V(_bld, treebuilder)); +} + +/* {{{ proto resource git_treebuilder_get(bld, filename) +*/ +PHP_FUNCTION(git_treebuilder_get) +{ + zval *bld; + php_git2_t *_bld, *result; + char *filename = {0}; + int filename_len; + const git_tree_entry *entry = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &bld, &filename, &filename_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + entry = git_treebuilder_get(PHP_GIT2_V(_bld, treebuilder), filename); + if (entry != NULL) { + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); + } else { + RETURN_FALSE; + } +} + +/* {{{ proto resource git_treebuilder_insert(bld, filename, id, filemode) +*/ +PHP_FUNCTION(git_treebuilder_insert) +{ + zval *bld; + php_git2_t *_bld, *result; + char *filename = {0}; + int filename_len; + char *id = {0}; + int id_len; + long filemode; + const git_tree_entry *entry; + int error = 0; + git_oid oid; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rssl", &bld, &filename, &filename_len, &id, &id_len, &filemode) == FAILURE) { + return; + } + + if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { + return; + } + + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_treebuilder_insert(&entry, PHP_GIT2_V(_bld, treebuilder), filename, &oid, filemode); + + if (php_git2_check_error(error, "git_treebuilder_write" TSRMLS_CC)) { + RETURN_FALSE; + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, tree_entry) = entry; + result->type = PHP_GIT2_TYPE_TREE_ENTRY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto long git_treebuilder_remove(bld, filename) +*/ +PHP_FUNCTION(git_treebuilder_remove) +{ + zval *bld; + php_git2_t *_bld; + char *filename = {0}; + int filename_len; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &bld, &filename, &filename_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_treebuilder_remove(PHP_GIT2_V(_bld, treebuilder), filename); + + if (php_git2_check_error(error, "git_treebuilder_remove" TSRMLS_CC)) { + RETURN_FALSE; + } + + RETURN_TRUE; +} + +/* {{{ proto void git_treebuilder_filter(bld, filter, payload) +*/ +PHP_FUNCTION(git_treebuilder_filter) +{ + zval *bld; + php_git2_t *_bld; + zval *filter; + php_git2_t *_filter; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_treebuilder_filter not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &bld, &filter, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_treebuilder_write(repo, bld) +*/ +PHP_FUNCTION(git_treebuilder_write) +{ + zval *repo; + php_git2_t *_repo; + zval *bld; + php_git2_t *_bld; + git_oid id; + int error = 0; + char out[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &bld) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_treebuilder_write(&id, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_bld, treebuilder)); + if (php_git2_check_error(error, "git_treebuilder_write" TSRMLS_CC)) { + RETURN_FALSE; + } + + git_oid_fmt(out, &id); + RETURN_STRING(out, 1); + +} + diff --git a/treebuilder.h b/treebuilder.h new file mode 100644 index 0000000000..6d587b9747 --- /dev/null +++ b/treebuilder.h @@ -0,0 +1,109 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_TREEBUILDER_H +#define PHP_GIT2_TREEBUILDER_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_create, 0, 0, 1) + ZEND_ARG_INFO(0, source) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_clear, 0, 0, 1) + ZEND_ARG_INFO(0, bld) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_entrycount, 0, 0, 1) + ZEND_ARG_INFO(0, bld) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_free, 0, 0, 1) + ZEND_ARG_INFO(0, bld) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_get, 0, 0, 2) + ZEND_ARG_INFO(0, bld) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_insert, 0, 0, 4) + ZEND_ARG_INFO(0, bld) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, filemode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_remove, 0, 0, 2) + ZEND_ARG_INFO(0, bld) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_filter, 0, 0, 3) + ZEND_ARG_INFO(0, bld) + ZEND_ARG_INFO(0, filter) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_write, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, bld) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_treebuilder_create(source) +*/ +PHP_FUNCTION(git_treebuilder_create); + +/* {{{ proto void git_treebuilder_clear(bld) +*/ +PHP_FUNCTION(git_treebuilder_clear); + +/* {{{ proto resource git_treebuilder_entrycount(bld) +*/ +PHP_FUNCTION(git_treebuilder_entrycount); + +/* {{{ proto void git_treebuilder_free(bld) +*/ +PHP_FUNCTION(git_treebuilder_free); + +/* {{{ proto resource git_treebuilder_get(bld, filename) +*/ +PHP_FUNCTION(git_treebuilder_get); + +/* {{{ proto resource git_treebuilder_insert(bld, filename, id, filemode) +*/ +PHP_FUNCTION(git_treebuilder_insert); + +/* {{{ proto long git_treebuilder_remove(bld, filename) +*/ +PHP_FUNCTION(git_treebuilder_remove); + +/* {{{ proto void git_treebuilder_filter(bld, filter, payload) +*/ +PHP_FUNCTION(git_treebuilder_filter); + +/* {{{ proto long git_treebuilder_write(repo, bld) +*/ +PHP_FUNCTION(git_treebuilder_write); + +#endif \ No newline at end of file From a6721ced3b00a904f225495d771496be6d0b1f5e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 02:43:01 +0900 Subject: [PATCH 011/136] update readme --- README.md | 186 ------------------------------------------------------ 1 file changed, 186 deletions(-) diff --git a/README.md b/README.md index b970b5e071..ce784d49c9 100644 --- a/README.md +++ b/README.md @@ -3,192 +3,6 @@ php-git2 is a PHP bindings to the libgit2 linkable C Git library. this extension are re-writing php-git as that code too dirty. -# Important Notice - -php-git changed it's API drastically. this changes doesn't care about compatibility between old one. -please check tests cases. - -# Installing And Running - -you need to install libgit2 before make php-git. - -```` -git clone https://github.com/libgit2/php-git.git --recursive -cd libgit2 -mkdir build && cd build -cmake .. -cmake -DBUILD_SHARED_LIBS=OFF -build . -make -cd ../../ -phpize -./configure -make -make install -sudo make install -# add `extension=git2.so` to your php.ini -```` - -new php-git features almost tested. - -# API - -## Repository Access - -````php -$repo = new Git2\Repository($path); -/* - bool = $repo->exists(string sha1) - Git2\Object = $repo->lookup(string sha1) - string sha1 = $repo->hash(string content, long type) - string sha1 = $repo->write(string content, long type) - bool = $repo->isBare() - bool = $repo->isEmpty() - bool = $repo->headDetached() - bool = $repo->headOrphan() - string path = Git2\Repository::discover("/Users/chobie/projects/work/repo/lib/subdir"); - // => /Users/chobie/projects/work/repo/.git - - Git2\Repository = Git2\Repository::init(string $path, bool isBare) -*/ -```` - -## Object Access - -### create new blob - -```` -$oid = Git2\Blob::create($repo, "Hello World"); -/* - $blob = $repo->lookup($oid); - int $blob->getSize(); - string $blob->getContent(); -*/ -```` - -## Tree Access - -```` -$repo = new Git2\Repository($path); -$tree = $repo->lookup(tree sha); // specify tree sha -foreach ($tree as $oid => $entry) { -/* - bool $entry->isTree(); - bool $entry->isBlob(); - bool $entry->isSubmodule(); -*/ - var_dump($entry); -} -```` - -## Ref Management - -```` -$ref = Git2\Reference::lookup($repo, "refs/heads/master"); - sha = $ref->getTarget(); - str = $ref->getName(); -```` - -```` -foreach (Git2\Reference::each($repo) as $ref) { - echo $ref->getName() . PHP_EOL; -} -```` - - -## Commit - -```` -insert(new Git2\TreeEntry(array( - "name" => "README.txt", - "oid" => "63542fbea05732b78711479a31557bd1b0aa2116", - "attributes" => octdec('100644'), -))); -$tree = $bld->write($repo); - -$parent = ""; -$parents = array(); -$parent = Git2\Commit::create($repo, array( - "author" => $author, - "committer" => $author, - "message" => "Hello World", - "tree" => $tree, - "parents" => $parents, -)); -```` - -## Revision Walking - -```` -$repo = new Git2\Repository($path); -$walker = new Git2\Walker($repo); -/* specify HEAD oid */ -$walker->push("6e20138dc38f9f626107f1cd3ef0f9838c43defe"); - -foreach ($walker as $oid => $commit) { - printf("oid: %s\n", $oid); - printf("message: %s\n", $commit->getMessage()); -} -```` - -## Config access - -```` -$config = new Git2\Config("path/to/git/config"); -$config->get("core.bare"); -$config->store("core.bare","1"); - -// Git2\Config supports read / write dimension. -$config['core.bare'] -$config['core.bare'] = 1; -```` - -## ODB operation - -```` -$repo = Git2\Repository::init("/path/to/repo",true); -$odb = $repo->odb // read only property -Git\OdbObject $odb->read(sha1) // returns uncompressed git raw data. -string $odb->hash(string contents, int type)// same as Git2\Repository::hash -string $odb->write(string contents, int type)// same as Git2\Repository::write -bool $odb->exists(sha1)// same as Git2\Repository::exists -```` - -## Reflog -will be add. - -## Remote access (Experimental) - -this API will be change. - -```` -$repo = new Git2\Repository("/path/to/.git"); -$remote = new Git2\Remote($repo,"http://github.com/libgit2/php-git.git"); -// for now, remote can fetch files only. that does not update references. -$remote->fetch(); -```` - -## Author -* Shuhei Tanuma - -## Contributors - -* Anthony Van de Gejuchte -* Cameron Eagans -* Graham Weldon -* James Titcumb -* Matthieu Moquet -* Ryusuke SEKIYAMA -* Shuhei Tanuma -* Vasileios Georgitzikis -* tsteiner - ## LICENSE MIT License From c97b1dc97144149856ec7db2759e1d2f40c41eb5 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 13:02:32 +0900 Subject: [PATCH 012/136] add config --- README.md | 66 ++++- blob.c | 2 +- config.m4 | 2 +- g_config.c | 764 +++++++++++++++++++++++++++++++++++++++++++++++++++++ g_config.h | 366 +++++++++++++++++++++++++ gen.php | 2 +- php_git2.c | 42 +++ php_git2.h | 2 + 8 files changed, 1242 insertions(+), 4 deletions(-) create mode 100644 g_config.c create mode 100644 g_config.h diff --git a/README.md b/README.md index ce784d49c9..f57c3881c4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,71 @@ # PHP-Git2 - libgit2 bindings in PHP php-git2 is a PHP bindings to the libgit2 linkable C Git library. -this extension are re-writing php-git as that code too dirty. + +## Status + +0.3.0 Alpha (switching to functions) + +## For Contributors + +##### Issue first. + +please make a issue first. don't work before creating it. + +##### Coding Styles + +follow pecl coding standards (except 8 at this moment). + +* http://git.php.net/?p=php-src.git;a=blob_plain;f=CODING_STANDARDS;hb=HEAD + +##### Signature conversions + +```` +GIT_EXTERN(int) git_repository_init( + git_repository **out, + const char *path, + unsigned is_bare); + + +// error code will handle extension. +// resource creation or getting functions will return their resource or bool. +resource|bool function git_repository_init(string $path, long $is_bare); + +some small structure (e.g: git_config_entry) should consider return as an array. it's usefull. +```` + +see http://libgit2.github.com/libgit2/#HEAD + +##### file name rules. + +basically, we rely libgit2 grouping at this time. (`branch` group functions should be in branch.c) +some group (e.g config) will conflicts php headers. we choose `g_` prefix for now. + +check grouping here http://libgit2.github.com/libgit2/#HEAD + +##### generating files + +if you wanna try to work new file. please use gen.php and generate stubs. as declarations are bored task. +(sometimes, this generator might output wrong headers. then just comment out or fix generator) + +```` +php gen.php libgit2/include/git2/branch.h (0|1) [filter] > target.c or target.h +```` + +you can ouptut function entry with this. past it to `php_git2.c` + +```` +php fe.php target.c +```` + +##### testing + +group/function.phpt + +##### policy + +* don't create OOP interface for ease of maintenance. +* follow latest libgit2 api. don't consider BC at this time. ## LICENSE diff --git a/blob.c b/blob.c index c3b37ea60d..17ff3b1929 100644 --- a/blob.c +++ b/blob.c @@ -180,12 +180,12 @@ PHP_FUNCTION(git_blob_lookup) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - PHP_GIT2_MAKE_RESOURCE(result); error = git_blob_lookup(&blob, PHP_GIT2_V(git2, repository), &id); if (php_git2_check_error(error, "git_blob_lookup" TSRMLS_CC)) { RETURN_FALSE } + PHP_GIT2_MAKE_RESOURCE(result); PHP_GIT2_V(result, blob) = blob; result->type = PHP_GIT2_TYPE_BLOB; result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); diff --git a/config.m4 b/config.m4 index 54a6021758..3c6284b5e2 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/g_config.c b/g_config.c new file mode 100644 index 0000000000..d35778d089 --- /dev/null +++ b/g_config.c @@ -0,0 +1,764 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "g_config.h" + + +enum php_git2_config { + PHP_GIT2_CONFIG_STRING, + PHP_GIT2_CONFIG_BOOL, + PHP_GIT2_CONFIG_INT64, + PHP_GIT2_CONFIG_INT32, +}; + +static void php_git2_config_get_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2_config type) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &cfg, &name, &name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + switch (type) { + case PHP_GIT2_CONFIG_STRING: { + const char *ptr; + error = git_config_get_string(&ptr, PHP_GIT2_V(_cfg, config), name); + if (php_git2_check_error(error, "git_config_get_string" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_STRING(ptr, 1); + break; + } + case PHP_GIT2_CONFIG_BOOL: { + int ptr; + error = git_config_get_bool(&ptr, PHP_GIT2_V(_cfg, config), name); + if (php_git2_check_error(error, "git_config_get_bool" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_BOOL(ptr); + break; + } + case PHP_GIT2_CONFIG_INT64: { + int64_t ptr; + error = git_config_get_int64(&ptr, PHP_GIT2_V(_cfg, config), name); + if (php_git2_check_error(error, "git_config_get_int64" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_LONG(ptr); + break; + } + case PHP_GIT2_CONFIG_INT32: { + int32_t ptr; + error = git_config_get_int32(&ptr, PHP_GIT2_V(_cfg, config), name); + if (php_git2_check_error(error, "git_config_get_int32" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_LONG(ptr); + break; + } + } +} + + +/* {{{ proto resource git_config_find_global() +*/ +PHP_FUNCTION(git_config_find_global) +{ + char buffer[512]; + size_t buffer_len = 512; + int error = 0; + + error = git_config_find_global(buffer, buffer_len); + if (php_git2_check_error(error, "git_config_find_global" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_STRING(buffer, 1); +} + +/* {{{ proto resource git_config_find_xdg(length) +*/ +PHP_FUNCTION(git_config_find_xdg) +{ + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_find_xdg not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "", &length) == FAILURE) { +// return; +// } +} + +/* {{{ proto resource git_config_find_system(length) +*/ +PHP_FUNCTION(git_config_find_system) +{ + char buffer[512]; + size_t buffer_len = 512; + int error = 0; + + error = git_config_find_system(buffer, buffer_len); + if (php_git2_check_error(error, "git_config_find_system" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_STRING(buffer, 1); +} + +/* {{{ proto resource git_config_open_default() +*/ +PHP_FUNCTION(git_config_open_default) +{ + git_config *config; + int error = 0; + php_git2_t *result; + + error = git_config_open_default(&config); + if (php_git2_check_error(error, "git_config_open_default" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, config) = config; + result->type = PHP_GIT2_TYPE_CONFIG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto resource git_config_new() +*/ +PHP_FUNCTION(git_config_new) +{ + git_config *config; + php_git2_t *result; + int error = 0; + + error = git_config_new(&config); + if (php_git2_check_error(error, "git_config_new" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, config) = config; + result->type = PHP_GIT2_TYPE_CONFIG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); +} + +/* {{{ proto long git_config_add_file_ondisk(cfg, path, level, force) +*/ +PHP_FUNCTION(git_config_add_file_ondisk) +{ + zval *cfg; + php_git2_t *_cfg; + char *path = {0}; + int path_len; + zval *level; + php_git2_t *_level; + long force; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_add_file_ondisk not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrl", &cfg, &path, &path_len, &level, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_open_ondisk(path) +*/ +PHP_FUNCTION(git_config_open_ondisk) +{ + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_ondisk not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &path, &path_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_config_open_level(parent, level) +*/ +PHP_FUNCTION(git_config_open_level) +{ + zval *parent; + php_git2_t *_parent; + zval *level; + php_git2_t *_level; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_level not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &parent, &level) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_parent, php_git2_t*, &parent, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_open_global(config) +*/ +PHP_FUNCTION(git_config_open_global) +{ + zval *config; + php_git2_t *_config; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_global not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &config) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_config, php_git2_t*, &config, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_refresh(cfg) +*/ +PHP_FUNCTION(git_config_refresh) +{ + zval *cfg; + php_git2_t *_cfg; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &cfg) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_config_refresh(PHP_GIT2_V(_cfg, config)); + if (php_git2_check_error(error, "git_config_refresh" TSRMLS_CC)) { + RETURN_FALSE + } + + RETURN_TRUE; +} + +/* {{{ proto void git_config_free(cfg) +*/ +PHP_FUNCTION(git_config_free) +{ + zval *cfg; + php_git2_t *_cfg; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &cfg) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + if (_cfg->should_free_v) { + git_config_free(PHP_GIT2_V(_cfg, config)); + _cfg->should_free_v = 0; + } + zval_ptr_dtor(&cfg); +} + +/* {{{ proto resource git_config_get_entry(cfg, name) +*/ +PHP_FUNCTION(git_config_get_entry) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + git_config_entry *entry; + int error = 0; + zval *result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &cfg, &name, &name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_config_get_entry(&entry, PHP_GIT2_V(_cfg, config), name); + if (php_git2_check_error(error, "git_config_get_entry" TSRMLS_CC)) { + RETURN_FALSE + } + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_string_ex(result, ZEND_STRS("name"), entry->name, 1); + add_assoc_string_ex(result, ZEND_STRS("value"), entry->value, 1); + add_assoc_long_ex(result, ZEND_STRS("level"), entry->level); + + RETURN_ZVAL(result, 0, 1); +} + +/* {{{ proto resource git_config_get_int32(cfg, name) +*/ +PHP_FUNCTION(git_config_get_int32) +{ + php_git2_config_get_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_INT32); +} + +/* {{{ proto resource git_config_get_int64(cfg, name) +*/ +PHP_FUNCTION(git_config_get_int64) +{ + php_git2_config_get_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_INT64); +} + +/* {{{ proto resource git_config_get_bool(cfg, name) +*/ +PHP_FUNCTION(git_config_get_bool) +{ + php_git2_config_get_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_BOOL); +} + +/* {{{ proto resource git_config_get_string(cfg, name) +*/ +PHP_FUNCTION(git_config_get_string) +{ + php_git2_config_get_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_STRING); +} + +/* {{{ proto long git_config_get_multivar_foreach(cfg, name, regexp, callback, payload) +*/ +PHP_FUNCTION(git_config_get_multivar_foreach) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + char *regexp = {0}; + int regexp_len; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_get_multivar_foreach not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rssrz", &cfg, &name, &name_len, ®exp, ®exp_len, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_multivar_iterator_new(cfg, name, regexp) +*/ +PHP_FUNCTION(git_config_multivar_iterator_new) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + char *regexp = {0}; + int regexp_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_multivar_iterator_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &cfg, &name, &name_len, ®exp, ®exp_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_next(iter) +*/ +PHP_FUNCTION(git_config_next) +{ + zval *iter; + php_git2_t *_iter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_next not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &iter) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_config_iterator_free(iter) +*/ +PHP_FUNCTION(git_config_iterator_free) +{ + zval *iter; + php_git2_t *_iter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_iterator_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &iter) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_set_int32(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_int32) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + long value; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_int32 not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &cfg, &name, &name_len, &value) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_set_int64(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_int64) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + long value; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_int64 not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &cfg, &name, &name_len, &value) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_set_bool(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_bool) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + long value; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_bool not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &cfg, &name, &name_len, &value) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_set_string(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_string) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + char *value = {0}; + int value_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_string not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &cfg, &name, &name_len, &value, &value_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_set_multivar(cfg, name, regexp, value) +*/ +PHP_FUNCTION(git_config_set_multivar) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + char *regexp = {0}; + int regexp_len; + char *value = {0}; + int value_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_multivar not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsss", &cfg, &name, &name_len, ®exp, ®exp_len, &value, &value_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_delete_entry(cfg, name) +*/ +PHP_FUNCTION(git_config_delete_entry) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_delete_entry not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &cfg, &name, &name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_delete_multivar(cfg, name, regexp) +*/ +PHP_FUNCTION(git_config_delete_multivar) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + char *regexp = {0}; + int regexp_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_delete_multivar not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &cfg, &name, &name_len, ®exp, ®exp_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_foreach(cfg, callback, payload) +*/ +PHP_FUNCTION(git_config_foreach) +{ + zval *cfg; + php_git2_t *_cfg; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_foreach not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &cfg, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_iterator_new(cfg) +*/ +PHP_FUNCTION(git_config_iterator_new) +{ + zval *cfg; + php_git2_t *_cfg; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_iterator_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &cfg) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_iterator_glob_new(cfg, regexp) +*/ +PHP_FUNCTION(git_config_iterator_glob_new) +{ + zval *cfg; + php_git2_t *_cfg; + char *regexp = {0}; + int regexp_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_iterator_glob_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &cfg, ®exp, ®exp_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_config_foreach_match(cfg, regexp, callback, payload) +*/ +PHP_FUNCTION(git_config_foreach_match) +{ + zval *cfg; + php_git2_t *_cfg; + char *regexp = {0}; + int regexp_len; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_foreach_match not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrz", &cfg, ®exp, ®exp_len, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_get_mapped(cfg, name, maps, map_n) +*/ +PHP_FUNCTION(git_config_get_mapped) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + zval *maps; + php_git2_t *_maps; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_get_mapped not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rsr", &cfg, &name, &name_len, &maps, &map_n) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_lookup_map_value(maps, map_n, value) +*/ +PHP_FUNCTION(git_config_lookup_map_value) +{ + zval *maps; + php_git2_t *_maps; + char *value = {0}; + int value_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_lookup_map_value not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rs", &maps, &map_n, &value, &value_len) == FAILURE) { +// return; +// } + ZEND_FETCH_RESOURCE(_maps, php_git2_t*, &maps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_config_parse_bool(value) +*/ +PHP_FUNCTION(git_config_parse_bool) +{ + char *value = {0}; + int value_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_parse_bool not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &value, &value_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_config_parse_int32(value) +*/ +PHP_FUNCTION(git_config_parse_int32) +{ + char *value = {0}; + int value_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_parse_int32 not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &value, &value_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_config_parse_int64(value) +*/ +PHP_FUNCTION(git_config_parse_int64) +{ + char *value = {0}; + int value_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_parse_int64 not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &value, &value_len) == FAILURE) { + return; + } +} + +/* {{{ proto long git_config_backend_foreach_match(backend, regexp, , ), data) +*/ +PHP_FUNCTION(git_config_backend_foreach_match) +{ + zval *backend; + php_git2_t *_backend; + char *regexp = {0}; + int regexp_len; + long ; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_backend_foreach_match not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rsl", &backend, ®exp, ®exp_len, &, &), &data) == FAILURE) { +// return; +// } + ZEND_FETCH_RESOURCE(_backend, php_git2_t*, &backend, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} diff --git a/g_config.h b/g_config.h new file mode 100644 index 0000000000..d721a6a153 --- /dev/null +++ b/g_config.h @@ -0,0 +1,366 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_G_CONFIG_H +#define PHP_GIT2_G_CONFIG_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_find_global, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_find_xdg, 0, 0, 2) + ZEND_ARG_INFO(0, length) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_find_system, 0, 0, 2) + ZEND_ARG_INFO(0, length) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_open_default, 0, 0, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_new, 0, 0, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_add_file_ondisk, 0, 0, 4) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_open_ondisk, 0, 0, 2) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_open_level, 0, 0, 3) + ZEND_ARG_INFO(0, parent) + ZEND_ARG_INFO(0, level) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_open_global, 0, 0, 2) + ZEND_ARG_INFO(0, config) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_refresh, 0, 0, 1) + ZEND_ARG_INFO(0, cfg) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_free, 0, 0, 1) + ZEND_ARG_INFO(0, cfg) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_entry, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_int32, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_int64, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_bool, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_string, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_multivar_foreach, 0, 0, 5) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, regexp) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_multivar_iterator_new, 0, 0, 4) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, regexp) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_next, 0, 0, 2) + ZEND_ARG_INFO(0, iter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_iterator_free, 0, 0, 1) + ZEND_ARG_INFO(0, iter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_set_int32, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_set_int64, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_set_bool, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_set_string, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_set_multivar, 0, 0, 4) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, regexp) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_delete_entry, 0, 0, 2) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_delete_multivar, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, regexp) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_iterator_new, 0, 0, 2) + ZEND_ARG_INFO(0, cfg) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_iterator_glob_new, 0, 0, 3) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, regexp) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_foreach_match, 0, 0, 4) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, regexp) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_mapped, 0, 0, 5) + ZEND_ARG_INFO(0, cfg) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, maps) + ZEND_ARG_INFO(0, map_n) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_lookup_map_value, 0, 0, 4) + ZEND_ARG_INFO(0, maps) + ZEND_ARG_INFO(0, map_n) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_parse_bool, 0, 0, 2) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_parse_int32, 0, 0, 2) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_parse_int64, 0, 0, 2) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_backend_foreach_match, 0, 0, 5) + ZEND_ARG_INFO(0, backend) + ZEND_ARG_INFO(0, regexp) +// ZEND_ARG_INFO(0, ) +// ZEND_ARG_INFO(0, )) +// ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_config_find_global(length) +*/ +PHP_FUNCTION(git_config_find_global); + +/* {{{ proto resource git_config_find_xdg(length) +*/ +PHP_FUNCTION(git_config_find_xdg); + +/* {{{ proto resource git_config_find_system(length) +*/ +PHP_FUNCTION(git_config_find_system); + +/* {{{ proto resource git_config_open_default() +*/ +PHP_FUNCTION(git_config_open_default); + +/* {{{ proto resource git_config_new() +*/ +PHP_FUNCTION(git_config_new); + +/* {{{ proto long git_config_add_file_ondisk(cfg, path, level, force) +*/ +PHP_FUNCTION(git_config_add_file_ondisk); + +/* {{{ proto resource git_config_open_ondisk(path) +*/ +PHP_FUNCTION(git_config_open_ondisk); + +/* {{{ proto resource git_config_open_level(parent, level) +*/ +PHP_FUNCTION(git_config_open_level); + +/* {{{ proto resource git_config_open_global(config) +*/ +PHP_FUNCTION(git_config_open_global); + +/* {{{ proto long git_config_refresh(cfg) +*/ +PHP_FUNCTION(git_config_refresh); + +/* {{{ proto void git_config_free(cfg) +*/ +PHP_FUNCTION(git_config_free); + +/* {{{ proto resource git_config_get_entry(cfg, name) +*/ +PHP_FUNCTION(git_config_get_entry); + +/* {{{ proto resource git_config_get_int32(cfg, name) +*/ +PHP_FUNCTION(git_config_get_int32); + +/* {{{ proto resource git_config_get_int64(cfg, name) +*/ +PHP_FUNCTION(git_config_get_int64); + +/* {{{ proto resource git_config_get_bool(cfg, name) +*/ +PHP_FUNCTION(git_config_get_bool); + +/* {{{ proto resource git_config_get_string(cfg, name) +*/ +PHP_FUNCTION(git_config_get_string); + +/* {{{ proto long git_config_get_multivar_foreach(cfg, name, regexp, callback, payload) +*/ +PHP_FUNCTION(git_config_get_multivar_foreach); + +/* {{{ proto resource git_config_multivar_iterator_new(cfg, name, regexp) +*/ +PHP_FUNCTION(git_config_multivar_iterator_new); + +/* {{{ proto resource git_config_next(iter) +*/ +PHP_FUNCTION(git_config_next); + +/* {{{ proto void git_config_iterator_free(iter) +*/ +PHP_FUNCTION(git_config_iterator_free); + +/* {{{ proto long git_config_set_int32(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_int32); + +/* {{{ proto long git_config_set_int64(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_int64); + +/* {{{ proto long git_config_set_bool(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_bool); + +/* {{{ proto long git_config_set_string(cfg, name, value) +*/ +PHP_FUNCTION(git_config_set_string); + +/* {{{ proto long git_config_set_multivar(cfg, name, regexp, value) +*/ +PHP_FUNCTION(git_config_set_multivar); + +/* {{{ proto long git_config_delete_entry(cfg, name) +*/ +PHP_FUNCTION(git_config_delete_entry); + +/* {{{ proto long git_config_delete_multivar(cfg, name, regexp) +*/ +PHP_FUNCTION(git_config_delete_multivar); + +/* {{{ proto long git_config_foreach(cfg, callback, payload) +*/ +PHP_FUNCTION(git_config_foreach); + +/* {{{ proto resource git_config_iterator_new(cfg) +*/ +PHP_FUNCTION(git_config_iterator_new); + +/* {{{ proto resource git_config_iterator_glob_new(cfg, regexp) +*/ +PHP_FUNCTION(git_config_iterator_glob_new); + +/* {{{ proto long git_config_foreach_match(cfg, regexp, callback, payload) +*/ +PHP_FUNCTION(git_config_foreach_match); + +/* {{{ proto resource git_config_get_mapped(cfg, name, maps, map_n) +*/ +PHP_FUNCTION(git_config_get_mapped); + +/* {{{ proto resource git_config_lookup_map_value(maps, map_n, value) +*/ +PHP_FUNCTION(git_config_lookup_map_value); + +/* {{{ proto resource git_config_parse_bool(value) +*/ +PHP_FUNCTION(git_config_parse_bool); + +/* {{{ proto resource git_config_parse_int32(value) +*/ +PHP_FUNCTION(git_config_parse_int32); + +/* {{{ proto resource git_config_parse_int64(value) +*/ +PHP_FUNCTION(git_config_parse_int64); + +/* {{{ proto long git_config_backend_foreach_match(backend, regexp, , ), data) +*/ +PHP_FUNCTION(git_config_backend_foreach_match); + +#endif \ No newline at end of file diff --git a/gen.php b/gen.php index 611ae4ebd5..c3248638ed 100644 --- a/gen.php +++ b/gen.php @@ -19,7 +19,7 @@ $tmp['retval'] = $match[1][$i]; $d = count($list); - if (preg_match("/\*\*/", $list[0])) { + if ((preg_match("/(\*\*|out)/", $list[0]) || preg_match("/(write|create|new)/", $match[2][$i]))) { $d--; } diff --git a/php_git2.c b/php_git2.c index 787b5f66f6..95f81c228a 100644 --- a/php_git2.c +++ b/php_git2.c @@ -33,6 +33,7 @@ #include "revwalk.h" #include "treebuilder.h" #include "reference.h" +#include "g_config.h" int git2_resource_handle; @@ -61,6 +62,8 @@ void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) git_treebuilder_free(PHP_GIT2_V(resource, treebuilder)); case PHP_GIT2_TYPE_REFERENCE: git_reference_free(PHP_GIT2_V(resource, reference)); + case PHP_GIT2_TYPE_CONFIG: + git_config_free(PHP_GIT2_V(resource, config)); default: break; } @@ -213,6 +216,45 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_revwalk_free, arginfo_git_revwalk_free) PHP_FE(git_revwalk_repository, arginfo_git_revwalk_repository) + /* config */ + PHP_FE(git_config_find_global, arginfo_git_config_find_global) + PHP_FE(git_config_find_xdg, arginfo_git_config_find_xdg) + PHP_FE(git_config_find_system, arginfo_git_config_find_system) + PHP_FE(git_config_open_default, arginfo_git_config_open_default) + PHP_FE(git_config_new, arginfo_git_config_new) + PHP_FE(git_config_add_file_ondisk, arginfo_git_config_add_file_ondisk) + PHP_FE(git_config_open_ondisk, arginfo_git_config_open_ondisk) + PHP_FE(git_config_open_level, arginfo_git_config_open_level) + PHP_FE(git_config_open_global, arginfo_git_config_open_global) + PHP_FE(git_config_refresh, arginfo_git_config_refresh) + PHP_FE(git_config_free, arginfo_git_config_free) + PHP_FE(git_config_get_entry, arginfo_git_config_get_entry) + PHP_FE(git_config_get_int32, arginfo_git_config_get_int32) + PHP_FE(git_config_get_int64, arginfo_git_config_get_int64) + PHP_FE(git_config_get_bool, arginfo_git_config_get_bool) + PHP_FE(git_config_get_string, arginfo_git_config_get_string) + PHP_FE(git_config_get_multivar_foreach, arginfo_git_config_get_multivar_foreach) + PHP_FE(git_config_multivar_iterator_new, arginfo_git_config_multivar_iterator_new) + PHP_FE(git_config_next, arginfo_git_config_next) + PHP_FE(git_config_iterator_free, arginfo_git_config_iterator_free) + PHP_FE(git_config_set_int32, arginfo_git_config_set_int32) + PHP_FE(git_config_set_int64, arginfo_git_config_set_int64) + PHP_FE(git_config_set_bool, arginfo_git_config_set_bool) + PHP_FE(git_config_set_string, arginfo_git_config_set_string) + PHP_FE(git_config_set_multivar, arginfo_git_config_set_multivar) + PHP_FE(git_config_delete_entry, arginfo_git_config_delete_entry) + PHP_FE(git_config_delete_multivar, arginfo_git_config_delete_multivar) + PHP_FE(git_config_foreach, arginfo_git_config_foreach) + PHP_FE(git_config_iterator_new, arginfo_git_config_iterator_new) + PHP_FE(git_config_iterator_glob_new, arginfo_git_config_iterator_glob_new) + PHP_FE(git_config_foreach_match, arginfo_git_config_foreach_match) + PHP_FE(git_config_get_mapped, arginfo_git_config_get_mapped) + PHP_FE(git_config_lookup_map_value, arginfo_git_config_lookup_map_value) + PHP_FE(git_config_parse_bool, arginfo_git_config_parse_bool) + PHP_FE(git_config_parse_int32, arginfo_git_config_parse_int32) + PHP_FE(git_config_parse_int64, arginfo_git_config_parse_int64) + PHP_FE(git_config_backend_foreach_match, arginfo_git_config_backend_foreach_match) + PHP_FE_END }; diff --git a/php_git2.h b/php_git2.h index 1128ba472b..556207651f 100644 --- a/php_git2.h +++ b/php_git2.h @@ -82,6 +82,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_REVWALK, PHP_GIT2_TYPE_TREEBUILDER, PHP_GIT2_TYPE_REFERENCE, + PHP_GIT2_TYPE_CONFIG, }; typedef struct php_git2_t { @@ -95,6 +96,7 @@ typedef struct php_git2_t { git_revwalk *revwalk; git_treebuilder *treebuilder; git_reference *reference; + git_config *config; } v; int should_free_v; int resource_id; From 75e9093728a79331b14f6978a91ab41b6a78a405 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 13:14:57 +0900 Subject: [PATCH 013/136] [config] add parse --- g_config.c | 209 ++++++++++++++++++++++++++++------------------------- 1 file changed, 111 insertions(+), 98 deletions(-) diff --git a/g_config.c b/g_config.c index d35778d089..65e30fc856 100644 --- a/g_config.c +++ b/g_config.c @@ -64,6 +64,102 @@ static void php_git2_config_get_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2 } } +static void php_git2_config_set_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2_config type) +{ + zval *cfg; + php_git2_t *_cfg; + char *name = {0}; + int name_len; + int error = 0; + zval *value; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsz", &cfg, &name, &name_len, &value) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + switch (type) { + case PHP_GIT2_CONFIG_STRING: { + if (Z_TYPE_P(value) != IS_STRING) { + convert_to_string(value); + } + error = git_config_set_string(PHP_GIT2_V(_cfg, config), name, Z_STRVAL_P(value)); + if (php_git2_check_error(error, "git_config_set_string" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; + break; + } + case PHP_GIT2_CONFIG_BOOL: { + if (Z_TYPE_P(value) != IS_BOOL) { + convert_to_bool(value); + } + error = git_config_set_bool(PHP_GIT2_V(_cfg, config), name, Z_LVAL_P(value)); + if (php_git2_check_error(error, "git_config_set_bool" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; + break; + } + case PHP_GIT2_CONFIG_INT32: { + if (Z_TYPE_P(value) != IS_LONG) { + convert_to_long(value); + } + error = git_config_set_int32(PHP_GIT2_V(_cfg, config), name, Z_LVAL_P(value)); + if (php_git2_check_error(error, "git_config_set_int32" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; + break; + } + case PHP_GIT2_CONFIG_INT64: { + if (Z_TYPE_P(value) != IS_LONG) { + convert_to_long(value); + } + error = git_config_set_int64(PHP_GIT2_V(_cfg, config), name, Z_LVAL_P(value)); + if (php_git2_check_error(error, "git_config_set_int64" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; + break; + } + } +} + + +static void php_git2_config_parse_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2_config type) +{ + char *value = {0}; + int value_len; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &value, &value_len) == FAILURE) { + return; + } + + switch (type) { + case PHP_GIT2_CONFIG_BOOL: { + int result; + result = git_config_parse_bool(&result, value); + RETURN_BOOL(result); + break; + } + case PHP_GIT2_CONFIG_INT32: { + int32_t result; + result = git_config_parse_int32(&result, value); + RETURN_LONG(result); + break; + } + case PHP_GIT2_CONFIG_INT64: { + int64_t result; + result = git_config_parse_int64(&result, value); + RETURN_LONG(result); + break; + } + } +} /* {{{ proto resource git_config_find_global() */ @@ -420,85 +516,28 @@ PHP_FUNCTION(git_config_iterator_free) */ PHP_FUNCTION(git_config_set_int32) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - long value; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_int32 not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsl", &cfg, &name, &name_len, &value) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_config_set_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_INT32); } /* {{{ proto long git_config_set_int64(cfg, name, value) */ PHP_FUNCTION(git_config_set_int64) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - long value; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_int64 not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsl", &cfg, &name, &name_len, &value) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_config_set_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_INT64); } /* {{{ proto long git_config_set_bool(cfg, name, value) */ PHP_FUNCTION(git_config_set_bool) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - long value; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_bool not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsl", &cfg, &name, &name_len, &value) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_config_set_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_BOOL); } /* {{{ proto long git_config_set_string(cfg, name, value) */ PHP_FUNCTION(git_config_set_string) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - char *value = {0}; - int value_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_string not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rss", &cfg, &name, &name_len, &value, &value_len) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_config_set_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_STRING); } /* {{{ proto long git_config_set_multivar(cfg, name, regexp, value) @@ -533,16 +572,20 @@ PHP_FUNCTION(git_config_delete_entry) php_git2_t *_cfg; char *name = {0}; int name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_delete_entry not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &cfg, &name, &name_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_config_delete_entry(PHP_GIT2_V(_cfg, config), name); + if (php_git2_check_error(error, "git_config_delete_entry" TSRMLS_CC)) { + RETURN_FALSE + } + + RETURN_TRUE; } /* {{{ proto long git_config_delete_multivar(cfg, name, regexp) @@ -695,51 +738,21 @@ PHP_FUNCTION(git_config_lookup_map_value) */ PHP_FUNCTION(git_config_parse_bool) { - char *value = {0}; - int value_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_parse_bool not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &value, &value_len) == FAILURE) { - return; - } + php_git2_config_parse_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_BOOL); } /* {{{ proto resource git_config_parse_int32(value) */ PHP_FUNCTION(git_config_parse_int32) { - char *value = {0}; - int value_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_parse_int32 not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &value, &value_len) == FAILURE) { - return; - } + php_git2_config_parse_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_INT32); } /* {{{ proto resource git_config_parse_int64(value) */ PHP_FUNCTION(git_config_parse_int64) { - char *value = {0}; - int value_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_parse_int64 not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &value, &value_len) == FAILURE) { - return; - } + php_git2_config_parse_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_INT64); } /* {{{ proto long git_config_backend_foreach_match(backend, regexp, , ), data) From 0d3856f12b3d1ff2b80a1c53539841e11e0b49b2 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 13:28:22 +0900 Subject: [PATCH 014/136] wip --- g_config.c | 79 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/g_config.c b/g_config.c index 65e30fc856..c2690608b5 100644 --- a/g_config.c +++ b/g_config.c @@ -258,19 +258,21 @@ PHP_FUNCTION(git_config_add_file_ondisk) php_git2_t *_cfg; char *path = {0}; int path_len; - zval *level; - php_git2_t *_level; - long force; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_add_file_ondisk not implemented yet"); - return; + long level; + long force = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl", &cfg, &path, &path_len, &level, &force) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_config_add_file_ondisk(PHP_GIT2_V(_cfg, config), path, level, force); + if (php_git2_check_error(error, "git_config_add_file_ondisk" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto resource git_config_open_ondisk(path) @@ -279,15 +281,25 @@ PHP_FUNCTION(git_config_open_ondisk) { char *path = {0}; int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_ondisk not implemented yet"); - return; + git_config *config; + php_git2_t *result; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) { return; } + error = git_config_open_ondisk(&config, path); + if (php_git2_check_error(error, "git_config_open_ondisk" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, config) = config; + result->type = PHP_GIT2_TYPE_CONFIG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_config_open_level(parent, level) @@ -295,19 +307,28 @@ PHP_FUNCTION(git_config_open_ondisk) PHP_FUNCTION(git_config_open_level) { zval *parent; - php_git2_t *_parent; - zval *level; - php_git2_t *_level; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_level not implemented yet"); - return; + php_git2_t *_parent, *result; + long level; + int error = 0; + git_config *out; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &parent, &level) == FAILURE) { + "rl", &parent, &level) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_parent, php_git2_t*, &parent, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_config_open_level(&out, PHP_GIT2_V(_parent, config), level); + if (php_git2_check_error(error, "git_config_open_level" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, config) = out; + result->type = PHP_GIT2_TYPE_CONFIG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_config_open_global(config) @@ -315,17 +336,27 @@ PHP_FUNCTION(git_config_open_level) PHP_FUNCTION(git_config_open_global) { zval *config; - php_git2_t *_config; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_global not implemented yet"); - return; + php_git2_t *_config, *result; + git_config *out; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &config) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_config, php_git2_t*, &config, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_config_open_global(&out, PHP_GIT2_V(_config, config)); + if (php_git2_check_error(error, "git_config_open_global" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, config) = out; + result->type = PHP_GIT2_TYPE_CONFIG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto long git_config_refresh(cfg) From 36866824cb4e95767f30064d98d3ae7ae2fce04f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 13:45:34 +0900 Subject: [PATCH 015/136] add stubs --- config.m4 | 2 +- gen.php | 2 +- index.c | 653 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.h | 305 ++++++++++++++++++++++++ object.c | 251 ++++++++++++++++++++ object.h | 141 +++++++++++ php_git2.c | 83 +++++++ php_git2.h | 4 + repository.c | 533 ++++++++++++++++++++++++++++++++++++++++- repository.h | 243 +++++++++++++++++++ 10 files changed, 2214 insertions(+), 3 deletions(-) create mode 100644 index.c create mode 100644 index.h create mode 100644 object.c create mode 100644 object.h diff --git a/config.m4 b/config.m4 index 3c6284b5e2..40319b56d4 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/gen.php b/gen.php index c3248638ed..c75f6504aa 100644 --- a/gen.php +++ b/gen.php @@ -23,7 +23,7 @@ $d--; } - if (isset($_SERVER['argv'][3]) && !preg_match("/{$_SERVER['argv'][3]}/", $match[2][$i])) { + if (isset($_SERVER['argv'][3]) && preg_match("/{$_SERVER['argv'][3]}/", $match[2][$i])) { continue; } diff --git a/index.c b/index.c new file mode 100644 index 0000000000..c914bd47c6 --- /dev/null +++ b/index.c @@ -0,0 +1,653 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "index.h" +/* {{{ proto resource git_index_open(index_path) +*/ +PHP_FUNCTION(git_index_open) +{ + char *index_path = {0}; + int index_path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_open not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &index_path, &index_path_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_index_new() +*/ +PHP_FUNCTION(git_index_new) +{ + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_new not implemented yet"); + return; +} + +/* {{{ proto void git_index_free(index) +*/ +PHP_FUNCTION(git_index_free) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_owner(index) +*/ +PHP_FUNCTION(git_index_owner) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_owner not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_caps(index) +*/ +PHP_FUNCTION(git_index_caps) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_caps not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_set_caps(index, caps) +*/ +PHP_FUNCTION(git_index_set_caps) +{ + zval *index; + php_git2_t *_index; + long caps; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_set_caps not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &index, &caps) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_read(index, force) +*/ +PHP_FUNCTION(git_index_read) +{ + zval *index; + php_git2_t *_index; + long force; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_read not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &index, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_write() +*/ +PHP_FUNCTION(git_index_write) +{ + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_write not implemented yet"); + return; +} + +/* {{{ proto resource git_index_path(index) +*/ +PHP_FUNCTION(git_index_path) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_path not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_read_tree(index, tree) +*/ +PHP_FUNCTION(git_index_read_tree) +{ + zval *index; + php_git2_t *_index; + zval *tree; + php_git2_t *_tree; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_read_tree not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &index, &tree) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_write_tree(index) +*/ +PHP_FUNCTION(git_index_write_tree) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_write_tree not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_write_tree_to(index, repo) +*/ +PHP_FUNCTION(git_index_write_tree_to) +{ + zval *index; + php_git2_t *_index; + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_write_tree_to not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &index, &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_entrycount(index) +*/ +PHP_FUNCTION(git_index_entrycount) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_entrycount not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_index_clear(index) +*/ +PHP_FUNCTION(git_index_clear) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_clear not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_get_byindex(index, n) +*/ +PHP_FUNCTION(git_index_get_byindex) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_get_byindex not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &index, &n) == FAILURE) { +// return; +// } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_get_bypath(index, path, stage) +*/ +PHP_FUNCTION(git_index_get_bypath) +{ + zval *index; + php_git2_t *_index; + char *path = {0}; + int path_len; + long stage; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_get_bypath not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &index, &path, &path_len, &stage) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_remove(index, path, stage) +*/ +PHP_FUNCTION(git_index_remove) +{ + zval *index; + php_git2_t *_index; + char *path = {0}; + int path_len; + long stage; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &index, &path, &path_len, &stage) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_remove_directory(index, dir, stage) +*/ +PHP_FUNCTION(git_index_remove_directory) +{ + zval *index; + php_git2_t *_index; + char *dir = {0}; + int dir_len; + long stage; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove_directory not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &index, &dir, &dir_len, &stage) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_add(index, source_entry) +*/ +PHP_FUNCTION(git_index_add) +{ + zval *index; + php_git2_t *_index; + zval *source_entry; + php_git2_t *_source_entry; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_add not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &index, &source_entry) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_entry_stage(entry) +*/ +PHP_FUNCTION(git_index_entry_stage) +{ + zval *entry; + php_git2_t *_entry; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_entry_stage not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &entry) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_add_bypath(index, path) +*/ +PHP_FUNCTION(git_index_add_bypath) +{ + zval *index; + php_git2_t *_index; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_add_bypath not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &index, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_remove_bypath(index, path) +*/ +PHP_FUNCTION(git_index_remove_bypath) +{ + zval *index; + php_git2_t *_index; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove_bypath not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &index, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_add_all(index, pathspec, flags, callback, payload) +*/ +PHP_FUNCTION(git_index_add_all) +{ + zval *index; + php_git2_t *_index; + zval *pathspec; + php_git2_t *_pathspec; + long flags; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_add_all not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrlr", &index, &pathspec, &flags, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_remove_all(index, pathspec, callback, payload) +*/ +PHP_FUNCTION(git_index_remove_all) +{ + zval *index; + php_git2_t *_index; + zval *pathspec; + php_git2_t *_pathspec; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove_all not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrr", &index, &pathspec, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_update_all(index, pathspec, callback, payload) +*/ +PHP_FUNCTION(git_index_update_all) +{ + zval *index; + php_git2_t *_index; + zval *pathspec; + php_git2_t *_pathspec; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_update_all not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrr", &index, &pathspec, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_find(at_pos, index, path) +*/ +PHP_FUNCTION(git_index_find) +{ + zval *index; + php_git2_t *_index; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_find not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rs", &at_pos, &index, &path, &path_len) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_at_pos, php_git2_t*, &at_pos, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_conflict_add(index, ancestor_entry, our_entry, their_entry) +*/ +PHP_FUNCTION(git_index_conflict_add) +{ + zval *index; + php_git2_t *_index; + zval *ancestor_entry; + php_git2_t *_ancestor_entry; + zval *our_entry; + php_git2_t *_our_entry; + zval *their_entry; + php_git2_t *_their_entry; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_add not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrrr", &index, &ancestor_entry, &our_entry, &their_entry) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_conflict_get(our_out, their_out, index, path) +*/ +PHP_FUNCTION(git_index_conflict_get) +{ + zval *our_out; + php_git2_t *_our_out; + zval *their_out; + php_git2_t *_their_out; + zval *index; + php_git2_t *_index; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_get not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrrs", &our_out, &their_out, &index, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_our_out, php_git2_t*, &our_out, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_conflict_remove(index, path) +*/ +PHP_FUNCTION(git_index_conflict_remove) +{ + zval *index; + php_git2_t *_index; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_remove not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &index, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_index_conflict_cleanup(index) +*/ +PHP_FUNCTION(git_index_conflict_cleanup) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_cleanup not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_index_has_conflicts(index) +*/ +PHP_FUNCTION(git_index_has_conflicts) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_has_conflicts not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_conflict_iterator_new(index) +*/ +PHP_FUNCTION(git_index_conflict_iterator_new) +{ + zval *index; + php_git2_t *_index; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_iterator_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_index_conflict_next(our_out, their_out, iterator) +*/ +PHP_FUNCTION(git_index_conflict_next) +{ + zval *our_out; + php_git2_t *_our_out; + zval *their_out; + php_git2_t *_their_out; + zval *iterator; + php_git2_t *_iterator; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_next not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrr", &our_out, &their_out, &iterator) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_our_out, php_git2_t*, &our_out, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_index_conflict_iterator_free(iterator) +*/ +PHP_FUNCTION(git_index_conflict_iterator_free) +{ + zval *iterator; + php_git2_t *_iterator; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_iterator_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &iterator) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_iterator, php_git2_t*, &iterator, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/index.h b/index.h new file mode 100644 index 0000000000..56bce30f54 --- /dev/null +++ b/index.h @@ -0,0 +1,305 @@ +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_open, 0, 0, 1) + ZEND_ARG_INFO(0, index_path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_new, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_free, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_owner, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_caps, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_set_caps, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, caps) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_read, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_write, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_path, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_read_tree, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, tree) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_write_tree, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_write_tree_to, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_entrycount, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_clear, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_get_byindex, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, n) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_get_bypath, 0, 0, 3) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, stage) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_remove, 0, 0, 3) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, stage) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_remove_directory, 0, 0, 3) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, dir) + ZEND_ARG_INFO(0, stage) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_add, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, source_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_entry_stage, 0, 0, 1) + ZEND_ARG_INFO(0, entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_add_bypath, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_remove_bypath, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_add_all, 0, 0, 5) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, pathspec) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_remove_all, 0, 0, 4) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, pathspec) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_update_all, 0, 0, 4) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, pathspec) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_find, 0, 0, 3) + ZEND_ARG_INFO(0, at_pos) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_conflict_add, 0, 0, 4) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, ancestor_entry) + ZEND_ARG_INFO(0, our_entry) + ZEND_ARG_INFO(0, their_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_conflict_get, 0, 0, 4) + ZEND_ARG_INFO(0, our_out) + ZEND_ARG_INFO(0, their_out) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_conflict_remove, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_conflict_cleanup, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_has_conflicts, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_conflict_iterator_new, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_conflict_next, 0, 0, 3) + ZEND_ARG_INFO(0, our_out) + ZEND_ARG_INFO(0, their_out) + ZEND_ARG_INFO(0, iterator) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_conflict_iterator_free, 0, 0, 1) + ZEND_ARG_INFO(0, iterator) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_index_open(index_path) +*/ +PHP_FUNCTION(git_index_open); + +/* {{{ proto resource git_index_new() +*/ +PHP_FUNCTION(git_index_new); + +/* {{{ proto void git_index_free(index) +*/ +PHP_FUNCTION(git_index_free); + +/* {{{ proto resource git_index_owner(index) +*/ +PHP_FUNCTION(git_index_owner); + +/* {{{ proto resource git_index_caps(index) +*/ +PHP_FUNCTION(git_index_caps); + +/* {{{ proto long git_index_set_caps(index, caps) +*/ +PHP_FUNCTION(git_index_set_caps); + +/* {{{ proto long git_index_read(index, force) +*/ +PHP_FUNCTION(git_index_read); + +/* {{{ proto resource git_index_write() +*/ +PHP_FUNCTION(git_index_write); + +/* {{{ proto resource git_index_path(index) +*/ +PHP_FUNCTION(git_index_path); + +/* {{{ proto long git_index_read_tree(index, tree) +*/ +PHP_FUNCTION(git_index_read_tree); + +/* {{{ proto resource git_index_write_tree(index) +*/ +PHP_FUNCTION(git_index_write_tree); + +/* {{{ proto resource git_index_write_tree_to(index, repo) +*/ +PHP_FUNCTION(git_index_write_tree_to); + +/* {{{ proto resource git_index_entrycount(index) +*/ +PHP_FUNCTION(git_index_entrycount); + +/* {{{ proto void git_index_clear(index) +*/ +PHP_FUNCTION(git_index_clear); + +/* {{{ proto resource git_index_get_byindex(index, n) +*/ +PHP_FUNCTION(git_index_get_byindex); + +/* {{{ proto resource git_index_get_bypath(index, path, stage) +*/ +PHP_FUNCTION(git_index_get_bypath); + +/* {{{ proto long git_index_remove(index, path, stage) +*/ +PHP_FUNCTION(git_index_remove); + +/* {{{ proto long git_index_remove_directory(index, dir, stage) +*/ +PHP_FUNCTION(git_index_remove_directory); + +/* {{{ proto long git_index_add(index, source_entry) +*/ +PHP_FUNCTION(git_index_add); + +/* {{{ proto long git_index_entry_stage(entry) +*/ +PHP_FUNCTION(git_index_entry_stage); + +/* {{{ proto long git_index_add_bypath(index, path) +*/ +PHP_FUNCTION(git_index_add_bypath); + +/* {{{ proto long git_index_remove_bypath(index, path) +*/ +PHP_FUNCTION(git_index_remove_bypath); + +/* {{{ proto long git_index_add_all(index, pathspec, flags, callback, payload) +*/ +PHP_FUNCTION(git_index_add_all); + +/* {{{ proto long git_index_remove_all(index, pathspec, callback, payload) +*/ +PHP_FUNCTION(git_index_remove_all); + +/* {{{ proto long git_index_update_all(index, pathspec, callback, payload) +*/ +PHP_FUNCTION(git_index_update_all); + +/* {{{ proto long git_index_find(at_pos, index, path) +*/ +PHP_FUNCTION(git_index_find); + +/* {{{ proto long git_index_conflict_add(index, ancestor_entry, our_entry, their_entry) +*/ +PHP_FUNCTION(git_index_conflict_add); + +/* {{{ proto resource git_index_conflict_get(our_out, their_out, index, path) +*/ +PHP_FUNCTION(git_index_conflict_get); + +/* {{{ proto long git_index_conflict_remove(index, path) +*/ +PHP_FUNCTION(git_index_conflict_remove); + +/* {{{ proto void git_index_conflict_cleanup(index) +*/ +PHP_FUNCTION(git_index_conflict_cleanup); + +/* {{{ proto long git_index_has_conflicts(index) +*/ +PHP_FUNCTION(git_index_has_conflicts); + +/* {{{ proto resource git_index_conflict_iterator_new(index) +*/ +PHP_FUNCTION(git_index_conflict_iterator_new); + +/* {{{ proto resource git_index_conflict_next(our_out, their_out, iterator) +*/ +PHP_FUNCTION(git_index_conflict_next); + +/* {{{ proto void git_index_conflict_iterator_free(iterator) +*/ +PHP_FUNCTION(git_index_conflict_iterator_free); + diff --git a/object.c b/object.c new file mode 100644 index 0000000000..0da7c36c06 --- /dev/null +++ b/object.c @@ -0,0 +1,251 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "object.h" + +/* {{{ proto resource git_object_lookup(repo, id, type) +*/ +PHP_FUNCTION(git_object_lookup) +{ + zval *repo; + php_git2_t *_repo; + char *id = {0}; + int id_len; + zval *type; + php_git2_t *_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_lookup not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsr", &repo, &id, &id_len, &type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_lookup_prefix(repo, id, len, type) +*/ +PHP_FUNCTION(git_object_lookup_prefix) +{ + zval *repo; + php_git2_t *_repo; + char *id = {0}; + int id_len; + zval *type; + php_git2_t *_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_lookup_prefix not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rsr", &repo, &id, &id_len, &len, &type) == FAILURE) { +// return; +// } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_lookup_bypath(treeish, path, type) +*/ +PHP_FUNCTION(git_object_lookup_bypath) +{ + zval *treeish; + php_git2_t *_treeish; + char *path = {0}; + int path_len; + zval *type; + php_git2_t *_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_lookup_bypath not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsr", &treeish, &path, &path_len, &type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_treeish, php_git2_t*, &treeish, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_id(obj) +*/ +PHP_FUNCTION(git_object_id) +{ + zval *obj; + php_git2_t *_obj; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_id not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &obj) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_type(obj) +*/ +PHP_FUNCTION(git_object_type) +{ + zval *obj; + php_git2_t *_obj; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_type not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &obj) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_owner(obj) +*/ +PHP_FUNCTION(git_object_owner) +{ + zval *obj; + php_git2_t *_obj; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_owner not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &obj) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_object_free(object) +*/ +PHP_FUNCTION(git_object_free) +{ + zval *object; + php_git2_t *_object; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &object) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_type2string(type) +*/ +PHP_FUNCTION(git_object_type2string) +{ + zval *type; + php_git2_t *_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_type2string not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_string2type(str) +*/ +PHP_FUNCTION(git_object_string2type) +{ + char *str = {0}; + int str_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_string2type not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &str, &str_len) == FAILURE) { + return; + } +} + +/* {{{ proto long git_object_typeisloose(type) +*/ +PHP_FUNCTION(git_object_typeisloose) +{ + zval *type; + php_git2_t *_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_typeisloose not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object__size(type) +*/ +PHP_FUNCTION(git_object__size) +{ + zval *type; + php_git2_t *_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object__size not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_peel(object, target_type) +*/ +PHP_FUNCTION(git_object_peel) +{ + zval *object; + php_git2_t *_object; + zval *target_type; + php_git2_t *_target_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_peel not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &object, &target_type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_object_dup(source) +*/ +PHP_FUNCTION(git_object_dup) +{ + zval *source; + php_git2_t *_source; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_dup not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &source) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/object.h b/object.h new file mode 100644 index 0000000000..dc414ef3d1 --- /dev/null +++ b/object.h @@ -0,0 +1,141 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_OBJECT_H +#define PHP_GIT2_OBJECT_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_lookup, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_lookup_prefix, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, len) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_lookup_bypath, 0, 0, 3) + ZEND_ARG_INFO(0, treeish) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_id, 0, 0, 1) + ZEND_ARG_INFO(0, obj) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_type, 0, 0, 1) + ZEND_ARG_INFO(0, obj) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_owner, 0, 0, 1) + ZEND_ARG_INFO(0, obj) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_free, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_type2string, 0, 0, 1) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_string2type, 0, 0, 1) + ZEND_ARG_INFO(0, str) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_typeisloose, 0, 0, 1) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object__size, 0, 0, 1) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_peel, 0, 0, 2) + ZEND_ARG_INFO(0, object) + ZEND_ARG_INFO(0, target_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_object_dup, 0, 0, 1) + ZEND_ARG_INFO(0, source) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_object_lookup(repo, id, type) +*/ +PHP_FUNCTION(git_object_lookup); + +/* {{{ proto resource git_object_lookup_prefix(repo, id, len, type) +*/ +PHP_FUNCTION(git_object_lookup_prefix); + +/* {{{ proto resource git_object_lookup_bypath(treeish, path, type) +*/ +PHP_FUNCTION(git_object_lookup_bypath); + +/* {{{ proto resource git_object_id(obj) +*/ +PHP_FUNCTION(git_object_id); + +/* {{{ proto resource git_object_type(obj) +*/ +PHP_FUNCTION(git_object_type); + +/* {{{ proto resource git_object_owner(obj) +*/ +PHP_FUNCTION(git_object_owner); + +/* {{{ proto void git_object_free(object) +*/ +PHP_FUNCTION(git_object_free); + +/* {{{ proto resource git_object_type2string(type) +*/ +PHP_FUNCTION(git_object_type2string); + +/* {{{ proto resource git_object_string2type(str) +*/ +PHP_FUNCTION(git_object_string2type); + +/* {{{ proto long git_object_typeisloose(type) +*/ +PHP_FUNCTION(git_object_typeisloose); + +/* {{{ proto resource git_object__size(type) +*/ +PHP_FUNCTION(git_object__size); + +/* {{{ proto resource git_object_peel(object, target_type) +*/ +PHP_FUNCTION(git_object_peel); + +/* {{{ proto resource git_object_dup(source) +*/ +PHP_FUNCTION(git_object_dup); + +#endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 95f81c228a..ff09f13b72 100644 --- a/php_git2.c +++ b/php_git2.c @@ -34,6 +34,8 @@ #include "treebuilder.h" #include "reference.h" #include "g_config.h" +#include "object.h" +#include "index.h" int git2_resource_handle; @@ -84,13 +86,94 @@ static zend_class_entry *php_git2_get_exception_base(TSRMLS_D) } static zend_function_entry php_git2_functions[] = { + /* repository */ PHP_FE(git_repository_new, arginfo_git_repository_new) PHP_FE(git_repository_init, arginfo_git_repository_init) PHP_FE(git_repository_open_bare, arginfo_git_repository_open_bare) PHP_FE(git_repository_open, arginfo_git_repository_open) PHP_FE(git_repository_get_namespace, arginfo_git_repository_get_namespace) PHP_FE(git_repository_workdir, arginfo_git_repository_workdir) + PHP_FE(git_repository_wrap_odb, arginfo_git_repository_wrap_odb) + PHP_FE(git_repository_discover, arginfo_git_repository_discover) + PHP_FE(git_repository_open_ext, arginfo_git_repository_open_ext) + PHP_FE(git_repository_free, arginfo_git_repository_free) + PHP_FE(git_repository_init_ext, arginfo_git_repository_init_ext) + PHP_FE(git_repository_head, arginfo_git_repository_head) + PHP_FE(git_repository_head_detached, arginfo_git_repository_head_detached) + PHP_FE(git_repository_head_unborn, arginfo_git_repository_head_unborn) + PHP_FE(git_repository_is_empty, arginfo_git_repository_is_empty) + PHP_FE(git_repository_path, arginfo_git_repository_path) + PHP_FE(git_repository_set_workdir, arginfo_git_repository_set_workdir) + PHP_FE(git_repository_is_bare, arginfo_git_repository_is_bare) + PHP_FE(git_repository_config, arginfo_git_repository_config) + PHP_FE(git_repository_odb, arginfo_git_repository_odb) + PHP_FE(git_repository_refdb, arginfo_git_repository_refdb) + PHP_FE(git_repository_index, arginfo_git_repository_index) + PHP_FE(git_repository_message, arginfo_git_repository_message) + PHP_FE(git_repository_message_remove, arginfo_git_repository_message_remove) + PHP_FE(git_repository_merge_cleanup, arginfo_git_repository_merge_cleanup) + PHP_FE(git_repository_fetchhead_foreach, arginfo_git_repository_fetchhead_foreach) + PHP_FE(git_repository_mergehead_foreach, arginfo_git_repository_mergehead_foreach) + PHP_FE(git_repository_hashfile, arginfo_git_repository_hashfile) + PHP_FE(git_repository_set_head, arginfo_git_repository_set_head) + PHP_FE(git_repository_set_head_detached, arginfo_git_repository_set_head_detached) + PHP_FE(git_repository_detach_head, arginfo_git_repository_detach_head) + PHP_FE(git_repository_state, arginfo_git_repository_state) + PHP_FE(git_repository_set_namespace, arginfo_git_repository_set_namespace) + PHP_FE(git_repository_is_shallow, arginfo_git_repository_is_shallow) + /* index */ + PHP_FE(git_index_open, arginfo_git_index_open) + PHP_FE(git_index_new, arginfo_git_index_new) + PHP_FE(git_index_free, arginfo_git_index_free) + PHP_FE(git_index_owner, arginfo_git_index_owner) + PHP_FE(git_index_caps, arginfo_git_index_caps) + PHP_FE(git_index_set_caps, arginfo_git_index_set_caps) + PHP_FE(git_index_read, arginfo_git_index_read) + PHP_FE(git_index_write, arginfo_git_index_write) + PHP_FE(git_index_path, arginfo_git_index_path) + PHP_FE(git_index_read_tree, arginfo_git_index_read_tree) + PHP_FE(git_index_write_tree, arginfo_git_index_write_tree) + PHP_FE(git_index_write_tree_to, arginfo_git_index_write_tree_to) + PHP_FE(git_index_entrycount, arginfo_git_index_entrycount) + PHP_FE(git_index_clear, arginfo_git_index_clear) + PHP_FE(git_index_get_byindex, arginfo_git_index_get_byindex) + PHP_FE(git_index_get_bypath, arginfo_git_index_get_bypath) + PHP_FE(git_index_remove, arginfo_git_index_remove) + PHP_FE(git_index_remove_directory, arginfo_git_index_remove_directory) + PHP_FE(git_index_add, arginfo_git_index_add) + PHP_FE(git_index_entry_stage, arginfo_git_index_entry_stage) + PHP_FE(git_index_add_bypath, arginfo_git_index_add_bypath) + PHP_FE(git_index_remove_bypath, arginfo_git_index_remove_bypath) + PHP_FE(git_index_add_all, arginfo_git_index_add_all) + PHP_FE(git_index_remove_all, arginfo_git_index_remove_all) + PHP_FE(git_index_update_all, arginfo_git_index_update_all) + PHP_FE(git_index_find, arginfo_git_index_find) + PHP_FE(git_index_conflict_add, arginfo_git_index_conflict_add) + PHP_FE(git_index_conflict_get, arginfo_git_index_conflict_get) + PHP_FE(git_index_conflict_remove, arginfo_git_index_conflict_remove) + PHP_FE(git_index_conflict_cleanup, arginfo_git_index_conflict_cleanup) + PHP_FE(git_index_has_conflicts, arginfo_git_index_has_conflicts) + PHP_FE(git_index_conflict_iterator_new, arginfo_git_index_conflict_iterator_new) + PHP_FE(git_index_conflict_next, arginfo_git_index_conflict_next) + PHP_FE(git_index_conflict_iterator_free, arginfo_git_index_conflict_iterator_free) + + /* object */ + PHP_FE(git_object_lookup, arginfo_git_object_lookup) + PHP_FE(git_object_lookup_prefix, arginfo_git_object_lookup_prefix) + PHP_FE(git_object_lookup_bypath, arginfo_git_object_lookup_bypath) + PHP_FE(git_object_id, arginfo_git_object_id) + PHP_FE(git_object_type, arginfo_git_object_type) + PHP_FE(git_object_owner, arginfo_git_object_owner) + PHP_FE(git_object_free, arginfo_git_object_free) + PHP_FE(git_object_type2string, arginfo_git_object_type2string) + PHP_FE(git_object_string2type, arginfo_git_object_string2type) + PHP_FE(git_object_typeisloose, arginfo_git_object_typeisloose) + PHP_FE(git_object__size, arginfo_git_object__size) + PHP_FE(git_object_peel, arginfo_git_object_peel) + PHP_FE(git_object_dup, arginfo_git_object_dup) + + /* clone */ PHP_FE(git_clone, arginfo_git_clone) /* reference */ diff --git a/php_git2.h b/php_git2.h index 556207651f..8a77627cb1 100644 --- a/php_git2.h +++ b/php_git2.h @@ -83,6 +83,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_TREEBUILDER, PHP_GIT2_TYPE_REFERENCE, PHP_GIT2_TYPE_CONFIG, + PHP_GIT2_TYPE_OBJECT, + PHP_GIT2_TYPE_INDEX, }; typedef struct php_git2_t { @@ -97,6 +99,8 @@ typedef struct php_git2_t { git_treebuilder *treebuilder; git_reference *reference; git_config *config; + git_object *object; + git_index *index; } v; int should_free_v; int resource_id; diff --git a/repository.c b/repository.c index ba81e1a25d..3364337dff 100644 --- a/repository.c +++ b/repository.c @@ -157,4 +157,535 @@ PHP_FUNCTION(git_repository_workdir) RETURN_STRING("", 1); } } -/* }}} */ \ No newline at end of file +/* }}} */ + +/* {{{ proto resource git_repository_wrap_odb(odb) +*/ +PHP_FUNCTION(git_repository_wrap_odb) +{ + zval *odb; + php_git2_t *_odb; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_wrap_odb not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &odb) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_discover(path_size, start_path, across_fs, ceiling_dirs) +*/ +PHP_FUNCTION(git_repository_discover) +{ + char *start_path = {0}; + int start_path_len; + long across_fs; + char *ceiling_dirs = {0}; + int ceiling_dirs_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_discover not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "sls", &path_size, &start_path, &start_path_len, &across_fs, &ceiling_dirs, &ceiling_dirs_len) == FAILURE) { +// return; +// } +} + +/* {{{ proto resource git_repository_open_ext(path, flags, ceiling_dirs) +*/ +PHP_FUNCTION(git_repository_open_ext) +{ + char *path = {0}; + int path_len; + long flags; + char *ceiling_dirs = {0}; + int ceiling_dirs_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_open_ext not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sls", &path, &path_len, &flags, &ceiling_dirs, &ceiling_dirs_len) == FAILURE) { + return; + } +} + +/* {{{ proto void git_repository_free(repo) +*/ +PHP_FUNCTION(git_repository_free) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_init_ext(repo_path, opts) +*/ +PHP_FUNCTION(git_repository_init_ext) +{ + char *repo_path = {0}; + int repo_path_len; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_init_ext not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "sr", &repo_path, &repo_path_len, &opts) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_repo_path, php_git2_t*, &repo_path, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_head(repo) +*/ +PHP_FUNCTION(git_repository_head) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_head not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_head_detached(repo) +*/ +PHP_FUNCTION(git_repository_head_detached) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_head_detached not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_head_unborn(repo) +*/ +PHP_FUNCTION(git_repository_head_unborn) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_head_unborn not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_is_empty(repo) +*/ +PHP_FUNCTION(git_repository_is_empty) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_is_empty not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_path(repo) +*/ +PHP_FUNCTION(git_repository_path) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_path not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_set_workdir(repo, workdir, update_gitlink) +*/ +PHP_FUNCTION(git_repository_set_workdir) +{ + zval *repo; + php_git2_t *_repo; + char *workdir = {0}; + int workdir_len; + long update_gitlink; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_workdir not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &repo, &workdir, &workdir_len, &update_gitlink) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_is_bare(repo) +*/ +PHP_FUNCTION(git_repository_is_bare) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_is_bare not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_config(repo) +*/ +PHP_FUNCTION(git_repository_config) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_config not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_odb(repo) +*/ +PHP_FUNCTION(git_repository_odb) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_odb not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_refdb(repo) +*/ +PHP_FUNCTION(git_repository_refdb) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_refdb not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_index(repo) +*/ +PHP_FUNCTION(git_repository_index) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_index not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_message(len, repo) +*/ +PHP_FUNCTION(git_repository_message) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_message not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_message_remove(repo) +*/ +PHP_FUNCTION(git_repository_message_remove) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_message_remove not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_merge_cleanup(repo) +*/ +PHP_FUNCTION(git_repository_merge_cleanup) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_merge_cleanup not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_fetchhead_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_repository_fetchhead_foreach) +{ + zval *repo; + php_git2_t *_repo; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_fetchhead_foreach not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &repo, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_mergehead_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_repository_mergehead_foreach) +{ + zval *repo; + php_git2_t *_repo; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_mergehead_foreach not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &repo, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_repository_hashfile(repo, path, type, as_path) +*/ +PHP_FUNCTION(git_repository_hashfile) +{ + zval *repo; + php_git2_t *_repo; + char *path = {0}; + int path_len; + zval *type; + php_git2_t *_type; + char *as_path = {0}; + int as_path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_hashfile not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrs", &repo, &path, &path_len, &type, &as_path, &as_path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_set_head(repo, refname) +*/ +PHP_FUNCTION(git_repository_set_head) +{ + zval *repo; + php_git2_t *_repo; + char *refname = {0}; + int refname_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_head not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &refname, &refname_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_set_head_detached(repo, commitish) +*/ +PHP_FUNCTION(git_repository_set_head_detached) +{ + zval *repo; + php_git2_t *_repo; + char *commitish = {0}; + int commitish_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_head_detached not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &commitish, &commitish_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_detach_head(repo) +*/ +PHP_FUNCTION(git_repository_detach_head) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_detach_head not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_state(repo) +*/ +PHP_FUNCTION(git_repository_state) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_state not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_set_namespace(repo, nmspace) +*/ +PHP_FUNCTION(git_repository_set_namespace) +{ + zval *repo; + php_git2_t *_repo; + char *nmspace = {0}; + int nmspace_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_namespace not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &nmspace, &nmspace_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_repository_is_shallow(repo) +*/ +PHP_FUNCTION(git_repository_is_shallow) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_is_shallow not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} \ No newline at end of file diff --git a/repository.h b/repository.h index 6ca665e0ce..ace9aae604 100644 --- a/repository.h +++ b/repository.h @@ -50,6 +50,137 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_workdir, 0, 0, 1) ZEND_ARG_INFO(0, repository) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_wrap_odb, 0, 0, 1) + ZEND_ARG_INFO(0, odb) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_discover, 0, 0, 4) + ZEND_ARG_INFO(0, path_size) + ZEND_ARG_INFO(0, start_path) + ZEND_ARG_INFO(0, across_fs) + ZEND_ARG_INFO(0, ceiling_dirs) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_open_ext, 0, 0, 3) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, ceiling_dirs) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_free, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_init_ext, 0, 0, 2) + ZEND_ARG_INFO(0, repo_path) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_head, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_head_detached, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_head_unborn, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_is_empty, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_path, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_set_workdir, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, workdir) + ZEND_ARG_INFO(0, update_gitlink) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_is_bare, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_config, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_odb, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_refdb, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_index, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_message, 0, 0, 2) + ZEND_ARG_INFO(0, len) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_message_remove, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_merge_cleanup, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_fetchhead_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_mergehead_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_hashfile, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, as_path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_set_head, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, refname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_set_head_detached, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, commitish) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_detach_head, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_state, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_set_namespace, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, nmspace) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_is_shallow, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + /* {{{ proto resource git_repository_new() */ PHP_FUNCTION(git_repository_new); @@ -74,4 +205,116 @@ PHP_FUNCTION(git_repository_get_namespace); */ PHP_FUNCTION(git_repository_workdir); +/* {{{ proto resource git_repository_wrap_odb(odb) +*/ +PHP_FUNCTION(git_repository_wrap_odb); + +/* {{{ proto resource git_repository_discover(path_size, start_path, across_fs, ceiling_dirs) +*/ +PHP_FUNCTION(git_repository_discover); + +/* {{{ proto resource git_repository_open_ext(path, flags, ceiling_dirs) +*/ +PHP_FUNCTION(git_repository_open_ext); + +/* {{{ proto void git_repository_free(repo) +*/ +PHP_FUNCTION(git_repository_free); + +/* {{{ proto resource git_repository_init_ext(repo_path, opts) +*/ +PHP_FUNCTION(git_repository_init_ext); + +/* {{{ proto resource git_repository_head(repo) +*/ +PHP_FUNCTION(git_repository_head); + +/* {{{ proto long git_repository_head_detached(repo) +*/ +PHP_FUNCTION(git_repository_head_detached); + +/* {{{ proto long git_repository_head_unborn(repo) +*/ +PHP_FUNCTION(git_repository_head_unborn); + +/* {{{ proto long git_repository_is_empty(repo) +*/ +PHP_FUNCTION(git_repository_is_empty); + +/* {{{ proto resource git_repository_path(repo) +*/ +PHP_FUNCTION(git_repository_path); + +/* {{{ proto long git_repository_set_workdir(repo, workdir, update_gitlink) +*/ +PHP_FUNCTION(git_repository_set_workdir); + +/* {{{ proto long git_repository_is_bare(repo) +*/ +PHP_FUNCTION(git_repository_is_bare); + +/* {{{ proto resource git_repository_config(repo) +*/ +PHP_FUNCTION(git_repository_config); + +/* {{{ proto resource git_repository_odb(repo) +*/ +PHP_FUNCTION(git_repository_odb); + +/* {{{ proto resource git_repository_refdb(repo) +*/ +PHP_FUNCTION(git_repository_refdb); + +/* {{{ proto resource git_repository_index(repo) +*/ +PHP_FUNCTION(git_repository_index); + +/* {{{ proto resource git_repository_message(len, repo) +*/ +PHP_FUNCTION(git_repository_message); + +/* {{{ proto long git_repository_message_remove(repo) +*/ +PHP_FUNCTION(git_repository_message_remove); + +/* {{{ proto long git_repository_merge_cleanup(repo) +*/ +PHP_FUNCTION(git_repository_merge_cleanup); + +/* {{{ proto long git_repository_fetchhead_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_repository_fetchhead_foreach); + +/* {{{ proto long git_repository_mergehead_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_repository_mergehead_foreach); + +/* {{{ proto resource git_repository_hashfile(repo, path, type, as_path) +*/ +PHP_FUNCTION(git_repository_hashfile); + +/* {{{ proto long git_repository_set_head(repo, refname) +*/ +PHP_FUNCTION(git_repository_set_head); + +/* {{{ proto long git_repository_set_head_detached(repo, commitish) +*/ +PHP_FUNCTION(git_repository_set_head_detached); + +/* {{{ proto long git_repository_detach_head(repo) +*/ +PHP_FUNCTION(git_repository_detach_head); + +/* {{{ proto long git_repository_state(repo) +*/ +PHP_FUNCTION(git_repository_state); + +/* {{{ proto long git_repository_set_namespace(repo, nmspace) +*/ +PHP_FUNCTION(git_repository_set_namespace); + +/* {{{ proto long git_repository_is_shallow(repo) +*/ +PHP_FUNCTION(git_repository_is_shallow); + #endif \ No newline at end of file From ea6568e81fe540189577d31d9d5205c53fdc28c5 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 14:40:40 +0900 Subject: [PATCH 016/136] [repository] implement several functions --- php_git2.h | 4 + repository.c | 320 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 202 insertions(+), 122 deletions(-) diff --git a/php_git2.h b/php_git2.h index 8a77627cb1..a562d60b5c 100644 --- a/php_git2.h +++ b/php_git2.h @@ -85,6 +85,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_CONFIG, PHP_GIT2_TYPE_OBJECT, PHP_GIT2_TYPE_INDEX, + PHP_GIT2_TYPE_ODB, + PHP_GIT2_TYPE_REFDB, }; typedef struct php_git2_t { @@ -101,6 +103,8 @@ typedef struct php_git2_t { git_config *config; git_object *object; git_index *index; + git_odb *odb; + git_refdb *refdb; } v; int should_free_v; int resource_id; diff --git a/repository.c b/repository.c index 3364337dff..3f1687069c 100644 --- a/repository.c +++ b/repository.c @@ -6,22 +6,22 @@ */ PHP_FUNCTION(git_repository_new) { -// git_repository *repository; -// int error; -// php_git2_t *git2; -// -// error = git_repository_new(&repository); -// if (php_git2_check_error(error, "git_repository_new" TSRMLS_CC)) { -// RETURN_FALSE -// } -// -// PHP_GIT2_MAKE_RESOURCE(git2); -// -// git2->type = PHP_GIT2_TYPE_REPOSITORY; -// git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); -// git2->should_free_v = 0; -// -// ZVAL_RESOURCE(return_value, git2->resource_id); + git_repository *repository; + int error; + php_git2_t *git2; + + error = git_repository_new(&repository); + if (php_git2_check_error(error, "git_repository_new" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(git2); + + git2->type = PHP_GIT2_TYPE_REPOSITORY; + git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); + git2->should_free_v = 0; + + ZVAL_RESOURCE(return_value, git2->resource_id); } /* {{{ proto resource git_repository_init(string $path, long is_bare = 0) @@ -177,7 +177,7 @@ PHP_FUNCTION(git_repository_wrap_odb) ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto resource git_repository_discover(path_size, start_path, across_fs, ceiling_dirs) +/* {{{ proto resource git_repository_discover(start_path, across_fs, ceiling_dirs) */ PHP_FUNCTION(git_repository_discover) { @@ -186,15 +186,21 @@ PHP_FUNCTION(git_repository_discover) long across_fs; char *ceiling_dirs = {0}; int ceiling_dirs_len; + int error = 0; + char buffer[512]; + size_t buffer_len = 512; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_discover not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sls", &start_path, &start_path_len, &across_fs, &ceiling_dirs, &ceiling_dirs_len) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "sls", &path_size, &start_path, &start_path_len, &across_fs, &ceiling_dirs, &ceiling_dirs_len) == FAILURE) { -// return; -// } + error = git_repository_discover(buffer, buffer_len, start_path, across_fs, ceiling_dirs); + if (php_git2_check_error(error, "git_repository_discover" TSRMLS_CC)) { + RETURN_FALSE + } + + RETURN_STRING(buffer, 1); } /* {{{ proto resource git_repository_open_ext(path, flags, ceiling_dirs) @@ -206,15 +212,25 @@ PHP_FUNCTION(git_repository_open_ext) long flags; char *ceiling_dirs = {0}; int ceiling_dirs_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_open_ext not implemented yet"); - return; + int error = 0; + git_repository *repository; + php_git2_t *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &path, &path_len, &flags, &ceiling_dirs, &ceiling_dirs_len) == FAILURE) { return; } + error = git_repository_open_ext(&repository, path, flags, ceiling_dirs); + if (php_git2_check_error(error, "git_repository_open_ext" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto void git_repository_free(repo) @@ -224,15 +240,16 @@ PHP_FUNCTION(git_repository_free) zval *repo; php_git2_t *_repo; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_free not implemented yet"); - return; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_repo->should_free_v) { + git_repository_free(PHP_GIT2_V(_repo, repository)); + _repo->should_free_v = 0; + } + zval_ptr_dtor(&repo); } /* {{{ proto resource git_repository_init_ext(repo_path, opts) @@ -243,11 +260,7 @@ PHP_FUNCTION(git_repository_init_ext) int repo_path_len; zval *opts; php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_init_ext not implemented yet"); - return; - +// TODO // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, // "sr", &repo_path, &repo_path_len, &opts) == FAILURE) { // return; @@ -260,17 +273,25 @@ PHP_FUNCTION(git_repository_init_ext) PHP_FUNCTION(git_repository_head) { zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_head not implemented yet"); - return; + php_git2_t *_repo, *result; + git_reference *reference; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_head(&reference, PHP_GIT2_V(_repo, repository)); + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = reference; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto long git_repository_head_detached(repo) @@ -279,16 +300,15 @@ PHP_FUNCTION(git_repository_head_detached) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_head_detached not implemented yet"); - return; + int result = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_repository_head_detached(PHP_GIT2_V(_repo, repository)); + RETURN_BOOL(result); } /* {{{ proto long git_repository_head_unborn(repo) @@ -297,16 +317,15 @@ PHP_FUNCTION(git_repository_head_unborn) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_head_unborn not implemented yet"); - return; + int unborn = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + unborn = git_repository_head_unborn(PHP_GIT2_V(_repo, repository)); + RETURN_BOOL(unborn); } /* {{{ proto long git_repository_is_empty(repo) @@ -315,16 +334,15 @@ PHP_FUNCTION(git_repository_is_empty) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_is_empty not implemented yet"); - return; + int empty; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + empty = git_repository_is_empty(PHP_GIT2_V(_repo, repository)); + RETURN_BOOL(empty); } /* {{{ proto resource git_repository_path(repo) @@ -333,16 +351,15 @@ PHP_FUNCTION(git_repository_path) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_path not implemented yet"); - return; + const char *path; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + path = git_repository_path(PHP_GIT2_V(_repo, repository)); + RETURN_STRING(path, 1); } /* {{{ proto long git_repository_set_workdir(repo, workdir, update_gitlink) @@ -354,16 +371,18 @@ PHP_FUNCTION(git_repository_set_workdir) char *workdir = {0}; int workdir_len; long update_gitlink; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_workdir not implemented yet"); - return; + int error; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &repo, &workdir, &workdir_len, &update_gitlink) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_set_workdir(PHP_GIT2_V(_repo, repository), workdir, update_gitlink); + if (php_git2_check_error(error, "git_repository_set_workdir" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_repository_is_bare(repo) @@ -372,16 +391,16 @@ PHP_FUNCTION(git_repository_is_bare) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_is_bare not implemented yet"); - return; + int is_bare = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + is_bare = git_repository_is_bare(PHP_GIT2_V(_repo, repository)); + + RETURN_BOOL(is_bare); } /* {{{ proto resource git_repository_config(repo) @@ -389,17 +408,27 @@ PHP_FUNCTION(git_repository_is_bare) PHP_FUNCTION(git_repository_config) { zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_config not implemented yet"); - return; + php_git2_t *_repo, *result; + git_config *config; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_config(&config, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_config" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, config) = config; + result->type = PHP_GIT2_TYPE_CONFIG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_repository_odb(repo) @@ -407,17 +436,26 @@ PHP_FUNCTION(git_repository_config) PHP_FUNCTION(git_repository_odb) { zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_odb not implemented yet"); - return; + php_git2_t *_repo, *result; + git_odb *odb; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_odb(&odb, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_odb" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, odb) = odb; + result->type = PHP_GIT2_TYPE_ODB; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_repository_refdb(repo) @@ -425,17 +463,26 @@ PHP_FUNCTION(git_repository_odb) PHP_FUNCTION(git_repository_refdb) { zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_refdb not implemented yet"); - return; + php_git2_t *_repo, *result; + git_refdb *refdb; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_refdb(&refdb, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_refdb" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, refdb) = refdb; + result->type = PHP_GIT2_TYPE_REFDB; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_repository_index(repo) @@ -443,17 +490,23 @@ PHP_FUNCTION(git_repository_refdb) PHP_FUNCTION(git_repository_index) { zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_index not implemented yet"); - return; + php_git2_t *_repo, *result; + git_index *index; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_index(&index, PHP_GIT2_V(_repo, repository)); + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, index) = index; + result->type = PHP_GIT2_TYPE_INDEX; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_repository_message(len, repo) @@ -462,16 +515,20 @@ PHP_FUNCTION(git_repository_message) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_message not implemented yet"); - return; + char buffer[512]; + size_t buffer_len = 512; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_message(buffer, buffer_len, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_message" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_STRING(buffer, 1); } /* {{{ proto long git_repository_message_remove(repo) @@ -480,16 +537,18 @@ PHP_FUNCTION(git_repository_message_remove) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_message_remove not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_message_remove(PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_message_remove" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_repository_merge_cleanup(repo) @@ -564,16 +623,21 @@ PHP_FUNCTION(git_repository_hashfile) php_git2_t *_type; char *as_path = {0}; int as_path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_hashfile not implemented yet"); - return; + git_oid oid; + int error = 0; + char out[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrs", &repo, &path, &path_len, &type, &as_path, &as_path_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_hashfile(&out, PHP_GIT2_V(_repo, repository), path, type, as_path); + if (php_git2_check_error(error, "git_repository_hashfile" TSRMLS_CC)) { + RETURN_FALSE + } + git_oid_fmt(out, &oid); + } /* {{{ proto long git_repository_set_head(repo, refname) @@ -584,16 +648,18 @@ PHP_FUNCTION(git_repository_set_head) php_git2_t *_repo; char *refname = {0}; int refname_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_head not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &refname, &refname_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_set_head(PHP_GIT2_V(_repo, repository), refname); + if (php_git2_check_error(error, "git_repository_set_head" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_repository_set_head_detached(repo, commitish) @@ -604,16 +670,23 @@ PHP_FUNCTION(git_repository_set_head_detached) php_git2_t *_repo; char *commitish = {0}; int commitish_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_head_detached not implemented yet"); - return; + int error = 0; + git_oid id; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &commitish, &commitish_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&id, commitish, commitish_len) != GIT_OK) { + return; + } + + error = git_repository_set_head_detached(PHP_GIT2_V(_repo, repository), &id); + if (php_git2_check_error(error, "git_repository_set_head_detached" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_repository_detach_head(repo) @@ -622,16 +695,18 @@ PHP_FUNCTION(git_repository_detach_head) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_detach_head not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_detach_head(PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_detach_head" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_repository_state(repo) @@ -640,16 +715,16 @@ PHP_FUNCTION(git_repository_state) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_state not implemented yet"); - return; + int state = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + state = git_repository_state(PHP_GIT2_V(_repo, repository)); + + RETURN_LONG(state); } /* {{{ proto long git_repository_set_namespace(repo, nmspace) @@ -660,16 +735,18 @@ PHP_FUNCTION(git_repository_set_namespace) php_git2_t *_repo; char *nmspace = {0}; int nmspace_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_set_namespace not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &nmspace, &nmspace_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_set_namespace(PHP_GIT2_V(_repo, repository), nmspace); + if (php_git2_check_error(error, "git_repository_set_namespace" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_repository_is_shallow(repo) @@ -678,14 +755,13 @@ PHP_FUNCTION(git_repository_is_shallow) { zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_is_shallow not implemented yet"); - return; + int is_shallow; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + is_shallow = git_repository_is_shallow(PHP_GIT2_V(_repo, repository)); + RETURN_LONG(is_shallow); } \ No newline at end of file From faf4e4a7fd55154135015101e70f0d070e2aea11 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 15:03:48 +0900 Subject: [PATCH 017/136] [object] implement several functions --- object.c | 157 ++++++++++++++++++++++++++++++++++------------------- php_git2.c | 2 + 2 files changed, 102 insertions(+), 57 deletions(-) diff --git a/object.c b/object.c index 0da7c36c06..c3e593fbe9 100644 --- a/object.c +++ b/object.c @@ -7,21 +7,34 @@ PHP_FUNCTION(git_object_lookup) { zval *repo; - php_git2_t *_repo; + php_git2_t *_repo, *result; char *id = {0}; int id_len; zval *type; php_git2_t *_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_lookup not implemented yet"); - return; + int error = 0; + git_object *object; + git_oid oid; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &repo, &id, &id_len, &type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { + return; + } + error = git_object_lookup(&object, PHP_GIT2_V(_repo, repository), &oid, type); + if (php_git2_check_error(error, "git_object_lookup" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, object) = object; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_object_lookup_prefix(repo, id, len, type) @@ -51,21 +64,31 @@ PHP_FUNCTION(git_object_lookup_prefix) PHP_FUNCTION(git_object_lookup_bypath) { zval *treeish; - php_git2_t *_treeish; + php_git2_t *_treeish, *result; char *path = {0}; int path_len; zval *type; php_git2_t *_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_lookup_bypath not implemented yet"); - return; + git_object *object; + int error; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &treeish, &path, &path_len, &type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_treeish, php_git2_t*, &treeish, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + // TODO: cast object + error = git_object_lookup_bypath(&object, PHP_GIT2_V(_treeish, tree), path, type); + if (php_git2_check_error(error, "git_object_lookup_bypath" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, object) = object; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_object_id(obj) @@ -74,16 +97,17 @@ PHP_FUNCTION(git_object_id) { zval *obj; php_git2_t *_obj; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_id not implemented yet"); - return; + const git_oid *id; + char buf[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &obj) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + id = git_object_id(PHP_GIT2_V(_obj, object)); + git_oid_fmt(buf, id); + RETURN_STRING(buf, 1); } /* {{{ proto resource git_object_type(obj) @@ -92,16 +116,15 @@ PHP_FUNCTION(git_object_type) { zval *obj; php_git2_t *_obj; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_type not implemented yet"); - return; + const git_otype *type; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &obj) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + type = git_object_type(PHP_GIT2_V(_obj, object)); + RETURN_LONG(type); } /* {{{ proto resource git_object_owner(obj) @@ -109,17 +132,23 @@ PHP_FUNCTION(git_object_type) PHP_FUNCTION(git_object_owner) { zval *obj; - php_git2_t *_obj; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_owner not implemented yet"); - return; + php_git2_t *_obj, *result; + git_repository *repository; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &obj) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + // TODO: consider cast + repository = git_object_owner(PHP_GIT2_V(_obj, object)); + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto void git_object_free(object) @@ -129,15 +158,16 @@ PHP_FUNCTION(git_object_free) zval *object; php_git2_t *_object; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_free not implemented yet"); - return; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &object) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_object->should_free_v) { + git_object_free(PHP_GIT2_V(_object, object)); + _object->should_free_v = 0; + } + zval_ptr_dtor(&object); } /* {{{ proto resource git_object_type2string(type) @@ -146,16 +176,16 @@ PHP_FUNCTION(git_object_type2string) { zval *type; php_git2_t *_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_type2string not implemented yet"); - return; + const char *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + // TODO: consider cast + result = git_object_type2string(PHP_GIT2_V(_type, object)); + RETURN_STRING(result, 1); } /* {{{ proto resource git_object_string2type(str) @@ -164,15 +194,14 @@ PHP_FUNCTION(git_object_string2type) { char *str = {0}; int str_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_string2type not implemented yet"); - return; + git_otype type; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } + type = git_object_string2type(str); + RETURN_LONG(type); } /* {{{ proto long git_object_typeisloose(type) @@ -181,34 +210,33 @@ PHP_FUNCTION(git_object_typeisloose) { zval *type; php_git2_t *_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_typeisloose not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_object_typeisloose(PHP_GIT2_V(_type, object)); + if (php_git2_check_error(error, "git_object_typeisloose" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto resource git_object__size(type) */ PHP_FUNCTION(git_object__size) { - zval *type; - php_git2_t *_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object__size not implemented yet"); - return; + long type; + size_t size; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &type) == FAILURE) { + "l", &type) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + size = git_object__size(type); + RETURN_LONG(size); } /* {{{ proto resource git_object_peel(object, target_type) @@ -216,19 +244,28 @@ PHP_FUNCTION(git_object__size) PHP_FUNCTION(git_object_peel) { zval *object; - php_git2_t *_object; + php_git2_t *_object, *result; zval *target_type; php_git2_t *_target_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_peel not implemented yet"); - return; + int error = 0; + git_object *out; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &object, &target_type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_object_peel(&out, PHP_GIT2_V(_object, object), target_type); + if (php_git2_check_error(error, "git_object_peel" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, object) = object; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_object_dup(source) @@ -236,16 +273,22 @@ PHP_FUNCTION(git_object_peel) PHP_FUNCTION(git_object_dup) { zval *source; - php_git2_t *_source; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_dup not implemented yet"); - return; + php_git2_t *_source, *result; + git_object *dest; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &source) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_object_dup(&dest, PHP_GIT2_V(_source, object)); + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, object) = dest; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } diff --git a/php_git2.c b/php_git2.c index ff09f13b72..d85d1e642b 100644 --- a/php_git2.c +++ b/php_git2.c @@ -66,6 +66,8 @@ void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) git_reference_free(PHP_GIT2_V(resource, reference)); case PHP_GIT2_TYPE_CONFIG: git_config_free(PHP_GIT2_V(resource, config)); + case PHP_GIT2_TYPE_OBJECT: + git_object_free(PHP_GIT2_V(resource, object)); default: break; } From 7e31ddb0d9b972996dd3b4187967c4dbaa7cc394 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 16:16:56 +0900 Subject: [PATCH 018/136] [index] implment several functions --- commit.c | 11 -- helper.c | 38 ++++++ helper.h | 6 + index.c | 398 +++++++++++++++++++++++++++++++++++++------------------ 4 files changed, 310 insertions(+), 143 deletions(-) diff --git a/commit.c b/commit.c index 530aa5b377..1116a14ff4 100644 --- a/commit.c +++ b/commit.c @@ -469,17 +469,6 @@ PHP_FUNCTION(git_commit_nth_gen_ancestor) } -static zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC) -{ - zval *result = NULL, **element; - - if (zend_hash_find(Z_ARRVAL_P(array), name, name_len, (void**)&element) == SUCCESS) { - result = *element; - } - - return result; -} - static void php_git2_array_to_signature(git_signature *signature, zval *author TSRMLS_DC) { zval *name = NULL, *email = NULL, *time = NULL; diff --git a/helper.c b/helper.c index b91f0313b6..ec53e07066 100644 --- a/helper.c +++ b/helper.c @@ -16,3 +16,41 @@ int php_git2_check_error(int error_code, const char *action TSRMLS_DC) result = 1; return result; } + + +zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC) +{ + zval *result = NULL, **element; + + if (zend_hash_find(Z_ARRVAL_P(array), name, name_len, (void**)&element) == SUCCESS) { + result = *element; + } + + return result; +} + +long php_git2_read_arrval_long(zval *array, char *name, size_t name_len TSRMLS_DC) +{ + zval *tmp; + long result = 0; + + tmp = php_git2_read_arrval(array, name, name_len TSRMLS_CC); + if (tmp) { + result = Z_LVAL_P(tmp); + } + + return result; +} + +const char* php_git2_read_arrval_string(zval *array, char *name, size_t name_len TSRMLS_DC) +{ + zval *tmp; + const char *result = NULL; + + tmp = php_git2_read_arrval(array, name, name_len TSRMLS_CC); + if (tmp) { + result = Z_STRVAL_P(tmp); + } + + return result; +} \ No newline at end of file diff --git a/helper.h b/helper.h index dd6765b7b0..6132ba02ea 100644 --- a/helper.h +++ b/helper.h @@ -30,4 +30,10 @@ int php_git2_check_error(int error_code, const char *action TSRMLS_DC); +zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC); + +long php_git2_read_arrval_long(zval *array, char *name, size_t name_len TSRMLS_DC); + +const char* php_git2_read_arrval_string(zval *array, char *name, size_t name_len TSRMLS_DC); + #endif \ No newline at end of file diff --git a/index.c b/index.c index c914bd47c6..d6cb9f6c7e 100644 --- a/index.c +++ b/index.c @@ -1,30 +1,120 @@ #include "php_git2.h" #include "php_git2_priv.h" #include "index.h" + +static int php_git2_array_to_index_entry(git_index_entry *entry, zval *array TSRMLS_DC) +{ + zval *ctime, *mtime, *oid; + memset(entry, '\0', sizeof(git_index_entry)); + + ctime = php_git2_read_arrval(array, ZEND_STRS("ctime") TSRMLS_CC); + mtime = php_git2_read_arrval(array, ZEND_STRS("mtime") TSRMLS_CC); + + oid = php_git2_read_arrval(array, ZEND_STRS("oid") TSRMLS_CC); + if (git_oid_fromstrn(&entry->oid, Z_STRVAL_P(oid), Z_STRLEN_P(oid)) != GIT_OK) { + return 0; + } + + entry->ctime.seconds = php_git2_read_arrval_long(ctime, ZEND_STRS("seconds") TSRMLS_CC); + entry->ctime.nanoseconds = php_git2_read_arrval_long(ctime, ZEND_STRS("nanoseconds") TSRMLS_CC); + entry->mtime.seconds = php_git2_read_arrval_long(mtime, ZEND_STRS("seconds") TSRMLS_CC); + entry->mtime.nanoseconds = php_git2_read_arrval_long(mtime, ZEND_STRS("nanoseconds") TSRMLS_CC); + entry->dev = php_git2_read_arrval_long(array, ZEND_STRS("dev") TSRMLS_CC); + entry->ino = php_git2_read_arrval_long(array, ZEND_STRS("ino") TSRMLS_CC); + entry->mode = php_git2_read_arrval_long(array, ZEND_STRS("mode") TSRMLS_CC); + entry->uid = php_git2_read_arrval_long(array, ZEND_STRS("uid") TSRMLS_CC); + entry->gid = php_git2_read_arrval_long(array, ZEND_STRS("gid") TSRMLS_CC); + entry->file_size = php_git2_read_arrval_long(array, ZEND_STRS("file_size") TSRMLS_CC); + entry->flags = php_git2_read_arrval_long(array, ZEND_STRS("flags") TSRMLS_CC); + entry->flags_extended = php_git2_read_arrval_long(array, ZEND_STRS("flags_extended") TSRMLS_CC); + entry->path = php_git2_read_arrval_string(array, ZEND_STRS("path") TSRMLS_CC); + + return 1; +} + +static void php_git2_index_entry_to_array(const git_index_entry *entry, zval **result TSRMLS_DC) +{ + zval *tmp, *ctime, *mtime; + char buf[41] = {0}; + + MAKE_STD_ZVAL(tmp); + MAKE_STD_ZVAL(ctime); + MAKE_STD_ZVAL(mtime); + array_init(tmp); + array_init(ctime); + array_init(mtime); + + git_oid_fmt(buf, &entry->oid); + + add_assoc_long_ex(ctime, ZEND_STRS("seconds"), entry->ctime.seconds); + add_assoc_long_ex(ctime, ZEND_STRS("nanoseconds"), entry->ctime.nanoseconds); + add_assoc_long_ex(mtime, ZEND_STRS("seconds"), entry->mtime.seconds); + add_assoc_long_ex(mtime, ZEND_STRS("nanoseconds"), entry->mtime.nanoseconds); + + add_assoc_zval_ex(tmp, ZEND_STRS("ctime"), ctime); + add_assoc_zval_ex(tmp, ZEND_STRS("mtime"), mtime); + + add_assoc_long_ex(tmp, ZEND_STRS("dev"), entry->dev); + add_assoc_long_ex(tmp, ZEND_STRS("ino"), entry->ino); + add_assoc_long_ex(tmp, ZEND_STRS("mode"), entry->mode); + add_assoc_long_ex(tmp, ZEND_STRS("uid"), entry->uid); + add_assoc_long_ex(tmp, ZEND_STRS("gid"), entry->gid); + add_assoc_long_ex(tmp, ZEND_STRS("file_size"), entry->file_size); + add_assoc_string_ex(tmp, ZEND_STRS("oid"), buf, 1); + add_assoc_long_ex(tmp, ZEND_STRS("flags"), entry->flags); + add_assoc_long_ex(tmp, ZEND_STRS("flags_extended"), entry->flags_extended); + add_assoc_string_ex(tmp, ZEND_STRS("path"), entry->path, 1); + + *result = tmp; +} + /* {{{ proto resource git_index_open(index_path) */ PHP_FUNCTION(git_index_open) { char *index_path = {0}; int index_path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_open not implemented yet"); - return; + git_index *index; + php_git2_t *result; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &index_path, &index_path_len) == FAILURE) { return; } + error = git_index_open(&index, index_path); + if (php_git2_check_error(error, "git_index_open" TSRMLS_CC)) { + RETURN_FALSE + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, index) = index; + result->type = PHP_GIT2_TYPE_INDEX; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_index_new() */ PHP_FUNCTION(git_index_new) { - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_new not implemented yet"); - return; + git_index *index; + php_git2_t *result; + int error = 0; + + error = git_index_new(&index); + if (php_git2_check_error(error, "git_index_new" TSRMLS_CC)) { + RETURN_FALSE + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, index) = index; + result->type = PHP_GIT2_TYPE_INDEX; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto void git_index_free(index) @@ -34,15 +124,16 @@ PHP_FUNCTION(git_index_free) zval *index; php_git2_t *_index; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_free not implemented yet"); - return; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_index->should_free_v) { + git_index_free(PHP_GIT2_V(_index, index)); + _index->should_free_v = 0; + } + zval_ptr_dtor(&index); } /* {{{ proto resource git_index_owner(index) @@ -50,17 +141,22 @@ PHP_FUNCTION(git_index_free) PHP_FUNCTION(git_index_owner) { zval *index; - php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_owner not implemented yet"); - return; + php_git2_t *_index, *result; + git_repository *repository; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + repository = git_index_owner(PHP_GIT2_V(_index, index)); + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, repository) = repository; + result->type = PHP_GIT2_TYPE_REPOSITORY; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + + ZVAL_RESOURCE(return_value, result->resource_id); } /* {{{ proto resource git_index_caps(index) @@ -69,16 +165,15 @@ PHP_FUNCTION(git_index_caps) { zval *index; php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_caps not implemented yet"); - return; + unsigned int caps; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + caps = git_index_caps(PHP_GIT2_V(_index, index)); + RETURN_LONG(caps); } /* {{{ proto long git_index_set_caps(index, caps) @@ -88,16 +183,15 @@ PHP_FUNCTION(git_index_set_caps) zval *index; php_git2_t *_index; long caps; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_set_caps not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &index, &caps) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_set_caps(PHP_GIT2_V(_index, index), caps); + RETURN_LONG(error); } /* {{{ proto long git_index_read(index, force) @@ -107,25 +201,38 @@ PHP_FUNCTION(git_index_read) zval *index; php_git2_t *_index; long force; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_read not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &index, &force) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_read(PHP_GIT2_V(_index, index), force); + if (php_git2_check_error(error, "git_index_read" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto resource git_index_write() */ PHP_FUNCTION(git_index_write) { - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_write not implemented yet"); - return; + zval *index; + php_git2_t *_index; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &index) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_write(PHP_GIT2_V(_index, index)); + if (php_git2_check_error(error, "git_index_write" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto resource git_index_path(index) @@ -134,16 +241,15 @@ PHP_FUNCTION(git_index_path) { zval *index; php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_path not implemented yet"); - return; + const char *path; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + path = git_index_path(PHP_GIT2_V(_index, index)); + RETURN_STRING(path, 1); } /* {{{ proto long git_index_read_tree(index, tree) @@ -154,16 +260,19 @@ PHP_FUNCTION(git_index_read_tree) php_git2_t *_index; zval *tree; php_git2_t *_tree; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_read_tree not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &index, &tree) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_tree, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_read_tree(PHP_GIT2_V(_index, index), PHP_GIT2_V(_tree, tree)); + if (php_git2_check_error(error, "git_index_read_tree" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto resource git_index_write_tree(index) @@ -172,16 +281,21 @@ PHP_FUNCTION(git_index_write_tree) { zval *index; php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_write_tree not implemented yet"); - return; + int error = 0; + git_oid id; + char out[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_write_tree(&id, PHP_GIT2_V(_index, index)); + if (php_git2_check_error(error, "git_index_write_tree" TSRMLS_CC)) { + RETURN_FALSE + } + git_oid_fmt(out, &id); + RETURN_STRING(out, 1); } /* {{{ proto resource git_index_write_tree_to(index, repo) @@ -192,16 +306,21 @@ PHP_FUNCTION(git_index_write_tree_to) php_git2_t *_index; zval *repo; php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_write_tree_to not implemented yet"); - return; + git_oid id; + char out[41]= {0}; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &index, &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_write_tree_to(&id, PHP_GIT2_V(_index, index), PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_index_write_tree_to" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto resource git_index_entrycount(index) @@ -210,16 +329,15 @@ PHP_FUNCTION(git_index_entrycount) { zval *index; php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_entrycount not implemented yet"); - return; + size_t count; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + count = git_index_entrycount(PHP_GIT2_V(_index, index)); + RETURN_LONG(count); } /* {{{ proto void git_index_clear(index) @@ -229,15 +347,12 @@ PHP_FUNCTION(git_index_clear) zval *index; php_git2_t *_index; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_clear not implemented yet"); - return; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_index_clear(PHP_GIT2_V(_index, index)); } /* {{{ proto resource git_index_get_byindex(index, n) @@ -246,16 +361,21 @@ PHP_FUNCTION(git_index_get_byindex) { zval *index; php_git2_t *_index; + long n; + const git_index_entry *entry; + zval *result; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_get_byindex not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &index, &n) == FAILURE) { -// return; -// } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &index, &n) == FAILURE) { + return; + } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + entry = git_index_get_byindex(PHP_GIT2_V(_index, index), n); + if (entry == NULL) { + RETURN_FALSE; + } + php_git2_index_entry_to_array(entry, &result TSRMLS_CC); + RETURN_ZVAL(result, 0, 1); } /* {{{ proto resource git_index_get_bypath(index, path, stage) @@ -266,17 +386,21 @@ PHP_FUNCTION(git_index_get_bypath) php_git2_t *_index; char *path = {0}; int path_len; - long stage; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_get_bypath not implemented yet"); - return; + long stage = 0; + const git_index_entry *entry; + zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsl", &index, &path, &path_len, &stage) == FAILURE) { + "rs|l", &index, &path, &path_len, &stage) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + entry = git_index_get_bypath(PHP_GIT2_V(_index, index), path, stage); + if (entry == NULL) { + RETURN_FALSE; + } + php_git2_index_entry_to_array(entry, &result TSRMLS_CC); + RETURN_ZVAL(result, 0, 1); } /* {{{ proto long git_index_remove(index, path, stage) @@ -287,17 +411,19 @@ PHP_FUNCTION(git_index_remove) php_git2_t *_index; char *path = {0}; int path_len; - long stage; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove not implemented yet"); - return; + long stage = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &index, &path, &path_len, &stage) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_remove(PHP_GIT2_V(_index, index), path, stage); + if (php_git2_check_error(error, "git_index_remove" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_TRUE; } /* {{{ proto long git_index_remove_directory(index, dir, stage) @@ -308,17 +434,19 @@ PHP_FUNCTION(git_index_remove_directory) php_git2_t *_index; char *dir = {0}; int dir_len; - long stage; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove_directory not implemented yet"); - return; + long stage = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &index, &dir, &dir_len, &stage) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_remove_directory(PHP_GIT2_V(_index, index), dir, stage); + if (php_git2_check_error(error, "git_index_remove_directory" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_TRUE; } /* {{{ proto long git_index_add(index, source_entry) @@ -328,35 +456,42 @@ PHP_FUNCTION(git_index_add) zval *index; php_git2_t *_index; zval *source_entry; - php_git2_t *_source_entry; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_add not implemented yet"); - return; + int error = 0; + git_index_entry entry; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &index, &source_entry) == FAILURE) { + "ra", &index, &source_entry) == FAILURE) { + return; + } + if (!php_git2_array_to_index_entry(&entry, source_entry TSRMLS_CC)) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_add(PHP_GIT2_V(_index, index), &entry); + if (php_git2_check_error(error, "git_index_add" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_index_entry_stage(entry) */ PHP_FUNCTION(git_index_entry_stage) { - zval *entry; - php_git2_t *_entry; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_entry_stage not implemented yet"); - return; + zval *source; + git_index_entry entry; + int result = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &entry) == FAILURE) { + "a", &source) == FAILURE) { + return; + } + if (!php_git2_array_to_index_entry(&entry, source TSRMLS_CC)) { return; } - ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_index_entry_stage(&entry); + RETURN_LONG(result); } /* {{{ proto long git_index_add_bypath(index, path) @@ -367,16 +502,18 @@ PHP_FUNCTION(git_index_add_bypath) php_git2_t *_index; char *path = {0}; int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_add_bypath not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &index, &path, &path_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_add_bypath(PHP_GIT2_V(_index, index), path); + if (php_git2_check_error(error, "git_index_add_bypath" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_index_remove_bypath(index, path) @@ -387,16 +524,18 @@ PHP_FUNCTION(git_index_remove_bypath) php_git2_t *_index; char *path = {0}; int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove_bypath not implemented yet"); - return; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &index, &path, &path_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_remove_bypath(PHP_GIT2_V(_index, index), path); + if (php_git2_check_error(error, "git_index_remove_bypath" TSRMLS_CC)) { + RETURN_FALSE + } + RETURN_TRUE; } /* {{{ proto long git_index_add_all(index, pathspec, flags, callback, payload) @@ -477,40 +616,36 @@ PHP_FUNCTION(git_index_find) php_git2_t *_index; char *path = {0}; int path_len; + long at_pos; + int result = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_find not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rs", &at_pos, &index, &path, &path_len) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_at_pos, php_git2_t*, &at_pos, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lrs", &at_pos, &index, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_index_find(at_pos, PHP_GIT2_V(_index, index), path); + RETURN_LONG(result); } /* {{{ proto long git_index_conflict_add(index, ancestor_entry, our_entry, their_entry) */ PHP_FUNCTION(git_index_conflict_add) { - zval *index; - php_git2_t *_index; - zval *ancestor_entry; - php_git2_t *_ancestor_entry; - zval *our_entry; - php_git2_t *_our_entry; - zval *their_entry; - php_git2_t *_their_entry; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_add not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrrr", &index, &ancestor_entry, &our_entry, &their_entry) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// zval *index; +// php_git2_t *_index; +// zval *ancestor_entry; +// php_git2_t *_ancestor_entry; +// zval *our_entry; +// php_git2_t *_our_entry; +// zval *their_entry; +// php_git2_t *_their_entry; +// +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rrrr", &index, &ancestor_entry, &our_entry, &their_entry) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } /* {{{ proto resource git_index_conflict_get(our_out, their_out, index, path) @@ -581,16 +716,15 @@ PHP_FUNCTION(git_index_has_conflicts) { zval *index; php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_has_conflicts not implemented yet"); - return; + int conflict = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + conflict = git_index_has_conflicts(PHP_GIT2_V(_index, index)); + RETURN_LONG(conflict); } /* {{{ proto resource git_index_conflict_iterator_new(index) From 14a07f0482aa4cc90953dd5684c38118f2974878 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 17:03:25 +0900 Subject: [PATCH 019/136] add several stubs --- branch.c | 260 +++++++++++++++++ branch.h | 147 ++++++++++ config.m4 | 2 +- cred.c | 121 ++++++++ cred.h | 87 ++++++ gen.php | 26 +- php_git2.c | 85 ++++++ remote.c | 803 ++++++++++++++++++++++++++++++++++++++++++++++++++++ remote.h | 392 +++++++++++++++++++++++++ revparse.c | 68 +++++ revparse.h | 58 ++++ status.c | 165 +++++++++++ status.h | 104 +++++++ tag.c | 404 ++++++++++++++++++++++++++ tag.h | 212 ++++++++++++++ transport.c | 171 +++++++++++ transport.h | 109 +++++++ 17 files changed, 3211 insertions(+), 3 deletions(-) create mode 100644 branch.c create mode 100644 branch.h create mode 100644 cred.c create mode 100644 cred.h create mode 100644 remote.c create mode 100644 remote.h create mode 100644 revparse.c create mode 100644 revparse.h create mode 100644 status.c create mode 100644 status.h create mode 100644 tag.c create mode 100644 tag.h create mode 100644 transport.c create mode 100644 transport.h diff --git a/branch.c b/branch.c new file mode 100644 index 0000000000..78bca958ba --- /dev/null +++ b/branch.c @@ -0,0 +1,260 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "branch.h" + +/* {{{ proto resource git_branch_create(repo, branch_name, target, force) +*/ +PHP_FUNCTION(git_branch_create) +{ + zval *repo; + php_git2_t *_repo; + char *branch_name = {0}; + int branch_name_len; + zval *target; + php_git2_t *_target; + long force; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_create not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrl", &repo, &branch_name, &branch_name_len, &target, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_branch_delete(branch) +*/ +PHP_FUNCTION(git_branch_delete) +{ + zval *branch; + php_git2_t *_branch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_delete not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &branch) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_iterator_new(repo, list_flags) +*/ +PHP_FUNCTION(git_branch_iterator_new) +{ + zval *repo; + php_git2_t *_repo; + zval *list_flags; + php_git2_t *_list_flags; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_iterator_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &list_flags) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_next(out_type, iter) +*/ +PHP_FUNCTION(git_branch_next) +{ + zval *out_type; + php_git2_t *_out_type; + zval *iter; + php_git2_t *_iter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_next not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &out_type, &iter) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_out_type, php_git2_t*, &out_type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_branch_iterator_free(iter) +*/ +PHP_FUNCTION(git_branch_iterator_free) +{ + zval *iter; + php_git2_t *_iter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_iterator_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &iter) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_move(branch, new_branch_name, force) +*/ +PHP_FUNCTION(git_branch_move) +{ + zval *branch; + php_git2_t *_branch; + char *new_branch_name = {0}; + int new_branch_name_len; + long force; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_move not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &branch, &new_branch_name, &new_branch_name_len, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_lookup(repo, branch_name, branch_type) +*/ +PHP_FUNCTION(git_branch_lookup) +{ + zval *repo; + php_git2_t *_repo; + char *branch_name = {0}; + int branch_name_len; + zval *branch_type; + php_git2_t *_branch_type; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_lookup not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsr", &repo, &branch_name, &branch_name_len, &branch_type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_name(ref) +*/ +PHP_FUNCTION(git_branch_name) +{ + zval *ref; + php_git2_t *_ref; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_name not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_upstream(branch) +*/ +PHP_FUNCTION(git_branch_upstream) +{ + zval *branch; + php_git2_t *_branch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_upstream not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &branch) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_branch_set_upstream(branch, upstream_name) +*/ +PHP_FUNCTION(git_branch_set_upstream) +{ + zval *branch; + php_git2_t *_branch; + char *upstream_name = {0}; + int upstream_name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_set_upstream not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &branch, &upstream_name, &upstream_name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_upstream_name(buffer_size, repo, canonical_branch_name) +*/ +PHP_FUNCTION(git_branch_upstream_name) +{ + zval *repo; + php_git2_t *_repo; + char *canonical_branch_name = {0}; + int canonical_branch_name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_upstream_name not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rs", &buffer_size, &repo, &canonical_branch_name, &canonical_branch_name_len) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_buffer_size, php_git2_t*, &buffer_size, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_branch_is_head(branch) +*/ +PHP_FUNCTION(git_branch_is_head) +{ + zval *branch; + php_git2_t *_branch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_is_head not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &branch) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_branch_remote_name(buffer_size, repo, canonical_branch_name) +*/ +PHP_FUNCTION(git_branch_remote_name) +{ + zval *repo; + php_git2_t *_repo; + char *canonical_branch_name = {0}; + int canonical_branch_name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_remote_name not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rs", &buffer_size, &repo, &canonical_branch_name, &canonical_branch_name_len) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_buffer_size, php_git2_t*, &buffer_size, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/branch.h b/branch.h new file mode 100644 index 0000000000..5e5ae0f83f --- /dev/null +++ b/branch.h @@ -0,0 +1,147 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_BRANCH_H +#define PHP_GIT2_BRANCH_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_create, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, branch_name) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_delete, 0, 0, 1) + ZEND_ARG_INFO(0, branch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_iterator_new, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, list_flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_next, 0, 0, 2) + ZEND_ARG_INFO(0, out_type) + ZEND_ARG_INFO(0, iter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_iterator_free, 0, 0, 1) + ZEND_ARG_INFO(0, iter) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_move, 0, 0, 3) + ZEND_ARG_INFO(0, branch) + ZEND_ARG_INFO(0, new_branch_name) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_lookup, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, branch_name) + ZEND_ARG_INFO(0, branch_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_name, 0, 0, 1) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_upstream, 0, 0, 1) + ZEND_ARG_INFO(0, branch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_set_upstream, 0, 0, 2) + ZEND_ARG_INFO(0, branch) + ZEND_ARG_INFO(0, upstream_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_upstream_name, 0, 0, 3) + ZEND_ARG_INFO(0, buffer_size) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, canonical_branch_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_is_head, 0, 0, 1) + ZEND_ARG_INFO(0, branch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_branch_remote_name, 0, 0, 3) + ZEND_ARG_INFO(0, buffer_size) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, canonical_branch_name) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_branch_create(repo, branch_name, target, force) +*/ +PHP_FUNCTION(git_branch_create); + +/* {{{ proto long git_branch_delete(branch) +*/ +PHP_FUNCTION(git_branch_delete); + +/* {{{ proto resource git_branch_iterator_new(repo, list_flags) +*/ +PHP_FUNCTION(git_branch_iterator_new); + +/* {{{ proto resource git_branch_next(out_type, iter) +*/ +PHP_FUNCTION(git_branch_next); + +/* {{{ proto void git_branch_iterator_free(iter) +*/ +PHP_FUNCTION(git_branch_iterator_free); + +/* {{{ proto resource git_branch_move(branch, new_branch_name, force) +*/ +PHP_FUNCTION(git_branch_move); + +/* {{{ proto resource git_branch_lookup(repo, branch_name, branch_type) +*/ +PHP_FUNCTION(git_branch_lookup); + +/* {{{ proto resource git_branch_name(ref) +*/ +PHP_FUNCTION(git_branch_name); + +/* {{{ proto resource git_branch_upstream(branch) +*/ +PHP_FUNCTION(git_branch_upstream); + +/* {{{ proto long git_branch_set_upstream(branch, upstream_name) +*/ +PHP_FUNCTION(git_branch_set_upstream); + +/* {{{ proto resource git_branch_upstream_name(buffer_size, repo, canonical_branch_name) +*/ +PHP_FUNCTION(git_branch_upstream_name); + +/* {{{ proto long git_branch_is_head(branch) +*/ +PHP_FUNCTION(git_branch_is_head); + +/* {{{ proto resource git_branch_remote_name(buffer_size, repo, canonical_branch_name) +*/ +PHP_FUNCTION(git_branch_remote_name); + +#endif \ No newline at end of file diff --git a/config.m4 b/config.m4 index 40319b56d4..e81c8f05a8 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/cred.c b/cred.c new file mode 100644 index 0000000000..be9f0260ba --- /dev/null +++ b/cred.c @@ -0,0 +1,121 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "cred.h" + +/* {{{ proto long git_cred_has_username(cred) +*/ +PHP_FUNCTION(git_cred_has_username) +{ + zval *cred; + php_git2_t *_cred; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_has_username not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &cred) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_cred, php_git2_t*, &cred, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_cred_userpass_plaintext_new(username, password) +*/ +PHP_FUNCTION(git_cred_userpass_plaintext_new) +{ + char *username = {0}; + int username_len; + char *password = {0}; + int password_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_userpass_plaintext_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ss", &username, &username_len, &password, &password_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_cred_ssh_key_new(username, publickey, privatekey, passphrase) +*/ +PHP_FUNCTION(git_cred_ssh_key_new) +{ + char *username = {0}; + int username_len; + char *publickey = {0}; + int publickey_len; + char *privatekey = {0}; + int privatekey_len; + char *passphrase = {0}; + int passphrase_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_ssh_key_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ssss", &username, &username_len, &publickey, &publickey_len, &privatekey, &privatekey_len, &passphrase, &passphrase_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_cred_ssh_custom_new(username, publickey, publickey_len, sign_fn, sign_data) +*/ +PHP_FUNCTION(git_cred_ssh_custom_new) +{ + char *username = {0}; + int username_len; + char *publickey = {0}; + int publickey_len; + zval *sign_fn; + php_git2_t *_sign_fn; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_ssh_custom_new not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "ssr", &username, &username_len, &publickey, &publickey_len, &publickey_len, &sign_fn, &sign_data) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_username, php_git2_t*, &username, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_cred_default_new() +*/ +PHP_FUNCTION(git_cred_default_new) +{ + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_default_new not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "", ) == FAILURE) { +// return; +// } +} + +/* {{{ proto resource git_cred_userpass(url, user_from_url, allowed_types, payload) +*/ +PHP_FUNCTION(git_cred_userpass) +{ + char *url = {0}; + int url_len; + char *user_from_url = {0}; + int user_from_url_len; + long allowed_types; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_userpass not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "ssl", &url, &url_len, &user_from_url, &user_from_url_len, &allowed_types, &payload) == FAILURE) { +// return; +// } +} + diff --git a/cred.h b/cred.h new file mode 100644 index 0000000000..657ffc3d05 --- /dev/null +++ b/cred.h @@ -0,0 +1,87 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_CRED_H +#define PHP_GIT2_CRED_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_cred_has_username, 0, 0, 1) + ZEND_ARG_INFO(0, cred) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_cred_userpass_plaintext_new, 0, 0, 2) + ZEND_ARG_INFO(0, username) + ZEND_ARG_INFO(0, password) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_cred_ssh_key_new, 0, 0, 4) + ZEND_ARG_INFO(0, username) + ZEND_ARG_INFO(0, publickey) + ZEND_ARG_INFO(0, privatekey) + ZEND_ARG_INFO(0, passphrase) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_cred_ssh_custom_new, 0, 0, 5) + ZEND_ARG_INFO(0, username) + ZEND_ARG_INFO(0, publickey) + ZEND_ARG_INFO(0, publickey_len) + ZEND_ARG_INFO(0, sign_fn) + ZEND_ARG_INFO(0, sign_data) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_cred_default_new, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_cred_userpass, 0, 0, 4) + ZEND_ARG_INFO(0, url) + ZEND_ARG_INFO(0, user_from_url) + ZEND_ARG_INFO(0, allowed_types) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_cred_has_username(cred) +*/ +PHP_FUNCTION(git_cred_has_username); + +/* {{{ proto resource git_cred_userpass_plaintext_new(username, password) +*/ +PHP_FUNCTION(git_cred_userpass_plaintext_new); + +/* {{{ proto resource git_cred_ssh_key_new(username, publickey, privatekey, passphrase) +*/ +PHP_FUNCTION(git_cred_ssh_key_new); + +/* {{{ proto resource git_cred_ssh_custom_new(username, publickey, publickey_len, sign_fn, sign_data) +*/ +PHP_FUNCTION(git_cred_ssh_custom_new); + +/* {{{ proto resource git_cred_default_new() +*/ +PHP_FUNCTION(git_cred_default_new); + +/* {{{ proto resource git_cred_userpass(url, user_from_url, allowed_types, payload) +*/ +PHP_FUNCTION(git_cred_userpass); + +#endif \ No newline at end of file diff --git a/gen.php b/gen.php index c75f6504aa..78824e1149 100644 --- a/gen.php +++ b/gen.php @@ -1,5 +1,18 @@ generate header +// 1 => generate source +// +// filter: +// - prefix: don't show matched keywords +// e.g ) -cred +// will ignore codes which have `cred` keyword +// default: show matched keywords only +// e.g ) cred +// will show codes which have `cred` keyword +// // php gen.php libgit2/include/git2/.h (0|1) [filter] > target.h or target.c $data = file_get_contents($_SERVER['argv'][1]); @@ -23,8 +36,17 @@ $d--; } - if (isset($_SERVER['argv'][3]) && preg_match("/{$_SERVER['argv'][3]}/", $match[2][$i])) { - continue; + + if (isset($_SERVER['argv'][3])) { + if ($_SERVER['argv'][3][0] == "-") { + $_SERVER['argv'][3] = substr($_SERVER['argv'][3][0], 1); + $flag = true; + } else { + $flag = false; + } + if (preg_match("/{$_SERVER['argv'][3]}/", $match[2][$i]) == $flag) { + continue; + } } $match[3][$i] = trim(preg_replace("/\r?\n/", "", $match[3][$i])); diff --git a/php_git2.c b/php_git2.c index d85d1e642b..265b289405 100644 --- a/php_git2.c +++ b/php_git2.c @@ -36,6 +36,13 @@ #include "g_config.h" #include "object.h" #include "index.h" +#include "revparse.h" +#include "branch.h" +#include "tag.h" +#include "status.h" +#include "cred.h" +#include "remote.h" +#include "transport.h" int git2_resource_handle; @@ -340,6 +347,84 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_config_parse_int64, arginfo_git_config_parse_int64) PHP_FE(git_config_backend_foreach_match, arginfo_git_config_backend_foreach_match) + /* revparse */ + PHP_FE(git_revparse_single, arginfo_git_revparse_single) + PHP_FE(git_revparse_ext, arginfo_git_revparse_ext) + PHP_FE(git_revparse, arginfo_git_revparse) + + /* remote */ + PHP_FE(git_remote_create, arginfo_git_remote_create) + PHP_FE(git_remote_create_with_fetchspec, arginfo_git_remote_create_with_fetchspec) + PHP_FE(git_remote_create_inmemory, arginfo_git_remote_create_inmemory) + PHP_FE(git_remote_load, arginfo_git_remote_load) + PHP_FE(git_remote_save, arginfo_git_remote_save) + PHP_FE(git_remote_owner, arginfo_git_remote_owner) + PHP_FE(git_remote_name, arginfo_git_remote_name) + PHP_FE(git_remote_url, arginfo_git_remote_url) + PHP_FE(git_remote_pushurl, arginfo_git_remote_pushurl) + PHP_FE(git_remote_set_url, arginfo_git_remote_set_url) + PHP_FE(git_remote_set_pushurl, arginfo_git_remote_set_pushurl) + PHP_FE(git_remote_add_fetch, arginfo_git_remote_add_fetch) + PHP_FE(git_remote_get_fetch_refspecs, arginfo_git_remote_get_fetch_refspecs) + PHP_FE(git_remote_set_fetch_refspecs, arginfo_git_remote_set_fetch_refspecs) + PHP_FE(git_remote_add_push, arginfo_git_remote_add_push) + PHP_FE(git_remote_get_push_refspecs, arginfo_git_remote_get_push_refspecs) + PHP_FE(git_remote_set_push_refspecs, arginfo_git_remote_set_push_refspecs) + PHP_FE(git_remote_clear_refspecs, arginfo_git_remote_clear_refspecs) + PHP_FE(git_remote_refspec_count, arginfo_git_remote_refspec_count) + PHP_FE(git_remote_get_refspec, arginfo_git_remote_get_refspec) + PHP_FE(git_remote_connect, arginfo_git_remote_connect) + PHP_FE(git_remote_ls, arginfo_git_remote_ls) + PHP_FE(git_remote_download, arginfo_git_remote_download) + PHP_FE(git_remote_connected, arginfo_git_remote_connected) + PHP_FE(git_remote_stop, arginfo_git_remote_stop) + PHP_FE(git_remote_disconnect, arginfo_git_remote_disconnect) + PHP_FE(git_remote_free, arginfo_git_remote_free) + PHP_FE(git_remote_update_tips, arginfo_git_remote_update_tips) + PHP_FE(git_remote_fetch, arginfo_git_remote_fetch) + PHP_FE(git_remote_valid_url, arginfo_git_remote_valid_url) + PHP_FE(git_remote_supported_url, arginfo_git_remote_supported_url) + PHP_FE(git_remote_list, arginfo_git_remote_list) + PHP_FE(git_remote_check_cert, arginfo_git_remote_check_cert) + PHP_FE(git_remote_set_transport, arginfo_git_remote_set_transport) + PHP_FE(git_remote_set_callbacks, arginfo_git_remote_set_callbacks) + PHP_FE(git_remote_stats, arginfo_git_remote_stats) + PHP_FE(git_remote_autotag, arginfo_git_remote_autotag) + PHP_FE(git_remote_set_autotag, arginfo_git_remote_set_autotag) + PHP_FE(git_remote_rename, arginfo_git_remote_rename) + PHP_FE(git_remote_update_fetchhead, arginfo_git_remote_update_fetchhead) + PHP_FE(git_remote_set_update_fetchhead, arginfo_git_remote_set_update_fetchhead) + PHP_FE(git_remote_is_valid_name, arginfo_git_remote_is_valid_name) + + /* cred */ + PHP_FE(git_cred_has_username, arginfo_git_cred_has_username) + PHP_FE(git_cred_userpass_plaintext_new, arginfo_git_cred_userpass_plaintext_new) + PHP_FE(git_cred_ssh_key_new, arginfo_git_cred_ssh_key_new) + PHP_FE(git_cred_ssh_custom_new, arginfo_git_cred_ssh_custom_new) + PHP_FE(git_cred_default_new, arginfo_git_cred_default_new) + PHP_FE(git_cred_userpass, arginfo_git_cred_userpass) + + /* status */ + PHP_FE(git_status_foreach, arginfo_git_status_foreach) + PHP_FE(git_status_foreach_ext, arginfo_git_status_foreach_ext) + PHP_FE(git_status_file, arginfo_git_status_file) + PHP_FE(git_status_list_new, arginfo_git_status_list_new) + PHP_FE(git_status_list_entrycount, arginfo_git_status_list_entrycount) + PHP_FE(git_status_byindex, arginfo_git_status_byindex) + PHP_FE(git_status_list_free, arginfo_git_status_list_free) + PHP_FE(git_status_should_ignore, arginfo_git_status_should_ignore) + + /* transport */ + PHP_FE(git_transport_new, arginfo_git_transport_new) + PHP_FE(git_transport_register, arginfo_git_transport_register) + PHP_FE(git_transport_unregister, arginfo_git_transport_unregister) + PHP_FE(git_transport_dummy, arginfo_git_transport_dummy) + PHP_FE(git_transport_local, arginfo_git_transport_local) + PHP_FE(git_transport_smart, arginfo_git_transport_smart) + PHP_FE(git_smart_subtransport_http, arginfo_git_smart_subtransport_http) + PHP_FE(git_smart_subtransport_git, arginfo_git_smart_subtransport_git) + PHP_FE(git_smart_subtransport_ssh, arginfo_git_smart_subtransport_ssh) + PHP_FE_END }; diff --git a/remote.c b/remote.c new file mode 100644 index 0000000000..6aa1fd6952 --- /dev/null +++ b/remote.c @@ -0,0 +1,803 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "remote.h" + +/* {{{ proto resource git_remote_create(repo, name, url) +*/ +PHP_FUNCTION(git_remote_create) +{ + zval *repo; + php_git2_t *_repo; + char *name = {0}; + int name_len; + char *url = {0}; + int url_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_create not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &repo, &name, &name_len, &url, &url_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_create_with_fetchspec(repo, name, url, fetch) +*/ +PHP_FUNCTION(git_remote_create_with_fetchspec) +{ + zval *repo; + php_git2_t *_repo; + char *name = {0}; + int name_len; + char *url = {0}; + int url_len; + char *fetch = {0}; + int fetch_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_create_with_fetchspec not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsss", &repo, &name, &name_len, &url, &url_len, &fetch, &fetch_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_create_inmemory(repo, fetch, url) +*/ +PHP_FUNCTION(git_remote_create_inmemory) +{ + zval *repo; + php_git2_t *_repo; + char *fetch = {0}; + int fetch_len; + char *url = {0}; + int url_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_create_inmemory not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &repo, &fetch, &fetch_len, &url, &url_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_load(repo, name) +*/ +PHP_FUNCTION(git_remote_load) +{ + zval *repo; + php_git2_t *_repo; + char *name = {0}; + int name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_load not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &name, &name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_save(remote) +*/ +PHP_FUNCTION(git_remote_save) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_save not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_owner(remote) +*/ +PHP_FUNCTION(git_remote_owner) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_owner not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_name(remote) +*/ +PHP_FUNCTION(git_remote_name) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_name not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_url(remote) +*/ +PHP_FUNCTION(git_remote_url) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_url not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_pushurl(remote) +*/ +PHP_FUNCTION(git_remote_pushurl) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_pushurl not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_set_url(remote, url) +*/ +PHP_FUNCTION(git_remote_set_url) +{ + zval *remote; + php_git2_t *_remote; + char *url = {0}; + int url_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_url not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &remote, &url, &url_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_set_pushurl(remote, url) +*/ +PHP_FUNCTION(git_remote_set_pushurl) +{ + zval *remote; + php_git2_t *_remote; + char *url = {0}; + int url_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_pushurl not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &remote, &url, &url_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_add_fetch(remote, refspec) +*/ +PHP_FUNCTION(git_remote_add_fetch) +{ + zval *remote; + php_git2_t *_remote; + char *refspec = {0}; + int refspec_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_add_fetch not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &remote, &refspec, &refspec_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_get_fetch_refspecs(array, remote) +*/ +PHP_FUNCTION(git_remote_get_fetch_refspecs) +{ + zval *array; + php_git2_t *_array; + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_get_fetch_refspecs not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &array, &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_array, php_git2_t*, &array, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_set_fetch_refspecs(remote, array) +*/ +PHP_FUNCTION(git_remote_set_fetch_refspecs) +{ + zval *remote; + php_git2_t *_remote; + zval *array; + php_git2_t *_array; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_fetch_refspecs not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &remote, &array) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_add_push(remote, refspec) +*/ +PHP_FUNCTION(git_remote_add_push) +{ + zval *remote; + php_git2_t *_remote; + char *refspec = {0}; + int refspec_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_add_push not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &remote, &refspec, &refspec_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_get_push_refspecs(array, remote) +*/ +PHP_FUNCTION(git_remote_get_push_refspecs) +{ + zval *array; + php_git2_t *_array; + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_get_push_refspecs not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &array, &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_array, php_git2_t*, &array, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_set_push_refspecs(remote, array) +*/ +PHP_FUNCTION(git_remote_set_push_refspecs) +{ + zval *remote; + php_git2_t *_remote; + zval *array; + php_git2_t *_array; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_push_refspecs not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &remote, &array) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_remote_clear_refspecs(remote) +*/ +PHP_FUNCTION(git_remote_clear_refspecs) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_clear_refspecs not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_refspec_count(remote) +*/ +PHP_FUNCTION(git_remote_refspec_count) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_refspec_count not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_get_refspec(remote, n) +*/ +PHP_FUNCTION(git_remote_get_refspec) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_get_refspec not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &remote, &n) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_connect(remote, direction) +*/ +PHP_FUNCTION(git_remote_connect) +{ + zval *remote; + php_git2_t *_remote; + zval *direction; + php_git2_t *_direction; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_connect not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &remote, &direction) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_ls(size, remote) +*/ +PHP_FUNCTION(git_remote_ls) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_ls not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &size, &remote) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_size, php_git2_t*, &size, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_download(remote) +*/ +PHP_FUNCTION(git_remote_download) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_download not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_connected(remote) +*/ +PHP_FUNCTION(git_remote_connected) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_connected not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_remote_stop(remote) +*/ +PHP_FUNCTION(git_remote_stop) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_stop not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_remote_disconnect(remote) +*/ +PHP_FUNCTION(git_remote_disconnect) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_disconnect not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_remote_free(remote) +*/ +PHP_FUNCTION(git_remote_free) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_update_tips(remote) +*/ +PHP_FUNCTION(git_remote_update_tips) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_update_tips not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_fetch(remote) +*/ +PHP_FUNCTION(git_remote_fetch) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_fetch not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_valid_url(url) +*/ +PHP_FUNCTION(git_remote_valid_url) +{ + char *url = {0}; + int url_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_valid_url not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &url, &url_len) == FAILURE) { + return; + } +} + +/* {{{ proto long git_remote_supported_url(url) +*/ +PHP_FUNCTION(git_remote_supported_url) +{ + char *url = {0}; + int url_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_supported_url not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &url, &url_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_remote_list(repo) +*/ +PHP_FUNCTION(git_remote_list) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_list not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_remote_check_cert(remote, check) +*/ +PHP_FUNCTION(git_remote_check_cert) +{ + zval *remote; + php_git2_t *_remote; + long check; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_check_cert not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &remote, &check) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_set_transport(remote, transport) +*/ +PHP_FUNCTION(git_remote_set_transport) +{ + zval *remote; + php_git2_t *_remote; + zval *transport; + php_git2_t *_transport; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_transport not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &remote, &transport) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_set_callbacks(remote, callbacks) +*/ +PHP_FUNCTION(git_remote_set_callbacks) +{ + zval *remote; + php_git2_t *_remote; + zval *callbacks; + php_git2_t *_callbacks; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_callbacks not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &remote, &callbacks) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_stats(remote) +*/ +PHP_FUNCTION(git_remote_stats) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_stats not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_remote_autotag(remote) +*/ +PHP_FUNCTION(git_remote_autotag) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_autotag not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_remote_set_autotag(remote, value) +*/ +PHP_FUNCTION(git_remote_set_autotag) +{ + zval *remote; + php_git2_t *_remote; + zval *value; + php_git2_t *_value; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_autotag not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &remote, &value) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_rename(remote, new_name, callback, payload) +*/ +PHP_FUNCTION(git_remote_rename) +{ + zval *remote; + php_git2_t *_remote; + char *new_name = {0}; + int new_name_len; + zval *callback; + php_git2_t *_callback; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_rename not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rsr", &remote, &new_name, &new_name_len, &callback, &payload) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_update_fetchhead(remote) +*/ +PHP_FUNCTION(git_remote_update_fetchhead) +{ + zval *remote; + php_git2_t *_remote; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_update_fetchhead not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_remote_set_update_fetchhead(remote, value) +*/ +PHP_FUNCTION(git_remote_set_update_fetchhead) +{ + zval *remote; + php_git2_t *_remote; + long value; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_update_fetchhead not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &remote, &value) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_remote_is_valid_name(remote_name) +*/ +PHP_FUNCTION(git_remote_is_valid_name) +{ + char *remote_name = {0}; + int remote_name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_is_valid_name not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &remote_name, &remote_name_len) == FAILURE) { + return; + } +} + diff --git a/remote.h b/remote.h new file mode 100644 index 0000000000..7d8b17d871 --- /dev/null +++ b/remote.h @@ -0,0 +1,392 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_REMOTE_H +#define PHP_GIT2_REMOTE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_create, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_create_with_fetchspec, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, url) + ZEND_ARG_INFO(0, fetch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_create_inmemory, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, fetch) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_load, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_save, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_owner, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_name, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_url, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_pushurl, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_url, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_pushurl, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_add_fetch, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, refspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_get_fetch_refspecs, 0, 0, 2) + ZEND_ARG_INFO(0, array) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_fetch_refspecs, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, array) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_add_push, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, refspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_get_push_refspecs, 0, 0, 2) + ZEND_ARG_INFO(0, array) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_push_refspecs, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, array) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_clear_refspecs, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_refspec_count, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_get_refspec, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, n) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_connect, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, direction) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_ls, 0, 0, 2) + ZEND_ARG_INFO(0, size) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_download, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_connected, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_stop, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_disconnect, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_free, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_update_tips, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_fetch, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_valid_url, 0, 0, 1) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_supported_url, 0, 0, 1) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_list, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_check_cert, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, check) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_transport, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, transport) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_callbacks, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, callbacks) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_stats, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_autotag, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_autotag, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_rename, 0, 0, 4) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, new_name) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_update_fetchhead, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_set_update_fetchhead, 0, 0, 2) + ZEND_ARG_INFO(0, remote) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_is_valid_name, 0, 0, 1) + ZEND_ARG_INFO(0, remote_name) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_remote_create(repo, name, url) +*/ +PHP_FUNCTION(git_remote_create); + +/* {{{ proto resource git_remote_create_with_fetchspec(repo, name, url, fetch) +*/ +PHP_FUNCTION(git_remote_create_with_fetchspec); + +/* {{{ proto resource git_remote_create_inmemory(repo, fetch, url) +*/ +PHP_FUNCTION(git_remote_create_inmemory); + +/* {{{ proto resource git_remote_load(repo, name) +*/ +PHP_FUNCTION(git_remote_load); + +/* {{{ proto long git_remote_save(remote) +*/ +PHP_FUNCTION(git_remote_save); + +/* {{{ proto resource git_remote_owner(remote) +*/ +PHP_FUNCTION(git_remote_owner); + +/* {{{ proto resource git_remote_name(remote) +*/ +PHP_FUNCTION(git_remote_name); + +/* {{{ proto resource git_remote_url(remote) +*/ +PHP_FUNCTION(git_remote_url); + +/* {{{ proto resource git_remote_pushurl(remote) +*/ +PHP_FUNCTION(git_remote_pushurl); + +/* {{{ proto long git_remote_set_url(remote, url) +*/ +PHP_FUNCTION(git_remote_set_url); + +/* {{{ proto long git_remote_set_pushurl(remote, url) +*/ +PHP_FUNCTION(git_remote_set_pushurl); + +/* {{{ proto long git_remote_add_fetch(remote, refspec) +*/ +PHP_FUNCTION(git_remote_add_fetch); + +/* {{{ proto long git_remote_get_fetch_refspecs(array, remote) +*/ +PHP_FUNCTION(git_remote_get_fetch_refspecs); + +/* {{{ proto long git_remote_set_fetch_refspecs(remote, array) +*/ +PHP_FUNCTION(git_remote_set_fetch_refspecs); + +/* {{{ proto long git_remote_add_push(remote, refspec) +*/ +PHP_FUNCTION(git_remote_add_push); + +/* {{{ proto long git_remote_get_push_refspecs(array, remote) +*/ +PHP_FUNCTION(git_remote_get_push_refspecs); + +/* {{{ proto long git_remote_set_push_refspecs(remote, array) +*/ +PHP_FUNCTION(git_remote_set_push_refspecs); + +/* {{{ proto void git_remote_clear_refspecs(remote) +*/ +PHP_FUNCTION(git_remote_clear_refspecs); + +/* {{{ proto resource git_remote_refspec_count(remote) +*/ +PHP_FUNCTION(git_remote_refspec_count); + +/* {{{ proto resource git_remote_get_refspec(remote, n) +*/ +PHP_FUNCTION(git_remote_get_refspec); + +/* {{{ proto long git_remote_connect(remote, direction) +*/ +PHP_FUNCTION(git_remote_connect); + +/* {{{ proto resource git_remote_ls(size, remote) +*/ +PHP_FUNCTION(git_remote_ls); + +/* {{{ proto long git_remote_download(remote) +*/ +PHP_FUNCTION(git_remote_download); + +/* {{{ proto long git_remote_connected(remote) +*/ +PHP_FUNCTION(git_remote_connected); + +/* {{{ proto void git_remote_stop(remote) +*/ +PHP_FUNCTION(git_remote_stop); + +/* {{{ proto void git_remote_disconnect(remote) +*/ +PHP_FUNCTION(git_remote_disconnect); + +/* {{{ proto void git_remote_free(remote) +*/ +PHP_FUNCTION(git_remote_free); + +/* {{{ proto long git_remote_update_tips(remote) +*/ +PHP_FUNCTION(git_remote_update_tips); + +/* {{{ proto long git_remote_fetch(remote) +*/ +PHP_FUNCTION(git_remote_fetch); + +/* {{{ proto long git_remote_valid_url(url) +*/ +PHP_FUNCTION(git_remote_valid_url); + +/* {{{ proto long git_remote_supported_url(url) +*/ +PHP_FUNCTION(git_remote_supported_url); + +/* {{{ proto resource git_remote_list(repo) +*/ +PHP_FUNCTION(git_remote_list); + +/* {{{ proto void git_remote_check_cert(remote, check) +*/ +PHP_FUNCTION(git_remote_check_cert); + +/* {{{ proto long git_remote_set_transport(remote, transport) +*/ +PHP_FUNCTION(git_remote_set_transport); + +/* {{{ proto long git_remote_set_callbacks(remote, callbacks) +*/ +PHP_FUNCTION(git_remote_set_callbacks); + +/* {{{ proto resource git_remote_stats(remote) +*/ +PHP_FUNCTION(git_remote_stats); + +/* {{{ proto resource git_remote_autotag(remote) +*/ +PHP_FUNCTION(git_remote_autotag); + +/* {{{ proto void git_remote_set_autotag(remote, value) +*/ +PHP_FUNCTION(git_remote_set_autotag); + +/* {{{ proto long git_remote_rename(remote, new_name, callback, payload) +*/ +PHP_FUNCTION(git_remote_rename); + +/* {{{ proto long git_remote_update_fetchhead(remote) +*/ +PHP_FUNCTION(git_remote_update_fetchhead); + +/* {{{ proto void git_remote_set_update_fetchhead(remote, value) +*/ +PHP_FUNCTION(git_remote_set_update_fetchhead); + +/* {{{ proto long git_remote_is_valid_name(remote_name) +*/ +PHP_FUNCTION(git_remote_is_valid_name); + +#endif \ No newline at end of file diff --git a/revparse.c b/revparse.c new file mode 100644 index 0000000000..81faddf146 --- /dev/null +++ b/revparse.c @@ -0,0 +1,68 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "revparse.h" + +/* {{{ proto resource git_revparse_single(repo, spec) +*/ +PHP_FUNCTION(git_revparse_single) +{ + zval *repo; + php_git2_t *_repo; + char *spec = {0}; + int spec_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse_single not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &spec, &spec_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_revparse_ext(reference_out, repo, spec) +*/ +PHP_FUNCTION(git_revparse_ext) +{ + zval *reference_out; + php_git2_t *_reference_out; + zval *repo; + php_git2_t *_repo; + char *spec = {0}; + int spec_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse_ext not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrs", &reference_out, &repo, &spec, &spec_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_reference_out, php_git2_t*, &reference_out, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_revparse(revspec, repo, spec) +*/ +PHP_FUNCTION(git_revparse) +{ + zval *revspec; + php_git2_t *_revspec; + zval *repo; + php_git2_t *_repo; + char *spec = {0}; + int spec_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrs", &revspec, &repo, &spec, &spec_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_revspec, php_git2_t*, &revspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/revparse.h b/revparse.h new file mode 100644 index 0000000000..8aa88dfa40 --- /dev/null +++ b/revparse.h @@ -0,0 +1,58 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_REVPARSE_H +#define PHP_GIT2_REVPARSE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revparse_single, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, spec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revparse_ext, 0, 0, 3) + ZEND_ARG_INFO(0, reference_out) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, spec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_revparse, 0, 0, 3) + ZEND_ARG_INFO(0, revspec) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, spec) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_revparse_single(repo, spec) +*/ +PHP_FUNCTION(git_revparse_single); + +/* {{{ proto resource git_revparse_ext(reference_out, repo, spec) +*/ +PHP_FUNCTION(git_revparse_ext); + +/* {{{ proto long git_revparse(revspec, repo, spec) +*/ +PHP_FUNCTION(git_revparse); + +#endif \ No newline at end of file diff --git a/status.c b/status.c new file mode 100644 index 0000000000..e16d2ab457 --- /dev/null +++ b/status.c @@ -0,0 +1,165 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "status.h" + +/* {{{ proto long git_status_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_status_foreach) +{ + zval *repo; + php_git2_t *_repo; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_foreach not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &repo, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_status_foreach_ext(repo, opts, callback, payload) +*/ +PHP_FUNCTION(git_status_foreach_ext) +{ + zval *repo; + php_git2_t *_repo; + zval *opts; + php_git2_t *_opts; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_foreach_ext not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrrz", &repo, &opts, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_status_file(status_flags, repo, path) +*/ +PHP_FUNCTION(git_status_file) +{ + long status_flags; + zval *repo; + php_git2_t *_repo; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_file not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lrs", &status_flags, &repo, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_status_list_new(repo, opts) +*/ +PHP_FUNCTION(git_status_list_new) +{ + zval *repo; + php_git2_t *_repo; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &opts) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_status_list_entrycount(statuslist) +*/ +PHP_FUNCTION(git_status_list_entrycount) +{ + zval *statuslist; + php_git2_t *_statuslist; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_entrycount not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &statuslist) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_status_byindex(statuslist, idx) +*/ +PHP_FUNCTION(git_status_byindex) +{ + zval *statuslist; + php_git2_t *_statuslist; + long idx; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_byindex not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &statuslist, &idx) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_status_list_free(statuslist) +*/ +PHP_FUNCTION(git_status_list_free) +{ + zval *statuslist; + php_git2_t *_statuslist; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &statuslist) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_status_should_ignore(ignored, repo, path) +*/ +PHP_FUNCTION(git_status_should_ignore) +{ + long ignored; + zval *repo; + php_git2_t *_repo; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_should_ignore not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lrs", &ignored, &repo, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/status.h b/status.h new file mode 100644 index 0000000000..d2a7f9f2c7 --- /dev/null +++ b/status.h @@ -0,0 +1,104 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_STATUS_H +#define PHP_GIT2_STATUS_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_foreach_ext, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, opts) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_file, 0, 0, 3) + ZEND_ARG_INFO(0, status_flags) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_list_new, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_list_entrycount, 0, 0, 1) + ZEND_ARG_INFO(0, statuslist) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_byindex, 0, 0, 2) + ZEND_ARG_INFO(0, statuslist) + ZEND_ARG_INFO(0, idx) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_list_free, 0, 0, 1) + ZEND_ARG_INFO(0, statuslist) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_should_ignore, 0, 0, 3) + ZEND_ARG_INFO(0, ignored) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_status_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_status_foreach); + +/* {{{ proto long git_status_foreach_ext(repo, opts, callback, payload) +*/ +PHP_FUNCTION(git_status_foreach_ext); + +/* {{{ proto long git_status_file(status_flags, repo, path) +*/ +PHP_FUNCTION(git_status_file); + +/* {{{ proto resource git_status_list_new(repo, opts) +*/ +PHP_FUNCTION(git_status_list_new); + +/* {{{ proto resource git_status_list_entrycount(statuslist) +*/ +PHP_FUNCTION(git_status_list_entrycount); + +/* {{{ proto resource git_status_byindex(statuslist, idx) +*/ +PHP_FUNCTION(git_status_byindex); + +/* {{{ proto void git_status_list_free(statuslist) +*/ +PHP_FUNCTION(git_status_list_free); + +/* {{{ proto long git_status_should_ignore(ignored, repo, path) +*/ +PHP_FUNCTION(git_status_should_ignore); + +#endif \ No newline at end of file diff --git a/tag.c b/tag.c new file mode 100644 index 0000000000..4e8d9542b7 --- /dev/null +++ b/tag.c @@ -0,0 +1,404 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "tag.h" + +/* {{{ proto resource git_tag_lookup(repo, id) +*/ +PHP_FUNCTION(git_tag_lookup) +{ + zval *repo; + php_git2_t *_repo; + char *id = {0}; + int id_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_lookup not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &id, &id_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_lookup_prefix(repo, id, len) +*/ +PHP_FUNCTION(git_tag_lookup_prefix) +{ + zval *repo; + php_git2_t *_repo; + char *id = {0}; + int id_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_lookup_prefix not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rs", &repo, &id, &id_len, &len) == FAILURE) { +// return; +// } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_tag_free(tag) +*/ +PHP_FUNCTION(git_tag_free) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_id(tag) +*/ +PHP_FUNCTION(git_tag_id) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_id not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_owner(tag) +*/ +PHP_FUNCTION(git_tag_owner) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_owner not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_target(tag) +*/ +PHP_FUNCTION(git_tag_target) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_target not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_target_id(tag) +*/ +PHP_FUNCTION(git_tag_target_id) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_target_id not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_target_type(tag) +*/ +PHP_FUNCTION(git_tag_target_type) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_target_type not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_name(tag) +*/ +PHP_FUNCTION(git_tag_name) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_name not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_tagger(tag) +*/ +PHP_FUNCTION(git_tag_tagger) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_tagger not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_message(tag) +*/ +PHP_FUNCTION(git_tag_message) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_message not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_create(repo, tag_name, target, tagger, message, force) +*/ +PHP_FUNCTION(git_tag_create) +{ + zval *repo; + php_git2_t *_repo; + char *tag_name = {0}; + int tag_name_len; + zval *target; + php_git2_t *_target; + zval *tagger; + php_git2_t *_tagger; + char *message = {0}; + int message_len; + long force; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_create not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrrsl", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_annotation_create(repo, tag_name, target, tagger, message) +*/ +PHP_FUNCTION(git_tag_annotation_create) +{ + zval *repo; + php_git2_t *_repo; + char *tag_name = {0}; + int tag_name_len; + zval *target; + php_git2_t *_target; + zval *tagger; + php_git2_t *_tagger; + char *message = {0}; + int message_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_annotation_create not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrrs", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_create_frombuffer(repo, buffer, force) +*/ +PHP_FUNCTION(git_tag_create_frombuffer) +{ + zval *repo; + php_git2_t *_repo; + char *buffer = {0}; + int buffer_len; + long force; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_create_frombuffer not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &repo, &buffer, &buffer_len, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_create_lightweight(repo, tag_name, target, force) +*/ +PHP_FUNCTION(git_tag_create_lightweight) +{ + zval *repo; + php_git2_t *_repo; + char *tag_name = {0}; + int tag_name_len; + zval *target; + php_git2_t *_target; + long force; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_create_lightweight not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrl", &repo, &tag_name, &tag_name_len, &target, &force) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_tag_delete(repo, tag_name) +*/ +PHP_FUNCTION(git_tag_delete) +{ + zval *repo; + php_git2_t *_repo; + char *tag_name = {0}; + int tag_name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_delete not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &tag_name, &tag_name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_tag_list(tag_names, repo) +*/ +PHP_FUNCTION(git_tag_list) +{ + zval *tag_names; + php_git2_t *_tag_names; + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_list not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &tag_names, &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag_names, php_git2_t*, &tag_names, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_tag_list_match(tag_names, pattern, repo) +*/ +PHP_FUNCTION(git_tag_list_match) +{ + zval *tag_names; + php_git2_t *_tag_names; + char *pattern = {0}; + int pattern_len; + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_list_match not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsr", &tag_names, &pattern, &pattern_len, &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag_names, php_git2_t*, &tag_names, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_tag_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_tag_foreach) +{ + zval *repo; + php_git2_t *_repo; + zval *callback; + php_git2_t *_callback; + zval *payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_foreach not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrz", &repo, &callback, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_tag_peel(tag) +*/ +PHP_FUNCTION(git_tag_peel) +{ + zval *tag; + php_git2_t *_tag; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_peel not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &tag) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/tag.h b/tag.h new file mode 100644 index 0000000000..0b6d4a742c --- /dev/null +++ b/tag.h @@ -0,0 +1,212 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_TAG_H +#define PHP_GIT2_TAG_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_lookup, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_lookup_prefix, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, len) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_free, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_id, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_owner, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_target, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_target_id, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_target_type, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_name, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_tagger, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_message, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_create, 0, 0, 6) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, tag_name) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, tagger) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_annotation_create, 0, 0, 5) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, tag_name) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, tagger) + ZEND_ARG_INFO(0, message) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_create_frombuffer, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, buffer) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_create_lightweight, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, tag_name) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_delete, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, tag_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_list, 0, 0, 2) + ZEND_ARG_INFO(0, tag_names) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_list_match, 0, 0, 3) + ZEND_ARG_INFO(0, tag_names) + ZEND_ARG_INFO(0, pattern) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_peel, 0, 0, 1) + ZEND_ARG_INFO(0, tag) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_tag_lookup(repo, id) +*/ +PHP_FUNCTION(git_tag_lookup); + +/* {{{ proto resource git_tag_lookup_prefix(repo, id, len) +*/ +PHP_FUNCTION(git_tag_lookup_prefix); + +/* {{{ proto void git_tag_free(tag) +*/ +PHP_FUNCTION(git_tag_free); + +/* {{{ proto resource git_tag_id(tag) +*/ +PHP_FUNCTION(git_tag_id); + +/* {{{ proto resource git_tag_owner(tag) +*/ +PHP_FUNCTION(git_tag_owner); + +/* {{{ proto resource git_tag_target(tag) +*/ +PHP_FUNCTION(git_tag_target); + +/* {{{ proto resource git_tag_target_id(tag) +*/ +PHP_FUNCTION(git_tag_target_id); + +/* {{{ proto resource git_tag_target_type(tag) +*/ +PHP_FUNCTION(git_tag_target_type); + +/* {{{ proto resource git_tag_name(tag) +*/ +PHP_FUNCTION(git_tag_name); + +/* {{{ proto resource git_tag_tagger(tag) +*/ +PHP_FUNCTION(git_tag_tagger); + +/* {{{ proto resource git_tag_message(tag) +*/ +PHP_FUNCTION(git_tag_message); + +/* {{{ proto resource git_tag_create(repo, tag_name, target, tagger, message, force) +*/ +PHP_FUNCTION(git_tag_create); + +/* {{{ proto resource git_tag_annotation_create(repo, tag_name, target, tagger, message) +*/ +PHP_FUNCTION(git_tag_annotation_create); + +/* {{{ proto resource git_tag_create_frombuffer(repo, buffer, force) +*/ +PHP_FUNCTION(git_tag_create_frombuffer); + +/* {{{ proto resource git_tag_create_lightweight(repo, tag_name, target, force) +*/ +PHP_FUNCTION(git_tag_create_lightweight); + +/* {{{ proto long git_tag_delete(repo, tag_name) +*/ +PHP_FUNCTION(git_tag_delete); + +/* {{{ proto long git_tag_list(tag_names, repo) +*/ +PHP_FUNCTION(git_tag_list); + +/* {{{ proto long git_tag_list_match(tag_names, pattern, repo) +*/ +PHP_FUNCTION(git_tag_list_match); + +/* {{{ proto long git_tag_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_tag_foreach); + +/* {{{ proto resource git_tag_peel(tag) +*/ +PHP_FUNCTION(git_tag_peel); + +#endif \ No newline at end of file diff --git a/transport.c b/transport.c new file mode 100644 index 0000000000..6a06c72d9c --- /dev/null +++ b/transport.c @@ -0,0 +1,171 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "transport.h" + +/* {{{ proto resource git_transport_new(owner, url) +*/ +PHP_FUNCTION(git_transport_new) +{ + zval *owner; + php_git2_t *_owner; + char *url = {0}; + int url_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &owner, &url, &url_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_transport_register(prefix, priority, cb, param) +*/ +PHP_FUNCTION(git_transport_register) +{ + char *prefix = {0}; + int prefix_len; + zval *cb; + php_git2_t *_cb; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_register not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "sr", &prefix, &prefix_len, &priority, &cb, ¶m) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_prefix, php_git2_t*, &prefix, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_transport_unregister(prefix, priority) +*/ +PHP_FUNCTION(git_transport_unregister) +{ + char *prefix = {0}; + int prefix_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_unregister not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "s", &prefix, &prefix_len, &priority) == FAILURE) { +// return; +// } +} + +/* {{{ proto resource git_transport_dummy(owner, payload) +*/ +PHP_FUNCTION(git_transport_dummy) +{ + zval *owner; + php_git2_t *_owner; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_dummy not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &owner, &payload) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_transport_local(owner, payload) +*/ +PHP_FUNCTION(git_transport_local) +{ + zval *owner; + php_git2_t *_owner; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_local not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &owner, &payload) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_transport_smart(owner, payload) +*/ +PHP_FUNCTION(git_transport_smart) +{ + zval *owner; + php_git2_t *_owner; + zval *payload; + php_git2_t *_payload; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_smart not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &owner, &payload) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_smart_subtransport_http(owner) +*/ +PHP_FUNCTION(git_smart_subtransport_http) +{ + zval *owner; + php_git2_t *_owner; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_smart_subtransport_http not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &owner) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_smart_subtransport_git(owner) +*/ +PHP_FUNCTION(git_smart_subtransport_git) +{ + zval *owner; + php_git2_t *_owner; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_smart_subtransport_git not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &owner) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_smart_subtransport_ssh(owner) +*/ +PHP_FUNCTION(git_smart_subtransport_ssh) +{ + zval *owner; + php_git2_t *_owner; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_smart_subtransport_ssh not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &owner) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/transport.h b/transport.h new file mode 100644 index 0000000000..d297adbf23 --- /dev/null +++ b/transport.h @@ -0,0 +1,109 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_TRANSPORT_H +#define PHP_GIT2_TRANSPORT_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_new, 0, 0, 2) + ZEND_ARG_INFO(0, owner) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_register, 0, 0, 4) + ZEND_ARG_INFO(0, prefix) + ZEND_ARG_INFO(0, priority) + ZEND_ARG_INFO(0, cb) + ZEND_ARG_INFO(0, param) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_unregister, 0, 0, 2) + ZEND_ARG_INFO(0, prefix) + ZEND_ARG_INFO(0, priority) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_dummy, 0, 0, 2) + ZEND_ARG_INFO(0, owner) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_local, 0, 0, 2) + ZEND_ARG_INFO(0, owner) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_smart, 0, 0, 2) + ZEND_ARG_INFO(0, owner) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_smart_subtransport_http, 0, 0, 1) + ZEND_ARG_INFO(0, owner) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_smart_subtransport_git, 0, 0, 1) + ZEND_ARG_INFO(0, owner) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_smart_subtransport_ssh, 0, 0, 1) + ZEND_ARG_INFO(0, owner) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_transport_new(owner, url) +*/ +PHP_FUNCTION(git_transport_new); + +/* {{{ proto long git_transport_register(prefix, priority, cb, param) +*/ +PHP_FUNCTION(git_transport_register); + +/* {{{ proto long git_transport_unregister(prefix, priority) +*/ +PHP_FUNCTION(git_transport_unregister); + +/* {{{ proto resource git_transport_dummy(owner, payload) +*/ +PHP_FUNCTION(git_transport_dummy); + +/* {{{ proto resource git_transport_local(owner, payload) +*/ +PHP_FUNCTION(git_transport_local); + +/* {{{ proto resource git_transport_smart(owner, payload) +*/ +PHP_FUNCTION(git_transport_smart); + +/* {{{ proto resource git_smart_subtransport_http(owner) +*/ +PHP_FUNCTION(git_smart_subtransport_http); + +/* {{{ proto resource git_smart_subtransport_git(owner) +*/ +PHP_FUNCTION(git_smart_subtransport_git); + +/* {{{ proto resource git_smart_subtransport_ssh(owner) +*/ +PHP_FUNCTION(git_smart_subtransport_ssh); + +#endif \ No newline at end of file From ffe9ef504f68685cc08f28b697484fe59d587f2a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 11 Jan 2014 22:12:45 +0900 Subject: [PATCH 020/136] [revparse] implement functions --- revparse.c | 142 +++++++++++++++++++++++++++++++++++++++-------------- tree.c | 2 +- 2 files changed, 105 insertions(+), 39 deletions(-) diff --git a/revparse.c b/revparse.c index 81faddf146..f21aeca18d 100644 --- a/revparse.c +++ b/revparse.c @@ -2,67 +2,133 @@ #include "php_git2_priv.h" #include "revparse.h" -/* {{{ proto resource git_revparse_single(repo, spec) -*/ +/* {{{ proto resource git_revparse_single(resource $repo, string $spec) + */ PHP_FUNCTION(git_revparse_single) { - zval *repo; - php_git2_t *_repo; - char *spec = {0}; - int spec_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse_single not implemented yet"); - return; + php_git2_t *result = NULL; + git_object *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *spec = NULL; + int spec_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &spec, &spec_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_revparse_single(&out, PHP_GIT2_V(_repo, repository), spec); + if (php_git2_check_error(error, "git_revparse_single" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, object) = out; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_revparse_ext(reference_out, repo, spec) -*/ +/* {{{ proto array git_revparse_ext(resource $repo, string $spec) + */ PHP_FUNCTION(git_revparse_ext) { - zval *reference_out; - php_git2_t *_reference_out; - zval *repo; - php_git2_t *_repo; - char *spec = {0}; - int spec_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse_ext not implemented yet"); - return; + zval *array, *a, *b; + php_git2_t *result = NULL, *result2 = NULL; + git_object *object_out = NULL; + git_reference *reference_out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *spec = NULL; + int spec_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrs", &reference_out, &repo, &spec, &spec_len) == FAILURE) { + "rs", &repo, &spec, &spec_len) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_reference_out, php_git2_t*, &reference_out, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_revparse_ext(&object_out, &reference_out, PHP_GIT2_V(_repo, repository), spec); + if (php_git2_check_error(error, "git_revparse_ext" TSRMLS_CC)) { + RETURN_FALSE; + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_MAKE_RESOURCE(result2); + MAKE_STD_ZVAL(array); + MAKE_STD_ZVAL(a); + MAKE_STD_ZVAL(b); + + PHP_GIT2_V(result, object) = object_out; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(a, result->resource_id); + + PHP_GIT2_V(result2, reference) = reference_out; + result2->type = PHP_GIT2_TYPE_REFERENCE; + result2->resource_id = PHP_GIT2_LIST_INSERT(result2, git2_resource_handle); + result2->should_free_v = 0; + ZVAL_RESOURCE(b, result->resource_id); + + array_init(array); + add_next_index_zval(array, a); + add_next_index_zval(array, b); + RETURN_ZVAL(array, 0, 1); } +/* }}} */ -/* {{{ proto long git_revparse(revspec, repo, spec) -*/ +/* {{{ proto array git_revparse(resource $repo, string $spec) + */ PHP_FUNCTION(git_revparse) { - zval *revspec; - php_git2_t *_revspec; - zval *repo; - php_git2_t *_repo; - char *spec = {0}; - int spec_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse not implemented yet"); - return; + git_revspec revspec; + zval *repo = NULL; + php_git2_t *_repo = NULL, *_from = NULL, *_to = NULL; + zval *result = NULL, *from, *to; + char *spec = NULL; + int spec_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrs", &revspec, &repo, &spec, &spec_len) == FAILURE) { + "rs", &repo, &spec, &spec_len) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_revspec, php_git2_t*, &revspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + memset(&revspec, '\0', sizeof(revspec)); + error = git_revparse(&revspec, PHP_GIT2_V(_repo, repository), spec); + if (php_git2_check_error(error, "git_revparse" TSRMLS_CC)) { + RETURN_FALSE; + } + MAKE_STD_ZVAL(result); + MAKE_STD_ZVAL(from); + MAKE_STD_ZVAL(to); + + PHP_GIT2_V(_from, object) = revspec.from; + _from->type = PHP_GIT2_TYPE_OBJECT; + _from->resource_id = PHP_GIT2_LIST_INSERT(_from, git2_resource_handle); + _from->should_free_v = 0; + ZVAL_RESOURCE(from, _from->resource_id); + + PHP_GIT2_V(_to, object) = revspec.to; + _to->type = PHP_GIT2_TYPE_OBJECT; + _to->resource_id = PHP_GIT2_LIST_INSERT(_to, git2_resource_handle); + _to->should_free_v = 0; + ZVAL_RESOURCE(to, _to->resource_id); + + array_init(result); + add_assoc_zval_ex(result, ZEND_STRS("from"), from); + add_assoc_zval_ex(result, ZEND_STRS("to"), to); + add_assoc_long_ex(result, ZEND_STRS("flags"), revspec.flags); + + RETURN_ZVAL(result, 0, 1); } +/* }}} */ diff --git a/tree.c b/tree.c index adbc5981a7..338b4054a3 100644 --- a/tree.c +++ b/tree.c @@ -373,12 +373,12 @@ PHP_FUNCTION(git_tree_lookup) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - PHP_GIT2_MAKE_RESOURCE(result); error = git_tree_lookup(&tree, PHP_GIT2_V(git2, repository), &id); if (php_git2_check_error(error, "git_commit_lookup" TSRMLS_CC)) { RETURN_FALSE } + PHP_GIT2_MAKE_RESOURCE(result); PHP_GIT2_V(result, tree) = tree; result->type = PHP_GIT2_TYPE_TREE; result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); From ded8f8f1586e671000d2c6c07875bf1427b8bbc7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 00:04:09 +0900 Subject: [PATCH 021/136] [git_status_list] add stub codes --- ng.php | 813 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 813 insertions(+) create mode 100644 ng.php diff --git a/ng.php b/ng.php new file mode 100644 index 0000000000..44a3fd534c --- /dev/null +++ b/ng.php @@ -0,0 +1,813 @@ +name = $name; + $this->return_type = preg_replace("/\*/", "", $return_type); + + for ($i = 0; $i < count($return_type); $i++) { + if ($return_type[$i] == '*') { + $this->ptr++; + } + } + } + + public function getReturnType() + { + return $this->return_type; + } + + public function isResourceCreator() + { + if (count($this->args)) { + $first = $this->args[0]; + if (preg_match("/out/", $first->getName())) { + return true; + } + } else { + if (preg_match("/git_/", $this->getReturnType())) { + return true; + } + } + return false; + } + + public function isLongCreator() + { + if (preg_match("/size_t/", $this->getReturnType())) { + return true; + } + } + + public function isArrayCreator() + { + if (preg_match("/git_/", $this->getReturnType())) { + return true; + } + } + + public function isSavior() + { + if (preg_match('/_free$/', $this->getName())) { + return true; + } + } + + public function getArguments() + { + return $this->args; + } + + public function addArgument(Arg $arg) + { + $this->args[] = $arg; + } + + public function getName() + { + return $this->name; + } + + public function first() + { + return $this->args[0]; + } +} + +class Arg +{ + protected $type; + protected $ptr = 0; + protected $name; + protected $const; + + public function getDefaultValue() + { + if (preg_match("/long/", $this->getZendType())) { + return "0"; + } else { + return "NULL"; + } + } + + public function getName() + { + return $this->name; + } + + public function getType() + { + return $this->type; + } + + public function getPtr() + { + return str_repeat("*", $this->ptr - 1); + } + + public function shouldWrite() + { + if ($this->ptr == 2) { + if (preg_match("/^git_/", $this->type)) { + return true; + } + } + + return false; + + } + + public function getZendType() + { + if (preg_match("/char/", $this->type)) { + return "char"; + } else if (preg_match("/^git_/", $this->type)) { + return "zval"; + } else if (preg_match("/size_t/", $this->type)) { + return "long"; + } + } + + public function __construct($type, $name) + { + $this->type = $type; + $this->name = $name; + + for ($i = 0; $i < strlen($name); $i++) { + if ($name[$i] == '*') { + $this->ptr++; + } + } + $this->name = preg_replace("/\*/", "", $this->name); + if (preg_match("/^const/", $this->type)) { + $this->const = 1; + $this->type = preg_replace("/^const\s+/", "", $this->type); + } + } +} + +class StringStream +{ + protected $buffer = ""; + + public function __construct($string = "") + { + $this->buffer = $string; + } + + public function append($string) + { + $this->buffer .= $string; + } + + public function assign($message) + { + $this->buffer = $message; + } + + public function __toString() + { + return $this->buffer; + } +} + +class ZeroCopyOutputStream +{ + protected $stream; + + public function __construct($stream) + { + $this->stream = $stream; + } + + public function write($message) + { + $this->stream->append($message); + } +} + +class Printer +{ + protected $replace; + protected $level = 0; + protected $indent_char = "\t"; + protected $stream; + + protected $next; + + public function __construct($stream, $replace) + { + $this->stream = $stream; + $this->replace = $replace; + } + + public function block(Callable $call) + { + $this->indent(); + $call($this); + $this->outdent(); + } + + public function indent() + { + $this->level++; + } + + public function outdent() + { + $this->level--; + if ($this->level < 0) { + throw new RuntimeException("too low indent level."); + } + } + + public function put($message/* $args */) + { + $args = func_get_args(); + array_shift($args); + + $key = ""; + $value = ""; + $tmp = array(); + if (count($args)) { + if (count($args) % 2 != 0) { + throw new InvalidArgumentException("parameter doesn't match"); + } + + for ($i = 0; $i < count($args); $i++) { + if ($i % 2 == 0) { + $key = $args[$i]; + } else { + $value = $args[$i]; + + $tmp[$key] = $value; + unset($key); + unset($value); + } + } + foreach ($tmp as $key => $value) { + $message = str_replace(sprintf("%s%s%s", $this->replace, $key, $this->replace), $value, $message); + } + } + + if ($this->next) { + $this->stream->write(str_repeat($this->indent_char, $this->level)); + } + + if (preg_match('/\n$/m', $message)) { + $this->next = true; + } else { + $this->next = false; + } + $this->stream->write($message); + } +} +class Fashion +{ +/* + {{{ proto resource git_revparse_single(repo, spec) + PHP_FUNCTION(git_revparse_single) + { + zval *repo; + php_git2_t *_repo; + char *spec = {0}; + int spec_len; + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse_single not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &spec, &spec_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + } + */ + public function shouldResource(Arg $arg) + { + static $types; + if (!$types) { + $types = array( + "git_repository", + "git_commit", + "git_tree", + "git_tree_entry", // really? + "git_blob", + "git_revwalk", + "git_treebuilder", + "git_reference", + "git_config", + "git_object", + "git_index", + "git_odb", + "git_refdb", + "git_status_list", + ); + } + + if (in_array($arg->getType(), $types)) { + return true; + } else { + return false; + } + } + + public function getReturnType(Func $f) + { + if ($f->isResourceCreator()) { + return "resource"; + } else { + if (preg_match("/(int|size_t)/", $f->getReturnType())) { + return "long"; + } else if (preg_match("/git/", $f->getReturnType())) { + return "resource"; + } else if (preg_match("/void/", $f->getReturnType())) { + return "void"; + } else { + error_log(sprintf("%s does not support yet", $f->getReturnType())); + } + } + } + + public function generateProto(Printer $printer, Func $f) + { + $printer->put("/* {{{ proto `return_type` `function`", + "return_type", $this->getReturnType($f), + "function", $f->getName() + ); + $printer->put("("); + $cnt = count($f->getArguments()); + $i = 0; + + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($i == 0 && $f->isResourceCreator()) { + $i++; + continue; + } + if ($arg->shouldWrite()) { + $i++; + continue; + } + + if ($this->shouldResource($arg)) { + $printer->put("resource"); + } else { + if (preg_match("/char/", $arg->getType())) { + $printer->put("string"); + } else if (preg_match("/(int|size_t)/", $arg->getType())) { + $printer->put("long"); + } else { + error_log("HOGE"); + } + } + $printer->put(" "); + + // variable name + $printer->put("\$`arg`", "arg", $arg->getName()); + if ($i +1 < $cnt) { + $printer->put(", "); + } + $i++; + } + $printer->put(")\n"); + $printer->put(" */\n"); + } + + public function isPtr(Arg $arg) + { + if (preg_match("/zval/", $arg->getZendType())) { + return "*"; + } else { + if (preg_match("/char/", $arg->getZendType())) { + return "*"; + } else { + return ""; + } + } + } + + public function generateDeclarations(Printer $printer, Func $f) + { + if ($f->isResourceCreator()) { + $printer->put("php_git2_t *result = NULL;\n"); + } else if ($f->isArrayCreator()) { + $printer->put("`type` *result = NULL;\n", "type", $f->getReturnType()); + } else if ($f->isLongCreator()) { + $printer->put("`type` result = 0;\n", "type", $f->getReturnType()); + } + + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($i == 0 && $f->isResourceCreator()) { + $printer->put("`type` `ptr``name` = NULL;\n", + "type", $arg->getType(), + "ptr", $arg->getPtr(), + "name", $arg->getName() + ); + $i++; + continue; + } + if ($arg->shouldWrite()) { + $printer->put("`type` `ptr``name` = NULL;\n", + "type", $arg->getType(), + "ptr", $arg->getPtr(), + "name", $arg->getName() + ); + } else { + /** @var Arg $arg */ + $printer->put("`type` `ptr``name` = `value`;\n", + "type", $arg->getZendType(), + "ptr", $this->isPtr($arg), + "name", $arg->getName(), + "value", $arg->getDefaultValue() + ); + if ($this->shouldResource($arg)) { + $printer->put("`type` *_`name` = NULL;\n", + "type", "php_git2_t", + "name", $arg->getName() + ); + } + + if (preg_match("/char/", $arg->getZendType())) { + $printer->put("int `name`_len = 0;\n", + "name", $arg->getName()); + } + } + + $i++; + } + if ($f->getReturnType() == "int") { + $printer->put("`type` error = 0;\n", "type", $f->getReturnType()); + } + } + + public function generateParse(Printer $printer, Func $f) + { + $printer->put("if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,\n"); + $printer->block(function(Printer $printer) use ($f) { +// $printer->put('"`specs`", `values`) == FAILURE) {', +// "specs", "s", +// "values", "&a, &a_len"); + $i = 0; + $cnt = count($f->getArguments()); + $printer->put('"'); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($i == 0 && $f->isResourceCreator()) { + $i++; + continue; + } + if ($arg->shouldWrite()) { + $i++; + continue; + } + + if (preg_match("/char/", $arg->getZendType())) { + $printer->put("s"); + } else if (preg_match("/long/", $arg->getZendType())) { + $printer->put("l"); + } else if ($this->shouldResource($arg)) { + $printer->put("r"); + } else { + $printer->put("<{$arg->getType()}>"); + } + } + $printer->put('", '); + + $i = 0; + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($i == 0 && $f->isResourceCreator()) { + $i++; + continue; + } + if ($arg->shouldWrite()) { + $i++; + continue; + } + + $printer->put("&`name`", "name", $arg->getName()); + if (preg_match("/char/", $arg->getZendType())) { + $printer->put(", "); + $printer->put("&`name`_len", "name", $arg->getName()); + } + if ($i+1 < $cnt) { + $printer->put(", "); + } + $i++; + } + + $printer->put(") == FAILURE) {\n"); + $printer->put("return;\n"); + }); + $printer->put("}\n"); + } + + public function generateFetchResourceIfNeeded(Printer $printer, Func $f) + { + $i = 0; + foreach ($f->getArguments() as $arg) { + if ($f->isResourceCreator() && $i == 0) { + $i++; + continue; + } + + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("ZEND_FETCH_RESOURCE(_`container`, php_git2_t*, &`value`, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);\n", + "container", $arg->getName(), + "value", $arg->getName() + ); + } + $i++; + } + } + + public function generateFunctionCall(Printer $printer, Func $f) + { + if ($f->getReturnType() == "int") { + $printer->put("error = `function`", + "function", $f->getName() + ); + $printer->put("("); + + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($i == 0 && $f->isResourceCreator()) { + $printer->put("&"); + } + + if ($i != 0) { + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("PHP_GIT2_V(_`name`, `type`)", + "name", $arg->getName(), + "type", $this->getNormarizedTypeName($arg) + ); + } else if ($arg->shouldWrite()) { + $printer->put("&`name`", "name", $arg->getName()); + } else { + $printer->put("`name`", "name", $arg->getName()); + } + } else { + $printer->put("`name`", "name", $arg->getName()); + } + + if ($i + 1 < $cnt) { + $printer->put(", "); + } + $i++; + } + + $printer->put(");"); + $printer->put("\n"); + } else if ($f->isResourceCreator()) { + $printer->put("`retval` = `function`", + "retval", "result", + "function", $f->getName() + ); + $printer->put("("); + + + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($i == 0 && $f->isResourceCreator()) { + $printer->put("&"); + } + + if ($i != 0) { + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("PHP_GIT2_V(_`name`, `type`)", + "name", $arg->getName(), + "type", $this->getNormarizedTypeName($arg) + ); + } else if ($arg->shouldWrite()) { + $printer->put("&`name`", "name", $arg->getName()); + } else { + $printer->put("`name`", "name", $arg->getName()); + } + } else { + $printer->put("`name`", "name", $arg->getName()); + } + + if ($i + 1 < $cnt) { + $printer->put(", "); + } + $i++; + } + $printer->put(");\n"); + } else if ($f->isArrayCreator()) { + $printer->put("result = `function`", + "function", $f->getName() + ); + $printer->put("("); + + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("PHP_GIT2_V(_`name`, `type`)", + "name", $arg->getName(), + "type", $this->getNormarizedTypeName($arg) + ); + } else if ($arg->shouldWrite()) { + $printer->put("&`name`", "name", $arg->getName()); + } else { + $printer->put("`name`", "name", $arg->getName()); + } + + if ($i + 1 < $cnt) { + $printer->put(", "); + } + $i++; + } + + $printer->put(");\n"); + $printer->put("/* TODO(chobie): implement this */\n"); + } else if ($f->isLongCreator()) { + $printer->put("result = `function`", + "function", $f->getName() + ); + $printer->put("("); + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("PHP_GIT2_V(_`name`, `type`)", + "name", $arg->getName(), + "type", $this->getNormarizedTypeName($arg) + ); + } else if ($arg->shouldWrite()) { + $printer->put("&`name`", "name", $arg->getName()); + } else { + $printer->put("`name`", "name", $arg->getName()); + } + + if ($i + 1 < $cnt) { + $printer->put(", "); + } + $i++; + } + $printer->put(");\n"); + + $printer->put("RETURN_LONG(`name`);\n", "name", "result"); + } else if ($f->isSavior()) { + + $first = $f->first(); + $printer->put("if (_`name`->should_free_v) {\n", + "name", $first->getName() + ); + $printer->block(function(Printer $printer) use ($f) { + $printer->put("`function`", + "function", $f->getName() + ); + $printer->put("("); + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("PHP_GIT2_V(_`name`, `type`)", + "name", $arg->getName(), + "type", $this->getNormarizedTypeName($arg) + ); + } else if ($arg->shouldWrite()) { + $printer->put("&`name`", "name", $arg->getName()); + } else { + $printer->put("`name`", "name", $arg->getName()); + } + + if ($i + 1 < $cnt) { + $printer->put(", "); + } + $i++; + } + $printer->put(");\n"); + + }); + $printer->put("};\n"); + + $printer->put("zval_ptr_dtor(&`name`);\n", "name", $first->getName()); + + } else { + error_log(sprintf("# %s not supported (call function)", $f->getName())); + } + } + + public function generateCheckStatementIfNeeded(Printer $printer, Func $f) + { + if ($f->getReturnType() == "int") { + $printer->put('if (php_git2_check_error(error, "`func`" TSRMLS_CC)) {', + "func", $f->getName() + ); + $printer->put("\n"); + $printer->block(function (Printer $printer) use ($f) { + $printer->put("RETURN_FALSE;\n"); + }); + $printer->put("}\n"); + } + } + + public function getNormarizedTypeName(Arg $arg) + { + $name = $arg->getType(); + return preg_replace("/^git_/", "", $name); + } + + public function generateMakeResourceIfNeeded(Printer $printer, Func $f) + { + if ($f->isResourceCreator()) { + $arg = $f->first(); + $printer->put("PHP_GIT2_MAKE_RESOURCE(result);\n"); + $printer->put("PHP_GIT2_V(result, `type`) = `variable`;\n", + "type", $this->getNormarizedTypeName($arg), + "variable", $arg->getName() + ); + $printer->put("result->type = PHP_GIT2_TYPE_`type`;\n", + "type", strtoupper($this->getNormarizedTypeName($arg)) + ); + $printer->put("result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);\n"); + $printer->put("result->should_free_v = 0;\n"); + $printer->put("ZVAL_RESOURCE(return_value, result->resource_id);\n"); + } + } + + public function out(Func $f) + { + $stream = new StringStream(); + $out = new ZeroCopyOutputStream($stream); + $printer = new Printer($out, "`"); + + $this->generateProto($printer, $f); + $printer->put("PHP_FUNCTION(`function`)\n", + "function", $f->getName()); + $printer->put("{\n"); + $printer->block(function(Printer $printer) use ($f) { + $this->generateDeclarations($printer, $f); + $printer->put("\n"); + $this->generateParse($printer, $f); + $printer->put("\n"); + + $this->generateFetchResourceIfNeeded($printer, $f); + $this->generateFunctionCall($printer, $f); + $this->generateCheckStatementIfNeeded($printer, $f); + $this->generateMakeResourceIfNeeded($printer, $f); + }); + $printer->put("}\n"); + $printer->put("/* }}} */\n"); + $printer->put("\n"); + + + return $stream->__toString(); + } +} + +$data = file_get_contents($_SERVER['argv'][1]); +$table = array(); +if (preg_match_all("/GIT_EXTERN\((.+?)\)\s*([a-zA-Z0-9_-]+)\((.+?)\);/s", $data, $match)) { + $cnt = count($match[0]); + + for ($i = 0; $i < $cnt; $i++) { + $func = new Func($match[2][$i], $match[1][$i]); + $args = explode(",", $match[3][$i]); + + foreach ($args as $arg) { + $arg = trim($arg); + $pos = strrpos($arg, " "); + $key = trim(substr($arg, $pos)); + $type = trim(substr($arg, 0, $pos)); + $func->addArgument(new Arg($type, $key)); + } + $table[$func->getName()] = $func; + } +} + +$printer = new Fashion(); +echo $printer->out($table[$_SERVER['argv'][2]]); + From 4024a382fa0994479accf2f0d3c4dfacbbbfe35d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 00:04:49 +0900 Subject: [PATCH 022/136] [git_status_list] add stub codes --- php_git2.h | 2 + status.c | 147 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 89 insertions(+), 60 deletions(-) diff --git a/php_git2.h b/php_git2.h index a562d60b5c..5433c03bc0 100644 --- a/php_git2.h +++ b/php_git2.h @@ -87,6 +87,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_INDEX, PHP_GIT2_TYPE_ODB, PHP_GIT2_TYPE_REFDB, + PHP_GIT2_TYPE_STATUS_LIST, }; typedef struct php_git2_t { @@ -105,6 +106,7 @@ typedef struct php_git2_t { git_index *index; git_odb *odb; git_refdb *refdb; + git_status_list *status_list; } v; int should_free_v; int resource_id; diff --git a/status.c b/status.c index e16d2ab457..3de69a464e 100644 --- a/status.c +++ b/status.c @@ -46,120 +46,147 @@ PHP_FUNCTION(git_status_foreach_ext) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto long git_status_file(status_flags, repo, path) -*/ +/* {{{ proto long git_status_file(resource $repo, string $path) + */ PHP_FUNCTION(git_status_file) { - long status_flags; - zval *repo; - php_git2_t *_repo; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_file not implemented yet"); - return; + unsigned int status_flags = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *path = NULL; + int path_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "lrs", &status_flags, &repo, &path, &path_len) == FAILURE) { + "rs", &repo, &path, &path_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_status_file(status_flags, PHP_GIT2_V(_repo, repository), path); + if (php_git2_check_error(error, "git_status_file" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_LONG(status_flags); } +/* }}} */ -/* {{{ proto resource git_status_list_new(repo, opts) -*/ + +/* {{{ proto resource git_status_list_new(resource $repo, $opts) + */ PHP_FUNCTION(git_status_list_new) { - zval *repo; - php_git2_t *_repo; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_status_list *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *opts = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &repo, &opts) == FAILURE) { + "rz", &repo, &opts) == FAILURE) { return; } + + /* TODO(chobie): convert arra to git_status_options */ + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_status_list_new(&out, PHP_GIT2_V(_repo, repository), opts); + if (php_git2_check_error(error, "git_status_list_new" TSRMLS_CC)) { + RETURN_FALSE; + } + + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, status_list) = out; + result->type = PHP_GIT2_TYPE_STATUS_LIST; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_status_list_entrycount(statuslist) -*/ +/* {{{ proto long git_status_list_entrycount(resource $statuslist) + */ PHP_FUNCTION(git_status_list_entrycount) { - zval *statuslist; - php_git2_t *_statuslist; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_entrycount not implemented yet"); - return; + size_t result = 0; + zval *statuslist = NULL; + php_git2_t *_statuslist = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &statuslist) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_status_list_entrycount(PHP_GIT2_V(_statuslist, status_list)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_status_byindex(statuslist, idx) -*/ +/* {{{ proto resource git_status_byindex(resource $statuslist, long $idx) + */ PHP_FUNCTION(git_status_byindex) { - zval *statuslist; - php_git2_t *_statuslist; - long idx; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_byindex not implemented yet"); - return; + const git_status_entry *result = NULL; + zval *statuslist = NULL; + php_git2_t *_statuslist = NULL; + long idx = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &statuslist, &idx) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_status_byindex(PHP_GIT2_V(_statuslist, status_list), idx); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto void git_status_list_free(statuslist) -*/ +/* {{{ proto void git_status_list_free(resource $statuslist) + */ PHP_FUNCTION(git_status_list_free) { - zval *statuslist; - php_git2_t *_statuslist; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_list_free not implemented yet"); - return; + zval *statuslist = NULL; + php_git2_t *_statuslist = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &statuslist) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_statuslist->should_free_v) { + git_status_list_free(PHP_GIT2_V(_statuslist, status_list)); + }; + zval_ptr_dtor(&statuslist); } +/* }}} */ -/* {{{ proto long git_status_should_ignore(ignored, repo, path) -*/ +/* {{{ proto long git_status_should_ignore(resource $repo, string $path) + */ PHP_FUNCTION(git_status_should_ignore) { - long ignored; - zval *repo; - php_git2_t *_repo; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_should_ignore not implemented yet"); - return; + int ignored = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *path = NULL; + int path_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "lrs", &ignored, &repo, &path, &path_len) == FAILURE) { + "rs", &repo, &path, &path_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_status_should_ignore(&ignored, PHP_GIT2_V(_repo, repository), path); + if (php_git2_check_error(error, "git_status_should_ignore" TSRMLS_CC)) { + RETURN_FALSE; + } + + RETURN_LONG(ignored); } +/* }}} */ From 3746ab1d989cd5bf6731fc20b407b9cc70a2fc4b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 01:36:47 +0900 Subject: [PATCH 023/136] ad branch and tag --- branch.c | 372 ++++++++++++++++++++++--------------- commit.c | 94 +--------- helper.c | 83 ++++++++- helper.h | 6 + ng.php | 145 +++++++++++++-- php_git2.h | 4 + reference.c | 6 +- tag.c | 527 ++++++++++++++++++++++++++++++++-------------------- 8 files changed, 774 insertions(+), 463 deletions(-) diff --git a/branch.c b/branch.c index 78bca958ba..867376f90d 100644 --- a/branch.c +++ b/branch.c @@ -2,259 +2,333 @@ #include "php_git2_priv.h" #include "branch.h" -/* {{{ proto resource git_branch_create(repo, branch_name, target, force) -*/ +/* {{{ proto resource git_branch_create(resource $repo, string $branch_name, resource $target, long $force) + */ PHP_FUNCTION(git_branch_create) { - zval *repo; - php_git2_t *_repo; - char *branch_name = {0}; - int branch_name_len; - zval *target; - php_git2_t *_target; - long force; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_create not implemented yet"); - return; + php_git2_t *result = NULL; + git_reference *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *branch_name = NULL; + int branch_name_len = 0; + zval *target = NULL; + php_git2_t *_target = NULL; + long force = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl", &repo, &branch_name, &branch_name_len, &target, &force) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_create(&out, PHP_GIT2_V(_repo, repository), branch_name, PHP_GIT2_V(_target, commit), force); + if (php_git2_check_error(error, "git_branch_create" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 1; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + -/* {{{ proto long git_branch_delete(branch) -*/ +/* {{{ proto long git_branch_delete(resource $branch) + */ PHP_FUNCTION(git_branch_delete) { - zval *branch; - php_git2_t *_branch; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_delete not implemented yet"); - return; + int result = 0; + zval *branch = NULL; + php_git2_t *_branch = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &branch) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_branch_delete(PHP_GIT2_V(_branch, reference)); + RETURN_LONG(result); } +/* }}} */ + -/* {{{ proto resource git_branch_iterator_new(repo, list_flags) -*/ +/* {{{ proto resource git_branch_iterator_new(resource $repo, $list_flags) + */ PHP_FUNCTION(git_branch_iterator_new) { - zval *repo; - php_git2_t *_repo; - zval *list_flags; - php_git2_t *_list_flags; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_iterator_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_branch_iterator *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + long list_flags = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &repo, &list_flags) == FAILURE) { + "rl", &repo, &list_flags) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_iterator_new(&out, PHP_GIT2_V(_repo, repository), list_flags); + if (php_git2_check_error(error, "git_branch_iterator_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, branch_iterator) = out; + result->type = PHP_GIT2_TYPE_BRANCH_ITERATOR; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_branch_next(out_type, iter) -*/ + +/* {{{ proto resource git_branch_next(long $out_type, resource $iter) + */ PHP_FUNCTION(git_branch_next) { - zval *out_type; - php_git2_t *_out_type; - zval *iter; - php_git2_t *_iter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_next not implemented yet"); - return; + php_git2_t *result = NULL; + git_reference *out = NULL; + long out_type = 0; + zval *iter = NULL; + php_git2_t *_iter = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &out_type, &iter) == FAILURE) { + "lr", &out_type, &iter) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_out_type, php_git2_t*, &out_type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_next(&out, out_type, PHP_GIT2_V(_iter, branch_iterator)); + if (php_git2_check_error(error, "git_branch_next" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + -/* {{{ proto void git_branch_iterator_free(iter) -*/ +/* {{{ proto void git_branch_iterator_free(resource $iter) + */ PHP_FUNCTION(git_branch_iterator_free) { - zval *iter; - php_git2_t *_iter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_iterator_free not implemented yet"); - return; + zval *iter = NULL; + php_git2_t *_iter = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &iter) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_iter->should_free_v) { + git_branch_iterator_free(PHP_GIT2_V(_iter, branch_iterator)); + }; + zval_ptr_dtor(&iter); } +/* }}} */ -/* {{{ proto resource git_branch_move(branch, new_branch_name, force) -*/ +/* {{{ proto resource git_branch_move(resource $branch, string $new_branch_name, long $force) + */ PHP_FUNCTION(git_branch_move) { - zval *branch; - php_git2_t *_branch; - char *new_branch_name = {0}; - int new_branch_name_len; - long force; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_move not implemented yet"); - return; + php_git2_t *result = NULL; + git_reference *out = NULL; + zval *branch = NULL; + php_git2_t *_branch = NULL; + char *new_branch_name = NULL; + int new_branch_name_len = 0; + long force = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &branch, &new_branch_name, &new_branch_name_len, &force) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_move(&out, PHP_GIT2_V(_branch, reference), new_branch_name, force); + if (php_git2_check_error(error, "git_branch_move" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_branch_lookup(repo, branch_name, branch_type) -*/ +/* {{{ proto resource git_branch_lookup(resource $repo, string $branch_name, long $branch_type) + */ PHP_FUNCTION(git_branch_lookup) { - zval *repo; - php_git2_t *_repo; - char *branch_name = {0}; - int branch_name_len; - zval *branch_type; - php_git2_t *_branch_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_lookup not implemented yet"); - return; + php_git2_t *result = NULL; + git_reference *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *branch_name = NULL; + int branch_name_len = 0; + long branch_type = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsr", &repo, &branch_name, &branch_name_len, &branch_type) == FAILURE) { + "rsl", &repo, &branch_name, &branch_name_len, &branch_type) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_lookup(&out, PHP_GIT2_V(_repo, repository), branch_name, branch_type); + if (php_git2_check_error(error, "git_branch_lookup" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + -/* {{{ proto resource git_branch_name(ref) -*/ +/* {{{ proto resource git_branch_name(resource $ref) + */ PHP_FUNCTION(git_branch_name) { - zval *ref; - php_git2_t *_ref; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_name not implemented yet"); - return; + php_git2_t *result = NULL; + char out[512] = {0}; + zval *ref = NULL; + php_git2_t *_ref = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_name(&out, PHP_GIT2_V(_ref, reference)); + if (php_git2_check_error(error, "git_branch_name" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(out, 1); } +/* }}} */ -/* {{{ proto resource git_branch_upstream(branch) -*/ +/* {{{ proto resource git_branch_upstream(resource $branch) + */ PHP_FUNCTION(git_branch_upstream) { - zval *branch; - php_git2_t *_branch; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_upstream not implemented yet"); - return; + php_git2_t *result = NULL; + git_reference *out = NULL; + zval *branch = NULL; + php_git2_t *_branch = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &branch) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_upstream(&out, PHP_GIT2_V(_branch, reference)); + if (php_git2_check_error(error, "git_branch_upstream" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, reference) = out; + result->type = PHP_GIT2_TYPE_REFERENCE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto long git_branch_set_upstream(branch, upstream_name) -*/ -PHP_FUNCTION(git_branch_set_upstream) +/* {{{ proto resource git_branch_upstream_name(resource $repo, string $canonical_branch_name) + */ +PHP_FUNCTION(git_branch_upstream_name) { - zval *branch; - php_git2_t *_branch; - char *upstream_name = {0}; - int upstream_name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_set_upstream not implemented yet"); - return; + php_git2_t *result = NULL; + char tracking_branch_name_out[512] = {0}; + long buffer_size = 512; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *canonical_branch_name = NULL; + int canonical_branch_name_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &branch, &upstream_name, &upstream_name_len) == FAILURE) { + "rs", &repo, &canonical_branch_name, &canonical_branch_name_len) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -} -/* {{{ proto resource git_branch_upstream_name(buffer_size, repo, canonical_branch_name) -*/ -PHP_FUNCTION(git_branch_upstream_name) -{ - zval *repo; - php_git2_t *_repo; - char *canonical_branch_name = {0}; - int canonical_branch_name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_upstream_name not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rs", &buffer_size, &repo, &canonical_branch_name, &canonical_branch_name_len) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_buffer_size, php_git2_t*, &buffer_size, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_upstream_name(&tracking_branch_name_out, buffer_size, PHP_GIT2_V(_repo, repository), canonical_branch_name); + if (php_git2_check_error(error, "git_branch_upstream_name" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(tracking_branch_name_out, 1); } +/* }}} */ -/* {{{ proto long git_branch_is_head(branch) -*/ +/* {{{ proto long git_branch_is_head(resource $branch) + */ PHP_FUNCTION(git_branch_is_head) { - zval *branch; - php_git2_t *_branch; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_is_head not implemented yet"); - return; + int result = 0; + zval *branch = NULL; + php_git2_t *_branch = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &branch) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_branch, php_git2_t*, &branch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_branch_is_head(PHP_GIT2_V(_branch, reference)); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_branch_remote_name(buffer_size, repo, canonical_branch_name) -*/ +/* {{{ proto resource git_branch_remote_name(resource $repo, string $canonical_branch_name) + */ PHP_FUNCTION(git_branch_remote_name) { - zval *repo; - php_git2_t *_repo; - char *canonical_branch_name = {0}; - int canonical_branch_name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_branch_remote_name not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rs", &buffer_size, &repo, &canonical_branch_name, &canonical_branch_name_len) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_buffer_size, php_git2_t*, &buffer_size, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -} + php_git2_t *result = NULL; + char remote_name_out[512] = {0}; + long buffer_size = 512; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *canonical_branch_name = NULL; + int canonical_branch_name_len = 0; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &canonical_branch_name, &canonical_branch_name_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_branch_remote_name(&remote_name_out, buffer_size, PHP_GIT2_V(_repo, repository), canonical_branch_name); + if (php_git2_check_error(error, "git_branch_remote_name" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(remote_name_out, 1); +} +/* }}} */ diff --git a/commit.c b/commit.c index 1116a14ff4..9458bd22e8 100644 --- a/commit.c +++ b/commit.c @@ -2,19 +2,6 @@ #include "php_git2_priv.h" #include "commit.h" -static zval* datetime_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) -{ -#if PHP_VERSION_ID <= 50304 - Z_TYPE_P(object) = IS_OBJECT; - object_init_ex(object, pce); - Z_SET_REFCOUNT_P(object, 1); - Z_UNSET_ISREF_P(object); - return object; -#else - return php_date_instantiate(pce, object TSRMLS_CC); -#endif -} - /* {{{ proto resource git_commit_lookup(resource $repository, mixed $oid) */ PHP_FUNCTION(git_commit_lookup) @@ -61,9 +48,7 @@ PHP_FUNCTION(git_commit_author) php_git2_t *git2; zval *commit; git_signature *author; - zval *result, *datetime, *timezone; - php_timezone_obj *tzobj; - char time_str[12] = {0}; + zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &commit) == FAILURE) { @@ -73,30 +58,7 @@ PHP_FUNCTION(git_commit_author) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); author = git_commit_author(PHP_GIT2_V(git2, commit)); - - MAKE_STD_ZVAL(result); - array_init(result); - - MAKE_STD_ZVAL(datetime); - MAKE_STD_ZVAL(timezone); - - datetime_instantiate(php_date_get_date_ce(), datetime TSRMLS_CC); - snprintf(time_str,12,"%c%ld",'@', author->when.time); - - datetime_instantiate(php_date_get_timezone_ce(), timezone TSRMLS_CC); - tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone TSRMLS_CC); - tzobj->initialized = 1; - tzobj->type = TIMELIB_ZONETYPE_OFFSET; - tzobj->tzi.utc_offset = -author->when.offset; /* NOTE(chobie): probably this fine */ - - php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), NULL, 0, NULL, timezone, 0 TSRMLS_CC); - - add_assoc_string_ex(result, ZEND_STRS("name"), author->name, 1); - add_assoc_string_ex(result, ZEND_STRS("email"), author->email, 1); - add_assoc_zval_ex(result, ZEND_STRS("time"), datetime); - - zval_ptr_dtor(&timezone); - + php_git2_signature_to_array(author, &result TSRMLS_CC); RETURN_ZVAL(result, 0, 1); } /* }}} */ @@ -294,9 +256,7 @@ PHP_FUNCTION(git_commit_committer) zval *commit; php_git2_t *git2; git_signature *committer; - zval *result, *datetime, *timezone; - php_timezone_obj *tzobj; - char time_str[12] = {0}; + zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &commit) == FAILURE) { @@ -305,30 +265,7 @@ PHP_FUNCTION(git_commit_committer) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); committer = git_commit_committer(PHP_GIT2_V(git2, commit)); - - MAKE_STD_ZVAL(result); - array_init(result); - - MAKE_STD_ZVAL(datetime); - MAKE_STD_ZVAL(timezone); - - datetime_instantiate(php_date_get_date_ce(), datetime TSRMLS_CC); - snprintf(time_str,12,"%c%ld",'@', committer->when.time); - - datetime_instantiate(php_date_get_timezone_ce(), timezone TSRMLS_CC); - tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone TSRMLS_CC); - tzobj->initialized = 1; - tzobj->type = TIMELIB_ZONETYPE_OFFSET; - tzobj->tzi.utc_offset = -committer->when.offset; /* NOTE(chobie): probably this fine */ - - php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), NULL, 0, NULL, timezone, 0 TSRMLS_CC); - - add_assoc_string_ex(result, ZEND_STRS("name"), committer->name, 1); - add_assoc_string_ex(result, ZEND_STRS("email"), committer->email, 1); - add_assoc_zval_ex(result, ZEND_STRS("time"), datetime); - - zval_ptr_dtor(&timezone); - + php_git2_signature_to_array(committer, &result TSRMLS_CC); RETURN_ZVAL(result, 0, 1); } @@ -469,29 +406,6 @@ PHP_FUNCTION(git_commit_nth_gen_ancestor) } -static void php_git2_array_to_signature(git_signature *signature, zval *author TSRMLS_DC) -{ - zval *name = NULL, *email = NULL, *time = NULL; - - name = php_git2_read_arrval(author, ZEND_STRS("name") TSRMLS_CC); - email = php_git2_read_arrval(author, ZEND_STRS("email") TSRMLS_CC); - time = php_git2_read_arrval(author, ZEND_STRS("time") TSRMLS_CC); - - signature->name = Z_STRVAL_P(name); - signature->email = Z_STRVAL_P(email); - - //instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only TSRMLS_DC); - if (time != NULL && - Z_TYPE_P(time) == IS_OBJECT && - instanceof_function_ex(Z_OBJCE_P(time), php_date_get_date_ce(), 0 TSRMLS_CC)) { - php_date_obj *date; - - date = (php_date_obj *)zend_object_store_get_object(time TSRMLS_CC); - signature->when.time = date->time->sse; - signature->when.offset = date->time->z; - } -} - /* {{{ proto resource git_commit_create( resource $repo, string $update_ref, array $author, array $committer, string $message_encoding, string $message, resource $tree, array $parents) diff --git a/helper.c b/helper.c index ec53e07066..fd7c23d27d 100644 --- a/helper.c +++ b/helper.c @@ -1,6 +1,19 @@ #include "php_git2.h" #include "helper.h" +static zval* datetime_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) +{ +#if PHP_VERSION_ID <= 50304 + Z_TYPE_P(object) = IS_OBJECT; + object_init_ex(object, pce); + Z_SET_REFCOUNT_P(object, 1); + Z_UNSET_ISREF_P(object); + return object; +#else + return php_date_instantiate(pce, object TSRMLS_CC); +#endif +} + int php_git2_check_error(int error_code, const char *action TSRMLS_DC) { int result = 0; @@ -53,4 +66,72 @@ const char* php_git2_read_arrval_string(zval *array, char *name, size_t name_len } return result; -} \ No newline at end of file +} + +void php_git2_array_to_signature(git_signature *signature, zval *author TSRMLS_DC) +{ + zval *name = NULL, *email = NULL, *time = NULL; + + name = php_git2_read_arrval(author, ZEND_STRS("name") TSRMLS_CC); + email = php_git2_read_arrval(author, ZEND_STRS("email") TSRMLS_CC); + time = php_git2_read_arrval(author, ZEND_STRS("time") TSRMLS_CC); + + signature->name = Z_STRVAL_P(name); + signature->email = Z_STRVAL_P(email); + + //instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool interfaces_only TSRMLS_DC); + if (time != NULL && + Z_TYPE_P(time) == IS_OBJECT && + instanceof_function_ex(Z_OBJCE_P(time), php_date_get_date_ce(), 0 TSRMLS_CC)) { + php_date_obj *date; + + date = (php_date_obj *)zend_object_store_get_object(time TSRMLS_CC); + signature->when.time = date->time->sse; + signature->when.offset = date->time->z; + } +} + +void php_git2_signature_to_array(const git_signature *signature, zval **out TSRMLS_DC) +{ + zval *result, *datetime, *timezone; + php_timezone_obj *tzobj; + char time_str[12] = {0}; + + MAKE_STD_ZVAL(result); + array_init(result); + + MAKE_STD_ZVAL(datetime); + MAKE_STD_ZVAL(timezone); + + datetime_instantiate(php_date_get_date_ce(), datetime TSRMLS_CC); + snprintf(time_str,12,"%c%ld",'@', signature->when.time); + + datetime_instantiate(php_date_get_timezone_ce(), timezone TSRMLS_CC); + tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone TSRMLS_CC); + tzobj->initialized = 1; + tzobj->type = TIMELIB_ZONETYPE_OFFSET; + tzobj->tzi.utc_offset = -signature->when.offset; /* NOTE(chobie): probably this fine */ + + php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), NULL, 0, NULL, timezone, 0 TSRMLS_CC); + + add_assoc_string_ex(result, ZEND_STRS("name"), signature->name, 1); + add_assoc_string_ex(result, ZEND_STRS("email"), signature->email, 1); + add_assoc_zval_ex(result, ZEND_STRS("time"), datetime); + + zval_ptr_dtor(&timezone); + + *out = result; +} + +void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC) +{ + zval *result; + int i = 0; + + MAKE_STD_ZVAL(result); + array_init(result); + for (i = 0; i < array->count; i++) { + add_next_index_string(result, array->strings[i], 1); + } + *out = result; +} diff --git a/helper.h b/helper.h index 6132ba02ea..f65caa0d7e 100644 --- a/helper.h +++ b/helper.h @@ -36,4 +36,10 @@ long php_git2_read_arrval_long(zval *array, char *name, size_t name_len TSRMLS_D const char* php_git2_read_arrval_string(zval *array, char *name, size_t name_len TSRMLS_DC); +void php_git2_array_to_signature(git_signature *signature, zval *author TSRMLS_DC); + +void php_git2_signature_to_array(const git_signature *signature, zval **out TSRMLS_DC); + +void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC); + #endif \ No newline at end of file diff --git a/ng.php b/ng.php index 44a3fd534c..aab544b183 100644 --- a/ng.php +++ b/ng.php @@ -45,12 +45,20 @@ public function isResourceCreator() return true; } } + return false; } + public function isStringCreator() + { + if (preg_match("/(char)/", $this->getReturnType())) { + return true; + } + } + public function isLongCreator() { - if (preg_match("/size_t/", $this->getReturnType())) { + if (preg_match("/(size_t|int)/", $this->getReturnType())) { return true; } } @@ -111,6 +119,12 @@ public function getName() return $this->name; } + public function setName($name) + { + return $this->name = $name; + } + + public function getType() { return $this->type; @@ -137,10 +151,14 @@ public function getZendType() { if (preg_match("/char/", $this->type)) { return "char"; + } else if (preg_match("/(size_t|int)/", $this->type)) { + return "long"; + } else if (preg_match("/git_oid/", $this->type)) { + return "char"; } else if (preg_match("/^git_/", $this->type)) { return "zval"; - } else if (preg_match("/size_t/", $this->type)) { - return "long"; + } else { + error_log(sprintf("%s (zendtype)", $this->type)); } } @@ -318,6 +336,8 @@ public function shouldResource(Arg $arg) "git_odb", "git_refdb", "git_status_list", + "git_branch_iterator", + "git_tag", ); } @@ -335,10 +355,14 @@ public function getReturnType(Func $f) } else { if (preg_match("/(int|size_t)/", $f->getReturnType())) { return "long"; + } else if (preg_match("/git_signature/", $f->getReturnType())) { + return "array"; } else if (preg_match("/git/", $f->getReturnType())) { return "resource"; } else if (preg_match("/void/", $f->getReturnType())) { return "void"; + } else if (preg_match("/char/", $f->getReturnType())) { + return "string"; } else { error_log(sprintf("%s does not support yet", $f->getReturnType())); } @@ -373,8 +397,14 @@ public function generateProto(Printer $printer, Func $f) $printer->put("string"); } else if (preg_match("/(int|size_t)/", $arg->getType())) { $printer->put("long"); + } else if (preg_match("/(git_oid)/", $arg->getType())) { + $printer->put("string"); + } else if (preg_match("/(git_signature)/", $arg->getType())) { + $printer->put("array"); + } else if (preg_match("/(git_strarray)/", $arg->getType())) { + $printer->put("array"); } else { - error_log("HOGE"); + error_log(sprintf("# unknown type (%s)", $arg->getType())); } } $printer->put(" "); @@ -409,8 +439,13 @@ public function generateDeclarations(Printer $printer, Func $f) $printer->put("php_git2_t *result = NULL;\n"); } else if ($f->isArrayCreator()) { $printer->put("`type` *result = NULL;\n", "type", $f->getReturnType()); + if (preg_match("/git_signature/", $f->getReturnType())) { + $printer->put("zval *__result = NULL;\n"); + } } else if ($f->isLongCreator()) { $printer->put("`type` result = 0;\n", "type", $f->getReturnType()); + } else if ($f->isStringCreator()) { + $printer->put("`type` *result = NULL;\n", "type", $f->getReturnType()); } $i = 0; @@ -453,20 +488,27 @@ public function generateDeclarations(Printer $printer, Func $f) } } + if ($arg->getType() == "git_oid") { + $printer->put("git_oid __`name`;\n", "name", $arg->getName()); + } + $i++; } if ($f->getReturnType() == "int") { $printer->put("`type` error = 0;\n", "type", $f->getReturnType()); } + if (preg_match("/git_oid/", $f->getReturnType())) { + $printer->put("char __result[41] = {0};\n"); + } + if (preg_match("/_owner$/", $f->getName())) { + $printer->put("php_git2_t *__result = NULL;\n"); + } } public function generateParse(Printer $printer, Func $f) { $printer->put("if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,\n"); $printer->block(function(Printer $printer) use ($f) { -// $printer->put('"`specs`", `values`) == FAILURE) {', -// "specs", "s", -// "values", "&a, &a_len"); $i = 0; $cnt = count($f->getArguments()); $printer->put('"'); @@ -485,6 +527,8 @@ public function generateParse(Printer $printer, Func $f) $printer->put("s"); } else if (preg_match("/long/", $arg->getZendType())) { $printer->put("l"); + } else if (preg_match("/git_signature/", $arg->getType())) { + $printer->put("a"); } else if ($this->shouldResource($arg)) { $printer->put("r"); } else { @@ -541,9 +585,27 @@ public function generateFetchResourceIfNeeded(Printer $printer, Func $f) } } + public function generateOidTranslation(Printer $printer, Func $f) + { + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($arg->getType() == "git_oid") { + $printer->put("if (git_oid_fromstrn(&__`name`, `name`, `name`_len)) {\n", + "name", $arg->getName() + ); + $printer->block(function(Printer $printer) use($arg) { + $printer->put("RETURN_FALSE;\n"); + }); + $printer->put("}\n"); + $arg->setName("__" . $arg->getName()); + } + } + } + public function generateFunctionCall(Printer $printer, Func $f) { - if ($f->getReturnType() == "int") { + $this->generateOidTranslation($printer, $f); + if ($f->getReturnType() == "int" && $f->isResourceCreator()) { $printer->put("error = `function`", "function", $f->getName() ); @@ -646,7 +708,19 @@ public function generateFunctionCall(Printer $printer, Func $f) } $printer->put(");\n"); - $printer->put("/* TODO(chobie): implement this */\n"); + if (preg_match("/git_oid/", $f->getReturnType())) { + $printer->put("git_oid_fmt(__result, `name`);\n", "name", "result"); + $printer->put("RETURN_STRING(__result, 1);\n"); + } else if (preg_match("/_owner$/", $f->getName())) { + $this->generateMakeResourceIfNeeded($printer, $f, "__result", 1); + } else if (preg_match("/_type/", $f->getName())) { + $printer->put("RETURN_LONG(`name`);\n", "name", "result"); + } else if (preg_match("/git_signature/", $f->getReturnType())) { + $printer->put("php_git2_signature_to_array(result, &__result TSRMLS_CC);\n"); + $printer->put("RETURN_ZVAL(__result, 0, 1);\n"); + } else { + $printer->put("/* TODO(chobie): implement this */\n"); + } } else if ($f->isLongCreator()) { $printer->put("result = `function`", "function", $f->getName() @@ -675,7 +749,11 @@ public function generateFunctionCall(Printer $printer, Func $f) } $printer->put(");\n"); - $printer->put("RETURN_LONG(`name`);\n", "name", "result"); + if (preg_match("/_is_/", $f->getName())) { + $printer->put("RETURN_BOOL(`name`);\n", "name", "result"); + } else { + $printer->put("RETURN_LONG(`name`);\n", "name", "result"); + } } else if ($f->isSavior()) { $first = $f->first(); @@ -714,7 +792,34 @@ public function generateFunctionCall(Printer $printer, Func $f) $printer->put("};\n"); $printer->put("zval_ptr_dtor(&`name`);\n", "name", $first->getName()); + } else if ($f->isStringCreator()) { + $printer->put("result = `function`", + "function", $f->getName() + ); + $printer->put("("); + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("PHP_GIT2_V(_`name`, `type`)", + "name", $arg->getName(), + "type", $this->getNormarizedTypeName($arg) + ); + } else if ($arg->shouldWrite()) { + $printer->put("&`name`", "name", $arg->getName()); + } else { + $printer->put("`name`", "name", $arg->getName()); + } + if ($i + 1 < $cnt) { + $printer->put(", "); + } + $i++; + } + $printer->put(");\n"); + $printer->put("RETURN_STRING(`name`, 1);\n", "name", "result"); } else { error_log(sprintf("# %s not supported (call function)", $f->getName())); } @@ -722,7 +827,7 @@ public function generateFunctionCall(Printer $printer, Func $f) public function generateCheckStatementIfNeeded(Printer $printer, Func $f) { - if ($f->getReturnType() == "int") { + if ($f->getReturnType() == "int" && $f->isResourceCreator()) { $printer->put('if (php_git2_check_error(error, "`func`" TSRMLS_CC)) {', "func", $f->getName() ); @@ -740,21 +845,23 @@ public function getNormarizedTypeName(Arg $arg) return preg_replace("/^git_/", "", $name); } - public function generateMakeResourceIfNeeded(Printer $printer, Func $f) + public function generateMakeResourceIfNeeded(Printer $printer, Func $f, $name = "result", $force = 0) { - if ($f->isResourceCreator()) { + if ($f->isResourceCreator() || $force) { $arg = $f->first(); - $printer->put("PHP_GIT2_MAKE_RESOURCE(result);\n"); - $printer->put("PHP_GIT2_V(result, `type`) = `variable`;\n", + $printer->put("PHP_GIT2_MAKE_RESOURCE(`name`);\n", "name", $name); + $printer->put("PHP_GIT2_V(`name`, `type`) = `variable`;\n", + "name", $name, "type", $this->getNormarizedTypeName($arg), "variable", $arg->getName() ); - $printer->put("result->type = PHP_GIT2_TYPE_`type`;\n", + $printer->put("`name`->type = PHP_GIT2_TYPE_`type`;\n", + "name", $name, "type", strtoupper($this->getNormarizedTypeName($arg)) ); - $printer->put("result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);\n"); - $printer->put("result->should_free_v = 0;\n"); - $printer->put("ZVAL_RESOURCE(return_value, result->resource_id);\n"); + $printer->put("`name`->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);\n", "name", $name); + $printer->put("`name`->should_free_v = 0;\n", "name", $name); + $printer->put("ZVAL_RESOURCE(return_value, `name`->resource_id);\n", "name", $name); } } diff --git a/php_git2.h b/php_git2.h index 5433c03bc0..12521622b9 100644 --- a/php_git2.h +++ b/php_git2.h @@ -88,6 +88,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_ODB, PHP_GIT2_TYPE_REFDB, PHP_GIT2_TYPE_STATUS_LIST, + PHP_GIT2_TYPE_BRANCH_ITERATOR, + PHP_GIT2_TYPE_TAG, }; typedef struct php_git2_t { @@ -107,6 +109,8 @@ typedef struct php_git2_t { git_odb *odb; git_refdb *refdb; git_status_list *status_list; + git_branch_iterator *branch_iterator; + git_tag *tag; } v; int should_free_v; int resource_id; diff --git a/reference.c b/reference.c index 99447eee68..bebefecd64 100644 --- a/reference.c +++ b/reference.c @@ -451,11 +451,7 @@ PHP_FUNCTION(git_reference_list) RETURN_FALSE } - MAKE_STD_ZVAL(result); - array_init(result); - for (i = 0; i < list.count; i++) { - add_next_index_string(result, list.strings[i], 1); - } + php_git2_strarray_to_array(&list, &result TSRMLS_CC); git_strarray_free(&list); RETURN_ZVAL(result, 0, 1); diff --git a/tag.c b/tag.c index 4e8d9542b7..80b4b584e2 100644 --- a/tag.c +++ b/tag.c @@ -2,366 +2,485 @@ #include "php_git2_priv.h" #include "tag.h" -/* {{{ proto resource git_tag_lookup(repo, id) -*/ +/* {{{ proto resource git_tag_lookup(resource $repo, string $id) + */ PHP_FUNCTION(git_tag_lookup) { - zval *repo; - php_git2_t *_repo; - char *id = {0}; - int id_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_lookup not implemented yet"); - return; + php_git2_t *result = NULL; + git_tag *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *id = NULL; + int id_len = 0; + git_oid __id; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &id, &id_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + error = git_tag_lookup(&out, PHP_GIT2_V(_repo, repository), &__id); + if (php_git2_check_error(error, "git_tag_lookup" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, tag) = out; + result->type = PHP_GIT2_TYPE_TAG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_tag_lookup_prefix(repo, id, len) -*/ + +/* {{{ proto resource git_tag_lookup_prefix(resource $repo, string $id) + */ PHP_FUNCTION(git_tag_lookup_prefix) { - zval *repo; - php_git2_t *_repo; - char *id = {0}; - int id_len; + php_git2_t *result = NULL; + git_tag *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *id = NULL; + int id_len = 0; + git_oid __id; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_lookup_prefix not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &repo, &id, &id_len) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rs", &repo, &id, &id_len, &len) == FAILURE) { -// return; -// } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + error = git_tag_lookup_prefix(&out, PHP_GIT2_V(_repo, repository), &__id, id_len); + if (php_git2_check_error(error, "git_tag_lookup_prefix" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, tag) = out; + result->type = PHP_GIT2_TYPE_TAG; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto void git_tag_free(tag) -*/ +/* {{{ proto void git_tag_free(resource $tag) + */ PHP_FUNCTION(git_tag_free) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_free not implemented yet"); - return; + zval *tag = NULL; + php_git2_t *_tag = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_tag->should_free_v) { + git_tag_free(PHP_GIT2_V(_tag, tag)); + }; + zval_ptr_dtor(&tag); } +/* }}} */ -/* {{{ proto resource git_tag_id(tag) -*/ +/* {{{ proto resource git_tag_id(resource $tag) + */ PHP_FUNCTION(git_tag_id) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_id not implemented yet"); - return; + const git_oid *result = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; + char __result[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_id(PHP_GIT2_V(_tag, tag)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); } +/* }}} */ -/* {{{ proto resource git_tag_owner(tag) -*/ +/* {{{ proto resource git_tag_owner(resource $tag) + */ PHP_FUNCTION(git_tag_owner) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_owner not implemented yet"); - return; + git_repository *result = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; + php_git2_t *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_owner(PHP_GIT2_V(_tag, tag)); + PHP_GIT2_MAKE_RESOURCE(__result); + PHP_GIT2_V(__result, tag) = tag; + __result->type = PHP_GIT2_TYPE_TAG; + __result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + __result->should_free_v = 0; + ZVAL_RESOURCE(return_value, __result->resource_id); } +/* }}} */ -/* {{{ proto resource git_tag_target(tag) -*/ +/* {{{ proto resource git_tag_target(resource $tag) + */ PHP_FUNCTION(git_tag_target) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_target not implemented yet"); - return; + php_git2_t *result = NULL; + git_object *target_out = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_tag_target(&target_out, PHP_GIT2_V(_tag, tag)); + if (php_git2_check_error(error, "git_tag_target" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, object) = target_out; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_tag_target_id(tag) -*/ +/* {{{ proto resource git_tag_target_id(resource $tag) + */ PHP_FUNCTION(git_tag_target_id) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_target_id not implemented yet"); - return; + const git_oid *result = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; + char __result[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_target_id(PHP_GIT2_V(_tag, tag)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); } +/* }}} */ -/* {{{ proto resource git_tag_target_type(tag) -*/ +/* {{{ proto resource git_tag_target_type(resource $tag) + */ PHP_FUNCTION(git_tag_target_type) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_target_type not implemented yet"); - return; + git_otype *result = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_target_type(PHP_GIT2_V(_tag, tag)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_tag_name(tag) -*/ +/* {{{ proto string git_tag_name(resource $tag) + */ PHP_FUNCTION(git_tag_name) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_name not implemented yet"); - return; + const char *result = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_name(PHP_GIT2_V(_tag, tag)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_tag_tagger(tag) -*/ +/* {{{ proto array git_tag_tagger(resource $tag) + */ PHP_FUNCTION(git_tag_tagger) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_tagger not implemented yet"); - return; + const git_signature *result = NULL; + zval *__result = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_tagger(PHP_GIT2_V(_tag, tag)); + php_git2_signature_to_array(result, &__result TSRMLS_CC); + RETURN_ZVAL(__result, 0, 1); } +/* }}} */ -/* {{{ proto resource git_tag_message(tag) -*/ +/* {{{ proto string git_tag_message(resource $tag) + */ PHP_FUNCTION(git_tag_message) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_message not implemented yet"); - return; + const char *result = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_message(PHP_GIT2_V(_tag, tag)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_tag_create(repo, tag_name, target, tagger, message, force) -*/ +/* {{{ proto string git_tag_create(resource $repo, string $tag_name, resource $target, array $tagger, string $message, long $force) + */ PHP_FUNCTION(git_tag_create) { - zval *repo; - php_git2_t *_repo; - char *tag_name = {0}; - int tag_name_len; - zval *target; - php_git2_t *_target; - zval *tagger; - php_git2_t *_tagger; - char *message = {0}; - int message_len; - long force; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_create not implemented yet"); - return; + int result = 0; + git_oid __oid; + zval *repo = NULL; + php_git2_t *_repo = NULL, *out = NULL; + char *tag_name = NULL; + int tag_name_len = 0; + zval *target = NULL; + php_git2_t *_target = NULL; + zval *tagger = NULL; + char *message = NULL; + int message_len = 0; + long force = 0; + int error = 0; + char buffer[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsrrsl", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len, &force) == FAILURE) { + "rsrasl", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len, &force) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_create(&__oid, PHP_GIT2_V(_repo, repository), tag_name, PHP_GIT2_V(_target, object), tagger, message, force); + if (php_git2_check_error(result, "git_tag_create" TSRMLS_CC)) { + RETURN_FALSE + } + git_oid_fmt(buffer, &__oid); + RETURN_STRING(buffer, 1); + } +/* }}} */ -/* {{{ proto resource git_tag_annotation_create(repo, tag_name, target, tagger, message) -*/ + +/* {{{ proto string git_tag_annotation_create(resource $repo, string $tag_name, resource $target, array $tagger, string $message) + */ PHP_FUNCTION(git_tag_annotation_create) { - zval *repo; - php_git2_t *_repo; - char *tag_name = {0}; - int tag_name_len; - zval *target; - php_git2_t *_target; - zval *tagger; - php_git2_t *_tagger; - char *message = {0}; - int message_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_annotation_create not implemented yet"); - return; + int result = 0; + git_oid __oid; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *tag_name = NULL; + int tag_name_len = 0; + zval *target = NULL; + php_git2_t *_target = NULL; + zval *tagger = NULL; + char *message = NULL; + int message_len = 0; + int error = 0; + char buffer[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsrrs", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len) == FAILURE) { + "rsras", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_annotation_create(&__oid, PHP_GIT2_V(_repo, repository), tag_name, PHP_GIT2_V(_target, object), tagger, message); + if (php_git2_check_error(result, "git_tag_annotation_create" TSRMLS_CC)) { + RETURN_FALSE + } + git_oid_fmt(buffer, &__oid); + RETURN_STRING(buffer, 1); + } +/* }}} */ -/* {{{ proto resource git_tag_create_frombuffer(repo, buffer, force) -*/ +/* {{{ proto string git_tag_create_frombuffer(resource $repo, string $buffer, long $force) + */ PHP_FUNCTION(git_tag_create_frombuffer) { - zval *repo; - php_git2_t *_repo; - char *buffer = {0}; - int buffer_len; - long force; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_create_frombuffer not implemented yet"); - return; + int result = 0; + git_oid __oid; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *buffer = NULL; + int buffer_len = 0; + long force = 0; + int error = 0; + char oid[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &repo, &buffer, &buffer_len, &force) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_create_frombuffer(&__oid, PHP_GIT2_V(_repo, repository), buffer, force); + if (php_git2_check_error(result, "git_tag_create_frombuffer" TSRMLS_CC)) { + RETURN_FALSE + } + git_oid_fmt(oid, &__oid); + RETURN_STRING(oid, 1); } +/* }}} */ -/* {{{ proto resource git_tag_create_lightweight(repo, tag_name, target, force) -*/ + +/* {{{ proto string git_tag_create_lightweight(resource $repo, string $tag_name, resource $target, long $force) + */ PHP_FUNCTION(git_tag_create_lightweight) { - zval *repo; - php_git2_t *_repo; - char *tag_name = {0}; - int tag_name_len; - zval *target; - php_git2_t *_target; - long force; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_create_lightweight not implemented yet"); - return; + int result = 0; + git_oid __oid; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *tag_name = NULL; + int tag_name_len = 0; + zval *target = NULL; + php_git2_t *_target = NULL; + long force = 0; + int error = 0; + char oid[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl", &repo, &tag_name, &tag_name_len, &target, &force) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_create_lightweight(&__oid, PHP_GIT2_V(_repo, repository), tag_name, PHP_GIT2_V(_target, object), force); + if (php_git2_check_error(result, "git_tag_create_lightweight" TSRMLS_CC)) { + RETURN_FALSE + } + git_oid_fmt(oid, &__oid); + RETURN_STRING(oid, 1); } +/* }}} */ -/* {{{ proto long git_tag_delete(repo, tag_name) -*/ + +/* {{{ proto long git_tag_delete(resource $repo, string $tag_name) + */ PHP_FUNCTION(git_tag_delete) { - zval *repo; - php_git2_t *_repo; - char *tag_name = {0}; - int tag_name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_delete not implemented yet"); - return; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *tag_name = NULL; + int tag_name_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &tag_name, &tag_name_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tag_delete(PHP_GIT2_V(_repo, repository), tag_name); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_tag_list(tag_names, repo) -*/ + +/* {{{ proto long git_tag_list(resource $repo) + */ PHP_FUNCTION(git_tag_list) { - zval *tag_names; - php_git2_t *_tag_names; - zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_list not implemented yet"); - return; + int error = 0; + git_strarray tag_names = {0}; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &tag_names, &repo) == FAILURE) { + "r", &repo) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_tag_names, php_git2_t*, &tag_names, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_tag_list(&tag_names, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_tag_list" TSRMLS_CC)) { + RETURN_FALSE + } + php_git2_strarray_to_array(&tag_names, &result TSRMLS_CC); + git_strarray_free(&tag_names); + RETURN_ZVAL(result, 0, 1); } +/* }}} */ -/* {{{ proto long git_tag_list_match(tag_names, pattern, repo) -*/ + +/* {{{ proto long git_tag_list_match(string $pattern, resource $repo) + */ PHP_FUNCTION(git_tag_list_match) { - zval *tag_names; - php_git2_t *_tag_names; - char *pattern = {0}; - int pattern_len; - zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_list_match not implemented yet"); - return; + zval *result; + git_strarray tag_names = {0}; + char *pattern = NULL; + int pattern_len = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsr", &tag_names, &pattern, &pattern_len, &repo) == FAILURE) { + "sr", &pattern, &pattern_len, &repo) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_tag_names, php_git2_t*, &tag_names, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_tag_list_match(&tag_names, pattern, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_tag_list_match" TSRMLS_CC)) { + RETURN_FALSE + } + php_git2_strarray_to_array(&tag_names, &result TSRMLS_CC); + git_strarray_free(&tag_names); + RETURN_ZVAL(result, 0, 1); + } +/* }}} */ + /* {{{ proto long git_tag_foreach(repo, callback, payload) */ @@ -384,21 +503,31 @@ PHP_FUNCTION(git_tag_foreach) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto resource git_tag_peel(tag) -*/ +/* {{{ proto resource git_tag_peel(resource $tag) + */ PHP_FUNCTION(git_tag_peel) { - zval *tag; - php_git2_t *_tag; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_peel not implemented yet"); - return; + php_git2_t *result = NULL; + git_object *tag_target_out = NULL; + zval *tag = NULL; + php_git2_t *_tag = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_tag_peel(&tag_target_out, PHP_GIT2_V(_tag, tag)); + if (php_git2_check_error(error, "git_tag_peel" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, object) = tag_target_out; + result->type = PHP_GIT2_TYPE_OBJECT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } - +/* }}} */ From 0fbb04dfd860f4fb546d99167f4a43efee76cc39 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 02:11:19 +0900 Subject: [PATCH 024/136] [remote] add stubs --- cred.c | 114 ++++--- ng.php | 37 +++ php_git2.h | 6 + remote.c | 858 ++++++++++++++++++++++++++++++---------------------- transport.c | 31 +- 5 files changed, 634 insertions(+), 412 deletions(-) diff --git a/cred.c b/cred.c index be9f0260ba..57ae1fb757 100644 --- a/cred.c +++ b/cred.c @@ -2,65 +2,90 @@ #include "php_git2_priv.h" #include "cred.h" -/* {{{ proto long git_cred_has_username(cred) -*/ +/* {{{ proto long git_cred_has_username(resource $cred) + */ PHP_FUNCTION(git_cred_has_username) { - zval *cred; - php_git2_t *_cred; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_has_username not implemented yet"); - return; + int result = 0; + zval *cred = NULL; + php_git2_t *_cred = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &cred) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cred, php_git2_t*, &cred, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_cred_has_username(PHP_GIT2_V(_cred, cred)); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_cred_userpass_plaintext_new(username, password) -*/ +/* {{{ proto resource git_cred_userpass_plaintext_new(string $username, string $password) + */ PHP_FUNCTION(git_cred_userpass_plaintext_new) { - char *username = {0}; - int username_len; - char *password = {0}; - int password_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_userpass_plaintext_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_cred *out = NULL; + char *username = NULL; + int username_len = 0; + char *password = NULL; + int password_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &username, &username_len, &password, &password_len) == FAILURE) { return; } + + error = git_cred_userpass_plaintext_new(&out, username, password); + if (php_git2_check_error(error, "git_cred_userpass_plaintext_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, cred) = out; + result->type = PHP_GIT2_TYPE_CRED; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_cred_ssh_key_new(username, publickey, privatekey, passphrase) -*/ +/* {{{ proto resource git_cred_ssh_key_new(string $username, string $publickey, string $privatekey, string $passphrase) + */ PHP_FUNCTION(git_cred_ssh_key_new) { - char *username = {0}; - int username_len; - char *publickey = {0}; - int publickey_len; - char *privatekey = {0}; - int privatekey_len; - char *passphrase = {0}; - int passphrase_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_ssh_key_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_cred *out = NULL; + char *username = NULL; + int username_len = 0; + char *publickey = NULL; + int publickey_len = 0; + char *privatekey = NULL; + int privatekey_len = 0; + char *passphrase = NULL; + int passphrase_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &username, &username_len, &publickey, &publickey_len, &privatekey, &privatekey_len, &passphrase, &passphrase_len) == FAILURE) { return; } + + error = git_cred_ssh_key_new(&out, username, publickey, privatekey, passphrase); + if (php_git2_check_error(error, "git_cred_ssh_key_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, cred) = out; + result->type = PHP_GIT2_TYPE_CRED; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + /* {{{ proto resource git_cred_ssh_custom_new(username, publickey, publickey_len, sign_fn, sign_data) */ @@ -85,19 +110,26 @@ PHP_FUNCTION(git_cred_ssh_custom_new) } /* {{{ proto resource git_cred_default_new() -*/ + */ PHP_FUNCTION(git_cred_default_new) { + php_git2_t *result = NULL; + git_cred *out = NULL; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_default_new not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "", ) == FAILURE) { -// return; -// } + error = git_cred_default_new(&out); + if (php_git2_check_error(error, "git_cred_default_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, cred) = out; + result->type = PHP_GIT2_TYPE_CRED; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + /* {{{ proto resource git_cred_userpass(url, user_from_url, allowed_types, payload) */ diff --git a/ng.php b/ng.php index aab544b183..99e69e1448 100644 --- a/ng.php +++ b/ng.php @@ -70,6 +70,13 @@ public function isArrayCreator() } } + public function isVoidCreator() + { + if (preg_match("/void/", $this->getReturnType())) { + return true; + } + } + public function isSavior() { if (preg_match('/_free$/', $this->getName())) { @@ -338,6 +345,9 @@ public function shouldResource(Arg $arg) "git_status_list", "git_branch_iterator", "git_tag", + "git_cred", + "git_transport", + "git_remote", ); } @@ -820,6 +830,33 @@ public function generateFunctionCall(Printer $printer, Func $f) } $printer->put(");\n"); $printer->put("RETURN_STRING(`name`, 1);\n", "name", "result"); + } else if ($f->isVoidCreator()) { + $printer->put("`function`", + "function", $f->getName() + ); + $printer->put("("); + $i = 0; + $cnt = count($f->getArguments()); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + + if ($this->shouldResource($arg) && !$arg->shouldWrite()) { + $printer->put("PHP_GIT2_V(_`name`, `type`)", + "name", $arg->getName(), + "type", $this->getNormarizedTypeName($arg) + ); + } else if ($arg->shouldWrite()) { + $printer->put("&`name`", "name", $arg->getName()); + } else { + $printer->put("`name`", "name", $arg->getName()); + } + + if ($i + 1 < $cnt) { + $printer->put(", "); + } + $i++; + } + $printer->put(");\n"); } else { error_log(sprintf("# %s not supported (call function)", $f->getName())); } diff --git a/php_git2.h b/php_git2.h index 12521622b9..2884f72663 100644 --- a/php_git2.h +++ b/php_git2.h @@ -90,6 +90,9 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_STATUS_LIST, PHP_GIT2_TYPE_BRANCH_ITERATOR, PHP_GIT2_TYPE_TAG, + PHP_GIT2_TYPE_CRED, + PHP_GIT2_TYPE_TRANSPORT, + PHP_GIT2_TYPE_REMOTE, }; typedef struct php_git2_t { @@ -111,6 +114,9 @@ typedef struct php_git2_t { git_status_list *status_list; git_branch_iterator *branch_iterator; git_tag *tag; + git_cred *cred; + git_transport *transport; + git_remote *remote; } v; int should_free_v; int resource_id; diff --git a/remote.c b/remote.c index 6aa1fd6952..e03bcd5d58 100644 --- a/remote.c +++ b/remote.c @@ -2,652 +2,783 @@ #include "php_git2_priv.h" #include "remote.h" -/* {{{ proto resource git_remote_create(repo, name, url) -*/ +/* {{{ proto resource git_remote_create(resource $repo, string $name, string $url) + */ PHP_FUNCTION(git_remote_create) { - zval *repo; - php_git2_t *_repo; - char *name = {0}; - int name_len; - char *url = {0}; - int url_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_create not implemented yet"); - return; + php_git2_t *result = NULL; + git_remote *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *name = NULL; + int name_len = 0; + char *url = NULL; + int url_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &repo, &name, &name_len, &url, &url_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_create(&out, PHP_GIT2_V(_repo, repository), name, url); + if (php_git2_check_error(error, "git_remote_create" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, remote) = out; + result->type = PHP_GIT2_TYPE_REMOTE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_remote_create_with_fetchspec(repo, name, url, fetch) -*/ + +/* {{{ proto resource git_remote_create_with_fetchspec(resource $repo, string $name, string $url, string $fetch) + */ PHP_FUNCTION(git_remote_create_with_fetchspec) { - zval *repo; - php_git2_t *_repo; - char *name = {0}; - int name_len; - char *url = {0}; - int url_len; - char *fetch = {0}; - int fetch_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_create_with_fetchspec not implemented yet"); - return; + php_git2_t *result = NULL; + git_remote *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *name = NULL; + int name_len = 0; + char *url = NULL; + int url_len = 0; + char *fetch = NULL; + int fetch_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &repo, &name, &name_len, &url, &url_len, &fetch, &fetch_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_create_with_fetchspec(&out, PHP_GIT2_V(_repo, repository), name, url, fetch); + if (php_git2_check_error(error, "git_remote_create_with_fetchspec" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, remote) = out; + result->type = PHP_GIT2_TYPE_REMOTE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_remote_create_inmemory(repo, fetch, url) -*/ + +/* {{{ proto resource git_remote_create_inmemory(resource $repo, string $fetch, string $url) + */ PHP_FUNCTION(git_remote_create_inmemory) { - zval *repo; - php_git2_t *_repo; - char *fetch = {0}; - int fetch_len; - char *url = {0}; - int url_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_create_inmemory not implemented yet"); - return; + php_git2_t *result = NULL; + git_remote *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *fetch = NULL; + int fetch_len = 0; + char *url = NULL; + int url_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &repo, &fetch, &fetch_len, &url, &url_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_create_inmemory(&out, PHP_GIT2_V(_repo, repository), fetch, url); + if (php_git2_check_error(error, "git_remote_create_inmemory" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, remote) = out; + result->type = PHP_GIT2_TYPE_REMOTE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_remote_load(repo, name) -*/ +/* {{{ proto resource git_remote_load(resource $repo, string $name) + */ PHP_FUNCTION(git_remote_load) { - zval *repo; - php_git2_t *_repo; - char *name = {0}; - int name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_load not implemented yet"); - return; + php_git2_t *result = NULL; + git_remote *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *name = NULL; + int name_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &name, &name_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_load(&out, PHP_GIT2_V(_repo, repository), name); + if (php_git2_check_error(error, "git_remote_load" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, remote) = out; + result->type = PHP_GIT2_TYPE_REMOTE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto long git_remote_save(remote) -*/ +/* {{{ proto long git_remote_save(resource $remote) + */ PHP_FUNCTION(git_remote_save) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_save not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_save(PHP_GIT2_V(_remote, remote)); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_remote_owner(remote) -*/ + +/* {{{ proto resource git_remote_owner(resource $remote) + */ PHP_FUNCTION(git_remote_owner) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_owner not implemented yet"); - return; + git_repository *result = NULL; + zval *remote = NULL; + php_git2_t *_remote = NULL; + php_git2_t *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -} -/* {{{ proto resource git_remote_name(remote) -*/ + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_owner(PHP_GIT2_V(_remote, remote)); + PHP_GIT2_MAKE_RESOURCE(__result); + PHP_GIT2_V(__result, remote) = remote; + __result->type = PHP_GIT2_TYPE_REPOSITORY; + __result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + __result->should_free_v = 0; + ZVAL_RESOURCE(return_value, __result->resource_id); +} +/* }}} */ + +/* {{{ proto string git_remote_name(resource $remote) + */ PHP_FUNCTION(git_remote_name) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_name not implemented yet"); - return; + const char *result = NULL; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_name(PHP_GIT2_V(_remote, remote)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_remote_url(remote) -*/ +/* {{{ proto string git_remote_url(resource $remote) + */ PHP_FUNCTION(git_remote_url) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_url not implemented yet"); - return; + const char *result = NULL; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_url(PHP_GIT2_V(_remote, remote)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_remote_pushurl(remote) -*/ +/* {{{ proto string git_remote_pushurl(resource $remote) + */ PHP_FUNCTION(git_remote_pushurl) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_pushurl not implemented yet"); - return; + const char *result = NULL; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_pushurl(PHP_GIT2_V(_remote, remote)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto long git_remote_set_url(remote, url) -*/ +/* {{{ proto long git_remote_set_url(resource $remote, string $url) + */ PHP_FUNCTION(git_remote_set_url) { - zval *remote; - php_git2_t *_remote; - char *url = {0}; - int url_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_url not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + char *url = NULL; + int url_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &url, &url_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_set_url(PHP_GIT2_V(_remote, remote), url); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto long git_remote_set_pushurl(remote, url) -*/ +/* {{{ proto long git_remote_set_pushurl(resource $remote, string $url) + */ PHP_FUNCTION(git_remote_set_pushurl) { - zval *remote; - php_git2_t *_remote; - char *url = {0}; - int url_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_pushurl not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + char *url = NULL; + int url_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &url, &url_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_set_pushurl(PHP_GIT2_V(_remote, remote), url); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto long git_remote_add_fetch(remote, refspec) -*/ + +/* {{{ proto long git_remote_add_fetch(resource $remote, string $refspec) + */ PHP_FUNCTION(git_remote_add_fetch) { - zval *remote; - php_git2_t *_remote; - char *refspec = {0}; - int refspec_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_add_fetch not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + char *refspec = NULL; + int refspec_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &refspec, &refspec_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_add_fetch(PHP_GIT2_V(_remote, remote), refspec); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto long git_remote_get_fetch_refspecs(array, remote) -*/ + +/* {{{ proto array git_remote_get_fetch_refspecs(resource $remote) + */ PHP_FUNCTION(git_remote_get_fetch_refspecs) { - zval *array; - php_git2_t *_array; - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_get_fetch_refspecs not implemented yet"); - return; + zval *result; + git_strarray array = {0}; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &array, &remote) == FAILURE) { + "r", &remote) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_array, php_git2_t*, &array, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_get_fetch_refspecs(&array, PHP_GIT2_V(_remote, remote)); + php_git2_strarray_to_array(&array, &result TSRMLS_CC); + git_strarray_free(&array); + + RETURN_ZVAL(result, 0, 1); + } +/* }}} */ -/* {{{ proto long git_remote_set_fetch_refspecs(remote, array) -*/ + +/* {{{ proto long git_remote_set_fetch_refspecs(resource $remote, array $array) + */ PHP_FUNCTION(git_remote_set_fetch_refspecs) { - zval *remote; - php_git2_t *_remote; - zval *array; - php_git2_t *_array; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + zval *array = NULL; + int error = 0; /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_fetch_refspecs not implemented yet"); - return; +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &remote, &array) == FAILURE) { +// return; +// } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &remote, &array) == FAILURE) { - return; - } ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_set_fetch_refspecs(PHP_GIT2_V(_remote, remote), array); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_remote_add_push(remote, refspec) -*/ + +/* {{{ proto long git_remote_add_push(resource $remote, string $refspec) + */ PHP_FUNCTION(git_remote_add_push) { - zval *remote; - php_git2_t *_remote; - char *refspec = {0}; - int refspec_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_add_push not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + char *refspec = NULL; + int refspec_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &refspec, &refspec_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_add_push(PHP_GIT2_V(_remote, remote), refspec); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto long git_remote_get_push_refspecs(array, remote) -*/ +/* {{{ proto long git_remote_get_push_refspecs(array $array, resource $remote) + */ PHP_FUNCTION(git_remote_get_push_refspecs) { - zval *array; - php_git2_t *_array; - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_get_push_refspecs not implemented yet"); - return; + zval *result; + git_strarray array = {0}; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &array, &remote) == FAILURE) { + "r", &array, &remote) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_array, php_git2_t*, &array, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_get_push_refspecs(&array, PHP_GIT2_V(_remote, remote)); + php_git2_strarray_to_array(&array, &result TSRMLS_CC); + git_strarray_free(&array); + + RETURN_ZVAL(result, 0, 1); } +/* }}} */ -/* {{{ proto long git_remote_set_push_refspecs(remote, array) -*/ + +/* {{{ proto long git_remote_set_push_refspecs(resource $remote, array $array) + */ PHP_FUNCTION(git_remote_set_push_refspecs) { - zval *remote; - php_git2_t *_remote; - zval *array; - php_git2_t *_array; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + zval *array = NULL; + int error = 0; /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_push_refspecs not implemented yet"); - return; +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &remote, &array) == FAILURE) { +// return; +// } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &remote, &array) == FAILURE) { - return; - } ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_set_push_refspecs(PHP_GIT2_V(_remote, remote), array); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto void git_remote_clear_refspecs(remote) -*/ + +/* {{{ proto void git_remote_clear_refspecs(resource $remote) + */ PHP_FUNCTION(git_remote_clear_refspecs) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_clear_refspecs not implemented yet"); - return; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_remote_clear_refspecs(PHP_GIT2_V(_remote, remote)); } +/* }}} */ -/* {{{ proto resource git_remote_refspec_count(remote) -*/ + +/* {{{ proto long git_remote_refspec_count(resource $remote) + */ PHP_FUNCTION(git_remote_refspec_count) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_refspec_count not implemented yet"); - return; + size_t result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_refspec_count(PHP_GIT2_V(_remote, remote)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_remote_get_refspec(remote, n) -*/ +/* {{{ proto resource git_remote_get_refspec(resource $remote, long $n) + */ PHP_FUNCTION(git_remote_get_refspec) { - zval *remote; - php_git2_t *_remote; + const git_refspec *result = NULL; + zval *remote = NULL; + php_git2_t *_remote = NULL; + long n = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_get_refspec not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &remote, &n) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &remote, &n) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_get_refspec(PHP_GIT2_V(_remote, remote), n); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto long git_remote_connect(remote, direction) -*/ + +/* {{{ proto bool git_remote_connect(resource $remote, long $direction) + */ PHP_FUNCTION(git_remote_connect) { - zval *remote; - php_git2_t *_remote; - zval *direction; - php_git2_t *_direction; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_connect not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + long direction = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &remote, &direction) == FAILURE) { + "rl", &remote, &direction) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_connect(PHP_GIT2_V(_remote, remote), direction); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_remote_ls(size, remote) -*/ +/* {{{ proto resource git_remote_ls(long $size, resource $remote) + */ PHP_FUNCTION(git_remote_ls) { - zval *remote; - php_git2_t *_remote; + php_git2_t *result = NULL; + git_remote_head **out = NULL; + long size = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_ls not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lr", &size, &remote) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &size, &remote) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_size, php_git2_t*, &size, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_ls(&out, size, PHP_GIT2_V(_remote, remote)); + if (php_git2_check_error(error, "git_remote_ls" TSRMLS_CC)) { + RETURN_FALSE; + } + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto long git_remote_download(remote) -*/ + +/* {{{ proto long git_remote_download(resource $remote) + */ PHP_FUNCTION(git_remote_download) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_download not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_download(PHP_GIT2_V(_remote, remote)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_remote_connected(remote) -*/ + +/* {{{ proto long git_remote_connected(resource $remote) + */ PHP_FUNCTION(git_remote_connected) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_connected not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_connected(PHP_GIT2_V(_remote, remote)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto void git_remote_stop(remote) -*/ +/* {{{ proto void git_remote_stop(resource $remote) + */ PHP_FUNCTION(git_remote_stop) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_stop not implemented yet"); - return; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_remote_stop(PHP_GIT2_V(_remote, remote)); } +/* }}} */ -/* {{{ proto void git_remote_disconnect(remote) -*/ +/* {{{ proto void git_remote_disconnect(resource $remote) + */ PHP_FUNCTION(git_remote_disconnect) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_disconnect not implemented yet"); - return; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_remote_disconnect(PHP_GIT2_V(_remote, remote)); } +/* }}} */ -/* {{{ proto void git_remote_free(remote) -*/ + +/* {{{ proto void git_remote_free(resource $remote) + */ PHP_FUNCTION(git_remote_free) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_free not implemented yet"); - return; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_remote->should_free_v) { + git_remote_free(PHP_GIT2_V(_remote, remote)); + }; + zval_ptr_dtor(&remote); } +/* }}} */ -/* {{{ proto long git_remote_update_tips(remote) -*/ + +/* {{{ proto long git_remote_update_tips(resource $remote) + */ PHP_FUNCTION(git_remote_update_tips) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_update_tips not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_update_tips(PHP_GIT2_V(_remote, remote)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_remote_fetch(remote) -*/ + +/* {{{ proto long git_remote_fetch(resource $remote) + */ PHP_FUNCTION(git_remote_fetch) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_fetch not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_fetch(PHP_GIT2_V(_remote, remote)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_remote_valid_url(url) -*/ +/* {{{ proto long git_remote_valid_url(string $url) + */ PHP_FUNCTION(git_remote_valid_url) { - char *url = {0}; - int url_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_valid_url not implemented yet"); - return; + int result = 0; + char *url = NULL; + int url_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &url_len) == FAILURE) { return; } + + result = git_remote_valid_url(url); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_remote_supported_url(url) -*/ +/* {{{ proto long git_remote_supported_url(string $url) + */ PHP_FUNCTION(git_remote_supported_url) { - char *url = {0}; - int url_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_supported_url not implemented yet"); - return; + int result = 0; + char *url = NULL; + int url_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &url_len) == FAILURE) { return; } + + result = git_remote_supported_url(url); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_remote_list(repo) -*/ + +/* {{{ proto resource git_remote_list(resource $repo) + */ PHP_FUNCTION(git_remote_list) { - zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_list not implemented yet"); - return; + zval *result = NULL; + git_strarray out = {0}; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_remote_list(&out, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_remote_list" TSRMLS_CC)) { + RETURN_FALSE; + } + + php_git2_strarray_to_array(&out, &result TSRMLS_CC); + git_strarray_free(&out); + + RETURN_ZVAL(result, 0, 1); } +/* }}} */ -/* {{{ proto void git_remote_check_cert(remote, check) -*/ + +/* {{{ proto void git_remote_check_cert(resource $remote, long $check) + */ PHP_FUNCTION(git_remote_check_cert) { - zval *remote; - php_git2_t *_remote; - long check; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_check_cert not implemented yet"); - return; + zval *remote = NULL; + php_git2_t *_remote = NULL; + long check = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &remote, &check) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_remote_check_cert(PHP_GIT2_V(_remote, remote), check); } +/* }}} */ -/* {{{ proto long git_remote_set_transport(remote, transport) -*/ + +/* {{{ proto long git_remote_set_transport(resource $remote, resource $transport) + */ PHP_FUNCTION(git_remote_set_transport) { - zval *remote; - php_git2_t *_remote; - zval *transport; - php_git2_t *_transport; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_transport not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + zval *transport = NULL; + php_git2_t *_transport = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &remote, &transport) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_transport, php_git2_t*, &transport, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_set_transport(PHP_GIT2_V(_remote, remote), PHP_GIT2_V(_transport, transport)); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_remote_set_callbacks(remote, callbacks) */ @@ -669,23 +800,25 @@ PHP_FUNCTION(git_remote_set_callbacks) ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto resource git_remote_stats(remote) -*/ +/* {{{ proto resource git_remote_stats(resource $remote) + */ PHP_FUNCTION(git_remote_stats) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_stats not implemented yet"); - return; + const git_transfer_progress *result = NULL; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_stats(PHP_GIT2_V(_remote, remote)); + /* TODO(chobie): implement this */ } +/* }}} */ + /* {{{ proto resource git_remote_autotag(remote) */ @@ -747,57 +880,60 @@ PHP_FUNCTION(git_remote_rename) // ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto long git_remote_update_fetchhead(remote) -*/ +/* {{{ proto long git_remote_update_fetchhead(resource $remote) + */ PHP_FUNCTION(git_remote_update_fetchhead) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_update_fetchhead not implemented yet"); - return; + int result = 0; + zval *remote = NULL; + php_git2_t *_remote = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_update_fetchhead(PHP_GIT2_V(_remote, remote)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto void git_remote_set_update_fetchhead(remote, value) -*/ +/* {{{ proto void git_remote_set_update_fetchhead(resource $remote, long $value) + */ PHP_FUNCTION(git_remote_set_update_fetchhead) { - zval *remote; - php_git2_t *_remote; - long value; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_update_fetchhead not implemented yet"); - return; + zval *remote = NULL; + php_git2_t *_remote = NULL; + long value = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &remote, &value) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_remote_set_update_fetchhead(PHP_GIT2_V(_remote, remote), value); } +/* }}} */ -/* {{{ proto long git_remote_is_valid_name(remote_name) -*/ +/* {{{ proto long git_remote_is_valid_name(string $remote_name) + */ PHP_FUNCTION(git_remote_is_valid_name) { - char *remote_name = {0}; - int remote_name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_is_valid_name not implemented yet"); - return; + int result = 0; + char *remote_name = NULL; + int remote_name_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &remote_name, &remote_name_len) == FAILURE) { return; } + + result = git_remote_is_valid_name(remote_name); + RETURN_BOOL(result); } +/* }}} */ diff --git a/transport.c b/transport.c index 6a06c72d9c..cf95c246c8 100644 --- a/transport.c +++ b/transport.c @@ -2,25 +2,36 @@ #include "php_git2_priv.h" #include "transport.h" -/* {{{ proto resource git_transport_new(owner, url) -*/ +/* {{{ proto resource git_transport_new(resource $owner, string $url) + */ PHP_FUNCTION(git_transport_new) { - zval *owner; - php_git2_t *_owner; - char *url = {0}; - int url_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_transport *out = NULL; + zval *owner = NULL; + php_git2_t *_owner = NULL; + char *url = NULL; + int url_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &owner, &url, &url_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_transport_new(&out, PHP_GIT2_V(_owner, remote), url); + if (php_git2_check_error(error, "git_transport_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, transport) = out; + result->type = PHP_GIT2_TYPE_TRANSPORT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ /* {{{ proto long git_transport_register(prefix, priority, cb, param) */ From bd18688b78260148352afefd64628242b8ab096a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 02:43:22 +0900 Subject: [PATCH 025/136] add several stubs --- checkout.c | 67 ++++++++++++ checkout.h | 58 ++++++++++ config.m4 | 2 +- diff.c | 112 +++++++++++++++++++ diff.h | 215 ++++++++++++++++++++++++++++++++++++ filter.c | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++ filter.h | 170 +++++++++++++++++++++++++++++ ignore.c | 63 +++++++++++ ignore.h | 56 ++++++++++ indexer.c | 103 ++++++++++++++++++ indexer.h | 77 +++++++++++++ merge.c | 248 ++++++++++++++++++++++++++++++++++++++++++ merge.h | 141 ++++++++++++++++++++++++ patch.c | 212 ++++++++++++++++++++++++++++++++++++ patch.h | 156 +++++++++++++++++++++++++++ pathspec.c | 253 +++++++++++++++++++++++++++++++++++++++++++ pathspec.h | 146 +++++++++++++++++++++++++ php_git2.c | 132 +++++++++++++++++++++++ php_git2.h | 2 + 19 files changed, 2523 insertions(+), 1 deletion(-) create mode 100644 checkout.c create mode 100644 checkout.h create mode 100644 diff.c create mode 100644 diff.h create mode 100644 filter.c create mode 100644 filter.h create mode 100644 ignore.c create mode 100644 ignore.h create mode 100644 indexer.c create mode 100644 indexer.h create mode 100644 merge.c create mode 100644 merge.h create mode 100644 patch.c create mode 100644 patch.h create mode 100644 pathspec.c create mode 100644 pathspec.h diff --git a/checkout.c b/checkout.c new file mode 100644 index 0000000000..2e5e96fe26 --- /dev/null +++ b/checkout.c @@ -0,0 +1,67 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "checkout.h" +/* {{{ proto long git_checkout_head(repo, opts) +*/ +PHP_FUNCTION(git_checkout_head) +{ + zval *repo; + php_git2_t *_repo; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_checkout_head not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &opts) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_checkout_index(repo, index, opts) +*/ +PHP_FUNCTION(git_checkout_index) +{ + zval *repo; + php_git2_t *_repo; + zval *index; + php_git2_t *_index; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_checkout_index not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrr", &repo, &index, &opts) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_checkout_tree(repo, treeish, opts) +*/ +PHP_FUNCTION(git_checkout_tree) +{ + zval *repo; + php_git2_t *_repo; + zval *treeish; + php_git2_t *_treeish; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_checkout_tree not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrr", &repo, &treeish, &opts) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/checkout.h b/checkout.h new file mode 100644 index 0000000000..29eb09d27a --- /dev/null +++ b/checkout.h @@ -0,0 +1,58 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_CHECKOUT_H +#define PHP_GIT2_CHECKOUT_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_checkout_head, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_checkout_index, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_checkout_tree, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, treeish) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_checkout_head(repo, opts) +*/ +PHP_FUNCTION(git_checkout_head); + +/* {{{ proto long git_checkout_index(repo, index, opts) +*/ +PHP_FUNCTION(git_checkout_index); + +/* {{{ proto long git_checkout_tree(repo, treeish, opts) +*/ +PHP_FUNCTION(git_checkout_tree); + +#endif \ No newline at end of file diff --git a/config.m4 b/config.m4 index e81c8f05a8..4d7b0f7e2d 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/diff.c b/diff.c new file mode 100644 index 0000000000..c3016b7d27 --- /dev/null +++ b/diff.c @@ -0,0 +1,112 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "diff.h" + +/* {{{ proto void git_diff_free(diff) +*/ +PHP_FUNCTION(git_diff_free) +{ +} + +/* {{{ proto resource git_diff_tree_to_tree(repo, old_tree, new_tree, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_tree) +{ +} + +/* {{{ proto resource git_diff_tree_to_index(repo, old_tree, index, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_index) +{ +} + +/* {{{ proto resource git_diff_index_to_workdir(repo, index, opts) +*/ +PHP_FUNCTION(git_diff_index_to_workdir) +{ +} + +/* {{{ proto resource git_diff_tree_to_workdir(repo, old_tree, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_workdir) +{ +} + +/* {{{ proto resource git_diff_tree_to_workdir_with_index(repo, old_tree, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_workdir_with_index) +{ +} + +/* {{{ proto long git_diff_merge(onto, from) +*/ +PHP_FUNCTION(git_diff_merge) +{ +} + +/* {{{ proto long git_diff_find_similar(diff, options) +*/ +PHP_FUNCTION(git_diff_find_similar) +{ +} + +/* {{{ proto long git_diff_options_init(options, version) +*/ +PHP_FUNCTION(git_diff_options_init) +{ +} + +/* {{{ proto resource git_diff_num_deltas(diff) +*/ +PHP_FUNCTION(git_diff_num_deltas) +{ +} + +/* {{{ proto resource git_diff_num_deltas_of_type(diff, type) +*/ +PHP_FUNCTION(git_diff_num_deltas_of_type) +{ +} + +/* {{{ proto resource git_diff_get_delta(diff, idx) +*/ +PHP_FUNCTION(git_diff_get_delta) +{ +} + +/* {{{ proto long git_diff_is_sorted_icase(diff) +*/ +PHP_FUNCTION(git_diff_is_sorted_icase) +{ +} + +/* {{{ proto long git_diff_foreach(diff, file_cb, hunk_cb, line_cb, payload) +*/ +PHP_FUNCTION(git_diff_foreach) +{ +} + +/* {{{ proto resource git_diff_status_char(status) +*/ +PHP_FUNCTION(git_diff_status_char) +{ +} + +/* {{{ proto long git_diff_print(diff, format, print_cb, payload) +*/ +PHP_FUNCTION(git_diff_print) +{ +} + +/* {{{ proto long git_diff_blobs(old_blob, old_as_path, new_blob, new_as_path, options, file_cb, hunk_cb, line_cb, payload) +*/ +PHP_FUNCTION(git_diff_blobs) +{ +} + +/* {{{ proto long git_diff_blob_to_buffer(old_blob, old_as_path, buffer, buffer_len, buffer_as_path, options, file_cb, hunk_cb, line_cb, payload) +*/ +PHP_FUNCTION(git_diff_blob_to_buffer) +{ +} + diff --git a/diff.h b/diff.h new file mode 100644 index 0000000000..699e83ac64 --- /dev/null +++ b/diff.h @@ -0,0 +1,215 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_DIFF_H +#define PHP_GIT2_DIFF_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_free, 0, 0, 1) + ZEND_ARG_INFO(0, diff) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_tree_to_tree, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, old_tree) + ZEND_ARG_INFO(0, new_tree) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_tree_to_index, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, old_tree) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_index_to_workdir, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_tree_to_workdir, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, old_tree) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_tree_to_workdir_with_index, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, old_tree) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_merge, 0, 0, 2) + ZEND_ARG_INFO(0, onto) + ZEND_ARG_INFO(0, from) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_find_similar, 0, 0, 2) + ZEND_ARG_INFO(0, diff) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_options_init, 0, 0, 2) + ZEND_ARG_INFO(0, options) + ZEND_ARG_INFO(0, version) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_num_deltas, 0, 0, 1) + ZEND_ARG_INFO(0, diff) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_num_deltas_of_type, 0, 0, 2) + ZEND_ARG_INFO(0, diff) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_get_delta, 0, 0, 2) + ZEND_ARG_INFO(0, diff) + ZEND_ARG_INFO(0, idx) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_is_sorted_icase, 0, 0, 1) + ZEND_ARG_INFO(0, diff) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_foreach, 0, 0, 5) + ZEND_ARG_INFO(0, diff) + ZEND_ARG_INFO(0, file_cb) + ZEND_ARG_INFO(0, hunk_cb) + ZEND_ARG_INFO(0, line_cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_status_char, 0, 0, 1) + ZEND_ARG_INFO(0, status) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_print, 0, 0, 4) + ZEND_ARG_INFO(0, diff) + ZEND_ARG_INFO(0, format) + ZEND_ARG_INFO(0, print_cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_blobs, 0, 0, 9) + ZEND_ARG_INFO(0, old_blob) + ZEND_ARG_INFO(0, old_as_path) + ZEND_ARG_INFO(0, new_blob) + ZEND_ARG_INFO(0, new_as_path) + ZEND_ARG_INFO(0, options) + ZEND_ARG_INFO(0, file_cb) + ZEND_ARG_INFO(0, hunk_cb) + ZEND_ARG_INFO(0, line_cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_blob_to_buffer, 0, 0, 10) + ZEND_ARG_INFO(0, old_blob) + ZEND_ARG_INFO(0, old_as_path) + ZEND_ARG_INFO(0, buffer) + ZEND_ARG_INFO(0, buffer_len) + ZEND_ARG_INFO(0, buffer_as_path) + ZEND_ARG_INFO(0, options) + ZEND_ARG_INFO(0, file_cb) + ZEND_ARG_INFO(0, hunk_cb) + ZEND_ARG_INFO(0, line_cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +/* {{{ proto void git_diff_free(diff) +*/ +PHP_FUNCTION(git_diff_free); + +/* {{{ proto resource git_diff_tree_to_tree(repo, old_tree, new_tree, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_tree); + +/* {{{ proto resource git_diff_tree_to_index(repo, old_tree, index, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_index); + +/* {{{ proto resource git_diff_index_to_workdir(repo, index, opts) +*/ +PHP_FUNCTION(git_diff_index_to_workdir); + +/* {{{ proto resource git_diff_tree_to_workdir(repo, old_tree, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_workdir); + +/* {{{ proto resource git_diff_tree_to_workdir_with_index(repo, old_tree, opts) +*/ +PHP_FUNCTION(git_diff_tree_to_workdir_with_index); + +/* {{{ proto long git_diff_merge(onto, from) +*/ +PHP_FUNCTION(git_diff_merge); + +/* {{{ proto long git_diff_find_similar(diff, options) +*/ +PHP_FUNCTION(git_diff_find_similar); + +/* {{{ proto long git_diff_options_init(options, version) +*/ +PHP_FUNCTION(git_diff_options_init); + +/* {{{ proto resource git_diff_num_deltas(diff) +*/ +PHP_FUNCTION(git_diff_num_deltas); + +/* {{{ proto resource git_diff_num_deltas_of_type(diff, type) +*/ +PHP_FUNCTION(git_diff_num_deltas_of_type); + +/* {{{ proto resource git_diff_get_delta(diff, idx) +*/ +PHP_FUNCTION(git_diff_get_delta); + +/* {{{ proto long git_diff_is_sorted_icase(diff) +*/ +PHP_FUNCTION(git_diff_is_sorted_icase); + +/* {{{ proto long git_diff_foreach(diff, file_cb, hunk_cb, line_cb, payload) +*/ +PHP_FUNCTION(git_diff_foreach); + +/* {{{ proto resource git_diff_status_char(status) +*/ +PHP_FUNCTION(git_diff_status_char); + +/* {{{ proto long git_diff_print(diff, format, print_cb, payload) +*/ +PHP_FUNCTION(git_diff_print); + +/* {{{ proto long git_diff_blobs(old_blob, old_as_path, new_blob, new_as_path, options, file_cb, hunk_cb, line_cb, payload) +*/ +PHP_FUNCTION(git_diff_blobs); + +/* {{{ proto long git_diff_blob_to_buffer(old_blob, old_as_path, buffer, buffer_len, buffer_as_path, options, file_cb, hunk_cb, line_cb, payload) +*/ +PHP_FUNCTION(git_diff_blob_to_buffer); + + +#endif \ No newline at end of file diff --git a/filter.c b/filter.c new file mode 100644 index 0000000000..c7a19b8a4c --- /dev/null +++ b/filter.c @@ -0,0 +1,311 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "filter.h" + +/* {{{ proto resource git_filter_list_load(repo, blob, path, mode) +*/ +PHP_FUNCTION(git_filter_list_load) +{ + zval *repo; + php_git2_t *_repo; + zval *blob; + php_git2_t *_blob; + char *path = {0}; + int path_len; + zval *mode; + php_git2_t *_mode; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_load not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrsr", &repo, &blob, &path, &path_len, &mode) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_list_apply_to_data(filters, in) +*/ +PHP_FUNCTION(git_filter_list_apply_to_data) +{ + zval *filters; + php_git2_t *_filters; + zval *in; + php_git2_t *_in; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_data not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &filters, &in) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_list_apply_to_file(filters, repo, path) +*/ +PHP_FUNCTION(git_filter_list_apply_to_file) +{ + zval *filters; + php_git2_t *_filters; + zval *repo; + php_git2_t *_repo; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_file not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrs", &filters, &repo, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_list_apply_to_blob(filters, blob) +*/ +PHP_FUNCTION(git_filter_list_apply_to_blob) +{ + zval *filters; + php_git2_t *_filters; + zval *blob; + php_git2_t *_blob; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_blob not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &filters, &blob) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_filter_list_free(filters) +*/ +PHP_FUNCTION(git_filter_list_free) +{ + zval *filters; + php_git2_t *_filters; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &filters) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_lookup(name) +*/ +PHP_FUNCTION(git_filter_lookup) +{ + char *name = {0}; + int name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_lookup not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &name, &name_len) == FAILURE) { + return; + } +} + +/* {{{ proto resource git_filter_list_new(repo, mode) +*/ +PHP_FUNCTION(git_filter_list_new) +{ + zval *repo; + php_git2_t *_repo; + zval *mode; + php_git2_t *_mode; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &mode) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_filter_list_push(fl, filter, payload) +*/ +PHP_FUNCTION(git_filter_list_push) +{ + zval *fl; + php_git2_t *_fl; + zval *filter; + php_git2_t *_filter; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_push not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rr", &fl, &filter, &payload) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_list_length(fl) +*/ +PHP_FUNCTION(git_filter_list_length) +{ + zval *fl; + php_git2_t *_fl; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_length not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &fl) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_source_repo(src) +*/ +PHP_FUNCTION(git_filter_source_repo) +{ + zval *src; + php_git2_t *_src; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_repo not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_source_path(src) +*/ +PHP_FUNCTION(git_filter_source_path) +{ + zval *src; + php_git2_t *_src; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_path not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_source_filemode(src) +*/ +PHP_FUNCTION(git_filter_source_filemode) +{ + zval *src; + php_git2_t *_src; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_filemode not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_source_id(src) +*/ +PHP_FUNCTION(git_filter_source_id) +{ + zval *src; + php_git2_t *_src; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_id not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_filter_source_mode(src) +*/ +PHP_FUNCTION(git_filter_source_mode) +{ + zval *src; + php_git2_t *_src; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_mode not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_filter_register(name, filter, priority) +*/ +PHP_FUNCTION(git_filter_register) +{ + char *name = {0}; + int name_len; + zval *filter; + php_git2_t *_filter; + long priority; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_register not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "srl", &name, &name_len, &filter, &priority) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_name, php_git2_t*, &name, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_filter_unregister(name) +*/ +PHP_FUNCTION(git_filter_unregister) +{ + char *name = {0}; + int name_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_unregister not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &name, &name_len) == FAILURE) { + return; + } +} + diff --git a/filter.h b/filter.h new file mode 100644 index 0000000000..ae02e0ddb5 --- /dev/null +++ b/filter.h @@ -0,0 +1,170 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_FILTER_H +#define PHP_GIT2_FILTER_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_load, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, blob) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, mode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_apply_to_data, 0, 0, 2) + ZEND_ARG_INFO(0, filters) + ZEND_ARG_INFO(0, in) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_apply_to_file, 0, 0, 3) + ZEND_ARG_INFO(0, filters) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_apply_to_blob, 0, 0, 2) + ZEND_ARG_INFO(0, filters) + ZEND_ARG_INFO(0, blob) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_free, 0, 0, 1) + ZEND_ARG_INFO(0, filters) +ZEND_END_ARG_INFO() + + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_lookup, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_new, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, mode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_push, 0, 0, 3) + ZEND_ARG_INFO(0, fl) + ZEND_ARG_INFO(0, filter) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_length, 0, 0, 1) + ZEND_ARG_INFO(0, fl) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_source_repo, 0, 0, 1) + ZEND_ARG_INFO(0, src) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_source_path, 0, 0, 1) + ZEND_ARG_INFO(0, src) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_source_filemode, 0, 0, 1) + ZEND_ARG_INFO(0, src) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_source_id, 0, 0, 1) + ZEND_ARG_INFO(0, src) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_source_mode, 0, 0, 1) + ZEND_ARG_INFO(0, src) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_register, 0, 0, 3) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, filter) + ZEND_ARG_INFO(0, priority) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_unregister, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_filter_list_load(repo, blob, path, mode) +*/ +PHP_FUNCTION(git_filter_list_load); + +/* {{{ proto resource git_filter_list_apply_to_data(filters, in) +*/ +PHP_FUNCTION(git_filter_list_apply_to_data); + +/* {{{ proto resource git_filter_list_apply_to_file(filters, repo, path) +*/ +PHP_FUNCTION(git_filter_list_apply_to_file); + +/* {{{ proto resource git_filter_list_apply_to_blob(filters, blob) +*/ +PHP_FUNCTION(git_filter_list_apply_to_blob); + +/* {{{ proto void git_filter_list_free(filters) +*/ +PHP_FUNCTION(git_filter_list_free); + +/* {{{ proto resource git_filter_lookup(name) +*/ +PHP_FUNCTION(git_filter_lookup); + +/* {{{ proto resource git_filter_list_new(repo, mode) +*/ +PHP_FUNCTION(git_filter_list_new); + +/* {{{ proto long git_filter_list_push(fl, filter, payload) +*/ +PHP_FUNCTION(git_filter_list_push); + +/* {{{ proto resource git_filter_list_length(fl) +*/ +PHP_FUNCTION(git_filter_list_length); + +/* {{{ proto resource git_filter_source_repo(src) +*/ +PHP_FUNCTION(git_filter_source_repo); + +/* {{{ proto resource git_filter_source_path(src) +*/ +PHP_FUNCTION(git_filter_source_path); + +/* {{{ proto resource git_filter_source_filemode(src) +*/ +PHP_FUNCTION(git_filter_source_filemode); + +/* {{{ proto resource git_filter_source_id(src) +*/ +PHP_FUNCTION(git_filter_source_id); + +/* {{{ proto resource git_filter_source_mode(src) +*/ +PHP_FUNCTION(git_filter_source_mode); + +/* {{{ proto long git_filter_register(name, filter, priority) +*/ +PHP_FUNCTION(git_filter_register); + +/* {{{ proto long git_filter_unregister(name) +*/ +PHP_FUNCTION(git_filter_unregister); + +#endif diff --git a/ignore.c b/ignore.c new file mode 100644 index 0000000000..1713f03fe8 --- /dev/null +++ b/ignore.c @@ -0,0 +1,63 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "ignore.h" + +/* {{{ proto long git_ignore_add_rule(repo, rules) +*/ +PHP_FUNCTION(git_ignore_add_rule) +{ + zval *repo; + php_git2_t *_repo; + char *rules = {0}; + int rules_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_ignore_add_rule not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &rules, &rules_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_ignore_clear_internal_rules(repo) +*/ +PHP_FUNCTION(git_ignore_clear_internal_rules) +{ + zval *repo; + php_git2_t *_repo; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_ignore_clear_internal_rules not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_ignore_path_is_ignored(ignored, repo, path) +*/ +PHP_FUNCTION(git_ignore_path_is_ignored) +{ + long ignored; + zval *repo; + php_git2_t *_repo; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_ignore_path_is_ignored not implemented yet"); + return; +// +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "lrs", &ignored, &repo, &path, &path_len) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_ignored, php_git2_t*, &ignored, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/ignore.h b/ignore.h new file mode 100644 index 0000000000..9fc261047a --- /dev/null +++ b/ignore.h @@ -0,0 +1,56 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_IGNORE_H +#define PHP_GIT2_IGNORE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_ignore_add_rule, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, rules) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_ignore_clear_internal_rules, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_ignore_path_is_ignored, 0, 0, 3) + ZEND_ARG_INFO(0, ignored) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_ignore_add_rule(repo, rules) +*/ +PHP_FUNCTION(git_ignore_add_rule); + +/* {{{ proto long git_ignore_clear_internal_rules(repo) +*/ +PHP_FUNCTION(git_ignore_clear_internal_rules); + +/* {{{ proto long git_ignore_path_is_ignored(ignored, repo, path) +*/ +PHP_FUNCTION(git_ignore_path_is_ignored); + +#endif \ No newline at end of file diff --git a/indexer.c b/indexer.c new file mode 100644 index 0000000000..b5da4bdc69 --- /dev/null +++ b/indexer.c @@ -0,0 +1,103 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "indexer.h" + +/* {{{ proto resource git_indexer_new(path, mode, odb, progress_cb, progress_cb_payload) +*/ +PHP_FUNCTION(git_indexer_new) +{ + char *path = {0}; + int path_len; + long mode; + zval *odb; + php_git2_t *_odb; + zval *progress_cb; + php_git2_t *_progress_cb; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_new not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "slrr", &path, &path_len, &mode, &odb, &progress_cb, &progress_cb_payload) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_path, php_git2_t*, &path, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_indexer_append(idx, data, size, stats) +*/ +PHP_FUNCTION(git_indexer_append) +{ + zval *idx; + php_git2_t *_idx; + zval *stats; + php_git2_t *_stats; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_append not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rr", &idx, &data, &size, &stats) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_indexer_commit(idx, stats) +*/ +PHP_FUNCTION(git_indexer_commit) +{ + zval *idx; + php_git2_t *_idx; + zval *stats; + php_git2_t *_stats; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_commit not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &idx, &stats) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_indexer_hash(idx) +*/ +PHP_FUNCTION(git_indexer_hash) +{ + zval *idx; + php_git2_t *_idx; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_hash not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &idx) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_indexer_free(idx) +*/ +PHP_FUNCTION(git_indexer_free) +{ + zval *idx; + php_git2_t *_idx; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &idx) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/indexer.h b/indexer.h new file mode 100644 index 0000000000..29106edf68 --- /dev/null +++ b/indexer.h @@ -0,0 +1,77 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_INDEXER_H +#define PHP_GIT2_INDEXER_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_new, 0, 0, 5) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, mode) + ZEND_ARG_INFO(0, odb) + ZEND_ARG_INFO(0, progress_cb) + ZEND_ARG_INFO(0, progress_cb_payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_append, 0, 0, 4) + ZEND_ARG_INFO(0, idx) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, size) + ZEND_ARG_INFO(0, stats) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_commit, 0, 0, 2) + ZEND_ARG_INFO(0, idx) + ZEND_ARG_INFO(0, stats) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_hash, 0, 0, 1) + ZEND_ARG_INFO(0, idx) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_free, 0, 0, 1) + ZEND_ARG_INFO(0, idx) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_indexer_new(path, mode, odb, progress_cb, progress_cb_payload) +*/ +PHP_FUNCTION(git_indexer_new); + +/* {{{ proto long git_indexer_append(idx, data, size, stats) +*/ +PHP_FUNCTION(git_indexer_append); + +/* {{{ proto long git_indexer_commit(idx, stats) +*/ +PHP_FUNCTION(git_indexer_commit); + +/* {{{ proto resource git_indexer_hash(idx) +*/ +PHP_FUNCTION(git_indexer_hash); + +/* {{{ proto void git_indexer_free(idx) +*/ +PHP_FUNCTION(git_indexer_free); + +#endif \ No newline at end of file diff --git a/merge.c b/merge.c new file mode 100644 index 0000000000..a3207beaf6 --- /dev/null +++ b/merge.c @@ -0,0 +1,248 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "merge.h" + +/* {{{ proto resource git_merge_base(repo, one, two) +*/ +PHP_FUNCTION(git_merge_base) +{ + zval *repo; + php_git2_t *_repo; + char *one = {0}; + int one_len; + char *two = {0}; + int two_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_base not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &repo, &one, &one_len, &two, &two_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_merge_base_many(repo, length, input_array[]) +*/ +PHP_FUNCTION(git_merge_base_many) +{ +// zval *repo; +// php_git2_t *_repo; +// char *input_array[] = {0}; +// int input_array[]_len; +// +// /* TODO(chobie): implement this */ +// php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_base_many not implemented yet"); +// return; +// +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rs", &repo, &length, &input_array[], &input_array[]_len) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_merge_head_from_ref(repo, ref) +*/ +PHP_FUNCTION(git_merge_head_from_ref) +{ + zval *repo; + php_git2_t *_repo; + zval *ref; + php_git2_t *_ref; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_from_ref not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &ref) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_merge_head_from_fetchhead(repo, branch_name, remote_url, oid) +*/ +PHP_FUNCTION(git_merge_head_from_fetchhead) +{ + zval *repo; + php_git2_t *_repo; + char *branch_name = {0}; + int branch_name_len; + char *remote_url = {0}; + int remote_url_len; + char *oid = {0}; + int oid_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_from_fetchhead not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsss", &repo, &branch_name, &branch_name_len, &remote_url, &remote_url_len, &oid, &oid_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_merge_head_from_oid(repo, oid) +*/ +PHP_FUNCTION(git_merge_head_from_oid) +{ + zval *repo; + php_git2_t *_repo; + char *oid = {0}; + int oid_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_from_oid not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &oid, &oid_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_merge_head_free(head) +*/ +PHP_FUNCTION(git_merge_head_free) +{ + zval *head; + php_git2_t *_head; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &head) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_head, php_git2_t*, &head, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_merge_trees(repo, ancestor_tree, our_tree, their_tree, opts) +*/ +PHP_FUNCTION(git_merge_trees) +{ + zval *repo; + php_git2_t *_repo; + zval *ancestor_tree; + php_git2_t *_ancestor_tree; + zval *our_tree; + php_git2_t *_our_tree; + zval *their_tree; + php_git2_t *_their_tree; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_trees not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrrrr", &repo, &ancestor_tree, &our_tree, &their_tree, &opts) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_merge(repo, their_heads, their_heads_len, opts) +*/ +PHP_FUNCTION(git_merge) +{ + zval *repo; + php_git2_t *_repo; + zval *their_heads; + php_git2_t *_their_heads; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rrr", &repo, &their_heads, &their_heads_len, &opts) == FAILURE) { +// return; +// } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_merge_result_is_uptodate(merge_result) +*/ +PHP_FUNCTION(git_merge_result_is_uptodate) +{ + zval *merge_result; + php_git2_t *_merge_result; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_is_uptodate not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &merge_result) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_merge_result_is_fastforward(merge_result) +*/ +PHP_FUNCTION(git_merge_result_is_fastforward) +{ + zval *merge_result; + php_git2_t *_merge_result; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_is_fastforward not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &merge_result) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_merge_result_fastforward_oid(merge_result) +*/ +PHP_FUNCTION(git_merge_result_fastforward_oid) +{ + zval *merge_result; + php_git2_t *_merge_result; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_fastforward_oid not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &merge_result) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_merge_result_free(merge_result) +*/ +PHP_FUNCTION(git_merge_result_free) +{ + zval *merge_result; + php_git2_t *_merge_result; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &merge_result) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/merge.h b/merge.h new file mode 100644 index 0000000000..0367b95ae7 --- /dev/null +++ b/merge.h @@ -0,0 +1,141 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_MERGE_H +#define PHP_GIT2_MERGE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_base, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, one) + ZEND_ARG_INFO(0, two) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_base_many, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, length) + ZEND_ARG_INFO(0, input_array[]) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_head_from_ref, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_head_from_fetchhead, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, branch_name) + ZEND_ARG_INFO(0, remote_url) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_head_from_oid, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_head_free, 0, 0, 1) + ZEND_ARG_INFO(0, head) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_trees, 0, 0, 5) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, ancestor_tree) + ZEND_ARG_INFO(0, our_tree) + ZEND_ARG_INFO(0, their_tree) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, their_heads) + ZEND_ARG_INFO(0, their_heads_len) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_result_is_uptodate, 0, 0, 1) + ZEND_ARG_INFO(0, merge_result) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_result_is_fastforward, 0, 0, 1) + ZEND_ARG_INFO(0, merge_result) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_result_fastforward_oid, 0, 0, 1) + ZEND_ARG_INFO(0, merge_result) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_merge_result_free, 0, 0, 1) + ZEND_ARG_INFO(0, merge_result) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_merge_base(repo, one, two) +*/ +PHP_FUNCTION(git_merge_base); + +/* {{{ proto resource git_merge_base_many(repo, length, input_array[]) +*/ +PHP_FUNCTION(git_merge_base_many); + +/* {{{ proto resource git_merge_head_from_ref(repo, ref) +*/ +PHP_FUNCTION(git_merge_head_from_ref); + +/* {{{ proto resource git_merge_head_from_fetchhead(repo, branch_name, remote_url, oid) +*/ +PHP_FUNCTION(git_merge_head_from_fetchhead); + +/* {{{ proto resource git_merge_head_from_oid(repo, oid) +*/ +PHP_FUNCTION(git_merge_head_from_oid); + +/* {{{ proto void git_merge_head_free(head) +*/ +PHP_FUNCTION(git_merge_head_free); + +/* {{{ proto resource git_merge_trees(repo, ancestor_tree, our_tree, their_tree, opts) +*/ +PHP_FUNCTION(git_merge_trees); + +/* {{{ proto resource git_merge(repo, their_heads, their_heads_len, opts) +*/ +PHP_FUNCTION(git_merge); + +/* {{{ proto long git_merge_result_is_uptodate(merge_result) +*/ +PHP_FUNCTION(git_merge_result_is_uptodate); + +/* {{{ proto long git_merge_result_is_fastforward(merge_result) +*/ +PHP_FUNCTION(git_merge_result_is_fastforward); + +/* {{{ proto resource git_merge_result_fastforward_oid(merge_result) +*/ +PHP_FUNCTION(git_merge_result_fastforward_oid); + +/* {{{ proto void git_merge_result_free(merge_result) +*/ +PHP_FUNCTION(git_merge_result_free); + +#endif \ No newline at end of file diff --git a/patch.c b/patch.c new file mode 100644 index 0000000000..0b107b22a8 --- /dev/null +++ b/patch.c @@ -0,0 +1,212 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "patch.h" + +/* {{{ proto resource git_patch_from_diff(diff, idx) +*/ +PHP_FUNCTION(git_patch_from_diff) +{ + zval *diff; + php_git2_t *_diff; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_from_diff not implemented yet"); + return; + +} + +/* {{{ proto resource git_patch_from_blobs(old_blob, old_as_path, new_blob, new_as_path, opts) +*/ +PHP_FUNCTION(git_patch_from_blobs) +{ + zval *old_blob; + php_git2_t *_old_blob; + char *old_as_path = {0}; + int old_as_path_len; + zval *new_blob; + php_git2_t *_new_blob; + char *new_as_path = {0}; + int new_as_path_len; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_from_blobs not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrsr", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &opts) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_patch_from_blob_and_buffer(old_blob, old_as_path, buffer, buffer_len, buffer_as_path, opts) +*/ +PHP_FUNCTION(git_patch_from_blob_and_buffer) +{ + zval *old_blob; + php_git2_t *_old_blob; + char *old_as_path = {0}; + int old_as_path_len; + char *buffer = {0}; + int buffer_len; + char *buffer_as_path = {0}; + int buffer_as_path_len; + zval *opts; + php_git2_t *_opts; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_from_blob_and_buffer not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsssr", &old_blob, &old_as_path, &old_as_path_len, &buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &opts) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_patch_free(patch) +*/ +PHP_FUNCTION(git_patch_free) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &patch) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_patch_get_delta(patch) +*/ +PHP_FUNCTION(git_patch_get_delta) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_get_delta not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &patch) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_patch_num_hunks(patch) +*/ +PHP_FUNCTION(git_patch_num_hunks) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_num_hunks not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &patch) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_patch_line_stats(total_context, total_additions, total_deletions, patch) +*/ +PHP_FUNCTION(git_patch_line_stats) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_line_stats not implemented yet"); + return; + +} + +/* {{{ proto resource git_patch_get_hunk(lines_in_hunk, patch, hunk_idx) +*/ +PHP_FUNCTION(git_patch_get_hunk) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_get_hunk not implemented yet"); + return; +} + +/* {{{ proto long git_patch_num_lines_in_hunk(patch, hunk_idx) +*/ +PHP_FUNCTION(git_patch_num_lines_in_hunk) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_num_lines_in_hunk not implemented yet"); + return; +} + +/* {{{ proto resource git_patch_get_line_in_hunk(patch, hunk_idx, line_of_hunk) +*/ +PHP_FUNCTION(git_patch_get_line_in_hunk) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_get_line_in_hunk not implemented yet"); + return; +} + +/* {{{ proto resource git_patch_size(patch, include_context, include_hunk_headers, include_file_headers) +*/ +PHP_FUNCTION(git_patch_size) +{ + zval *patch; + php_git2_t *_patch; + long include_context; + long include_hunk_headers; + long include_file_headers; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_size not implemented yet"); + return; +} + +/* {{{ proto long git_patch_print(patch, print_cb, payload) +*/ +PHP_FUNCTION(git_patch_print) +{ + zval *patch; + php_git2_t *_patch; + zval *print_cb; + php_git2_t *_print_cb; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_print not implemented yet"); + return; +} + +/* {{{ proto resource git_patch_to_str(patch) +*/ +PHP_FUNCTION(git_patch_to_str) +{ + zval *patch; + php_git2_t *_patch; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_to_str not implemented yet"); + return; +} diff --git a/patch.h b/patch.h new file mode 100644 index 0000000000..0be24e9138 --- /dev/null +++ b/patch.h @@ -0,0 +1,156 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_PATCH_H +#define PHP_GIT2_PATCH_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_from_diff, 0, 0, 2) + ZEND_ARG_INFO(0, diff) + ZEND_ARG_INFO(0, idx) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_from_blobs, 0, 0, 5) + ZEND_ARG_INFO(0, old_blob) + ZEND_ARG_INFO(0, old_as_path) + ZEND_ARG_INFO(0, new_blob) + ZEND_ARG_INFO(0, new_as_path) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_from_blob_and_buffer, 0, 0, 6) + ZEND_ARG_INFO(0, old_blob) + ZEND_ARG_INFO(0, old_as_path) + ZEND_ARG_INFO(0, buffer) + ZEND_ARG_INFO(0, buffer_len) + ZEND_ARG_INFO(0, buffer_as_path) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_free, 0, 0, 1) + ZEND_ARG_INFO(0, patch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_get_delta, 0, 0, 1) + ZEND_ARG_INFO(0, patch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_num_hunks, 0, 0, 1) + ZEND_ARG_INFO(0, patch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_line_stats, 0, 0, 4) + ZEND_ARG_INFO(0, total_context) + ZEND_ARG_INFO(0, total_additions) + ZEND_ARG_INFO(0, total_deletions) + ZEND_ARG_INFO(0, patch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_get_hunk, 0, 0, 3) + ZEND_ARG_INFO(0, lines_in_hunk) + ZEND_ARG_INFO(0, patch) + ZEND_ARG_INFO(0, hunk_idx) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_num_lines_in_hunk, 0, 0, 2) + ZEND_ARG_INFO(0, patch) + ZEND_ARG_INFO(0, hunk_idx) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_get_line_in_hunk, 0, 0, 3) + ZEND_ARG_INFO(0, patch) + ZEND_ARG_INFO(0, hunk_idx) + ZEND_ARG_INFO(0, line_of_hunk) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_size, 0, 0, 4) + ZEND_ARG_INFO(0, patch) + ZEND_ARG_INFO(0, include_context) + ZEND_ARG_INFO(0, include_hunk_headers) + ZEND_ARG_INFO(0, include_file_headers) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_print, 0, 0, 3) + ZEND_ARG_INFO(0, patch) + ZEND_ARG_INFO(0, print_cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_to_str, 0, 0, 1) + ZEND_ARG_INFO(0, patch) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_patch_from_diff(diff, idx) +*/ +PHP_FUNCTION(git_patch_from_diff); + +/* {{{ proto resource git_patch_from_blobs(old_blob, old_as_path, new_blob, new_as_path, opts) +*/ +PHP_FUNCTION(git_patch_from_blobs); + +/* {{{ proto resource git_patch_from_blob_and_buffer(old_blob, old_as_path, buffer, buffer_len, buffer_as_path, opts) +*/ +PHP_FUNCTION(git_patch_from_blob_and_buffer); + +/* {{{ proto void git_patch_free(patch) +*/ +PHP_FUNCTION(git_patch_free); + +/* {{{ proto resource git_patch_get_delta(patch) +*/ +PHP_FUNCTION(git_patch_get_delta); + +/* {{{ proto resource git_patch_num_hunks(patch) +*/ +PHP_FUNCTION(git_patch_num_hunks); + +/* {{{ proto long git_patch_line_stats(total_context, total_additions, total_deletions, patch) +*/ +PHP_FUNCTION(git_patch_line_stats); + +/* {{{ proto resource git_patch_get_hunk(lines_in_hunk, patch, hunk_idx) +*/ +PHP_FUNCTION(git_patch_get_hunk); + +/* {{{ proto long git_patch_num_lines_in_hunk(patch, hunk_idx) +*/ +PHP_FUNCTION(git_patch_num_lines_in_hunk); + +/* {{{ proto resource git_patch_get_line_in_hunk(patch, hunk_idx, line_of_hunk) +*/ +PHP_FUNCTION(git_patch_get_line_in_hunk); + +/* {{{ proto resource git_patch_size(patch, include_context, include_hunk_headers, include_file_headers) +*/ +PHP_FUNCTION(git_patch_size); + +/* {{{ proto long git_patch_print(patch, print_cb, payload) +*/ +PHP_FUNCTION(git_patch_print); + +/* {{{ proto resource git_patch_to_str(patch) +*/ +PHP_FUNCTION(git_patch_to_str); + +#endif \ No newline at end of file diff --git a/pathspec.c b/pathspec.c new file mode 100644 index 0000000000..aeec8300af --- /dev/null +++ b/pathspec.c @@ -0,0 +1,253 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "pathspec.h" + +/* {{{ proto resource git_pathspec_new(pathspec) +*/ +PHP_FUNCTION(git_pathspec_new) +{ + zval *pathspec; + php_git2_t *_pathspec; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_new not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &pathspec) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_pathspec, php_git2_t*, &pathspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_pathspec_free(ps) +*/ +PHP_FUNCTION(git_pathspec_free) +{ + zval *ps; + php_git2_t *_ps; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &ps) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto long git_pathspec_matches_path(ps, flags, path) +*/ +PHP_FUNCTION(git_pathspec_matches_path) +{ + zval *ps; + php_git2_t *_ps; + long flags; + char *path = {0}; + int path_len; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_matches_path not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rls", &ps, &flags, &path, &path_len) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_workdir(repo, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_workdir) +{ + zval *repo; + php_git2_t *_repo; + long flags; + zval *ps; + php_git2_t *_ps; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_workdir not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlr", &repo, &flags, &ps) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_index(index, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_index) +{ + zval *index; + php_git2_t *_index; + long flags; + zval *ps; + php_git2_t *_ps; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_index not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlr", &index, &flags, &ps) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_tree(tree, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_tree) +{ + zval *tree; + php_git2_t *_tree; + long flags; + zval *ps; + php_git2_t *_ps; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_tree not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlr", &tree, &flags, &ps) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_tree, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_diff(diff, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_diff) +{ + zval *diff; + php_git2_t *_diff; + long flags; + zval *ps; + php_git2_t *_ps; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_diff not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlr", &diff, &flags, &ps) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto void git_pathspec_match_list_free(m) +*/ +PHP_FUNCTION(git_pathspec_match_list_free) +{ + zval *m; + php_git2_t *_m; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_free not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &m) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_list_entrycount(m) +*/ +PHP_FUNCTION(git_pathspec_match_list_entrycount) +{ + zval *m; + php_git2_t *_m; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_entrycount not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &m) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_list_entry(m, pos) +*/ +PHP_FUNCTION(git_pathspec_match_list_entry) +{ + zval *m; + php_git2_t *_m; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_entry not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &m, &pos) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_list_diff_entry(m, pos) +*/ +PHP_FUNCTION(git_pathspec_match_list_diff_entry) +{ + zval *m; + php_git2_t *_m; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_diff_entry not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &m, &pos) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_list_failed_entrycount(m) +*/ +PHP_FUNCTION(git_pathspec_match_list_failed_entrycount) +{ + zval *m; + php_git2_t *_m; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_failed_entrycount not implemented yet"); + return; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &m) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + +/* {{{ proto resource git_pathspec_match_list_failed_entry(m, pos) +*/ +PHP_FUNCTION(git_pathspec_match_list_failed_entry) +{ + zval *m; + php_git2_t *_m; + + /* TODO(chobie): implement this */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_failed_entry not implemented yet"); + return; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &m, &pos) == FAILURE) { +// return; +// } +// ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +} + diff --git a/pathspec.h b/pathspec.h new file mode 100644 index 0000000000..bc57b43009 --- /dev/null +++ b/pathspec.h @@ -0,0 +1,146 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_PATHSPEC_H +#define PHP_GIT2_PATHSPEC_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_new, 0, 0, 1) + ZEND_ARG_INFO(0, pathspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_free, 0, 0, 1) + ZEND_ARG_INFO(0, ps) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_matches_path, 0, 0, 3) + ZEND_ARG_INFO(0, ps) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_workdir, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, ps) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_index, 0, 0, 3) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, ps) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_tree, 0, 0, 3) + ZEND_ARG_INFO(0, tree) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, ps) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_diff, 0, 0, 3) + ZEND_ARG_INFO(0, diff) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, ps) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_list_free, 0, 0, 1) + ZEND_ARG_INFO(0, m) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_list_entrycount, 0, 0, 1) + ZEND_ARG_INFO(0, m) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_list_entry, 0, 0, 2) + ZEND_ARG_INFO(0, m) + ZEND_ARG_INFO(0, pos) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_list_diff_entry, 0, 0, 2) + ZEND_ARG_INFO(0, m) + ZEND_ARG_INFO(0, pos) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_list_failed_entrycount, 0, 0, 1) + ZEND_ARG_INFO(0, m) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_pathspec_match_list_failed_entry, 0, 0, 2) + ZEND_ARG_INFO(0, m) + ZEND_ARG_INFO(0, pos) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_pathspec_new(pathspec) +*/ +PHP_FUNCTION(git_pathspec_new); + +/* {{{ proto void git_pathspec_free(ps) +*/ +PHP_FUNCTION(git_pathspec_free); + +/* {{{ proto long git_pathspec_matches_path(ps, flags, path) +*/ +PHP_FUNCTION(git_pathspec_matches_path); + +/* {{{ proto resource git_pathspec_match_workdir(repo, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_workdir); + +/* {{{ proto resource git_pathspec_match_index(index, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_index); + +/* {{{ proto resource git_pathspec_match_tree(tree, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_tree); + +/* {{{ proto resource git_pathspec_match_diff(diff, flags, ps) +*/ +PHP_FUNCTION(git_pathspec_match_diff); + +/* {{{ proto void git_pathspec_match_list_free(m) +*/ +PHP_FUNCTION(git_pathspec_match_list_free); + +/* {{{ proto resource git_pathspec_match_list_entrycount(m) +*/ +PHP_FUNCTION(git_pathspec_match_list_entrycount); + +/* {{{ proto resource git_pathspec_match_list_entry(m, pos) +*/ +PHP_FUNCTION(git_pathspec_match_list_entry); + +/* {{{ proto resource git_pathspec_match_list_diff_entry(m, pos) +*/ +PHP_FUNCTION(git_pathspec_match_list_diff_entry); + +/* {{{ proto resource git_pathspec_match_list_failed_entrycount(m) +*/ +PHP_FUNCTION(git_pathspec_match_list_failed_entrycount); + +/* {{{ proto resource git_pathspec_match_list_failed_entry(m, pos) +*/ +PHP_FUNCTION(git_pathspec_match_list_failed_entry); + +#endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 265b289405..ed7902864c 100644 --- a/php_git2.c +++ b/php_git2.c @@ -43,6 +43,14 @@ #include "cred.h" #include "remote.h" #include "transport.h" +#include "diff.h" +#include "checkout.h" +#include "filter.h" +#include "ignore.h" +#include "indexer.h" +#include "pathspec.h" +#include "patch.h" +#include "merge.h" int git2_resource_handle; @@ -425,6 +433,130 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_smart_subtransport_git, arginfo_git_smart_subtransport_git) PHP_FE(git_smart_subtransport_ssh, arginfo_git_smart_subtransport_ssh) + /* diff */ + PHP_FE(git_diff_free, arginfo_git_diff_free) + PHP_FE(git_diff_tree_to_tree, arginfo_git_diff_tree_to_tree) + PHP_FE(git_diff_tree_to_index, arginfo_git_diff_tree_to_index) + PHP_FE(git_diff_index_to_workdir, arginfo_git_diff_index_to_workdir) + PHP_FE(git_diff_tree_to_workdir, arginfo_git_diff_tree_to_workdir) + PHP_FE(git_diff_tree_to_workdir_with_index, arginfo_git_diff_tree_to_workdir_with_index) + PHP_FE(git_diff_merge, arginfo_git_diff_merge) + PHP_FE(git_diff_find_similar, arginfo_git_diff_find_similar) + PHP_FE(git_diff_options_init, arginfo_git_diff_options_init) + PHP_FE(git_diff_num_deltas, arginfo_git_diff_num_deltas) + PHP_FE(git_diff_num_deltas_of_type, arginfo_git_diff_num_deltas_of_type) + PHP_FE(git_diff_get_delta, arginfo_git_diff_get_delta) + PHP_FE(git_diff_is_sorted_icase, arginfo_git_diff_is_sorted_icase) + PHP_FE(git_diff_foreach, arginfo_git_diff_foreach) + PHP_FE(git_diff_status_char, arginfo_git_diff_status_char) + PHP_FE(git_diff_print, arginfo_git_diff_print) + PHP_FE(git_diff_blobs, arginfo_git_diff_blobs) + PHP_FE(git_diff_blob_to_buffer, arginfo_git_diff_blob_to_buffer) + + /* checkout */ + PHP_FE(git_checkout_head, arginfo_git_checkout_head) + PHP_FE(git_checkout_index, arginfo_git_checkout_index) + PHP_FE(git_checkout_tree, arginfo_git_checkout_tree) + + /* diff */ + PHP_FE(git_diff_free, arginfo_git_diff_free) + PHP_FE(git_diff_tree_to_tree, arginfo_git_diff_tree_to_tree) + PHP_FE(git_diff_tree_to_index, arginfo_git_diff_tree_to_index) + PHP_FE(git_diff_index_to_workdir, arginfo_git_diff_index_to_workdir) + PHP_FE(git_diff_tree_to_workdir, arginfo_git_diff_tree_to_workdir) + PHP_FE(git_diff_tree_to_workdir_with_index, arginfo_git_diff_tree_to_workdir_with_index) + PHP_FE(git_diff_merge, arginfo_git_diff_merge) + PHP_FE(git_diff_find_similar, arginfo_git_diff_find_similar) + PHP_FE(git_diff_options_init, arginfo_git_diff_options_init) + PHP_FE(git_diff_num_deltas, arginfo_git_diff_num_deltas) + PHP_FE(git_diff_num_deltas_of_type, arginfo_git_diff_num_deltas_of_type) + PHP_FE(git_diff_get_delta, arginfo_git_diff_get_delta) + PHP_FE(git_diff_is_sorted_icase, arginfo_git_diff_is_sorted_icase) + PHP_FE(git_diff_foreach, arginfo_git_diff_foreach) + PHP_FE(git_diff_status_char, arginfo_git_diff_status_char) + PHP_FE(git_diff_print, arginfo_git_diff_print) + PHP_FE(git_diff_blobs, arginfo_git_diff_blobs) + PHP_FE(git_diff_blob_to_buffer, arginfo_git_diff_blob_to_buffer) + + /* checkout */ + PHP_FE(git_checkout_head, arginfo_git_checkout_head) + PHP_FE(git_checkout_index, arginfo_git_checkout_index) + PHP_FE(git_checkout_tree, arginfo_git_checkout_tree) + + /* filter */ + PHP_FE(git_filter_list_load, arginfo_git_filter_list_load) + PHP_FE(git_filter_list_apply_to_data, arginfo_git_filter_list_apply_to_data) + PHP_FE(git_filter_list_apply_to_file, arginfo_git_filter_list_apply_to_file) + PHP_FE(git_filter_list_apply_to_blob, arginfo_git_filter_list_apply_to_blob) + PHP_FE(git_filter_list_free, arginfo_git_filter_list_free) + PHP_FE(git_filter_lookup, arginfo_git_filter_lookup) + PHP_FE(git_filter_list_new, arginfo_git_filter_list_new) + PHP_FE(git_filter_list_push, arginfo_git_filter_list_push) + PHP_FE(git_filter_list_length, arginfo_git_filter_list_length) + PHP_FE(git_filter_source_repo, arginfo_git_filter_source_repo) + PHP_FE(git_filter_source_path, arginfo_git_filter_source_path) + PHP_FE(git_filter_source_filemode, arginfo_git_filter_source_filemode) + PHP_FE(git_filter_source_id, arginfo_git_filter_source_id) + PHP_FE(git_filter_source_mode, arginfo_git_filter_source_mode) + PHP_FE(git_filter_register, arginfo_git_filter_register) + PHP_FE(git_filter_unregister, arginfo_git_filter_unregister) + + /* ignore */ + PHP_FE(git_ignore_add_rule, arginfo_git_ignore_add_rule) + PHP_FE(git_ignore_clear_internal_rules, arginfo_git_ignore_clear_internal_rules) + PHP_FE(git_ignore_path_is_ignored, arginfo_git_ignore_path_is_ignored) + + /* indexer */ + PHP_FE(git_indexer_new, arginfo_git_indexer_new) + PHP_FE(git_indexer_append, arginfo_git_indexer_append) + PHP_FE(git_indexer_commit, arginfo_git_indexer_commit) + PHP_FE(git_indexer_hash, arginfo_git_indexer_hash) + PHP_FE(git_indexer_free, arginfo_git_indexer_free) + + /* pathspec */ + PHP_FE(git_pathspec_new, arginfo_git_pathspec_new) + PHP_FE(git_pathspec_free, arginfo_git_pathspec_free) + PHP_FE(git_pathspec_matches_path, arginfo_git_pathspec_matches_path) + PHP_FE(git_pathspec_match_workdir, arginfo_git_pathspec_match_workdir) + PHP_FE(git_pathspec_match_index, arginfo_git_pathspec_match_index) + PHP_FE(git_pathspec_match_tree, arginfo_git_pathspec_match_tree) + PHP_FE(git_pathspec_match_diff, arginfo_git_pathspec_match_diff) + PHP_FE(git_pathspec_match_list_free, arginfo_git_pathspec_match_list_free) + PHP_FE(git_pathspec_match_list_entrycount, arginfo_git_pathspec_match_list_entrycount) + PHP_FE(git_pathspec_match_list_entry, arginfo_git_pathspec_match_list_entry) + PHP_FE(git_pathspec_match_list_diff_entry, arginfo_git_pathspec_match_list_diff_entry) + PHP_FE(git_pathspec_match_list_failed_entrycount, arginfo_git_pathspec_match_list_failed_entrycount) + PHP_FE(git_pathspec_match_list_failed_entry, arginfo_git_pathspec_match_list_failed_entry) + + /* patch */ + PHP_FE(git_patch_from_diff, arginfo_git_patch_from_diff) + PHP_FE(git_patch_from_blobs, arginfo_git_patch_from_blobs) + PHP_FE(git_patch_from_blob_and_buffer, arginfo_git_patch_from_blob_and_buffer) + PHP_FE(git_patch_free, arginfo_git_patch_free) + PHP_FE(git_patch_get_delta, arginfo_git_patch_get_delta) + PHP_FE(git_patch_num_hunks, arginfo_git_patch_num_hunks) + PHP_FE(git_patch_line_stats, arginfo_git_patch_line_stats) + PHP_FE(git_patch_get_hunk, arginfo_git_patch_get_hunk) + PHP_FE(git_patch_num_lines_in_hunk, arginfo_git_patch_num_lines_in_hunk) + PHP_FE(git_patch_get_line_in_hunk, arginfo_git_patch_get_line_in_hunk) + PHP_FE(git_patch_size, arginfo_git_patch_size) + PHP_FE(git_patch_print, arginfo_git_patch_print) + PHP_FE(git_patch_to_str, arginfo_git_patch_to_str) + + /* merge */ + PHP_FE(git_merge_base, arginfo_git_merge_base) + PHP_FE(git_merge_base_many, arginfo_git_merge_base_many) + PHP_FE(git_merge_head_from_ref, arginfo_git_merge_head_from_ref) + PHP_FE(git_merge_head_from_fetchhead, arginfo_git_merge_head_from_fetchhead) + PHP_FE(git_merge_head_from_oid, arginfo_git_merge_head_from_oid) + PHP_FE(git_merge_head_free, arginfo_git_merge_head_free) + PHP_FE(git_merge_trees, arginfo_git_merge_trees) + PHP_FE(git_merge, arginfo_git_merge) + PHP_FE(git_merge_result_is_uptodate, arginfo_git_merge_result_is_uptodate) + PHP_FE(git_merge_result_is_fastforward, arginfo_git_merge_result_is_fastforward) + PHP_FE(git_merge_result_fastforward_oid, arginfo_git_merge_result_fastforward_oid) + PHP_FE(git_merge_result_free, arginfo_git_merge_result_free) + PHP_FE_END }; diff --git a/php_git2.h b/php_git2.h index 2884f72663..a2b4457d41 100644 --- a/php_git2.h +++ b/php_git2.h @@ -93,6 +93,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_CRED, PHP_GIT2_TYPE_TRANSPORT, PHP_GIT2_TYPE_REMOTE, + PHP_GIT2_TYPE_DIFF, }; typedef struct php_git2_t { @@ -117,6 +118,7 @@ typedef struct php_git2_t { git_cred *cred; git_transport *transport; git_remote *remote; + git_diff *diff; } v; int should_free_v; int resource_id; From a0aabc14665089db23bd7fcc0f5b6e708987507d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 03:01:57 +0900 Subject: [PATCH 026/136] fix warnings --- php_git2.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/php_git2.c b/php_git2.c index ed7902864c..8eaec4e9f5 100644 --- a/php_git2.c +++ b/php_git2.c @@ -458,31 +458,6 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_checkout_index, arginfo_git_checkout_index) PHP_FE(git_checkout_tree, arginfo_git_checkout_tree) - /* diff */ - PHP_FE(git_diff_free, arginfo_git_diff_free) - PHP_FE(git_diff_tree_to_tree, arginfo_git_diff_tree_to_tree) - PHP_FE(git_diff_tree_to_index, arginfo_git_diff_tree_to_index) - PHP_FE(git_diff_index_to_workdir, arginfo_git_diff_index_to_workdir) - PHP_FE(git_diff_tree_to_workdir, arginfo_git_diff_tree_to_workdir) - PHP_FE(git_diff_tree_to_workdir_with_index, arginfo_git_diff_tree_to_workdir_with_index) - PHP_FE(git_diff_merge, arginfo_git_diff_merge) - PHP_FE(git_diff_find_similar, arginfo_git_diff_find_similar) - PHP_FE(git_diff_options_init, arginfo_git_diff_options_init) - PHP_FE(git_diff_num_deltas, arginfo_git_diff_num_deltas) - PHP_FE(git_diff_num_deltas_of_type, arginfo_git_diff_num_deltas_of_type) - PHP_FE(git_diff_get_delta, arginfo_git_diff_get_delta) - PHP_FE(git_diff_is_sorted_icase, arginfo_git_diff_is_sorted_icase) - PHP_FE(git_diff_foreach, arginfo_git_diff_foreach) - PHP_FE(git_diff_status_char, arginfo_git_diff_status_char) - PHP_FE(git_diff_print, arginfo_git_diff_print) - PHP_FE(git_diff_blobs, arginfo_git_diff_blobs) - PHP_FE(git_diff_blob_to_buffer, arginfo_git_diff_blob_to_buffer) - - /* checkout */ - PHP_FE(git_checkout_head, arginfo_git_checkout_head) - PHP_FE(git_checkout_index, arginfo_git_checkout_index) - PHP_FE(git_checkout_tree, arginfo_git_checkout_tree) - /* filter */ PHP_FE(git_filter_list_load, arginfo_git_filter_list_load) PHP_FE(git_filter_list_apply_to_data, arginfo_git_filter_list_apply_to_data) @@ -572,6 +547,7 @@ PHP_MINFO_FUNCTION(git2) php_info_print_table_start(); php_info_print_table_header(2, "Git2 Support", "enabled"); + php_info_print_table_header(2, "libgit2 version", buf); php_info_print_table_end(); } From 18fc8310ea35c9d390bf97b1a1a198765c94d886 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 11:56:46 +0900 Subject: [PATCH 027/136] [ignore] add functions --- ignore.c | 82 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/ignore.c b/ignore.c index 1713f03fe8..c77e30754b 100644 --- a/ignore.c +++ b/ignore.c @@ -2,62 +2,74 @@ #include "php_git2_priv.h" #include "ignore.h" -/* {{{ proto long git_ignore_add_rule(repo, rules) -*/ +/* {{{ proto long git_ignore_add_rule(resource $repo, string $rules) + */ PHP_FUNCTION(git_ignore_add_rule) { - zval *repo; - php_git2_t *_repo; - char *rules = {0}; - int rules_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_ignore_add_rule not implemented yet"); - return; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *rules = NULL; + int rules_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &rules, &rules_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_ignore_add_rule(PHP_GIT2_V(_repo, repository), rules); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_ignore_clear_internal_rules(repo) -*/ + +/* {{{ proto long git_ignore_clear_internal_rules(resource $repo) + */ PHP_FUNCTION(git_ignore_clear_internal_rules) { - zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_ignore_clear_internal_rules not implemented yet"); - return; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_ignore_clear_internal_rules(PHP_GIT2_V(_repo, repository)); + RETURN_LONG(result); } +/* }}} */ + -/* {{{ proto long git_ignore_path_is_ignored(ignored, repo, path) -*/ +/* {{{ proto long git_ignore_path_is_ignored(resource $repo, string $path) + */ PHP_FUNCTION(git_ignore_path_is_ignored) { - long ignored; - zval *repo; - php_git2_t *_repo; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_ignore_path_is_ignored not implemented yet"); - return; -// -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "lrs", &ignored, &repo, &path, &path_len) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_ignored, php_git2_t*, &ignored, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + int result = 0; + long ignored = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *path = NULL; + int path_len = 0; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &path, &path_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_ignore_path_is_ignored(&ignored, PHP_GIT2_V(_repo, repository), path); + if (php_git2_check_error(error, "git_ignore_path_is_ignored" TSRMLS_CC)) { + RETURN_FALSE + } + + RETURN_LONG(ignored); } +/* }}} */ From a0e898879fb8b4ad8cfd91e254c480c433c21f30 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 12:10:26 +0900 Subject: [PATCH 028/136] [merge] add stub codes --- merge.c | 347 +++++++++++++++++++++++++++++++++++------------------ ng.php | 2 + php_git2.h | 4 + 3 files changed, 233 insertions(+), 120 deletions(-) diff --git a/merge.c b/merge.c index a3207beaf6..d0a551b3fd 100644 --- a/merge.c +++ b/merge.c @@ -2,27 +2,43 @@ #include "php_git2_priv.h" #include "merge.h" -/* {{{ proto resource git_merge_base(repo, one, two) -*/ +/* {{{ proto resource git_merge_base(resource $repo, string $one, string $two) + */ PHP_FUNCTION(git_merge_base) { - zval *repo; - php_git2_t *_repo; - char *one = {0}; - int one_len; - char *two = {0}; - int two_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_base not implemented yet"); - return; + git_oid out = {0}; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *one = NULL; + int one_len = 0; + git_oid __one; + char *two = NULL; + int two_len = 0; + git_oid __two; + int error = 0; + char result[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &repo, &one, &one_len, &two, &two_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__one, one, one_len)) { + RETURN_FALSE; + } + if (git_oid_fromstrn(&__two, two, two_len)) { + RETURN_FALSE; + } + error = git_merge_base(&out, PHP_GIT2_V(_repo, repository), &__one, &__two); + if (php_git2_check_error(error, "git_merge_base" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(result, &out); + RETURN_STRING(result, 1); } +/* }}} */ + /* {{{ proto resource git_merge_base_many(repo, length, input_array[]) */ @@ -44,205 +60,296 @@ PHP_FUNCTION(git_merge_base_many) // ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto resource git_merge_head_from_ref(repo, ref) -*/ +/* {{{ proto resource git_merge_head_from_ref(resource $repo, resource $ref) + */ PHP_FUNCTION(git_merge_head_from_ref) { - zval *repo; - php_git2_t *_repo; - zval *ref; - php_git2_t *_ref; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_from_ref not implemented yet"); - return; + php_git2_t *result = NULL; + git_merge_head *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *ref = NULL; + php_git2_t *_ref = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &repo, &ref) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_merge_head_from_ref(&out, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_ref, reference)); + if (php_git2_check_error(error, "git_merge_head_from_ref" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, merge_head) = out; + result->type = PHP_GIT2_TYPE_MERGE_HEAD; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_merge_head_from_fetchhead(repo, branch_name, remote_url, oid) -*/ +/* {{{ proto resource git_merge_head_from_fetchhead(resource $repo, string $branch_name, string $remote_url, string $oid) + */ PHP_FUNCTION(git_merge_head_from_fetchhead) { - zval *repo; - php_git2_t *_repo; - char *branch_name = {0}; - int branch_name_len; - char *remote_url = {0}; - int remote_url_len; - char *oid = {0}; - int oid_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_from_fetchhead not implemented yet"); - return; + php_git2_t *result = NULL; + git_merge_head *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *branch_name = NULL; + int branch_name_len = 0; + char *remote_url = NULL; + int remote_url_len = 0; + char *oid = NULL; + int oid_len = 0; + git_oid __oid; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &repo, &branch_name, &branch_name_len, &remote_url, &remote_url_len, &oid, &oid_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__oid, oid, oid_len)) { + RETURN_FALSE; + } + error = git_merge_head_from_fetchhead(&out, PHP_GIT2_V(_repo, repository), branch_name, remote_url, &__oid); + if (php_git2_check_error(error, "git_merge_head_from_fetchhead" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, merge_head) = out; + result->type = PHP_GIT2_TYPE_MERGE_HEAD; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_merge_head_from_oid(repo, oid) -*/ + +/* {{{ proto resource git_merge_head_from_oid(resource $repo, string $oid) + */ PHP_FUNCTION(git_merge_head_from_oid) { - zval *repo; - php_git2_t *_repo; - char *oid = {0}; - int oid_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_from_oid not implemented yet"); - return; + php_git2_t *result = NULL; + git_merge_head *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *oid = NULL; + int oid_len = 0; + git_oid __oid; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &oid, &oid_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__oid, oid, oid_len)) { + RETURN_FALSE; + } + error = git_merge_head_from_oid(&out, PHP_GIT2_V(_repo, repository), &__oid); + if (php_git2_check_error(error, "git_merge_head_from_oid" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, merge_head) = out; + result->type = PHP_GIT2_TYPE_MERGE_HEAD; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto void git_merge_head_free(head) -*/ + +/* {{{ proto void git_merge_head_free(resource $head) + */ PHP_FUNCTION(git_merge_head_free) { - zval *head; - php_git2_t *_head; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_head_free not implemented yet"); - return; + zval *head = NULL; + php_git2_t *_head = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &head) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_head, php_git2_t*, &head, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_head->should_free_v) { + git_merge_head_free(PHP_GIT2_V(_head, merge_head)); + }; + zval_ptr_dtor(&head); } +/* }}} */ -/* {{{ proto resource git_merge_trees(repo, ancestor_tree, our_tree, their_tree, opts) -*/ + +/* {{{ proto resource git_merge_trees(resource $repo, resource $ancestor_tree, resource $our_tree, resource $their_tree, $opts) + */ PHP_FUNCTION(git_merge_trees) { - zval *repo; - php_git2_t *_repo; - zval *ancestor_tree; - php_git2_t *_ancestor_tree; - zval *our_tree; - php_git2_t *_our_tree; - zval *their_tree; - php_git2_t *_their_tree; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_trees not implemented yet"); - return; - + php_git2_t *result = NULL; + git_index *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *ancestor_tree = NULL; + php_git2_t *_ancestor_tree = NULL; + zval *our_tree = NULL; + php_git2_t *_our_tree = NULL; + zval *their_tree = NULL; + php_git2_t *_their_tree = NULL; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): create array converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrrrr", &repo, &ancestor_tree, &our_tree, &their_tree, &opts) == FAILURE) { + "rrrra", &repo, &ancestor_tree, &our_tree, &their_tree, &opts) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_ancestor_tree, php_git2_t*, &ancestor_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_our_tree, php_git2_t*, &our_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_their_tree, php_git2_t*, &their_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_merge_trees(&out, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_ancestor_tree, tree), PHP_GIT2_V(_our_tree, tree), PHP_GIT2_V(_their_tree, tree), opts); + if (php_git2_check_error(error, "git_merge_trees" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, index) = out; + result->type = PHP_GIT2_TYPE_INDEX; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_merge(repo, their_heads, their_heads_len, opts) -*/ + + +/* {{{ proto resource git_merge(resource $repo, long $their_heads_len, $opts) + */ PHP_FUNCTION(git_merge) { - zval *repo; - php_git2_t *_repo; - zval *their_heads; - php_git2_t *_their_heads; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge not implemented yet"); - return; + php_git2_t *result = NULL; + git_merge_result *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + git_merge_head *their_heads = NULL; + long their_heads_len = 0; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): implement converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rla", &repo, &their_heads_len, &opts) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rrr", &repo, &their_heads, &their_heads_len, &opts) == FAILURE) { -// return; -// } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + //error = git_merge(&out, PHP_GIT2_V(_repo, repository), &their_heads, their_heads_len, opts); + if (php_git2_check_error(error, "git_merge" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, merge_result) = out; + result->type = PHP_GIT2_TYPE_MERGE_RESULT; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto long git_merge_result_is_uptodate(merge_result) -*/ + +/* {{{ proto long git_merge_result_is_uptodate(resource $merge_result) + */ PHP_FUNCTION(git_merge_result_is_uptodate) { - zval *merge_result; - php_git2_t *_merge_result; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_is_uptodate not implemented yet"); - return; + int result = 0; + zval *merge_result = NULL; + php_git2_t *_merge_result = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_merge_result_is_uptodate(PHP_GIT2_V(_merge_result, merge_result)); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto long git_merge_result_is_fastforward(merge_result) -*/ + +/* {{{ proto long git_merge_result_is_fastforward(resource $merge_result) + */ PHP_FUNCTION(git_merge_result_is_fastforward) { - zval *merge_result; - php_git2_t *_merge_result; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_is_fastforward not implemented yet"); - return; + int result = 0; + zval *merge_result = NULL; + php_git2_t *_merge_result = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_merge_result_is_fastforward(PHP_GIT2_V(_merge_result, merge_result)); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_merge_result_fastforward_oid(merge_result) -*/ + +/* {{{ proto resource git_merge_result_fastforward_oid(resource $merge_result) + */ PHP_FUNCTION(git_merge_result_fastforward_oid) { - zval *merge_result; - php_git2_t *_merge_result; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_fastforward_oid not implemented yet"); - return; + php_git2_t *result = NULL; + git_oid out = {0}; + zval *merge_result = NULL; + php_git2_t *_merge_result = NULL; + int error = 0; + char buffer[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_merge_result_fastforward_oid(&out, PHP_GIT2_V(_merge_result, merge_result)); + if (php_git2_check_error(error, "git_merge_result_fastforward_oid" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(buffer, &out); + RETURN_STRING(buffer, 1); } +/* }}} */ -/* {{{ proto void git_merge_result_free(merge_result) -*/ +/* {{{ proto void git_merge_result_free(resource $merge_result) + */ PHP_FUNCTION(git_merge_result_free) { - zval *merge_result; - php_git2_t *_merge_result; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_result_free not implemented yet"); - return; + zval *merge_result = NULL; + php_git2_t *_merge_result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_merge_result->should_free_v) { + git_merge_result_free(PHP_GIT2_V(_merge_result, merge_result)); + }; + zval_ptr_dtor(&merge_result); } +/* }}} */ diff --git a/ng.php b/ng.php index 99e69e1448..1f4669fd4c 100644 --- a/ng.php +++ b/ng.php @@ -348,6 +348,8 @@ public function shouldResource(Arg $arg) "git_cred", "git_transport", "git_remote", + "git_merge_head", + "git_merge_result", ); } diff --git a/php_git2.h b/php_git2.h index a2b4457d41..64c0128982 100644 --- a/php_git2.h +++ b/php_git2.h @@ -94,6 +94,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_TRANSPORT, PHP_GIT2_TYPE_REMOTE, PHP_GIT2_TYPE_DIFF, + PHP_GIT2_TYPE_MERGE_RESULT, + PHP_GIT2_TYPE_MERGE_HEAD, }; typedef struct php_git2_t { @@ -119,6 +121,8 @@ typedef struct php_git2_t { git_transport *transport; git_remote *remote; git_diff *diff; + git_merge_result *merge_result; + git_merge_head *merge_head; } v; int should_free_v; int resource_id; From d7998414b2bbb995e974b6cc39ab7561f2524447 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 12:14:04 +0900 Subject: [PATCH 029/136] [checkout] add stub codes --- checkout.c | 85 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/checkout.c b/checkout.c index 2e5e96fe26..4d751869df 100644 --- a/checkout.c +++ b/checkout.c @@ -1,67 +1,78 @@ #include "php_git2.h" #include "php_git2_priv.h" #include "checkout.h" -/* {{{ proto long git_checkout_head(repo, opts) -*/ + +/* {{{ proto long git_checkout_head(resource $repo, $opts) + */ PHP_FUNCTION(git_checkout_head) { - zval *repo; - php_git2_t *_repo; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_checkout_head not implemented yet"); - return; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *opts = NULL; + int error = 0; + /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &repo, &opts) == FAILURE) { + "ra", &repo, &opts) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_checkout_head(PHP_GIT2_V(_repo, repository), opts); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_checkout_index(repo, index, opts) -*/ + +/* {{{ proto long git_checkout_index(resource $repo, resource $index, $opts) + */ PHP_FUNCTION(git_checkout_index) { - zval *repo; - php_git2_t *_repo; - zval *index; - php_git2_t *_index; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_checkout_index not implemented yet"); - return; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *index = NULL; + php_git2_t *_index = NULL; + zval *opts = NULL; + int error = 0; + /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrr", &repo, &index, &opts) == FAILURE) { + "rra", &repo, &index, &opts) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_checkout_index(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_index, index), opts); + RETURN_LONG(result); } +/* }}} */ + -/* {{{ proto long git_checkout_tree(repo, treeish, opts) -*/ +/* {{{ proto long git_checkout_tree(resource $repo, resource $treeish, $opts) + */ PHP_FUNCTION(git_checkout_tree) { - zval *repo; - php_git2_t *_repo; - zval *treeish; - php_git2_t *_treeish; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_checkout_tree not implemented yet"); - return; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *treeish = NULL; + php_git2_t *_treeish = NULL; + zval *opts = NULL; + int error = 0; + /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrr", &repo, &treeish, &opts) == FAILURE) { + "rra", &repo, &treeish, &opts) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_treeish, php_git2_t*, &treeish, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_checkout_tree(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_treeish, object), opts); + RETURN_LONG(result); } +/* }}} */ From d98c8867e02ebe5513ff1130f423c1b00fa0abd3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 12:23:16 +0900 Subject: [PATCH 030/136] [pathspec] add stub codes --- ng.php | 3 + pathspec.c | 354 +++++++++++++++++++++++++++++++++-------------------- php_git2.h | 4 + 3 files changed, 226 insertions(+), 135 deletions(-) diff --git a/ng.php b/ng.php index 1f4669fd4c..18cac448be 100644 --- a/ng.php +++ b/ng.php @@ -350,6 +350,9 @@ public function shouldResource(Arg $arg) "git_remote", "git_merge_head", "git_merge_result", + "git_pathspec", + "git_pathspec_match_list", + "git_diff", ); } diff --git a/pathspec.c b/pathspec.c index aeec8300af..7c1d328848 100644 --- a/pathspec.c +++ b/pathspec.c @@ -2,252 +2,336 @@ #include "php_git2_priv.h" #include "pathspec.h" -/* {{{ proto resource git_pathspec_new(pathspec) -*/ +/* {{{ proto resource git_pathspec_new(array $pathspec) + */ PHP_FUNCTION(git_pathspec_new) { - zval *pathspec; - php_git2_t *_pathspec; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_pathspec *out; + zval *pathspec = NULL; + int error = 0; + /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &pathspec) == FAILURE) { + "a", &pathspec) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_pathspec, php_git2_t*, &pathspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + error = git_pathspec_new(&out, pathspec); + if (php_git2_check_error(error, "git_pathspec_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, pathspec) = out; + result->type = PHP_GIT2_TYPE_PATHSPEC; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + -/* {{{ proto void git_pathspec_free(ps) -*/ +/* {{{ proto void git_pathspec_free(resource $ps) + */ PHP_FUNCTION(git_pathspec_free) { - zval *ps; - php_git2_t *_ps; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_free not implemented yet"); - return; + zval *ps = NULL; + php_git2_t *_ps = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ps) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_ps->should_free_v) { + git_pathspec_free(PHP_GIT2_V(_ps, pathspec)); + }; + zval_ptr_dtor(&ps); } +/* }}} */ + -/* {{{ proto long git_pathspec_matches_path(ps, flags, path) -*/ +/* {{{ proto long git_pathspec_matches_path(resource $ps, long $flags, string $path) + */ PHP_FUNCTION(git_pathspec_matches_path) { - zval *ps; - php_git2_t *_ps; - long flags; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_matches_path not implemented yet"); - return; + int result = 0; + zval *ps = NULL; + php_git2_t *_ps = NULL; + long flags = 0; + char *path = NULL; + int path_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &ps, &flags, &path, &path_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_pathspec_matches_path(PHP_GIT2_V(_ps, pathspec), flags, path); + RETURN_LONG(result); } +/* }}} */ + -/* {{{ proto resource git_pathspec_match_workdir(repo, flags, ps) -*/ +/* {{{ proto resource git_pathspec_match_workdir(resource $repo, long $flags, resource $ps) + */ PHP_FUNCTION(git_pathspec_match_workdir) { - zval *repo; - php_git2_t *_repo; - long flags; - zval *ps; - php_git2_t *_ps; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_workdir not implemented yet"); - return; + php_git2_t *result = NULL; + git_pathspec_match_list *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + long flags = 0; + zval *ps = NULL; + php_git2_t *_ps = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlr", &repo, &flags, &ps) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_pathspec_match_workdir(&out, PHP_GIT2_V(_repo, repository), flags, PHP_GIT2_V(_ps, pathspec)); + if (php_git2_check_error(error, "git_pathspec_match_workdir" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, pathspec_match_list) = out; + result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + -/* {{{ proto resource git_pathspec_match_index(index, flags, ps) -*/ +/* {{{ proto resource git_pathspec_match_index(resource $index, long $flags, resource $ps) + */ PHP_FUNCTION(git_pathspec_match_index) { - zval *index; - php_git2_t *_index; - long flags; - zval *ps; - php_git2_t *_ps; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_index not implemented yet"); - return; + php_git2_t *result = NULL; + git_pathspec_match_list *out = NULL; + zval *index = NULL; + php_git2_t *_index = NULL; + long flags = 0; + zval *ps = NULL; + php_git2_t *_ps = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlr", &index, &flags, &ps) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_pathspec_match_index(&out, PHP_GIT2_V(_index, index), flags, PHP_GIT2_V(_ps, pathspec)); + if (php_git2_check_error(error, "git_pathspec_match_index" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, pathspec_match_list) = out; + result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_pathspec_match_tree(tree, flags, ps) -*/ + +/* {{{ proto resource git_pathspec_match_tree(resource $tree, long $flags, resource $ps) + */ PHP_FUNCTION(git_pathspec_match_tree) { - zval *tree; - php_git2_t *_tree; - long flags; - zval *ps; - php_git2_t *_ps; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_tree not implemented yet"); - return; + php_git2_t *result = NULL; + git_pathspec_match_list *out = NULL; + zval *tree = NULL; + php_git2_t *_tree = NULL; + long flags = 0; + zval *ps = NULL; + php_git2_t *_ps = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlr", &tree, &flags, &ps) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_tree, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_pathspec_match_tree(&out, PHP_GIT2_V(_tree, tree), flags, PHP_GIT2_V(_ps, pathspec)); + if (php_git2_check_error(error, "git_pathspec_match_tree" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, pathspec_match_list) = out; + result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_pathspec_match_diff(diff, flags, ps) -*/ + +/* {{{ proto resource git_pathspec_match_diff(resource $diff, long $flags, resource $ps) + */ PHP_FUNCTION(git_pathspec_match_diff) { - zval *diff; - php_git2_t *_diff; - long flags; - zval *ps; - php_git2_t *_ps; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_diff not implemented yet"); - return; + php_git2_t *result = NULL; + git_pathspec_match_list *out = NULL; + zval *diff = NULL; + php_git2_t *_diff = NULL; + long flags = 0; + zval *ps = NULL; + php_git2_t *_ps = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlr", &diff, &flags, &ps) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_pathspec_match_diff(&out, PHP_GIT2_V(_diff, diff), flags, PHP_GIT2_V(_ps, pathspec)); + if (php_git2_check_error(error, "git_pathspec_match_diff" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, pathspec_match_list) = out; + result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + -/* {{{ proto void git_pathspec_match_list_free(m) -*/ +/* {{{ proto void git_pathspec_match_list_free(resource $m) + */ PHP_FUNCTION(git_pathspec_match_list_free) { - zval *m; - php_git2_t *_m; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_free not implemented yet"); - return; + zval *m = NULL; + php_git2_t *_m = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &m) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_m->should_free_v) { + git_pathspec_match_list_free(PHP_GIT2_V(_m, pathspec_match_list)); + }; + zval_ptr_dtor(&m); } +/* }}} */ + -/* {{{ proto resource git_pathspec_match_list_entrycount(m) -*/ +/* {{{ proto long git_pathspec_match_list_entrycount(resource $m) + */ PHP_FUNCTION(git_pathspec_match_list_entrycount) { - zval *m; - php_git2_t *_m; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_entrycount not implemented yet"); - return; + size_t result = 0; + zval *m = NULL; + php_git2_t *_m = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &m) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_pathspec_match_list_entrycount(PHP_GIT2_V(_m, pathspec_match_list)); + RETURN_LONG(result); } +/* }}} */ + -/* {{{ proto resource git_pathspec_match_list_entry(m, pos) -*/ +/* {{{ proto string git_pathspec_match_list_entry(resource $m, long $pos) + */ PHP_FUNCTION(git_pathspec_match_list_entry) { - zval *m; - php_git2_t *_m; + const char *result = NULL; + zval *m = NULL; + php_git2_t *_m = NULL; + long pos = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_entry not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &m, &pos) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &m, &pos) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_pathspec_match_list_entry(PHP_GIT2_V(_m, pathspec_match_list), pos); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_pathspec_match_list_diff_entry(m, pos) -*/ + +/* {{{ proto resource git_pathspec_match_list_diff_entry(resource $m, long $pos) + */ PHP_FUNCTION(git_pathspec_match_list_diff_entry) { - zval *m; - php_git2_t *_m; + const git_diff_delta *result = NULL; + zval *m = NULL; + php_git2_t *_m = NULL; + long pos = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &m, &pos) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_pathspec_match_list_diff_entry(PHP_GIT2_V(_m, pathspec_match_list), pos); /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_diff_entry not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &m, &pos) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } +/* }}} */ + -/* {{{ proto resource git_pathspec_match_list_failed_entrycount(m) -*/ +/* {{{ proto long git_pathspec_match_list_failed_entrycount(resource $m) + */ PHP_FUNCTION(git_pathspec_match_list_failed_entrycount) { - zval *m; - php_git2_t *_m; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_failed_entrycount not implemented yet"); - return; + size_t result = 0; + zval *m = NULL; + php_git2_t *_m = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &m) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_pathspec_match_list_failed_entrycount(PHP_GIT2_V(_m, pathspec_match_list)); + RETURN_LONG(result); } +/* }}} */ + -/* {{{ proto resource git_pathspec_match_list_failed_entry(m, pos) -*/ +/* {{{ proto string git_pathspec_match_list_failed_entry(resource $m, long $pos) + */ PHP_FUNCTION(git_pathspec_match_list_failed_entry) { - zval *m; - php_git2_t *_m; + const char *result = NULL; + zval *m = NULL; + php_git2_t *_m = NULL; + long pos = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_pathspec_match_list_failed_entry not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &m, &pos) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &m, &pos) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_pathspec_match_list_failed_entry(PHP_GIT2_V(_m, pathspec_match_list), pos); + RETURN_STRING(result, 1); } +/* }}} */ diff --git a/php_git2.h b/php_git2.h index 64c0128982..943c44b74e 100644 --- a/php_git2.h +++ b/php_git2.h @@ -96,6 +96,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_DIFF, PHP_GIT2_TYPE_MERGE_RESULT, PHP_GIT2_TYPE_MERGE_HEAD, + PHP_GIT2_TYPE_PATHSPEC, + PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, }; typedef struct php_git2_t { @@ -123,6 +125,8 @@ typedef struct php_git2_t { git_diff *diff; git_merge_result *merge_result; git_merge_head *merge_head; + git_pathspec *pathspec; + git_pathspec_match_list *pathspec_match_list; } v; int should_free_v; int resource_id; From 6def3e86f13d2f4b77ee2c8dc73ec471feb45dc3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 12:29:41 +0900 Subject: [PATCH 031/136] [diff] add stub codes --- diff.c | 287 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 261 insertions(+), 26 deletions(-) diff --git a/diff.c b/diff.c index c3016b7d27..a3c772df0a 100644 --- a/diff.c +++ b/diff.c @@ -2,83 +2,318 @@ #include "php_git2_priv.h" #include "diff.h" -/* {{{ proto void git_diff_free(diff) -*/ +/* {{{ proto void git_diff_free(resource $diff) + */ PHP_FUNCTION(git_diff_free) { + zval *diff = NULL; + php_git2_t *_diff = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &diff) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_diff->should_free_v) { + git_diff_free(PHP_GIT2_V(_diff, diff)); + }; + zval_ptr_dtor(&diff); } +/* }}} */ -/* {{{ proto resource git_diff_tree_to_tree(repo, old_tree, new_tree, opts) -*/ + +/* {{{ proto long git_diff_tree_to_tree(resource $repo, resource $old_tree, resource $new_tree, $opts) + */ PHP_FUNCTION(git_diff_tree_to_tree) { + int result = 0; + git_diff *diff = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *old_tree = NULL; + php_git2_t *_old_tree = NULL; + zval *new_tree = NULL; + php_git2_t *_new_tree = NULL; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrra", &repo, &old_tree, &new_tree, &opts) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_new_tree, php_git2_t*, &new_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_tree_to_tree(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), PHP_GIT2_V(_new_tree, tree), opts); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_diff_tree_to_index(repo, old_tree, index, opts) -*/ + +/* {{{ proto long git_diff_tree_to_index(resource $repo, resource $old_tree, resource $index, $opts) + */ PHP_FUNCTION(git_diff_tree_to_index) { + int result = 0; + git_diff *diff = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *old_tree = NULL; + php_git2_t *_old_tree = NULL; + zval *index = NULL; + php_git2_t *_index = NULL; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrra", &repo, &old_tree, &index, &opts) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_tree_to_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), PHP_GIT2_V(_index, index), opts); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_diff_index_to_workdir(repo, index, opts) -*/ + +/* {{{ proto long git_diff_index_to_workdir(resource $repo, resource $index, $opts) + */ PHP_FUNCTION(git_diff_index_to_workdir) { + int result = 0; + git_diff *diff = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *index = NULL; + php_git2_t *_index = NULL; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rra", &repo, &index, &opts) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_index_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_index, index), opts); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_diff_tree_to_workdir(repo, old_tree, opts) -*/ + +/* {{{ proto long git_diff_tree_to_workdir(resource $repo, resource $old_tree, $opts) + */ PHP_FUNCTION(git_diff_tree_to_workdir) { + int result = 0; + git_diff *diff = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *old_tree = NULL; + php_git2_t *_old_tree = NULL; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rra", &repo, &old_tree, &opts) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_diff_tree_to_workdir_with_index(repo, old_tree, opts) -*/ + +/* {{{ proto long git_diff_tree_to_workdir_with_index(resource $repo, resource $old_tree, $opts) + */ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) { + int result = 0; + git_diff *diff = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *old_tree = NULL; + php_git2_t *_old_tree = NULL; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rra", &repo, &old_tree, &opts) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_tree_to_workdir_with_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_diff_merge(onto, from) -*/ + +/* {{{ proto long git_diff_merge(resource $onto, resource $from) + */ PHP_FUNCTION(git_diff_merge) { + int result = 0; + zval *onto = NULL; + php_git2_t *_onto = NULL; + zval *from = NULL; + php_git2_t *_from = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &onto, &from) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_onto, php_git2_t*, &onto, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_from, php_git2_t*, &from, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_merge(PHP_GIT2_V(_onto, diff), PHP_GIT2_V(_from, diff)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_diff_find_similar(diff, options) -*/ + +/* {{{ proto long git_diff_find_similar(resource $diff, $options) + */ PHP_FUNCTION(git_diff_find_similar) { + int result = 0; + zval *diff = NULL; + php_git2_t *_diff = NULL; + zval *options = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ra", &diff, &options) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_find_similar(PHP_GIT2_V(_diff, diff), options); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_diff_options_init(options, version) -*/ + +/* {{{ proto long git_diff_options_init( $options, long $version) + */ PHP_FUNCTION(git_diff_options_init) { + int result = 0; + zval *options = NULL; + long version = 0; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "al", &options, &version) == FAILURE) { + return; + } + + result = git_diff_options_init(options, version); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_diff_num_deltas(diff) -*/ + +/* {{{ proto long git_diff_num_deltas(resource $diff) + */ PHP_FUNCTION(git_diff_num_deltas) { + size_t result = 0; + zval *diff = NULL; + php_git2_t *_diff = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &diff) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_num_deltas(PHP_GIT2_V(_diff, diff)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_diff_num_deltas_of_type(diff, type) -*/ + +/* {{{ proto long git_diff_num_deltas_of_type(resource $diff, $type) + */ PHP_FUNCTION(git_diff_num_deltas_of_type) { + size_t result = 0; + zval *diff = NULL; + php_git2_t *_diff = NULL; + long type = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &diff, &type) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_num_deltas_of_type(PHP_GIT2_V(_diff, diff), type); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_diff_get_delta(diff, idx) -*/ + +/* {{{ proto resource git_diff_get_delta(resource $diff, long $idx) + */ PHP_FUNCTION(git_diff_get_delta) { + const git_diff_delta *result = NULL; + zval *diff = NULL; + php_git2_t *_diff = NULL; + long idx = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &diff, &idx) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_get_delta(PHP_GIT2_V(_diff, diff), idx); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto long git_diff_is_sorted_icase(diff) -*/ + +/* {{{ proto long git_diff_is_sorted_icase(resource $diff) + */ PHP_FUNCTION(git_diff_is_sorted_icase) { + int result = 0; + zval *diff = NULL; + php_git2_t *_diff = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &diff) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_is_sorted_icase(PHP_GIT2_V(_diff, diff)); + RETURN_BOOL(result); } +/* }}} */ + /* {{{ proto long git_diff_foreach(diff, file_cb, hunk_cb, line_cb, payload) */ From 6ff8f5c5e12f11da3c94321df7d366dc7debf5b4 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 12:46:18 +0900 Subject: [PATCH 032/136] [patch] add stub codes --- ng.php | 2 + patch.c | 351 ++++++++++++++++++++++++++++++++++++----------------- php_git2.h | 4 + 3 files changed, 245 insertions(+), 112 deletions(-) diff --git a/ng.php b/ng.php index 18cac448be..fb30e928e9 100644 --- a/ng.php +++ b/ng.php @@ -353,6 +353,8 @@ public function shouldResource(Arg $arg) "git_pathspec", "git_pathspec_match_list", "git_diff", + "git_patch", + "git_diff_hunk", ); } diff --git a/patch.c b/patch.c index 0b107b22a8..8726c53ab8 100644 --- a/patch.c +++ b/patch.c @@ -2,188 +2,305 @@ #include "php_git2_priv.h" #include "patch.h" -/* {{{ proto resource git_patch_from_diff(diff, idx) -*/ +/* {{{ proto resource git_patch_from_diff(resource $diff, long $idx) + */ PHP_FUNCTION(git_patch_from_diff) { - zval *diff; - php_git2_t *_diff; + php_git2_t *result = NULL; + git_patch *out = NULL; + zval *diff = NULL; + php_git2_t *_diff = NULL; + long idx = 0; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_from_diff not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &diff, &idx) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_patch_from_diff(&out, PHP_GIT2_V(_diff, diff), idx); + if (php_git2_check_error(error, "git_patch_from_diff" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, patch) = out; + result->type = PHP_GIT2_TYPE_PATCH; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_patch_from_blobs(old_blob, old_as_path, new_blob, new_as_path, opts) -*/ + +/* {{{ proto resource git_patch_from_blobs(resource $old_blob, string $old_as_path, resource $new_blob, string $new_as_path, $opts) + */ PHP_FUNCTION(git_patch_from_blobs) { - zval *old_blob; - php_git2_t *_old_blob; - char *old_as_path = {0}; - int old_as_path_len; - zval *new_blob; - php_git2_t *_new_blob; - char *new_as_path = {0}; - int new_as_path_len; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_from_blobs not implemented yet"); - return; - + php_git2_t *result = NULL; + git_patch *out = NULL; + zval *old_blob = NULL; + php_git2_t *_old_blob = NULL; + char *old_as_path = NULL; + int old_as_path_len = 0; + zval *new_blob = NULL; + php_git2_t *_new_blob = NULL; + char *new_as_path = NULL; + int new_as_path_len = 0; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsrsr", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &opts) == FAILURE) { + "rsrsa", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &opts) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_new_blob, php_git2_t*, &new_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_patch_from_blobs(&out, PHP_GIT2_V(_old_blob, blob), old_as_path, PHP_GIT2_V(_new_blob, blob), new_as_path, opts); + if (php_git2_check_error(error, "git_patch_from_blobs" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, patch) = out; + result->type = PHP_GIT2_TYPE_PATCH; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_patch_from_blob_and_buffer(old_blob, old_as_path, buffer, buffer_len, buffer_as_path, opts) -*/ +/* {{{ proto resource git_patch_from_blob_and_buffer(resource $old_blob, string $old_as_path, string $buffer, long $buffer_len, string $buffer_as_path, $opts) + */ PHP_FUNCTION(git_patch_from_blob_and_buffer) { - zval *old_blob; - php_git2_t *_old_blob; - char *old_as_path = {0}; - int old_as_path_len; - char *buffer = {0}; - int buffer_len; - char *buffer_as_path = {0}; - int buffer_as_path_len; - zval *opts; - php_git2_t *_opts; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_from_blob_and_buffer not implemented yet"); - return; - + php_git2_t *result = NULL; + git_patch *out = NULL; + zval *old_blob = NULL; + php_git2_t *_old_blob = NULL; + char *old_as_path = NULL; + int old_as_path_len = 0; + char *buffer = NULL; + int buffer_len = 0; + long buffer_len = 0; + char *buffer_as_path = NULL; + int buffer_as_path_len = 0; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsssr", &old_blob, &old_as_path, &old_as_path_len, &buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &opts) == FAILURE) { + "rsslsa", &old_blob, &old_as_path, &old_as_path_len, &buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &opts) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_patch_from_blob_and_buffer(&out, PHP_GIT2_V(_old_blob, blob), old_as_path, buffer, buffer_len, buffer_as_path, opts); + if (php_git2_check_error(error, "git_patch_from_blob_and_buffer" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, patch) = out; + result->type = PHP_GIT2_TYPE_PATCH; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto void git_patch_free(patch) -*/ + +/* {{{ proto void git_patch_free(resource $patch) + */ PHP_FUNCTION(git_patch_free) { - zval *patch; - php_git2_t *_patch; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_free not implemented yet"); - return; + zval *patch = NULL; + php_git2_t *_patch = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &patch) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_patch->should_free_v) { + git_patch_free(PHP_GIT2_V(_patch, patch)); + }; + zval_ptr_dtor(&patch); } +/* }}} */ -/* {{{ proto resource git_patch_get_delta(patch) -*/ + +/* {{{ proto resource git_patch_get_delta(resource $patch) + */ PHP_FUNCTION(git_patch_get_delta) { - zval *patch; - php_git2_t *_patch; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_get_delta not implemented yet"); - return; + const git_diff_delta *result = NULL; + zval *patch = NULL; + php_git2_t *_patch = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &patch) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_patch_get_delta(PHP_GIT2_V(_patch, patch)); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto resource git_patch_num_hunks(patch) -*/ + +/* {{{ proto long git_patch_num_hunks(resource $patch) + */ PHP_FUNCTION(git_patch_num_hunks) { - zval *patch; - php_git2_t *_patch; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_num_hunks not implemented yet"); - return; + size_t result = 0; + zval *patch = NULL; + php_git2_t *_patch = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &patch) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_patch_num_hunks(PHP_GIT2_V(_patch, patch)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_patch_line_stats(total_context, total_additions, total_deletions, patch) -*/ + +/* {{{ proto long git_patch_line_stats(long $total_context, long $total_additions, long $total_deletions, resource $patch) + */ PHP_FUNCTION(git_patch_line_stats) { - zval *patch; - php_git2_t *_patch; + int result = 0; + long total_context = 0; + long total_additions = 0; + long total_deletions = 0; + zval *patch = NULL; + php_git2_t *_patch = NULL; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_line_stats not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lllr", &total_context, &total_additions, &total_deletions, &patch) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_patch_line_stats(total_context, total_additions, total_deletions, PHP_GIT2_V(_patch, patch)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_patch_get_hunk(lines_in_hunk, patch, hunk_idx) -*/ + +/* {{{ proto resource git_patch_get_hunk(long $lines_in_hunk, resource $patch, long $hunk_idx) + */ PHP_FUNCTION(git_patch_get_hunk) { - zval *patch; - php_git2_t *_patch; + php_git2_t *result = NULL; + git_diff_hunk *out = NULL; + long lines_in_hunk = 0; + zval *patch = NULL; + php_git2_t *_patch = NULL; + long hunk_idx = 0; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_get_hunk not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lrl", &lines_in_hunk, &patch, &hunk_idx) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_patch_get_hunk(&out, lines_in_hunk, PHP_GIT2_V(_patch, patch), hunk_idx); + if (php_git2_check_error(error, "git_patch_get_hunk" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, diff_hunk) = out; + result->type = PHP_GIT2_TYPE_DIFF_HUNK; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto long git_patch_num_lines_in_hunk(patch, hunk_idx) -*/ + +/* {{{ proto long git_patch_num_lines_in_hunk(resource $patch, long $hunk_idx) + */ PHP_FUNCTION(git_patch_num_lines_in_hunk) { - zval *patch; - php_git2_t *_patch; + int result = 0; + zval *patch = NULL; + php_git2_t *_patch = NULL; + long hunk_idx = 0; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_num_lines_in_hunk not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &patch, &hunk_idx) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_patch_num_lines_in_hunk(PHP_GIT2_V(_patch, patch), hunk_idx); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_patch_get_line_in_hunk(patch, hunk_idx, line_of_hunk) -*/ +/* {{{ proto resource git_patch_get_line_in_hunk(resource $patch, long $hunk_idx, long $line_of_hunk) + */ PHP_FUNCTION(git_patch_get_line_in_hunk) { - zval *patch; - php_git2_t *_patch; + php_git2_t *result = NULL; + git_diff_line *out = NULL; + zval *patch = NULL; + php_git2_t *_patch = NULL; + long hunk_idx = 0; + long line_of_hunk = 0; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_get_line_in_hunk not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rll", &patch, &hunk_idx, &line_of_hunk) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_patch_get_line_in_hunk(&out, PHP_GIT2_V(_patch, patch), hunk_idx, line_of_hunk); + if (php_git2_check_error(error, "git_patch_get_line_in_hunk" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, diff_line) = out; + result->type = PHP_GIT2_TYPE_DIFF_LINE; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_patch_size(patch, include_context, include_hunk_headers, include_file_headers) -*/ + +/* {{{ proto long git_patch_size(resource $patch, long $include_context, long $include_hunk_headers, long $include_file_headers) + */ PHP_FUNCTION(git_patch_size) { - zval *patch; - php_git2_t *_patch; - long include_context; - long include_hunk_headers; - long include_file_headers; + size_t result = 0; + zval *patch = NULL; + php_git2_t *_patch = NULL; + long include_context = 0; + long include_hunk_headers = 0; + long include_file_headers = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_size not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlll", &patch, &include_context, &include_hunk_headers, &include_file_headers) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_patch_size(PHP_GIT2_V(_patch, patch), include_context, include_hunk_headers, include_file_headers); + RETURN_LONG(result); } +/* }}} */ /* {{{ proto long git_patch_print(patch, print_cb, payload) */ @@ -199,14 +316,24 @@ PHP_FUNCTION(git_patch_print) return; } -/* {{{ proto resource git_patch_to_str(patch) -*/ +/* {{{ proto long git_patch_to_str(string $string, resource $patch) + */ PHP_FUNCTION(git_patch_to_str) { - zval *patch; - php_git2_t *_patch; + int result = 0; + char *string = NULL; + int string_len = 0; + zval *patch = NULL; + php_git2_t *_patch = NULL; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_to_str not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sr", &string, &string_len, &patch) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_patch_to_str(string, PHP_GIT2_V(_patch, patch)); + RETURN_LONG(result); } +/* }}} */ diff --git a/php_git2.h b/php_git2.h index 943c44b74e..a619e5d11a 100644 --- a/php_git2.h +++ b/php_git2.h @@ -98,6 +98,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_MERGE_HEAD, PHP_GIT2_TYPE_PATHSPEC, PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, + PHP_GIT2_TYPE_PATCH, + PHP_GIT2_TYPE_DIFF_HUNK, }; typedef struct php_git2_t { @@ -127,6 +129,8 @@ typedef struct php_git2_t { git_merge_head *merge_head; git_pathspec *pathspec; git_pathspec_match_list *pathspec_match_list; + git_patch *patch; + git_diff_hunk *diff_hunk; } v; int should_free_v; int resource_id; From 39e7b888df5666c8b50aff74bd3d3565c19d1414 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 13:01:44 +0900 Subject: [PATCH 033/136] [patch] add stubs --- filter.c | 365 ++++++++++++++++++++++++++++++++--------------------- ng.php | 4 + patch.c | 3 +- php_git2.h | 9 ++ 4 files changed, 233 insertions(+), 148 deletions(-) diff --git a/filter.c b/filter.c index c7a19b8a4c..d1f013e9f7 100644 --- a/filter.c +++ b/filter.c @@ -2,146 +2,204 @@ #include "php_git2_priv.h" #include "filter.h" -/* {{{ proto resource git_filter_list_load(repo, blob, path, mode) -*/ +/* {{{ proto long git_filter_list_load(resource $repo, resource $blob, string $path, $mode) + */ PHP_FUNCTION(git_filter_list_load) { - zval *repo; - php_git2_t *_repo; - zval *blob; - php_git2_t *_blob; - char *path = {0}; - int path_len; - zval *mode; - php_git2_t *_mode; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_load not implemented yet"); - return; + int result = 0; + git_filter_list *filters = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + zval *blob = NULL; + php_git2_t *_blob = NULL; + char *path = NULL; + int path_len = 0; + long mode = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrsr", &repo, &blob, &path, &path_len, &mode) == FAILURE) { + "rrsl", &repo, &blob, &path, &path_len, &mode) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_list_load(&filters, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_blob, blob), path, mode); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_filter_list_apply_to_data(filters, in) -*/ + +/* {{{ proto resource git_filter_list_apply_to_data(resource $filters, resource $in) + */ PHP_FUNCTION(git_filter_list_apply_to_data) { - zval *filters; - php_git2_t *_filters; - zval *in; - php_git2_t *_in; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_data not implemented yet"); - return; + php_git2_t *result = NULL; + git_buf out = {0}; + zval *filters = NULL; + php_git2_t *_filters = NULL; + zval *in = NULL; + php_git2_t *_in = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &filters, &in) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_in, php_git2_t*, &in, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_apply_to_data(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_in, buf)); + if (php_git2_check_error(error, "git_filter_list_apply_to_data" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, buf) = &out; + result->type = PHP_GIT2_TYPE_BUF; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_filter_list_apply_to_file(filters, repo, path) -*/ + +/* {{{ proto resource git_filter_list_apply_to_file(resource $filters, resource $repo, string $path) + */ PHP_FUNCTION(git_filter_list_apply_to_file) { - zval *filters; - php_git2_t *_filters; - zval *repo; - php_git2_t *_repo; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_file not implemented yet"); - return; + php_git2_t *result = NULL; + git_buf out = {0}; + zval *filters = NULL; + php_git2_t *_filters = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *path = NULL; + int path_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrs", &filters, &repo, &path, &path_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_apply_to_file(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_repo, repository), path); + if (php_git2_check_error(error, "git_filter_list_apply_to_file" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, buf) = &out; + result->type = PHP_GIT2_TYPE_BUF; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto resource git_filter_list_apply_to_blob(filters, blob) -*/ + +/* {{{ proto resource git_filter_list_apply_to_blob(resource $filters, resource $blob) + */ PHP_FUNCTION(git_filter_list_apply_to_blob) { - zval *filters; - php_git2_t *_filters; - zval *blob; - php_git2_t *_blob; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_apply_to_blob not implemented yet"); - return; + php_git2_t *result = NULL; + git_buf out = {0}; + zval *filters = NULL; + php_git2_t *_filters = NULL; + zval *blob = NULL; + php_git2_t *_blob = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &filters, &blob) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_apply_to_blob(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_blob, blob)); + if (php_git2_check_error(error, "git_filter_list_apply_to_blob" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, buf) = &out; + result->type = PHP_GIT2_TYPE_BUF; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ -/* {{{ proto void git_filter_list_free(filters) -*/ + +/* {{{ proto void git_filter_list_free(resource $filters) + */ PHP_FUNCTION(git_filter_list_free) { - zval *filters; - php_git2_t *_filters; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_free not implemented yet"); - return; + zval *filters = NULL; + php_git2_t *_filters = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &filters) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (_filters->should_free_v) { + git_filter_list_free(PHP_GIT2_V(_filters, filter_list)); + }; + zval_ptr_dtor(&filters); } +/* }}} */ -/* {{{ proto resource git_filter_lookup(name) -*/ +/* {{{ proto resource git_filter_lookup(string $name) + */ PHP_FUNCTION(git_filter_lookup) { - char *name = {0}; - int name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_lookup not implemented yet"); - return; + git_filter *result = NULL; + char *name = NULL; + int name_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } + + result = git_filter_lookup(name); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto resource git_filter_list_new(repo, mode) -*/ + +/* {{{ proto resource git_filter_list_new(resource $repo, $mode) + */ PHP_FUNCTION(git_filter_list_new) { - zval *repo; - php_git2_t *_repo; - zval *mode; - php_git2_t *_mode; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_new not implemented yet"); - return; + php_git2_t *result = NULL; + git_filter_list *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + long mode = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &repo, &mode) == FAILURE) { + "rl", &repo, &mode) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_new(&out, PHP_GIT2_V(_repo, repository), mode); + if (php_git2_check_error(error, "git_filter_list_new" TSRMLS_CC)) { + RETURN_FALSE; + } + PHP_GIT2_MAKE_RESOURCE(result); + PHP_GIT2_V(result, filter_list) = out; + result->type = PHP_GIT2_TYPE_FILTER_LIST; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = 0; + ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ + /* {{{ proto long git_filter_list_push(fl, filter, payload) */ @@ -163,149 +221,164 @@ PHP_FUNCTION(git_filter_list_push) // ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto resource git_filter_list_length(fl) -*/ +/* {{{ proto long git_filter_list_length(resource $fl) + */ PHP_FUNCTION(git_filter_list_length) { - zval *fl; - php_git2_t *_fl; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_length not implemented yet"); - return; + size_t result = 0; + zval *fl = NULL; + php_git2_t *_fl = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &fl) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_list_length(PHP_GIT2_V(_fl, filter_list)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_filter_source_repo(src) -*/ + +/* {{{ proto resource git_filter_source_repo(resource $src) + */ PHP_FUNCTION(git_filter_source_repo) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_repo not implemented yet"); - return; + git_repository *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_repo(PHP_GIT2_V(_src, filter_source)); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto resource git_filter_source_path(src) -*/ + +/* {{{ proto string git_filter_source_path(resource $src) + */ PHP_FUNCTION(git_filter_source_path) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_path not implemented yet"); - return; + const char *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_path(PHP_GIT2_V(_src, filter_source)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_filter_source_filemode(src) -*/ + +/* {{{ proto long git_filter_source_filemode(resource $src) + */ PHP_FUNCTION(git_filter_source_filemode) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_filemode not implemented yet"); - return; + uint16_t result = 0; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_filemode(PHP_GIT2_V(_src, filter_source)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_filter_source_id(src) -*/ + +/* {{{ proto resource git_filter_source_id(resource $src) + */ PHP_FUNCTION(git_filter_source_id) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_id not implemented yet"); - return; + const git_oid *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; + char __result[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_id(PHP_GIT2_V(_src, filter_source)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); } +/* }}} */ -/* {{{ proto resource git_filter_source_mode(src) -*/ + +/* {{{ proto resource git_filter_source_mode(resource $src) + */ PHP_FUNCTION(git_filter_source_mode) { - zval *src; - php_git2_t *_src; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_source_mode not implemented yet"); - return; + git_filter_mode_t *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_mode(PHP_GIT2_V(_src, filter_source)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_filter_register(name, filter, priority) -*/ + +/* {{{ proto long git_filter_register(string $name, $filter, long $priority) + */ PHP_FUNCTION(git_filter_register) { - char *name = {0}; - int name_len; - zval *filter; - php_git2_t *_filter; - long priority; + int result = 0; + char *name = NULL; + int name_len = 0; + zval *filter = NULL; + long priority = 0; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_register not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sal", &name, &name_len, &filter, &priority) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "srl", &name, &name_len, &filter, &priority) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_name, php_git2_t*, &name, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_register(name, filter, priority); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_filter_unregister(name) -*/ +/* {{{ proto long git_filter_unregister(string $name) + */ PHP_FUNCTION(git_filter_unregister) { - char *name = {0}; - int name_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_unregister not implemented yet"); - return; + int result = 0; + char *name = NULL; + int name_len = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } -} + result = git_filter_unregister(name); + RETURN_LONG(result); +} +/* }}} */ diff --git a/ng.php b/ng.php index fb30e928e9..a1f9072961 100644 --- a/ng.php +++ b/ng.php @@ -355,6 +355,10 @@ public function shouldResource(Arg $arg) "git_diff", "git_patch", "git_diff_hunk", + "git_filter_list", + "git_buf", + "git_filter_source", + "git_diff_line", ); } diff --git a/patch.c b/patch.c index 8726c53ab8..392975b1f8 100644 --- a/patch.c +++ b/patch.c @@ -71,7 +71,7 @@ PHP_FUNCTION(git_patch_from_blobs) } /* }}} */ -/* {{{ proto resource git_patch_from_blob_and_buffer(resource $old_blob, string $old_as_path, string $buffer, long $buffer_len, string $buffer_as_path, $opts) +/* {{{ proto resource git_patch_from_blob_and_buffer(resource $old_blob, string $old_as_path, string $buffer, string $buffer_as_path, $opts) */ PHP_FUNCTION(git_patch_from_blob_and_buffer) { @@ -83,7 +83,6 @@ PHP_FUNCTION(git_patch_from_blob_and_buffer) int old_as_path_len = 0; char *buffer = NULL; int buffer_len = 0; - long buffer_len = 0; char *buffer_as_path = NULL; int buffer_as_path_len = 0; zval *opts = NULL; diff --git a/php_git2.h b/php_git2.h index a619e5d11a..e271b32094 100644 --- a/php_git2.h +++ b/php_git2.h @@ -48,6 +48,7 @@ #include "limits.h" #include "git2.h" +#include "git2/sys/filter.h" #include "date/php_date.h" @@ -100,6 +101,10 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, PHP_GIT2_TYPE_PATCH, PHP_GIT2_TYPE_DIFF_HUNK, + PHP_GIT2_TYPE_BUF, + PHP_GIT2_TYPE_FILTER_LIST, + PHP_GIT2_TYPE_FILTER_SOURCE, + PHP_GIT2_TYPE_DIFF_LINE, }; typedef struct php_git2_t { @@ -131,6 +136,10 @@ typedef struct php_git2_t { git_pathspec_match_list *pathspec_match_list; git_patch *patch; git_diff_hunk *diff_hunk; + git_buf *buf; + git_filter_list *filter_list; + git_filter_source *filter_source; + git_diff_line *diff_line; } v; int should_free_v; int resource_id; From e796ab3182be8fbc3889b865e1db0cb050c8478d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 13:20:07 +0900 Subject: [PATCH 034/136] [tests] add stub codes --- .gitignore | 13 ++++++------- tests/blob/git_blob_create_frombuffer.phpt | 10 ++++++++++ tests/blob/git_blob_create_fromchunks.phpt | 10 ++++++++++ tests/blob/git_blob_create_fromdisk.phpt | 10 ++++++++++ tests/blob/git_blob_create_fromworkdir.phpt | 10 ++++++++++ tests/blob/git_blob_filtered_content.phpt | 10 ++++++++++ tests/blob/git_blob_free.phpt | 10 ++++++++++ tests/blob/git_blob_id.phpt | 10 ++++++++++ tests/blob/git_blob_is_binary.phpt | 10 ++++++++++ tests/blob/git_blob_lookup.phpt | 10 ++++++++++ tests/blob/git_blob_lookup_prefix.phpt | 10 ++++++++++ tests/blob/git_blob_owner.phpt | 10 ++++++++++ tests/blob/git_blob_rawcontent.phpt | 10 ++++++++++ tests/blob/git_blob_rawsize.phpt | 10 ++++++++++ tests/branch/git_branch_create.phpt | 10 ++++++++++ tests/branch/git_branch_delete.phpt | 10 ++++++++++ tests/branch/git_branch_is_head.phpt | 10 ++++++++++ tests/branch/git_branch_iterator_free.phpt | 10 ++++++++++ tests/branch/git_branch_iterator_new.phpt | 10 ++++++++++ tests/branch/git_branch_lookup.phpt | 10 ++++++++++ tests/branch/git_branch_move.phpt | 10 ++++++++++ tests/branch/git_branch_name.phpt | 10 ++++++++++ tests/branch/git_branch_next.phpt | 10 ++++++++++ tests/branch/git_branch_remote_name.phpt | 10 ++++++++++ tests/branch/git_branch_upstream.phpt | 10 ++++++++++ tests/branch/git_branch_upstream_name.phpt | 10 ++++++++++ tests/checkout/git_checkout_head.phpt | 10 ++++++++++ tests/checkout/git_checkout_index.phpt | 10 ++++++++++ tests/checkout/git_checkout_tree.phpt | 10 ++++++++++ tests/clone/git_clone.phpt | 10 ++++++++++ tests/clone/git_clone_into.phpt | 10 ++++++++++ tests/commit/git_commit_author.phpt | 10 ++++++++++ tests/commit/git_commit_committer.phpt | 10 ++++++++++ tests/commit/git_commit_create.phpt | 10 ++++++++++ tests/commit/git_commit_id.phpt | 10 ++++++++++ tests/commit/git_commit_lookup.phpt | 10 ++++++++++ tests/commit/git_commit_lookup_prefix.phpt | 10 ++++++++++ tests/commit/git_commit_message.phpt | 10 ++++++++++ tests/commit/git_commit_message_encoding.phpt | 10 ++++++++++ tests/commit/git_commit_message_raw.phpt | 10 ++++++++++ tests/commit/git_commit_nth_gen_ancestor.phpt | 10 ++++++++++ tests/commit/git_commit_owner.phpt | 10 ++++++++++ tests/commit/git_commit_parent.phpt | 10 ++++++++++ tests/commit/git_commit_parent_id.phpt | 10 ++++++++++ tests/commit/git_commit_parentcount.phpt | 10 ++++++++++ tests/commit/git_commit_raw_header.phpt | 10 ++++++++++ tests/commit/git_commit_time.phpt | 10 ++++++++++ tests/commit/git_commit_time_offset.phpt | 10 ++++++++++ tests/commit/git_commit_tree.phpt | 10 ++++++++++ tests/commit/git_commit_tree_id.phpt | 10 ++++++++++ tests/config/git_config_add_file_ondisk.phpt | 10 ++++++++++ tests/config/git_config_backend_foreach_match.phpt | 10 ++++++++++ tests/config/git_config_delete_entry.phpt | 10 ++++++++++ tests/config/git_config_delete_multivar.phpt | 10 ++++++++++ tests/config/git_config_find_global.phpt | 10 ++++++++++ tests/config/git_config_find_system.phpt | 10 ++++++++++ tests/config/git_config_find_xdg.phpt | 10 ++++++++++ tests/config/git_config_foreach.phpt | 10 ++++++++++ tests/config/git_config_foreach_match.phpt | 10 ++++++++++ tests/config/git_config_free.phpt | 10 ++++++++++ tests/config/git_config_get_bool.phpt | 10 ++++++++++ tests/config/git_config_get_entry.phpt | 10 ++++++++++ tests/config/git_config_get_int32.phpt | 10 ++++++++++ tests/config/git_config_get_int64.phpt | 10 ++++++++++ tests/config/git_config_get_mapped.phpt | 10 ++++++++++ tests/config/git_config_get_multivar_foreach.phpt | 10 ++++++++++ tests/config/git_config_get_string.phpt | 10 ++++++++++ tests/config/git_config_iterator_free.phpt | 10 ++++++++++ tests/config/git_config_iterator_glob_new.phpt | 10 ++++++++++ tests/config/git_config_iterator_new.phpt | 10 ++++++++++ tests/config/git_config_lookup_map_value.phpt | 10 ++++++++++ tests/config/git_config_multivar_iterator_new.phpt | 10 ++++++++++ tests/config/git_config_new.phpt | 10 ++++++++++ tests/config/git_config_next.phpt | 10 ++++++++++ tests/config/git_config_open_default.phpt | 10 ++++++++++ tests/config/git_config_open_global.phpt | 10 ++++++++++ tests/config/git_config_open_level.phpt | 10 ++++++++++ tests/config/git_config_open_ondisk.phpt | 10 ++++++++++ tests/config/git_config_parse_bool.phpt | 10 ++++++++++ tests/config/git_config_parse_int32.phpt | 10 ++++++++++ tests/config/git_config_parse_int64.phpt | 10 ++++++++++ tests/config/git_config_refresh.phpt | 10 ++++++++++ tests/config/git_config_set_bool.phpt | 10 ++++++++++ tests/config/git_config_set_int32.phpt | 10 ++++++++++ tests/config/git_config_set_int64.phpt | 10 ++++++++++ tests/config/git_config_set_multivar.phpt | 10 ++++++++++ tests/config/git_config_set_string.phpt | 10 ++++++++++ tests/cred/git_cred_default_new.phpt | 10 ++++++++++ tests/cred/git_cred_has_username.phpt | 10 ++++++++++ tests/cred/git_cred_ssh_custom_new.phpt | 10 ++++++++++ tests/cred/git_cred_ssh_key_new.phpt | 10 ++++++++++ tests/cred/git_cred_userpass.phpt | 10 ++++++++++ tests/cred/git_cred_userpass_plaintext_new.phpt | 10 ++++++++++ tests/diff/git_diff_blob_to_buffer.phpt | 10 ++++++++++ tests/diff/git_diff_blobs.phpt | 10 ++++++++++ tests/diff/git_diff_find_similar.phpt | 10 ++++++++++ tests/diff/git_diff_foreach.phpt | 10 ++++++++++ tests/diff/git_diff_free.phpt | 10 ++++++++++ tests/diff/git_diff_get_delta.phpt | 10 ++++++++++ tests/diff/git_diff_index_to_workdir.phpt | 10 ++++++++++ tests/diff/git_diff_is_sorted_icase.phpt | 10 ++++++++++ tests/diff/git_diff_merge.phpt | 10 ++++++++++ tests/diff/git_diff_num_deltas.phpt | 10 ++++++++++ tests/diff/git_diff_num_deltas_of_type.phpt | 10 ++++++++++ tests/diff/git_diff_options_init.phpt | 10 ++++++++++ tests/diff/git_diff_print.phpt | 10 ++++++++++ tests/diff/git_diff_status_char.phpt | 10 ++++++++++ tests/diff/git_diff_tree_to_index.phpt | 10 ++++++++++ tests/diff/git_diff_tree_to_tree.phpt | 10 ++++++++++ tests/diff/git_diff_tree_to_workdir.phpt | 10 ++++++++++ tests/diff/git_diff_tree_to_workdir_with_index.phpt | 10 ++++++++++ tests/filter/git_filter_list_apply_to_blob.phpt | 10 ++++++++++ tests/filter/git_filter_list_apply_to_data.phpt | 10 ++++++++++ tests/filter/git_filter_list_apply_to_file.phpt | 10 ++++++++++ tests/filter/git_filter_list_free.phpt | 10 ++++++++++ tests/filter/git_filter_list_length.phpt | 10 ++++++++++ tests/filter/git_filter_list_load.phpt | 10 ++++++++++ tests/filter/git_filter_list_new.phpt | 10 ++++++++++ tests/filter/git_filter_list_push.phpt | 10 ++++++++++ tests/filter/git_filter_lookup.phpt | 10 ++++++++++ tests/filter/git_filter_register.phpt | 10 ++++++++++ tests/filter/git_filter_source_filemode.phpt | 10 ++++++++++ tests/filter/git_filter_source_id.phpt | 10 ++++++++++ tests/filter/git_filter_source_mode.phpt | 10 ++++++++++ tests/filter/git_filter_source_path.phpt | 10 ++++++++++ tests/filter/git_filter_source_repo.phpt | 10 ++++++++++ tests/filter/git_filter_unregister.phpt | 10 ++++++++++ tests/ignore/git_ignore_add_rule.phpt | 10 ++++++++++ tests/ignore/git_ignore_clear_internal_rules.phpt | 10 ++++++++++ tests/ignore/git_ignore_path_is_ignored.phpt | 10 ++++++++++ tests/index/git_index_add.phpt | 10 ++++++++++ tests/index/git_index_add_all.phpt | 10 ++++++++++ tests/index/git_index_add_bypath.phpt | 10 ++++++++++ tests/index/git_index_caps.phpt | 10 ++++++++++ tests/index/git_index_clear.phpt | 10 ++++++++++ tests/index/git_index_conflict_add.phpt | 10 ++++++++++ tests/index/git_index_conflict_cleanup.phpt | 10 ++++++++++ tests/index/git_index_conflict_get.phpt | 10 ++++++++++ tests/index/git_index_conflict_iterator_free.phpt | 10 ++++++++++ tests/index/git_index_conflict_iterator_new.phpt | 10 ++++++++++ tests/index/git_index_conflict_next.phpt | 10 ++++++++++ tests/index/git_index_conflict_remove.phpt | 10 ++++++++++ tests/index/git_index_entry_stage.phpt | 10 ++++++++++ tests/index/git_index_entrycount.phpt | 10 ++++++++++ tests/index/git_index_find.phpt | 10 ++++++++++ tests/index/git_index_free.phpt | 10 ++++++++++ tests/index/git_index_get_byindex.phpt | 10 ++++++++++ tests/index/git_index_get_bypath.phpt | 10 ++++++++++ tests/index/git_index_has_conflicts.phpt | 10 ++++++++++ tests/index/git_index_new.phpt | 10 ++++++++++ tests/index/git_index_open.phpt | 10 ++++++++++ tests/index/git_index_owner.phpt | 10 ++++++++++ tests/index/git_index_path.phpt | 10 ++++++++++ tests/index/git_index_read.phpt | 10 ++++++++++ tests/index/git_index_read_tree.phpt | 10 ++++++++++ tests/index/git_index_remove.phpt | 10 ++++++++++ tests/index/git_index_remove_all.phpt | 10 ++++++++++ tests/index/git_index_remove_bypath.phpt | 10 ++++++++++ tests/index/git_index_remove_directory.phpt | 10 ++++++++++ tests/index/git_index_set_caps.phpt | 10 ++++++++++ tests/index/git_index_update_all.phpt | 10 ++++++++++ tests/index/git_index_write.phpt | 10 ++++++++++ tests/index/git_index_write_tree.phpt | 10 ++++++++++ tests/index/git_index_write_tree_to.phpt | 10 ++++++++++ tests/indexer/git_indexer_append.phpt | 10 ++++++++++ tests/indexer/git_indexer_commit.phpt | 10 ++++++++++ tests/indexer/git_indexer_free.phpt | 10 ++++++++++ tests/indexer/git_indexer_hash.phpt | 10 ++++++++++ tests/indexer/git_indexer_new.phpt | 10 ++++++++++ tests/merge/git_merge.phpt | 10 ++++++++++ tests/merge/git_merge_base.phpt | 10 ++++++++++ tests/merge/git_merge_base_many.phpt | 10 ++++++++++ tests/merge/git_merge_head_free.phpt | 10 ++++++++++ tests/merge/git_merge_head_from_fetchhead.phpt | 10 ++++++++++ tests/merge/git_merge_head_from_oid.phpt | 10 ++++++++++ tests/merge/git_merge_head_from_ref.phpt | 10 ++++++++++ tests/merge/git_merge_result_fastforward_oid.phpt | 10 ++++++++++ tests/merge/git_merge_result_free.phpt | 10 ++++++++++ tests/merge/git_merge_result_is_fastforward.phpt | 10 ++++++++++ tests/merge/git_merge_result_is_uptodate.phpt | 10 ++++++++++ tests/merge/git_merge_trees.phpt | 10 ++++++++++ tests/object/git_object__size.phpt | 10 ++++++++++ tests/object/git_object_dup.phpt | 10 ++++++++++ tests/object/git_object_free.phpt | 10 ++++++++++ tests/object/git_object_id.phpt | 10 ++++++++++ tests/object/git_object_lookup.phpt | 10 ++++++++++ tests/object/git_object_lookup_bypath.phpt | 10 ++++++++++ tests/object/git_object_lookup_prefix.phpt | 10 ++++++++++ tests/object/git_object_owner.phpt | 10 ++++++++++ tests/object/git_object_peel.phpt | 10 ++++++++++ tests/object/git_object_string2type.phpt | 10 ++++++++++ tests/object/git_object_type.phpt | 10 ++++++++++ tests/object/git_object_type2string.phpt | 10 ++++++++++ tests/object/git_object_typeisloose.phpt | 10 ++++++++++ tests/patch/git_patch_free.phpt | 10 ++++++++++ tests/patch/git_patch_from_blob_and_buffer.phpt | 10 ++++++++++ tests/patch/git_patch_from_blobs.phpt | 10 ++++++++++ tests/patch/git_patch_from_diff.phpt | 10 ++++++++++ tests/patch/git_patch_get_delta.phpt | 10 ++++++++++ tests/patch/git_patch_get_hunk.phpt | 10 ++++++++++ tests/patch/git_patch_get_line_in_hunk.phpt | 10 ++++++++++ tests/patch/git_patch_line_stats.phpt | 10 ++++++++++ tests/patch/git_patch_num_hunks.phpt | 10 ++++++++++ tests/patch/git_patch_num_lines_in_hunk.phpt | 10 ++++++++++ tests/patch/git_patch_print.phpt | 10 ++++++++++ tests/patch/git_patch_size.phpt | 10 ++++++++++ tests/patch/git_patch_to_str.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_free.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_match_diff.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_match_index.phpt | 10 ++++++++++ .../git_pathspec_match_list_diff_entry.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_match_list_entry.phpt | 10 ++++++++++ .../git_pathspec_match_list_entrycount.phpt | 10 ++++++++++ .../git_pathspec_match_list_failed_entry.phpt | 10 ++++++++++ .../git_pathspec_match_list_failed_entrycount.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_match_list_free.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_match_tree.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_match_workdir.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_matches_path.phpt | 10 ++++++++++ tests/pathspec/git_pathspec_new.phpt | 10 ++++++++++ tests/reference/git_reference_cmp.phpt | 10 ++++++++++ tests/reference/git_reference_create.phpt | 10 ++++++++++ tests/reference/git_reference_delete.phpt | 10 ++++++++++ tests/reference/git_reference_dwim.phpt | 10 ++++++++++ tests/reference/git_reference_foreach.phpt | 10 ++++++++++ tests/reference/git_reference_foreach_glob.phpt | 10 ++++++++++ tests/reference/git_reference_foreach_name.phpt | 10 ++++++++++ tests/reference/git_reference_free.phpt | 10 ++++++++++ tests/reference/git_reference_has_log.phpt | 10 ++++++++++ tests/reference/git_reference_is_branch.phpt | 10 ++++++++++ tests/reference/git_reference_is_remote.phpt | 10 ++++++++++ tests/reference/git_reference_is_tag.phpt | 10 ++++++++++ tests/reference/git_reference_is_valid_name.phpt | 10 ++++++++++ tests/reference/git_reference_iterator_free.phpt | 10 ++++++++++ .../reference/git_reference_iterator_glob_new.phpt | 10 ++++++++++ tests/reference/git_reference_iterator_new.phpt | 10 ++++++++++ tests/reference/git_reference_list.phpt | 10 ++++++++++ tests/reference/git_reference_lookup.phpt | 10 ++++++++++ tests/reference/git_reference_name.phpt | 10 ++++++++++ tests/reference/git_reference_name_to_id.phpt | 10 ++++++++++ tests/reference/git_reference_next.phpt | 10 ++++++++++ tests/reference/git_reference_next_name.phpt | 10 ++++++++++ tests/reference/git_reference_normalize_name.phpt | 10 ++++++++++ tests/reference/git_reference_owner.phpt | 10 ++++++++++ tests/reference/git_reference_peel.phpt | 10 ++++++++++ tests/reference/git_reference_rename.phpt | 10 ++++++++++ tests/reference/git_reference_resolve.phpt | 10 ++++++++++ tests/reference/git_reference_set_target.phpt | 10 ++++++++++ tests/reference/git_reference_shorthand.phpt | 10 ++++++++++ tests/reference/git_reference_symbolic_create.phpt | 10 ++++++++++ .../git_reference_symbolic_set_target.phpt | 10 ++++++++++ tests/reference/git_reference_symbolic_target.phpt | 10 ++++++++++ tests/reference/git_reference_target.phpt | 10 ++++++++++ tests/reference/git_reference_target_peel.phpt | 10 ++++++++++ tests/reference/git_reference_type.phpt | 10 ++++++++++ tests/repository/git_repository_config.phpt | 10 ++++++++++ tests/repository/git_repository_detach_head.phpt | 10 ++++++++++ tests/repository/git_repository_discover.phpt | 10 ++++++++++ .../git_repository_fetchhead_foreach.phpt | 10 ++++++++++ tests/repository/git_repository_free.phpt | 10 ++++++++++ tests/repository/git_repository_get_namespace.phpt | 10 ++++++++++ tests/repository/git_repository_hashfile.phpt | 10 ++++++++++ tests/repository/git_repository_head.phpt | 10 ++++++++++ tests/repository/git_repository_head_detached.phpt | 10 ++++++++++ tests/repository/git_repository_head_unborn.phpt | 10 ++++++++++ tests/repository/git_repository_index.phpt | 10 ++++++++++ tests/repository/git_repository_init.phpt | 10 ++++++++++ tests/repository/git_repository_init_ext.phpt | 10 ++++++++++ tests/repository/git_repository_is_bare.phpt | 10 ++++++++++ tests/repository/git_repository_is_empty.phpt | 10 ++++++++++ tests/repository/git_repository_is_shallow.phpt | 10 ++++++++++ tests/repository/git_repository_merge_cleanup.phpt | 10 ++++++++++ .../git_repository_mergehead_foreach.phpt | 10 ++++++++++ tests/repository/git_repository_message.phpt | 10 ++++++++++ tests/repository/git_repository_message_remove.phpt | 10 ++++++++++ tests/repository/git_repository_new.phpt | 10 ++++++++++ tests/repository/git_repository_odb.phpt | 10 ++++++++++ tests/repository/git_repository_open.phpt | 10 ++++++++++ tests/repository/git_repository_open_bare.phpt | 10 ++++++++++ tests/repository/git_repository_open_ext.phpt | 10 ++++++++++ tests/repository/git_repository_path.phpt | 10 ++++++++++ tests/repository/git_repository_refdb.phpt | 10 ++++++++++ tests/repository/git_repository_set_head.phpt | 10 ++++++++++ .../git_repository_set_head_detached.phpt | 10 ++++++++++ tests/repository/git_repository_set_namespace.phpt | 10 ++++++++++ tests/repository/git_repository_set_workdir.phpt | 10 ++++++++++ tests/repository/git_repository_state.phpt | 10 ++++++++++ tests/repository/git_repository_workdir.phpt | 10 ++++++++++ tests/repository/git_repository_wrap_odb.phpt | 10 ++++++++++ tests/revparse/git_revparse.phpt | 10 ++++++++++ tests/revparse/git_revparse_ext.phpt | 10 ++++++++++ tests/revparse/git_revparse_single.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_free.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_hide.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_hide_glob.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_hide_head.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_hide_ref.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_new.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_next.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_push.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_push_glob.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_push_head.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_push_range.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_push_ref.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_repository.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_reset.phpt | 10 ++++++++++ .../revwalk/git_revwalk_simplify_first_parent.phpt | 10 ++++++++++ tests/revwalk/git_revwalk_sorting.phpt | 10 ++++++++++ tests/status/git_status_byindex.phpt | 10 ++++++++++ tests/status/git_status_file.phpt | 10 ++++++++++ tests/status/git_status_foreach.phpt | 10 ++++++++++ tests/status/git_status_foreach_ext.phpt | 10 ++++++++++ tests/status/git_status_list_entrycount.phpt | 10 ++++++++++ tests/status/git_status_list_free.phpt | 10 ++++++++++ tests/status/git_status_list_new.phpt | 10 ++++++++++ tests/status/git_status_should_ignore.phpt | 10 ++++++++++ tests/tag/git_tag_annotation_create.phpt | 10 ++++++++++ tests/tag/git_tag_create.phpt | 10 ++++++++++ tests/tag/git_tag_create_frombuffer.phpt | 10 ++++++++++ tests/tag/git_tag_create_lightweight.phpt | 10 ++++++++++ tests/tag/git_tag_delete.phpt | 10 ++++++++++ tests/tag/git_tag_foreach.phpt | 10 ++++++++++ tests/tag/git_tag_free.phpt | 10 ++++++++++ tests/tag/git_tag_id.phpt | 10 ++++++++++ tests/tag/git_tag_list.phpt | 10 ++++++++++ tests/tag/git_tag_list_match.phpt | 10 ++++++++++ tests/tag/git_tag_lookup.phpt | 10 ++++++++++ tests/tag/git_tag_lookup_prefix.phpt | 10 ++++++++++ tests/tag/git_tag_message.phpt | 10 ++++++++++ tests/tag/git_tag_name.phpt | 10 ++++++++++ tests/tag/git_tag_owner.phpt | 10 ++++++++++ tests/tag/git_tag_peel.phpt | 10 ++++++++++ tests/tag/git_tag_tagger.phpt | 10 ++++++++++ tests/tag/git_tag_target.phpt | 10 ++++++++++ tests/tag/git_tag_target_id.phpt | 10 ++++++++++ tests/tag/git_tag_target_type.phpt | 10 ++++++++++ tests/transport/git_smart_subtransport_git.phpt | 10 ++++++++++ tests/transport/git_smart_subtransport_http.phpt | 10 ++++++++++ tests/transport/git_smart_subtransport_ssh.phpt | 10 ++++++++++ tests/transport/git_transport_dummy.phpt | 10 ++++++++++ tests/transport/git_transport_local.phpt | 10 ++++++++++ tests/transport/git_transport_new.phpt | 10 ++++++++++ tests/transport/git_transport_register.phpt | 10 ++++++++++ tests/transport/git_transport_smart.phpt | 10 ++++++++++ tests/transport/git_transport_unregister.phpt | 10 ++++++++++ tests/tree/git_tree_entry_byindex.phpt | 10 ++++++++++ tests/tree/git_tree_entry_byname.phpt | 10 ++++++++++ tests/tree/git_tree_entry_byoid.phpt | 10 ++++++++++ tests/tree/git_tree_entry_bypath.phpt | 10 ++++++++++ tests/tree/git_tree_entry_cmp.phpt | 10 ++++++++++ tests/tree/git_tree_entry_dup.phpt | 10 ++++++++++ tests/tree/git_tree_entry_filemode.phpt | 10 ++++++++++ tests/tree/git_tree_entry_filemode_raw.phpt | 10 ++++++++++ tests/tree/git_tree_entry_free.phpt | 10 ++++++++++ tests/tree/git_tree_entry_id.phpt | 10 ++++++++++ tests/tree/git_tree_entry_name.phpt | 10 ++++++++++ tests/tree/git_tree_entry_type.phpt | 10 ++++++++++ tests/tree/git_tree_entrycount.phpt | 10 ++++++++++ tests/tree/git_tree_free.phpt | 10 ++++++++++ tests/tree/git_tree_id.phpt | 10 ++++++++++ tests/tree/git_tree_lookup.phpt | 10 ++++++++++ tests/tree/git_tree_owner.phpt | 10 ++++++++++ tests/tree/git_tree_walk.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_clear.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_create.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_entrycount.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_filter.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_free.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_get.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_insert.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_remove.phpt | 10 ++++++++++ tests/treebuilder/git_treebuilder_write.phpt | 10 ++++++++++ 372 files changed, 3716 insertions(+), 7 deletions(-) create mode 100644 tests/blob/git_blob_create_frombuffer.phpt create mode 100644 tests/blob/git_blob_create_fromchunks.phpt create mode 100644 tests/blob/git_blob_create_fromdisk.phpt create mode 100644 tests/blob/git_blob_create_fromworkdir.phpt create mode 100644 tests/blob/git_blob_filtered_content.phpt create mode 100644 tests/blob/git_blob_free.phpt create mode 100644 tests/blob/git_blob_id.phpt create mode 100644 tests/blob/git_blob_is_binary.phpt create mode 100644 tests/blob/git_blob_lookup.phpt create mode 100644 tests/blob/git_blob_lookup_prefix.phpt create mode 100644 tests/blob/git_blob_owner.phpt create mode 100644 tests/blob/git_blob_rawcontent.phpt create mode 100644 tests/blob/git_blob_rawsize.phpt create mode 100644 tests/branch/git_branch_create.phpt create mode 100644 tests/branch/git_branch_delete.phpt create mode 100644 tests/branch/git_branch_is_head.phpt create mode 100644 tests/branch/git_branch_iterator_free.phpt create mode 100644 tests/branch/git_branch_iterator_new.phpt create mode 100644 tests/branch/git_branch_lookup.phpt create mode 100644 tests/branch/git_branch_move.phpt create mode 100644 tests/branch/git_branch_name.phpt create mode 100644 tests/branch/git_branch_next.phpt create mode 100644 tests/branch/git_branch_remote_name.phpt create mode 100644 tests/branch/git_branch_upstream.phpt create mode 100644 tests/branch/git_branch_upstream_name.phpt create mode 100644 tests/checkout/git_checkout_head.phpt create mode 100644 tests/checkout/git_checkout_index.phpt create mode 100644 tests/checkout/git_checkout_tree.phpt create mode 100644 tests/clone/git_clone.phpt create mode 100644 tests/clone/git_clone_into.phpt create mode 100644 tests/commit/git_commit_author.phpt create mode 100644 tests/commit/git_commit_committer.phpt create mode 100644 tests/commit/git_commit_create.phpt create mode 100644 tests/commit/git_commit_id.phpt create mode 100644 tests/commit/git_commit_lookup.phpt create mode 100644 tests/commit/git_commit_lookup_prefix.phpt create mode 100644 tests/commit/git_commit_message.phpt create mode 100644 tests/commit/git_commit_message_encoding.phpt create mode 100644 tests/commit/git_commit_message_raw.phpt create mode 100644 tests/commit/git_commit_nth_gen_ancestor.phpt create mode 100644 tests/commit/git_commit_owner.phpt create mode 100644 tests/commit/git_commit_parent.phpt create mode 100644 tests/commit/git_commit_parent_id.phpt create mode 100644 tests/commit/git_commit_parentcount.phpt create mode 100644 tests/commit/git_commit_raw_header.phpt create mode 100644 tests/commit/git_commit_time.phpt create mode 100644 tests/commit/git_commit_time_offset.phpt create mode 100644 tests/commit/git_commit_tree.phpt create mode 100644 tests/commit/git_commit_tree_id.phpt create mode 100644 tests/config/git_config_add_file_ondisk.phpt create mode 100644 tests/config/git_config_backend_foreach_match.phpt create mode 100644 tests/config/git_config_delete_entry.phpt create mode 100644 tests/config/git_config_delete_multivar.phpt create mode 100644 tests/config/git_config_find_global.phpt create mode 100644 tests/config/git_config_find_system.phpt create mode 100644 tests/config/git_config_find_xdg.phpt create mode 100644 tests/config/git_config_foreach.phpt create mode 100644 tests/config/git_config_foreach_match.phpt create mode 100644 tests/config/git_config_free.phpt create mode 100644 tests/config/git_config_get_bool.phpt create mode 100644 tests/config/git_config_get_entry.phpt create mode 100644 tests/config/git_config_get_int32.phpt create mode 100644 tests/config/git_config_get_int64.phpt create mode 100644 tests/config/git_config_get_mapped.phpt create mode 100644 tests/config/git_config_get_multivar_foreach.phpt create mode 100644 tests/config/git_config_get_string.phpt create mode 100644 tests/config/git_config_iterator_free.phpt create mode 100644 tests/config/git_config_iterator_glob_new.phpt create mode 100644 tests/config/git_config_iterator_new.phpt create mode 100644 tests/config/git_config_lookup_map_value.phpt create mode 100644 tests/config/git_config_multivar_iterator_new.phpt create mode 100644 tests/config/git_config_new.phpt create mode 100644 tests/config/git_config_next.phpt create mode 100644 tests/config/git_config_open_default.phpt create mode 100644 tests/config/git_config_open_global.phpt create mode 100644 tests/config/git_config_open_level.phpt create mode 100644 tests/config/git_config_open_ondisk.phpt create mode 100644 tests/config/git_config_parse_bool.phpt create mode 100644 tests/config/git_config_parse_int32.phpt create mode 100644 tests/config/git_config_parse_int64.phpt create mode 100644 tests/config/git_config_refresh.phpt create mode 100644 tests/config/git_config_set_bool.phpt create mode 100644 tests/config/git_config_set_int32.phpt create mode 100644 tests/config/git_config_set_int64.phpt create mode 100644 tests/config/git_config_set_multivar.phpt create mode 100644 tests/config/git_config_set_string.phpt create mode 100644 tests/cred/git_cred_default_new.phpt create mode 100644 tests/cred/git_cred_has_username.phpt create mode 100644 tests/cred/git_cred_ssh_custom_new.phpt create mode 100644 tests/cred/git_cred_ssh_key_new.phpt create mode 100644 tests/cred/git_cred_userpass.phpt create mode 100644 tests/cred/git_cred_userpass_plaintext_new.phpt create mode 100644 tests/diff/git_diff_blob_to_buffer.phpt create mode 100644 tests/diff/git_diff_blobs.phpt create mode 100644 tests/diff/git_diff_find_similar.phpt create mode 100644 tests/diff/git_diff_foreach.phpt create mode 100644 tests/diff/git_diff_free.phpt create mode 100644 tests/diff/git_diff_get_delta.phpt create mode 100644 tests/diff/git_diff_index_to_workdir.phpt create mode 100644 tests/diff/git_diff_is_sorted_icase.phpt create mode 100644 tests/diff/git_diff_merge.phpt create mode 100644 tests/diff/git_diff_num_deltas.phpt create mode 100644 tests/diff/git_diff_num_deltas_of_type.phpt create mode 100644 tests/diff/git_diff_options_init.phpt create mode 100644 tests/diff/git_diff_print.phpt create mode 100644 tests/diff/git_diff_status_char.phpt create mode 100644 tests/diff/git_diff_tree_to_index.phpt create mode 100644 tests/diff/git_diff_tree_to_tree.phpt create mode 100644 tests/diff/git_diff_tree_to_workdir.phpt create mode 100644 tests/diff/git_diff_tree_to_workdir_with_index.phpt create mode 100644 tests/filter/git_filter_list_apply_to_blob.phpt create mode 100644 tests/filter/git_filter_list_apply_to_data.phpt create mode 100644 tests/filter/git_filter_list_apply_to_file.phpt create mode 100644 tests/filter/git_filter_list_free.phpt create mode 100644 tests/filter/git_filter_list_length.phpt create mode 100644 tests/filter/git_filter_list_load.phpt create mode 100644 tests/filter/git_filter_list_new.phpt create mode 100644 tests/filter/git_filter_list_push.phpt create mode 100644 tests/filter/git_filter_lookup.phpt create mode 100644 tests/filter/git_filter_register.phpt create mode 100644 tests/filter/git_filter_source_filemode.phpt create mode 100644 tests/filter/git_filter_source_id.phpt create mode 100644 tests/filter/git_filter_source_mode.phpt create mode 100644 tests/filter/git_filter_source_path.phpt create mode 100644 tests/filter/git_filter_source_repo.phpt create mode 100644 tests/filter/git_filter_unregister.phpt create mode 100644 tests/ignore/git_ignore_add_rule.phpt create mode 100644 tests/ignore/git_ignore_clear_internal_rules.phpt create mode 100644 tests/ignore/git_ignore_path_is_ignored.phpt create mode 100644 tests/index/git_index_add.phpt create mode 100644 tests/index/git_index_add_all.phpt create mode 100644 tests/index/git_index_add_bypath.phpt create mode 100644 tests/index/git_index_caps.phpt create mode 100644 tests/index/git_index_clear.phpt create mode 100644 tests/index/git_index_conflict_add.phpt create mode 100644 tests/index/git_index_conflict_cleanup.phpt create mode 100644 tests/index/git_index_conflict_get.phpt create mode 100644 tests/index/git_index_conflict_iterator_free.phpt create mode 100644 tests/index/git_index_conflict_iterator_new.phpt create mode 100644 tests/index/git_index_conflict_next.phpt create mode 100644 tests/index/git_index_conflict_remove.phpt create mode 100644 tests/index/git_index_entry_stage.phpt create mode 100644 tests/index/git_index_entrycount.phpt create mode 100644 tests/index/git_index_find.phpt create mode 100644 tests/index/git_index_free.phpt create mode 100644 tests/index/git_index_get_byindex.phpt create mode 100644 tests/index/git_index_get_bypath.phpt create mode 100644 tests/index/git_index_has_conflicts.phpt create mode 100644 tests/index/git_index_new.phpt create mode 100644 tests/index/git_index_open.phpt create mode 100644 tests/index/git_index_owner.phpt create mode 100644 tests/index/git_index_path.phpt create mode 100644 tests/index/git_index_read.phpt create mode 100644 tests/index/git_index_read_tree.phpt create mode 100644 tests/index/git_index_remove.phpt create mode 100644 tests/index/git_index_remove_all.phpt create mode 100644 tests/index/git_index_remove_bypath.phpt create mode 100644 tests/index/git_index_remove_directory.phpt create mode 100644 tests/index/git_index_set_caps.phpt create mode 100644 tests/index/git_index_update_all.phpt create mode 100644 tests/index/git_index_write.phpt create mode 100644 tests/index/git_index_write_tree.phpt create mode 100644 tests/index/git_index_write_tree_to.phpt create mode 100644 tests/indexer/git_indexer_append.phpt create mode 100644 tests/indexer/git_indexer_commit.phpt create mode 100644 tests/indexer/git_indexer_free.phpt create mode 100644 tests/indexer/git_indexer_hash.phpt create mode 100644 tests/indexer/git_indexer_new.phpt create mode 100644 tests/merge/git_merge.phpt create mode 100644 tests/merge/git_merge_base.phpt create mode 100644 tests/merge/git_merge_base_many.phpt create mode 100644 tests/merge/git_merge_head_free.phpt create mode 100644 tests/merge/git_merge_head_from_fetchhead.phpt create mode 100644 tests/merge/git_merge_head_from_oid.phpt create mode 100644 tests/merge/git_merge_head_from_ref.phpt create mode 100644 tests/merge/git_merge_result_fastforward_oid.phpt create mode 100644 tests/merge/git_merge_result_free.phpt create mode 100644 tests/merge/git_merge_result_is_fastforward.phpt create mode 100644 tests/merge/git_merge_result_is_uptodate.phpt create mode 100644 tests/merge/git_merge_trees.phpt create mode 100644 tests/object/git_object__size.phpt create mode 100644 tests/object/git_object_dup.phpt create mode 100644 tests/object/git_object_free.phpt create mode 100644 tests/object/git_object_id.phpt create mode 100644 tests/object/git_object_lookup.phpt create mode 100644 tests/object/git_object_lookup_bypath.phpt create mode 100644 tests/object/git_object_lookup_prefix.phpt create mode 100644 tests/object/git_object_owner.phpt create mode 100644 tests/object/git_object_peel.phpt create mode 100644 tests/object/git_object_string2type.phpt create mode 100644 tests/object/git_object_type.phpt create mode 100644 tests/object/git_object_type2string.phpt create mode 100644 tests/object/git_object_typeisloose.phpt create mode 100644 tests/patch/git_patch_free.phpt create mode 100644 tests/patch/git_patch_from_blob_and_buffer.phpt create mode 100644 tests/patch/git_patch_from_blobs.phpt create mode 100644 tests/patch/git_patch_from_diff.phpt create mode 100644 tests/patch/git_patch_get_delta.phpt create mode 100644 tests/patch/git_patch_get_hunk.phpt create mode 100644 tests/patch/git_patch_get_line_in_hunk.phpt create mode 100644 tests/patch/git_patch_line_stats.phpt create mode 100644 tests/patch/git_patch_num_hunks.phpt create mode 100644 tests/patch/git_patch_num_lines_in_hunk.phpt create mode 100644 tests/patch/git_patch_print.phpt create mode 100644 tests/patch/git_patch_size.phpt create mode 100644 tests/patch/git_patch_to_str.phpt create mode 100644 tests/pathspec/git_pathspec_free.phpt create mode 100644 tests/pathspec/git_pathspec_match_diff.phpt create mode 100644 tests/pathspec/git_pathspec_match_index.phpt create mode 100644 tests/pathspec/git_pathspec_match_list_diff_entry.phpt create mode 100644 tests/pathspec/git_pathspec_match_list_entry.phpt create mode 100644 tests/pathspec/git_pathspec_match_list_entrycount.phpt create mode 100644 tests/pathspec/git_pathspec_match_list_failed_entry.phpt create mode 100644 tests/pathspec/git_pathspec_match_list_failed_entrycount.phpt create mode 100644 tests/pathspec/git_pathspec_match_list_free.phpt create mode 100644 tests/pathspec/git_pathspec_match_tree.phpt create mode 100644 tests/pathspec/git_pathspec_match_workdir.phpt create mode 100644 tests/pathspec/git_pathspec_matches_path.phpt create mode 100644 tests/pathspec/git_pathspec_new.phpt create mode 100644 tests/reference/git_reference_cmp.phpt create mode 100644 tests/reference/git_reference_create.phpt create mode 100644 tests/reference/git_reference_delete.phpt create mode 100644 tests/reference/git_reference_dwim.phpt create mode 100644 tests/reference/git_reference_foreach.phpt create mode 100644 tests/reference/git_reference_foreach_glob.phpt create mode 100644 tests/reference/git_reference_foreach_name.phpt create mode 100644 tests/reference/git_reference_free.phpt create mode 100644 tests/reference/git_reference_has_log.phpt create mode 100644 tests/reference/git_reference_is_branch.phpt create mode 100644 tests/reference/git_reference_is_remote.phpt create mode 100644 tests/reference/git_reference_is_tag.phpt create mode 100644 tests/reference/git_reference_is_valid_name.phpt create mode 100644 tests/reference/git_reference_iterator_free.phpt create mode 100644 tests/reference/git_reference_iterator_glob_new.phpt create mode 100644 tests/reference/git_reference_iterator_new.phpt create mode 100644 tests/reference/git_reference_list.phpt create mode 100644 tests/reference/git_reference_lookup.phpt create mode 100644 tests/reference/git_reference_name.phpt create mode 100644 tests/reference/git_reference_name_to_id.phpt create mode 100644 tests/reference/git_reference_next.phpt create mode 100644 tests/reference/git_reference_next_name.phpt create mode 100644 tests/reference/git_reference_normalize_name.phpt create mode 100644 tests/reference/git_reference_owner.phpt create mode 100644 tests/reference/git_reference_peel.phpt create mode 100644 tests/reference/git_reference_rename.phpt create mode 100644 tests/reference/git_reference_resolve.phpt create mode 100644 tests/reference/git_reference_set_target.phpt create mode 100644 tests/reference/git_reference_shorthand.phpt create mode 100644 tests/reference/git_reference_symbolic_create.phpt create mode 100644 tests/reference/git_reference_symbolic_set_target.phpt create mode 100644 tests/reference/git_reference_symbolic_target.phpt create mode 100644 tests/reference/git_reference_target.phpt create mode 100644 tests/reference/git_reference_target_peel.phpt create mode 100644 tests/reference/git_reference_type.phpt create mode 100644 tests/repository/git_repository_config.phpt create mode 100644 tests/repository/git_repository_detach_head.phpt create mode 100644 tests/repository/git_repository_discover.phpt create mode 100644 tests/repository/git_repository_fetchhead_foreach.phpt create mode 100644 tests/repository/git_repository_free.phpt create mode 100644 tests/repository/git_repository_get_namespace.phpt create mode 100644 tests/repository/git_repository_hashfile.phpt create mode 100644 tests/repository/git_repository_head.phpt create mode 100644 tests/repository/git_repository_head_detached.phpt create mode 100644 tests/repository/git_repository_head_unborn.phpt create mode 100644 tests/repository/git_repository_index.phpt create mode 100644 tests/repository/git_repository_init.phpt create mode 100644 tests/repository/git_repository_init_ext.phpt create mode 100644 tests/repository/git_repository_is_bare.phpt create mode 100644 tests/repository/git_repository_is_empty.phpt create mode 100644 tests/repository/git_repository_is_shallow.phpt create mode 100644 tests/repository/git_repository_merge_cleanup.phpt create mode 100644 tests/repository/git_repository_mergehead_foreach.phpt create mode 100644 tests/repository/git_repository_message.phpt create mode 100644 tests/repository/git_repository_message_remove.phpt create mode 100644 tests/repository/git_repository_new.phpt create mode 100644 tests/repository/git_repository_odb.phpt create mode 100644 tests/repository/git_repository_open.phpt create mode 100644 tests/repository/git_repository_open_bare.phpt create mode 100644 tests/repository/git_repository_open_ext.phpt create mode 100644 tests/repository/git_repository_path.phpt create mode 100644 tests/repository/git_repository_refdb.phpt create mode 100644 tests/repository/git_repository_set_head.phpt create mode 100644 tests/repository/git_repository_set_head_detached.phpt create mode 100644 tests/repository/git_repository_set_namespace.phpt create mode 100644 tests/repository/git_repository_set_workdir.phpt create mode 100644 tests/repository/git_repository_state.phpt create mode 100644 tests/repository/git_repository_workdir.phpt create mode 100644 tests/repository/git_repository_wrap_odb.phpt create mode 100644 tests/revparse/git_revparse.phpt create mode 100644 tests/revparse/git_revparse_ext.phpt create mode 100644 tests/revparse/git_revparse_single.phpt create mode 100644 tests/revwalk/git_revwalk_free.phpt create mode 100644 tests/revwalk/git_revwalk_hide.phpt create mode 100644 tests/revwalk/git_revwalk_hide_glob.phpt create mode 100644 tests/revwalk/git_revwalk_hide_head.phpt create mode 100644 tests/revwalk/git_revwalk_hide_ref.phpt create mode 100644 tests/revwalk/git_revwalk_new.phpt create mode 100644 tests/revwalk/git_revwalk_next.phpt create mode 100644 tests/revwalk/git_revwalk_push.phpt create mode 100644 tests/revwalk/git_revwalk_push_glob.phpt create mode 100644 tests/revwalk/git_revwalk_push_head.phpt create mode 100644 tests/revwalk/git_revwalk_push_range.phpt create mode 100644 tests/revwalk/git_revwalk_push_ref.phpt create mode 100644 tests/revwalk/git_revwalk_repository.phpt create mode 100644 tests/revwalk/git_revwalk_reset.phpt create mode 100644 tests/revwalk/git_revwalk_simplify_first_parent.phpt create mode 100644 tests/revwalk/git_revwalk_sorting.phpt create mode 100644 tests/status/git_status_byindex.phpt create mode 100644 tests/status/git_status_file.phpt create mode 100644 tests/status/git_status_foreach.phpt create mode 100644 tests/status/git_status_foreach_ext.phpt create mode 100644 tests/status/git_status_list_entrycount.phpt create mode 100644 tests/status/git_status_list_free.phpt create mode 100644 tests/status/git_status_list_new.phpt create mode 100644 tests/status/git_status_should_ignore.phpt create mode 100644 tests/tag/git_tag_annotation_create.phpt create mode 100644 tests/tag/git_tag_create.phpt create mode 100644 tests/tag/git_tag_create_frombuffer.phpt create mode 100644 tests/tag/git_tag_create_lightweight.phpt create mode 100644 tests/tag/git_tag_delete.phpt create mode 100644 tests/tag/git_tag_foreach.phpt create mode 100644 tests/tag/git_tag_free.phpt create mode 100644 tests/tag/git_tag_id.phpt create mode 100644 tests/tag/git_tag_list.phpt create mode 100644 tests/tag/git_tag_list_match.phpt create mode 100644 tests/tag/git_tag_lookup.phpt create mode 100644 tests/tag/git_tag_lookup_prefix.phpt create mode 100644 tests/tag/git_tag_message.phpt create mode 100644 tests/tag/git_tag_name.phpt create mode 100644 tests/tag/git_tag_owner.phpt create mode 100644 tests/tag/git_tag_peel.phpt create mode 100644 tests/tag/git_tag_tagger.phpt create mode 100644 tests/tag/git_tag_target.phpt create mode 100644 tests/tag/git_tag_target_id.phpt create mode 100644 tests/tag/git_tag_target_type.phpt create mode 100644 tests/transport/git_smart_subtransport_git.phpt create mode 100644 tests/transport/git_smart_subtransport_http.phpt create mode 100644 tests/transport/git_smart_subtransport_ssh.phpt create mode 100644 tests/transport/git_transport_dummy.phpt create mode 100644 tests/transport/git_transport_local.phpt create mode 100644 tests/transport/git_transport_new.phpt create mode 100644 tests/transport/git_transport_register.phpt create mode 100644 tests/transport/git_transport_smart.phpt create mode 100644 tests/transport/git_transport_unregister.phpt create mode 100644 tests/tree/git_tree_entry_byindex.phpt create mode 100644 tests/tree/git_tree_entry_byname.phpt create mode 100644 tests/tree/git_tree_entry_byoid.phpt create mode 100644 tests/tree/git_tree_entry_bypath.phpt create mode 100644 tests/tree/git_tree_entry_cmp.phpt create mode 100644 tests/tree/git_tree_entry_dup.phpt create mode 100644 tests/tree/git_tree_entry_filemode.phpt create mode 100644 tests/tree/git_tree_entry_filemode_raw.phpt create mode 100644 tests/tree/git_tree_entry_free.phpt create mode 100644 tests/tree/git_tree_entry_id.phpt create mode 100644 tests/tree/git_tree_entry_name.phpt create mode 100644 tests/tree/git_tree_entry_type.phpt create mode 100644 tests/tree/git_tree_entrycount.phpt create mode 100644 tests/tree/git_tree_free.phpt create mode 100644 tests/tree/git_tree_id.phpt create mode 100644 tests/tree/git_tree_lookup.phpt create mode 100644 tests/tree/git_tree_owner.phpt create mode 100644 tests/tree/git_tree_walk.phpt create mode 100644 tests/treebuilder/git_treebuilder_clear.phpt create mode 100644 tests/treebuilder/git_treebuilder_create.phpt create mode 100644 tests/treebuilder/git_treebuilder_entrycount.phpt create mode 100644 tests/treebuilder/git_treebuilder_filter.phpt create mode 100644 tests/treebuilder/git_treebuilder_free.phpt create mode 100644 tests/treebuilder/git_treebuilder_get.phpt create mode 100644 tests/treebuilder/git_treebuilder_insert.phpt create mode 100644 tests/treebuilder/git_treebuilder_remove.phpt create mode 100644 tests/treebuilder/git_treebuilder_write.phpt diff --git a/.gitignore b/.gitignore index 312104bff7..e59d6338c1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,13 +4,12 @@ tmp/* # ignore tests -tests/*.php -tests/*.sh -tests/*.log -tests/*.diff -tests/*.exp -tests/*.out -tests/mock +tests/*/*.php +tests/*/*.sh +tests/*/*.log +tests/*/*.diff +tests/*/*.exp +tests/*/*.out # ignore phpized files Makefile.global diff --git a/tests/blob/git_blob_create_frombuffer.phpt b/tests/blob/git_blob_create_frombuffer.phpt new file mode 100644 index 0000000000..04f99aa180 --- /dev/null +++ b/tests/blob/git_blob_create_frombuffer.phpt @@ -0,0 +1,10 @@ +--TEST-- +Check for git_blob_create_frombuffer presence +--SKIPIF-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + Date: Sun, 12 Jan 2014 14:41:34 +0900 Subject: [PATCH 035/136] add constants --- php_git2.c | 468 +++++++++++++++++++++++++++++++++++++++++++++++++++++ php_git2.h | 2 + 2 files changed, 470 insertions(+) diff --git a/php_git2.c b/php_git2.c index 8eaec4e9f5..0f931a4784 100644 --- a/php_git2.c +++ b/php_git2.c @@ -102,6 +102,28 @@ static zend_class_entry *php_git2_get_exception_base(TSRMLS_D) #endif } +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_resource_type, 0, 0, 1) + ZEND_ARG_INFO(0, resource) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_resource_type(resource $git) + */ +PHP_FUNCTION(git_resource_type) +{ + int result = 0; + zval *resource = NULL; + php_git2_t *_resource= NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &resource) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_resource, php_git2_t*, &resource, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + RETURN_LONG(_resource->type); +} +/* }}} */ + static zend_function_entry php_git2_functions[] = { /* repository */ PHP_FE(git_repository_new, arginfo_git_repository_new) @@ -532,6 +554,8 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_merge_result_fastforward_oid, arginfo_git_merge_result_fastforward_oid) PHP_FE(git_merge_result_free, arginfo_git_merge_result_free) + /* misc */ + PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END }; @@ -568,6 +592,450 @@ PHP_MINIT_FUNCTION(git2) REGISTER_INI_ENTRIES(); git2_resource_handle = zend_register_list_destructors_ex(destruct_git2, NULL, PHP_GIT2_RESOURCE_NAME, module_number); + + REGISTER_LONG_CONSTANT("GIT_TYPE_REPOSITORY", PHP_GIT2_TYPE_REPOSITORY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_COMMIT", PHP_GIT2_TYPE_COMMIT,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_TREE", PHP_GIT2_TYPE_TREE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_TREE_ENTRY", PHP_GIT2_TYPE_TREE_ENTRY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_BLOB", PHP_GIT2_TYPE_BLOB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_REVWALK", PHP_GIT2_TYPE_REVWALK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_TREEBUILDER", PHP_GIT2_TYPE_TREEBUILDER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_REFERENCE", PHP_GIT2_TYPE_REFERENCE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_CONFIG", PHP_GIT2_TYPE_CONFIG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_OBJECT", PHP_GIT2_TYPE_OBJECT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_INDEX", PHP_GIT2_TYPE_INDEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_ODB", PHP_GIT2_TYPE_ODB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_REFDB", PHP_GIT2_TYPE_REFDB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_BRANCH_ITERATOR", PHP_GIT2_TYPE_BRANCH_ITERATOR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_TAG", PHP_GIT2_TYPE_TAG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_CRED", PHP_GIT2_TYPE_CRED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_TRANSPORT", PHP_GIT2_TYPE_TRANSPORT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_REMOTE", PHP_GIT2_TYPE_REMOTE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_DIFF", PHP_GIT2_TYPE_DIFF, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_MERGE_RESULT", PHP_GIT2_TYPE_MERGE_RESULT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_MERGE_HEAD", PHP_GIT2_TYPE_MERGE_HEAD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_PATHSPEC", PHP_GIT2_TYPE_PATHSPEC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_PATHSPEC_MATCH_LIST", PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_PATCH", PHP_GIT2_TYPE_PATCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_DIFF_HUNK", PHP_GIT2_TYPE_DIFF_HUNK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_STATUS_LIST", PHP_GIT2_TYPE_STATUS_LIST, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_BUF", PHP_GIT2_TYPE_BUF, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_FILTER_LIST", PHP_GIT2_TYPE_FILTER_LIST, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_FILTER_SOURCE", PHP_GIT2_TYPE_FILTER_SOURCE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TYPE_DIFF_LINE", PHP_GIT2_TYPE_DIFF_LINE, CONST_CS | CONST_PERSISTENT); + + /* git_ref_t */ + REGISTER_LONG_CONSTANT("GIT_REF_INVALID", GIT_REF_INVALID, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REF_OID", GIT_REF_OID, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REF_SYMBOLIC", GIT_REF_SYMBOLIC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REF_LISTALL", GIT_REF_LISTALL, CONST_CS | CONST_PERSISTENT); + /* git_branch_t */ + REGISTER_LONG_CONSTANT("GIT_BRANCH_LOCAL", GIT_BRANCH_LOCAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_BRANCH_REMOTE", GIT_BRANCH_REMOTE, CONST_CS | CONST_PERSISTENT); + /* git_filemode_t */ + REGISTER_LONG_CONSTANT("GIT_FILEMODE_NEW", GIT_FILEMODE_NEW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILEMODE_TREE", GIT_FILEMODE_TREE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILEMODE_BLOB", GIT_FILEMODE_BLOB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILEMODE_BLOB_EXECUTABLE", GIT_FILEMODE_BLOB_EXECUTABLE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILEMODE_LINK", GIT_FILEMODE_LINK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILEMODE_COMMIT", GIT_FILEMODE_COMMIT, CONST_CS | CONST_PERSISTENT); + /* git_submodule_update_t */ + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_UPDATE_RESET", GIT_SUBMODULE_UPDATE_RESET, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_UPDATE_CHECKOUT", GIT_SUBMODULE_UPDATE_CHECKOUT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_UPDATE_REBASE", GIT_SUBMODULE_UPDATE_REBASE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_UPDATE_MERGE", GIT_SUBMODULE_UPDATE_MERGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_UPDATE_NONE", GIT_SUBMODULE_UPDATE_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_UPDATE_DEFAULT", GIT_SUBMODULE_UPDATE_DEFAULT, CONST_CS | CONST_PERSISTENT); + /* git_submodule_ignore_t */ + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_IGNORE_RESET", GIT_SUBMODULE_IGNORE_RESET, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_IGNORE_NONE", GIT_SUBMODULE_IGNORE_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_IGNORE_UNTRACKED", GIT_SUBMODULE_IGNORE_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_IGNORE_DIRTY", GIT_SUBMODULE_IGNORE_DIRTY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_IGNORE_ALL", GIT_SUBMODULE_IGNORE_ALL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_IGNORE_DEFAULT", GIT_SUBMODULE_IGNORE_DEFAULT, CONST_CS | CONST_PERSISTENT); + + /* git_attr_t */ + REGISTER_LONG_CONSTANT("GIT_ATTR_UNSPECIFIED_T", GIT_ATTR_UNSPECIFIED_T, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ATTR_TRUE_T", GIT_ATTR_TRUE_T, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ATTR_FALSE_T", GIT_ATTR_FALSE_T, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ATTR_VALUE_T", GIT_ATTR_VALUE_T, CONST_CS | CONST_PERSISTENT); + + /* git_blame_flag_t */ + REGISTER_LONG_CONSTANT("GIT_BLAME_NORMAL", GIT_BLAME_NORMAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_BLAME_TRACK_COPIES_SAME_FILE", GIT_BLAME_TRACK_COPIES_SAME_FILE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES", GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES", GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES", GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES, CONST_CS | CONST_PERSISTENT); + + /* git_checkout_strategy_t */ + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NONE", GIT_CHECKOUT_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_SAFE", GIT_CHECKOUT_SAFE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_SAFE_CREATE", GIT_CHECKOUT_SAFE_CREATE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_FORCE", GIT_CHECKOUT_FORCE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_ALLOW_CONFLICTS", GIT_CHECKOUT_ALLOW_CONFLICTS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_REMOVE_UNTRACKED", GIT_CHECKOUT_REMOVE_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_REMOVE_IGNORED", GIT_CHECKOUT_REMOVE_IGNORED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_UPDATE_ONLY", GIT_CHECKOUT_UPDATE_ONLY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_DONT_UPDATE_INDEX", GIT_CHECKOUT_DONT_UPDATE_INDEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NO_REFRESH", GIT_CHECKOUT_NO_REFRESH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_SKIP_UNMERGED", GIT_CHECKOUT_SKIP_UNMERGED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_USE_OURS", GIT_CHECKOUT_USE_OURS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_USE_THEIRS", GIT_CHECKOUT_USE_THEIRS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH", GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES", GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_UPDATE_SUBMODULES", GIT_CHECKOUT_UPDATE_SUBMODULES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED", GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED, CONST_CS | CONST_PERSISTENT); + + /* git_checkout_notify_t */ + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NOTIFY_NONE", GIT_CHECKOUT_NOTIFY_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NOTIFY_CONFLICT", GIT_CHECKOUT_NOTIFY_CONFLICT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NOTIFY_DIRTY", GIT_CHECKOUT_NOTIFY_DIRTY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NOTIFY_UPDATED", GIT_CHECKOUT_NOTIFY_UPDATED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NOTIFY_UNTRACKED", GIT_CHECKOUT_NOTIFY_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NOTIFY_IGNORED", GIT_CHECKOUT_NOTIFY_IGNORED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CHECKOUT_NOTIFY_ALL", GIT_CHECKOUT_NOTIFY_ALL, CONST_CS | CONST_PERSISTENT); + + /* git_cap_t */ + REGISTER_LONG_CONSTANT("GIT_CAP_THREADS", GIT_CAP_THREADS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CAP_HTTPS", GIT_CAP_HTTPS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CAP_SSH", GIT_CAP_SSH, CONST_CS | CONST_PERSISTENT); + + /* git_libgit2_opt_t */ + REGISTER_LONG_CONSTANT("GIT_OPT_GET_MWINDOW_SIZE", GIT_OPT_GET_MWINDOW_SIZE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_SET_MWINDOW_SIZE", GIT_OPT_SET_MWINDOW_SIZE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_GET_MWINDOW_MAPPED_LIMIT", GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_SET_MWINDOW_MAPPED_LIMIT", GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_GET_SEARCH_PATH", GIT_OPT_GET_SEARCH_PATH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_SET_SEARCH_PATH", GIT_OPT_SET_SEARCH_PATH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_SET_CACHE_OBJECT_LIMIT", GIT_OPT_SET_CACHE_OBJECT_LIMIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_SET_CACHE_MAX_SIZE", GIT_OPT_SET_CACHE_MAX_SIZE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_ENABLE_CACHING", GIT_OPT_ENABLE_CACHING, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_GET_CACHED_MEMORY", GIT_OPT_GET_CACHED_MEMORY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_GET_TEMPLATE_PATH", GIT_OPT_GET_TEMPLATE_PATH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OPT_SET_TEMPLATE_PATH", GIT_OPT_SET_TEMPLATE_PATH, CONST_CS | CONST_PERSISTENT); + + /* git_config_level_t */ + REGISTER_LONG_CONSTANT("GIT_CONFIG_LEVEL_SYSTEM", GIT_CONFIG_LEVEL_SYSTEM, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CONFIG_LEVEL_XDG", GIT_CONFIG_LEVEL_XDG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CONFIG_LEVEL_GLOBAL", GIT_CONFIG_LEVEL_GLOBAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CONFIG_LEVEL_LOCAL", GIT_CONFIG_LEVEL_LOCAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CONFIG_LEVEL_APP", GIT_CONFIG_LEVEL_APP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CONFIG_HIGHEST_LEVEL", GIT_CONFIG_HIGHEST_LEVEL, CONST_CS | CONST_PERSISTENT); + + /* git_cvar_t */ + REGISTER_LONG_CONSTANT("GIT_CVAR_FALSE", GIT_CVAR_FALSE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CVAR_TRUE", GIT_CVAR_TRUE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CVAR_INT32", GIT_CVAR_INT32, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CVAR_STRING", GIT_CVAR_STRING, CONST_CS | CONST_PERSISTENT); + + /* git_diff_option_t */ + REGISTER_LONG_CONSTANT("GIT_DIFF_NORMAL", GIT_DIFF_NORMAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_REVERSE", GIT_DIFF_REVERSE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_INCLUDE_IGNORED", GIT_DIFF_INCLUDE_IGNORED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_RECURSE_IGNORED_DIRS", GIT_DIFF_RECURSE_IGNORED_DIRS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_INCLUDE_UNTRACKED", GIT_DIFF_INCLUDE_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_RECURSE_UNTRACKED_DIRS", GIT_DIFF_RECURSE_UNTRACKED_DIRS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_INCLUDE_UNMODIFIED", GIT_DIFF_INCLUDE_UNMODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_INCLUDE_TYPECHANGE", GIT_DIFF_INCLUDE_TYPECHANGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_INCLUDE_TYPECHANGE_TREES", GIT_DIFF_INCLUDE_TYPECHANGE_TREES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_IGNORE_FILEMODE", GIT_DIFF_IGNORE_FILEMODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_IGNORE_SUBMODULES", GIT_DIFF_IGNORE_SUBMODULES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_IGNORE_CASE", GIT_DIFF_IGNORE_CASE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_DISABLE_PATHSPEC_MATCH", GIT_DIFF_DISABLE_PATHSPEC_MATCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_SKIP_BINARY_CHECK", GIT_DIFF_SKIP_BINARY_CHECK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS", GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FORCE_TEXT", GIT_DIFF_FORCE_TEXT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FORCE_BINARY", GIT_DIFF_FORCE_BINARY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_IGNORE_WHITESPACE", GIT_DIFF_IGNORE_WHITESPACE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_IGNORE_WHITESPACE_CHANGE", GIT_DIFF_IGNORE_WHITESPACE_CHANGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_IGNORE_WHITESPACE_EOL", GIT_DIFF_IGNORE_WHITESPACE_EOL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_SHOW_UNTRACKED_CONTENT", GIT_DIFF_SHOW_UNTRACKED_CONTENT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_SHOW_UNMODIFIED", GIT_DIFF_SHOW_UNMODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_PATIENCE", GIT_DIFF_PATIENCE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_MINIMAL", GIT_DIFF_MINIMAL, CONST_CS | CONST_PERSISTENT); + /* git_diff_flag_t */ + REGISTER_LONG_CONSTANT("GIT_DIFF_FLAG_BINARY", GIT_DIFF_FLAG_BINARY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FLAG_NOT_BINARY", GIT_DIFF_FLAG_NOT_BINARY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FLAG_VALID_OID", GIT_DIFF_FLAG_VALID_OID, CONST_CS | CONST_PERSISTENT); + /* git_delta_t */ + REGISTER_LONG_CONSTANT("GIT_DELTA_UNMODIFIED", GIT_DELTA_UNMODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_ADDED", GIT_DELTA_ADDED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_DELETED", GIT_DELTA_DELETED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_MODIFIED", GIT_DELTA_MODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_RENAMED", GIT_DELTA_RENAMED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_COPIED", GIT_DELTA_COPIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_IGNORED", GIT_DELTA_IGNORED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_UNTRACKED", GIT_DELTA_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DELTA_TYPECHANGE", GIT_DELTA_TYPECHANGE, CONST_CS | CONST_PERSISTENT); + /* git_diff_line_t */ + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_CONTEXT", GIT_DIFF_LINE_CONTEXT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_ADDITION", GIT_DIFF_LINE_ADDITION, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_DELETION", GIT_DIFF_LINE_DELETION, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_CONTEXT_EOFNL", GIT_DIFF_LINE_CONTEXT_EOFNL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_ADD_EOFNL", GIT_DIFF_LINE_ADD_EOFNL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_DEL_EOFNL", GIT_DIFF_LINE_DEL_EOFNL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_FILE_HDR", GIT_DIFF_LINE_FILE_HDR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_HUNK_HDR", GIT_DIFF_LINE_HUNK_HDR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_LINE_BINARY", GIT_DIFF_LINE_BINARY, CONST_CS | CONST_PERSISTENT); + /* git_diff_find_t */ + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_RENAMES", GIT_DIFF_FIND_RENAMES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_RENAMES_FROM_REWRITES", GIT_DIFF_FIND_RENAMES_FROM_REWRITES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_COPIES", GIT_DIFF_FIND_COPIES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED", GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_REWRITES", GIT_DIFF_FIND_REWRITES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_BREAK_REWRITES", GIT_DIFF_BREAK_REWRITES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_AND_BREAK_REWRITES", GIT_DIFF_FIND_AND_BREAK_REWRITES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("(GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES)", (GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES), CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_FOR_UNTRACKED", GIT_DIFF_FIND_FOR_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_ALL", GIT_DIFF_FIND_ALL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE", GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_IGNORE_WHITESPACE", GIT_DIFF_FIND_IGNORE_WHITESPACE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE", GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FIND_EXACT_MATCH_ONLY", GIT_DIFF_FIND_EXACT_MATCH_ONLY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY", GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY, CONST_CS | CONST_PERSISTENT); + /* git_diff_format_t */ + REGISTER_LONG_CONSTANT("GIT_DIFF_FORMAT_PATCH", GIT_DIFF_FORMAT_PATCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FORMAT_PATCH_HEADER", GIT_DIFF_FORMAT_PATCH_HEADER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FORMAT_RAW", GIT_DIFF_FORMAT_RAW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FORMAT_NAME_ONLY", GIT_DIFF_FORMAT_NAME_ONLY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIFF_FORMAT_NAME_STATUS", GIT_DIFF_FORMAT_NAME_STATUS, CONST_CS | CONST_PERSISTENT); + + /* git_error_code */ + REGISTER_LONG_CONSTANT("GIT_OK", GIT_OK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ERROR", GIT_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ENOTFOUND", GIT_ENOTFOUND, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EEXISTS", GIT_EEXISTS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EAMBIGUOUS", GIT_EAMBIGUOUS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EBUFS", GIT_EBUFS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EUSER", GIT_EUSER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EBAREREPO", GIT_EBAREREPO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EUNBORNBRANCH", GIT_EUNBORNBRANCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EUNMERGED", GIT_EUNMERGED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ENONFASTFORWARD", GIT_ENONFASTFORWARD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EINVALIDSPEC", GIT_EINVALIDSPEC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_EMERGECONFLICT", GIT_EMERGECONFLICT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ELOCKED", GIT_ELOCKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PASSTHROUGH", GIT_PASSTHROUGH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_ITEROVER", GIT_ITEROVER, CONST_CS | CONST_PERSISTENT); + + /* git_error_t */ + REGISTER_LONG_CONSTANT("GITERR_NONE", GITERR_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_NOMEMORY", GITERR_NOMEMORY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_OS", GITERR_OS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_INVALID", GITERR_INVALID, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_REFERENCE", GITERR_REFERENCE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_ZLIB", GITERR_ZLIB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_REPOSITORY", GITERR_REPOSITORY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_CONFIG", GITERR_CONFIG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_REGEX", GITERR_REGEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_ODB", GITERR_ODB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_INDEX", GITERR_INDEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_OBJECT", GITERR_OBJECT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_NET", GITERR_NET, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_TAG", GITERR_TAG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_TREE", GITERR_TREE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_INDEXER", GITERR_INDEXER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_SSL", GITERR_SSL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_SUBMODULE", GITERR_SUBMODULE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_THREAD", GITERR_THREAD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_STASH", GITERR_STASH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_CHECKOUT", GITERR_CHECKOUT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_FETCHHEAD", GITERR_FETCHHEAD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_MERGE", GITERR_MERGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_SSH", GITERR_SSH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GITERR_FILTER", GITERR_FILTER, CONST_CS | CONST_PERSISTENT); + + /* git_filter_mode_t */ + REGISTER_LONG_CONSTANT("GIT_FILTER_TO_WORKTREE", GIT_FILTER_TO_WORKTREE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILTER_SMUDGE", GIT_FILTER_SMUDGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILTER_TO_ODB", GIT_FILTER_TO_ODB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_FILTER_CLEAN", GIT_FILTER_CLEAN, CONST_CS | CONST_PERSISTENT); + + /* git_indexcap_t */ + REGISTER_LONG_CONSTANT("GIT_INDEXCAP_IGNORE_CASE", GIT_INDEXCAP_IGNORE_CASE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_INDEXCAP_NO_FILEMODE", GIT_INDEXCAP_NO_FILEMODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_INDEXCAP_NO_SYMLINKS", GIT_INDEXCAP_NO_SYMLINKS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_INDEXCAP_FROM_OWNER", GIT_INDEXCAP_FROM_OWNER, CONST_CS | CONST_PERSISTENT); + /* git_index_add_option_t */ + REGISTER_LONG_CONSTANT("GIT_INDEX_ADD_DEFAULT", GIT_INDEX_ADD_DEFAULT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_INDEX_ADD_FORCE", GIT_INDEX_ADD_FORCE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH", GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_INDEX_ADD_CHECK_PATHSPEC", GIT_INDEX_ADD_CHECK_PATHSPEC, CONST_CS | CONST_PERSISTENT); + + /* git_merge_tree_flag_t */ + REGISTER_LONG_CONSTANT("GIT_MERGE_TREE_FIND_RENAMES", GIT_MERGE_TREE_FIND_RENAMES, CONST_CS | CONST_PERSISTENT); + /* git_merge_automerge_flags */ + REGISTER_LONG_CONSTANT("GIT_MERGE_AUTOMERGE_NORMAL", GIT_MERGE_AUTOMERGE_NORMAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_MERGE_AUTOMERGE_NONE", GIT_MERGE_AUTOMERGE_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_MERGE_AUTOMERGE_FAVOR_OURS", GIT_MERGE_AUTOMERGE_FAVOR_OURS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_MERGE_AUTOMERGE_FAVOR_THEIRS", GIT_MERGE_AUTOMERGE_FAVOR_THEIRS, CONST_CS | CONST_PERSISTENT); + /* git_merge_flags_t */ + REGISTER_LONG_CONSTANT("GIT_MERGE_NO_FASTFORWARD", GIT_MERGE_NO_FASTFORWARD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_MERGE_FASTFORWARD_ONLY", GIT_MERGE_FASTFORWARD_ONLY, CONST_CS | CONST_PERSISTENT); + + /* git_direction */ + REGISTER_LONG_CONSTANT("GIT_DIRECTION_FETCH", GIT_DIRECTION_FETCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_DIRECTION_PUSH", GIT_DIRECTION_PUSH, CONST_CS | CONST_PERSISTENT); + + /* git_odb_stream_t */ + REGISTER_LONG_CONSTANT("GIT_STREAM_RDONLY", GIT_STREAM_RDONLY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STREAM_WRONLY", GIT_STREAM_WRONLY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STREAM_RW", GIT_STREAM_RW, CONST_CS | CONST_PERSISTENT); + + /* git_packbuilder_stage_t */ + REGISTER_LONG_CONSTANT("GIT_PACKBUILDER_ADDING_OBJECTS", GIT_PACKBUILDER_ADDING_OBJECTS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PACKBUILDER_DELTAFICATION", GIT_PACKBUILDER_DELTAFICATION, CONST_CS | CONST_PERSISTENT); + + /* git_pathspec_flag_t */ + REGISTER_LONG_CONSTANT("GIT_PATHSPEC_DEFAULT", GIT_PATHSPEC_DEFAULT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PATHSPEC_IGNORE_CASE", GIT_PATHSPEC_IGNORE_CASE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PATHSPEC_USE_CASE", GIT_PATHSPEC_USE_CASE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PATHSPEC_NO_GLOB", GIT_PATHSPEC_NO_GLOB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PATHSPEC_NO_MATCH_ERROR", GIT_PATHSPEC_NO_MATCH_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PATHSPEC_FIND_FAILURES", GIT_PATHSPEC_FIND_FAILURES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_PATHSPEC_FAILURES_ONLY", GIT_PATHSPEC_FAILURES_ONLY, CONST_CS | CONST_PERSISTENT); + + /* git_reference_normalize_t */ + REGISTER_LONG_CONSTANT("GIT_REF_FORMAT_NORMAL", GIT_REF_FORMAT_NORMAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REF_FORMAT_ALLOW_ONELEVEL", GIT_REF_FORMAT_ALLOW_ONELEVEL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REF_FORMAT_REFSPEC_PATTERN", GIT_REF_FORMAT_REFSPEC_PATTERN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REF_FORMAT_REFSPEC_SHORTHAND", GIT_REF_FORMAT_REFSPEC_SHORTHAND, CONST_CS | CONST_PERSISTENT); + + /* git_remote_autotag_option_t */ + REGISTER_LONG_CONSTANT("GIT_REMOTE_DOWNLOAD_TAGS_AUTO", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REMOTE_DOWNLOAD_TAGS_NONE", GIT_REMOTE_DOWNLOAD_TAGS_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REMOTE_DOWNLOAD_TAGS_ALL", GIT_REMOTE_DOWNLOAD_TAGS_ALL, CONST_CS | CONST_PERSISTENT); + + /* git_repository_open_flag_t */ + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_OPEN_NO_SEARCH", GIT_REPOSITORY_OPEN_NO_SEARCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_OPEN_CROSS_FS", GIT_REPOSITORY_OPEN_CROSS_FS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_OPEN_BARE", GIT_REPOSITORY_OPEN_BARE, CONST_CS | CONST_PERSISTENT); + /* git_repository_init_flag_t */ + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_BARE", GIT_REPOSITORY_INIT_BARE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_NO_REINIT", GIT_REPOSITORY_INIT_NO_REINIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_NO_DOTGIT_DIR", GIT_REPOSITORY_INIT_NO_DOTGIT_DIR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_MKDIR", GIT_REPOSITORY_INIT_MKDIR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_MKPATH", GIT_REPOSITORY_INIT_MKPATH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE", GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE, CONST_CS | CONST_PERSISTENT); + /* git_repository_init_mode_t */ + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_SHARED_UMASK", GIT_REPOSITORY_INIT_SHARED_UMASK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_SHARED_GROUP", GIT_REPOSITORY_INIT_SHARED_GROUP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_INIT_SHARED_ALL", GIT_REPOSITORY_INIT_SHARED_ALL, CONST_CS | CONST_PERSISTENT); + /* git_repository_state_t */ + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_NONE", GIT_REPOSITORY_STATE_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_MERGE", GIT_REPOSITORY_STATE_MERGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_REVERT", GIT_REPOSITORY_STATE_REVERT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_CHERRY_PICK", GIT_REPOSITORY_STATE_CHERRY_PICK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_BISECT", GIT_REPOSITORY_STATE_BISECT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_REBASE", GIT_REPOSITORY_STATE_REBASE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_REBASE_INTERACTIVE", GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_REBASE_MERGE", GIT_REPOSITORY_STATE_REBASE_MERGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_APPLY_MAILBOX", GIT_REPOSITORY_STATE_APPLY_MAILBOX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE", GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE, CONST_CS | CONST_PERSISTENT); + + /* git_reset_t */ + REGISTER_LONG_CONSTANT("GIT_RESET_SOFT", GIT_RESET_SOFT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_RESET_MIXED", GIT_RESET_MIXED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_RESET_HARD", GIT_RESET_HARD, CONST_CS | CONST_PERSISTENT); + + /* git_revparse_mode_t */ + REGISTER_LONG_CONSTANT("GIT_REVPARSE_SINGLE", GIT_REVPARSE_SINGLE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REVPARSE_RANGE", GIT_REVPARSE_RANGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_REVPARSE_MERGE_BASE", GIT_REVPARSE_MERGE_BASE, CONST_CS | CONST_PERSISTENT); + + /* git_stash_flags */ + REGISTER_LONG_CONSTANT("GIT_STASH_DEFAULT", GIT_STASH_DEFAULT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STASH_KEEP_INDEX", GIT_STASH_KEEP_INDEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STASH_INCLUDE_UNTRACKED", GIT_STASH_INCLUDE_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STASH_INCLUDE_IGNORED", GIT_STASH_INCLUDE_IGNORED, CONST_CS | CONST_PERSISTENT); + + /* git_status_t */ + REGISTER_LONG_CONSTANT("GIT_STATUS_CURRENT", GIT_STATUS_CURRENT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_INDEX_NEW", GIT_STATUS_INDEX_NEW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_INDEX_MODIFIED", GIT_STATUS_INDEX_MODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_INDEX_DELETED", GIT_STATUS_INDEX_DELETED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_INDEX_RENAMED", GIT_STATUS_INDEX_RENAMED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_INDEX_TYPECHANGE", GIT_STATUS_INDEX_TYPECHANGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_WT_NEW", GIT_STATUS_WT_NEW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_WT_MODIFIED", GIT_STATUS_WT_MODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_WT_DELETED", GIT_STATUS_WT_DELETED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_WT_TYPECHANGE", GIT_STATUS_WT_TYPECHANGE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_WT_RENAMED", GIT_STATUS_WT_RENAMED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_IGNORED", GIT_STATUS_IGNORED, CONST_CS | CONST_PERSISTENT); + /* git_status_show_t */ + REGISTER_LONG_CONSTANT("GIT_STATUS_SHOW_INDEX_AND_WORKDIR", GIT_STATUS_SHOW_INDEX_AND_WORKDIR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_SHOW_INDEX_ONLY", GIT_STATUS_SHOW_INDEX_ONLY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_SHOW_WORKDIR_ONLY", GIT_STATUS_SHOW_WORKDIR_ONLY, CONST_CS | CONST_PERSISTENT); + /* git_status_opt_t */ + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_INCLUDE_UNTRACKED", GIT_STATUS_OPT_INCLUDE_UNTRACKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_INCLUDE_IGNORED", GIT_STATUS_OPT_INCLUDE_IGNORED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_INCLUDE_UNMODIFIED", GIT_STATUS_OPT_INCLUDE_UNMODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_EXCLUDE_SUBMODULES", GIT_STATUS_OPT_EXCLUDE_SUBMODULES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS", GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH", GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_RECURSE_IGNORED_DIRS", GIT_STATUS_OPT_RECURSE_IGNORED_DIRS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX", GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR", GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_SORT_CASE_SENSITIVELY", GIT_STATUS_OPT_SORT_CASE_SENSITIVELY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY", GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_RENAMES_FROM_REWRITES", GIT_STATUS_OPT_RENAMES_FROM_REWRITES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_STATUS_OPT_NO_REFRESH", GIT_STATUS_OPT_NO_REFRESH, CONST_CS | CONST_PERSISTENT); + + /* git_submodule_status_t */ + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_IN_HEAD", GIT_SUBMODULE_STATUS_IN_HEAD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_IN_INDEX", GIT_SUBMODULE_STATUS_IN_INDEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_IN_CONFIG", GIT_SUBMODULE_STATUS_IN_CONFIG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_IN_WD", GIT_SUBMODULE_STATUS_IN_WD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_INDEX_ADDED", GIT_SUBMODULE_STATUS_INDEX_ADDED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_INDEX_DELETED", GIT_SUBMODULE_STATUS_INDEX_DELETED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_INDEX_MODIFIED", GIT_SUBMODULE_STATUS_INDEX_MODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_WD_UNINITIALIZED", GIT_SUBMODULE_STATUS_WD_UNINITIALIZED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_WD_ADDED", GIT_SUBMODULE_STATUS_WD_ADDED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_WD_DELETED", GIT_SUBMODULE_STATUS_WD_DELETED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_WD_MODIFIED", GIT_SUBMODULE_STATUS_WD_MODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED", GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_WD_WD_MODIFIED", GIT_SUBMODULE_STATUS_WD_WD_MODIFIED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SUBMODULE_STATUS_WD_UNTRACKED", GIT_SUBMODULE_STATUS_WD_UNTRACKED, CONST_CS | CONST_PERSISTENT); + + /* git_trace_level_t */ + REGISTER_LONG_CONSTANT("GIT_TRACE_NONE", GIT_TRACE_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TRACE_FATAL", GIT_TRACE_FATAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TRACE_ERROR", GIT_TRACE_ERROR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TRACE_WARN", GIT_TRACE_WARN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TRACE_INFO", GIT_TRACE_INFO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TRACE_DEBUG", GIT_TRACE_DEBUG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TRACE_TRACE", GIT_TRACE_TRACE, CONST_CS | CONST_PERSISTENT); + + /* git_credtype_t */ + REGISTER_LONG_CONSTANT("GIT_CREDTYPE_USERPASS_PLAINTEXT", GIT_CREDTYPE_USERPASS_PLAINTEXT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CREDTYPE_SSH_KEY", GIT_CREDTYPE_SSH_KEY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CREDTYPE_SSH_CUSTOM", GIT_CREDTYPE_SSH_CUSTOM, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_CREDTYPE_DEFAULT", GIT_CREDTYPE_DEFAULT, CONST_CS | CONST_PERSISTENT); + /* git_transport_flags_t */ + REGISTER_LONG_CONSTANT("GIT_TRANSPORTFLAGS_NONE", GIT_TRANSPORTFLAGS_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TRANSPORTFLAGS_NO_CHECK_CERT", GIT_TRANSPORTFLAGS_NO_CHECK_CERT, CONST_CS | CONST_PERSISTENT); + /* git_smart_service_t */ + REGISTER_LONG_CONSTANT("GIT_SERVICE_UPLOADPACK_LS", GIT_SERVICE_UPLOADPACK_LS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SERVICE_UPLOADPACK", GIT_SERVICE_UPLOADPACK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SERVICE_RECEIVEPACK_LS", GIT_SERVICE_RECEIVEPACK_LS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_SERVICE_RECEIVEPACK", GIT_SERVICE_RECEIVEPACK, CONST_CS | CONST_PERSISTENT); + + /* git_treewalk_mode */ + REGISTER_LONG_CONSTANT("GIT_TREEWALK_PRE", GIT_TREEWALK_PRE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_TREEWALK_POST", GIT_TREEWALK_POST, CONST_CS | CONST_PERSISTENT); + + /* git_otype */ + REGISTER_LONG_CONSTANT("GIT_OBJ_ANY", GIT_OBJ_ANY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ_BAD", GIT_OBJ_BAD, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ__EXT1", GIT_OBJ__EXT1, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ_COMMIT", GIT_OBJ_COMMIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ_TREE", GIT_OBJ_TREE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ_BLOB", GIT_OBJ_BLOB, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ_TAG", GIT_OBJ_TAG, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ__EXT2", GIT_OBJ__EXT2, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ_OFS_DELTA", GIT_OBJ_OFS_DELTA, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("GIT_OBJ_REF_DELTA", GIT_OBJ_REF_DELTA, CONST_CS | CONST_PERSISTENT); + return SUCCESS; } diff --git a/php_git2.h b/php_git2.h index e271b32094..60dd2947d2 100644 --- a/php_git2.h +++ b/php_git2.h @@ -49,6 +49,8 @@ #include "git2.h" #include "git2/sys/filter.h" +#include "git2/odb_backend.h" +#include "git2/trace.h" #include "date/php_date.h" From bd044396932c162d90abc19112ffaa9c7f6ba4b2 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 15:22:26 +0900 Subject: [PATCH 036/136] [blob] add git_blob_create_frombuffer test --- blob.c | 9 ++++----- commit.c | 8 ++++---- filter.c | 2 +- index.c | 6 +++--- merge.c | 4 ++-- ng.php | 2 +- object.c | 2 +- php_git2.h | 3 ++- php_git2_priv.h | 2 ++ reference.c | 4 ++-- repository.c | 2 +- revwalk.c | 2 +- tag.c | 12 ++++++------ tests/blob/git_blob_create_frombuffer.phpt | 11 ++++++++--- tree.c | 4 ++-- treebuilder.c | 2 +- 16 files changed, 41 insertions(+), 34 deletions(-) diff --git a/blob.c b/blob.c index 17ff3b1929..42f73a7714 100644 --- a/blob.c +++ b/blob.c @@ -12,7 +12,7 @@ PHP_FUNCTION(git_blob_create_frombuffer) int buffer_len; int error; git_oid id; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repository, &buffer, &buffer_len) == FAILURE) { @@ -20,7 +20,6 @@ PHP_FUNCTION(git_blob_create_frombuffer) } ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_blob_create_frombuffer(&id, PHP_GIT2_V(git2, repository), buffer, buffer_len); if (php_git2_check_error(error, "git_blob_create_frombuffer" TSRMLS_CC)) { RETURN_FALSE @@ -46,7 +45,7 @@ PHP_FUNCTION(git_blob_create_fromdisk) int path_len; int error; git_oid id; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repository, &path, &path_len) == FAILURE) { @@ -74,7 +73,7 @@ PHP_FUNCTION(git_blob_create_fromworkdir) int path_len; int error; git_oid id; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repository, &path, &path_len) == FAILURE) { @@ -124,7 +123,7 @@ PHP_FUNCTION(git_blob_id) { zval *blob; php_git2_t *git2; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; const git_oid *id; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/commit.c b/commit.c index 9458bd22e8..bd26cee7ab 100644 --- a/commit.c +++ b/commit.c @@ -121,7 +121,7 @@ PHP_FUNCTION(git_commit_id) { zval *commit; php_git2_t *_commit; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; const git_oid *id; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -293,7 +293,7 @@ PHP_FUNCTION(git_commit_tree_id) { zval *commit; php_git2_t *_commit; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; const git_oid *id; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -362,7 +362,7 @@ PHP_FUNCTION(git_commit_parent_id) php_git2_t *_commit; long n; git_oid *oid; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &commit, &n) == FAILURE) { @@ -417,7 +417,7 @@ PHP_FUNCTION(git_commit_create) int update_ref_len, message_encoding_len, message_len, parent_count = 0, error = 0, i; php_git2_t *_repo, *_author, *_committer, *_tree; git_signature __author, __committer; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; git_oid oid; const git_commit **__parents = NULL; HashPosition pos; diff --git a/filter.c b/filter.c index d1f013e9f7..ca43c4f682 100644 --- a/filter.c +++ b/filter.c @@ -308,7 +308,7 @@ PHP_FUNCTION(git_filter_source_id) const git_oid *result = NULL; zval *src = NULL; php_git2_t *_src = NULL; - char __result[41] = {0}; + char __result[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { diff --git a/index.c b/index.c index d6cb9f6c7e..f87e3b3f97 100644 --- a/index.c +++ b/index.c @@ -35,7 +35,7 @@ static int php_git2_array_to_index_entry(git_index_entry *entry, zval *array TSR static void php_git2_index_entry_to_array(const git_index_entry *entry, zval **result TSRMLS_DC) { zval *tmp, *ctime, *mtime; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; MAKE_STD_ZVAL(tmp); MAKE_STD_ZVAL(ctime); @@ -283,7 +283,7 @@ PHP_FUNCTION(git_index_write_tree) php_git2_t *_index; int error = 0; git_oid id; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { @@ -307,7 +307,7 @@ PHP_FUNCTION(git_index_write_tree_to) zval *repo; php_git2_t *_repo; git_oid id; - char out[41]= {0}; + char out[GIT2_OID_HEXSIZE]= {0}; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/merge.c b/merge.c index d0a551b3fd..32237b819f 100644 --- a/merge.c +++ b/merge.c @@ -16,7 +16,7 @@ PHP_FUNCTION(git_merge_base) int two_len = 0; git_oid __two; int error = 0; - char result[41] = {0}; + char result[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &repo, &one, &one_len, &two, &two_len) == FAILURE) { @@ -316,7 +316,7 @@ PHP_FUNCTION(git_merge_result_fastforward_oid) zval *merge_result = NULL; php_git2_t *_merge_result = NULL; int error = 0; - char buffer[41] = {0}; + char buffer[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { diff --git a/ng.php b/ng.php index a1f9072961..4f27c4ded9 100644 --- a/ng.php +++ b/ng.php @@ -519,7 +519,7 @@ public function generateDeclarations(Printer $printer, Func $f) $printer->put("`type` error = 0;\n", "type", $f->getReturnType()); } if (preg_match("/git_oid/", $f->getReturnType())) { - $printer->put("char __result[41] = {0};\n"); + $printer->put("char __result[GIT2_OID_HEXSIZE] = {0};\n"); } if (preg_match("/_owner$/", $f->getName())) { $printer->put("php_git2_t *__result = NULL;\n"); diff --git a/object.c b/object.c index c3e593fbe9..76e8a39b34 100644 --- a/object.c +++ b/object.c @@ -98,7 +98,7 @@ PHP_FUNCTION(git_object_id) zval *obj; php_git2_t *_obj; const git_oid *id; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &obj) == FAILURE) { diff --git a/php_git2.h b/php_git2.h index 60dd2947d2..85e195cb6c 100644 --- a/php_git2.h +++ b/php_git2.h @@ -48,9 +48,10 @@ #include "limits.h" #include "git2.h" -#include "git2/sys/filter.h" +#include "git2/odb.h" #include "git2/odb_backend.h" #include "git2/trace.h" +#include "git2/sys/filter.h" #include "date/php_date.h" diff --git a/php_git2_priv.h b/php_git2_priv.h index 2749584e11..3f1883cda5 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -57,6 +57,8 @@ do {\ val->mutable = 0;\ } while (0);\ +#define GIT2_OID_HEXSIZE (GIT_OID_HEXSZ+1) + #include "helper.h" #endif \ No newline at end of file diff --git a/reference.c b/reference.c index bebefecd64..0519c7de04 100644 --- a/reference.c +++ b/reference.c @@ -42,7 +42,7 @@ PHP_FUNCTION(git_reference_name_to_id) char *name = {0}; int name_len; git_oid id; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; int error; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -196,7 +196,7 @@ PHP_FUNCTION(git_reference_target_peel) zval *ref; php_git2_t *_ref; git_oid *oid; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { diff --git a/repository.c b/repository.c index 3f1687069c..8911b5a703 100644 --- a/repository.c +++ b/repository.c @@ -625,7 +625,7 @@ PHP_FUNCTION(git_repository_hashfile) int as_path_len; git_oid oid; int error = 0; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrs", &repo, &path, &path_len, &type, &as_path, &as_path_len) == FAILURE) { diff --git a/revwalk.c b/revwalk.c index 8252c57017..9548006025 100644 --- a/revwalk.c +++ b/revwalk.c @@ -238,7 +238,7 @@ PHP_FUNCTION(git_revwalk_next) zval *walk; php_git2_t *_walk; git_oid id = {0}; - char out[41] = {0}; + char out[GIT2_OID_HEXSIZE] = {0}; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/tag.c b/tag.c index 80b4b584e2..92119ff57f 100644 --- a/tag.c +++ b/tag.c @@ -100,7 +100,7 @@ PHP_FUNCTION(git_tag_id) const git_oid *result = NULL; zval *tag = NULL; php_git2_t *_tag = NULL; - char __result[41] = {0}; + char __result[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { @@ -175,7 +175,7 @@ PHP_FUNCTION(git_tag_target_id) const git_oid *result = NULL; zval *tag = NULL; php_git2_t *_tag = NULL; - char __result[41] = {0}; + char __result[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { @@ -284,7 +284,7 @@ PHP_FUNCTION(git_tag_create) int message_len = 0; long force = 0; int error = 0; - char buffer[41] = {0}; + char buffer[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrasl", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len, &force) == FAILURE) { @@ -320,7 +320,7 @@ PHP_FUNCTION(git_tag_annotation_create) char *message = NULL; int message_len = 0; int error = 0; - char buffer[41] = {0}; + char buffer[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsras", &repo, &tag_name, &tag_name_len, &target, &tagger, &message, &message_len) == FAILURE) { @@ -351,7 +351,7 @@ PHP_FUNCTION(git_tag_create_frombuffer) int buffer_len = 0; long force = 0; int error = 0; - char oid[41] = {0}; + char oid[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &repo, &buffer, &buffer_len, &force) == FAILURE) { @@ -383,7 +383,7 @@ PHP_FUNCTION(git_tag_create_lightweight) php_git2_t *_target = NULL; long force = 0; int error = 0; - char oid[41] = {0}; + char oid[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl", &repo, &tag_name, &tag_name_len, &target, &force) == FAILURE) { diff --git a/tests/blob/git_blob_create_frombuffer.phpt b/tests/blob/git_blob_create_frombuffer.phpt index 04f99aa180..e33ae29aa5 100644 --- a/tests/blob/git_blob_create_frombuffer.phpt +++ b/tests/blob/git_blob_create_frombuffer.phpt @@ -4,7 +4,12 @@ Check for git_blob_create_frombuffer presence --FILE-- Date: Sun, 12 Jan 2014 16:14:30 +0900 Subject: [PATCH 037/136] [repository] improve codes --- helper.c | 112 +++++ helper.h | 2 + ng.php | 22 +- php_git2_priv.h | 2 + repository.c | 471 +++++++++++---------- tests/blob/git_blob_create_frombuffer.phpt | 12 +- tests/common.php | 1 + 7 files changed, 385 insertions(+), 237 deletions(-) create mode 100644 tests/common.php diff --git a/helper.c b/helper.c index fd7c23d27d..e140ef5d01 100644 --- a/helper.c +++ b/helper.c @@ -1,4 +1,5 @@ #include "php_git2.h" +#include "php_git2_priv.h" #include "helper.h" static zval* datetime_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) @@ -135,3 +136,114 @@ void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC) } *out = result; } + +int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC) +{ + php_git2_t *result = NULL; + + PHP_GIT2_MAKE_RESOURCE_NOCHECK(result); + if (result == NULL) { + return 1; + } + + switch (type) { + case PHP_GIT2_TYPE_REPOSITORY: + PHP_GIT2_V(result, repository) = (git_repository*)resource; + break; + case PHP_GIT2_TYPE_COMMIT: + PHP_GIT2_V(result, commit) = (git_commit*)resource; + break; + case PHP_GIT2_TYPE_TREE: + PHP_GIT2_V(result, commit) = (git_tree*)resource; + break; + case PHP_GIT2_TYPE_TREE_ENTRY: + PHP_GIT2_V(result, tree_entry) = (git_tree_entry*)resource; + break; + case PHP_GIT2_TYPE_BLOB: + PHP_GIT2_V(result, blob) = (git_blob*)resource; + break; + case PHP_GIT2_TYPE_REVWALK: + PHP_GIT2_V(result, revwalk) = (git_revwalk*)resource; + break; + case PHP_GIT2_TYPE_TREEBUILDER: + PHP_GIT2_V(result, treebuilder) = (git_treebuilder*)resource; + break; + case PHP_GIT2_TYPE_REFERENCE: + PHP_GIT2_V(result, reference) = (git_reference*)resource; + break; + case PHP_GIT2_TYPE_CONFIG: + PHP_GIT2_V(result, config) = (git_config*)resource; + break; + case PHP_GIT2_TYPE_OBJECT: + PHP_GIT2_V(result, object) = (git_object*)resource; + break; + case PHP_GIT2_TYPE_INDEX: + PHP_GIT2_V(result, index) = (git_index*)resource; + break; + case PHP_GIT2_TYPE_ODB: + PHP_GIT2_V(result, odb) = (git_odb*)resource; + break; + case PHP_GIT2_TYPE_REFDB: + PHP_GIT2_V(result, refdb) = (git_refdb*)resource; + break; + case PHP_GIT2_TYPE_STATUS_LIST: + PHP_GIT2_V(result, status_list) = (git_status_list*)resource; + break; + case PHP_GIT2_TYPE_BRANCH_ITERATOR: + PHP_GIT2_V(result, branch_iterator) = (git_branch_iterator*)resource; + break; + case PHP_GIT2_TYPE_TAG: + PHP_GIT2_V(result, tag) = (git_tag*)resource; + break; + case PHP_GIT2_TYPE_CRED: + PHP_GIT2_V(result, cred) = (git_cred*)resource; + break; + case PHP_GIT2_TYPE_TRANSPORT: + PHP_GIT2_V(result, transport) = (git_transport*)resource; + break; + case PHP_GIT2_TYPE_REMOTE: + PHP_GIT2_V(result, remote) = (git_remote*)resource; + break; + case PHP_GIT2_TYPE_DIFF: + PHP_GIT2_V(result, diff) = (git_diff*)resource; + break; + case PHP_GIT2_TYPE_MERGE_RESULT: + PHP_GIT2_V(result, merge_result) = (git_merge_result*)resource; + break; + case PHP_GIT2_TYPE_MERGE_HEAD: + PHP_GIT2_V(result, merge_head) = (git_merge_head*)resource; + break; + case PHP_GIT2_TYPE_PATHSPEC: + PHP_GIT2_V(result, pathspec) = (git_pathspec*)resource; + break; + case PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST: + PHP_GIT2_V(result, pathspec_match_list) = (git_pathspec_match_list*)resource; + break; + case PHP_GIT2_TYPE_PATCH: + PHP_GIT2_V(result, patch) = (git_patch*)resource; + break; + case PHP_GIT2_TYPE_DIFF_HUNK: + PHP_GIT2_V(result, diff_hunk) = (git_diff_hunk*)resource; + break; + case PHP_GIT2_TYPE_BUF: + PHP_GIT2_V(result, buf) = (git_buf*)resource; + break; + case PHP_GIT2_TYPE_FILTER_LIST: + PHP_GIT2_V(result, filter_list) = (git_filter_list*)resource; + break; + case PHP_GIT2_TYPE_FILTER_SOURCE: + PHP_GIT2_V(result, filter_source) = (git_filter_source*)resource; + break; + case PHP_GIT2_TYPE_DIFF_LINE: + PHP_GIT2_V(result, diff_line) = (git_diff_line*)resource; + break; + } + + result->type = type; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = should_free; + + *out = result; + return 0; +} + diff --git a/helper.h b/helper.h index f65caa0d7e..2de959519f 100644 --- a/helper.h +++ b/helper.h @@ -42,4 +42,6 @@ void php_git2_signature_to_array(const git_signature *signature, zval **out TSRM void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC); +int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC); + #endif \ No newline at end of file diff --git a/ng.php b/ng.php index 4f27c4ded9..3ec594fd2c 100644 --- a/ng.php +++ b/ng.php @@ -778,10 +778,10 @@ public function generateFunctionCall(Printer $printer, Func $f) } else if ($f->isSavior()) { $first = $f->first(); - $printer->put("if (_`name`->should_free_v) {\n", + $printer->put("if (GIT2_SHOULD_FREE(_`name`)) {\n", "name", $first->getName() ); - $printer->block(function(Printer $printer) use ($f) { + $printer->block(function(Printer $printer) use ($f, $first) { $printer->put("`function`", "function", $f->getName() ); @@ -808,7 +808,7 @@ public function generateFunctionCall(Printer $printer, Func $f) $i++; } $printer->put(");\n"); - + $printer->put("GIT2_SHOULD_FREE(_`name`) = 0;\n", "name", $first->getName()); }); $printer->put("};\n"); @@ -897,19 +897,15 @@ public function generateMakeResourceIfNeeded(Printer $printer, Func $f, $name = { if ($f->isResourceCreator() || $force) { $arg = $f->first(); - $printer->put("PHP_GIT2_MAKE_RESOURCE(`name`);\n", "name", $name); - $printer->put("PHP_GIT2_V(`name`, `type`) = `variable`;\n", - "name", $name, - "type", $this->getNormarizedTypeName($arg), - "variable", $arg->getName() - ); - $printer->put("`name`->type = PHP_GIT2_TYPE_`type`;\n", + $printer->put("if (php_git2_make_resource(&`name`, PHP_GIT2_TYPE_`type`, `name`, 1 TSRMLS_CC)) {\n", "name", $name, "type", strtoupper($this->getNormarizedTypeName($arg)) ); - $printer->put("`name`->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);\n", "name", $name); - $printer->put("`name`->should_free_v = 0;\n", "name", $name); - $printer->put("ZVAL_RESOURCE(return_value, `name`->resource_id);\n", "name", $name); + $printer->block(function(Printer $printer) { + $printer->put("RETURN_FALSE;\n"); + }); + $printer->put("}\n"); + $printer->put("ZVAL_RESOURCE(return_value, GIT2_RVAL_P(`name`));\n", "name", $name); } } diff --git a/php_git2_priv.h b/php_git2_priv.h index 3f1883cda5..668df73060 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -35,6 +35,8 @@ extern int git2_resource_handle; #endif #define PHP_GIT2_V(git2, type) git2->v.type +#define GIT2_RVAL_P(git2) git2->resource_id +#define GIT2_SHOULD_FREE(git2) git2->should_free_v #define PHP_GIT2_MAKE_RESOURCE(val) \ do {\ diff --git a/repository.c b/repository.c index 8911b5a703..6160f5b096 100644 --- a/repository.c +++ b/repository.c @@ -7,21 +7,17 @@ PHP_FUNCTION(git_repository_new) { git_repository *repository; - int error; php_git2_t *git2; + int error; error = git_repository_new(&repository); if (php_git2_check_error(error, "git_repository_new" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(git2); - - git2->type = PHP_GIT2_TYPE_REPOSITORY; - git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); - git2->should_free_v = 0; - - ZVAL_RESOURCE(return_value, git2->resource_id); + if (php_git2_make_resource(&git2, PHP_GIT2_TYPE_REPOSITORY, repository, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(git2)); } /* {{{ proto resource git_repository_init(string $path, long is_bare = 0) @@ -29,28 +25,22 @@ PHP_FUNCTION(git_repository_new) PHP_FUNCTION(git_repository_init) { git_repository *repository; - int error; php_git2_t *git2; char *path; - int path_len, is_bare = 0; + int error, path_len, is_bare = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &path_len, &is_bare) == FAILURE) { return; } - error = git_repository_init(&repository, path, is_bare); if (php_git2_check_error(error, "git_repository_init" TSRMLS_CC)) { RETURN_FALSE } - - PHP_GIT2_MAKE_RESOURCE(git2); - PHP_GIT2_V(git2, repository) = repository; - git2->type = PHP_GIT2_TYPE_REPOSITORY; - git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); - git2->should_free_v = 1; - - ZVAL_RESOURCE(return_value, git2->resource_id); + if (php_git2_make_resource(&git2, PHP_GIT2_TYPE_REPOSITORY, repository, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(git2)); } /* {{{ proto resource git_repository_open(string $path) @@ -72,14 +62,10 @@ PHP_FUNCTION(git_repository_open_bare) if (php_git2_check_error(error, "git_repository_open_bare" TSRMLS_CC)) { RETURN_FALSE } - - PHP_GIT2_MAKE_RESOURCE(git2); - PHP_GIT2_V(git2, repository) = repository; - git2->type = PHP_GIT2_TYPE_REPOSITORY; - git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); - git2->should_free_v = 1; - - ZVAL_RESOURCE(return_value, git2->resource_id); + if (php_git2_make_resource(&git2, PHP_GIT2_TYPE_REPOSITORY, repository, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(git2)); } /* {{{ proto resource git_repository_open(string $path) @@ -102,13 +88,10 @@ PHP_FUNCTION(git_repository_open) if (php_git2_check_error(error, "git_repository_open" TSRMLS_CC)) { RETURN_FALSE } - - PHP_GIT2_V(git2, repository) = repository; - git2->type = PHP_GIT2_TYPE_REPOSITORY; - git2->resource_id = PHP_GIT2_LIST_INSERT(git2, git2_resource_handle); - git2->should_free_v = 1; - - ZVAL_RESOURCE(return_value, git2->resource_id); + if (php_git2_make_resource(&git2, PHP_GIT2_TYPE_REPOSITORY, repository, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(git2)); } /* }}} */ @@ -150,7 +133,6 @@ PHP_FUNCTION(git_repository_workdir) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); workdir = git_repository_workdir(PHP_GIT2_V(git2, repository)); - if (workdir != NULL) { RETURN_STRING(workdir, 1); } else { @@ -159,23 +141,33 @@ PHP_FUNCTION(git_repository_workdir) } /* }}} */ -/* {{{ proto resource git_repository_wrap_odb(odb) -*/ +/* {{{ proto resource git_repository_wrap_odb(resource $odb) + */ PHP_FUNCTION(git_repository_wrap_odb) { - zval *odb; - php_git2_t *_odb; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_wrap_odb not implemented yet"); - return; + php_git2_t *result = NULL; + git_repository *out = NULL; + zval *odb = NULL; + php_git2_t *_odb = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &odb) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_repository_wrap_odb(&out, PHP_GIT2_V(_odb, odb)); + if (php_git2_check_error(error, "git_repository_wrap_odb" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ + /* {{{ proto resource git_repository_discover(start_path, across_fs, ceiling_dirs) */ @@ -203,78 +195,94 @@ PHP_FUNCTION(git_repository_discover) RETURN_STRING(buffer, 1); } -/* {{{ proto resource git_repository_open_ext(path, flags, ceiling_dirs) -*/ +/* {{{ proto resource git_repository_open_ext(string $path, long $flags, string $ceiling_dirs) + */ PHP_FUNCTION(git_repository_open_ext) { - char *path = {0}; - int path_len; - long flags; - char *ceiling_dirs = {0}; - int ceiling_dirs_len; + php_git2_t *result = NULL; + git_repository *out = NULL; + char *path = NULL; + int path_len = 0; + long flags = 0; + char *ceiling_dirs = NULL; + int ceiling_dirs_len = 0; int error = 0; - git_repository *repository; - php_git2_t *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &path, &path_len, &flags, &ceiling_dirs, &ceiling_dirs_len) == FAILURE) { return; } - error = git_repository_open_ext(&repository, path, flags, ceiling_dirs); + + error = git_repository_open_ext(&out, path, flags, ceiling_dirs); if (php_git2_check_error(error, "git_repository_open_ext" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, repository) = repository; - result->type = PHP_GIT2_TYPE_REPOSITORY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto void git_repository_free(repo) -*/ + +/* {{{ proto void git_repository_free(resource $repo) + */ PHP_FUNCTION(git_repository_free) { - zval *repo; - php_git2_t *_repo; + zval *repo = NULL; + php_git2_t *_repo = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_repo->should_free_v) { + if (GIT2_SHOULD_FREE(_repo)) { git_repository_free(PHP_GIT2_V(_repo, repository)); - _repo->should_free_v = 0; - } + GIT2_SHOULD_FREE(_repo) = 0; + }; zval_ptr_dtor(&repo); } +/* }}} */ -/* {{{ proto resource git_repository_init_ext(repo_path, opts) -*/ + +/* {{{ proto resource git_repository_init_ext(string $repo_path, $opts) + */ PHP_FUNCTION(git_repository_init_ext) { - char *repo_path = {0}; - int repo_path_len; - zval *opts; - php_git2_t *_opts; -// TODO -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "sr", &repo_path, &repo_path_len, &opts) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_repo_path, php_git2_t*, &repo_path, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_t *result = NULL; + git_repository *out = NULL; + char *repo_path = NULL; + int repo_path_len = 0; + zval *opts = NULL; + int error = 0; + + /* TODO(chobie): generate converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sa", &repo_path, &repo_path_len, &opts) == FAILURE) { + return; + } + + error = git_repository_init_ext(&out, repo_path, opts); + if (php_git2_check_error(error, "git_repository_init_ext" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_repository_head(repo) -*/ + +/* {{{ proto resource git_repository_head(resource $repo) + */ PHP_FUNCTION(git_repository_head) { - zval *repo; - php_git2_t *_repo, *result; - git_reference *reference; + php_git2_t *result = NULL; + git_reference *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -283,234 +291,255 @@ PHP_FUNCTION(git_repository_head) } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_repository_head(&reference, PHP_GIT2_V(_repo, repository)); - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = reference; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + error = git_repository_head(&out, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_head" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto long git_repository_head_detached(repo) -*/ + +/* {{{ proto long git_repository_head_detached(resource $repo) + */ PHP_FUNCTION(git_repository_head_detached) { - zval *repo; - php_git2_t *_repo; int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_repository_head_detached(PHP_GIT2_V(_repo, repository)); - RETURN_BOOL(result); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_repository_head_unborn(repo) -*/ +/* {{{ proto long git_repository_head_unborn(resource $repo) + */ PHP_FUNCTION(git_repository_head_unborn) { - zval *repo; - php_git2_t *_repo; - int unborn = 0; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - unborn = git_repository_head_unborn(PHP_GIT2_V(_repo, repository)); - RETURN_BOOL(unborn); + result = git_repository_head_unborn(PHP_GIT2_V(_repo, repository)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_repository_is_empty(repo) -*/ + +/* {{{ proto long git_repository_is_empty(resource $repo) + */ PHP_FUNCTION(git_repository_is_empty) { - zval *repo; - php_git2_t *_repo; - int empty; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - empty = git_repository_is_empty(PHP_GIT2_V(_repo, repository)); - RETURN_BOOL(empty); + result = git_repository_is_empty(PHP_GIT2_V(_repo, repository)); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_repository_path(repo) -*/ + +/* {{{ proto string git_repository_path(resource $repo) + */ PHP_FUNCTION(git_repository_path) { - zval *repo; - php_git2_t *_repo; - const char *path; + const char *result = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - path = git_repository_path(PHP_GIT2_V(_repo, repository)); - RETURN_STRING(path, 1); + result = git_repository_path(PHP_GIT2_V(_repo, repository)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto long git_repository_set_workdir(repo, workdir, update_gitlink) -*/ + +/* {{{ proto long git_repository_set_workdir(resource $repo, string $workdir, long $update_gitlink) + */ PHP_FUNCTION(git_repository_set_workdir) { - zval *repo; - php_git2_t *_repo; - char *workdir = {0}; - int workdir_len; - long update_gitlink; - int error; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *workdir = NULL; + int workdir_len = 0; + long update_gitlink = 0; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &repo, &workdir, &workdir_len, &update_gitlink) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_repository_set_workdir(PHP_GIT2_V(_repo, repository), workdir, update_gitlink); - if (php_git2_check_error(error, "git_repository_set_workdir" TSRMLS_CC)) { - RETURN_FALSE - } - RETURN_TRUE; + result = git_repository_set_workdir(PHP_GIT2_V(_repo, repository), workdir, update_gitlink); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_repository_is_bare(repo) -*/ +/* {{{ proto long git_repository_is_bare(resource $repo) + */ PHP_FUNCTION(git_repository_is_bare) { - zval *repo; - php_git2_t *_repo; - int is_bare = 0; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - is_bare = git_repository_is_bare(PHP_GIT2_V(_repo, repository)); - RETURN_BOOL(is_bare); + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_repository_is_bare(PHP_GIT2_V(_repo, repository)); + RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_repository_config(repo) -*/ +/* {{{ proto resource git_repository_config(resource $repo) + */ PHP_FUNCTION(git_repository_config) { - zval *repo; - php_git2_t *_repo, *result; - git_config *config; + php_git2_t *result = NULL; + git_config *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_repository_config(&config, PHP_GIT2_V(_repo, repository)); + error = git_repository_config(&out, PHP_GIT2_V(_repo, repository)); if (php_git2_check_error(error, "git_repository_config" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, config) = config; - result->type = PHP_GIT2_TYPE_CONFIG; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CONFIG, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_repository_odb(repo) -*/ + +/* {{{ proto resource git_repository_odb(resource $repo) + */ PHP_FUNCTION(git_repository_odb) { - zval *repo; - php_git2_t *_repo, *result; - git_odb *odb; + php_git2_t *result = NULL; + git_odb *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_repository_odb(&odb, PHP_GIT2_V(_repo, repository)); + error = git_repository_odb(&out, PHP_GIT2_V(_repo, repository)); if (php_git2_check_error(error, "git_repository_odb" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, odb) = odb; - result->type = PHP_GIT2_TYPE_ODB; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_repository_refdb(repo) -*/ + +/* {{{ proto resource git_repository_refdb(resource $repo) + */ PHP_FUNCTION(git_repository_refdb) { - zval *repo; - php_git2_t *_repo, *result; - git_refdb *refdb; + php_git2_t *result = NULL; + git_refdb *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_repository_refdb(&refdb, PHP_GIT2_V(_repo, repository)); + error = git_repository_refdb(&out, PHP_GIT2_V(_repo, repository)); if (php_git2_check_error(error, "git_repository_refdb" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, refdb) = refdb; - result->type = PHP_GIT2_TYPE_REFDB; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFDB, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_repository_index(repo) -*/ +/* {{{ proto resource git_repository_index(resource $repo) + */ PHP_FUNCTION(git_repository_index) { - zval *repo; - php_git2_t *_repo, *result; - git_index *index; + php_git2_t *result = NULL; + git_index *out = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_repository_index(&index, PHP_GIT2_V(_repo, repository)); - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, index) = index; - result->type = PHP_GIT2_TYPE_INDEX; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + error = git_repository_index(&out, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_repository_index" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_repository_message(len, repo) -*/ +/* {{{ proto resource git_repository_message(long $len, resource $repo) + */ PHP_FUNCTION(git_repository_message) { zval *repo; @@ -530,44 +559,49 @@ PHP_FUNCTION(git_repository_message) } RETURN_STRING(buffer, 1); } +/* }}} */ -/* {{{ proto long git_repository_message_remove(repo) -*/ + +/* {{{ proto long git_repository_message_remove(resource $repo) + */ PHP_FUNCTION(git_repository_message_remove) { - zval *repo; - php_git2_t *_repo; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_repository_message_remove(PHP_GIT2_V(_repo, repository)); - if (php_git2_check_error(error, "git_repository_message_remove" TSRMLS_CC)) { - RETURN_FALSE - } - RETURN_TRUE; + result = git_repository_message_remove(PHP_GIT2_V(_repo, repository)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_repository_merge_cleanup(repo) -*/ +/* {{{ proto long git_repository_merge_cleanup(resource $repo) + */ PHP_FUNCTION(git_repository_merge_cleanup) { - zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_merge_cleanup not implemented yet"); - return; + int result = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_repository_merge_cleanup(PHP_GIT2_V(_repo, repository)); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_repository_fetchhead_foreach(repo, callback, payload) */ @@ -637,7 +671,6 @@ PHP_FUNCTION(git_repository_hashfile) RETURN_FALSE } git_oid_fmt(out, &oid); - } /* {{{ proto long git_repository_set_head(repo, refname) diff --git a/tests/blob/git_blob_create_frombuffer.phpt b/tests/blob/git_blob_create_frombuffer.phpt index e33ae29aa5..a13056bd63 100644 --- a/tests/blob/git_blob_create_frombuffer.phpt +++ b/tests/blob/git_blob_create_frombuffer.phpt @@ -7,9 +7,11 @@ Check for git_blob_create_frombuffer presence $repositroy = git_repository_init("/tmp/a"); echo git_blob_create_frombuffer($repositroy, "Helo World"); -// TODO(chobie): we can't detect git_repository_new has correct odb now. fix this. -//$repositroy = git_repository_new(); -//git_blob_create_frombuffer($repositroy, "Helo World"); - +$repositroy = git_repository_new(); +$result = @git_blob_create_frombuffer($repositroy, "Helo World"); +if (is_null($result)) { + echo "OK" . PHP_EOL; +} --EXPECT-- -826a9a65bc435bb1f1812433fa8fd5fa2ee9d678 \ No newline at end of file +826a9a65bc435bb1f1812433fa8fd5fa2ee9d678 +OK \ No newline at end of file diff --git a/tests/common.php b/tests/common.php new file mode 100644 index 0000000000..b3d9bbc7f3 --- /dev/null +++ b/tests/common.php @@ -0,0 +1 @@ + Date: Sun, 12 Jan 2014 16:41:53 +0900 Subject: [PATCH 038/136] improve repository and revwalk --- ng.php | 100 ++++++++++++++++++++++++++++++++++++--------------- php_git2.c | 6 ++++ repository.c | 21 ++++++----- revwalk.c | 58 +++++++++++++----------------- 4 files changed, 112 insertions(+), 73 deletions(-) diff --git a/ng.php b/ng.php index 3ec594fd2c..ccdc0d6390 100644 --- a/ng.php +++ b/ng.php @@ -456,17 +456,33 @@ public function isPtr(Arg $arg) public function generateDeclarations(Printer $printer, Func $f) { + $tables = array(); if ($f->isResourceCreator()) { - $printer->put("php_git2_t *result = NULL;\n"); + $tables["php_git2_t"][] = array( + "name" => "*result", + "value" => "NULL", + ); } else if ($f->isArrayCreator()) { - $printer->put("`type` *result = NULL;\n", "type", $f->getReturnType()); + $tables[$f->getReturnType()][] = array( + "name" => "*result", + "value" => "NULL", + ); if (preg_match("/git_signature/", $f->getReturnType())) { - $printer->put("zval *__result = NULL;\n"); + $tables["zval"][] = array( + "name" => "*__result", + "value" => "NULL", + ); } } else if ($f->isLongCreator()) { - $printer->put("`type` result = 0;\n", "type", $f->getReturnType()); + $tables[$f->getReturnType()][] = array( + "name" => "result", + "value" => "0", + ); } else if ($f->isStringCreator()) { - $printer->put("`type` *result = NULL;\n", "type", $f->getReturnType()); + $tables[$f->getReturnType()][] = array( + "name" => "*result", + "value" => "NULL", + ); } $i = 0; @@ -474,55 +490,80 @@ public function generateDeclarations(Printer $printer, Func $f) foreach ($f->getArguments() as $arg) { /** @var Arg $arg */ if ($i == 0 && $f->isResourceCreator()) { - $printer->put("`type` `ptr``name` = NULL;\n", - "type", $arg->getType(), - "ptr", $arg->getPtr(), - "name", $arg->getName() + $tables[$arg->getType()][] = array( + "name" => sprintf("%s%s", $arg->getPtr(), $arg->getName()), + "value" => "NULL", ); $i++; continue; } if ($arg->shouldWrite()) { - $printer->put("`type` `ptr``name` = NULL;\n", - "type", $arg->getType(), - "ptr", $arg->getPtr(), - "name", $arg->getName() + $tables[$arg->getType()][] = array( + "name" => sprintf("%s%s", $arg->getPtr(), $arg->getName()), + "value" => "NULL", ); } else { /** @var Arg $arg */ - $printer->put("`type` `ptr``name` = `value`;\n", - "type", $arg->getZendType(), - "ptr", $this->isPtr($arg), - "name", $arg->getName(), - "value", $arg->getDefaultValue() + $tables[$arg->getZendType()][] = array( + "name" => sprintf("%s%s", $this->isPtr($arg), $arg->getName()), + "value" => $arg->getDefaultValue(), ); if ($this->shouldResource($arg)) { - $printer->put("`type` *_`name` = NULL;\n", - "type", "php_git2_t", - "name", $arg->getName() + $tables["php_git2_t"][] = array( + "name" => sprintf("*_%s", $arg->getName()), + "value" => "NULL", ); } if (preg_match("/char/", $arg->getZendType())) { - $printer->put("int `name`_len = 0;\n", - "name", $arg->getName()); + $tables["int"][] = array( + "name" => sprintf("%s_len", $arg->getName()), + "value" => "0", + ); } } if ($arg->getType() == "git_oid") { - $printer->put("git_oid __`name`;\n", "name", $arg->getName()); + $tables["git_oid"][] = array( + "name" => sprintf("__%s", $arg->getName()), + "value" => "{0}", + ); } $i++; } if ($f->getReturnType() == "int") { - $printer->put("`type` error = 0;\n", "type", $f->getReturnType()); + $tables[$f->getReturnType()][] = array( + "name" => "error", + "value" => "0", + ); } if (preg_match("/git_oid/", $f->getReturnType())) { - $printer->put("char __result[GIT2_OID_HEXSIZE] = {0};\n"); + $tables["char"][] = array( + "name" => "__result[GIT2_OID_HEXSIZE]", + "value" => "{0}", + ); } if (preg_match("/_owner$/", $f->getName())) { - $printer->put("php_git2_t *__result = NULL;\n"); + $tables["php_git2_t"][] = array( + "name" => "*__result", + "value" => "NULL", + ); + } + + + foreach ($tables as $type => $values) { + $printer->put("`type` ", "type", $type); + $i = 0; + $cnt = count($values); + foreach ($values as $val) { + $printer->put("`name` = `value`", "name", $val['name'], "value", $val["value"]); + if ($i+1 < $cnt) { + $printer->put(", "); + } + $i++; + } + $printer->put(";\n"); } } @@ -897,9 +938,10 @@ public function generateMakeResourceIfNeeded(Printer $printer, Func $f, $name = { if ($f->isResourceCreator() || $force) { $arg = $f->first(); - $printer->put("if (php_git2_make_resource(&`name`, PHP_GIT2_TYPE_`type`, `name`, 1 TSRMLS_CC)) {\n", + $printer->put("if (php_git2_make_resource(&`name`, PHP_GIT2_TYPE_`type`, `target`, 1 TSRMLS_CC)) {\n", "name", $name, - "type", strtoupper($this->getNormarizedTypeName($arg)) + "type", strtoupper($this->getNormarizedTypeName($arg)), + "target", "out" ); $printer->block(function(Printer $printer) { $printer->put("RETURN_FALSE;\n"); diff --git a/php_git2.c b/php_git2.c index 0f931a4784..5830a070c4 100644 --- a/php_git2.c +++ b/php_git2.c @@ -73,16 +73,22 @@ void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) break; case PHP_GIT2_TYPE_BLOB: git_blob_free(PHP_GIT2_V(resource, blob)); + break; case PHP_GIT2_TYPE_REVWALK: git_revwalk_free(PHP_GIT2_V(resource, revwalk)); + break; case PHP_GIT2_TYPE_TREEBUILDER: git_treebuilder_free(PHP_GIT2_V(resource, treebuilder)); + break; case PHP_GIT2_TYPE_REFERENCE: git_reference_free(PHP_GIT2_V(resource, reference)); + break; case PHP_GIT2_TYPE_CONFIG: git_config_free(PHP_GIT2_V(resource, config)); + break; case PHP_GIT2_TYPE_OBJECT: git_object_free(PHP_GIT2_V(resource, object)); + break; default: break; } diff --git a/repository.c b/repository.c index 6160f5b096..c60c532e7e 100644 --- a/repository.c +++ b/repository.c @@ -69,32 +69,31 @@ PHP_FUNCTION(git_repository_open_bare) } /* {{{ proto resource git_repository_open(string $path) -*/ + */ PHP_FUNCTION(git_repository_open) { - char *path; - int path_len; - git_repository *repository; - int error = 0; - php_git2_t *git2; + php_git2_t *result = NULL; + git_repository *out = NULL; + char *path = NULL; + int path_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) { return; } - PHP_GIT2_MAKE_RESOURCE(git2); - error = git_repository_open(&repository, path); + error = git_repository_open(&out, path); if (php_git2_check_error(error, "git_repository_open" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - if (php_git2_make_resource(&git2, PHP_GIT2_TYPE_REPOSITORY, repository, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, out, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT2_RVAL_P(git2)); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto string git_repository_get_namespace(resource $repository) */ PHP_FUNCTION(git_repository_get_namespace) diff --git a/revwalk.c b/revwalk.c index 9548006025..8130287e10 100644 --- a/revwalk.c +++ b/revwalk.c @@ -2,13 +2,13 @@ #include "php_git2_priv.h" #include "revwalk.h" -/* {{{ proto resource git_revwalk_new(repo) -*/ +/* {{{ proto resource git_revwalk_new(resource $repo) + */ PHP_FUNCTION(git_revwalk_new) { - zval *repo; - php_git2_t *_repo, *result; - git_revwalk *walker; + php_git2_t *result = NULL, *_repo = NULL; + git_revwalk *out = NULL; + zval *repo = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -17,19 +17,17 @@ PHP_FUNCTION(git_revwalk_new) } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_revwalk_new(&walker, PHP_GIT2_V(_repo, repository)); + error = git_revwalk_new(&out, PHP_GIT2_V(_repo, repository)); if (php_git2_check_error(error, "git_revwalk_new" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, revwalk) = walker; - result->type = PHP_GIT2_TYPE_REVWALK; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REVWALK, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ + /* {{{ proto void git_revwalk_reset(walker) */ @@ -47,35 +45,30 @@ PHP_FUNCTION(git_revwalk_reset) git_revwalk_reset(PHP_GIT2_V(_walker, revwalk)); } -/* {{{ proto long git_revwalk_push(walk, id) -*/ +/* {{{ proto long git_revwalk_push(resource $walk, string $id) + */ PHP_FUNCTION(git_revwalk_push) { - zval *walk; - php_git2_t *_walk; - char *id = {0}; - int id_len; - git_oid oid; - int error = 0; + int result = 0, id_len = 0; + zval *walk = NULL; + php_git2_t *_walk = NULL; + char *id = NULL; + git_oid __id = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &walk, &id, &id_len) == FAILURE) { return; } - if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { - return; - } - ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_revwalk_push(PHP_GIT2_V(_walk, revwalk), &oid); - - if (php_git2_check_error(error, "git_revwalk_push" TSRMLS_CC)) { + if (git_oid_fromstrn(&__id, id, id_len)) { RETURN_FALSE; - } else { - RETURN_TRUE; } + result = git_revwalk_push(PHP_GIT2_V(_walk, revwalk), &__id); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_revwalk_push_glob(walk, glob) */ @@ -248,7 +241,6 @@ PHP_FUNCTION(git_revwalk_next) ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_revwalk_next(&id, PHP_GIT2_V(_walk, revwalk)); - if (error == GIT_ITEROVER) { RETURN_FALSE; } From 10249ff9b2685d13bf00bcbf0d5b2ff0a7ebfe47 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 17:57:59 +0900 Subject: [PATCH 039/136] improve call function --- helper.c | 39 +++++++++++ helper.h | 3 + php_git2_priv.h | 10 +++ tree.c | 170 ++++++++++++++++++++++-------------------------- 4 files changed, 130 insertions(+), 92 deletions(-) diff --git a/helper.c b/helper.c index e140ef5d01..bc0dbf44c2 100644 --- a/helper.c +++ b/helper.c @@ -247,3 +247,42 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v return 0; } + +int php_git2_call_function_v( + zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC, zval **retval_ptr_ptr, zend_uint param_count, ...) +{ + zval **params = NULL; + va_list ap; + int i = 0; + + if (param_count > 0) { + params = emalloc(sizeof(zval*) * param_count); + va_start(ap, param_count); + for (i = 0; i < param_count; i++) { + params[i] = va_arg(ap, zval**); + } + va_end(ap); + } else { + params = NULL; + } + + if (ZEND_FCI_INITIALIZED(*fci)) { + fci->params = params; + fci->retval_ptr_ptr = retval_ptr_ptr; + fci->param_count = param_count; + fci->no_separation = 1; + + if (zend_call_function(fci, fcc TSRMLS_CC) != SUCCESS) { + return 1; + } + zend_fcall_info_args_clear(fci, 0); + } + + if (param_count > 0) { + for (i = 0; i < param_count; i++) { + zval_ptr_dtor(params[i]); + } + efree(params); + } + return 0; +} \ No newline at end of file diff --git a/helper.h b/helper.h index 2de959519f..cb794b5d56 100644 --- a/helper.h +++ b/helper.h @@ -44,4 +44,7 @@ void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC); int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC); +int php_git2_call_function_v( + zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC, zval **retval_ptr_ptr, zend_uint param_count, ...); + #endif \ No newline at end of file diff --git a/php_git2_priv.h b/php_git2_priv.h index 668df73060..03415b4edf 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -38,6 +38,16 @@ extern int git2_resource_handle; #define GIT2_RVAL_P(git2) git2->resource_id #define GIT2_SHOULD_FREE(git2) git2->should_free_v +#ifdef ZTS +#define GIT2_TSRMLS_SET(target) void ***tsrm_ls = target; +#define GIT2_TSRMLS_DECL void ***tsrm_ls; +#define GIT2_TSRMLS_SET2(target, value) target->tsrm_ls = value; +#else +#define GIT2_TSRMLS_SET(target) +#define GIT2_TSRMLS_SET2(target, value) +#define GIT2_TSRMLS_DECL +#endif + #define PHP_GIT2_MAKE_RESOURCE(val) \ do {\ val = (php_git2_t *)emalloc(sizeof(php_git2_t));\ diff --git a/tree.c b/tree.c index 560b7b03d8..545e33b2b1 100644 --- a/tree.c +++ b/tree.c @@ -2,6 +2,64 @@ #include "php_git2_priv.h" #include "tree.h" +typedef struct tree_walk_cb_t { + zval *payload; + zend_fcall_info *fci; + zend_fcall_info_cache *fcc; + GIT2_TSRMLS_DECL +}; + +static int tree_walk_cb(const char *root, const git_tree_entry *entry, void *payload) +{ + php_git2_t *result; + zval *param_root, *param_rsrc, *retval_ptr = NULL; + struct tree_walk_cb_t *p = (struct tree_walk_cb_t*)payload; + int i = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_root); + MAKE_STD_ZVAL(param_rsrc); + + ZVAL_STRING(param_root, root, 1); + php_git2_make_resource(&result, PHP_GIT2_TYPE_TREE_ENTRY, entry, 0 TSRMLS_CC); + zend_list_addref(result->resource_id); + ZVAL_RESOURCE(param_rsrc, result->resource_id); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, ¶m_root, ¶m_rsrc, &p->payload)) { + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + return 0; + } + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + + return 1; +} + +static int php_git2_tree_walk_cb_init(struct tree_walk_cb **out, zend_fcall_info *fci, zend_fcall_info_cache *fcc, void *payload TSRMLS_DC) +{ + struct tree_walk_cb_t *cb; + + cb = (struct tree_walk_cb_t*)emalloc(sizeof(struct tree_walk_cb_t)); + if (cb == NULL) { + return 1; + } + + cb->payload = payload; + cb->fci = fci; + cb->fcc = fcc; + GIT2_TSRMLS_SET2(cb, TSRMLS_C); + + *out = cb; + return 0; +} + +static void php_git2_tree_walk_cb_free(struct tree_walk_cb *target) +{ + efree(target); +} + /* {{{ proto resource git_tree_entry_byindex(resource $tree, string $name) */ PHP_FUNCTION(git_tree_entry_byindex) @@ -128,7 +186,6 @@ PHP_FUNCTION(git_tree_entry_id) zval *tree_entry; php_git2_t *git2; char out[GIT2_OID_HEXSIZE] = {0}; - const git_oid *id; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -138,7 +195,6 @@ PHP_FUNCTION(git_tree_entry_id) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); id = git_tree_entry_id(PHP_GIT2_V(git2, tree_entry)); - git_oid_fmt(out, id); RETURN_STRING(out, 1); } @@ -159,7 +215,6 @@ PHP_FUNCTION(git_tree_entry_type) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); type = git_tree_entry_type(PHP_GIT2_V(git2, tree)); - RETURN_LONG(type); } @@ -178,7 +233,6 @@ PHP_FUNCTION(git_tree_entry_name) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); name = git_tree_entry_name(PHP_GIT2_V(git2, tree_entry)); - RETURN_STRING(name, 1); } @@ -197,7 +251,6 @@ PHP_FUNCTION(git_tree_entrycount) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); count = git_tree_entrycount(PHP_GIT2_V(git2, tree)); - RETURN_LONG(count); } @@ -216,7 +269,6 @@ PHP_FUNCTION(git_tree_entry_filemode) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); filemode = git_tree_entry_filemode(PHP_GIT2_V(git2, tree_entry)); - RETURN_LONG(filemode); } @@ -235,7 +287,6 @@ PHP_FUNCTION(git_tree_entry_filemode_raw) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree_entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); filemode = git_tree_entry_filemode_raw(PHP_GIT2_V(git2, tree_entry)); - RETURN_LONG(filemode); } @@ -254,7 +305,6 @@ PHP_FUNCTION(git_tree_entry_cmp) ZEND_FETCH_RESOURCE(g_e1, php_git2_t*, &e1, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(g_e2, php_git2_t*, &e2, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_tree_entry_cmp(PHP_GIT2_V(g_e1, tree_entry), PHP_GIT2_V(g_e2, tree_entry)); RETURN_LONG(result); } @@ -334,7 +384,6 @@ PHP_FUNCTION(git_tree_id) zval *tree; php_git2_t *git2; char out[GIT2_OID_HEXSIZE] = {0}; - const git_oid *id; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -344,7 +393,6 @@ PHP_FUNCTION(git_tree_id) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); id = git_tree_id(PHP_GIT2_V(git2, tree)); - git_oid_fmt(out, id); RETURN_STRING(out, 1); } @@ -389,88 +437,27 @@ PHP_FUNCTION(git_tree_lookup) /* }}} */ /* {{{ proto resource git_tree_owner(resource $tree) -*/ + */ PHP_FUNCTION(git_tree_owner) { - zval *tree; - php_git2_t *git2, *result; - git_repository *repository; + git_repository *result = NULL; + zval *tree = NULL; + php_git2_t *_tree = NULL, *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tree) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - PHP_GIT2_MAKE_RESOURCE(result); - repository = git_tree_owner(PHP_GIT2_V(git2, tree)); - - PHP_GIT2_V(result, repository) = repository; - result->type = PHP_GIT2_TYPE_REPOSITORY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + ZEND_FETCH_RESOURCE(_tree, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_tree_owner(PHP_GIT2_V(_tree, tree)); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_TREE, result, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); } /* }}} */ -typedef struct tree_walk_cb_t { - zval *payload; - zend_fcall_info *fci; - zend_fcall_info_cache *fcc; -#ifdef ZTS - void ***tsrmls; -#endif -}; - -static int tree_walk_cb(const char *root, const git_tree_entry *entry, void *payload) -{ - php_git2_t *result; - zval **params[3], *param_root, *param_rsrc, *retval_ptr = NULL; - struct tree_walk_cb_t *p = (struct tree_walk_cb_t*)payload; -#ifdef ZTS - void ***tsrm_ls = p->tsrmls; -#endif - - MAKE_STD_ZVAL(param_root); - ZVAL_STRING(param_root, root, 1); - MAKE_STD_ZVAL(param_rsrc); - //MAKE_STD_ZVAL(retval_ptr); - - PHP_GIT2_MAKE_RESOURCE_NOCHECK(result); - - PHP_GIT2_V(result, tree_entry) = entry; - result->type = PHP_GIT2_TYPE_TREE_ENTRY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(param_rsrc, result->resource_id); - - params[0] = ¶m_root; - params[1] = ¶m_rsrc; - params[2] = &p->payload; - - if (ZEND_FCI_INITIALIZED(*p->fci)) { - p->fci->params = params; - p->fci->retval_ptr_ptr = &retval_ptr; - p->fci->param_count = 3; - p->fci->no_separation = 1; - - if (zend_call_function(p->fci, p->fcc TSRMLS_CC) != SUCCESS) { - } - - zend_fcall_info_args_clear(p->fci, 0); - } - - zval_ptr_dtor(¶m_root); - zval_ptr_dtor(¶m_rsrc); - zval_ptr_dtor(&retval_ptr); - - zend_list_delete(result->resource_id); - - return 1; -} /* {{{ proto void git_tree_walk(resource $tree, long $mode, Callable $callback, mixed &$payload) */ @@ -480,25 +467,24 @@ PHP_FUNCTION(git_tree_walk) php_git2_t *git2, *result; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; - long mode; + long mode = GIT_TREEWALK_PRE; struct tree_walk_cb_t *cb; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlf|z", &tree, &mode, &fci, &fcc, &payload) == FAILURE) { return; } - cb = (struct tree_walk_cb_t*)emalloc(sizeof(struct tree_walk_cb_t)); - cb->payload = payload; -#ifdef ZTS - cb->tsrmls = TSRMLS_C; -#endif - cb->fci = &fci; - cb->fcc = &fcc; - ZEND_FETCH_RESOURCE(git2, php_git2_t*, &tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - git_tree_walk(PHP_GIT2_V(git2, tree), mode, tree_walk_cb, cb); + if (php_git2_tree_walk_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + error = git_tree_walk(PHP_GIT2_V(git2, tree), mode, tree_walk_cb, cb); + php_git2_tree_walk_cb_free(cb); + if (php_git2_check_error(error, "git_tree_walk" TSRMLS_CC)) { + RETURN_FALSE + } - efree(cb); } /* }}} */ From 0543448b496a6ad5025174140fd5fc33efd15d81 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 19:11:15 +0900 Subject: [PATCH 040/136] [reference] add foreach callback --- helper.c | 28 ++++++ helper.h | 4 + ng.php | 1 + php_git2.c | 2 - php_git2.h | 2 + php_git2_priv.h | 7 ++ reference.c | 258 ++++++++++++++++++++++++++++++++++-------------- reference.h | 4 +- 8 files changed, 227 insertions(+), 79 deletions(-) diff --git a/helper.c b/helper.c index bc0dbf44c2..7d31a61c60 100644 --- a/helper.c +++ b/helper.c @@ -171,6 +171,9 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v case PHP_GIT2_TYPE_REFERENCE: PHP_GIT2_V(result, reference) = (git_reference*)resource; break; + case PHP_GIT2_TYPE_REFERENCE_ITERATOR: + PHP_GIT2_V(result, reference_iterator) = (git_reference_iterator*)resource; + break; case PHP_GIT2_TYPE_CONFIG: PHP_GIT2_V(result, config) = (git_config*)resource; break; @@ -237,6 +240,8 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v case PHP_GIT2_TYPE_DIFF_LINE: PHP_GIT2_V(result, diff_line) = (git_diff_line*)resource; break; + default: + php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } result->type = type; @@ -285,4 +290,27 @@ int php_git2_call_function_v( efree(params); } return 0; +} + +int php_git2_cb_init(php_git2_cb_t **out, zend_fcall_info *fci, zend_fcall_info_cache *fcc, void *payload TSRMLS_DC) +{ + php_git2_cb_t *cb; + + cb = (struct php_git2_cb_t*)emalloc(sizeof(php_git2_cb_t)); + if (cb == NULL) { + return 1; + } + + cb->payload = payload; + cb->fci = fci; + cb->fcc = fcc; + GIT2_TSRMLS_SET2(cb, TSRMLS_C); + + *out = cb; + return 0; +} + +void php_git2_cb_free(php_git2_cb_t *target) +{ + efree(target); } \ No newline at end of file diff --git a/helper.h b/helper.h index cb794b5d56..10f7692d5d 100644 --- a/helper.h +++ b/helper.h @@ -47,4 +47,8 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v int php_git2_call_function_v( zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC, zval **retval_ptr_ptr, zend_uint param_count, ...); +int php_git2_cb_init(php_git2_cb_t **out, zend_fcall_info *fci, zend_fcall_info_cache *fcc, void *payload TSRMLS_DC); + +void php_git2_cb_free(php_git2_cb_t *target); + #endif \ No newline at end of file diff --git a/ng.php b/ng.php index ccdc0d6390..c35317924a 100644 --- a/ng.php +++ b/ng.php @@ -359,6 +359,7 @@ public function shouldResource(Arg $arg) "git_buf", "git_filter_source", "git_diff_line", + "git_reference_iterator", ); } diff --git a/php_git2.c b/php_git2.c index 5830a070c4..c9b1cb82e8 100644 --- a/php_git2.c +++ b/php_git2.c @@ -89,8 +89,6 @@ void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) case PHP_GIT2_TYPE_OBJECT: git_object_free(PHP_GIT2_V(resource, object)); break; - default: - break; } } diff --git a/php_git2.h b/php_git2.h index 85e195cb6c..2c44ac6c2e 100644 --- a/php_git2.h +++ b/php_git2.h @@ -86,6 +86,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_REVWALK, PHP_GIT2_TYPE_TREEBUILDER, PHP_GIT2_TYPE_REFERENCE, + PHP_GIT2_TYPE_REFERENCE_ITERATOR, PHP_GIT2_TYPE_CONFIG, PHP_GIT2_TYPE_OBJECT, PHP_GIT2_TYPE_INDEX, @@ -121,6 +122,7 @@ typedef struct php_git2_t { git_revwalk *revwalk; git_treebuilder *treebuilder; git_reference *reference; + git_reference_iterator *reference_iterator; git_config *config; git_object *object; git_index *index; diff --git a/php_git2_priv.h b/php_git2_priv.h index 03415b4edf..db700c65ee 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -71,6 +71,13 @@ do {\ #define GIT2_OID_HEXSIZE (GIT_OID_HEXSZ+1) +typedef struct php_git2_cb_t { + zval *payload; + zend_fcall_info *fci; + zend_fcall_info_cache *fcc; + GIT2_TSRMLS_DECL +} php_git2_cb_t; + #include "helper.h" #endif \ No newline at end of file diff --git a/reference.c b/reference.c index 0519c7de04..080305129f 100644 --- a/reference.c +++ b/reference.c @@ -2,6 +2,60 @@ #include "php_git2_priv.h" #include "reference.h" +static int php_git2_reference_foreach_cb(git_reference *reference, void *payload) +{ + php_git2_t *result; + zval *param_reference, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_reference); + + php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, reference, 0 TSRMLS_CC); + zend_list_addref(result->resource_id); + ZVAL_RESOURCE(param_reference, result->resource_id); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_reference, &p->payload)) { + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + return GIT_EUSER; + } + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + + return retval; +} + +static int php_git2_reference_foreach_name_cb(const char *name, void *payload) +{ + php_git2_t *result; + zval *param_name, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_name); + ZVAL_STRING(param_name, name, 1); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_name, &p->payload)) { + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + return GIT_EUSER; + } + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + + return retval; +} + + /* {{{ proto resource git_reference_lookup(repo, name) */ PHP_FUNCTION(git_reference_lookup) @@ -457,47 +511,59 @@ PHP_FUNCTION(git_reference_list) RETURN_ZVAL(result, 0, 1); } -/* {{{ proto long git_reference_foreach(repo, callback, payload) -*/ +/* {{{ proto long git_reference_foreach(resource $repo, $callback, $payload) + */ PHP_FUNCTION(git_reference_foreach) { - zval *repo; - php_git2_t *_repo; - zval *callback; - php_git2_t *_callback; + int result = 0, error = 0; + zval *repo = NULL, *callback = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb; zval *payload; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_foreach not implemented yet"); - return; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &repo, &callback, &payload) == FAILURE) { + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_reference_foreach(PHP_GIT2_V(_repo, repository), php_git2_reference_foreach_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_reference_foreach_name(repo, callback, payload) -*/ +/* {{{ proto long git_reference_foreach_name(resource $repo, $callback, $payload) + */ PHP_FUNCTION(git_reference_foreach_name) { - zval *repo; - php_git2_t *_repo; - zval *callback; - php_git2_t *_callback; + int result = 0, error = 0; + zval *repo = NULL, *callback = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb; zval *payload; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_foreach_name not implemented yet"); - return; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &repo, &callback, &payload) == FAILURE) { + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_reference_foreach_name(PHP_GIT2_V(_repo, repository), php_git2_reference_foreach_name_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ /* {{{ proto void git_reference_free(ref) */ @@ -538,97 +604,133 @@ PHP_FUNCTION(git_reference_cmp) RETURN_LONG(result); } -/* {{{ proto resource git_reference_iterator_new(repo) -*/ +/* {{{ proto resource git_reference_iterator_new(resource $repo) + */ PHP_FUNCTION(git_reference_iterator_new) { - zval *repo; - php_git2_t *_repo; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_iterator_new not implemented yet"); - return; + php_git2_t *result = NULL, *_repo = NULL; + git_reference_iterator *out = NULL; + zval *repo = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_iterator_new(&out, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_reference_iterator_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE_ITERATOR, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_iterator_glob_new(repo, glob) -*/ + +/* {{{ proto resource git_reference_iterator_glob_new(resource $repo, string $glob) + */ PHP_FUNCTION(git_reference_iterator_glob_new) { - zval *repo; - php_git2_t *_repo; - char *glob = {0}; - int glob_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_iterator_glob_new not implemented yet"); - return; + php_git2_t *result = NULL, *_repo = NULL; + git_reference_iterator *out = NULL; + zval *repo = NULL; + char *glob = NULL; + int glob_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &glob, &glob_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_iterator_glob_new(&out, PHP_GIT2_V(_repo, repository), glob); + if (php_git2_check_error(error, "git_reference_iterator_glob_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE_ITERATOR, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_next(iter) -*/ + +/* {{{ proto resource git_reference_next(resource $iter) + */ PHP_FUNCTION(git_reference_next) { - zval *iter; - php_git2_t *_iter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_next not implemented yet"); - return; + php_git2_t *result = NULL, *_iter = NULL; + git_reference *out = NULL; + zval *iter = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &iter) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_next(&out, PHP_GIT2_V(_iter, reference_iterator)); + if (error == GIT_ITEROVER || php_git2_check_error(error, "git_reference_next" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_next_name(iter) -*/ + +/* {{{ proto resource git_reference_next_name(resource $iter) + */ PHP_FUNCTION(git_reference_next_name) { - zval *iter; - php_git2_t *_iter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_next_name not implemented yet"); - return; + php_git2_t *result = NULL, *_iter = NULL; + const char *out = NULL; + zval *iter = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &iter) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_next_name(&out, PHP_GIT2_V(_iter, reference_iterator)); + if (php_git2_check_error(error, "git_reference_next_name" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(out, 1); } +/* }}} */ -/* {{{ proto void git_reference_iterator_free(iter) -*/ + +/* {{{ proto void git_reference_iterator_free(resource $iter) + */ PHP_FUNCTION(git_reference_iterator_free) { - zval *iter; - php_git2_t *_iter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_iterator_free not implemented yet"); - return; + zval *iter = NULL; + php_git2_t *_iter = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &iter) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_iter)) { + git_reference_iterator_free(PHP_GIT2_V(_iter, reference_iterator)); + GIT2_SHOULD_FREE(_iter) = 0; + }; + zval_ptr_dtor(&iter); } +/* }}} */ + /* {{{ proto long git_reference_foreach_glob(repo, glob, callback, payload) */ @@ -745,25 +847,31 @@ PHP_FUNCTION(git_reference_normalize_name) RETURN_STRING(buffer, 1); } -/* {{{ proto resource git_reference_peel(ref, type) -*/ +/* {{{ proto resource git_reference_peel(resource $ref, $type) + */ PHP_FUNCTION(git_reference_peel) { - zval *ref; - php_git2_t *_ref; - zval *type; - php_git2_t *_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_peel not implemented yet"); - return; + php_git2_t *result = NULL, *_ref = NULL; + git_object *out = NULL; + zval *ref = NULL, *type = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &ref, &type) == FAILURE) { + "r", &ref, &type) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reference_peel(&out, PHP_GIT2_V(_ref, reference), type); + if (php_git2_check_error(error, "git_reference_peel" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ /* {{{ proto long git_reference_is_valid_name(refname) */ diff --git a/reference.h b/reference.h index 22597db64d..70f0a12f4c 100644 --- a/reference.h +++ b/reference.h @@ -111,13 +111,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_foreach, 0, 0, 3) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_foreach_name, 0, 0, 3) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_free, 0, 0, 1) From 08e30003bf5d9ae6804ef02bb8b7db54d37925ea Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 19:17:21 +0900 Subject: [PATCH 041/136] [ref] add foreach_glob --- reference.c | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/reference.c b/reference.c index 080305129f..d21b2c8cc9 100644 --- a/reference.c +++ b/reference.c @@ -263,23 +263,25 @@ PHP_FUNCTION(git_reference_target_peel) RETURN_STRING(out, 1); } -/* {{{ proto resource git_reference_symbolic_target(ref) -*/ +/* {{{ proto string git_reference_symbolic_target(resource $ref) + */ PHP_FUNCTION(git_reference_symbolic_target) { - zval *ref; - php_git2_t *_ref; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_symbolic_target not implemented yet"); - return; + const char *result = NULL; + zval *ref = NULL; + php_git2_t *_ref = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reference_symbolic_target(PHP_GIT2_V(_ref, reference)); + RETURN_STRING(result, 1); } +/* }}} */ + /* {{{ proto resource git_reference_type(ref) */ @@ -731,29 +733,33 @@ PHP_FUNCTION(git_reference_iterator_free) } /* }}} */ - -/* {{{ proto long git_reference_foreach_glob(repo, glob, callback, payload) -*/ +/* {{{ proto long git_reference_foreach_glob(resource $repo, string $glob, $callback, $payload) + */ PHP_FUNCTION(git_reference_foreach_glob) { - zval *repo; - php_git2_t *_repo; - char *glob = {0}; - int glob_len; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_reference_foreach_glob not implemented yet"); - return; + int result = 0, glob_len = 0, error = 0; + zval *repo = NULL, *callback = NULL; + php_git2_t *_repo = NULL; + char *glob = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb; + zval *payload = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsrz", &repo, &glob, &glob_len, &callback, &payload) == FAILURE) { + "rsfz", &repo, &glob, &glob_len, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_reference_foreach_glob(PHP_GIT2_V(_repo, repository), glob, php_git2_reference_foreach_name_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ /* {{{ proto long git_reference_has_log(ref) */ From bf9b67515c4b90a6e6a8290d09384e42a2b47b09 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 19:23:03 +0900 Subject: [PATCH 042/136] [revwalk] improve functions --- revwalk.c | 132 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/revwalk.c b/revwalk.c index 8130287e10..221a2ca2ac 100644 --- a/revwalk.c +++ b/revwalk.c @@ -69,26 +69,26 @@ PHP_FUNCTION(git_revwalk_push) } /* }}} */ - -/* {{{ proto long git_revwalk_push_glob(walk, glob) -*/ +/* {{{ proto long git_revwalk_push_glob(resource $walk, string $glob) + */ PHP_FUNCTION(git_revwalk_push_glob) { - zval *walk; - php_git2_t *_walk; - char *glob = {0}; - int glob_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_push_glob not implemented yet"); - return; + int result = 0, glob_len = 0, error = 0; + zval *walk = NULL; + php_git2_t *_walk = NULL; + char *glob = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &walk, &glob, &glob_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_revwalk_push_glob(PHP_GIT2_V(_walk, revwalk), glob); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_revwalk_push_head(walk) */ @@ -142,25 +142,26 @@ PHP_FUNCTION(git_revwalk_hide) } -/* {{{ proto long git_revwalk_hide_glob(walk, glob) -*/ +/* {{{ proto long git_revwalk_hide_glob(resource $walk, string $glob) + */ PHP_FUNCTION(git_revwalk_hide_glob) { - zval *walk; - php_git2_t *_walk; - char *glob = {0}; - int glob_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_hide_glob not implemented yet"); - return; + int result = 0, glob_len = 0, error = 0; + zval *walk = NULL; + php_git2_t *_walk = NULL; + char *glob = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &walk, &glob, &glob_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_revwalk_hide_glob(PHP_GIT2_V(_walk, revwalk), glob); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_revwalk_hide_head(walk) */ @@ -184,45 +185,47 @@ PHP_FUNCTION(git_revwalk_hide_head) } } -/* {{{ proto long git_revwalk_push_ref(walk, refname) -*/ +/* {{{ proto long git_revwalk_push_ref(resource $walk, string $refname) + */ PHP_FUNCTION(git_revwalk_push_ref) { - zval *walk; - php_git2_t *_walk; - char *refname = {0}; - int refname_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_push_ref not implemented yet"); - return; + int result = 0, refname_len = 0, error = 0; + zval *walk = NULL; + php_git2_t *_walk = NULL; + char *refname = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &walk, &refname, &refname_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_revwalk_push_ref(PHP_GIT2_V(_walk, revwalk), refname); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_revwalk_hide_ref(walk, refname) -*/ + +/* {{{ proto long git_revwalk_hide_ref(resource $walk, string $refname) + */ PHP_FUNCTION(git_revwalk_hide_ref) { - zval *walk; - php_git2_t *_walk; - char *refname = {0}; - int refname_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_hide_ref not implemented yet"); - return; + int result = 0, refname_len = 0, error = 0; + zval *walk = NULL; + php_git2_t *_walk = NULL; + char *refname = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &walk, &refname, &refname_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_revwalk_hide_ref(PHP_GIT2_V(_walk, revwalk), refname); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto string git_revwalk_next(walk) */ @@ -267,25 +270,26 @@ PHP_FUNCTION(git_revwalk_sorting) git_revwalk_sorting(PHP_GIT2_V(_walk, revwalk), sort_mode); } -/* {{{ proto long git_revwalk_push_range(walk, range) -*/ +/* {{{ proto long git_revwalk_push_range(resource $walk, string $range) + */ PHP_FUNCTION(git_revwalk_push_range) { - zval *walk; - php_git2_t *_walk; - char *range = {0}; - int range_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revwalk_push_range not implemented yet"); - return; + int result = 0, range_len = 0, error = 0; + zval *walk = NULL; + php_git2_t *_walk = NULL; + char *range = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &walk, &range, &range_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_revwalk_push_range(PHP_GIT2_V(_walk, revwalk), range); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto void git_revwalk_simplify_first_parent(walk) */ @@ -303,24 +307,27 @@ PHP_FUNCTION(git_revwalk_simplify_first_parent) git_revwalk_simplify_first_parent(PHP_GIT2_V(_walk, revwalk)); } -/* {{{ proto void git_revwalk_free(walk) -*/ +/* {{{ proto void git_revwalk_free(resource $walk) + */ PHP_FUNCTION(git_revwalk_free) { - zval *walk; - php_git2_t *_walk; + zval *walk = NULL; + php_git2_t *_walk = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &walk) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_walk->should_free_v) { + ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_walk)) { git_revwalk_free(PHP_GIT2_V(_walk, revwalk)); - } + GIT2_SHOULD_FREE(_walk) = 0; + }; zval_ptr_dtor(&walk); } +/* }}} */ + /* {{{ proto resource git_revwalk_repository(walk) */ @@ -337,12 +344,9 @@ PHP_FUNCTION(git_revwalk_repository) ZEND_FETCH_RESOURCE(_walk, php_git2_t*, &walk, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); repository = git_revwalk_repository(PHP_GIT2_V(_walk, revwalk)); - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, repository) = repository; - result->type = PHP_GIT2_TYPE_REPOSITORY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, repository, 0 TSRMLS_CC)) { + RETURN_FALSE; + } ZVAL_RESOURCE(return_value, result->resource_id); } From 7a81f1b2dc90a68df3a0689678acd486227361c5 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 12 Jan 2014 19:29:17 +0900 Subject: [PATCH 043/136] [tag] add foreach function --- php_git2.c | 22 +++++++++++++++++++ tag.c | 63 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/php_git2.c b/php_git2.c index c9b1cb82e8..1bb1e357be 100644 --- a/php_git2.c +++ b/php_git2.c @@ -558,6 +558,28 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_merge_result_fastforward_oid, arginfo_git_merge_result_fastforward_oid) PHP_FE(git_merge_result_free, arginfo_git_merge_result_free) + /* tag */ + PHP_FE(git_tag_lookup, arginfo_git_tag_lookup) + PHP_FE(git_tag_lookup_prefix, arginfo_git_tag_lookup_prefix) + PHP_FE(git_tag_free, arginfo_git_tag_free) + PHP_FE(git_tag_id, arginfo_git_tag_id) + PHP_FE(git_tag_owner, arginfo_git_tag_owner) + PHP_FE(git_tag_target, arginfo_git_tag_target) + PHP_FE(git_tag_target_id, arginfo_git_tag_target_id) + PHP_FE(git_tag_target_type, arginfo_git_tag_target_type) + PHP_FE(git_tag_name, arginfo_git_tag_name) + PHP_FE(git_tag_tagger, arginfo_git_tag_tagger) + PHP_FE(git_tag_message, arginfo_git_tag_message) + PHP_FE(git_tag_create, arginfo_git_tag_create) + PHP_FE(git_tag_annotation_create, arginfo_git_tag_annotation_create) + PHP_FE(git_tag_create_frombuffer, arginfo_git_tag_create_frombuffer) + PHP_FE(git_tag_create_lightweight, arginfo_git_tag_create_lightweight) + PHP_FE(git_tag_delete, arginfo_git_tag_delete) + PHP_FE(git_tag_list, arginfo_git_tag_list) + PHP_FE(git_tag_list_match, arginfo_git_tag_list_match) + PHP_FE(git_tag_foreach, arginfo_git_tag_foreach) + PHP_FE(git_tag_peel, arginfo_git_tag_peel) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/tag.c b/tag.c index 92119ff57f..df9a35ac7e 100644 --- a/tag.c +++ b/tag.c @@ -2,6 +2,38 @@ #include "php_git2_priv.h" #include "tag.h" +static int php_git2_tag_foreach_cb(const char *name, git_oid *oid, void *payload) +{ + php_git2_t *result; + zval *param_name, *param_oid, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + char buffer[41] = {0}; + GIT2_TSRMLS_SET(p->tsrm_ls) + + git_oid_fmt(buffer, oid); + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_name); + MAKE_STD_ZVAL(param_oid); + ZVAL_STRING(param_name, name, 1); + ZVAL_STRING(param_oid, buffer, 1); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, ¶m_name, ¶m_oid, &p->payload)) { + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + + return retval; +} + + /* {{{ proto resource git_tag_lookup(resource $repo, string $id) */ PHP_FUNCTION(git_tag_lookup) @@ -482,26 +514,33 @@ PHP_FUNCTION(git_tag_list_match) /* }}} */ -/* {{{ proto long git_tag_foreach(repo, callback, payload) -*/ +/* {{{ proto long git_tag_foreach(resource $repo, $callback, $payload) + */ PHP_FUNCTION(git_tag_foreach) { - zval *repo; - php_git2_t *_repo; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_tag_foreach not implemented yet"); - return; + int result = 0, error = 0; + zval *repo = NULL, *callback = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb; + zval *payload = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &repo, &callback, &payload) == FAILURE) { + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_tag_foreach(PHP_GIT2_V(_repo, repository), php_git2_tag_foreach_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto resource git_tag_peel(resource $tag) */ From 9e6e921eeba72e0cc26bfd1837d66eda61d6fa20 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 01:31:38 +0900 Subject: [PATCH 044/136] [treebuilder] add filter function --- helper.c | 6 +++++ reference.c | 3 +-- tree.c | 1 - treebuilder.c | 62 +++++++++++++++++++++++++++++++++++++++++---------- treebuilder.h | 2 +- 5 files changed, 58 insertions(+), 16 deletions(-) diff --git a/helper.c b/helper.c index 7d31a61c60..d5bdc1cb0c 100644 --- a/helper.c +++ b/helper.c @@ -278,6 +278,12 @@ int php_git2_call_function_v( fci->no_separation = 1; if (zend_call_function(fci, fcc TSRMLS_CC) != SUCCESS) { + if (param_count > 0) { + for (i = 0; i < param_count; i++) { + zval_ptr_dtor(params[i]); + } + efree(params); + } return 1; } zend_fcall_info_args_clear(fci, 0); diff --git a/reference.c b/reference.c index d21b2c8cc9..248c3581c4 100644 --- a/reference.c +++ b/reference.c @@ -19,14 +19,13 @@ static int php_git2_reference_foreach_cb(git_reference *reference, void *payload ZVAL_RESOURCE(param_reference, result->resource_id); if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_reference, &p->payload)) { - zval_ptr_dtor(&retval_ptr); zend_list_delete(result->resource_id); return GIT_EUSER; } + retval = Z_LVAL_P(retval_ptr); zval_ptr_dtor(&retval_ptr); zend_list_delete(result->resource_id); - return retval; } diff --git a/tree.c b/tree.c index 545e33b2b1..1fc2f40048 100644 --- a/tree.c +++ b/tree.c @@ -27,7 +27,6 @@ static int tree_walk_cb(const char *root, const git_tree_entry *entry, void *pay ZVAL_RESOURCE(param_rsrc, result->resource_id); if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, ¶m_root, ¶m_rsrc, &p->payload)) { - zval_ptr_dtor(&retval_ptr); zend_list_delete(result->resource_id); return 0; } diff --git a/treebuilder.c b/treebuilder.c index 1d2780f85b..f671629a2f 100644 --- a/treebuilder.c +++ b/treebuilder.c @@ -2,6 +2,39 @@ #include "php_git2_priv.h" #include "revwalk.h" +static int php_git2_treebuilder_filter_cb(const git_tree_entry *entry, void *payload) +{ + php_git2_t *result; + zval *param_tree_entry, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + MAKE_STD_ZVAL(param_tree_entry); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREE_ENTRY, entry, 0 TSRMLS_CC)) { + return 0; + } + ZVAL_RESOURCE(param_tree_entry, GIT2_RVAL_P(result)); + zend_list_addref(GIT2_RVAL_P(result)); + Z_ADDREF_P(p->payload); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_tree_entry, &p->payload)) { + zval_ptr_dtor(¶m_tree_entry); + zval_ptr_dtor(&p->payload); + zend_list_delete(result->resource_id); + retval = 0; + return 0; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + zend_list_delete(result->resource_id); + + return retval; +} + + /* {{{ proto resource git_treebuilder_create([resource $source]) */ PHP_FUNCTION(git_treebuilder_create) @@ -179,26 +212,31 @@ PHP_FUNCTION(git_treebuilder_remove) RETURN_TRUE; } -/* {{{ proto void git_treebuilder_filter(bld, filter, payload) -*/ +/* {{{ proto void git_treebuilder_filter(resource $bld, $filter, $payload) + */ PHP_FUNCTION(git_treebuilder_filter) { - zval *bld; - php_git2_t *_bld; - zval *filter; - php_git2_t *_filter; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_treebuilder_filter not implemented yet"); - return; + zval *bld = NULL, *filter = NULL; + php_git2_t *_bld = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb; + zval *payload = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &bld, &filter, &payload) == FAILURE) { + "rfz", &bld, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + git_treebuilder_filter(PHP_GIT2_V(_bld, treebuilder), php_git2_treebuilder_filter_cb, cb); + php_git2_cb_free(cb); } +/* }}} */ + /* {{{ proto resource git_treebuilder_write(repo, bld) */ diff --git a/treebuilder.h b/treebuilder.h index 6d587b9747..46be8dcfe1 100644 --- a/treebuilder.h +++ b/treebuilder.h @@ -62,7 +62,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_filter, 0, 0, 3) ZEND_ARG_INFO(0, bld) ZEND_ARG_INFO(0, filter) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_treebuilder_write, 0, 0, 2) From 2de2ab81bc7cc6f93693de7abdcc1c50e954922f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 02:26:22 +0900 Subject: [PATCH 045/136] [config] add callback --- g_config.c | 343 +++++++++++++++++++++++++++++------------------- g_config.h | 4 +- helper.c | 116 ---------------- helper.h | 2 - ng.php | 97 +++++++++++--- php_git2.c | 118 +++++++++++++++++ php_git2.h | 2 + php_git2_priv.h | 2 + 8 files changed, 413 insertions(+), 271 deletions(-) diff --git a/g_config.c b/g_config.c index c2690608b5..f62afb1068 100644 --- a/g_config.c +++ b/g_config.c @@ -2,7 +2,6 @@ #include "php_git2_priv.h" #include "g_config.h" - enum php_git2_config { PHP_GIT2_CONFIG_STRING, PHP_GIT2_CONFIG_BOOL, @@ -10,6 +9,34 @@ enum php_git2_config { PHP_GIT2_CONFIG_INT32, }; +static void php_git2_config_entry_to_array(git_config_entry *entry, zval **result); + +static int php_git2_config_foreach_cb(const git_config_entry *entry, void *payload) +{ + php_git2_t *result; + zval *param_config_entry, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + php_git2_config_entry_to_array(entry, ¶m_config_entry); + Z_ADDREF_P(p->payload); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_config_entry, &p->payload)) { + zval_ptr_dtor(¶m_config_entry); + zval_ptr_dtor(&p->payload); + zend_list_delete(result->resource_id); + retval = 0; + return 0; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + + static void php_git2_config_get_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2_config type) { zval *cfg; @@ -161,6 +188,19 @@ static void php_git2_config_parse_with(INTERNAL_FUNCTION_PARAMETERS, enum php_gi } } +static void php_git2_config_entry_to_array(git_config_entry *entry, zval **result) +{ + zval *tmp; + + MAKE_STD_ZVAL(tmp); + array_init(tmp); + + add_assoc_string_ex(tmp, ZEND_STRS("name"), entry->name, 1); + add_assoc_string_ex(tmp, ZEND_STRS("value"), entry->value, 1); + add_assoc_long_ex(tmp, ZEND_STRS("level"), entry->level); + *result = tmp; +} + /* {{{ proto resource git_config_find_global() */ PHP_FUNCTION(git_config_find_global) @@ -350,12 +390,9 @@ PHP_FUNCTION(git_config_open_global) if (php_git2_check_error(error, "git_config_open_global" TSRMLS_CC)) { RETURN_FALSE } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, config) = out; - result->type = PHP_GIT2_TYPE_CONFIG; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CONFIG, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } ZVAL_RESOURCE(return_value, result->resource_id); } @@ -380,25 +417,26 @@ PHP_FUNCTION(git_config_refresh) RETURN_TRUE; } -/* {{{ proto void git_config_free(cfg) -*/ +/* {{{ proto void git_config_free(resource $cfg) + */ PHP_FUNCTION(git_config_free) { - zval *cfg; - php_git2_t *_cfg; + zval *cfg = NULL; + php_git2_t *_cfg = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &cfg) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_cfg->should_free_v) { + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_cfg)) { git_config_free(PHP_GIT2_V(_cfg, config)); - _cfg->should_free_v = 0; - } + GIT2_SHOULD_FREE(_cfg) = 0; + }; zval_ptr_dtor(&cfg); } +/* }}} */ /* {{{ proto resource git_config_get_entry(cfg, name) */ @@ -422,13 +460,7 @@ PHP_FUNCTION(git_config_get_entry) RETURN_FALSE } - MAKE_STD_ZVAL(result); - array_init(result); - - add_assoc_string_ex(result, ZEND_STRS("name"), entry->name, 1); - add_assoc_string_ex(result, ZEND_STRS("value"), entry->value, 1); - add_assoc_long_ex(result, ZEND_STRS("level"), entry->level); - + php_git2_config_entry_to_array(entry, &result); RETURN_ZVAL(result, 0, 1); } @@ -460,88 +492,106 @@ PHP_FUNCTION(git_config_get_string) php_git2_config_get_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_STRING); } -/* {{{ proto long git_config_get_multivar_foreach(cfg, name, regexp, callback, payload) -*/ +/* {{{ proto long git_config_get_multivar_foreach(resource $cfg, string $name, string $regexp, Callable $callback, $payload) + */ PHP_FUNCTION(git_config_get_multivar_foreach) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - char *regexp = {0}; - int regexp_len; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_get_multivar_foreach not implemented yet"); - return; + int result = 0, name_len = 0, regexp_len = 0, error = 0; + zval *cfg = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_cfg = NULL; + char *name = NULL, *regexp = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rssrz", &cfg, &name, &name_len, ®exp, ®exp_len, &callback, &payload) == FAILURE) { + "rssfz", &cfg, &name, &name_len, ®exp, ®exp_len, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_config_get_multivar_foreach(PHP_GIT2_V(_cfg, config), name, regexp, php_git2_config_foreach_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_config_multivar_iterator_new(cfg, name, regexp) -*/ + +/* {{{ proto resource git_config_multivar_iterator_new(resource $cfg, string $name, string $regexp) + */ PHP_FUNCTION(git_config_multivar_iterator_new) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - char *regexp = {0}; - int regexp_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_multivar_iterator_new not implemented yet"); - return; + php_git2_t *result = NULL, *_cfg = NULL; + git_config_iterator *out = NULL; + zval *cfg = NULL; + char *name = NULL, *regexp = NULL; + int name_len = 0, regexp_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &cfg, &name, &name_len, ®exp, ®exp_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_config_multivar_iterator_new(&out, PHP_GIT2_V(_cfg, config), name, regexp); + if (php_git2_check_error(error, "git_config_multivar_iterator_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CONFIG_ITERATOR, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_config_next(iter) -*/ +/* {{{ proto long git_config_next(resource $iter) + */ PHP_FUNCTION(git_config_next) { - zval *iter; - php_git2_t *_iter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_next not implemented yet"); - return; + int result = 0, error = 0; + git_config_entry *entry = NULL; + zval *iter = NULL; + php_git2_t *_iter = NULL; + zval *out; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &iter) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_config_next(&entry, PHP_GIT2_V(_iter, config_iterator)); + if (result == GIT_ITEROVER || php_git2_check_error(result, "git_config_next" TSRMLS_CC)) { + RETURN_FALSE + } + php_git2_config_entry_to_array(entry, &out); + RETURN_ZVAL(out, 0, 1); } +/* }}} */ -/* {{{ proto void git_config_iterator_free(iter) -*/ +/* {{{ proto void git_config_iterator_free(resource $iter) + */ PHP_FUNCTION(git_config_iterator_free) { - zval *iter; - php_git2_t *_iter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_iterator_free not implemented yet"); - return; + zval *iter = NULL; + php_git2_t *_iter = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &iter) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_iter)) { + git_config_iterator_free(PHP_GIT2_V(_iter, config_iterator)); + GIT2_SHOULD_FREE(_iter) = 0; + }; + zval_ptr_dtor(&iter); } +/* }}} */ /* {{{ proto long git_config_set_int32(cfg, name, value) */ @@ -571,29 +621,25 @@ PHP_FUNCTION(git_config_set_string) php_git2_config_set_with(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GIT2_CONFIG_STRING); } -/* {{{ proto long git_config_set_multivar(cfg, name, regexp, value) -*/ +/* {{{ proto long git_config_set_multivar(resource $cfg, string $name, string $regexp, string $value) + */ PHP_FUNCTION(git_config_set_multivar) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - char *regexp = {0}; - int regexp_len; - char *value = {0}; - int value_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_set_multivar not implemented yet"); - return; + int result = 0, name_len = 0, regexp_len = 0, value_len = 0, error = 0; + zval *cfg = NULL; + php_git2_t *_cfg = NULL; + char *name = NULL, *regexp = NULL, *value = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &cfg, &name, &name_len, ®exp, ®exp_len, &value, &value_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_config_set_multivar(PHP_GIT2_V(_cfg, config), name, regexp, value); + RETURN_LONG(result); } +/* }}} */ /* {{{ proto long git_config_delete_entry(cfg, name) */ @@ -619,109 +665,134 @@ PHP_FUNCTION(git_config_delete_entry) RETURN_TRUE; } -/* {{{ proto long git_config_delete_multivar(cfg, name, regexp) -*/ +/* {{{ proto long git_config_delete_multivar(resource $cfg, string $name, string $regexp) + */ PHP_FUNCTION(git_config_delete_multivar) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - char *regexp = {0}; - int regexp_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_delete_multivar not implemented yet"); - return; + int result = 0, name_len = 0, regexp_len = 0, error = 0; + zval *cfg = NULL; + php_git2_t *_cfg = NULL; + char *name = NULL, *regexp = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &cfg, &name, &name_len, ®exp, ®exp_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_config_delete_multivar(PHP_GIT2_V(_cfg, config), name, regexp); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_config_foreach(cfg, callback, payload) -*/ +/* {{{ proto long git_config_foreach(resource $cfg, $callback, $payload) + */ PHP_FUNCTION(git_config_foreach) { - zval *cfg; - php_git2_t *_cfg; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_foreach not implemented yet"); - return; + int result = 0, error = 0; + zval *cfg = NULL, *callback = NULL; + php_git2_t *_cfg = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb; + zval *payload = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &cfg, &callback, &payload) == FAILURE) { + "rfz", &cfg, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_config_foreach(PHP_GIT2_V(_cfg, config), php_git2_config_foreach_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_config_iterator_new(cfg) -*/ + +/* {{{ proto resource git_config_iterator_new(resource $cfg) + */ PHP_FUNCTION(git_config_iterator_new) { - zval *cfg; - php_git2_t *_cfg; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_iterator_new not implemented yet"); - return; + php_git2_t *result = NULL, *_cfg = NULL; + git_config_iterator *out = NULL; + zval *cfg = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &cfg) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_config_iterator_new(&out, PHP_GIT2_V(_cfg, config)); + if (php_git2_check_error(error, "git_config_iterator_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CONFIG_ITERATOR, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_config_iterator_glob_new(cfg, regexp) -*/ +/* {{{ proto resource git_config_iterator_glob_new(resource $cfg, string $regexp) + */ PHP_FUNCTION(git_config_iterator_glob_new) { - zval *cfg; - php_git2_t *_cfg; - char *regexp = {0}; - int regexp_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_iterator_glob_new not implemented yet"); - return; + php_git2_t *result = NULL, *_cfg = NULL; + git_config_iterator *out = NULL; + zval *cfg = NULL; + char *regexp = NULL; + int regexp_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &cfg, ®exp, ®exp_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_config_iterator_glob_new(&out, PHP_GIT2_V(_cfg, config), regexp); + if (php_git2_check_error(error, "git_config_iterator_glob_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CONFIG_ITERATOR, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto long git_config_foreach_match(cfg, regexp, callback, payload) -*/ +/* {{{ proto long git_config_foreach_match(resource $cfg, string $regexp, Callable $callback, $payload) + */ PHP_FUNCTION(git_config_foreach_match) { - zval *cfg; - php_git2_t *_cfg; - char *regexp = {0}; - int regexp_len; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_foreach_match not implemented yet"); - return; + int result = 0, regexp_len = 0, error = 0; + zval *cfg = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_cfg = NULL; + char *regexp = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsrz", &cfg, ®exp, ®exp_len, &callback, &payload) == FAILURE) { + "rsfz", &cfg, ®exp, ®exp_len, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_config_foreach_match(PHP_GIT2_V(_cfg, config), regexp, php_git2_config_foreach_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto resource git_config_get_mapped(cfg, name, maps, map_n) */ diff --git a/g_config.h b/g_config.h index d721a6a153..80313a7f21 100644 --- a/g_config.h +++ b/g_config.h @@ -163,7 +163,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_foreach, 0, 0, 3) ZEND_ARG_INFO(0, cfg) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_iterator_new, 0, 0, 2) @@ -179,7 +179,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_foreach_match, 0, 0, 4) ZEND_ARG_INFO(0, cfg) ZEND_ARG_INFO(0, regexp) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_mapped, 0, 0, 5) diff --git a/helper.c b/helper.c index d5bdc1cb0c..cd13cea3eb 100644 --- a/helper.c +++ b/helper.c @@ -137,122 +137,6 @@ void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC) *out = result; } -int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC) -{ - php_git2_t *result = NULL; - - PHP_GIT2_MAKE_RESOURCE_NOCHECK(result); - if (result == NULL) { - return 1; - } - - switch (type) { - case PHP_GIT2_TYPE_REPOSITORY: - PHP_GIT2_V(result, repository) = (git_repository*)resource; - break; - case PHP_GIT2_TYPE_COMMIT: - PHP_GIT2_V(result, commit) = (git_commit*)resource; - break; - case PHP_GIT2_TYPE_TREE: - PHP_GIT2_V(result, commit) = (git_tree*)resource; - break; - case PHP_GIT2_TYPE_TREE_ENTRY: - PHP_GIT2_V(result, tree_entry) = (git_tree_entry*)resource; - break; - case PHP_GIT2_TYPE_BLOB: - PHP_GIT2_V(result, blob) = (git_blob*)resource; - break; - case PHP_GIT2_TYPE_REVWALK: - PHP_GIT2_V(result, revwalk) = (git_revwalk*)resource; - break; - case PHP_GIT2_TYPE_TREEBUILDER: - PHP_GIT2_V(result, treebuilder) = (git_treebuilder*)resource; - break; - case PHP_GIT2_TYPE_REFERENCE: - PHP_GIT2_V(result, reference) = (git_reference*)resource; - break; - case PHP_GIT2_TYPE_REFERENCE_ITERATOR: - PHP_GIT2_V(result, reference_iterator) = (git_reference_iterator*)resource; - break; - case PHP_GIT2_TYPE_CONFIG: - PHP_GIT2_V(result, config) = (git_config*)resource; - break; - case PHP_GIT2_TYPE_OBJECT: - PHP_GIT2_V(result, object) = (git_object*)resource; - break; - case PHP_GIT2_TYPE_INDEX: - PHP_GIT2_V(result, index) = (git_index*)resource; - break; - case PHP_GIT2_TYPE_ODB: - PHP_GIT2_V(result, odb) = (git_odb*)resource; - break; - case PHP_GIT2_TYPE_REFDB: - PHP_GIT2_V(result, refdb) = (git_refdb*)resource; - break; - case PHP_GIT2_TYPE_STATUS_LIST: - PHP_GIT2_V(result, status_list) = (git_status_list*)resource; - break; - case PHP_GIT2_TYPE_BRANCH_ITERATOR: - PHP_GIT2_V(result, branch_iterator) = (git_branch_iterator*)resource; - break; - case PHP_GIT2_TYPE_TAG: - PHP_GIT2_V(result, tag) = (git_tag*)resource; - break; - case PHP_GIT2_TYPE_CRED: - PHP_GIT2_V(result, cred) = (git_cred*)resource; - break; - case PHP_GIT2_TYPE_TRANSPORT: - PHP_GIT2_V(result, transport) = (git_transport*)resource; - break; - case PHP_GIT2_TYPE_REMOTE: - PHP_GIT2_V(result, remote) = (git_remote*)resource; - break; - case PHP_GIT2_TYPE_DIFF: - PHP_GIT2_V(result, diff) = (git_diff*)resource; - break; - case PHP_GIT2_TYPE_MERGE_RESULT: - PHP_GIT2_V(result, merge_result) = (git_merge_result*)resource; - break; - case PHP_GIT2_TYPE_MERGE_HEAD: - PHP_GIT2_V(result, merge_head) = (git_merge_head*)resource; - break; - case PHP_GIT2_TYPE_PATHSPEC: - PHP_GIT2_V(result, pathspec) = (git_pathspec*)resource; - break; - case PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST: - PHP_GIT2_V(result, pathspec_match_list) = (git_pathspec_match_list*)resource; - break; - case PHP_GIT2_TYPE_PATCH: - PHP_GIT2_V(result, patch) = (git_patch*)resource; - break; - case PHP_GIT2_TYPE_DIFF_HUNK: - PHP_GIT2_V(result, diff_hunk) = (git_diff_hunk*)resource; - break; - case PHP_GIT2_TYPE_BUF: - PHP_GIT2_V(result, buf) = (git_buf*)resource; - break; - case PHP_GIT2_TYPE_FILTER_LIST: - PHP_GIT2_V(result, filter_list) = (git_filter_list*)resource; - break; - case PHP_GIT2_TYPE_FILTER_SOURCE: - PHP_GIT2_V(result, filter_source) = (git_filter_source*)resource; - break; - case PHP_GIT2_TYPE_DIFF_LINE: - PHP_GIT2_V(result, diff_line) = (git_diff_line*)resource; - break; - default: - php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); - } - - result->type = type; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = should_free; - - *out = result; - return 0; -} - - int php_git2_call_function_v( zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC, zval **retval_ptr_ptr, zend_uint param_count, ...) { diff --git a/helper.h b/helper.h index 10f7692d5d..66780942ab 100644 --- a/helper.h +++ b/helper.h @@ -42,8 +42,6 @@ void php_git2_signature_to_array(const git_signature *signature, zval **out TSRM void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC); -int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC); - int php_git2_call_function_v( zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC, zval **retval_ptr_ptr, zend_uint param_count, ...); diff --git a/ng.php b/ng.php index c35317924a..895c729ba2 100644 --- a/ng.php +++ b/ng.php @@ -84,6 +84,16 @@ public function isSavior() } } + public function isCallbacker() + { + foreach($this->args as $arg) { + if (preg_match("/_cb$/", $arg->getType())) { + return true; + } + } + return false; + } + public function getArguments() { return $this->args; @@ -137,6 +147,11 @@ public function getType() return $this->type; } + public function isCallback() + { + return preg_match("/_cb$/", $this->type); + } + public function getPtr() { return str_repeat("*", $this->ptr - 1); @@ -164,6 +179,8 @@ public function getZendType() return "char"; } else if (preg_match("/^git_/", $this->type)) { return "zval"; + } else if (preg_match("/payload/", $this->name)) { + return "zval"; } else { error_log(sprintf("%s (zendtype)", $this->type)); } @@ -360,6 +377,7 @@ public function shouldResource(Arg $arg) "git_filter_source", "git_diff_line", "git_reference_iterator", + "git_config_iterator", ); } @@ -425,6 +443,8 @@ public function generateProto(Printer $printer, Func $f) $printer->put("array"); } else if (preg_match("/(git_strarray)/", $arg->getType())) { $printer->put("array"); + } else if (preg_match("/_cb$/", $arg->getType())) { + $printer->put("Callable"); } else { error_log(sprintf("# unknown type (%s)", $arg->getType())); } @@ -551,6 +571,20 @@ public function generateDeclarations(Printer $printer, Func $f) "value" => "NULL", ); } + if ($f->isCallbacker()) { + $tables["zend_fcall_info"][] = array( + "name" => "fci", + "value" => "empty_fcall_info", + ); + $tables["zend_fcall_info_cache"][] = array( + "name" => "fcc", + "value" => "empty_fcall_info_cache", + ); + $tables["php_git2_cb_t"][] = array( + "name" => "*cb", + "value" => "NULL", + ); + } foreach ($tables as $type => $values) { @@ -594,6 +628,10 @@ public function generateParse(Printer $printer, Func $f) $printer->put("a"); } else if ($this->shouldResource($arg)) { $printer->put("r"); + } else if ($arg->isCallback()) { + $printer->put("f"); + } else if ($f->isCallbacker() && preg_match("/payload/", $arg->getName())) { + $printer->put("z"); } else { $printer->put("<{$arg->getType()}>"); } @@ -612,7 +650,12 @@ public function generateParse(Printer $printer, Func $f) continue; } - $printer->put("&`name`", "name", $arg->getName()); + if ($arg->isCallback()) { + $printer->put("&fci, "); + $printer->put("&fcc"); + } else { + $printer->put("&`name`", "name", $arg->getName()); + } if (preg_match("/char/", $arg->getZendType())) { $printer->put(", "); $printer->put("&`name`_len", "name", $arg->getName()); @@ -648,26 +691,45 @@ public function generateFetchResourceIfNeeded(Printer $printer, Func $f) } } - public function generateOidTranslation(Printer $printer, Func $f) - { - foreach ($f->getArguments() as $arg) { - /** @var Arg $arg */ - if ($arg->getType() == "git_oid") { - $printer->put("if (git_oid_fromstrn(&__`name`, `name`, `name`_len)) {\n", - "name", $arg->getName() - ); - $printer->block(function(Printer $printer) use($arg) { - $printer->put("RETURN_FALSE;\n"); - }); - $printer->put("}\n"); - $arg->setName("__" . $arg->getName()); - } + public function generateOidTranslation(Printer $printer, Func $f) + { + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($arg->getType() == "git_oid") { + $printer->put("if (git_oid_fromstrn(&__`name`, `name`, `name`_len)) {\n", + "name", $arg->getName() + ); + $printer->block(function(Printer $printer) use($arg) { + $printer->put("RETURN_FALSE;\n"); + }); + $printer->put("}\n"); + $arg->setName("__" . $arg->getName()); } } + } + + public function generateCallbackInit(Printer $printer, Func $f) + { + if ($f->isCallbacker()) { + $printer->put("if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {\n"); + $printer->block(function(Printer $printer) { + $printer->put("RETURN_FALSE;\n"); + }); + $printer->put("}\n"); + } + } + + public function generateCallbackFree(Printer $printer, Func $f) + { + if ($f->isCallbacker()) { + $printer->put("php_git2_cb_free(cb);\n"); + } + } public function generateFunctionCall(Printer $printer, Func $f) { $this->generateOidTranslation($printer, $f); + $this->generateCallbackInit($printer, $f); if ($f->getReturnType() == "int" && $f->isResourceCreator()) { $printer->put("error = `function`", "function", $f->getName() @@ -801,6 +863,10 @@ public function generateFunctionCall(Printer $printer, Func $f) ); } else if ($arg->shouldWrite()) { $printer->put("&`name`", "name", $arg->getName()); + } else if ($arg->isCallback()) { + $printer->put(""); + } else if (preg_match("/payload/", $arg->getName())) { + $printer->put("cb"); } else { $printer->put("`name`", "name", $arg->getName()); } @@ -812,6 +878,7 @@ public function generateFunctionCall(Printer $printer, Func $f) } $printer->put(");\n"); + $this->generateCallbackFree($printer, $f); if (preg_match("/_is_/", $f->getName())) { $printer->put("RETURN_BOOL(`name`);\n", "name", "result"); } else { diff --git a/php_git2.c b/php_git2.c index 1bb1e357be..3e64c791e9 100644 --- a/php_git2.c +++ b/php_git2.c @@ -106,6 +106,124 @@ static zend_class_entry *php_git2_get_exception_base(TSRMLS_D) #endif } +int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC) +{ + php_git2_t *result = NULL; + + PHP_GIT2_MAKE_RESOURCE_NOCHECK(result); + if (result == NULL) { + return 1; + } + + switch (type) { + case PHP_GIT2_TYPE_REPOSITORY: + PHP_GIT2_V(result, repository) = (git_repository*)resource; + break; + case PHP_GIT2_TYPE_COMMIT: + PHP_GIT2_V(result, commit) = (git_commit*)resource; + break; + case PHP_GIT2_TYPE_TREE: + PHP_GIT2_V(result, commit) = (git_tree*)resource; + break; + case PHP_GIT2_TYPE_TREE_ENTRY: + PHP_GIT2_V(result, tree_entry) = (git_tree_entry*)resource; + break; + case PHP_GIT2_TYPE_BLOB: + PHP_GIT2_V(result, blob) = (git_blob*)resource; + break; + case PHP_GIT2_TYPE_REVWALK: + PHP_GIT2_V(result, revwalk) = (git_revwalk*)resource; + break; + case PHP_GIT2_TYPE_TREEBUILDER: + PHP_GIT2_V(result, treebuilder) = (git_treebuilder*)resource; + break; + case PHP_GIT2_TYPE_REFERENCE: + PHP_GIT2_V(result, reference) = (git_reference*)resource; + break; + case PHP_GIT2_TYPE_REFERENCE_ITERATOR: + PHP_GIT2_V(result, reference_iterator) = (git_reference_iterator*)resource; + break; + case PHP_GIT2_TYPE_CONFIG: + PHP_GIT2_V(result, config) = (git_config*)resource; + break; + case PHP_GIT2_TYPE_CONFIG_ITERATOR: + PHP_GIT2_V(result, config_iterator) = (git_config_iterator*)resource; + break; + case PHP_GIT2_TYPE_OBJECT: + PHP_GIT2_V(result, object) = (git_object*)resource; + break; + case PHP_GIT2_TYPE_INDEX: + PHP_GIT2_V(result, index) = (git_index*)resource; + break; + case PHP_GIT2_TYPE_ODB: + PHP_GIT2_V(result, odb) = (git_odb*)resource; + break; + case PHP_GIT2_TYPE_REFDB: + PHP_GIT2_V(result, refdb) = (git_refdb*)resource; + break; + case PHP_GIT2_TYPE_STATUS_LIST: + PHP_GIT2_V(result, status_list) = (git_status_list*)resource; + break; + case PHP_GIT2_TYPE_BRANCH_ITERATOR: + PHP_GIT2_V(result, branch_iterator) = (git_branch_iterator*)resource; + break; + case PHP_GIT2_TYPE_TAG: + PHP_GIT2_V(result, tag) = (git_tag*)resource; + break; + case PHP_GIT2_TYPE_CRED: + PHP_GIT2_V(result, cred) = (git_cred*)resource; + break; + case PHP_GIT2_TYPE_TRANSPORT: + PHP_GIT2_V(result, transport) = (git_transport*)resource; + break; + case PHP_GIT2_TYPE_REMOTE: + PHP_GIT2_V(result, remote) = (git_remote*)resource; + break; + case PHP_GIT2_TYPE_DIFF: + PHP_GIT2_V(result, diff) = (git_diff*)resource; + break; + case PHP_GIT2_TYPE_MERGE_RESULT: + PHP_GIT2_V(result, merge_result) = (git_merge_result*)resource; + break; + case PHP_GIT2_TYPE_MERGE_HEAD: + PHP_GIT2_V(result, merge_head) = (git_merge_head*)resource; + break; + case PHP_GIT2_TYPE_PATHSPEC: + PHP_GIT2_V(result, pathspec) = (git_pathspec*)resource; + break; + case PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST: + PHP_GIT2_V(result, pathspec_match_list) = (git_pathspec_match_list*)resource; + break; + case PHP_GIT2_TYPE_PATCH: + PHP_GIT2_V(result, patch) = (git_patch*)resource; + break; + case PHP_GIT2_TYPE_DIFF_HUNK: + PHP_GIT2_V(result, diff_hunk) = (git_diff_hunk*)resource; + break; + case PHP_GIT2_TYPE_BUF: + PHP_GIT2_V(result, buf) = (git_buf*)resource; + break; + case PHP_GIT2_TYPE_FILTER_LIST: + PHP_GIT2_V(result, filter_list) = (git_filter_list*)resource; + break; + case PHP_GIT2_TYPE_FILTER_SOURCE: + PHP_GIT2_V(result, filter_source) = (git_filter_source*)resource; + break; + case PHP_GIT2_TYPE_DIFF_LINE: + PHP_GIT2_V(result, diff_line) = (git_diff_line*)resource; + break; + default: + php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); + } + + result->type = type; + result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); + result->should_free_v = should_free; + + *out = result; + return 0; +} + ZEND_BEGIN_ARG_INFO_EX(arginfo_git_resource_type, 0, 0, 1) ZEND_ARG_INFO(0, resource) ZEND_END_ARG_INFO() diff --git a/php_git2.h b/php_git2.h index 2c44ac6c2e..f69dfff64c 100644 --- a/php_git2.h +++ b/php_git2.h @@ -88,6 +88,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_REFERENCE, PHP_GIT2_TYPE_REFERENCE_ITERATOR, PHP_GIT2_TYPE_CONFIG, + PHP_GIT2_TYPE_CONFIG_ITERATOR, PHP_GIT2_TYPE_OBJECT, PHP_GIT2_TYPE_INDEX, PHP_GIT2_TYPE_ODB, @@ -124,6 +125,7 @@ typedef struct php_git2_t { git_reference *reference; git_reference_iterator *reference_iterator; git_config *config; + git_config_iterator *config_iterator; git_object *object; git_index *index; git_odb *odb; diff --git a/php_git2_priv.h b/php_git2_priv.h index db700c65ee..b489d02b10 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -78,6 +78,8 @@ typedef struct php_git2_cb_t { GIT2_TSRMLS_DECL } php_git2_cb_t; +int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC); + #include "helper.h" #endif \ No newline at end of file From ba610c629b29286262d5a640db19bdad207d6207 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 03:07:35 +0900 Subject: [PATCH 046/136] [index] add several callbacks --- helper.c | 33 +++++- helper.h | 4 + index.c | 334 +++++++++++++++++++++++++++++++++-------------------- ng.php | 40 ++++--- php_git2.c | 3 + php_git2.h | 2 + 6 files changed, 270 insertions(+), 146 deletions(-) diff --git a/helper.c b/helper.c index cd13cea3eb..3d8b44bf04 100644 --- a/helper.c +++ b/helper.c @@ -203,4 +203,35 @@ int php_git2_cb_init(php_git2_cb_t **out, zend_fcall_info *fci, zend_fcall_info_ void php_git2_cb_free(php_git2_cb_t *target) { efree(target); -} \ No newline at end of file +} + +void php_git2_array_to_strarray(git_strarray *out, zval *array TSRMLS_DC) +{ + int elements = 0, i; + HashPosition pos; + zval **value; + + elements = zend_hash_num_elements(Z_ARRVAL_P(array)); + out->strings = (char**)emalloc(sizeof(char*) * elements); + out->count = elements; + for (i = 0, zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos); + zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **)&value, &pos) == SUCCESS; + zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos), i++) { + char *buffer; + + Z_STRVAL_PP(value); + buffer = emalloc(sizeof(char*) * Z_STRLEN_PP(value) + 1); + memcpy(buffer, Z_STRVAL_PP(value), Z_STRLEN_PP(value)); + buffer[Z_STRLEN_PP(value)] = '\0'; + out->strings[i] = buffer; + } +} + +void php_git2_strarray_free(git_strarray *out) +{ + int i = 0; + for (i = 0; i < out->count; i++) { + efree(out->strings[i]); + } + efree(out->strings); +} diff --git a/helper.h b/helper.h index 66780942ab..7259571510 100644 --- a/helper.h +++ b/helper.h @@ -49,4 +49,8 @@ int php_git2_cb_init(php_git2_cb_t **out, zend_fcall_info *fci, zend_fcall_info_ void php_git2_cb_free(php_git2_cb_t *target); +void php_git2_array_to_strarray(git_strarray *out, zval *array TSRMLS_DC); + +void php_git2_strarray_free(git_strarray *out); + #endif \ No newline at end of file diff --git a/index.c b/index.c index f87e3b3f97..f7f4915ad0 100644 --- a/index.c +++ b/index.c @@ -2,6 +2,34 @@ #include "php_git2_priv.h" #include "index.h" +static int php_git2_index_matched_path_cb(const char *path, const char *matched_pathspec, void *payload) +{ + php_git2_t *result; + zval *param_path, *param_matched_pathspec, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_path); + MAKE_STD_ZVAL(param_matched_pathspec); + ZVAL_STRING(param_path, path, 1); + ZVAL_STRING(param_matched_pathspec, matched_pathspec, 1); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, ¶m_path, ¶m_matched_pathspec, &p->payload)) { + zval_ptr_dtor(¶m_path); + zval_ptr_dtor(¶m_matched_pathspec); + zval_ptr_dtor(&p->payload); + return 0; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + + static int php_git2_array_to_index_entry(git_index_entry *entry, zval *array TSRMLS_DC) { zval *ctime, *mtime, *oid; @@ -538,75 +566,96 @@ PHP_FUNCTION(git_index_remove_bypath) RETURN_TRUE; } -/* {{{ proto long git_index_add_all(index, pathspec, flags, callback, payload) -*/ +/* {{{ proto long git_index_add_all(resource $index, array $pathspec, long $flags, Callable $callback, $payload) + */ PHP_FUNCTION(git_index_add_all) { - zval *index; - php_git2_t *_index; - zval *pathspec; - php_git2_t *_pathspec; - long flags; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_add_all not implemented yet"); - return; + int result = 0, error = 0; + zval *index = NULL, *pathspec = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_index = NULL; + git_strarray _pathspec = {0}; + long flags = 0; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrlr", &index, &pathspec, &flags, &callback, &payload) == FAILURE) { + "ralfz", &index, &pathspec, &flags, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_strarray(&_pathspec, pathspec TSRMLS_CC); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_index_add_all(PHP_GIT2_V(_index, index), pathspec, flags, php_git2_index_matched_path_cb, cb); + php_git2_cb_free(cb); + php_git2_strarray_free(&_pathspec); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_index_remove_all(index, pathspec, callback, payload) -*/ + +/* {{{ proto long git_index_remove_all(resource $index, array $pathspec, Callable $callback, $payload) + */ PHP_FUNCTION(git_index_remove_all) { - zval *index; - php_git2_t *_index; - zval *pathspec; - php_git2_t *_pathspec; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_remove_all not implemented yet"); - return; + int result = 0, error = 0; + zval *index = NULL, *pathspec = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_index = NULL; + git_strarray _pathspec = {0}; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrr", &index, &pathspec, &callback, &payload) == FAILURE) { + "rafz", &index, &pathspec, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_strarray(&_pathspec, pathspec TSRMLS_CC); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_index_remove_all(PHP_GIT2_V(_index, index), pathspec, php_git2_index_matched_path_cb, cb); + php_git2_cb_free(cb); + php_git2_strarray_free(&_pathspec); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_index_update_all(index, pathspec, callback, payload) -*/ + +/* {{{ proto long git_index_update_all(resource $index, array $pathspec, Callable $callback, $payload) + */ PHP_FUNCTION(git_index_update_all) { - zval *index; - php_git2_t *_index; - zval *pathspec; - php_git2_t *_pathspec; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_update_all not implemented yet"); - return; + int result = 0, error = 0; + zval *index = NULL, *pathspec = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_index = NULL; + git_strarray _pathspec = {0}; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrr", &index, &pathspec, &callback, &payload) == FAILURE) { + "rafz", &index, &pathspec, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_strarray(&_pathspec, pathspec TSRMLS_CC); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_index_update_all(PHP_GIT2_V(_index, index), pathspec, php_git2_index_matched_path_cb, cb); + php_git2_cb_free(cb); + php_git2_strarray_free(&_pathspec); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_index_find(at_pos, index, path) */ @@ -628,87 +677,99 @@ PHP_FUNCTION(git_index_find) RETURN_LONG(result); } -/* {{{ proto long git_index_conflict_add(index, ancestor_entry, our_entry, their_entry) -*/ +/* {{{ proto long git_index_conflict_add(resource $index, $ancestor_entry, $our_entry, $their_entry) + */ PHP_FUNCTION(git_index_conflict_add) { -// zval *index; -// php_git2_t *_index; -// zval *ancestor_entry; -// php_git2_t *_ancestor_entry; -// zval *our_entry; -// php_git2_t *_our_entry; -// zval *their_entry; -// php_git2_t *_their_entry; -// -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rrrr", &index, &ancestor_entry, &our_entry, &their_entry) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -} - -/* {{{ proto resource git_index_conflict_get(our_out, their_out, index, path) -*/ + int result = 0, error = 0; + zval *index = NULL, *ancestor_entry = NULL, *our_entry = NULL, *their_entry = NULL; + php_git2_t *_index = NULL; + git_index_entry ancestor = {0}, our = {0}, their = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "raaa", &index, &ancestor_entry, &our_entry, &their_entry) == FAILURE) { + return; + } + + php_git2_array_to_index_entry(&ancestor, ancestor_entry TSRMLS_CC); + php_git2_array_to_index_entry(&our, our_entry TSRMLS_CC); + php_git2_array_to_index_entry(&their, their_entry TSRMLS_CC); + + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_index_conflict_add(PHP_GIT2_V(_index, index), &ancestor, &our, &their); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_index_conflict_get(resource $index, string $path) + */ PHP_FUNCTION(git_index_conflict_get) { - zval *our_out; - php_git2_t *_our_out; - zval *their_out; - php_git2_t *_their_out; - zval *index; - php_git2_t *_index; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_get not implemented yet"); - return; + php_git2_t *result = NULL, *_index = NULL; + git_index_entry *ancestor_out = NULL, *our_out = NULL, *their_out = NULL; + zval *index = NULL, *ancestor, *our, *their, *container; + char *path = NULL; + int path_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrrs", &our_out, &their_out, &index, &path, &path_len) == FAILURE) { + "rs", &index, &path, &path_len) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_our_out, php_git2_t*, &our_out, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_conflict_get(&ancestor_out, &our_out, &their_out, PHP_GIT2_V(_index, index), path); + if (php_git2_check_error(error, "git_index_conflict_get" TSRMLS_CC)) { + RETURN_FALSE; + } + + php_git2_index_entry_to_array(ancestor_out, &ancestor TSRMLS_CC); + php_git2_index_entry_to_array(our_out, &our TSRMLS_CC); + php_git2_index_entry_to_array(their_out, &their TSRMLS_CC); + MAKE_STD_ZVAL(container); + array_init(container); + add_next_index_zval(container, ancestor); + add_next_index_zval(container, our); + add_next_index_zval(container, their); + RETURN_ZVAL(container, 0, 1); } +/* }}} */ -/* {{{ proto long git_index_conflict_remove(index, path) -*/ +/* {{{ proto long git_index_conflict_remove(resource $index, string $path) + */ PHP_FUNCTION(git_index_conflict_remove) { - zval *index; - php_git2_t *_index; - char *path = {0}; - int path_len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_remove not implemented yet"); - return; + int result = 0, path_len = 0, error = 0; + zval *index = NULL; + php_git2_t *_index = NULL; + char *path = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &index, &path, &path_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_index_conflict_remove(PHP_GIT2_V(_index, index), path); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto void git_index_conflict_cleanup(index) -*/ +/* {{{ proto void git_index_conflict_cleanup(resource $index) + */ PHP_FUNCTION(git_index_conflict_cleanup) { - zval *index; - php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_cleanup not implemented yet"); - return; + zval *index = NULL; + php_git2_t *_index = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_index_conflict_cleanup(PHP_GIT2_V(_index, index)); } +/* }}} */ /* {{{ proto long git_index_has_conflicts(index) */ @@ -727,61 +788,82 @@ PHP_FUNCTION(git_index_has_conflicts) RETURN_LONG(conflict); } -/* {{{ proto resource git_index_conflict_iterator_new(index) -*/ +/* {{{ proto resource git_index_conflict_iterator_new(resource $index) + */ PHP_FUNCTION(git_index_conflict_iterator_new) { - zval *index; - php_git2_t *_index; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_iterator_new not implemented yet"); - return; + php_git2_t *result = NULL, *_index = NULL; + git_index_conflict_iterator *iterator_out = NULL; + zval *index = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &index) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_conflict_iterator_new(&iterator_out, PHP_GIT2_V(_index, index)); + if (php_git2_check_error(error, "git_index_conflict_iterator_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR, iterator_out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_index_conflict_next(our_out, their_out, iterator) -*/ +/* {{{ proto resource git_index_conflict_next(resource $iterator) + */ PHP_FUNCTION(git_index_conflict_next) { - zval *our_out; - php_git2_t *_our_out; - zval *their_out; - php_git2_t *_their_out; - zval *iterator; - php_git2_t *_iterator; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_next not implemented yet"); - return; + php_git2_t *result = NULL, *_iterator = NULL; + git_index_entry *ancestor_out = NULL, *our_out = NULL, *their_out = NULL; + zval *iterator = NULL, *ancestor, *our, *their, *container; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrr", &our_out, &their_out, &iterator) == FAILURE) { + "r", &iterator) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_our_out, php_git2_t*, &our_out, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + + ZEND_FETCH_RESOURCE(_iterator, php_git2_t*, &iterator, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_index_conflict_next(&ancestor_out, &our_out, &their_out, PHP_GIT2_V(_iterator, index_conflict_iterator)); + if (php_git2_check_error(error, "git_index_conflict_next" TSRMLS_CC)) { + RETURN_FALSE; + } + + php_git2_index_entry_to_array(ancestor_out, &ancestor TSRMLS_CC); + php_git2_index_entry_to_array(our_out, &our TSRMLS_CC); + php_git2_index_entry_to_array(their_out, &their TSRMLS_CC); + MAKE_STD_ZVAL(container); + array_init(container); + add_next_index_zval(container, ancestor); + add_next_index_zval(container, our); + add_next_index_zval(container, their); + RETURN_ZVAL(container, 0, 1); + } +/* }}} */ -/* {{{ proto void git_index_conflict_iterator_free(iterator) -*/ +/* {{{ proto void git_index_conflict_iterator_free(resource $iterator) + */ PHP_FUNCTION(git_index_conflict_iterator_free) { - zval *iterator; - php_git2_t *_iterator; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_index_conflict_iterator_free not implemented yet"); - return; + zval *iterator = NULL; + php_git2_t *_iterator = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &iterator) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_iterator, php_git2_t*, &iterator, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_iterator)) { + git_index_conflict_iterator_free(PHP_GIT2_V(_iterator, index_conflict_iterator)); + GIT2_SHOULD_FREE(_iterator) = 0; + }; + zval_ptr_dtor(&iterator); } - +/* }}} */ diff --git a/ng.php b/ng.php index 895c729ba2..fdfeb8fb80 100644 --- a/ng.php +++ b/ng.php @@ -322,25 +322,6 @@ public function put($message/* $args */) } class Fashion { -/* - {{{ proto resource git_revparse_single(repo, spec) - PHP_FUNCTION(git_revparse_single) - { - zval *repo; - php_git2_t *_repo; - char *spec = {0}; - int spec_len; - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_revparse_single not implemented yet"); - return; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &repo, &spec, &spec_len) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - } - */ public function shouldResource(Arg $arg) { static $types; @@ -378,6 +359,7 @@ public function shouldResource(Arg $arg) "git_diff_line", "git_reference_iterator", "git_config_iterator", + "git_index_conflict_iterator", ); } @@ -535,6 +517,12 @@ public function generateDeclarations(Printer $printer, Func $f) "value" => "NULL", ); } + if ($arg->getType() == "git_strarray") { + $tables["git_strarray"][] = array( + "name" => sprintf("_%s", $arg->getName()), + "value" => "{0}", + ); + } if (preg_match("/char/", $arg->getZendType())) { $tables["int"][] = array( @@ -626,6 +614,8 @@ public function generateParse(Printer $printer, Func $f) $printer->put("l"); } else if (preg_match("/git_signature/", $arg->getType())) { $printer->put("a"); + } else if (preg_match("/git_strarray/", $arg->getType())) { + $printer->put("a"); } else if ($this->shouldResource($arg)) { $printer->put("r"); } else if ($arg->isCallback()) { @@ -1019,6 +1009,17 @@ public function generateMakeResourceIfNeeded(Printer $printer, Func $f, $name = } } + public function generateStrarrayConversion(Printer $printer, Func $f) + { + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + if ($arg->getType() == "git_strarray") { + $printer->put("php_git2_array_to_strarray(&_`name`, `name` TSRMLS_CC);\n", + "name", $arg->getName()); + } + } + } + public function out(Func $f) { $stream = new StringStream(); @@ -1036,6 +1037,7 @@ public function out(Func $f) $printer->put("\n"); $this->generateFetchResourceIfNeeded($printer, $f); + $this->generateStrarrayConversion($printer, $f); $this->generateFunctionCall($printer, $f); $this->generateCheckStatementIfNeeded($printer, $f); $this->generateMakeResourceIfNeeded($printer, $f); diff --git a/php_git2.c b/php_git2.c index 3e64c791e9..0c382181e4 100644 --- a/php_git2.c +++ b/php_git2.c @@ -212,6 +212,9 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v case PHP_GIT2_TYPE_DIFF_LINE: PHP_GIT2_V(result, diff_line) = (git_diff_line*)resource; break; + case PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR: + PHP_GIT2_V(result, index_conflict_iterator) = (git_index_conflict_iterator*)resource; + break; default: php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } diff --git a/php_git2.h b/php_git2.h index f69dfff64c..9c02afd84c 100644 --- a/php_git2.h +++ b/php_git2.h @@ -110,6 +110,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_FILTER_LIST, PHP_GIT2_TYPE_FILTER_SOURCE, PHP_GIT2_TYPE_DIFF_LINE, + PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR, }; typedef struct php_git2_t { @@ -147,6 +148,7 @@ typedef struct php_git2_t { git_filter_list *filter_list; git_filter_source *filter_source; git_diff_line *diff_line; + git_index_conflict_iterator *index_conflict_iterator; } v; int should_free_v; int resource_id; From ed1e8cff46320871809a7ca62cb60e35ad100d16 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 03:32:17 +0900 Subject: [PATCH 047/136] [repository] add callback --- repository.c | 126 +++++++++++++++++++++++++++++++++++++++++---------- repository.h | 4 +- 2 files changed, 103 insertions(+), 27 deletions(-) diff --git a/repository.c b/repository.c index c60c532e7e..74310f97c1 100644 --- a/repository.c +++ b/repository.c @@ -2,6 +2,72 @@ #include "php_git2_priv.h" #include "repository.h" +static int php_git2_repository_fetchhead_foreach_cb(const char *ref_name, + const char *remote_url, + const git_oid *oid, + unsigned int is_merge, + void *payload) +{ + php_git2_t *result; + zval *param_ref_name, *param_remote_url, *param_oid, *param_is_merge, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + char _oid[41] = {0}; + GIT2_TSRMLS_SET(p->tsrm_ls) + + git_oid_fmt(_oid, oid); + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_ref_name); + MAKE_STD_ZVAL(param_remote_url); + MAKE_STD_ZVAL(param_oid); + MAKE_STD_ZVAL(param_is_merge); + ZVAL_STRING(param_ref_name, ref_name, 1); + ZVAL_STRING(param_remote_url, remote_url, 1); + ZVAL_STRING(param_oid, _oid, 1); + ZVAL_BOOL(param_is_merge, is_merge); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 5, + ¶m_ref_name, + ¶m_remote_url, + ¶m_oid, + ¶m_is_merge, + &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + +static int php_git2_repository_mergehead_foreach_cb(const git_oid *oid, + void *payload) +{ + php_git2_t *result; + zval *param_oid, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + char _oid[41] = {0}; + GIT2_TSRMLS_SET(p->tsrm_ls) + + git_oid_fmt(_oid, oid); + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_oid); + ZVAL_STRING(param_oid, _oid, 1); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_oid, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + /* {{{ proto resource git_repository_new() */ PHP_FUNCTION(git_repository_new) @@ -601,48 +667,58 @@ PHP_FUNCTION(git_repository_merge_cleanup) } /* }}} */ - -/* {{{ proto long git_repository_fetchhead_foreach(repo, callback, payload) -*/ +/* {{{ proto long git_repository_fetchhead_foreach(resource $repo, Callable $callback, $payload) + */ PHP_FUNCTION(git_repository_fetchhead_foreach) { - zval *repo; - php_git2_t *_repo; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_fetchhead_foreach not implemented yet"); - return; + int result = 0, error = 0; + zval *repo = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &repo, &callback, &payload) == FAILURE) { + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_repository_fetchhead_foreach(PHP_GIT2_V(_repo, repository), php_git2_repository_fetchhead_foreach_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_repository_mergehead_foreach(repo, callback, payload) -*/ +/* {{{ proto long git_repository_mergehead_foreach(resource $repo, Callable $callback, $payload) + */ PHP_FUNCTION(git_repository_mergehead_foreach) { - zval *repo; - php_git2_t *_repo; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_mergehead_foreach not implemented yet"); - return; + int result = 0, error = 0; + zval *repo = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &repo, &callback, &payload) == FAILURE) { + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_repository_mergehead_foreach(PHP_GIT2_V(_repo, repository), php_git2_repository_mergehead_foreach_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto resource git_repository_hashfile(repo, path, type, as_path) */ diff --git a/repository.h b/repository.h index ace9aae604..9d0ce642a0 100644 --- a/repository.h +++ b/repository.h @@ -138,13 +138,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_fetchhead_foreach, 0, 0, 3) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_mergehead_foreach, 0, 0, 3) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_repository_hashfile, 0, 0, 4) From 23167831263cfe8b937d7bc1ee16dcfd566c9253 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 03:50:08 +0900 Subject: [PATCH 048/136] [remote, transport] improve several functions --- ng.php | 2 + php_git2.c | 2 + php_git2.h | 2 + remote.c | 132 ++++++++++++------------------ transport.c | 228 +++++++++++++++++++++++++++++++++++----------------- 5 files changed, 213 insertions(+), 153 deletions(-) diff --git a/ng.php b/ng.php index fdfeb8fb80..175df4078e 100644 --- a/ng.php +++ b/ng.php @@ -360,6 +360,8 @@ public function shouldResource(Arg $arg) "git_reference_iterator", "git_config_iterator", "git_index_conflict_iterator", + "git_transport*", + "git_transport" ); } diff --git a/php_git2.c b/php_git2.c index 0c382181e4..27d7d751f4 100644 --- a/php_git2.c +++ b/php_git2.c @@ -215,6 +215,8 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v case PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR: PHP_GIT2_V(result, index_conflict_iterator) = (git_index_conflict_iterator*)resource; break; + case PHP_GIT2_TYPE_SMART_SUBTRANSPORT: + PHP_GIT2_V(result, smart_subtransport) = (git_smart_subtransport*)resource; default: php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } diff --git a/php_git2.h b/php_git2.h index 9c02afd84c..5d69268c91 100644 --- a/php_git2.h +++ b/php_git2.h @@ -111,6 +111,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_FILTER_SOURCE, PHP_GIT2_TYPE_DIFF_LINE, PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR, + PHP_GIT2_TYPE_SMART_SUBTRANSPORT, }; typedef struct php_git2_t { @@ -149,6 +150,7 @@ typedef struct php_git2_t { git_filter_source *filter_source; git_diff_line *diff_line; git_index_conflict_iterator *index_conflict_iterator; + git_smart_subtransport *smart_subtransport; } v; int should_free_v; int resource_id; diff --git a/remote.c b/remote.c index e03bcd5d58..fec0680d60 100644 --- a/remote.c +++ b/remote.c @@ -6,15 +6,11 @@ */ PHP_FUNCTION(git_remote_create) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_remote *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; - char *name = NULL; - int name_len = 0; - char *url = NULL; - int url_len = 0; - int error = 0; + char *name = NULL, *url = NULL; + int name_len = 0, url_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &repo, &name, &name_len, &url, &url_len) == FAILURE) { @@ -26,12 +22,10 @@ PHP_FUNCTION(git_remote_create) if (php_git2_check_error(error, "git_remote_create" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, remote) = out; - result->type = PHP_GIT2_TYPE_REMOTE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -40,17 +34,11 @@ PHP_FUNCTION(git_remote_create) */ PHP_FUNCTION(git_remote_create_with_fetchspec) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_remote *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; - char *name = NULL; - int name_len = 0; - char *url = NULL; - int url_len = 0; - char *fetch = NULL; - int fetch_len = 0; - int error = 0; + char *name = NULL, *url = NULL, *fetch = NULL; + int name_len = 0, url_len = 0, fetch_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &repo, &name, &name_len, &url, &url_len, &fetch, &fetch_len) == FAILURE) { @@ -62,29 +50,24 @@ PHP_FUNCTION(git_remote_create_with_fetchspec) if (php_git2_check_error(error, "git_remote_create_with_fetchspec" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, remote) = out; - result->type = PHP_GIT2_TYPE_REMOTE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto resource git_remote_create_inmemory(resource $repo, string $fetch, string $url) */ PHP_FUNCTION(git_remote_create_inmemory) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_remote *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; - char *fetch = NULL; - int fetch_len = 0; - char *url = NULL; - int url_len = 0; - int error = 0; + char *fetch = NULL, *url = NULL; + int fetch_len = 0, url_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &repo, &fetch, &fetch_len, &url, &url_len) == FAILURE) { @@ -96,12 +79,10 @@ PHP_FUNCTION(git_remote_create_inmemory) if (php_git2_check_error(error, "git_remote_create_inmemory" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, remote) = out; - result->type = PHP_GIT2_TYPE_REMOTE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -109,13 +90,11 @@ PHP_FUNCTION(git_remote_create_inmemory) */ PHP_FUNCTION(git_remote_load) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_remote *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; char *name = NULL; - int name_len = 0; - int error = 0; + int name_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &name, &name_len) == FAILURE) { @@ -127,15 +106,14 @@ PHP_FUNCTION(git_remote_load) if (php_git2_check_error(error, "git_remote_load" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, remote) = out; - result->type = PHP_GIT2_TYPE_REMOTE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REMOTE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto long git_remote_save(resource $remote) */ PHP_FUNCTION(git_remote_save) @@ -156,15 +134,13 @@ PHP_FUNCTION(git_remote_save) } /* }}} */ - /* {{{ proto resource git_remote_owner(resource $remote) */ PHP_FUNCTION(git_remote_owner) { git_repository *result = NULL; zval *remote = NULL; - php_git2_t *_remote = NULL; - php_git2_t *__result = NULL; + php_git2_t *_remote = NULL, *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { @@ -173,12 +149,10 @@ PHP_FUNCTION(git_remote_owner) ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_remote_owner(PHP_GIT2_V(_remote, remote)); - PHP_GIT2_MAKE_RESOURCE(__result); - PHP_GIT2_V(__result, remote) = remote; - __result->type = PHP_GIT2_TYPE_REPOSITORY; - __result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - __result->should_free_v = 0; - ZVAL_RESOURCE(return_value, __result->resource_id); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_REMOTE, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); } /* }}} */ @@ -820,43 +794,43 @@ PHP_FUNCTION(git_remote_stats) /* }}} */ -/* {{{ proto resource git_remote_autotag(remote) -*/ +/* {{{ proto resource git_remote_autotag(resource $remote) + */ PHP_FUNCTION(git_remote_autotag) { - zval *remote; - php_git2_t *_remote; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_autotag not implemented yet"); - return; + git_remote_autotag_option_t *result = NULL; + zval *remote = NULL; + php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_remote_autotag(PHP_GIT2_V(_remote, remote)); + /* TODO(chobie): implement this */ } +/* }}} */ -/* {{{ proto void git_remote_set_autotag(remote, value) -*/ +/* {{{ proto void git_remote_set_autotag(resource $remote, $value) + */ PHP_FUNCTION(git_remote_set_autotag) { - zval *remote; - php_git2_t *_remote; - zval *value; - php_git2_t *_value; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_autotag not implemented yet"); - return; + zval *remote = NULL, *value = NULL; + php_git2_t *_remote = NULL; + /* TODO(chobie):impelement this */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &remote, &value) == FAILURE) { + "r", &remote, &value) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_remote_set_autotag(PHP_GIT2_V(_remote, remote), value); } +/* }}} */ + /* {{{ proto long git_remote_rename(remote, new_name, callback, payload) */ diff --git a/transport.c b/transport.c index cf95c246c8..e98f17f7c3 100644 --- a/transport.c +++ b/transport.c @@ -33,78 +33,134 @@ PHP_FUNCTION(git_transport_new) } /* }}} */ -/* {{{ proto long git_transport_register(prefix, priority, cb, param) -*/ -PHP_FUNCTION(git_transport_register) +//typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param); +static int php_git2_transport_cb(git_transport **out, git_remote *owner, void *param) { - char *prefix = {0}; - int prefix_len; - zval *cb; - php_git2_t *_cb; + php_git2_t *result; + zval *param_owner, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)param; + php_git2_t *_param_owner; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_owner); + if (php_git2_make_resource(&_param_owner, PHP_GIT2_TYPE_REMOTE, owner, 0 TSRMLS_CC)) { + return 0; + } + ZVAL_RESOURCE(param_owner, GIT_RVAL_P(_param_owner)); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_owner, &p->payload)) { + return GIT_EUSER; + } /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_register not implemented yet"); - return; -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "sr", &prefix, &prefix_len, &priority, &cb, ¶m) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_prefix, php_git2_t*, &prefix, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; } -/* {{{ proto long git_transport_unregister(prefix, priority) -*/ +/* {{{ proto long git_transport_register(string $prefix, $priority, Callable $cb, $param) + */ +PHP_FUNCTION(git_transport_register) +{ + int result = 0, prefix_len = 0, error = 0; + char *prefix = NULL; + long priority = NULL; + zval *param = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "slfz", &prefix, &prefix_len, &priority, &fci, &fcc, ¶m) == FAILURE) { + return; + } + + if (php_git2_cb_init(&cb, &fci, &fcc, param TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_transport_register(prefix, priority, php_git2_transport_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + + +/* {{{ proto long git_transport_unregister(string $prefix, $priority) + */ PHP_FUNCTION(git_transport_unregister) { - char *prefix = {0}; - int prefix_len; + int result = 0, prefix_len = 0, error = 0; + char *prefix = NULL; + long priority = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_unregister not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sl", &prefix, &prefix_len, &priority) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "s", &prefix, &prefix_len, &priority) == FAILURE) { -// return; -// } + result = git_transport_unregister(prefix, priority); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_transport_dummy(owner, payload) -*/ + +/* {{{ proto resource git_transport_dummy(resource $owner) + */ PHP_FUNCTION(git_transport_dummy) { - zval *owner; - php_git2_t *_owner; + php_git2_t *result = NULL, *_owner = NULL; + git_transport *out = NULL; + zval *owner = NULL; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_dummy not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &owner) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &owner, &payload) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_transport_dummy(&out, PHP_GIT2_V(_owner, remote), NULL); + if (php_git2_check_error(error, "git_transport_dummy" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TRANSPORT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_transport_local(owner, payload) -*/ + +/* {{{ proto resource git_transport_local(resource $owner) + */ PHP_FUNCTION(git_transport_local) { - zval *owner; - php_git2_t *_owner; + php_git2_t *result = NULL, *_owner = NULL; + git_transport *out = NULL; + zval *owner = NULL; + int error = 0; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_local not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &owner) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &owner, &payload) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_transport_local(&out, PHP_GIT2_V(_owner, remote), NULL); + if (php_git2_check_error(error, "git_transport_local" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TRANSPORT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ + /* {{{ proto resource git_transport_smart(owner, payload) */ @@ -126,57 +182,81 @@ PHP_FUNCTION(git_transport_smart) ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); } -/* {{{ proto resource git_smart_subtransport_http(owner) -*/ +/* {{{ proto resource git_smart_subtransport_http(resource $owner) + */ PHP_FUNCTION(git_smart_subtransport_http) { - zval *owner; - php_git2_t *_owner; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_smart_subtransport_http not implemented yet"); - return; + php_git2_t *result = NULL, *_owner = NULL; + git_smart_subtransport *out = NULL; + zval *owner = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &owner) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_smart_subtransport_http(&out, PHP_GIT2_V(_owner, transport)); + if (php_git2_check_error(error, "git_smart_subtransport_http" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_SMART_SUBTRANSPORT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_smart_subtransport_git(owner) -*/ + +/* {{{ proto resource git_smart_subtransport_git(resource $owner) + */ PHP_FUNCTION(git_smart_subtransport_git) { - zval *owner; - php_git2_t *_owner; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_smart_subtransport_git not implemented yet"); - return; + php_git2_t *result = NULL, *_owner = NULL; + git_smart_subtransport *out = NULL; + zval *owner = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &owner) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_smart_subtransport_git(&out, PHP_GIT2_V(_owner, transport)); + if (php_git2_check_error(error, "git_smart_subtransport_git" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_SMART_SUBTRANSPORT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_smart_subtransport_ssh(owner) -*/ +/* {{{ proto resource git_smart_subtransport_ssh(resource $owner) + */ PHP_FUNCTION(git_smart_subtransport_ssh) { - zval *owner; - php_git2_t *_owner; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_smart_subtransport_ssh not implemented yet"); - return; + php_git2_t *result = NULL, *_owner = NULL; + git_smart_subtransport *out = NULL; + zval *owner = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &owner) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_smart_subtransport_ssh(&out, PHP_GIT2_V(_owner, transport)); + if (php_git2_check_error(error, "git_smart_subtransport_ssh" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_SMART_SUBTRANSPORT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } - +/* }}} */ From dded5baae7c530cb328e5fba61b09f1b4f766eb9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 04:29:47 +0900 Subject: [PATCH 049/136] add stub code for odb and note --- config.m4 | 2 +- ng.php | 24 +- note.c | 268 ++++++++++++++++++++ note.h | 135 ++++++++++ odb.c | 708 +++++++++++++++++++++++++++++++++++++++++++++++++++++ odb.h | 296 ++++++++++++++++++++++ php_git2.c | 54 ++++ php_git2.h | 12 + 8 files changed, 1495 insertions(+), 4 deletions(-) create mode 100644 note.c create mode 100644 note.h create mode 100644 odb.c create mode 100644 odb.h diff --git a/config.m4 b/config.m4 index 4d7b0f7e2d..430d070cb9 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/ng.php b/ng.php index 175df4078e..17cc02915a 100644 --- a/ng.php +++ b/ng.php @@ -90,7 +90,11 @@ public function isCallbacker() if (preg_match("/_cb$/", $arg->getType())) { return true; } + if (preg_match("/callback$/", $arg->getType())) { + return true; + } } + return false; } @@ -361,7 +365,14 @@ public function shouldResource(Arg $arg) "git_config_iterator", "git_index_conflict_iterator", "git_transport*", - "git_transport" + "git_transport", + "git_note", + "git_note_iterator", + "git_odb", + "git_odb_object", + "git_odb_backend", + "git_odb_stream", + "struct git_odb", ); } @@ -1073,6 +1084,13 @@ public function out(Func $f) } } -$printer = new Fashion(); -echo $printer->out($table[$_SERVER['argv'][2]]); +if (isset($_SERVER['argv'][2])) { + $printer = new Fashion(); + echo $printer->out($table[$_SERVER['argv'][2]]); +} else { + foreach ($table as $name => $func) { + $printer = new Fashion(); + echo $printer->out($func); + } +} diff --git a/note.c b/note.c new file mode 100644 index 0000000000..f79b9d5d2a --- /dev/null +++ b/note.c @@ -0,0 +1,268 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "note.h" + +/* {{{ proto resource git_note_iterator_new(resource $repo, string $notes_ref) + */ +PHP_FUNCTION(git_note_iterator_new) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_note_iterator *out = NULL; + zval *repo = NULL; + char *notes_ref = NULL; + int notes_ref_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, ¬es_ref, ¬es_ref_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_note_iterator_new(&out, PHP_GIT2_V(_repo, repository), notes_ref); + if (php_git2_check_error(error, "git_note_iterator_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_NOTE_ITERATOR, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto void git_note_iterator_free(resource $it) + */ +PHP_FUNCTION(git_note_iterator_free) +{ + zval *it = NULL; + php_git2_t *_it = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &it) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_it, php_git2_t*, &it, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_it)) { + git_note_iterator_free(PHP_GIT2_V(_it, note_iterator)); + GIT2_SHOULD_FREE(_it) = 0; + }; + zval_ptr_dtor(&it); +} +/* }}} */ + +/* {{{ proto long git_note_next(string $note_id, string $annotated_id, resource $it) + */ +PHP_FUNCTION(git_note_next) +{ + int result = 0, note_id_len = 0, annotated_id_len = 0, error = 0; + char *note_id = NULL, *annotated_id = NULL; + zval *it = NULL; + php_git2_t *_it = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ssr", ¬e_id, ¬e_id_len, &annotated_id, &annotated_id_len, &it) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_it, php_git2_t*, &it, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_note_next(note_id, annotated_id, PHP_GIT2_V(_it, note_iterator)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_note_read(resource $repo, string $notes_ref, string $oid) + */ +PHP_FUNCTION(git_note_read) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_note *out = NULL; + zval *repo = NULL; + char *notes_ref = NULL, *oid = NULL; + int notes_ref_len = 0, oid_len = 0, error = 0; + git_oid __oid = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &repo, ¬es_ref, ¬es_ref_len, &oid, &oid_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__oid, oid, oid_len)) { + RETURN_FALSE; + } + error = git_note_read(&out, PHP_GIT2_V(_repo, repository), notes_ref, &__oid); + if (php_git2_check_error(error, "git_note_read" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_NOTE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto string git_note_message(resource $note) + */ +PHP_FUNCTION(git_note_message) +{ + const char *result = NULL; + zval *note = NULL; + php_git2_t *_note = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", ¬e) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_note, php_git2_t*, ¬e, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_note_message(PHP_GIT2_V(_note, note)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto resource git_note_oid(resource $note) + */ +PHP_FUNCTION(git_note_oid) +{ + const git_oid *result = NULL; + zval *note = NULL; + php_git2_t *_note = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", ¬e) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_note, php_git2_t*, ¬e, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_note_oid(PHP_GIT2_V(_note, note)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto resource git_note_create(resource $repo, array $author, array $committer, string $notes_ref, string $oid, string $note, long $force) + */ +PHP_FUNCTION(git_note_create) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_oid out = {0}, __oid = {0}; + zval *repo = NULL, *author = NULL, *committer = NULL; + char *notes_ref = NULL, *oid = NULL, *note = NULL; + int notes_ref_len = 0, oid_len = 0, note_len = 0, error = 0; + long force = 0; + char buf[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "raasssl", &repo, &author, &committer, ¬es_ref, ¬es_ref_len, &oid, &oid_len, ¬e, ¬e_len, &force) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__oid, oid, oid_len)) { + RETURN_FALSE; + } + error = git_note_create(&out, PHP_GIT2_V(_repo, repository), author, committer, notes_ref, &__oid, note, force); + if (php_git2_check_error(error, "git_note_create" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(buf, &out); + RETURN_STRING(buf, 1); +} +/* }}} */ + +/* {{{ proto long git_note_remove(resource $repo, string $notes_ref, array $author, array $committer, string $oid) + */ +PHP_FUNCTION(git_note_remove) +{ + int result = 0, notes_ref_len = 0, oid_len = 0, error = 0; + zval *repo = NULL, *author = NULL, *committer = NULL; + php_git2_t *_repo = NULL; + char *notes_ref = NULL, *oid = NULL; + git_oid __oid = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsaas", &repo, ¬es_ref, ¬es_ref_len, &author, &committer, &oid, &oid_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__oid, oid, oid_len)) { + RETURN_FALSE; + } + result = git_note_remove(PHP_GIT2_V(_repo, repository), notes_ref, author, committer, &__oid); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto void git_note_free(resource $note) + */ +PHP_FUNCTION(git_note_free) +{ + zval *note = NULL; + php_git2_t *_note = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", ¬e) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_note, php_git2_t*, ¬e, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_note)) { + git_note_free(PHP_GIT2_V(_note, note)); + GIT2_SHOULD_FREE(_note) = 0; + }; + zval_ptr_dtor(¬e); +} +/* }}} */ + +/* {{{ proto resource git_note_default_ref(resource $repo) + */ +PHP_FUNCTION(git_note_default_ref) +{ + php_git2_t *result = NULL, *_repo = NULL; + char *out = NULL; + zval *repo = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_note_default_ref(&out, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_note_default_ref" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(out, 1); +} +/* }}} */ + +/* {{{ proto long git_note_foreach(resource $repo, string $notes_ref, Callable $note_cb, $payload) + */ +PHP_FUNCTION(git_note_foreach) +{ + int result = 0, notes_ref_len = 0, error = 0; + zval *repo = NULL, *note_cb = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + char *notes_ref = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsfz", &repo, ¬es_ref, ¬es_ref_len, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_note_foreach(PHP_GIT2_V(_repo, repository), notes_ref, , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + diff --git a/note.h b/note.h new file mode 100644 index 0000000000..6efc2a5daa --- /dev/null +++ b/note.h @@ -0,0 +1,135 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_NOTE_H +#define PHP_GIT2_NOTE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_iterator_new, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, notes_ref) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_iterator_free, 0, 0, 1) + ZEND_ARG_INFO(0, it) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_next, 0, 0, 3) + ZEND_ARG_INFO(0, note_id) + ZEND_ARG_INFO(0, annotated_id) + ZEND_ARG_INFO(0, it) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_read, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, notes_ref) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_message, 0, 0, 1) + ZEND_ARG_INFO(0, note) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_oid, 0, 0, 1) + ZEND_ARG_INFO(0, note) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_create, 0, 0, 7) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, author) + ZEND_ARG_INFO(0, committer) + ZEND_ARG_INFO(0, notes_ref) + ZEND_ARG_INFO(0, oid) + ZEND_ARG_INFO(0, note) + ZEND_ARG_INFO(0, force) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_remove, 0, 0, 5) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, notes_ref) + ZEND_ARG_INFO(0, author) + ZEND_ARG_INFO(0, committer) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_free, 0, 0, 1) + ZEND_ARG_INFO(0, note) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_default_ref, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_foreach, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, notes_ref) + ZEND_ARG_INFO(0, note_cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_note_iterator_new(repo, notes_ref) +*/ +PHP_FUNCTION(git_note_iterator_new); + +/* {{{ proto void git_note_iterator_free(it) +*/ +PHP_FUNCTION(git_note_iterator_free); + +/* {{{ proto long git_note_next(note_id, annotated_id, it) +*/ +PHP_FUNCTION(git_note_next); + +/* {{{ proto resource git_note_read(repo, notes_ref, oid) +*/ +PHP_FUNCTION(git_note_read); + +/* {{{ proto resource git_note_message(note) +*/ +PHP_FUNCTION(git_note_message); + +/* {{{ proto resource git_note_oid(note) +*/ +PHP_FUNCTION(git_note_oid); + +/* {{{ proto resource git_note_create(repo, author, committer, notes_ref, oid, note, force) +*/ +PHP_FUNCTION(git_note_create); + +/* {{{ proto long git_note_remove(repo, notes_ref, author, committer, oid) +*/ +PHP_FUNCTION(git_note_remove); + +/* {{{ proto void git_note_free(note) +*/ +PHP_FUNCTION(git_note_free); + +/* {{{ proto resource git_note_default_ref(repo) +*/ +PHP_FUNCTION(git_note_default_ref); + +/* {{{ proto long git_note_foreach(repo, notes_ref, note_cb, payload) +*/ +PHP_FUNCTION(git_note_foreach); + +#endif \ No newline at end of file diff --git a/odb.c b/odb.c new file mode 100644 index 0000000000..537256744e --- /dev/null +++ b/odb.c @@ -0,0 +1,708 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "odb.h" + +/* {{{ proto resource git_odb_new() + */ +PHP_FUNCTION(git_odb_new) +{ + php_git2_t *result = NULL; + git_odb *out = NULL; + int error = 0; + + error = git_odb_new(&out); + if (php_git2_check_error(error, "git_odb_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto resource git_odb_open(string $objects_dir) + */ +PHP_FUNCTION(git_odb_open) +{ + php_git2_t *result = NULL; + git_odb *out = NULL; + char *objects_dir = NULL; + int objects_dir_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &objects_dir, &objects_dir_len) == FAILURE) { + return; + } + + error = git_odb_open(&out, objects_dir); + if (php_git2_check_error(error, "git_odb_open" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto long git_odb_add_disk_alternate(resource $odb, string $path) + */ +PHP_FUNCTION(git_odb_add_disk_alternate) +{ + int result = 0, path_len = 0, error = 0; + zval *odb = NULL; + php_git2_t *_odb = NULL; + char *path = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &odb, &path, &path_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_add_disk_alternate(PHP_GIT2_V(_odb, odb), path); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto void git_odb_free(resource $db) + */ +PHP_FUNCTION(git_odb_free) +{ + zval *db = NULL; + php_git2_t *_db = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &db) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_db)) { + git_odb_free(PHP_GIT2_V(_db, odb)); + GIT2_SHOULD_FREE(_db) = 0; + }; + zval_ptr_dtor(&db); +} +/* }}} */ + +/* {{{ proto resource git_odb_read(resource $db, string $id) + */ +PHP_FUNCTION(git_odb_read) +{ + php_git2_t *result = NULL, *_db = NULL; + git_odb_object *out = NULL; + zval *db = NULL; + char *id = NULL; + int id_len = 0, error = 0; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &db, &id, &id_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + error = git_odb_read(&out, PHP_GIT2_V(_db, odb),& __id); + if (php_git2_check_error(error, "git_odb_read" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_OBJECT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto resource git_odb_read_prefix(resource $db, string $short_id, long $len) + */ +PHP_FUNCTION(git_odb_read_prefix) +{ + php_git2_t *result = NULL, *_db = NULL; + git_odb_object *out = NULL; + zval *db = NULL; + char *short_id = NULL; + int short_id_len = 0, error = 0; + git_oid __short_id = {0}; + long len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &db, &short_id, &short_id_len, &len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__short_id, short_id, short_id_len)) { + RETURN_FALSE; + } + error = git_odb_read_prefix(&out, PHP_GIT2_V(_db, odb), &__short_id, len); + if (php_git2_check_error(error, "git_odb_read_prefix" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_OBJECT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto resource git_odb_read_header( $type_out, resource $db, string $id) + */ +PHP_FUNCTION(git_odb_read_header) +{ + php_git2_t *result = NULL, *_db = NULL; + size_t len_out = NULL; + zval *type_out = NULL, *db = NULL; + char *id = NULL; + int id_len = 0, error = 0; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &type_out, &db, &id, &id_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + error = git_odb_read_header(&len_out, type_out, PHP_GIT2_V(_db, odb), &__id); + if (php_git2_check_error(error, "git_odb_read_header" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_LONG(len_out); +} +/* }}} */ + +/* {{{ proto long git_odb_exists(resource $db, string $id) + */ +PHP_FUNCTION(git_odb_exists) +{ + int result = 0, id_len = 0, error = 0; + zval *db = NULL; + php_git2_t *_db = NULL; + char *id = NULL; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &db, &id, &id_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_odb_exists(PHP_GIT2_V(_db, odb), &__id); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_odb_refresh(resource $db) + */ +PHP_FUNCTION(git_odb_refresh) +{ + int result = 0, error = 0; + zval *db = NULL; + php_git2_t *_db = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &db) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_refresh(PHP_GIT2_V(_db, odb)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_odb_foreach(resource $db, Callable $cb, $payload) + */ +PHP_FUNCTION(git_odb_foreach) +{ + int result = 0, error = 0; + zval *db = NULL, *payload = NULL; + php_git2_t *_db = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfz", &db, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_odb_foreach(PHP_GIT2_V(_db, odb), , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_odb_write(resource $odb, $data, long $len, $type) + */ +PHP_FUNCTION(git_odb_write) +{ + php_git2_t *result = NULL, *_odb = NULL; + git_oid out = {0}; + zval *odb = NULL, *type = NULL; + zval *data = NULL; + long len = 0; + int error = 0; + char buf[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &odb, &data, &len, &type) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_odb_write(&out, PHP_GIT2_V(_odb, odb), data, len, type); + if (php_git2_check_error(error, "git_odb_write" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(buf, &out); + RETURN_STRING(buf, 1); +} +/* }}} */ + +/* {{{ proto resource git_odb_open_wstream(resource $db, long $size, $type) + */ +PHP_FUNCTION(git_odb_open_wstream) +{ + php_git2_t *result = NULL, *_db = NULL; + git_odb_stream *out = NULL; + zval *db = NULL, *type = NULL; + long size = 0; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &db, &size, &type) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_odb_open_wstream(&out, PHP_GIT2_V(_db, odb), size, type); + if (php_git2_check_error(error, "git_odb_open_wstream" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_STREAM, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto long git_odb_stream_write(resource $stream, string $buffer, long $len) + */ +PHP_FUNCTION(git_odb_stream_write) +{ + int result = 0, buffer_len = 0, error = 0; + zval *stream = NULL; + php_git2_t *_stream = NULL; + char *buffer = NULL; + long len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &stream, &buffer, &buffer_len, &len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_stream, php_git2_t*, &stream, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_stream_write(PHP_GIT2_V(_stream, odb_stream), buffer, len); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_odb_stream_finalize_write(resource $stream) + */ +PHP_FUNCTION(git_odb_stream_finalize_write) +{ + php_git2_t *result = NULL, *_stream = NULL; + git_oid out = {0}; + zval *stream = NULL; + int error = 0; + char buf[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &stream) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_stream, php_git2_t*, &stream, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_odb_stream_finalize_write(&out, PHP_GIT2_V(_stream, odb_stream)); + if (php_git2_check_error(error, "git_odb_stream_finalize_write" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(buf, &out); + RETURN_STRING(buf, 1); +} +/* }}} */ + +/* {{{ proto long git_odb_stream_read(resource $stream, string $buffer, long $len) + */ +PHP_FUNCTION(git_odb_stream_read) +{ + int result = 0, buffer_len = 0, error = 0; + zval *stream = NULL; + php_git2_t *_stream = NULL; + char *buffer = NULL; + long len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &stream, &buffer, &buffer_len, &len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_stream, php_git2_t*, &stream, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_stream_read(PHP_GIT2_V(_stream, odb_stream), buffer, len); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto void git_odb_stream_free(resource $stream) + */ +PHP_FUNCTION(git_odb_stream_free) +{ + zval *stream = NULL; + php_git2_t *_stream = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &stream) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_stream, php_git2_t*, &stream, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_stream)) { + git_odb_stream_free(PHP_GIT2_V(_stream, odb_stream)); + GIT2_SHOULD_FREE(_stream) = 0; + }; + zval_ptr_dtor(&stream); +} +/* }}} */ + +/* {{{ proto resource git_odb_open_rstream(resource $db, string $oid) + */ +PHP_FUNCTION(git_odb_open_rstream) +{ + php_git2_t *result = NULL, *_db = NULL; + git_odb_stream *out = NULL; + zval *db = NULL; + char *oid = NULL; + int oid_len = 0, error = 0; + git_oid __oid = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &db, &oid, &oid_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__oid, oid, oid_len)) { + RETURN_FALSE; + } + error = git_odb_open_rstream(&out, PHP_GIT2_V(_db, odb), &__oid); + if (php_git2_check_error(error, "git_odb_open_rstream" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_STREAM, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto resource git_odb_write_pack(resource $db, $progress_cb, $progress_payload) + */ +PHP_FUNCTION(git_odb_write_pack) +{ + php_git2_t *result = NULL, *_db = NULL; + git_odb_writepack *out = NULL; + zval *db = NULL, *progress_cb = NULL, *progress_payload = NULL; + int error = 0; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rz", &db, &progress_cb, &progress_payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_db, php_git2_t*, &db, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, progress_payload TSRMLS_CC)) { + RETURN_FALSE; + } + error = git_odb_write_pack(&out, PHP_GIT2_V(_db, odb), progress_cb, cb); + if (php_git2_check_error(error, "git_odb_write_pack" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_WRITEPACK, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto resource git_odb_hash( $data, long $len, $type) + */ +PHP_FUNCTION(git_odb_hash) +{ + php_git2_t *result = NULL; + git_oid out = {0}; + zval *data = NULL; + long len = 0; + zval *type = NULL; + int error = 0; + char buf[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "l", &data, &len, &type) == FAILURE) { + return; + } + error = git_odb_hash(&out, data, len, type); + if (php_git2_check_error(error, "git_odb_hash" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(buf, &out); + RETURN_STRING(buf, 1); +} +/* }}} */ + +/* {{{ proto resource git_odb_hashfile(string $path, $type) + */ +PHP_FUNCTION(git_odb_hashfile) +{ + php_git2_t *result = NULL; + git_oid out = {0}; + char *path = NULL; + int path_len = 0, error = 0; + zval *type = NULL; + char buf[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &path, &path_len, &type) == FAILURE) { + return; + } + error = git_odb_hashfile(&out, path, type); + if (php_git2_check_error(error, "git_odb_hashfile" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(buf, &out); + RETURN_STRING(buf, 1); +} +/* }}} */ + +/* {{{ proto long git_odb_object_dup(resource $source) + */ +PHP_FUNCTION(git_odb_object_dup) +{ + int result = 0, error = 0; + git_odb_object *dest = NULL; + zval *source = NULL; + php_git2_t *_source = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &source) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_object_dup(&dest, PHP_GIT2_V(_source, odb_object)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto void git_odb_object_free(resource $object) + */ +PHP_FUNCTION(git_odb_object_free) +{ + zval *object = NULL; + php_git2_t *_object = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &object) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_object)) { + git_odb_object_free(PHP_GIT2_V(_object, odb_object)); + GIT2_SHOULD_FREE(_object) = 0; + }; + zval_ptr_dtor(&object); +} +/* }}} */ + +/* {{{ proto resource git_odb_object_id(resource $object) + */ +PHP_FUNCTION(git_odb_object_id) +{ + const git_oid *result = NULL; + zval *object = NULL; + php_git2_t *_object = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &object) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_object_id(PHP_GIT2_V(_object, odb_object)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto void git_odb_object_data(resource $object) + */ +PHP_FUNCTION(git_odb_object_data) +{ + zval *object = NULL; + php_git2_t *_object = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &object) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_odb_object_data(PHP_GIT2_V(_object, odb_object)); +} +/* }}} */ + +/* {{{ proto long git_odb_object_size(resource $object) + */ +PHP_FUNCTION(git_odb_object_size) +{ + size_t result = 0; + zval *object = NULL; + php_git2_t *_object = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &object) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_object_size(PHP_GIT2_V(_object, odb_object)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_odb_object_type(resource $object) + */ +PHP_FUNCTION(git_odb_object_type) +{ + git_otype *result = NULL; + zval *object = NULL; + php_git2_t *_object = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &object) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_object_type(PHP_GIT2_V(_object, odb_object)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_odb_add_backend(resource $odb, resource $backend, long $priority) + */ +PHP_FUNCTION(git_odb_add_backend) +{ + int result = 0, error = 0; + zval *odb = NULL, *backend = NULL; + php_git2_t *_odb = NULL, *_backend = NULL; + long priority = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrl", &odb, &backend, &priority) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_backend, php_git2_t*, &backend, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_add_backend(PHP_GIT2_V(_odb, odb), PHP_GIT2_V(_backend, odb_backend), priority); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_odb_add_alternate(resource $odb, resource $backend, long $priority) + */ +PHP_FUNCTION(git_odb_add_alternate) +{ + int result = 0, error = 0; + zval *odb = NULL, *backend = NULL; + php_git2_t *_odb = NULL, *_backend = NULL; + long priority = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rrl", &odb, &backend, &priority) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_backend, php_git2_t*, &backend, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_add_alternate(PHP_GIT2_V(_odb, odb), PHP_GIT2_V(_backend, odb_backend), priority); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_odb_num_backends(resource $odb) + */ +PHP_FUNCTION(git_odb_num_backends) +{ + size_t result = 0; + zval *odb = NULL; + php_git2_t *_odb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &odb) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_odb_num_backends(PHP_GIT2_V(_odb, odb)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_odb_get_backend(resource $odb, long $pos) + */ +PHP_FUNCTION(git_odb_get_backend) +{ + php_git2_t *result = NULL, *_odb = NULL; + git_odb_backend *out = NULL; + zval *odb = NULL; + long pos = 0; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &odb, &pos) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_odb_get_backend(&out, PHP_GIT2_V(_odb, odb), pos); + if (php_git2_check_error(error, "git_odb_get_backend" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_BACKEND, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + diff --git a/odb.h b/odb.h new file mode 100644 index 0000000000..c58fbac008 --- /dev/null +++ b/odb.h @@ -0,0 +1,296 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_ODB_H +#define PHP_GIT2_ODB_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_new, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_open, 0, 0, 1) + ZEND_ARG_INFO(0, objects_dir) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_add_disk_alternate, 0, 0, 2) + ZEND_ARG_INFO(0, odb) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_free, 0, 0, 1) + ZEND_ARG_INFO(0, db) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_read, 0, 0, 2) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_read_prefix, 0, 0, 3) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, short_id) + ZEND_ARG_INFO(0, len) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_read_header, 0, 0, 3) + ZEND_ARG_INFO(0, type_out) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_exists, 0, 0, 2) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_refresh, 0, 0, 1) + ZEND_ARG_INFO(0, db) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_write, 0, 0, 4) + ZEND_ARG_INFO(0, odb) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, len) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_open_wstream, 0, 0, 3) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, size) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_stream_write, 0, 0, 2) + ZEND_ARG_INFO(0, buffer) + ZEND_ARG_INFO(0, len) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_stream_finalize_write, 0, 0, 1) + ZEND_ARG_INFO(0, stream) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_stream_read, 0, 0, 3) + ZEND_ARG_INFO(0, stream) + ZEND_ARG_INFO(0, buffer) + ZEND_ARG_INFO(0, len) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_stream_free, 0, 0, 1) + ZEND_ARG_INFO(0, stream) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_open_rstream, 0, 0, 2) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_write_pack, 0, 0, 3) + ZEND_ARG_INFO(0, db) + ZEND_ARG_INFO(0, progress_cb) + ZEND_ARG_INFO(0, progress_payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_hash, 0, 0, 3) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, len) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_hashfile, 0, 0, 2) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_object_dup, 0, 0, 1) + ZEND_ARG_INFO(0, source) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_object_free, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_object_id, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_object_data, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_object_size, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_object_type, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_add_backend, 0, 0, 3) + ZEND_ARG_INFO(0, odb) + ZEND_ARG_INFO(0, backend) + ZEND_ARG_INFO(0, priority) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_add_alternate, 0, 0, 3) + ZEND_ARG_INFO(0, odb) + ZEND_ARG_INFO(0, backend) + ZEND_ARG_INFO(0, priority) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_num_backends, 0, 0, 1) + ZEND_ARG_INFO(0, odb) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_get_backend, 0, 0, 2) + ZEND_ARG_INFO(0, odb) + ZEND_ARG_INFO(0, pos) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_odb_new() +*/ +PHP_FUNCTION(git_odb_new); + +/* {{{ proto resource git_odb_open(objects_dir) +*/ +PHP_FUNCTION(git_odb_open); + +/* {{{ proto long git_odb_add_disk_alternate(odb, path) +*/ +PHP_FUNCTION(git_odb_add_disk_alternate); + +/* {{{ proto void git_odb_free(db) +*/ +PHP_FUNCTION(git_odb_free); + +/* {{{ proto resource git_odb_read(db, id) +*/ +PHP_FUNCTION(git_odb_read); + +/* {{{ proto resource git_odb_read_prefix(db, short_id, len) +*/ +PHP_FUNCTION(git_odb_read_prefix); + +/* {{{ proto resource git_odb_read_header(type_out, db, id) +*/ +PHP_FUNCTION(git_odb_read_header); + +/* {{{ proto long git_odb_exists(db, id) +*/ +PHP_FUNCTION(git_odb_exists); + +/* {{{ proto long git_odb_refresh(db) +*/ +PHP_FUNCTION(git_odb_refresh); + +/* {{{ proto long git_odb_foreach(db, cb, payload) +*/ +PHP_FUNCTION(git_odb_foreach); + +/* {{{ proto resource git_odb_write(odb, data, len, type) +*/ +PHP_FUNCTION(git_odb_write); + +/* {{{ proto resource git_odb_open_wstream(db, size, type) +*/ +PHP_FUNCTION(git_odb_open_wstream); + +/* {{{ proto resource git_odb_stream_write(buffer, len) +*/ +PHP_FUNCTION(git_odb_stream_write); + +/* {{{ proto resource git_odb_stream_finalize_write(stream) +*/ +PHP_FUNCTION(git_odb_stream_finalize_write); + +/* {{{ proto long git_odb_stream_read(stream, buffer, len) +*/ +PHP_FUNCTION(git_odb_stream_read); + +/* {{{ proto void git_odb_stream_free(stream) +*/ +PHP_FUNCTION(git_odb_stream_free); + +/* {{{ proto resource git_odb_open_rstream(db, oid) +*/ +PHP_FUNCTION(git_odb_open_rstream); + +/* {{{ proto resource git_odb_write_pack(db, progress_cb, progress_payload) +*/ +PHP_FUNCTION(git_odb_write_pack); + +/* {{{ proto resource git_odb_hash(data, len, type) +*/ +PHP_FUNCTION(git_odb_hash); + +/* {{{ proto resource git_odb_hashfile(path, type) +*/ +PHP_FUNCTION(git_odb_hashfile); + +/* {{{ proto resource git_odb_object_dup(source) +*/ +PHP_FUNCTION(git_odb_object_dup); + +/* {{{ proto void git_odb_object_free(object) +*/ +PHP_FUNCTION(git_odb_object_free); + +/* {{{ proto resource git_odb_object_id(object) +*/ +PHP_FUNCTION(git_odb_object_id); + +/* {{{ proto resource git_odb_object_data(object) +*/ +PHP_FUNCTION(git_odb_object_data); + +/* {{{ proto resource git_odb_object_size(object) +*/ +PHP_FUNCTION(git_odb_object_size); + +/* {{{ proto resource git_odb_object_type(object) +*/ +PHP_FUNCTION(git_odb_object_type); + +/* {{{ proto long git_odb_add_backend(odb, backend, priority) +*/ +PHP_FUNCTION(git_odb_add_backend); + +/* {{{ proto long git_odb_add_alternate(odb, backend, priority) +*/ +PHP_FUNCTION(git_odb_add_alternate); + +/* {{{ proto resource git_odb_num_backends(odb) +*/ +PHP_FUNCTION(git_odb_num_backends); + +/* {{{ proto resource git_odb_get_backend(odb, pos) +*/ +PHP_FUNCTION(git_odb_get_backend); + +#endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 27d7d751f4..3292d97677 100644 --- a/php_git2.c +++ b/php_git2.c @@ -51,6 +51,8 @@ #include "pathspec.h" #include "patch.h" #include "merge.h" +#include "note.h" +#include "odb.h" int git2_resource_handle; @@ -217,6 +219,13 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v break; case PHP_GIT2_TYPE_SMART_SUBTRANSPORT: PHP_GIT2_V(result, smart_subtransport) = (git_smart_subtransport*)resource; + break; + case PHP_GIT2_TYPE_NOTE: + PHP_GIT2_V(result, note) = (git_note*)resource; + break; + case PHP_GIT2_TYPE_NOTE_ITERATOR: + PHP_GIT2_V(result, note_iterator) = (git_note_iterator*)resource; + break; default: php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } @@ -703,6 +712,51 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_tag_foreach, arginfo_git_tag_foreach) PHP_FE(git_tag_peel, arginfo_git_tag_peel) + /* note */ + PHP_FE(git_note_iterator_new, arginfo_git_note_iterator_new) + PHP_FE(git_note_iterator_free, arginfo_git_note_iterator_free) + PHP_FE(git_note_next, arginfo_git_note_next) + PHP_FE(git_note_read, arginfo_git_note_read) + PHP_FE(git_note_message, arginfo_git_note_message) + PHP_FE(git_note_oid, arginfo_git_note_oid) + PHP_FE(git_note_create, arginfo_git_note_create) + PHP_FE(git_note_remove, arginfo_git_note_remove) + PHP_FE(git_note_free, arginfo_git_note_free) + PHP_FE(git_note_default_ref, arginfo_git_note_default_ref) + PHP_FE(git_note_foreach, arginfo_git_note_foreach) + + /* odb */ + PHP_FE(git_odb_new, arginfo_git_odb_new) + PHP_FE(git_odb_open, arginfo_git_odb_open) + PHP_FE(git_odb_add_disk_alternate, arginfo_git_odb_add_disk_alternate) + PHP_FE(git_odb_free, arginfo_git_odb_free) + PHP_FE(git_odb_read, arginfo_git_odb_read) + PHP_FE(git_odb_read_prefix, arginfo_git_odb_read_prefix) + PHP_FE(git_odb_read_header, arginfo_git_odb_read_header) + PHP_FE(git_odb_exists, arginfo_git_odb_exists) + PHP_FE(git_odb_refresh, arginfo_git_odb_refresh) + PHP_FE(git_odb_foreach, arginfo_git_odb_foreach) + PHP_FE(git_odb_write, arginfo_git_odb_write) + PHP_FE(git_odb_open_wstream, arginfo_git_odb_open_wstream) + PHP_FE(git_odb_stream_write, arginfo_git_odb_stream_write) + PHP_FE(git_odb_stream_finalize_write, arginfo_git_odb_stream_finalize_write) + PHP_FE(git_odb_stream_read, arginfo_git_odb_stream_read) + PHP_FE(git_odb_stream_free, arginfo_git_odb_stream_free) + PHP_FE(git_odb_open_rstream, arginfo_git_odb_open_rstream) + PHP_FE(git_odb_write_pack, arginfo_git_odb_write_pack) + PHP_FE(git_odb_hash, arginfo_git_odb_hash) + PHP_FE(git_odb_hashfile, arginfo_git_odb_hashfile) + PHP_FE(git_odb_object_dup, arginfo_git_odb_object_dup) + PHP_FE(git_odb_object_free, arginfo_git_odb_object_free) + PHP_FE(git_odb_object_id, arginfo_git_odb_object_id) + PHP_FE(git_odb_object_data, arginfo_git_odb_object_data) + PHP_FE(git_odb_object_size, arginfo_git_odb_object_size) + PHP_FE(git_odb_object_type, arginfo_git_odb_object_type) + PHP_FE(git_odb_add_backend, arginfo_git_odb_add_backend) + PHP_FE(git_odb_add_alternate, arginfo_git_odb_add_alternate) + PHP_FE(git_odb_num_backends, arginfo_git_odb_num_backends) + PHP_FE(git_odb_get_backend, arginfo_git_odb_get_backend) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/php_git2.h b/php_git2.h index 5d69268c91..5d46c23d98 100644 --- a/php_git2.h +++ b/php_git2.h @@ -112,6 +112,12 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_DIFF_LINE, PHP_GIT2_TYPE_INDEX_CONFLICT_ITERATOR, PHP_GIT2_TYPE_SMART_SUBTRANSPORT, + PHP_GIT2_TYPE_NOTE, + PHP_GIT2_TYPE_NOTE_ITERATOR, + PHP_GIT2_TYPE_ODB_STREAM, + PHP_GIT2_TYPE_ODB_OBJECT, + PHP_GIT2_TYPE_ODB_WRITEPACK, + PHP_GIT2_TYPE_ODB_BACKEND, }; typedef struct php_git2_t { @@ -151,6 +157,12 @@ typedef struct php_git2_t { git_diff_line *diff_line; git_index_conflict_iterator *index_conflict_iterator; git_smart_subtransport *smart_subtransport; + git_note *note; + git_note_iterator *note_iterator; + git_odb_stream *odb_stream; + git_odb_object *odb_object; + git_odb_writepack *odb_writepack; + git_odb_backend *odb_backend; } v; int should_free_v; int resource_id; From 286a546b6a592c2379f01e9bf9d994ddcdae9ab8 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 04:57:37 +0900 Subject: [PATCH 050/136] add reflog stubs --- config.m4 | 2 +- ng.php | 2 + php_git2.c | 17 +++ php_git2.h | 4 + reflog.c | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++++ reflog.h | 153 +++++++++++++++++++++++++++ 6 files changed, 476 insertions(+), 1 deletion(-) create mode 100644 reflog.c create mode 100644 reflog.h diff --git a/config.m4 b/config.m4 index 430d070cb9..9f57e70e0d 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/ng.php b/ng.php index 17cc02915a..a6a1ed950b 100644 --- a/ng.php +++ b/ng.php @@ -373,6 +373,8 @@ public function shouldResource(Arg $arg) "git_odb_backend", "git_odb_stream", "struct git_odb", + "git_reflog", + "git_reflog_entry", ); } diff --git a/php_git2.c b/php_git2.c index 3292d97677..8d9b0fcad1 100644 --- a/php_git2.c +++ b/php_git2.c @@ -53,6 +53,7 @@ #include "merge.h" #include "note.h" #include "odb.h" +#include "reflog.h" int git2_resource_handle; @@ -757,6 +758,22 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_odb_num_backends, arginfo_git_odb_num_backends) PHP_FE(git_odb_get_backend, arginfo_git_odb_get_backend) + /* reflog */ + PHP_FE(git_reflog_read, arginfo_git_reflog_read) + PHP_FE(git_reflog_write, arginfo_git_reflog_write) + PHP_FE(git_reflog_append, arginfo_git_reflog_append) + PHP_FE(git_reflog_append_to, arginfo_git_reflog_append_to) + PHP_FE(git_reflog_rename, arginfo_git_reflog_rename) + PHP_FE(git_reflog_delete, arginfo_git_reflog_delete) + PHP_FE(git_reflog_entrycount, arginfo_git_reflog_entrycount) + PHP_FE(git_reflog_entry_byindex, arginfo_git_reflog_entry_byindex) + PHP_FE(git_reflog_drop, arginfo_git_reflog_drop) + PHP_FE(git_reflog_entry_id_old, arginfo_git_reflog_entry_id_old) + PHP_FE(git_reflog_entry_id_new, arginfo_git_reflog_entry_id_new) + PHP_FE(git_reflog_entry_committer, arginfo_git_reflog_entry_committer) + PHP_FE(git_reflog_entry_message, arginfo_git_reflog_entry_message) + PHP_FE(git_reflog_free, arginfo_git_reflog_free) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/php_git2.h b/php_git2.h index 5d46c23d98..643ff687fd 100644 --- a/php_git2.h +++ b/php_git2.h @@ -118,6 +118,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_ODB_OBJECT, PHP_GIT2_TYPE_ODB_WRITEPACK, PHP_GIT2_TYPE_ODB_BACKEND, + PHP_GIT2_TYPE_REFLOG, + PHP_GIT2_TYPE_REFLOG_ENTRY, }; typedef struct php_git2_t { @@ -163,6 +165,8 @@ typedef struct php_git2_t { git_odb_object *odb_object; git_odb_writepack *odb_writepack; git_odb_backend *odb_backend; + git_reflog *reflog; + git_reflog_entry *reflog_entry; } v; int should_free_v; int resource_id; diff --git a/reflog.c b/reflog.c new file mode 100644 index 0000000000..ffff200c09 --- /dev/null +++ b/reflog.c @@ -0,0 +1,299 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "reflog.h" + +/* {{{ proto resource git_reflog_read(resource $repo, string $name) + */ +PHP_FUNCTION(git_reflog_read) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_reflog *out = NULL; + zval *repo = NULL; + char *name = NULL; + int name_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_reflog_read(&out, PHP_GIT2_V(_repo, repository), name); + if (php_git2_check_error(error, "git_reflog_read" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFLOG, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto long git_reflog_write(resource $reflog) + */ +PHP_FUNCTION(git_reflog_write) +{ + int result = 0, error = 0; + zval *reflog = NULL; + php_git2_t *_reflog = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &reflog) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_write(PHP_GIT2_V(_reflog, reflog)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_reflog_append(resource $reflog, string $id, array $committer, string $msg) + */ +PHP_FUNCTION(git_reflog_append) +{ + int result = 0, id_len = 0, msg_len = 0, error = 0; + zval *reflog = NULL, *committer = NULL; + php_git2_t *_reflog = NULL; + char *id = NULL, *msg = NULL; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsas", &reflog, &id, &id_len, &committer, &msg, &msg_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_reflog_append(PHP_GIT2_V(_reflog, reflog), &__id, committer, msg); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_reflog_append_to(resource $repo, string $name, string $id, array $committer, string $msg) + */ +PHP_FUNCTION(git_reflog_append_to) +{ + int result = 0, name_len = 0, id_len = 0, msg_len = 0, error = 0; + zval *repo = NULL, *committer = NULL; + php_git2_t *_repo = NULL; + char *name = NULL, *id = NULL, *msg = NULL; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rssas", &repo, &name, &name_len, &id, &id_len, &committer, &msg, &msg_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_reflog_append_to(PHP_GIT2_V(_repo, repository), name, &__id, committer, msg); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_reflog_rename(resource $repo, string $old_name, string $name) + */ +PHP_FUNCTION(git_reflog_rename) +{ + int result = 0, old_name_len = 0, name_len = 0, error = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *old_name = NULL, *name = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &repo, &old_name, &old_name_len, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_rename(PHP_GIT2_V(_repo, repository), old_name, name); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_reflog_delete(resource $repo, string $name) + */ +PHP_FUNCTION(git_reflog_delete) +{ + int result = 0, name_len = 0, error = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *name = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_delete(PHP_GIT2_V(_repo, repository), name); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_reflog_entrycount(resource $reflog) + */ +PHP_FUNCTION(git_reflog_entrycount) +{ + size_t result = 0; + zval *reflog = NULL; + php_git2_t *_reflog = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &reflog) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_entrycount(PHP_GIT2_V(_reflog, reflog)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_reflog_entry_byindex(resource $reflog, long $idx) + */ +PHP_FUNCTION(git_reflog_entry_byindex) +{ + const git_reflog_entry *result = NULL; + zval *reflog = NULL; + php_git2_t *_reflog = NULL; + long idx = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &reflog, &idx) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_entry_byindex(PHP_GIT2_V(_reflog, reflog), idx); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto long git_reflog_drop(resource $reflog, long $idx, long $rewrite_previous_entry) + */ +PHP_FUNCTION(git_reflog_drop) +{ + int result = 0, error = 0; + zval *reflog = NULL; + php_git2_t *_reflog = NULL; + long idx = 0, rewrite_previous_entry = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rll", &reflog, &idx, &rewrite_previous_entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_drop(PHP_GIT2_V(_reflog, reflog), idx, rewrite_previous_entry); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_reflog_entry_id_old(resource $entry) + */ +PHP_FUNCTION(git_reflog_entry_id_old) +{ + const git_oid *result = NULL; + zval *entry = NULL; + php_git2_t *_entry = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_entry_id_old(PHP_GIT2_V(_entry, reflog_entry)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto resource git_reflog_entry_id_new(resource $entry) + */ +PHP_FUNCTION(git_reflog_entry_id_new) +{ + const git_oid *result = NULL; + zval *entry = NULL; + php_git2_t *_entry = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_entry_id_new(PHP_GIT2_V(_entry, reflog_entry)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto array git_reflog_entry_committer(resource $entry) + */ +PHP_FUNCTION(git_reflog_entry_committer) +{ + const git_signature *result = NULL; + zval *__result = NULL, *entry = NULL; + php_git2_t *_entry = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_entry_committer(PHP_GIT2_V(_entry, reflog_entry)); + php_git2_signature_to_array(result, &__result TSRMLS_CC); + RETURN_ZVAL(__result, 0, 1); +} +/* }}} */ + +/* {{{ proto string git_reflog_entry_message(resource $entry) + */ +PHP_FUNCTION(git_reflog_entry_message) +{ + const char *result = NULL; + zval *entry = NULL; + php_git2_t *_entry = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &entry) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reflog_entry_message(PHP_GIT2_V(_entry, reflog_entry)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto void git_reflog_free(resource $reflog) + */ +PHP_FUNCTION(git_reflog_free) +{ + zval *reflog = NULL; + php_git2_t *_reflog = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &reflog) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_reflog)) { + git_reflog_free(PHP_GIT2_V(_reflog, reflog)); + GIT2_SHOULD_FREE(_reflog) = 0; + }; + zval_ptr_dtor(&reflog); +} +/* }}} */ + diff --git a/reflog.h b/reflog.h new file mode 100644 index 0000000000..5d1ad59618 --- /dev/null +++ b/reflog.h @@ -0,0 +1,153 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_REFLOG_H +#define PHP_GIT2_REFLOG_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_read, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_write, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_append, 0, 0, 4) + ZEND_ARG_INFO(0, reflog) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, committer) + ZEND_ARG_INFO(0, msg) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_append_to, 0, 0, 5) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, committer) + ZEND_ARG_INFO(0, msg) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_rename, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, old_name) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_delete, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_entrycount, 0, 0, 1) + ZEND_ARG_INFO(0, reflog) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_entry_byindex, 0, 0, 2) + ZEND_ARG_INFO(0, reflog) + ZEND_ARG_INFO(0, idx) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_drop, 0, 0, 3) + ZEND_ARG_INFO(0, reflog) + ZEND_ARG_INFO(0, idx) + ZEND_ARG_INFO(0, rewrite_previous_entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_entry_id_old, 0, 0, 1) + ZEND_ARG_INFO(0, entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_entry_id_new, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_entry_committer, 0, 0, 1) + ZEND_ARG_INFO(0, entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_entry_message, 0, 0, 1) + ZEND_ARG_INFO(0, entry) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reflog_free, 0, 0, 1) + ZEND_ARG_INFO(0, reflog) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_reflog_read(repo, name) +*/ +PHP_FUNCTION(git_reflog_read); + +/* {{{ proto resource git_reflog_write() +*/ +PHP_FUNCTION(git_reflog_write); + +/* {{{ proto long git_reflog_append(reflog, id, committer, msg) +*/ +PHP_FUNCTION(git_reflog_append); + +/* {{{ proto long git_reflog_append_to(repo, name, id, committer, msg) +*/ +PHP_FUNCTION(git_reflog_append_to); + +/* {{{ proto long git_reflog_rename(repo, old_name, name) +*/ +PHP_FUNCTION(git_reflog_rename); + +/* {{{ proto long git_reflog_delete(repo, name) +*/ +PHP_FUNCTION(git_reflog_delete); + +/* {{{ proto resource git_reflog_entrycount(reflog) +*/ +PHP_FUNCTION(git_reflog_entrycount); + +/* {{{ proto resource git_reflog_entry_byindex(reflog, idx) +*/ +PHP_FUNCTION(git_reflog_entry_byindex); + +/* {{{ proto long git_reflog_drop(reflog, idx, rewrite_previous_entry) +*/ +PHP_FUNCTION(git_reflog_drop); + +/* {{{ proto resource git_reflog_entry_id_old(entry) +*/ +PHP_FUNCTION(git_reflog_entry_id_old); + +/* {{{ proto resource git_reflog_entry_id_new() +*/ +PHP_FUNCTION(git_reflog_entry_id_new); + +/* {{{ proto resource git_reflog_entry_committer(entry) +*/ +PHP_FUNCTION(git_reflog_entry_committer); + +/* {{{ proto resource git_reflog_entry_message(entry) +*/ +PHP_FUNCTION(git_reflog_entry_message); + +/* {{{ proto void git_reflog_free(reflog) +*/ +PHP_FUNCTION(git_reflog_free); + +#endif \ No newline at end of file From 93c42501b42debd1f34b86c4dee240126cb4a7f5 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 04:59:46 +0900 Subject: [PATCH 051/136] cleanup tests --- tests/blob/git_blob_create_fromchunks.phpt | 10 ---------- tests/blob/git_blob_create_fromdisk.phpt | 10 ---------- tests/blob/git_blob_create_fromworkdir.phpt | 10 ---------- tests/blob/git_blob_filtered_content.phpt | 10 ---------- tests/blob/git_blob_free.phpt | 10 ---------- tests/blob/git_blob_id.phpt | 10 ---------- tests/blob/git_blob_is_binary.phpt | 10 ---------- tests/blob/git_blob_lookup.phpt | 10 ---------- tests/blob/git_blob_lookup_prefix.phpt | 10 ---------- tests/blob/git_blob_owner.phpt | 10 ---------- tests/blob/git_blob_rawcontent.phpt | 10 ---------- tests/blob/git_blob_rawsize.phpt | 10 ---------- tests/branch/git_branch_create.phpt | 10 ---------- tests/branch/git_branch_delete.phpt | 10 ---------- tests/branch/git_branch_is_head.phpt | 10 ---------- tests/branch/git_branch_iterator_free.phpt | 10 ---------- tests/branch/git_branch_iterator_new.phpt | 10 ---------- tests/branch/git_branch_lookup.phpt | 10 ---------- tests/branch/git_branch_move.phpt | 10 ---------- tests/branch/git_branch_name.phpt | 10 ---------- tests/branch/git_branch_next.phpt | 10 ---------- tests/branch/git_branch_remote_name.phpt | 10 ---------- tests/branch/git_branch_upstream.phpt | 10 ---------- tests/branch/git_branch_upstream_name.phpt | 10 ---------- tests/checkout/git_checkout_head.phpt | 10 ---------- tests/checkout/git_checkout_index.phpt | 10 ---------- tests/checkout/git_checkout_tree.phpt | 10 ---------- tests/clone/git_clone.phpt | 10 ---------- tests/clone/git_clone_into.phpt | 10 ---------- tests/commit/git_commit_author.phpt | 10 ---------- tests/commit/git_commit_committer.phpt | 10 ---------- tests/commit/git_commit_create.phpt | 10 ---------- tests/commit/git_commit_id.phpt | 10 ---------- tests/commit/git_commit_lookup.phpt | 10 ---------- tests/commit/git_commit_lookup_prefix.phpt | 10 ---------- tests/commit/git_commit_message.phpt | 10 ---------- tests/commit/git_commit_message_encoding.phpt | 10 ---------- tests/commit/git_commit_message_raw.phpt | 10 ---------- tests/commit/git_commit_nth_gen_ancestor.phpt | 10 ---------- tests/commit/git_commit_owner.phpt | 10 ---------- tests/commit/git_commit_parent.phpt | 10 ---------- tests/commit/git_commit_parent_id.phpt | 10 ---------- tests/commit/git_commit_parentcount.phpt | 10 ---------- tests/commit/git_commit_raw_header.phpt | 10 ---------- tests/commit/git_commit_time.phpt | 10 ---------- tests/commit/git_commit_time_offset.phpt | 10 ---------- tests/commit/git_commit_tree.phpt | 10 ---------- tests/commit/git_commit_tree_id.phpt | 10 ---------- tests/common.php | 1 - tests/config/git_config_add_file_ondisk.phpt | 10 ---------- tests/config/git_config_backend_foreach_match.phpt | 10 ---------- tests/config/git_config_delete_entry.phpt | 10 ---------- tests/config/git_config_delete_multivar.phpt | 10 ---------- tests/config/git_config_find_global.phpt | 10 ---------- tests/config/git_config_find_system.phpt | 10 ---------- tests/config/git_config_find_xdg.phpt | 10 ---------- tests/config/git_config_foreach.phpt | 10 ---------- tests/config/git_config_foreach_match.phpt | 10 ---------- tests/config/git_config_free.phpt | 10 ---------- tests/config/git_config_get_bool.phpt | 10 ---------- tests/config/git_config_get_entry.phpt | 10 ---------- tests/config/git_config_get_int32.phpt | 10 ---------- tests/config/git_config_get_int64.phpt | 10 ---------- tests/config/git_config_get_mapped.phpt | 10 ---------- tests/config/git_config_get_multivar_foreach.phpt | 10 ---------- tests/config/git_config_get_string.phpt | 10 ---------- tests/config/git_config_iterator_free.phpt | 10 ---------- tests/config/git_config_iterator_glob_new.phpt | 10 ---------- tests/config/git_config_iterator_new.phpt | 10 ---------- tests/config/git_config_lookup_map_value.phpt | 10 ---------- tests/config/git_config_multivar_iterator_new.phpt | 10 ---------- tests/config/git_config_new.phpt | 10 ---------- tests/config/git_config_next.phpt | 10 ---------- tests/config/git_config_open_default.phpt | 10 ---------- tests/config/git_config_open_global.phpt | 10 ---------- tests/config/git_config_open_level.phpt | 10 ---------- tests/config/git_config_open_ondisk.phpt | 10 ---------- tests/config/git_config_parse_bool.phpt | 10 ---------- tests/config/git_config_parse_int32.phpt | 10 ---------- tests/config/git_config_parse_int64.phpt | 10 ---------- tests/config/git_config_refresh.phpt | 10 ---------- tests/config/git_config_set_bool.phpt | 10 ---------- tests/config/git_config_set_int32.phpt | 10 ---------- tests/config/git_config_set_int64.phpt | 10 ---------- tests/config/git_config_set_multivar.phpt | 10 ---------- tests/config/git_config_set_string.phpt | 10 ---------- tests/cred/git_cred_default_new.phpt | 10 ---------- tests/cred/git_cred_has_username.phpt | 10 ---------- tests/cred/git_cred_ssh_custom_new.phpt | 10 ---------- tests/cred/git_cred_ssh_key_new.phpt | 10 ---------- tests/cred/git_cred_userpass.phpt | 10 ---------- tests/cred/git_cred_userpass_plaintext_new.phpt | 10 ---------- tests/diff/git_diff_blob_to_buffer.phpt | 10 ---------- tests/diff/git_diff_blobs.phpt | 10 ---------- tests/diff/git_diff_find_similar.phpt | 10 ---------- tests/diff/git_diff_foreach.phpt | 10 ---------- tests/diff/git_diff_free.phpt | 10 ---------- tests/diff/git_diff_get_delta.phpt | 10 ---------- tests/diff/git_diff_index_to_workdir.phpt | 10 ---------- tests/diff/git_diff_is_sorted_icase.phpt | 10 ---------- tests/diff/git_diff_merge.phpt | 10 ---------- tests/diff/git_diff_num_deltas.phpt | 10 ---------- tests/diff/git_diff_num_deltas_of_type.phpt | 10 ---------- tests/diff/git_diff_options_init.phpt | 10 ---------- tests/diff/git_diff_print.phpt | 10 ---------- tests/diff/git_diff_status_char.phpt | 10 ---------- tests/diff/git_diff_tree_to_index.phpt | 10 ---------- tests/diff/git_diff_tree_to_tree.phpt | 10 ---------- tests/diff/git_diff_tree_to_workdir.phpt | 10 ---------- tests/diff/git_diff_tree_to_workdir_with_index.phpt | 10 ---------- tests/filter/git_filter_list_apply_to_blob.phpt | 10 ---------- tests/filter/git_filter_list_apply_to_data.phpt | 10 ---------- tests/filter/git_filter_list_apply_to_file.phpt | 10 ---------- tests/filter/git_filter_list_free.phpt | 10 ---------- tests/filter/git_filter_list_length.phpt | 10 ---------- tests/filter/git_filter_list_load.phpt | 10 ---------- tests/filter/git_filter_list_new.phpt | 10 ---------- tests/filter/git_filter_list_push.phpt | 10 ---------- tests/filter/git_filter_lookup.phpt | 10 ---------- tests/filter/git_filter_register.phpt | 10 ---------- tests/filter/git_filter_source_filemode.phpt | 10 ---------- tests/filter/git_filter_source_id.phpt | 10 ---------- tests/filter/git_filter_source_mode.phpt | 10 ---------- tests/filter/git_filter_source_path.phpt | 10 ---------- tests/filter/git_filter_source_repo.phpt | 10 ---------- tests/filter/git_filter_unregister.phpt | 10 ---------- tests/ignore/git_ignore_add_rule.phpt | 10 ---------- tests/ignore/git_ignore_clear_internal_rules.phpt | 10 ---------- tests/ignore/git_ignore_path_is_ignored.phpt | 10 ---------- tests/index/git_index_add.phpt | 10 ---------- tests/index/git_index_add_all.phpt | 10 ---------- tests/index/git_index_add_bypath.phpt | 10 ---------- tests/index/git_index_caps.phpt | 10 ---------- tests/index/git_index_clear.phpt | 10 ---------- tests/index/git_index_conflict_add.phpt | 10 ---------- tests/index/git_index_conflict_cleanup.phpt | 10 ---------- tests/index/git_index_conflict_get.phpt | 10 ---------- tests/index/git_index_conflict_iterator_free.phpt | 10 ---------- tests/index/git_index_conflict_iterator_new.phpt | 10 ---------- tests/index/git_index_conflict_next.phpt | 10 ---------- tests/index/git_index_conflict_remove.phpt | 10 ---------- tests/index/git_index_entry_stage.phpt | 10 ---------- tests/index/git_index_entrycount.phpt | 10 ---------- tests/index/git_index_find.phpt | 10 ---------- tests/index/git_index_free.phpt | 10 ---------- tests/index/git_index_get_byindex.phpt | 10 ---------- tests/index/git_index_get_bypath.phpt | 10 ---------- tests/index/git_index_has_conflicts.phpt | 10 ---------- tests/index/git_index_new.phpt | 10 ---------- tests/index/git_index_open.phpt | 10 ---------- tests/index/git_index_owner.phpt | 10 ---------- tests/index/git_index_path.phpt | 10 ---------- tests/index/git_index_read.phpt | 10 ---------- tests/index/git_index_read_tree.phpt | 10 ---------- tests/index/git_index_remove.phpt | 10 ---------- tests/index/git_index_remove_all.phpt | 10 ---------- tests/index/git_index_remove_bypath.phpt | 10 ---------- tests/index/git_index_remove_directory.phpt | 10 ---------- tests/index/git_index_set_caps.phpt | 10 ---------- tests/index/git_index_update_all.phpt | 10 ---------- tests/index/git_index_write.phpt | 10 ---------- tests/index/git_index_write_tree.phpt | 10 ---------- tests/index/git_index_write_tree_to.phpt | 10 ---------- tests/indexer/git_indexer_append.phpt | 10 ---------- tests/indexer/git_indexer_commit.phpt | 10 ---------- tests/indexer/git_indexer_free.phpt | 10 ---------- tests/indexer/git_indexer_hash.phpt | 10 ---------- tests/indexer/git_indexer_new.phpt | 10 ---------- tests/merge/git_merge.phpt | 10 ---------- tests/merge/git_merge_base.phpt | 10 ---------- tests/merge/git_merge_base_many.phpt | 10 ---------- tests/merge/git_merge_head_free.phpt | 10 ---------- tests/merge/git_merge_head_from_fetchhead.phpt | 10 ---------- tests/merge/git_merge_head_from_oid.phpt | 10 ---------- tests/merge/git_merge_head_from_ref.phpt | 10 ---------- tests/merge/git_merge_result_fastforward_oid.phpt | 10 ---------- tests/merge/git_merge_result_free.phpt | 10 ---------- tests/merge/git_merge_result_is_fastforward.phpt | 10 ---------- tests/merge/git_merge_result_is_uptodate.phpt | 10 ---------- tests/merge/git_merge_trees.phpt | 10 ---------- tests/object/git_object__size.phpt | 10 ---------- tests/object/git_object_dup.phpt | 10 ---------- tests/object/git_object_free.phpt | 10 ---------- tests/object/git_object_id.phpt | 10 ---------- tests/object/git_object_lookup.phpt | 10 ---------- tests/object/git_object_lookup_bypath.phpt | 10 ---------- tests/object/git_object_lookup_prefix.phpt | 10 ---------- tests/object/git_object_owner.phpt | 10 ---------- tests/object/git_object_peel.phpt | 10 ---------- tests/object/git_object_string2type.phpt | 10 ---------- tests/object/git_object_type.phpt | 10 ---------- tests/object/git_object_type2string.phpt | 10 ---------- tests/object/git_object_typeisloose.phpt | 10 ---------- tests/patch/git_patch_free.phpt | 10 ---------- tests/patch/git_patch_from_blob_and_buffer.phpt | 10 ---------- tests/patch/git_patch_from_blobs.phpt | 10 ---------- tests/patch/git_patch_from_diff.phpt | 10 ---------- tests/patch/git_patch_get_delta.phpt | 10 ---------- tests/patch/git_patch_get_hunk.phpt | 10 ---------- tests/patch/git_patch_get_line_in_hunk.phpt | 10 ---------- tests/patch/git_patch_line_stats.phpt | 10 ---------- tests/patch/git_patch_num_hunks.phpt | 10 ---------- tests/patch/git_patch_num_lines_in_hunk.phpt | 10 ---------- tests/patch/git_patch_print.phpt | 10 ---------- tests/patch/git_patch_size.phpt | 10 ---------- tests/patch/git_patch_to_str.phpt | 10 ---------- tests/pathspec/git_pathspec_free.phpt | 10 ---------- tests/pathspec/git_pathspec_match_diff.phpt | 10 ---------- tests/pathspec/git_pathspec_match_index.phpt | 10 ---------- tests/pathspec/git_pathspec_match_list_diff_entry.phpt | 10 ---------- tests/pathspec/git_pathspec_match_list_entry.phpt | 10 ---------- tests/pathspec/git_pathspec_match_list_entrycount.phpt | 10 ---------- .../pathspec/git_pathspec_match_list_failed_entry.phpt | 10 ---------- .../git_pathspec_match_list_failed_entrycount.phpt | 10 ---------- tests/pathspec/git_pathspec_match_list_free.phpt | 10 ---------- tests/pathspec/git_pathspec_match_tree.phpt | 10 ---------- tests/pathspec/git_pathspec_match_workdir.phpt | 10 ---------- tests/pathspec/git_pathspec_matches_path.phpt | 10 ---------- tests/pathspec/git_pathspec_new.phpt | 10 ---------- tests/reference/git_reference_cmp.phpt | 10 ---------- tests/reference/git_reference_create.phpt | 10 ---------- tests/reference/git_reference_delete.phpt | 10 ---------- tests/reference/git_reference_dwim.phpt | 10 ---------- tests/reference/git_reference_foreach.phpt | 10 ---------- tests/reference/git_reference_foreach_glob.phpt | 10 ---------- tests/reference/git_reference_foreach_name.phpt | 10 ---------- tests/reference/git_reference_free.phpt | 10 ---------- tests/reference/git_reference_has_log.phpt | 10 ---------- tests/reference/git_reference_is_branch.phpt | 10 ---------- tests/reference/git_reference_is_remote.phpt | 10 ---------- tests/reference/git_reference_is_tag.phpt | 10 ---------- tests/reference/git_reference_is_valid_name.phpt | 10 ---------- tests/reference/git_reference_iterator_free.phpt | 10 ---------- tests/reference/git_reference_iterator_glob_new.phpt | 10 ---------- tests/reference/git_reference_iterator_new.phpt | 10 ---------- tests/reference/git_reference_list.phpt | 10 ---------- tests/reference/git_reference_lookup.phpt | 10 ---------- tests/reference/git_reference_name.phpt | 10 ---------- tests/reference/git_reference_name_to_id.phpt | 10 ---------- tests/reference/git_reference_next.phpt | 10 ---------- tests/reference/git_reference_next_name.phpt | 10 ---------- tests/reference/git_reference_normalize_name.phpt | 10 ---------- tests/reference/git_reference_owner.phpt | 10 ---------- tests/reference/git_reference_peel.phpt | 10 ---------- tests/reference/git_reference_rename.phpt | 10 ---------- tests/reference/git_reference_resolve.phpt | 10 ---------- tests/reference/git_reference_set_target.phpt | 10 ---------- tests/reference/git_reference_shorthand.phpt | 10 ---------- tests/reference/git_reference_symbolic_create.phpt | 10 ---------- tests/reference/git_reference_symbolic_set_target.phpt | 10 ---------- tests/reference/git_reference_symbolic_target.phpt | 10 ---------- tests/reference/git_reference_target.phpt | 10 ---------- tests/reference/git_reference_target_peel.phpt | 10 ---------- tests/reference/git_reference_type.phpt | 10 ---------- tests/repository/git_repository_config.phpt | 10 ---------- tests/repository/git_repository_detach_head.phpt | 10 ---------- tests/repository/git_repository_discover.phpt | 10 ---------- tests/repository/git_repository_fetchhead_foreach.phpt | 10 ---------- tests/repository/git_repository_free.phpt | 10 ---------- tests/repository/git_repository_get_namespace.phpt | 10 ---------- tests/repository/git_repository_hashfile.phpt | 10 ---------- tests/repository/git_repository_head.phpt | 10 ---------- tests/repository/git_repository_head_detached.phpt | 10 ---------- tests/repository/git_repository_head_unborn.phpt | 10 ---------- tests/repository/git_repository_index.phpt | 10 ---------- tests/repository/git_repository_init.phpt | 10 ---------- tests/repository/git_repository_init_ext.phpt | 10 ---------- tests/repository/git_repository_is_bare.phpt | 10 ---------- tests/repository/git_repository_is_empty.phpt | 10 ---------- tests/repository/git_repository_is_shallow.phpt | 10 ---------- tests/repository/git_repository_merge_cleanup.phpt | 10 ---------- tests/repository/git_repository_mergehead_foreach.phpt | 10 ---------- tests/repository/git_repository_message.phpt | 10 ---------- tests/repository/git_repository_message_remove.phpt | 10 ---------- tests/repository/git_repository_new.phpt | 10 ---------- tests/repository/git_repository_odb.phpt | 10 ---------- tests/repository/git_repository_open.phpt | 10 ---------- tests/repository/git_repository_open_bare.phpt | 10 ---------- tests/repository/git_repository_open_ext.phpt | 10 ---------- tests/repository/git_repository_path.phpt | 10 ---------- tests/repository/git_repository_refdb.phpt | 10 ---------- tests/repository/git_repository_set_head.phpt | 10 ---------- tests/repository/git_repository_set_head_detached.phpt | 10 ---------- tests/repository/git_repository_set_namespace.phpt | 10 ---------- tests/repository/git_repository_set_workdir.phpt | 10 ---------- tests/repository/git_repository_state.phpt | 10 ---------- tests/repository/git_repository_workdir.phpt | 10 ---------- tests/repository/git_repository_wrap_odb.phpt | 10 ---------- tests/revparse/git_revparse.phpt | 10 ---------- tests/revparse/git_revparse_ext.phpt | 10 ---------- tests/revparse/git_revparse_single.phpt | 10 ---------- tests/revwalk/git_revwalk_free.phpt | 10 ---------- tests/revwalk/git_revwalk_hide.phpt | 10 ---------- tests/revwalk/git_revwalk_hide_glob.phpt | 10 ---------- tests/revwalk/git_revwalk_hide_head.phpt | 10 ---------- tests/revwalk/git_revwalk_hide_ref.phpt | 10 ---------- tests/revwalk/git_revwalk_new.phpt | 10 ---------- tests/revwalk/git_revwalk_next.phpt | 10 ---------- tests/revwalk/git_revwalk_push.phpt | 10 ---------- tests/revwalk/git_revwalk_push_glob.phpt | 10 ---------- tests/revwalk/git_revwalk_push_head.phpt | 10 ---------- tests/revwalk/git_revwalk_push_range.phpt | 10 ---------- tests/revwalk/git_revwalk_push_ref.phpt | 10 ---------- tests/revwalk/git_revwalk_repository.phpt | 10 ---------- tests/revwalk/git_revwalk_reset.phpt | 10 ---------- tests/revwalk/git_revwalk_simplify_first_parent.phpt | 10 ---------- tests/revwalk/git_revwalk_sorting.phpt | 10 ---------- tests/status/git_status_byindex.phpt | 10 ---------- tests/status/git_status_file.phpt | 10 ---------- tests/status/git_status_foreach.phpt | 10 ---------- tests/status/git_status_foreach_ext.phpt | 10 ---------- tests/status/git_status_list_entrycount.phpt | 10 ---------- tests/status/git_status_list_free.phpt | 10 ---------- tests/status/git_status_list_new.phpt | 10 ---------- tests/status/git_status_should_ignore.phpt | 10 ---------- tests/tag/git_tag_annotation_create.phpt | 10 ---------- tests/tag/git_tag_create.phpt | 10 ---------- tests/tag/git_tag_create_frombuffer.phpt | 10 ---------- tests/tag/git_tag_create_lightweight.phpt | 10 ---------- tests/tag/git_tag_delete.phpt | 10 ---------- tests/tag/git_tag_foreach.phpt | 10 ---------- tests/tag/git_tag_free.phpt | 10 ---------- tests/tag/git_tag_id.phpt | 10 ---------- tests/tag/git_tag_list.phpt | 10 ---------- tests/tag/git_tag_list_match.phpt | 10 ---------- tests/tag/git_tag_lookup.phpt | 10 ---------- tests/tag/git_tag_lookup_prefix.phpt | 10 ---------- tests/tag/git_tag_message.phpt | 10 ---------- tests/tag/git_tag_name.phpt | 10 ---------- tests/tag/git_tag_owner.phpt | 10 ---------- tests/tag/git_tag_peel.phpt | 10 ---------- tests/tag/git_tag_tagger.phpt | 10 ---------- tests/tag/git_tag_target.phpt | 10 ---------- tests/tag/git_tag_target_id.phpt | 10 ---------- tests/tag/git_tag_target_type.phpt | 10 ---------- tests/transport/git_smart_subtransport_git.phpt | 10 ---------- tests/transport/git_smart_subtransport_http.phpt | 10 ---------- tests/transport/git_smart_subtransport_ssh.phpt | 10 ---------- tests/transport/git_transport_dummy.phpt | 10 ---------- tests/transport/git_transport_local.phpt | 10 ---------- tests/transport/git_transport_new.phpt | 10 ---------- tests/transport/git_transport_register.phpt | 10 ---------- tests/transport/git_transport_smart.phpt | 10 ---------- tests/transport/git_transport_unregister.phpt | 10 ---------- tests/tree/git_tree_entry_byindex.phpt | 10 ---------- tests/tree/git_tree_entry_byname.phpt | 10 ---------- tests/tree/git_tree_entry_byoid.phpt | 10 ---------- tests/tree/git_tree_entry_bypath.phpt | 10 ---------- tests/tree/git_tree_entry_cmp.phpt | 10 ---------- tests/tree/git_tree_entry_dup.phpt | 10 ---------- tests/tree/git_tree_entry_filemode.phpt | 10 ---------- tests/tree/git_tree_entry_filemode_raw.phpt | 10 ---------- tests/tree/git_tree_entry_free.phpt | 10 ---------- tests/tree/git_tree_entry_id.phpt | 10 ---------- tests/tree/git_tree_entry_name.phpt | 10 ---------- tests/tree/git_tree_entry_type.phpt | 10 ---------- tests/tree/git_tree_entrycount.phpt | 10 ---------- tests/tree/git_tree_free.phpt | 10 ---------- tests/tree/git_tree_id.phpt | 10 ---------- tests/tree/git_tree_lookup.phpt | 10 ---------- tests/tree/git_tree_owner.phpt | 10 ---------- tests/tree/git_tree_walk.phpt | 10 ---------- tests/treebuilder/git_treebuilder_clear.phpt | 10 ---------- tests/treebuilder/git_treebuilder_create.phpt | 10 ---------- tests/treebuilder/git_treebuilder_entrycount.phpt | 10 ---------- tests/treebuilder/git_treebuilder_filter.phpt | 10 ---------- tests/treebuilder/git_treebuilder_free.phpt | 10 ---------- tests/treebuilder/git_treebuilder_get.phpt | 10 ---------- tests/treebuilder/git_treebuilder_insert.phpt | 10 ---------- tests/treebuilder/git_treebuilder_remove.phpt | 10 ---------- tests/treebuilder/git_treebuilder_write.phpt | 10 ---------- 371 files changed, 3701 deletions(-) delete mode 100644 tests/blob/git_blob_create_fromchunks.phpt delete mode 100644 tests/blob/git_blob_create_fromdisk.phpt delete mode 100644 tests/blob/git_blob_create_fromworkdir.phpt delete mode 100644 tests/blob/git_blob_filtered_content.phpt delete mode 100644 tests/blob/git_blob_free.phpt delete mode 100644 tests/blob/git_blob_id.phpt delete mode 100644 tests/blob/git_blob_is_binary.phpt delete mode 100644 tests/blob/git_blob_lookup.phpt delete mode 100644 tests/blob/git_blob_lookup_prefix.phpt delete mode 100644 tests/blob/git_blob_owner.phpt delete mode 100644 tests/blob/git_blob_rawcontent.phpt delete mode 100644 tests/blob/git_blob_rawsize.phpt delete mode 100644 tests/branch/git_branch_create.phpt delete mode 100644 tests/branch/git_branch_delete.phpt delete mode 100644 tests/branch/git_branch_is_head.phpt delete mode 100644 tests/branch/git_branch_iterator_free.phpt delete mode 100644 tests/branch/git_branch_iterator_new.phpt delete mode 100644 tests/branch/git_branch_lookup.phpt delete mode 100644 tests/branch/git_branch_move.phpt delete mode 100644 tests/branch/git_branch_name.phpt delete mode 100644 tests/branch/git_branch_next.phpt delete mode 100644 tests/branch/git_branch_remote_name.phpt delete mode 100644 tests/branch/git_branch_upstream.phpt delete mode 100644 tests/branch/git_branch_upstream_name.phpt delete mode 100644 tests/checkout/git_checkout_head.phpt delete mode 100644 tests/checkout/git_checkout_index.phpt delete mode 100644 tests/checkout/git_checkout_tree.phpt delete mode 100644 tests/clone/git_clone.phpt delete mode 100644 tests/clone/git_clone_into.phpt delete mode 100644 tests/commit/git_commit_author.phpt delete mode 100644 tests/commit/git_commit_committer.phpt delete mode 100644 tests/commit/git_commit_create.phpt delete mode 100644 tests/commit/git_commit_id.phpt delete mode 100644 tests/commit/git_commit_lookup.phpt delete mode 100644 tests/commit/git_commit_lookup_prefix.phpt delete mode 100644 tests/commit/git_commit_message.phpt delete mode 100644 tests/commit/git_commit_message_encoding.phpt delete mode 100644 tests/commit/git_commit_message_raw.phpt delete mode 100644 tests/commit/git_commit_nth_gen_ancestor.phpt delete mode 100644 tests/commit/git_commit_owner.phpt delete mode 100644 tests/commit/git_commit_parent.phpt delete mode 100644 tests/commit/git_commit_parent_id.phpt delete mode 100644 tests/commit/git_commit_parentcount.phpt delete mode 100644 tests/commit/git_commit_raw_header.phpt delete mode 100644 tests/commit/git_commit_time.phpt delete mode 100644 tests/commit/git_commit_time_offset.phpt delete mode 100644 tests/commit/git_commit_tree.phpt delete mode 100644 tests/commit/git_commit_tree_id.phpt delete mode 100644 tests/common.php delete mode 100644 tests/config/git_config_add_file_ondisk.phpt delete mode 100644 tests/config/git_config_backend_foreach_match.phpt delete mode 100644 tests/config/git_config_delete_entry.phpt delete mode 100644 tests/config/git_config_delete_multivar.phpt delete mode 100644 tests/config/git_config_find_global.phpt delete mode 100644 tests/config/git_config_find_system.phpt delete mode 100644 tests/config/git_config_find_xdg.phpt delete mode 100644 tests/config/git_config_foreach.phpt delete mode 100644 tests/config/git_config_foreach_match.phpt delete mode 100644 tests/config/git_config_free.phpt delete mode 100644 tests/config/git_config_get_bool.phpt delete mode 100644 tests/config/git_config_get_entry.phpt delete mode 100644 tests/config/git_config_get_int32.phpt delete mode 100644 tests/config/git_config_get_int64.phpt delete mode 100644 tests/config/git_config_get_mapped.phpt delete mode 100644 tests/config/git_config_get_multivar_foreach.phpt delete mode 100644 tests/config/git_config_get_string.phpt delete mode 100644 tests/config/git_config_iterator_free.phpt delete mode 100644 tests/config/git_config_iterator_glob_new.phpt delete mode 100644 tests/config/git_config_iterator_new.phpt delete mode 100644 tests/config/git_config_lookup_map_value.phpt delete mode 100644 tests/config/git_config_multivar_iterator_new.phpt delete mode 100644 tests/config/git_config_new.phpt delete mode 100644 tests/config/git_config_next.phpt delete mode 100644 tests/config/git_config_open_default.phpt delete mode 100644 tests/config/git_config_open_global.phpt delete mode 100644 tests/config/git_config_open_level.phpt delete mode 100644 tests/config/git_config_open_ondisk.phpt delete mode 100644 tests/config/git_config_parse_bool.phpt delete mode 100644 tests/config/git_config_parse_int32.phpt delete mode 100644 tests/config/git_config_parse_int64.phpt delete mode 100644 tests/config/git_config_refresh.phpt delete mode 100644 tests/config/git_config_set_bool.phpt delete mode 100644 tests/config/git_config_set_int32.phpt delete mode 100644 tests/config/git_config_set_int64.phpt delete mode 100644 tests/config/git_config_set_multivar.phpt delete mode 100644 tests/config/git_config_set_string.phpt delete mode 100644 tests/cred/git_cred_default_new.phpt delete mode 100644 tests/cred/git_cred_has_username.phpt delete mode 100644 tests/cred/git_cred_ssh_custom_new.phpt delete mode 100644 tests/cred/git_cred_ssh_key_new.phpt delete mode 100644 tests/cred/git_cred_userpass.phpt delete mode 100644 tests/cred/git_cred_userpass_plaintext_new.phpt delete mode 100644 tests/diff/git_diff_blob_to_buffer.phpt delete mode 100644 tests/diff/git_diff_blobs.phpt delete mode 100644 tests/diff/git_diff_find_similar.phpt delete mode 100644 tests/diff/git_diff_foreach.phpt delete mode 100644 tests/diff/git_diff_free.phpt delete mode 100644 tests/diff/git_diff_get_delta.phpt delete mode 100644 tests/diff/git_diff_index_to_workdir.phpt delete mode 100644 tests/diff/git_diff_is_sorted_icase.phpt delete mode 100644 tests/diff/git_diff_merge.phpt delete mode 100644 tests/diff/git_diff_num_deltas.phpt delete mode 100644 tests/diff/git_diff_num_deltas_of_type.phpt delete mode 100644 tests/diff/git_diff_options_init.phpt delete mode 100644 tests/diff/git_diff_print.phpt delete mode 100644 tests/diff/git_diff_status_char.phpt delete mode 100644 tests/diff/git_diff_tree_to_index.phpt delete mode 100644 tests/diff/git_diff_tree_to_tree.phpt delete mode 100644 tests/diff/git_diff_tree_to_workdir.phpt delete mode 100644 tests/diff/git_diff_tree_to_workdir_with_index.phpt delete mode 100644 tests/filter/git_filter_list_apply_to_blob.phpt delete mode 100644 tests/filter/git_filter_list_apply_to_data.phpt delete mode 100644 tests/filter/git_filter_list_apply_to_file.phpt delete mode 100644 tests/filter/git_filter_list_free.phpt delete mode 100644 tests/filter/git_filter_list_length.phpt delete mode 100644 tests/filter/git_filter_list_load.phpt delete mode 100644 tests/filter/git_filter_list_new.phpt delete mode 100644 tests/filter/git_filter_list_push.phpt delete mode 100644 tests/filter/git_filter_lookup.phpt delete mode 100644 tests/filter/git_filter_register.phpt delete mode 100644 tests/filter/git_filter_source_filemode.phpt delete mode 100644 tests/filter/git_filter_source_id.phpt delete mode 100644 tests/filter/git_filter_source_mode.phpt delete mode 100644 tests/filter/git_filter_source_path.phpt delete mode 100644 tests/filter/git_filter_source_repo.phpt delete mode 100644 tests/filter/git_filter_unregister.phpt delete mode 100644 tests/ignore/git_ignore_add_rule.phpt delete mode 100644 tests/ignore/git_ignore_clear_internal_rules.phpt delete mode 100644 tests/ignore/git_ignore_path_is_ignored.phpt delete mode 100644 tests/index/git_index_add.phpt delete mode 100644 tests/index/git_index_add_all.phpt delete mode 100644 tests/index/git_index_add_bypath.phpt delete mode 100644 tests/index/git_index_caps.phpt delete mode 100644 tests/index/git_index_clear.phpt delete mode 100644 tests/index/git_index_conflict_add.phpt delete mode 100644 tests/index/git_index_conflict_cleanup.phpt delete mode 100644 tests/index/git_index_conflict_get.phpt delete mode 100644 tests/index/git_index_conflict_iterator_free.phpt delete mode 100644 tests/index/git_index_conflict_iterator_new.phpt delete mode 100644 tests/index/git_index_conflict_next.phpt delete mode 100644 tests/index/git_index_conflict_remove.phpt delete mode 100644 tests/index/git_index_entry_stage.phpt delete mode 100644 tests/index/git_index_entrycount.phpt delete mode 100644 tests/index/git_index_find.phpt delete mode 100644 tests/index/git_index_free.phpt delete mode 100644 tests/index/git_index_get_byindex.phpt delete mode 100644 tests/index/git_index_get_bypath.phpt delete mode 100644 tests/index/git_index_has_conflicts.phpt delete mode 100644 tests/index/git_index_new.phpt delete mode 100644 tests/index/git_index_open.phpt delete mode 100644 tests/index/git_index_owner.phpt delete mode 100644 tests/index/git_index_path.phpt delete mode 100644 tests/index/git_index_read.phpt delete mode 100644 tests/index/git_index_read_tree.phpt delete mode 100644 tests/index/git_index_remove.phpt delete mode 100644 tests/index/git_index_remove_all.phpt delete mode 100644 tests/index/git_index_remove_bypath.phpt delete mode 100644 tests/index/git_index_remove_directory.phpt delete mode 100644 tests/index/git_index_set_caps.phpt delete mode 100644 tests/index/git_index_update_all.phpt delete mode 100644 tests/index/git_index_write.phpt delete mode 100644 tests/index/git_index_write_tree.phpt delete mode 100644 tests/index/git_index_write_tree_to.phpt delete mode 100644 tests/indexer/git_indexer_append.phpt delete mode 100644 tests/indexer/git_indexer_commit.phpt delete mode 100644 tests/indexer/git_indexer_free.phpt delete mode 100644 tests/indexer/git_indexer_hash.phpt delete mode 100644 tests/indexer/git_indexer_new.phpt delete mode 100644 tests/merge/git_merge.phpt delete mode 100644 tests/merge/git_merge_base.phpt delete mode 100644 tests/merge/git_merge_base_many.phpt delete mode 100644 tests/merge/git_merge_head_free.phpt delete mode 100644 tests/merge/git_merge_head_from_fetchhead.phpt delete mode 100644 tests/merge/git_merge_head_from_oid.phpt delete mode 100644 tests/merge/git_merge_head_from_ref.phpt delete mode 100644 tests/merge/git_merge_result_fastforward_oid.phpt delete mode 100644 tests/merge/git_merge_result_free.phpt delete mode 100644 tests/merge/git_merge_result_is_fastforward.phpt delete mode 100644 tests/merge/git_merge_result_is_uptodate.phpt delete mode 100644 tests/merge/git_merge_trees.phpt delete mode 100644 tests/object/git_object__size.phpt delete mode 100644 tests/object/git_object_dup.phpt delete mode 100644 tests/object/git_object_free.phpt delete mode 100644 tests/object/git_object_id.phpt delete mode 100644 tests/object/git_object_lookup.phpt delete mode 100644 tests/object/git_object_lookup_bypath.phpt delete mode 100644 tests/object/git_object_lookup_prefix.phpt delete mode 100644 tests/object/git_object_owner.phpt delete mode 100644 tests/object/git_object_peel.phpt delete mode 100644 tests/object/git_object_string2type.phpt delete mode 100644 tests/object/git_object_type.phpt delete mode 100644 tests/object/git_object_type2string.phpt delete mode 100644 tests/object/git_object_typeisloose.phpt delete mode 100644 tests/patch/git_patch_free.phpt delete mode 100644 tests/patch/git_patch_from_blob_and_buffer.phpt delete mode 100644 tests/patch/git_patch_from_blobs.phpt delete mode 100644 tests/patch/git_patch_from_diff.phpt delete mode 100644 tests/patch/git_patch_get_delta.phpt delete mode 100644 tests/patch/git_patch_get_hunk.phpt delete mode 100644 tests/patch/git_patch_get_line_in_hunk.phpt delete mode 100644 tests/patch/git_patch_line_stats.phpt delete mode 100644 tests/patch/git_patch_num_hunks.phpt delete mode 100644 tests/patch/git_patch_num_lines_in_hunk.phpt delete mode 100644 tests/patch/git_patch_print.phpt delete mode 100644 tests/patch/git_patch_size.phpt delete mode 100644 tests/patch/git_patch_to_str.phpt delete mode 100644 tests/pathspec/git_pathspec_free.phpt delete mode 100644 tests/pathspec/git_pathspec_match_diff.phpt delete mode 100644 tests/pathspec/git_pathspec_match_index.phpt delete mode 100644 tests/pathspec/git_pathspec_match_list_diff_entry.phpt delete mode 100644 tests/pathspec/git_pathspec_match_list_entry.phpt delete mode 100644 tests/pathspec/git_pathspec_match_list_entrycount.phpt delete mode 100644 tests/pathspec/git_pathspec_match_list_failed_entry.phpt delete mode 100644 tests/pathspec/git_pathspec_match_list_failed_entrycount.phpt delete mode 100644 tests/pathspec/git_pathspec_match_list_free.phpt delete mode 100644 tests/pathspec/git_pathspec_match_tree.phpt delete mode 100644 tests/pathspec/git_pathspec_match_workdir.phpt delete mode 100644 tests/pathspec/git_pathspec_matches_path.phpt delete mode 100644 tests/pathspec/git_pathspec_new.phpt delete mode 100644 tests/reference/git_reference_cmp.phpt delete mode 100644 tests/reference/git_reference_create.phpt delete mode 100644 tests/reference/git_reference_delete.phpt delete mode 100644 tests/reference/git_reference_dwim.phpt delete mode 100644 tests/reference/git_reference_foreach.phpt delete mode 100644 tests/reference/git_reference_foreach_glob.phpt delete mode 100644 tests/reference/git_reference_foreach_name.phpt delete mode 100644 tests/reference/git_reference_free.phpt delete mode 100644 tests/reference/git_reference_has_log.phpt delete mode 100644 tests/reference/git_reference_is_branch.phpt delete mode 100644 tests/reference/git_reference_is_remote.phpt delete mode 100644 tests/reference/git_reference_is_tag.phpt delete mode 100644 tests/reference/git_reference_is_valid_name.phpt delete mode 100644 tests/reference/git_reference_iterator_free.phpt delete mode 100644 tests/reference/git_reference_iterator_glob_new.phpt delete mode 100644 tests/reference/git_reference_iterator_new.phpt delete mode 100644 tests/reference/git_reference_list.phpt delete mode 100644 tests/reference/git_reference_lookup.phpt delete mode 100644 tests/reference/git_reference_name.phpt delete mode 100644 tests/reference/git_reference_name_to_id.phpt delete mode 100644 tests/reference/git_reference_next.phpt delete mode 100644 tests/reference/git_reference_next_name.phpt delete mode 100644 tests/reference/git_reference_normalize_name.phpt delete mode 100644 tests/reference/git_reference_owner.phpt delete mode 100644 tests/reference/git_reference_peel.phpt delete mode 100644 tests/reference/git_reference_rename.phpt delete mode 100644 tests/reference/git_reference_resolve.phpt delete mode 100644 tests/reference/git_reference_set_target.phpt delete mode 100644 tests/reference/git_reference_shorthand.phpt delete mode 100644 tests/reference/git_reference_symbolic_create.phpt delete mode 100644 tests/reference/git_reference_symbolic_set_target.phpt delete mode 100644 tests/reference/git_reference_symbolic_target.phpt delete mode 100644 tests/reference/git_reference_target.phpt delete mode 100644 tests/reference/git_reference_target_peel.phpt delete mode 100644 tests/reference/git_reference_type.phpt delete mode 100644 tests/repository/git_repository_config.phpt delete mode 100644 tests/repository/git_repository_detach_head.phpt delete mode 100644 tests/repository/git_repository_discover.phpt delete mode 100644 tests/repository/git_repository_fetchhead_foreach.phpt delete mode 100644 tests/repository/git_repository_free.phpt delete mode 100644 tests/repository/git_repository_get_namespace.phpt delete mode 100644 tests/repository/git_repository_hashfile.phpt delete mode 100644 tests/repository/git_repository_head.phpt delete mode 100644 tests/repository/git_repository_head_detached.phpt delete mode 100644 tests/repository/git_repository_head_unborn.phpt delete mode 100644 tests/repository/git_repository_index.phpt delete mode 100644 tests/repository/git_repository_init.phpt delete mode 100644 tests/repository/git_repository_init_ext.phpt delete mode 100644 tests/repository/git_repository_is_bare.phpt delete mode 100644 tests/repository/git_repository_is_empty.phpt delete mode 100644 tests/repository/git_repository_is_shallow.phpt delete mode 100644 tests/repository/git_repository_merge_cleanup.phpt delete mode 100644 tests/repository/git_repository_mergehead_foreach.phpt delete mode 100644 tests/repository/git_repository_message.phpt delete mode 100644 tests/repository/git_repository_message_remove.phpt delete mode 100644 tests/repository/git_repository_new.phpt delete mode 100644 tests/repository/git_repository_odb.phpt delete mode 100644 tests/repository/git_repository_open.phpt delete mode 100644 tests/repository/git_repository_open_bare.phpt delete mode 100644 tests/repository/git_repository_open_ext.phpt delete mode 100644 tests/repository/git_repository_path.phpt delete mode 100644 tests/repository/git_repository_refdb.phpt delete mode 100644 tests/repository/git_repository_set_head.phpt delete mode 100644 tests/repository/git_repository_set_head_detached.phpt delete mode 100644 tests/repository/git_repository_set_namespace.phpt delete mode 100644 tests/repository/git_repository_set_workdir.phpt delete mode 100644 tests/repository/git_repository_state.phpt delete mode 100644 tests/repository/git_repository_workdir.phpt delete mode 100644 tests/repository/git_repository_wrap_odb.phpt delete mode 100644 tests/revparse/git_revparse.phpt delete mode 100644 tests/revparse/git_revparse_ext.phpt delete mode 100644 tests/revparse/git_revparse_single.phpt delete mode 100644 tests/revwalk/git_revwalk_free.phpt delete mode 100644 tests/revwalk/git_revwalk_hide.phpt delete mode 100644 tests/revwalk/git_revwalk_hide_glob.phpt delete mode 100644 tests/revwalk/git_revwalk_hide_head.phpt delete mode 100644 tests/revwalk/git_revwalk_hide_ref.phpt delete mode 100644 tests/revwalk/git_revwalk_new.phpt delete mode 100644 tests/revwalk/git_revwalk_next.phpt delete mode 100644 tests/revwalk/git_revwalk_push.phpt delete mode 100644 tests/revwalk/git_revwalk_push_glob.phpt delete mode 100644 tests/revwalk/git_revwalk_push_head.phpt delete mode 100644 tests/revwalk/git_revwalk_push_range.phpt delete mode 100644 tests/revwalk/git_revwalk_push_ref.phpt delete mode 100644 tests/revwalk/git_revwalk_repository.phpt delete mode 100644 tests/revwalk/git_revwalk_reset.phpt delete mode 100644 tests/revwalk/git_revwalk_simplify_first_parent.phpt delete mode 100644 tests/revwalk/git_revwalk_sorting.phpt delete mode 100644 tests/status/git_status_byindex.phpt delete mode 100644 tests/status/git_status_file.phpt delete mode 100644 tests/status/git_status_foreach.phpt delete mode 100644 tests/status/git_status_foreach_ext.phpt delete mode 100644 tests/status/git_status_list_entrycount.phpt delete mode 100644 tests/status/git_status_list_free.phpt delete mode 100644 tests/status/git_status_list_new.phpt delete mode 100644 tests/status/git_status_should_ignore.phpt delete mode 100644 tests/tag/git_tag_annotation_create.phpt delete mode 100644 tests/tag/git_tag_create.phpt delete mode 100644 tests/tag/git_tag_create_frombuffer.phpt delete mode 100644 tests/tag/git_tag_create_lightweight.phpt delete mode 100644 tests/tag/git_tag_delete.phpt delete mode 100644 tests/tag/git_tag_foreach.phpt delete mode 100644 tests/tag/git_tag_free.phpt delete mode 100644 tests/tag/git_tag_id.phpt delete mode 100644 tests/tag/git_tag_list.phpt delete mode 100644 tests/tag/git_tag_list_match.phpt delete mode 100644 tests/tag/git_tag_lookup.phpt delete mode 100644 tests/tag/git_tag_lookup_prefix.phpt delete mode 100644 tests/tag/git_tag_message.phpt delete mode 100644 tests/tag/git_tag_name.phpt delete mode 100644 tests/tag/git_tag_owner.phpt delete mode 100644 tests/tag/git_tag_peel.phpt delete mode 100644 tests/tag/git_tag_tagger.phpt delete mode 100644 tests/tag/git_tag_target.phpt delete mode 100644 tests/tag/git_tag_target_id.phpt delete mode 100644 tests/tag/git_tag_target_type.phpt delete mode 100644 tests/transport/git_smart_subtransport_git.phpt delete mode 100644 tests/transport/git_smart_subtransport_http.phpt delete mode 100644 tests/transport/git_smart_subtransport_ssh.phpt delete mode 100644 tests/transport/git_transport_dummy.phpt delete mode 100644 tests/transport/git_transport_local.phpt delete mode 100644 tests/transport/git_transport_new.phpt delete mode 100644 tests/transport/git_transport_register.phpt delete mode 100644 tests/transport/git_transport_smart.phpt delete mode 100644 tests/transport/git_transport_unregister.phpt delete mode 100644 tests/tree/git_tree_entry_byindex.phpt delete mode 100644 tests/tree/git_tree_entry_byname.phpt delete mode 100644 tests/tree/git_tree_entry_byoid.phpt delete mode 100644 tests/tree/git_tree_entry_bypath.phpt delete mode 100644 tests/tree/git_tree_entry_cmp.phpt delete mode 100644 tests/tree/git_tree_entry_dup.phpt delete mode 100644 tests/tree/git_tree_entry_filemode.phpt delete mode 100644 tests/tree/git_tree_entry_filemode_raw.phpt delete mode 100644 tests/tree/git_tree_entry_free.phpt delete mode 100644 tests/tree/git_tree_entry_id.phpt delete mode 100644 tests/tree/git_tree_entry_name.phpt delete mode 100644 tests/tree/git_tree_entry_type.phpt delete mode 100644 tests/tree/git_tree_entrycount.phpt delete mode 100644 tests/tree/git_tree_free.phpt delete mode 100644 tests/tree/git_tree_id.phpt delete mode 100644 tests/tree/git_tree_lookup.phpt delete mode 100644 tests/tree/git_tree_owner.phpt delete mode 100644 tests/tree/git_tree_walk.phpt delete mode 100644 tests/treebuilder/git_treebuilder_clear.phpt delete mode 100644 tests/treebuilder/git_treebuilder_create.phpt delete mode 100644 tests/treebuilder/git_treebuilder_entrycount.phpt delete mode 100644 tests/treebuilder/git_treebuilder_filter.phpt delete mode 100644 tests/treebuilder/git_treebuilder_free.phpt delete mode 100644 tests/treebuilder/git_treebuilder_get.phpt delete mode 100644 tests/treebuilder/git_treebuilder_insert.phpt delete mode 100644 tests/treebuilder/git_treebuilder_remove.phpt delete mode 100644 tests/treebuilder/git_treebuilder_write.phpt diff --git a/tests/blob/git_blob_create_fromchunks.phpt b/tests/blob/git_blob_create_fromchunks.phpt deleted file mode 100644 index 2226cd4f39..0000000000 --- a/tests/blob/git_blob_create_fromchunks.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -Check for git_blob_create_fromchunks presence ---SKIPIF-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - Date: Mon, 13 Jan 2014 05:11:58 +0900 Subject: [PATCH 052/136] add stub codes --- blame.c | 138 ++++++++++++++++++++++++ blame.h | 83 +++++++++++++++ config.m4 | 2 +- ng.php | 16 ++- packbuilder.c | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++ packbuilder.h | 137 ++++++++++++++++++++++++ php_git2.c | 2 + php_git2.h | 4 + 8 files changed, 662 insertions(+), 2 deletions(-) create mode 100644 blame.c create mode 100644 blame.h create mode 100644 packbuilder.c create mode 100644 packbuilder.h diff --git a/blame.c b/blame.c new file mode 100644 index 0000000000..fee8f31a50 --- /dev/null +++ b/blame.c @@ -0,0 +1,138 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "blame.h" + +/* {{{ proto long git_blame_get_hunk_count(resource $blame) + */ +PHP_FUNCTION(git_blame_get_hunk_count) +{ + uint32_t result = 0; + zval *blame = NULL; + php_git2_t *_blame = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blame) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_blame_get_hunk_count(PHP_GIT2_V(_blame, blame)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_blame_get_hunk_byindex(resource $blame, long $index) + */ +PHP_FUNCTION(git_blame_get_hunk_byindex) +{ + const git_blame_hunk *result = NULL; + zval *blame = NULL; + php_git2_t *_blame = NULL; + long index = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &blame, &index) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_blame_get_hunk_byindex(PHP_GIT2_V(_blame, blame), index); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto resource git_blame_get_hunk_byline(resource $blame, long $lineno) + */ +PHP_FUNCTION(git_blame_get_hunk_byline) +{ + const git_blame_hunk *result = NULL; + zval *blame = NULL; + php_git2_t *_blame = NULL; + long lineno = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &blame, &lineno) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_blame_get_hunk_byline(PHP_GIT2_V(_blame, blame), lineno); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto resource git_blame_file(resource $repo, string $path, $options) + */ +PHP_FUNCTION(git_blame_file) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_blame *out = NULL; + zval *repo = NULL, *options = NULL; + char *path = NULL; + int path_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &path, &path_len, &options) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_blame_file(&out, PHP_GIT2_V(_repo, repository), path, options); + if (php_git2_check_error(error, "git_blame_file" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BLAME, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto resource git_blame_buffer(resource $reference, string $buffer) + */ +PHP_FUNCTION(git_blame_buffer) +{ + php_git2_t *result = NULL, *_reference = NULL; + git_blame *out = NULL; + zval *reference = NULL; + char *buffer = NULL; + int buffer_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &reference, &buffer, &buffer_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_reference, php_git2_t*, &reference, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_blame_buffer(&out, PHP_GIT2_V(_reference, blame), buffer, buffer_len); + if (php_git2_check_error(error, "git_blame_buffer" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BLAME, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto void git_blame_free(resource $blame) + */ +PHP_FUNCTION(git_blame_free) +{ + zval *blame = NULL; + php_git2_t *_blame = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &blame) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_blame)) { + git_blame_free(PHP_GIT2_V(_blame, blame)); + GIT2_SHOULD_FREE(_blame) = 0; + }; + zval_ptr_dtor(&blame); +} +/* }}} */ + diff --git a/blame.h b/blame.h new file mode 100644 index 0000000000..19a1ef7cff --- /dev/null +++ b/blame.h @@ -0,0 +1,83 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_BLAME_H +#define PHP_GIT2_BLAME_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_get_hunk_count, 0, 0, 1) + ZEND_ARG_INFO(0, blame) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_get_hunk_byindex, 0, 0, 2) + ZEND_ARG_INFO(0, blame) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_get_hunk_byline, 0, 0, 2) + ZEND_ARG_INFO(0, blame) + ZEND_ARG_INFO(0, lineno) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_file, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_buffer, 0, 0, 3) + ZEND_ARG_INFO(0, reference) + ZEND_ARG_INFO(0, buffer) + ZEND_ARG_INFO(0, buffer_len) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_free, 0, 0, 1) + ZEND_ARG_INFO(0, blame) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_blame_get_hunk_count(blame) +*/ +PHP_FUNCTION(git_blame_get_hunk_count); + +/* {{{ proto resource git_blame_get_hunk_byindex(blame, index) +*/ +PHP_FUNCTION(git_blame_get_hunk_byindex); + +/* {{{ proto resource git_blame_get_hunk_byline(blame, lineno) +*/ +PHP_FUNCTION(git_blame_get_hunk_byline); + +/* {{{ proto resource git_blame_file(repo, path, options) +*/ +PHP_FUNCTION(git_blame_file); + +/* {{{ proto resource git_blame_buffer(reference, buffer, buffer_len) +*/ +PHP_FUNCTION(git_blame_buffer); + +/* {{{ proto void git_blame_free(blame) +*/ +PHP_FUNCTION(git_blame_free); + +#endif \ No newline at end of file diff --git a/config.m4 b/config.m4 index 9f57e70e0d..157bd8f3e9 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/ng.php b/ng.php index a6a1ed950b..5a726d9d97 100644 --- a/ng.php +++ b/ng.php @@ -93,6 +93,9 @@ public function isCallbacker() if (preg_match("/callback$/", $arg->getType())) { return true; } + if (preg_match("/packbuilder_progress/", $arg->getType())) { + return true; + } } return false; @@ -153,7 +156,16 @@ public function getType() public function isCallback() { - return preg_match("/_cb$/", $this->type); + if (preg_match("/_cb$/", $this->getType())) { + return true; + } + if (preg_match("/callback$/", $this->getType())) { + return true; + } + if (preg_match("/packbuilder_progress/", $this->getType())) { + return true; + } + return false; } public function getPtr() @@ -375,6 +387,8 @@ public function shouldResource(Arg $arg) "struct git_odb", "git_reflog", "git_reflog_entry", + "git_blame", + "git_packbuilder", ); } diff --git a/packbuilder.c b/packbuilder.c new file mode 100644 index 0000000000..4c4e04008e --- /dev/null +++ b/packbuilder.c @@ -0,0 +1,282 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "packbuilder.h" + +/* {{{ proto resource git_packbuilder_new(resource $repo) + */ +PHP_FUNCTION(git_packbuilder_new) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_packbuilder *out = NULL; + zval *repo = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_packbuilder_new(&out, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_packbuilder_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PACKBUILDER, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_set_threads(resource $pb, long $n) + */ +PHP_FUNCTION(git_packbuilder_set_threads) +{ + unsigned int result = 0; + zval *pb = NULL; + php_git2_t *_pb = NULL; + long n = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &pb, &n) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_packbuilder_set_threads(PHP_GIT2_V(_pb, packbuilder), n); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_insert(resource $pb, string $id, string $name) + */ +PHP_FUNCTION(git_packbuilder_insert) +{ + int result = 0, id_len = 0, name_len = 0, error = 0; + zval *pb = NULL; + php_git2_t *_pb = NULL; + char *id = NULL, *name = NULL; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &pb, &id, &id_len, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_packbuilder_insert(PHP_GIT2_V(_pb, packbuilder), &__id, name); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_insert_tree(resource $pb, string $id) + */ +PHP_FUNCTION(git_packbuilder_insert_tree) +{ + int result = 0, id_len = 0, error = 0; + zval *pb = NULL; + php_git2_t *_pb = NULL; + char *id = NULL; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &pb, &id, &id_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_packbuilder_insert_tree(PHP_GIT2_V(_pb, packbuilder), &__id); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_insert_commit(resource $pb, string $id) + */ +PHP_FUNCTION(git_packbuilder_insert_commit) +{ + int result = 0, id_len = 0, error = 0; + zval *pb = NULL; + php_git2_t *_pb = NULL; + char *id = NULL; + git_oid __id = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &pb, &id, &id_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_packbuilder_insert_commit(PHP_GIT2_V(_pb, packbuilder), &__id); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_write(resource $pb, string $path, long $mode, $progress_cb, $progress_cb_payload) + */ +PHP_FUNCTION(git_packbuilder_write) +{ + int result = 0, path_len = 0, error = 0; + zval *pb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL; + php_git2_t *_pb = NULL; + char *path = NULL; + long mode = 0; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rslfz", &pb, &path, &path_len, &mode, &fci, &fcc, &progress_cb_payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, progress_cb_payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_packbuilder_write(PHP_GIT2_V(_pb, packbuilder), path, mode, , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_packbuilder_hash(resource $pb) + */ +PHP_FUNCTION(git_packbuilder_hash) +{ + const git_oid *result = NULL; + zval *pb = NULL; + php_git2_t *_pb = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &pb) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_packbuilder_hash(PHP_GIT2_V(_pb, packbuilder)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_foreach(resource $pb, Callable $cb, $payload) + */ +PHP_FUNCTION(git_packbuilder_foreach) +{ + int result = 0, error = 0; + zval *pb = NULL, *payload = NULL; + php_git2_t *_pb = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfz", &pb, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_packbuilder_foreach(PHP_GIT2_V(_pb, packbuilder), , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_object_count(resource $pb) + */ +PHP_FUNCTION(git_packbuilder_object_count) +{ + uint32_t result = 0; + zval *pb = NULL; + php_git2_t *_pb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &pb) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_packbuilder_object_count(PHP_GIT2_V(_pb, packbuilder)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_written(resource $pb) + */ +PHP_FUNCTION(git_packbuilder_written) +{ + uint32_t result = 0; + zval *pb = NULL; + php_git2_t *_pb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &pb) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_packbuilder_written(PHP_GIT2_V(_pb, packbuilder)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_packbuilder_set_callbacks(resource $pb, $progress_cb, $progress_cb_payload) + */ +PHP_FUNCTION(git_packbuilder_set_callbacks) +{ + int result = 0, error = 0; + zval *pb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL; + php_git2_t *_pb = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfz", &pb, &fci, &fcc, &progress_cb_payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, progress_cb_payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_packbuilder_set_callbacks(PHP_GIT2_V(_pb, packbuilder), , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto void git_packbuilder_free(resource $pb) + */ +PHP_FUNCTION(git_packbuilder_free) +{ + zval *pb = NULL; + php_git2_t *_pb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &pb) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_pb)) { + git_packbuilder_free(PHP_GIT2_V(_pb, packbuilder)); + GIT2_SHOULD_FREE(_pb) = 0; + }; + zval_ptr_dtor(&pb); +} +/* }}} */ + diff --git a/packbuilder.h b/packbuilder.h new file mode 100644 index 0000000000..3337b9e788 --- /dev/null +++ b/packbuilder.h @@ -0,0 +1,137 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_PACKBUILDER_H +#define PHP_GIT2_PACKBUILDER_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_new, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_set_threads, 0, 0, 2) + ZEND_ARG_INFO(0, pb) + ZEND_ARG_INFO(0, n) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_insert, 0, 0, 3) + ZEND_ARG_INFO(0, pb) + ZEND_ARG_INFO(0, id) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_insert_tree, 0, 0, 2) + ZEND_ARG_INFO(0, pb) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_insert_commit, 0, 0, 2) + ZEND_ARG_INFO(0, pb) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_write, 0, 0, 4) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, mode) + ZEND_ARG_INFO(0, progress_cb) + ZEND_ARG_INFO(0, progress_cb_payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_hash, 0, 0, 1) + ZEND_ARG_INFO(0, pb) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, pb) + ZEND_ARG_INFO(0, cb) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_object_count, 0, 0, 1) + ZEND_ARG_INFO(0, pb) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_written, 0, 0, 1) + ZEND_ARG_INFO(0, pb) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_set_callbacks, 0, 0, 3) + ZEND_ARG_INFO(0, pb) + ZEND_ARG_INFO(0, progress_cb) + ZEND_ARG_INFO(0, progress_cb_payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_free, 0, 0, 1) + ZEND_ARG_INFO(0, pb) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_packbuilder_new(repo) +*/ +PHP_FUNCTION(git_packbuilder_new); + +/* {{{ proto resource git_packbuilder_set_threads(pb, n) +*/ +PHP_FUNCTION(git_packbuilder_set_threads); + +/* {{{ proto long git_packbuilder_insert(pb, id, name) +*/ +PHP_FUNCTION(git_packbuilder_insert); + +/* {{{ proto long git_packbuilder_insert_tree(pb, id) +*/ +PHP_FUNCTION(git_packbuilder_insert_tree); + +/* {{{ proto long git_packbuilder_insert_commit(pb, id) +*/ +PHP_FUNCTION(git_packbuilder_insert_commit); + +/* {{{ proto resource git_packbuilder_write(path, mode, progress_cb, progress_cb_payload) +*/ +PHP_FUNCTION(git_packbuilder_write); + +/* {{{ proto resource git_packbuilder_hash(pb) +*/ +PHP_FUNCTION(git_packbuilder_hash); + +/* {{{ proto long git_packbuilder_foreach(pb, cb, payload) +*/ +PHP_FUNCTION(git_packbuilder_foreach); + +/* {{{ proto resource git_packbuilder_object_count(pb) +*/ +PHP_FUNCTION(git_packbuilder_object_count); + +/* {{{ proto resource git_packbuilder_written(pb) +*/ +PHP_FUNCTION(git_packbuilder_written); + +/* {{{ proto long git_packbuilder_set_callbacks(pb, progress_cb, progress_cb_payload) +*/ +PHP_FUNCTION(git_packbuilder_set_callbacks); + +/* {{{ proto void git_packbuilder_free(pb) +*/ +PHP_FUNCTION(git_packbuilder_free); + +#endif diff --git a/php_git2.c b/php_git2.c index 8d9b0fcad1..9e75af678e 100644 --- a/php_git2.c +++ b/php_git2.c @@ -54,6 +54,8 @@ #include "note.h" #include "odb.h" #include "reflog.h" +#include "blame.h" +#include "packbuilder.h" int git2_resource_handle; diff --git a/php_git2.h b/php_git2.h index 643ff687fd..94134b338e 100644 --- a/php_git2.h +++ b/php_git2.h @@ -120,6 +120,8 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_ODB_BACKEND, PHP_GIT2_TYPE_REFLOG, PHP_GIT2_TYPE_REFLOG_ENTRY, + PHP_GIT2_TYPE_BLAME, + PHP_GIT2_TYPE_PACKBUILDER, }; typedef struct php_git2_t { @@ -167,6 +169,8 @@ typedef struct php_git2_t { git_odb_backend *odb_backend; git_reflog *reflog; git_reflog_entry *reflog_entry; + git_blame *blame; + git_packbuilder *packbuilder; } v; int should_free_v; int resource_id; From a1e34775699582fecf1ddfbef6f30bbf93c20140 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 05:18:43 +0900 Subject: [PATCH 053/136] add stash stub code --- config.m4 | 2 +- php_git2.c | 20 ++++++++++++++ stash.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ stash.h | 59 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 stash.c create mode 100644 stash.h diff --git a/config.m4 b/config.m4 index 157bd8f3e9..f77d983345 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/php_git2.c b/php_git2.c index 9e75af678e..70eb90e3dc 100644 --- a/php_git2.c +++ b/php_git2.c @@ -56,6 +56,7 @@ #include "reflog.h" #include "blame.h" #include "packbuilder.h" +#include "stash.h" int git2_resource_handle; @@ -776,6 +777,25 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_reflog_entry_message, arginfo_git_reflog_entry_message) PHP_FE(git_reflog_free, arginfo_git_reflog_free) + /* packbuilder */ + PHP_FE(git_packbuilder_new, arginfo_git_packbuilder_new) + PHP_FE(git_packbuilder_set_threads, arginfo_git_packbuilder_set_threads) + PHP_FE(git_packbuilder_insert, arginfo_git_packbuilder_insert) + PHP_FE(git_packbuilder_insert_tree, arginfo_git_packbuilder_insert_tree) + PHP_FE(git_packbuilder_insert_commit, arginfo_git_packbuilder_insert_commit) + PHP_FE(git_packbuilder_write, arginfo_git_packbuilder_write) + PHP_FE(git_packbuilder_hash, arginfo_git_packbuilder_hash) + PHP_FE(git_packbuilder_foreach, arginfo_git_packbuilder_foreach) + PHP_FE(git_packbuilder_object_count, arginfo_git_packbuilder_object_count) + PHP_FE(git_packbuilder_written, arginfo_git_packbuilder_written) + PHP_FE(git_packbuilder_set_callbacks, arginfo_git_packbuilder_set_callbacks) + PHP_FE(git_packbuilder_free, arginfo_git_packbuilder_free) + + /* stash */ + PHP_FE(git_stash_save, arginfo_git_stash_save) + PHP_FE(git_stash_foreach, arginfo_git_stash_foreach) + PHP_FE(git_stash_drop, arginfo_git_stash_drop) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/stash.c b/stash.c new file mode 100644 index 0000000000..6330e75cb0 --- /dev/null +++ b/stash.c @@ -0,0 +1,77 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "stash.h" + +/* {{{ proto resource git_stash_save(resource $repo, array $stasher, string $message, long $flags) + */ +PHP_FUNCTION(git_stash_save) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_oid out = {0}; + zval *repo = NULL, *stasher = NULL; + char *message = NULL; + int message_len = 0, error = 0; + long flags = 0; + char buf[41] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rasl", &repo, &stasher, &message, &message_len, &flags) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_stash_save(&out, PHP_GIT2_V(_repo, repository), stasher, message, flags); + if (php_git2_check_error(error, "git_stash_save" TSRMLS_CC)) { + RETURN_FALSE; + } + git_oid_fmt(buf, &out); + RETURN_STRING(buf, 1); +} +/* }}} */ + +/* {{{ proto long git_stash_foreach(resource $repo, Callable $callback, $payload) + */ +PHP_FUNCTION(git_stash_foreach) +{ + int result = 0, error = 0; + zval *repo = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_stash_foreach(PHP_GIT2_V(_repo, repository), , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_stash_drop(resource $repo, long $index) + */ +PHP_FUNCTION(git_stash_drop) +{ + int result = 0, error = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + long index = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &repo, &index) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_stash_drop(PHP_GIT2_V(_repo, repository), index); + RETURN_LONG(result); +} +/* }}} */ + diff --git a/stash.h b/stash.h new file mode 100644 index 0000000000..cf49997b17 --- /dev/null +++ b/stash.h @@ -0,0 +1,59 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_STASH_H +#define PHP_GIT2_STASH_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_save, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, stasher) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_foreach, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_drop, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_stash_save(repo, stasher, message, flags) +*/ +PHP_FUNCTION(git_stash_save); + +/* {{{ proto long git_stash_foreach(repo, callback, payload) +*/ +PHP_FUNCTION(git_stash_foreach); + +/* {{{ proto long git_stash_drop(repo, index) +*/ +PHP_FUNCTION(git_stash_drop); + +#endif \ No newline at end of file From 605af014ef99d21fc1ebc35bf4821985aeeaa868 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 05:25:03 +0900 Subject: [PATCH 054/136] add signature --- config.m4 | 2 +- php_git2.c | 8 ++++ signature.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ signature.h | 73 +++++++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 signature.c create mode 100644 signature.h diff --git a/config.m4 b/config.m4 index f77d983345..2899072329 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/php_git2.c b/php_git2.c index 70eb90e3dc..e7ee9ab230 100644 --- a/php_git2.c +++ b/php_git2.c @@ -57,6 +57,7 @@ #include "blame.h" #include "packbuilder.h" #include "stash.h" +#include "signature.h" int git2_resource_handle; @@ -796,6 +797,13 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_stash_foreach, arginfo_git_stash_foreach) PHP_FE(git_stash_drop, arginfo_git_stash_drop) + /* signature */ + PHP_FE(git_signature_new, arginfo_git_signature_new) + PHP_FE(git_signature_now, arginfo_git_signature_now) + PHP_FE(git_signature_default, arginfo_git_signature_default) + PHP_FE(git_signature_dup, arginfo_git_signature_dup) + PHP_FE(git_signature_free, arginfo_git_signature_free) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/signature.c b/signature.c new file mode 100644 index 0000000000..f8a8cca4e4 --- /dev/null +++ b/signature.c @@ -0,0 +1,107 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "signature.h" + +/* {{{ proto resource git_signature_new(string $name, string $email, $time, long $offset) + */ +PHP_FUNCTION(git_signature_new) +{ + php_git2_t *result = NULL; + git_signature *out = NULL; + char *name = NULL, *email = NULL; + int name_len = 0, email_len = 0, error = 0; + zval *time = NULL; + long offset = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ssal", &name, &name_len, &email, &email_len, &time, &offset) == FAILURE) { + return; + } + + error = git_signature_new(&out, name, email, time, offset); + if (php_git2_check_error(error, "git_signature_new" TSRMLS_CC)) { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto resource git_signature_now(string $name, string $email) + */ +PHP_FUNCTION(git_signature_now) +{ + php_git2_t *result = NULL; + git_signature *out = NULL; + char *name = NULL, *email = NULL; + int name_len = 0, email_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ss", &name, &name_len, &email, &email_len) == FAILURE) { + return; + } + + error = git_signature_now(&out, name, email); + if (php_git2_check_error(error, "git_signature_now" TSRMLS_CC)) { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto resource git_signature_default(resource $repo) + */ +PHP_FUNCTION(git_signature_default) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_signature *out = NULL; + zval *repo = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_signature_default(&out, PHP_GIT2_V(_repo, repository)); + if (php_git2_check_error(error, "git_signature_default" TSRMLS_CC)) { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto array git_signature_dup(array $sig) + */ +PHP_FUNCTION(git_signature_dup) +{ + git_signature *result = NULL; + zval *__result = NULL, *sig = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "a", &sig) == FAILURE) { + return; + } + + result = git_signature_dup(sig); + php_git2_signature_to_array(result, &__result TSRMLS_CC); + RETURN_ZVAL(__result, 0, 1); +} +/* }}} */ + +/* {{{ proto void git_signature_free(array $sig) + */ +PHP_FUNCTION(git_signature_free) +{ +// zval *sig = NULL; +// +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "a", &sig) == FAILURE) { +// return; +// } +// +// if (GIT2_SHOULD_FREE(_sig)) { +// git_signature_free(sig); +// GIT2_SHOULD_FREE(_sig) = 0; +// }; +// zval_ptr_dtor(&sig); +} +/* }}} */ + diff --git a/signature.h b/signature.h new file mode 100644 index 0000000000..71be5b503e --- /dev/null +++ b/signature.h @@ -0,0 +1,73 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_SIGNATURE_H +#define PHP_GIT2_SIGNATURE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_new, 0, 0, 4) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, email) + ZEND_ARG_INFO(0, time) + ZEND_ARG_INFO(0, offset) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_now, 0, 0, 2) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, email) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_default, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_dup, 0, 0, 1) + ZEND_ARG_INFO(0, sig) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_free, 0, 0, 1) + ZEND_ARG_INFO(0, sig) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_signature_new(name, email, time, offset) +*/ +PHP_FUNCTION(git_signature_new); + +/* {{{ proto resource git_signature_now(name, email) +*/ +PHP_FUNCTION(git_signature_now); + +/* {{{ proto resource git_signature_default(repo) +*/ +PHP_FUNCTION(git_signature_default); + +/* {{{ proto resource git_signature_dup(sig) +*/ +PHP_FUNCTION(git_signature_dup); + +/* {{{ proto void git_signature_free(sig) +*/ +PHP_FUNCTION(git_signature_free); + +#endif \ No newline at end of file From 323f805c8abbd4a5fbb53d320f9a46fecc2b94a3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 05:29:45 +0900 Subject: [PATCH 055/136] add reset --- config.m4 | 2 +- php_git2.c | 5 +++++ reset.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ reset.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 reset.c create mode 100644 reset.h diff --git a/config.m4 b/config.m4 index 2899072329..1cda9466af 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c reset.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/php_git2.c b/php_git2.c index e7ee9ab230..78c497b56b 100644 --- a/php_git2.c +++ b/php_git2.c @@ -58,6 +58,7 @@ #include "packbuilder.h" #include "stash.h" #include "signature.h" +#include "reset.h" int git2_resource_handle; @@ -804,6 +805,10 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_signature_dup, arginfo_git_signature_dup) PHP_FE(git_signature_free, arginfo_git_signature_free) + /* reset */ + PHP_FE(git_reset, arginfo_git_reset) + PHP_FE(git_reset_default, arginfo_git_reset_default) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/reset.c b/reset.c new file mode 100644 index 0000000000..eb5b5cf5e6 --- /dev/null +++ b/reset.c @@ -0,0 +1,44 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "reset.h" + +/* {{{ proto long git_reset(resource $repo, resource $target, $reset_type) + */ +PHP_FUNCTION(git_reset) +{ + int result = 0, error = 0; + zval *repo = NULL, *target = NULL, *reset_type = NULL; + php_git2_t *_repo = NULL, *_target = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &target, &reset_type) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reset(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_target, object), reset_type); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_reset_default(resource $repo, resource $target, array $pathspecs) + */ +PHP_FUNCTION(git_reset_default) +{ + int result = 0, error = 0; + zval *repo = NULL, *target = NULL, *pathspecs = NULL; + php_git2_t *_repo = NULL, *_target = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rra", &repo, &target, &pathspecs) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reset_default(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_target, object), pathspecs); + RETURN_LONG(result); +} +/* }}} */ + diff --git a/reset.h b/reset.h new file mode 100644 index 0000000000..4c1dabfc91 --- /dev/null +++ b/reset.h @@ -0,0 +1,49 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_RESET_H +#define PHP_GIT2_RESET_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reset, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, reset_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reset_default, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, target) + ZEND_ARG_INFO(0, pathspecs) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_reset(repo, target, reset_type) +*/ +PHP_FUNCTION(git_reset); + +/* {{{ proto long git_reset_default(repo, target, pathspecs) +*/ +PHP_FUNCTION(git_reset_default); + +#endif \ No newline at end of file From 20ebb6889333d3c9d72bc9563315d8e371a44bbc Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 05:32:29 +0900 Subject: [PATCH 056/136] add message --- config.m4 | 2 +- message.c | 26 ++++++++++++++++++++++++++ message.h | 39 +++++++++++++++++++++++++++++++++++++++ php_git2.c | 4 ++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 message.c create mode 100644 message.h diff --git a/config.m4 b/config.m4 index 1cda9466af..41658fbe79 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c reset.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c reset.c message.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/message.c b/message.c new file mode 100644 index 0000000000..ef78db7b0f --- /dev/null +++ b/message.c @@ -0,0 +1,26 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "message.h" + +/* {{{ proto resource git_message_prettify(long $out_size, string $message, long $strip_comments) + */ +PHP_FUNCTION(git_message_prettify) +{ + php_git2_t *result = NULL; + char out = NULL, *message = NULL; + long out_size = 0, strip_comments = 0; + int message_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lsl", &out_size, &message, &message_len, &strip_comments) == FAILURE) { + return; + } + + error = git_message_prettify(&out, out_size, message, strip_comments); + if (php_git2_check_error(error, "git_message_prettify" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(out, 1); +} +/* }}} */ + diff --git a/message.h b/message.h new file mode 100644 index 0000000000..0b40007b40 --- /dev/null +++ b/message.h @@ -0,0 +1,39 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_MESSAGE_H +#define PHP_GIT2_MESSAGE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_message_prettify, 0, 0, 3) + ZEND_ARG_INFO(0, out_size) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, strip_comments) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_message_prettify(out_size, message, strip_comments) +*/ +PHP_FUNCTION(git_message_prettify); + +#endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 78c497b56b..391d970bc5 100644 --- a/php_git2.c +++ b/php_git2.c @@ -59,6 +59,7 @@ #include "stash.h" #include "signature.h" #include "reset.h" +#include "message.h" int git2_resource_handle; @@ -809,6 +810,9 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_reset, arginfo_git_reset) PHP_FE(git_reset_default, arginfo_git_reset_default) + /* message */ + PHP_FE(git_message_prettify, arginfo_git_message_prettify) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END From 30871d9510d6c4decdf2279c886c99c41802697d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 05:38:23 +0900 Subject: [PATCH 057/136] add submodule --- config.m4 | 2 +- ng.php | 1 + php_git2.c | 30 +++ php_git2.h | 2 + submodule.c | 540 ++++++++++++++++++++++++++++++++++++++++++++++++++++ submodule.h | 260 +++++++++++++++++++++++++ 6 files changed, 834 insertions(+), 1 deletion(-) create mode 100644 submodule.c create mode 100644 submodule.h diff --git a/config.m4 b/config.m4 index 41658fbe79..e95ff4f996 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c reset.c message.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c reset.c message.c submodule.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/ng.php b/ng.php index 5a726d9d97..844838d32c 100644 --- a/ng.php +++ b/ng.php @@ -389,6 +389,7 @@ public function shouldResource(Arg $arg) "git_reflog_entry", "git_blame", "git_packbuilder", + "git_submodule", ); } diff --git a/php_git2.c b/php_git2.c index 391d970bc5..dad263ea3a 100644 --- a/php_git2.c +++ b/php_git2.c @@ -60,6 +60,7 @@ #include "signature.h" #include "reset.h" #include "message.h" +#include "submodule.h" int git2_resource_handle; @@ -813,6 +814,35 @@ static zend_function_entry php_git2_functions[] = { /* message */ PHP_FE(git_message_prettify, arginfo_git_message_prettify) + /* submodule */ + PHP_FE(git_submodule_lookup, arginfo_git_submodule_lookup) + PHP_FE(git_submodule_foreach, arginfo_git_submodule_foreach) + PHP_FE(git_submodule_add_setup, arginfo_git_submodule_add_setup) + PHP_FE(git_submodule_add_finalize, arginfo_git_submodule_add_finalize) + PHP_FE(git_submodule_add_to_index, arginfo_git_submodule_add_to_index) + PHP_FE(git_submodule_save, arginfo_git_submodule_save) + PHP_FE(git_submodule_owner, arginfo_git_submodule_owner) + PHP_FE(git_submodule_name, arginfo_git_submodule_name) + PHP_FE(git_submodule_path, arginfo_git_submodule_path) + PHP_FE(git_submodule_url, arginfo_git_submodule_url) + PHP_FE(git_submodule_set_url, arginfo_git_submodule_set_url) + PHP_FE(git_submodule_index_id, arginfo_git_submodule_index_id) + PHP_FE(git_submodule_head_id, arginfo_git_submodule_head_id) + PHP_FE(git_submodule_wd_id, arginfo_git_submodule_wd_id) + PHP_FE(git_submodule_ignore, arginfo_git_submodule_ignore) + PHP_FE(git_submodule_set_ignore, arginfo_git_submodule_set_ignore) + PHP_FE(git_submodule_update, arginfo_git_submodule_update) + PHP_FE(git_submodule_set_update, arginfo_git_submodule_set_update) + PHP_FE(git_submodule_fetch_recurse_submodules, arginfo_git_submodule_fetch_recurse_submodules) + PHP_FE(git_submodule_set_fetch_recurse_submodules, arginfo_git_submodule_set_fetch_recurse_submodules) + PHP_FE(git_submodule_init, arginfo_git_submodule_init) + PHP_FE(git_submodule_sync, arginfo_git_submodule_sync) + PHP_FE(git_submodule_open, arginfo_git_submodule_open) + PHP_FE(git_submodule_reload, arginfo_git_submodule_reload) + PHP_FE(git_submodule_reload_all, arginfo_git_submodule_reload_all) + PHP_FE(git_submodule_status, arginfo_git_submodule_status) + PHP_FE(git_submodule_location, arginfo_git_submodule_location) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/php_git2.h b/php_git2.h index 94134b338e..757e80b52c 100644 --- a/php_git2.h +++ b/php_git2.h @@ -122,6 +122,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_REFLOG_ENTRY, PHP_GIT2_TYPE_BLAME, PHP_GIT2_TYPE_PACKBUILDER, + PHP_GIT2_TYPE_SUBMODULE, }; typedef struct php_git2_t { @@ -171,6 +172,7 @@ typedef struct php_git2_t { git_reflog_entry *reflog_entry; git_blame *blame; git_packbuilder *packbuilder; + git_submodule *submodule; } v; int should_free_v; int resource_id; diff --git a/submodule.c b/submodule.c new file mode 100644 index 0000000000..15cea59fd5 --- /dev/null +++ b/submodule.c @@ -0,0 +1,540 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "submodule.h" + +/* {{{ proto long git_submodule_lookup(resource $repo, string $name) + */ +PHP_FUNCTION(git_submodule_lookup) +{ + int result = 0, name_len = 0, error = 0; + git_submodule *submodule = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *name = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &repo, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_lookup(&submodule, PHP_GIT2_V(_repo, repository), name); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_foreach(resource $repo, long $sm, string $name, $payload) + */ +PHP_FUNCTION(git_submodule_foreach) +{ + int result = 0, name_len = 0, error = 0; + zval *repo = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + long sm = 0; + char *name = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rls", &repo, &sm, &name, &name_len, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + //result = git_submodule_foreach(PHP_GIT2_V(_repo, repository), sm, name, cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_add_setup(resource $repo, string $url, string $path, long $use_gitlink) + */ +PHP_FUNCTION(git_submodule_add_setup) +{ + int result = 0, url_len = 0, path_len = 0, error = 0; + git_submodule *submodule = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *url = NULL, *path = NULL; + long use_gitlink = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rssl", &repo, &url, &url_len, &path, &path_len, &use_gitlink) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_add_setup(&submodule, PHP_GIT2_V(_repo, repository), url, path, use_gitlink); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_add_finalize(resource $submodule) + */ +PHP_FUNCTION(git_submodule_add_finalize) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_add_finalize(PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_add_to_index(resource $submodule, long $write_index) + */ +PHP_FUNCTION(git_submodule_add_to_index) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + long write_index = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &submodule, &write_index) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_add_to_index(PHP_GIT2_V(_submodule, submodule), write_index); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_save(resource $submodule) + */ +PHP_FUNCTION(git_submodule_save) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_save(PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_submodule_owner(resource $submodule) + */ +PHP_FUNCTION(git_submodule_owner) +{ + git_repository *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL, *__result = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_owner(PHP_GIT2_V(_submodule, submodule)); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_SUBMODULE, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); +} +/* }}} */ + +/* {{{ proto string git_submodule_name(resource $submodule) + */ +PHP_FUNCTION(git_submodule_name) +{ + const char *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_name(PHP_GIT2_V(_submodule, submodule)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto string git_submodule_path(resource $submodule) + */ +PHP_FUNCTION(git_submodule_path) +{ + const char *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_path(PHP_GIT2_V(_submodule, submodule)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto string git_submodule_url(resource $submodule) + */ +PHP_FUNCTION(git_submodule_url) +{ + const char *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_url(PHP_GIT2_V(_submodule, submodule)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto long git_submodule_set_url(resource $submodule, string $url) + */ +PHP_FUNCTION(git_submodule_set_url) +{ + int result = 0, url_len = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + char *url = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &submodule, &url, &url_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_set_url(PHP_GIT2_V(_submodule, submodule), url); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_submodule_index_id(resource $submodule) + */ +PHP_FUNCTION(git_submodule_index_id) +{ + const git_oid *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_index_id(PHP_GIT2_V(_submodule, submodule)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto resource git_submodule_head_id(resource $submodule) + */ +PHP_FUNCTION(git_submodule_head_id) +{ + const git_oid *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_head_id(PHP_GIT2_V(_submodule, submodule)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto resource git_submodule_wd_id(resource $submodule) + */ +PHP_FUNCTION(git_submodule_wd_id) +{ + const git_oid *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_wd_id(PHP_GIT2_V(_submodule, submodule)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto resource git_submodule_ignore(resource $submodule) + */ +PHP_FUNCTION(git_submodule_ignore) +{ + git_submodule_ignore_t *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_ignore(PHP_GIT2_V(_submodule, submodule)); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto resource git_submodule_set_ignore(resource $submodule, $ignore) + */ +PHP_FUNCTION(git_submodule_set_ignore) +{ + git_submodule_ignore_t *result = NULL; + zval *submodule = NULL, *ignore = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule, &ignore) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_set_ignore(PHP_GIT2_V(_submodule, submodule), ignore); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto resource git_submodule_update(resource $submodule) + */ +PHP_FUNCTION(git_submodule_update) +{ + git_submodule_update_t *result = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_update(PHP_GIT2_V(_submodule, submodule)); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto resource git_submodule_set_update(resource $submodule, $update) + */ +PHP_FUNCTION(git_submodule_set_update) +{ + git_submodule_update_t *result = NULL; + zval *submodule = NULL, *update = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule, &update) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_set_update(PHP_GIT2_V(_submodule, submodule), update); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto long git_submodule_fetch_recurse_submodules(resource $submodule) + */ +PHP_FUNCTION(git_submodule_fetch_recurse_submodules) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_fetch_recurse_submodules(PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_set_fetch_recurse_submodules(resource $submodule, long $fetch_recurse_submodules) + */ +PHP_FUNCTION(git_submodule_set_fetch_recurse_submodules) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + long fetch_recurse_submodules = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &submodule, &fetch_recurse_submodules) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_set_fetch_recurse_submodules(PHP_GIT2_V(_submodule, submodule), fetch_recurse_submodules); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_init(resource $submodule, long $overwrite) + */ +PHP_FUNCTION(git_submodule_init) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + long overwrite = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rl", &submodule, &overwrite) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_init(PHP_GIT2_V(_submodule, submodule), overwrite); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_sync(resource $submodule) + */ +PHP_FUNCTION(git_submodule_sync) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_sync(PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_open(resource $submodule) + */ +PHP_FUNCTION(git_submodule_open) +{ + int result = 0, error = 0; + git_repository *repo = NULL; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_open(&repo, PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_reload(resource $submodule) + */ +PHP_FUNCTION(git_submodule_reload) +{ + int result = 0, error = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_reload(PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_reload_all(resource $repo) + */ +PHP_FUNCTION(git_submodule_reload_all) +{ + int result = 0, error = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_reload_all(PHP_GIT2_V(_repo, repository)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_status(long $status, resource $submodule) + */ +PHP_FUNCTION(git_submodule_status) +{ + int result = 0, error = 0; + long status = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lr", &status, &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_status(status, PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_submodule_location(long $location_status, resource $submodule) + */ +PHP_FUNCTION(git_submodule_location) +{ + int result = 0, error = 0; + long location_status = 0; + zval *submodule = NULL; + php_git2_t *_submodule = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lr", &location_status, &submodule) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_submodule_location(location_status, PHP_GIT2_V(_submodule, submodule)); + RETURN_LONG(result); +} +/* }}} */ + diff --git a/submodule.h b/submodule.h new file mode 100644 index 0000000000..ca48b7810f --- /dev/null +++ b/submodule.h @@ -0,0 +1,260 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_SUBMODULE_H +#define PHP_GIT2_SUBMODULE_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_lookup, 0, 0, 2) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_foreach, 0, 0, 5) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, sm) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_add_setup, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, url) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, use_gitlink) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_add_finalize, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_add_to_index, 0, 0, 2) + ZEND_ARG_INFO(0, submodule) + ZEND_ARG_INFO(0, write_index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_save, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_owner, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_name, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_path, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_url, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_set_url, 0, 0, 2) + ZEND_ARG_INFO(0, submodule) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_index_id, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_head_id, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_wd_id, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_ignore, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_set_ignore, 0, 0, 2) + ZEND_ARG_INFO(0, submodule) + ZEND_ARG_INFO(0, ignore) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_update, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_set_update, 0, 0, 2) + ZEND_ARG_INFO(0, submodule) + ZEND_ARG_INFO(0, update) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_fetch_recurse_submodules, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_set_fetch_recurse_submodules, 0, 0, 2) + ZEND_ARG_INFO(0, submodule) + ZEND_ARG_INFO(0, fetch_recurse_submodules) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_init, 0, 0, 2) + ZEND_ARG_INFO(0, submodule) + ZEND_ARG_INFO(0, overwrite) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_sync, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_open, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_reload, 0, 0, 1) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_reload_all, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_status, 0, 0, 2) + ZEND_ARG_INFO(0, status) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_location, 0, 0, 2) + ZEND_ARG_INFO(0, location_status) + ZEND_ARG_INFO(0, submodule) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_submodule_lookup(repo, name) +*/ +PHP_FUNCTION(git_submodule_lookup); + +/* {{{ proto long git_submodule_foreach(repo, sm, name, payload), payload) +*/ +PHP_FUNCTION(git_submodule_foreach); + +/* {{{ proto resource git_submodule_add_setup(repo, url, path, use_gitlink) +*/ +PHP_FUNCTION(git_submodule_add_setup); + +/* {{{ proto long git_submodule_add_finalize(submodule) +*/ +PHP_FUNCTION(git_submodule_add_finalize); + +/* {{{ proto long git_submodule_add_to_index(submodule, write_index) +*/ +PHP_FUNCTION(git_submodule_add_to_index); + +/* {{{ proto long git_submodule_save(submodule) +*/ +PHP_FUNCTION(git_submodule_save); + +/* {{{ proto resource git_submodule_owner(submodule) +*/ +PHP_FUNCTION(git_submodule_owner); + +/* {{{ proto resource git_submodule_name(submodule) +*/ +PHP_FUNCTION(git_submodule_name); + +/* {{{ proto resource git_submodule_path(submodule) +*/ +PHP_FUNCTION(git_submodule_path); + +/* {{{ proto resource git_submodule_url(submodule) +*/ +PHP_FUNCTION(git_submodule_url); + +/* {{{ proto long git_submodule_set_url(submodule, url) +*/ +PHP_FUNCTION(git_submodule_set_url); + +/* {{{ proto resource git_submodule_index_id(submodule) +*/ +PHP_FUNCTION(git_submodule_index_id); + +/* {{{ proto resource git_submodule_head_id(submodule) +*/ +PHP_FUNCTION(git_submodule_head_id); + +/* {{{ proto resource git_submodule_wd_id(submodule) +*/ +PHP_FUNCTION(git_submodule_wd_id); + +/* {{{ proto resource git_submodule_ignore(submodule) +*/ +PHP_FUNCTION(git_submodule_ignore); + +/* {{{ proto resource git_submodule_set_ignore(submodule, ignore) +*/ +PHP_FUNCTION(git_submodule_set_ignore); + +/* {{{ proto resource git_submodule_update(submodule) +*/ +PHP_FUNCTION(git_submodule_update); + +/* {{{ proto resource git_submodule_set_update(submodule, update) +*/ +PHP_FUNCTION(git_submodule_set_update); + +/* {{{ proto long git_submodule_fetch_recurse_submodules(submodule) +*/ +PHP_FUNCTION(git_submodule_fetch_recurse_submodules); + +/* {{{ proto long git_submodule_set_fetch_recurse_submodules(submodule, fetch_recurse_submodules) +*/ +PHP_FUNCTION(git_submodule_set_fetch_recurse_submodules); + +/* {{{ proto long git_submodule_init(submodule, overwrite) +*/ +PHP_FUNCTION(git_submodule_init); + +/* {{{ proto long git_submodule_sync(submodule) +*/ +PHP_FUNCTION(git_submodule_sync); + +/* {{{ proto resource git_submodule_open(submodule) +*/ +PHP_FUNCTION(git_submodule_open); + +/* {{{ proto long git_submodule_reload(submodule) +*/ +PHP_FUNCTION(git_submodule_reload); + +/* {{{ proto long git_submodule_reload_all(repo) +*/ +PHP_FUNCTION(git_submodule_reload_all); + +/* {{{ proto long git_submodule_status(status, submodule) +*/ +PHP_FUNCTION(git_submodule_status); + +/* {{{ proto long git_submodule_location(location_status, submodule) +*/ +PHP_FUNCTION(git_submodule_location); + +#endif \ No newline at end of file From ceff0153f44d0de65d14314bdef7804336aae0cf Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 12:50:27 +0900 Subject: [PATCH 058/136] add attr --- attr.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ attr.h | 90 +++++++++++++++++++++++++++++++++++ config.m4 | 2 +- php_git2.c | 9 ++++ 4 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 attr.c create mode 100644 attr.h diff --git a/attr.c b/attr.c new file mode 100644 index 0000000000..93af1ccd3a --- /dev/null +++ b/attr.c @@ -0,0 +1,135 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "attr.h" + +/* {{{ proto resource git_attr_value(string $attr) + */ +PHP_FUNCTION(git_attr_value) +{ + git_attr_t *result = NULL; + char *attr = NULL; + int attr_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &attr, &attr_len) == FAILURE) { + return; + } + + result = git_attr_value(attr); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto resource git_attr_get(resource $repo, long $flags, string $path, string $name) + */ +PHP_FUNCTION(git_attr_get) +{ + php_git2_t *result = NULL, *_repo = NULL; + char *value_out = NULL, *path = NULL, *name = NULL; + zval *repo = NULL; + long flags = 0; + int path_len = 0, name_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlss", &repo, &flags, &path, &path_len, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_attr_get(&value_out, PHP_GIT2_V(_repo, repository), flags, path, name); + if (php_git2_check_error(error, "git_attr_get" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(value_out, 1); +} +/* }}} */ + +/* {{{ proto resource git_attr_get_many(resource $repo, long $flags, string $path, long $num_attr, string $names) + */ +PHP_FUNCTION(git_attr_get_many) +{ + php_git2_t *result = NULL, *_repo = NULL; + char *values_out = NULL, *path = NULL, *names = NULL; + zval *repo = NULL; + long flags = 0, num_attr = 0; + int path_len = 0, names_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlsls", &repo, &flags, &path, &path_len, &num_attr, &names, &names_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_attr_get_many(&values_out, PHP_GIT2_V(_repo, repository), flags, path, num_attr, names); + if (php_git2_check_error(error, "git_attr_get_many" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(values_out, 1); +} +/* }}} */ + +/* {{{ proto long git_attr_foreach(resource $repo, long $flags, string $path, Callable $callback, $payload) + */ +PHP_FUNCTION(git_attr_foreach) +{ + int result = 0, path_len = 0, error = 0; + zval *repo = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + long flags = 0; + char *path = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlsfz", &repo, &flags, &path, &path_len, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_attr_foreach(PHP_GIT2_V(_repo, repository), flags, path, , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto void git_attr_cache_flush(resource $repo) + */ +PHP_FUNCTION(git_attr_cache_flush) +{ + zval *repo = NULL; + php_git2_t *_repo = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_attr_cache_flush(PHP_GIT2_V(_repo, repository)); +} +/* }}} */ + +/* {{{ proto long git_attr_add_macro(resource $repo, string $name, string $values) + */ +PHP_FUNCTION(git_attr_add_macro) +{ + int result = 0, name_len = 0, values_len = 0, error = 0; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *name = NULL, *values = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &repo, &name, &name_len, &values, &values_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_attr_add_macro(PHP_GIT2_V(_repo, repository), name, values); + RETURN_LONG(result); +} +/* }}} */ + diff --git a/attr.h b/attr.h new file mode 100644 index 0000000000..3faec01df9 --- /dev/null +++ b/attr.h @@ -0,0 +1,90 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_ATTR_H +#define PHP_GIT2_ATTR_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_value, 0, 0, 1) + ZEND_ARG_INFO(0, attr) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_get, 0, 0, 4) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_get_many, 0, 0, 5) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, num_attr) + ZEND_ARG_INFO(0, names) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_foreach, 0, 0, 5) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_cache_flush, 0, 0, 1) + ZEND_ARG_INFO(0, repo) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_add_macro, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, values) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_attr_value(attr) +*/ +PHP_FUNCTION(git_attr_value); + +/* {{{ proto resource git_attr_get(repo, flags, path, name) +*/ +PHP_FUNCTION(git_attr_get); + +/* {{{ proto resource git_attr_get_many(repo, flags, path, num_attr, names) +*/ +PHP_FUNCTION(git_attr_get_many); + +/* {{{ proto long git_attr_foreach(repo, flags, path, callback, payload) +*/ +PHP_FUNCTION(git_attr_foreach); + +/* {{{ proto void git_attr_cache_flush(repo) +*/ +PHP_FUNCTION(git_attr_cache_flush); + +/* {{{ proto long git_attr_add_macro(repo, name, values) +*/ +PHP_FUNCTION(git_attr_add_macro); + +#endif \ No newline at end of file diff --git a/config.m4 b/config.m4 index e95ff4f996..3f98d64b57 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c reset.c message.c submodule.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/php_git2.c b/php_git2.c index dad263ea3a..59ab21126c 100644 --- a/php_git2.c +++ b/php_git2.c @@ -61,6 +61,7 @@ #include "reset.h" #include "message.h" #include "submodule.h" +#include "attr.h" int git2_resource_handle; @@ -843,6 +844,14 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_submodule_status, arginfo_git_submodule_status) PHP_FE(git_submodule_location, arginfo_git_submodule_location) + /* attr */ + PHP_FE(git_attr_value, arginfo_git_attr_value) + PHP_FE(git_attr_get, arginfo_git_attr_get) + PHP_FE(git_attr_get_many, arginfo_git_attr_get_many) + PHP_FE(git_attr_foreach, arginfo_git_attr_foreach) + PHP_FE(git_attr_cache_flush, arginfo_git_attr_cache_flush) + PHP_FE(git_attr_add_macro, arginfo_git_attr_add_macro) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END From 152812c1253196779e33b9ae0801cafdd583640c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 13:09:35 +0900 Subject: [PATCH 059/136] improve message --- attr.c | 12 ++++--- branch.c | 104 +++++++++++++++++++++--------------------------------- message.c | 19 +++++----- 3 files changed, 57 insertions(+), 78 deletions(-) diff --git a/attr.c b/attr.c index 93af1ccd3a..796a71a324 100644 --- a/attr.c +++ b/attr.c @@ -49,17 +49,19 @@ PHP_FUNCTION(git_attr_get) PHP_FUNCTION(git_attr_get_many) { php_git2_t *result = NULL, *_repo = NULL; - char *values_out = NULL, *path = NULL, *names = NULL; - zval *repo = NULL; + char *values_out = NULL, *path = NULL; + zval *repo = NULL, *names = NULL; long flags = 0, num_attr = 0; - int path_len = 0, names_len = 0, error = 0; - + int path_len = 0, error = 0; + + /* TODO(chobie): write array to const char** conversion */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rlsls", &repo, &flags, &path, &path_len, &num_attr, &names, &names_len) == FAILURE) { + "rlsla", &repo, &flags, &path, &path_len, &num_attr, &names) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + /* TODO(chobie): emalloc values_out */ error = git_attr_get_many(&values_out, PHP_GIT2_V(_repo, repository), flags, path, num_attr, names); if (php_git2_check_error(error, "git_attr_get_many" TSRMLS_CC)) { RETURN_FALSE; diff --git a/branch.c b/branch.c index 867376f90d..fa738b3a81 100644 --- a/branch.c +++ b/branch.c @@ -6,16 +6,12 @@ */ PHP_FUNCTION(git_branch_create) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL, *_target = NULL; git_reference *out = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; + zval *repo = NULL, *target = NULL; char *branch_name = NULL; - int branch_name_len = 0; - zval *target = NULL; - php_git2_t *_target = NULL; + int branch_name_len = 0, error = 0; long force = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrl", &repo, &branch_name, &branch_name_len, &target, &force) == FAILURE) { @@ -28,12 +24,10 @@ PHP_FUNCTION(git_branch_create) if (php_git2_check_error(error, "git_branch_create" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -63,12 +57,11 @@ PHP_FUNCTION(git_branch_delete) */ PHP_FUNCTION(git_branch_iterator_new) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_branch_iterator *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; - long list_flags = 0; int error = 0; + long list_flags = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &repo, &list_flags) == FAILURE) { @@ -80,12 +73,10 @@ PHP_FUNCTION(git_branch_iterator_new) if (php_git2_check_error(error, "git_branch_iterator_new" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, branch_iterator) = out; - result->type = PHP_GIT2_TYPE_BRANCH_ITERATOR; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BRANCH_ITERATOR, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -94,11 +85,10 @@ PHP_FUNCTION(git_branch_iterator_new) */ PHP_FUNCTION(git_branch_next) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_iter = NULL; git_reference *out = NULL; - long out_type = 0; zval *iter = NULL; - php_git2_t *_iter = NULL; + long out_type = 0; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -111,16 +101,13 @@ PHP_FUNCTION(git_branch_next) if (php_git2_check_error(error, "git_branch_next" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto void git_branch_iterator_free(resource $iter) */ PHP_FUNCTION(git_branch_iterator_free) @@ -134,8 +121,9 @@ PHP_FUNCTION(git_branch_iterator_free) } ZEND_FETCH_RESOURCE(_iter, php_git2_t*, &iter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_iter->should_free_v) { + if (GIT2_SHOULD_FREE(_iter)) { git_branch_iterator_free(PHP_GIT2_V(_iter, branch_iterator)); + GIT2_SHOULD_FREE(_iter) = 0; }; zval_ptr_dtor(&iter); } @@ -145,14 +133,12 @@ PHP_FUNCTION(git_branch_iterator_free) */ PHP_FUNCTION(git_branch_move) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_branch = NULL; git_reference *out = NULL; zval *branch = NULL; - php_git2_t *_branch = NULL; char *new_branch_name = NULL; - int new_branch_name_len = 0; + int new_branch_name_len = 0, error = 0; long force = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &branch, &new_branch_name, &new_branch_name_len, &force) == FAILURE) { @@ -164,27 +150,24 @@ PHP_FUNCTION(git_branch_move) if (php_git2_check_error(error, "git_branch_move" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ -/* {{{ proto resource git_branch_lookup(resource $repo, string $branch_name, long $branch_type) + +/* {{{ proto resource git_branch_lookup(resource $repo, string $branch_name, $branch_type) */ PHP_FUNCTION(git_branch_lookup) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_reference *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; char *branch_name = NULL; - int branch_name_len = 0; + int branch_name_len = 0, error = 0; long branch_type = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &repo, &branch_name, &branch_name_len, &branch_type) == FAILURE) { @@ -196,16 +179,13 @@ PHP_FUNCTION(git_branch_lookup) if (php_git2_check_error(error, "git_branch_lookup" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_branch_name(resource $ref) */ PHP_FUNCTION(git_branch_name) @@ -234,10 +214,9 @@ PHP_FUNCTION(git_branch_name) */ PHP_FUNCTION(git_branch_upstream) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_branch = NULL; git_reference *out = NULL; zval *branch = NULL; - php_git2_t *_branch = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -250,15 +229,14 @@ PHP_FUNCTION(git_branch_upstream) if (php_git2_check_error(error, "git_branch_upstream" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto resource git_branch_upstream_name(resource $repo, string $canonical_branch_name) */ PHP_FUNCTION(git_branch_upstream_name) diff --git a/message.c b/message.c index ef78db7b0f..c9be40e316 100644 --- a/message.c +++ b/message.c @@ -2,25 +2,24 @@ #include "php_git2_priv.h" #include "message.h" -/* {{{ proto resource git_message_prettify(long $out_size, string $message, long $strip_comments) +/* {{{ proto resource git_message_prettify(string $message, long $strip_comments) */ PHP_FUNCTION(git_message_prettify) { php_git2_t *result = NULL; - char out = NULL, *message = NULL; + char *out = NULL, *message = NULL; long out_size = 0, strip_comments = 0; int message_len = 0, error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "lsl", &out_size, &message, &message_len, &strip_comments) == FAILURE) { + "sl", &message, &message_len, &strip_comments) == FAILURE) { return; } - - error = git_message_prettify(&out, out_size, message, strip_comments); - if (php_git2_check_error(error, "git_message_prettify" TSRMLS_CC)) { - RETURN_FALSE; - } - RETURN_STRING(out, 1); + + out_size = git_message_prettify(NULL, NULL, message, strip_comments); + out = (char*)emalloc(sizeof(char) * out_size); + error = git_message_prettify(out, out_size, message, strip_comments); + RETURN_STRING(out, 0); } /* }}} */ From 34ab9e7bccde2e30a73eb9783fd4f3ee41dbc6c3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 13:21:38 +0900 Subject: [PATCH 060/136] [stash] add stash callback --- stash.c | 34 +++++++++++++++++++++++++++++++++- stash.h | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/stash.c b/stash.c index 6330e75cb0..f4383d9f30 100644 --- a/stash.c +++ b/stash.c @@ -2,6 +2,38 @@ #include "php_git2_priv.h" #include "stash.h" +static int php_git2_stash_cb(size_t index, + const char* message, + const git_oid *stash_id, + void *payload) +{ + php_git2_t *result; + zval *param_index, *param_message,*param_stash_id, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + char _oid[41] = {0}; + GIT2_TSRMLS_SET(p->tsrm_ls) + + git_oid_fmt(_oid, stash_id); + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_index); + MAKE_STD_ZVAL(param_message); + MAKE_STD_ZVAL(param_stash_id); + ZVAL_LONG(param_index, index); + ZVAL_STRING(param_message, message, 1); + ZVAL_STRING(param_stash_id, _oid, 1); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 4, ¶m_index, ¶m_message, ¶m_stash_id, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + /* {{{ proto resource git_stash_save(resource $repo, array $stasher, string $message, long $flags) */ PHP_FUNCTION(git_stash_save) @@ -49,7 +81,7 @@ PHP_FUNCTION(git_stash_foreach) if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { RETURN_FALSE; } - //result = git_stash_foreach(PHP_GIT2_V(_repo, repository), , cb); + result = git_stash_foreach(PHP_GIT2_V(_repo, repository), php_git2_stash_cb, cb); php_git2_cb_free(cb); RETURN_LONG(result); } diff --git a/stash.h b/stash.h index cf49997b17..5640514b0c 100644 --- a/stash.h +++ b/stash.h @@ -36,7 +36,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_foreach, 0, 0, 3) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_drop, 0, 0, 2) From e20f10d23d24a4f8dfb3bd8eba357346b03bfeb0 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 13:37:02 +0900 Subject: [PATCH 061/136] add giterr --- config.m4 | 2 +- giterr.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ giterr.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++ php_git2.c | 8 ++++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 giterr.c create mode 100644 giterr.h diff --git a/config.m4 b/config.m4 index 3f98d64b57..6c2b187a60 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/giterr.c b/giterr.c new file mode 100644 index 0000000000..b09be1e2e6 --- /dev/null +++ b/giterr.c @@ -0,0 +1,81 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "giterr.h" + +static void php_git2_error_to_array(const git_error *error, zval **out) +{ + zval *array; + + MAKE_STD_ZVAL(array); + array_init(array); + if (error == NULL) { + add_next_index_string(array, "", 1); + add_next_index_long(array, 0); + } else { + add_next_index_string(array, error->message, 1); + add_next_index_long(array, error->klass); + } + *out = array; +} + +/* {{{ proto resource giterr_last() + */ +PHP_FUNCTION(giterr_last) +{ + const git_error *result = {0}; + zval *array; + + result = giterr_last(); + php_git2_error_to_array(result, &array); + + RETURN_ZVAL(array, 0, 1); +} +/* }}} */ + +/* {{{ proto void giterr_clear() + */ +PHP_FUNCTION(giterr_clear) +{ + giterr_clear(); +} +/* }}} */ + +/* {{{ proto array giterr_detach() + */ +PHP_FUNCTION(giterr_detach) +{ + int result = 0, error = 0; + git_error cpy; + zval *array; + + result = giterr_detach(&cpy); + php_git2_error_to_array(&cpy, &array); + RETURN_ZVAL(array, 0, 1); +} +/* }}} */ + +/* {{{ proto void giterr_set_str(long $error_class, string $string) + */ +PHP_FUNCTION(giterr_set_str) +{ + long error_class = 0; + char *string = NULL; + int string_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ls", &error_class, &string, &string_len) == FAILURE) { + return; + } + + giterr_set_str(error_class, string); +} +/* }}} */ + +/* {{{ proto void giterr_set_oom() + */ +PHP_FUNCTION(giterr_set_oom) +{ + giterr_set_oom(); +} +/* }}} */ + diff --git a/giterr.h b/giterr.h new file mode 100644 index 0000000000..ff25692c15 --- /dev/null +++ b/giterr.h @@ -0,0 +1,70 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_GITERR_H +#define PHP_GIT2_GITERR_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_giterr_last, 0, 0, 1) + ZEND_ARG_INFO(0, void) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_giterr_clear, 0, 0, 1) + ZEND_ARG_INFO(0, void) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_giterr_detach, 0, 0, 1) + ZEND_ARG_INFO(0, cpy) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_giterr_set_str, 0, 0, 2) + ZEND_ARG_INFO(0, error_class) + ZEND_ARG_INFO(0, string) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_giterr_set_oom, 0, 0, 1) + ZEND_ARG_INFO(0, void) +ZEND_END_ARG_INFO() + +/* {{{ proto resource giterr_last(void) +*/ +PHP_FUNCTION(giterr_last); + +/* {{{ proto void giterr_clear(void) +*/ +PHP_FUNCTION(giterr_clear); + +/* {{{ proto long giterr_detach(cpy) +*/ +PHP_FUNCTION(giterr_detach); + +/* {{{ proto void giterr_set_str(error_class, string) +*/ +PHP_FUNCTION(giterr_set_str); + +/* {{{ proto void giterr_set_oom(void) +*/ +PHP_FUNCTION(giterr_set_oom); + +#endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 59ab21126c..996ac53544 100644 --- a/php_git2.c +++ b/php_git2.c @@ -62,6 +62,7 @@ #include "message.h" #include "submodule.h" #include "attr.h" +#include "giterr.h" int git2_resource_handle; @@ -852,6 +853,13 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_attr_cache_flush, arginfo_git_attr_cache_flush) PHP_FE(git_attr_add_macro, arginfo_git_attr_add_macro) + /* giterr */ + PHP_FE(giterr_last, arginfo_giterr_last) + PHP_FE(giterr_clear, arginfo_giterr_clear) + PHP_FE(giterr_detach, arginfo_giterr_detach) + PHP_FE(giterr_set_str, arginfo_giterr_set_str) + PHP_FE(giterr_set_oom, arginfo_giterr_set_oom) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END From b60e455ee11cc3e98edd1c5e6c1e1b4edbc746f6 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 14:18:56 +0900 Subject: [PATCH 062/136] improve transport --- transport.c | 60 ++++++++++++++++++-------------------- treebuilder.c | 81 +++++++++++++++++++++------------------------------ 2 files changed, 62 insertions(+), 79 deletions(-) diff --git a/transport.c b/transport.c index e98f17f7c3..933368e775 100644 --- a/transport.c +++ b/transport.c @@ -2,38 +2,6 @@ #include "php_git2_priv.h" #include "transport.h" -/* {{{ proto resource git_transport_new(resource $owner, string $url) - */ -PHP_FUNCTION(git_transport_new) -{ - php_git2_t *result = NULL; - git_transport *out = NULL; - zval *owner = NULL; - php_git2_t *_owner = NULL; - char *url = NULL; - int url_len = 0; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &owner, &url, &url_len) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_transport_new(&out, PHP_GIT2_V(_owner, remote), url); - if (php_git2_check_error(error, "git_transport_new" TSRMLS_CC)) { - RETURN_FALSE; - } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, transport) = out; - result->type = PHP_GIT2_TYPE_TRANSPORT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); -} -/* }}} */ - -//typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param); static int php_git2_transport_cb(git_transport **out, git_remote *owner, void *param) { php_git2_t *result; @@ -62,6 +30,34 @@ static int php_git2_transport_cb(git_transport **out, git_remote *owner, void *p return retval; } + +/* {{{ proto resource git_transport_new(resource $owner, string $url) + */ +PHP_FUNCTION(git_transport_new) +{ + php_git2_t *result = NULL, *_owner = NULL; + git_transport *out = NULL; + zval *owner = NULL; + char *url = NULL; + int url_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &owner, &url, &url_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_transport_new(&out, PHP_GIT2_V(_owner, remote), url); + if (php_git2_check_error(error, "git_transport_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TRANSPORT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + /* {{{ proto long git_transport_register(string $prefix, $priority, Callable $cb, $param) */ PHP_FUNCTION(git_transport_register) diff --git a/treebuilder.c b/treebuilder.c index f671629a2f..e09ee599c7 100644 --- a/treebuilder.c +++ b/treebuilder.c @@ -36,12 +36,12 @@ static int php_git2_treebuilder_filter_cb(const git_tree_entry *entry, void *pay /* {{{ proto resource git_treebuilder_create([resource $source]) -*/ + */ PHP_FUNCTION(git_treebuilder_create) { + php_git2_t *result = NULL, *_source = NULL; + git_treebuilder *out = NULL; zval *source = NULL; - php_git2_t *_source, *result; - git_treebuilder *builder; git_tree *tree = NULL; int error = 0; @@ -49,25 +49,22 @@ PHP_FUNCTION(git_treebuilder_create) "|r", &source) == FAILURE) { return; } - if (source != NULL) { - ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); tree = PHP_GIT2_V(_source, tree); } - error = git_treebuilder_create(&builder, tree); + ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_treebuilder_create(&out, tree); if (php_git2_check_error(error, "git_treebuilder_create" TSRMLS_CC)) { RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, treebuilder) = builder; - result->type = PHP_GIT2_TYPE_TREEBUILDER; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREEBUILDER, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ + /* {{{ proto void git_treebuilder_clear(bld) */ @@ -135,57 +132,47 @@ PHP_FUNCTION(git_treebuilder_get) ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); entry = git_treebuilder_get(PHP_GIT2_V(_bld, treebuilder), filename); if (entry != NULL) { - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, tree_entry) = entry; - result->type = PHP_GIT2_TYPE_TREE_ENTRY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREE_ENTRY, entry, 0 TSRMLS_CC)) { + RETURN_FALSE; + } ZVAL_RESOURCE(return_value, result->resource_id); } else { RETURN_FALSE; } } -/* {{{ proto resource git_treebuilder_insert(bld, filename, id, filemode) -*/ +/* {{{ proto resource git_treebuilder_insert(resource $bld, string $filename, string $id, $filemode) + */ PHP_FUNCTION(git_treebuilder_insert) { - zval *bld; - php_git2_t *_bld, *result; - char *filename = {0}; - int filename_len; - char *id = {0}; - int id_len; - long filemode; - const git_tree_entry *entry; - int error = 0; - git_oid oid; + php_git2_t *result = NULL, *_bld = NULL; + git_tree_entry *out = NULL; + zval *bld = NULL; + char *filename = NULL, *id = NULL; + int filename_len = 0, id_len = 0, error = 0; + git_oid __id = {0}; + long filemode = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &bld, &filename, &filename_len, &id, &id_len, &filemode) == FAILURE) { return; } - if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { - return; - } - ZEND_FETCH_RESOURCE(_bld, php_git2_t*, &bld, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_treebuilder_insert(&entry, PHP_GIT2_V(_bld, treebuilder), filename, &oid, filemode); - - if (php_git2_check_error(error, "git_treebuilder_write" TSRMLS_CC)) { + if (git_oid_fromstrn(&__id, id, id_len)) { RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, tree_entry) = entry; - result->type = PHP_GIT2_TYPE_TREE_ENTRY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + error = git_treebuilder_insert(&out, PHP_GIT2_V(_bld, treebuilder), filename, &__id, filemode); + if (php_git2_check_error(error, "git_treebuilder_insert" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREE_ENTRY, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ + /* {{{ proto long git_treebuilder_remove(bld, filename) */ From 40037d91b353f87e07cb68480f7d61dfb3b2636e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 16:57:36 +0900 Subject: [PATCH 063/136] improve diff --- diff.c | 107 +++++++++++++++++++++------------------------------------ 1 file changed, 40 insertions(+), 67 deletions(-) diff --git a/diff.c b/diff.c index a3c772df0a..86f65e0c9a 100644 --- a/diff.c +++ b/diff.c @@ -15,8 +15,9 @@ PHP_FUNCTION(git_diff_free) } ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_diff->should_free_v) { + if (GIT2_SHOULD_FREE(_diff)) { git_diff_free(PHP_GIT2_V(_diff, diff)); + GIT2_SHOULD_FREE(_diff) = 0; }; zval_ptr_dtor(&diff); } @@ -57,18 +58,12 @@ PHP_FUNCTION(git_diff_tree_to_tree) */ PHP_FUNCTION(git_diff_tree_to_index) { - int result = 0; + int result = 0, error = 0; git_diff *diff = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *old_tree = NULL; - php_git2_t *_old_tree = NULL; - zval *index = NULL; - php_git2_t *_index = NULL; - zval *opts = NULL; - int error = 0; + zval *repo = NULL, *old_tree = NULL, *index = NULL, *opts = NULL; + php_git2_t *_repo = NULL, *_old_tree = NULL, *_index = NULL, *_diff = NULL; - /* TODO(chobie): generate converter */ + /* TODO(chobie): convert options */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrra", &repo, &old_tree, &index, &opts) == FAILURE) { return; @@ -78,25 +73,23 @@ PHP_FUNCTION(git_diff_tree_to_index) ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_diff_tree_to_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), PHP_GIT2_V(_index, index), opts); - RETURN_LONG(result); + if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT_RVAL_P(_diff)); + } /* }}} */ - /* {{{ proto long git_diff_index_to_workdir(resource $repo, resource $index, $opts) */ PHP_FUNCTION(git_diff_index_to_workdir) { - int result = 0; + int result = 0, error = 0; git_diff *diff = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *index = NULL; - php_git2_t *_index = NULL; - zval *opts = NULL; - int error = 0; + zval *repo = NULL, *index = NULL, *opts = NULL; + php_git2_t *_repo = NULL, *_index = NULL, *_diff = NULL; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &index, &opts) == FAILURE) { return; @@ -105,52 +98,23 @@ PHP_FUNCTION(git_diff_index_to_workdir) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_diff_index_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_index, index), opts); - RETURN_LONG(result); -} -/* }}} */ - - -/* {{{ proto long git_diff_tree_to_workdir(resource $repo, resource $old_tree, $opts) - */ -PHP_FUNCTION(git_diff_tree_to_workdir) -{ - int result = 0; - git_diff *diff = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *old_tree = NULL; - php_git2_t *_old_tree = NULL; - zval *opts = NULL; - int error = 0; - - /* TODO(chobie): generate converter */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rra", &repo, &old_tree, &opts) == FAILURE) { - return; + if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { + RETURN_FALSE; } + ZVAL_RESOURCE(return_value, GIT_RVAL_P(_diff)); - ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts); - RETURN_LONG(result); } /* }}} */ - /* {{{ proto long git_diff_tree_to_workdir_with_index(resource $repo, resource $old_tree, $opts) */ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) { - int result = 0; + int result = 0, error = 0; git_diff *diff = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *old_tree = NULL; - php_git2_t *_old_tree = NULL; - zval *opts = NULL; - int error = 0; + zval *repo = NULL, *old_tree = NULL, *opts = NULL; + php_git2_t *_repo = NULL, *_old_tree = NULL, *_diff = NULL; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &old_tree, &opts) == FAILURE) { return; @@ -159,21 +123,20 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_diff_tree_to_workdir_with_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts); - RETURN_LONG(result); + if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT_RVAL_P(_diff)); } /* }}} */ - /* {{{ proto long git_diff_merge(resource $onto, resource $from) */ PHP_FUNCTION(git_diff_merge) { - int result = 0; - zval *onto = NULL; - php_git2_t *_onto = NULL; - zval *from = NULL; - php_git2_t *_from = NULL; - int error = 0; + int result = 0, error = 0; + zval *onto = NULL, *from = NULL; + php_git2_t *_onto = NULL, *_from = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &onto, &from) == FAILURE) { @@ -187,7 +150,6 @@ PHP_FUNCTION(git_diff_merge) } /* }}} */ - /* {{{ proto long git_diff_find_similar(resource $diff, $options) */ PHP_FUNCTION(git_diff_find_similar) @@ -321,11 +283,22 @@ PHP_FUNCTION(git_diff_foreach) { } -/* {{{ proto resource git_diff_status_char(status) -*/ +/* {{{ proto string git_diff_status_char( $status) + */ PHP_FUNCTION(git_diff_status_char) { + char *result = NULL; + long status = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "l", &status) == FAILURE) { + return; + } + + result = git_diff_status_char(status); + RETURN_STRING(result, 1); } +/* }}} */ /* {{{ proto long git_diff_print(diff, format, print_cb, payload) */ From 2c4de1a7ae1373daf9aef5865b59046b25e6851e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 17:10:39 +0900 Subject: [PATCH 064/136] improve signature --- diff.c | 21 +++++++++++++++++++++ signature.c | 36 ++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/diff.c b/diff.c index 86f65e0c9a..2890060bbd 100644 --- a/diff.c +++ b/diff.c @@ -106,6 +106,27 @@ PHP_FUNCTION(git_diff_index_to_workdir) } /* }}} */ +/* {{{ proto long git_diff_tree_to_workdir(resource $repo, resource $old_tree, $opts) + */ +PHP_FUNCTION(git_diff_tree_to_workdir) +{ + int result = 0, error = 0; + git_diff *diff = NULL; + zval *repo = NULL, *old_tree = NULL, *opts = NULL; + php_git2_t *_repo = NULL, *_old_tree = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &repo, &old_tree, &opts) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts); + RETURN_LONG(result); +} +/* }}} */ + /* {{{ proto long git_diff_tree_to_workdir_with_index(resource $repo, resource $old_tree, $opts) */ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) diff --git a/signature.c b/signature.c index f8a8cca4e4..b6a5b1b87e 100644 --- a/signature.c +++ b/signature.c @@ -2,7 +2,7 @@ #include "php_git2_priv.h" #include "signature.h" -/* {{{ proto resource git_signature_new(string $name, string $email, $time, long $offset) +/* {{{ proto resource git_signature_new(string $name, string $email, array $time, long $offset) */ PHP_FUNCTION(git_signature_new) { @@ -10,11 +10,11 @@ PHP_FUNCTION(git_signature_new) git_signature *out = NULL; char *name = NULL, *email = NULL; int name_len = 0, email_len = 0, error = 0; - zval *time = NULL; - long offset = 0; - + long time = 0, offset = 0; + zval *signature = NULL; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ssal", &name, &name_len, &email, &email_len, &time, &offset) == FAILURE) { + "ssll", &name, &name_len, &email, &email_len, &time, &offset) == FAILURE) { return; } @@ -22,6 +22,9 @@ PHP_FUNCTION(git_signature_new) if (php_git2_check_error(error, "git_signature_new" TSRMLS_CC)) { RETURN_FALSE; } + php_git2_signature_to_array(out, &signature TSRMLS_CC); + git_signature_free(out); + RETURN_ZVAL(signature, 0, 1); } /* }}} */ @@ -33,6 +36,7 @@ PHP_FUNCTION(git_signature_now) git_signature *out = NULL; char *name = NULL, *email = NULL; int name_len = 0, email_len = 0, error = 0; + zval *signature = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &email, &email_len) == FAILURE) { @@ -43,6 +47,9 @@ PHP_FUNCTION(git_signature_now) if (php_git2_check_error(error, "git_signature_now" TSRMLS_CC)) { RETURN_FALSE; } + php_git2_signature_to_array(out, &signature TSRMLS_CC); + git_signature_free(out); + RETURN_ZVAL(signature, 0, 1); } /* }}} */ @@ -52,7 +59,7 @@ PHP_FUNCTION(git_signature_default) { php_git2_t *result = NULL, *_repo = NULL; git_signature *out = NULL; - zval *repo = NULL; + zval *repo = NULL, *signature = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -65,6 +72,9 @@ PHP_FUNCTION(git_signature_default) if (php_git2_check_error(error, "git_signature_default" TSRMLS_CC)) { RETURN_FALSE; } + php_git2_signature_to_array(out, &signature TSRMLS_CC); + git_signature_free(out); + RETURN_ZVAL(signature, 0, 1); } /* }}} */ @@ -82,6 +92,7 @@ PHP_FUNCTION(git_signature_dup) result = git_signature_dup(sig); php_git2_signature_to_array(result, &__result TSRMLS_CC); + git_signature_free(result); RETURN_ZVAL(__result, 0, 1); } /* }}} */ @@ -90,18 +101,7 @@ PHP_FUNCTION(git_signature_dup) */ PHP_FUNCTION(git_signature_free) { -// zval *sig = NULL; -// -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "a", &sig) == FAILURE) { -// return; -// } -// -// if (GIT2_SHOULD_FREE(_sig)) { -// git_signature_free(sig); -// GIT2_SHOULD_FREE(_sig) = 0; -// }; -// zval_ptr_dtor(&sig); + // TODO(chobie): remove later. we don't need to export this function */ } /* }}} */ From 720df01d089917d986a47b8ff4c375b689bbcca5 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 17:19:06 +0900 Subject: [PATCH 065/136] add note --- signature.c | 1 + 1 file changed, 1 insertion(+) diff --git a/signature.c b/signature.c index b6a5b1b87e..12085b3345 100644 --- a/signature.c +++ b/signature.c @@ -82,6 +82,7 @@ PHP_FUNCTION(git_signature_default) */ PHP_FUNCTION(git_signature_dup) { + // TODO(chobie): remove later. we don't need to export this function */ git_signature *result = NULL; zval *__result = NULL, *sig = NULL; From f527c2d3e4e64fb8de650292f4f97e250187b81d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 19:03:35 +0900 Subject: [PATCH 066/136] remove needless functions --- php_git2.c | 2 -- signature.c | 29 ----------------------------- 2 files changed, 31 deletions(-) diff --git a/php_git2.c b/php_git2.c index 996ac53544..2f140f9567 100644 --- a/php_git2.c +++ b/php_git2.c @@ -806,8 +806,6 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_signature_new, arginfo_git_signature_new) PHP_FE(git_signature_now, arginfo_git_signature_now) PHP_FE(git_signature_default, arginfo_git_signature_default) - PHP_FE(git_signature_dup, arginfo_git_signature_dup) - PHP_FE(git_signature_free, arginfo_git_signature_free) /* reset */ PHP_FE(git_reset, arginfo_git_reset) diff --git a/signature.c b/signature.c index 12085b3345..4a6a6017ca 100644 --- a/signature.c +++ b/signature.c @@ -77,32 +77,3 @@ PHP_FUNCTION(git_signature_default) RETURN_ZVAL(signature, 0, 1); } /* }}} */ - -/* {{{ proto array git_signature_dup(array $sig) - */ -PHP_FUNCTION(git_signature_dup) -{ - // TODO(chobie): remove later. we don't need to export this function */ - git_signature *result = NULL; - zval *__result = NULL, *sig = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "a", &sig) == FAILURE) { - return; - } - - result = git_signature_dup(sig); - php_git2_signature_to_array(result, &__result TSRMLS_CC); - git_signature_free(result); - RETURN_ZVAL(__result, 0, 1); -} -/* }}} */ - -/* {{{ proto void git_signature_free(array $sig) - */ -PHP_FUNCTION(git_signature_free) -{ - // TODO(chobie): remove later. we don't need to export this function */ -} -/* }}} */ - From 05e05c327709c256a7f0d347f80e690f31e56f7d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 13 Jan 2014 23:23:58 +0900 Subject: [PATCH 067/136] [checkout] WIP: callback --- checkout.c | 40 +++++++--- helper.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++ helper.h | 6 ++ php_git2.c | 11 +++ 4 files changed, 276 insertions(+), 9 deletions(-) diff --git a/checkout.c b/checkout.c index 4d751869df..a3ebcd830c 100644 --- a/checkout.c +++ b/checkout.c @@ -10,16 +10,28 @@ PHP_FUNCTION(git_checkout_head) zval *repo = NULL; php_git2_t *_repo = NULL; zval *opts = NULL; - int error = 0; + int error = 0, shoud_free = 0; + git_checkout_opts *options; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ra", &repo, &opts) == FAILURE) { + "r|a", &repo, &opts) == FAILURE) { return; } + if (opts != NULL) { + if (php_git2_array_to_git_checkout_opts(&options, opts TSRMLS_CC)) { + RETURN_FALSE; + } + shoud_free = 1; + } else { + //memset(&options, '\0', sizeof(git_checkout_opts)); + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_checkout_head(PHP_GIT2_V(_repo, repository), opts); + result = git_checkout_head(PHP_GIT2_V(_repo, repository), options); + if (shoud_free) { + php_git_git_checkout_opts_free(options TSRMLS_CC); + } RETURN_LONG(result); } /* }}} */ @@ -50,7 +62,6 @@ PHP_FUNCTION(git_checkout_index) } /* }}} */ - /* {{{ proto long git_checkout_tree(resource $repo, resource $treeish, $opts) */ PHP_FUNCTION(git_checkout_tree) @@ -62,16 +73,27 @@ PHP_FUNCTION(git_checkout_tree) php_git2_t *_treeish = NULL; zval *opts = NULL; int error = 0; + git_checkout_opts options = GIT_CHECKOUT_OPTS_INIT; + git_object *__treeish = NULL; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rra", &repo, &treeish, &opts) == FAILURE) { + "r|ra", &repo, &treeish, &opts) == FAILURE) { return; } + if (opts != NULL && php_git2_array_to_git_checkout_opts(&options, opts TSRMLS_CC)) { + RETURN_FALSE; + } else { + memset(&options, '\0', sizeof(git_checkout_opts)); + } + + if (treeish != NULL) { + ZEND_FETCH_RESOURCE(_treeish, php_git2_t*, &treeish, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + treeish = PHP_GIT2_V(_treeish, object); + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - ZEND_FETCH_RESOURCE(_treeish, php_git2_t*, &treeish, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_checkout_tree(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_treeish, object), opts); + result = git_checkout_tree(PHP_GIT2_V(_repo, repository), __treeish, &options); RETURN_LONG(result); } /* }}} */ diff --git a/helper.c b/helper.c index 3d8b44bf04..6142c24f62 100644 --- a/helper.c +++ b/helper.c @@ -235,3 +235,231 @@ void php_git2_strarray_free(git_strarray *out) } efree(out->strings); } + +void php_git2_git_checkout_opts_to_array(git_checkout_opts *opts, zval **out TSRMLS_DC) +{ + zval *result; + git_checkout_opts tmp = GIT_CHECKOUT_OPTS_INIT; + opts = &tmp; + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("version"), opts->version); + add_assoc_long_ex(result, ZEND_STRS("checkout_strategy"), opts->checkout_strategy); + add_assoc_long_ex(result, ZEND_STRS("disable_filters"), opts->disable_filters); + add_assoc_long_ex(result, ZEND_STRS("dir_mode"), opts->dir_mode); + add_assoc_long_ex(result, ZEND_STRS("file_mode"), opts->file_mode); + add_assoc_long_ex(result, ZEND_STRS("file_open_flags"), opts->file_open_flags); + add_assoc_long_ex(result, ZEND_STRS("notify_flags"), opts->notify_flags); + + if (opts->notify_payload != NULL) { + + } else { + add_assoc_null_ex(result, ZEND_STRS("notify_cb")); + } + + if (opts->notify_payload != NULL) { + + } else { + add_assoc_null_ex(result, ZEND_STRS("notify_payload")); + } + + if (opts->progress_cb != NULL) { + + } else { + add_assoc_null_ex(result, ZEND_STRS("progress_cb")); + } + + if (opts->progress_payload != NULL) { + + } else { + add_assoc_null_ex(result, ZEND_STRS("progress_payload")); + } + + if (opts->paths.count > 0) { + zval *paths; + php_git2_strarray_to_array(&opts->paths, &paths TSRMLS_CC); + add_assoc_zval_ex(result, ZEND_STRS("paths"), paths); + } else { + zval *paths; + MAKE_STD_ZVAL(paths); + array_init(paths); + add_assoc_zval_ex(result, ZEND_STRS("paths"), paths); + } + + if (opts->baseline != NULL) { + // git_tree + + } else { + add_assoc_null_ex(result, ZEND_STRS("baseline")); + } + add_assoc_string_ex(result, ZEND_STRS("target_directory"), (opts->target_directory) ? opts->target_directory : "", 1); + add_assoc_string_ex(result, ZEND_STRS("our_label"), (opts->our_label) ? opts->our_label : "", 1); + add_assoc_string_ex(result, ZEND_STRS("their_label"), (opts->their_label) ? opts->their_label : "", 1); + + *out = result; +} + +void php_git_git_checkout_opts_free(git_checkout_opts *target TSRMLS_DC) +{ + php_git2_cb_t *tmp; + + if (target->notify_payload) { + tmp = (php_git2_cb_t*)target->notify_payload; + if (tmp->fci) { + efree(tmp->fci); + } + if (tmp->fcc) { + efree(tmp->fcc); + } + efree(target->notify_payload); + } + if (target->progress_payload) { + tmp = (php_git2_cb_t*)target->progress_payload; + if (tmp->fci) { + efree(tmp->fci); + } + if (tmp->fcc) { + efree(tmp->fcc); + } + efree(target->progress_payload); + } + + php_git2_strarray_free(&target->paths); + efree(target); +} + + +static int php_git2_git_checkout_notify_cb(git_checkout_notify_t why, + const char *path, + const git_diff_file *baseline, + const git_diff_file *target, + const git_diff_file *workdir, + void *payload) +{ + /* TODO(chobie): implement callback */ +} + +void php_git2_git_checkout_progress_cb(const char *path, + size_t completed_steps, + size_t total_steps, + void *payload) +{ + php_git2_t *result; + zval *param_path, *param_completed_steps, *param_total_steps, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + GIT2_TSRMLS_SET(p->tsrm_ls); + + MAKE_STD_ZVAL(param_path); + MAKE_STD_ZVAL(param_completed_steps); + MAKE_STD_ZVAL(param_total_steps); + ZVAL_NULL(param_path); + if (path != NULL) { + ZVAL_STRING(param_path, path, 1); + } + ZVAL_LONG(param_completed_steps, completed_steps); + ZVAL_LONG(param_total_steps, total_steps); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 4, ¶m_path, ¶m_completed_steps, ¶m_total_steps, &p->payload)) { + return; + } + + zval_ptr_dtor(&retval_ptr); +} + + +static void php_git2_fcall_info_wrapper(zval *target, zend_fcall_info **out_fci, zend_fcall_info_cache **out_fcc TSRMLS_DC) +{ + char *is_callable_error = NULL; + zend_fcall_info *fci = NULL; + zend_fcall_info_cache *fcc = NULL; + + fci = (zend_fcall_info*)emalloc(sizeof(zend_fcall_info)); + fcc = (zend_fcall_info_cache*)emalloc(sizeof(zend_fcall_info_cache)); + memcpy(fci, &empty_fcall_info, sizeof(zend_fcall_info)); + memcpy(fcc, &empty_fcall_info_cache, sizeof(zend_fcall_info_cache)); + + if (zend_fcall_info_init(target, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == SUCCESS) { + if (is_callable_error) { + efree(is_callable_error); + } + } else { + fprintf(stderr, "FAILED"); + efree(fci); + efree(fcc); + return; + } + + *out_fci = fci; + *out_fcc = fcc; +} + +int php_git2_array_to_git_checkout_opts(git_checkout_opts **out, zval *array TSRMLS_DC) +{ + const char *target_directory, *our_label, *their_label; + git_checkout_opts *opts = NULL, def = GIT_CHECKOUT_OPTS_INIT; + php_git2_cb_t *notify_payload = NULL, *progress_payload= NULL; + zval *notify_cb = NULL, *progress_cb = NULL; + char *tmp; + + opts = (git_checkout_opts*)emalloc(sizeof(struct git_checkout_opts)); + memcpy(opts, &def, sizeof(git_checkout_opts)); + + notify_cb = php_git2_read_arrval(array, ZEND_STRS("notify_cb") TSRMLS_CC); + progress_cb = php_git2_read_arrval(array, ZEND_STRS("progress_cb") TSRMLS_CC); + + + opts->notify_cb = php_git2_git_checkout_notify_cb; + opts->progress_cb = php_git2_git_checkout_progress_cb; + opts->version = php_git2_read_arrval_long(array, ZEND_STRS("version") TSRMLS_CC); + opts->checkout_strategy = php_git2_read_arrval_long(array, ZEND_STRS("checkout_strategy") TSRMLS_CC); + opts->disable_filters = php_git2_read_arrval_long(array, ZEND_STRS("disable_filters") TSRMLS_CC); + opts->dir_mode = php_git2_read_arrval_long(array, ZEND_STRS("dir_mode") TSRMLS_CC); + opts->file_mode = php_git2_read_arrval_long(array, ZEND_STRS("file_mode") TSRMLS_CC); + opts->file_open_flags = php_git2_read_arrval_long(array, ZEND_STRS("file_open_flags") TSRMLS_CC); + opts->notify_flags = php_git2_read_arrval_long(array, ZEND_STRS("notify_flags") TSRMLS_CC); + + //notify_cb + if (Z_TYPE_P(notify_cb) != IS_NULL) { + zend_fcall_info *fci; + zend_fcall_info_cache *fcc; + + php_git2_fcall_info_wrapper(notify_cb, &fci, &fcc TSRMLS_CC); + if (php_git2_cb_init(¬ify_payload, fci, fcc, + php_git2_read_arrval(array, ZEND_STRS("notify_payload") TSRMLS_CC) TSRMLS_CC)) { + } + opts->notify_payload = notify_payload; + } else { + opts->notify_cb = NULL; + } + + //progress_cb + if (Z_TYPE_P(progress_cb) != IS_NULL) { + zend_fcall_info *fci; + zend_fcall_info_cache *fcc; + + php_git2_fcall_info_wrapper(progress_cb, &fci, &fcc TSRMLS_CC); + if (php_git2_cb_init(&progress_payload, fci, fcc, + php_git2_read_arrval(array, ZEND_STRS("progress_payload") TSRMLS_CC) TSRMLS_CC)) { + } + opts->progress_payload = progress_payload; + } else { + opts->progress_cb = NULL; + } + + + php_git2_array_to_strarray(&opts->paths, php_git2_read_arrval(array, ZEND_STRS("paths") TSRMLS_CC) TSRMLS_CC); + + // TODO: assign baseline(git_tree) + + target_directory = php_git2_read_arrval_string(array, ZEND_STRS("target_directory") TSRMLS_CC); + our_label = php_git2_read_arrval_string(array, ZEND_STRS("our_label") TSRMLS_CC); + their_label = php_git2_read_arrval_string(array, ZEND_STRS("their_label") TSRMLS_CC); + opts->target_directory = target_directory; + opts->our_label = our_label; + opts->their_label = their_label; + + *out = opts; + return 0; +} \ No newline at end of file diff --git a/helper.h b/helper.h index 7259571510..5c9cfbda36 100644 --- a/helper.h +++ b/helper.h @@ -53,4 +53,10 @@ void php_git2_array_to_strarray(git_strarray *out, zval *array TSRMLS_DC); void php_git2_strarray_free(git_strarray *out); +void php_git2_git_checkout_opts_to_array(git_checkout_opts *opts, zval **out TSRMLS_DC); + +void php_git_git_checkout_opts_free(git_checkout_opts *target TSRMLS_DC); + +int php_git2_array_to_git_checkout_opts(git_checkout_opts **out, zval *array TSRMLS_DC); + #endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 2f140f9567..40425dab08 100644 --- a/php_git2.c +++ b/php_git2.c @@ -270,6 +270,15 @@ PHP_FUNCTION(git_resource_type) } /* }}} */ +PHP_FUNCTION(git_checkout_opts_new) +{ + zval *tmp; + git_checkout_opts opt = GIT_CHECKOUT_OPTS_INIT; + + php_git2_git_checkout_opts_to_array(&opt, &tmp TSRMLS_CC); + RETURN_ZVAL(tmp, 0, 1); +} + static zend_function_entry php_git2_functions[] = { /* repository */ PHP_FE(git_repository_new, arginfo_git_repository_new) @@ -626,6 +635,8 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_checkout_index, arginfo_git_checkout_index) PHP_FE(git_checkout_tree, arginfo_git_checkout_tree) + PHP_FE(git_checkout_opts_new, NULL) /* convention function */ + /* filter */ PHP_FE(git_filter_list_load, arginfo_git_filter_list_load) PHP_FE(git_filter_list_apply_to_data, arginfo_git_filter_list_apply_to_data) From 3f8327bbb2d90de15e2399ec5d052f0dd7974a15 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 00:10:04 +0900 Subject: [PATCH 068/136] [checkout] make payload as ref --- helper.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/helper.c b/helper.c index 6142c24f62..d72d200b72 100644 --- a/helper.c +++ b/helper.c @@ -351,6 +351,7 @@ void php_git2_git_checkout_progress_cb(const char *path, php_git2_cb_t *p = (php_git2_cb_t*)payload; GIT2_TSRMLS_SET(p->tsrm_ls); + Z_ADDREF_P(p->payload); MAKE_STD_ZVAL(param_path); MAKE_STD_ZVAL(param_completed_steps); MAKE_STD_ZVAL(param_total_steps); @@ -361,6 +362,7 @@ void php_git2_git_checkout_progress_cb(const char *path, ZVAL_LONG(param_completed_steps, completed_steps); ZVAL_LONG(param_total_steps, total_steps); + SEPARATE_ZVAL_TO_MAKE_IS_REF(&p->payload); if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 4, ¶m_path, ¶m_completed_steps, ¶m_total_steps, &p->payload)) { return; } From 614b976d16c4a9688ece90c659dda62f831dcf95 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 00:39:15 +0900 Subject: [PATCH 069/136] update readme --- README.md | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f57c3881c4..1a302b93c0 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,21 @@ GIT_EXTERN(int) git_repository_init( unsigned is_bare); -// error code will handle extension. +// error code should handle in extension. // resource creation or getting functions will return their resource or bool. resource|bool function git_repository_init(string $path, long $is_bare); -some small structure (e.g: git_config_entry) should consider return as an array. it's usefull. +public struct (e.g: git_config_entry) should consider return as an array. ```` -see http://libgit2.github.com/libgit2/#HEAD +see libgit2.github.com/libgit2/#v0.20.0 ##### file name rules. basically, we rely libgit2 grouping at this time. (`branch` group functions should be in branch.c) -some group (e.g config) will conflicts php headers. we choose `g_` prefix for now. +some group (e.g config) will conflicts php header files. we choose `g_` prefix for now. -check grouping here http://libgit2.github.com/libgit2/#HEAD +check grouping here libgit2.github.com/libgit2/#v0.20.0 ##### generating files @@ -49,18 +49,40 @@ if you wanna try to work new file. please use gen.php and generate stubs. as dec (sometimes, this generator might output wrong headers. then just comment out or fix generator) ```` -php gen.php libgit2/include/git2/branch.h (0|1) [filter] > target.c or target.h +php gen.php libgit2/include/git2/branch.h 0 > branch.h + +# improved code generator +php ng.php libgit2/include/git2/branch.h > branch.c ```` -you can ouptut function entry with this. past it to `php_git2.c` +you can generate `PHP_FE` with this. past it to `php_git2.c` ```` php fe.php target.c ```` +Note: usually, these generators might output needless variables. DON'T PR `prettify codes` at this moment. +As we have more than 500 php functions. we like to use some fixer command than fix by hand. + +##### documents + +use prototype. + +``` + /* {{{ proto int abs(int number) + Returns the absolute value of the number */ + PHP_FUNCTION(abs) + { + ... + } + /* }}} */ +``` + +document will generate later. please check source code before publish docs. + ##### testing -group/function.phpt +[group]/[function].phpt ##### policy From 9e521b467b0725cb6071da55d0f656a07e32b37d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 00:49:48 +0900 Subject: [PATCH 070/136] [reset] fix arguments --- reset.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reset.c b/reset.c index eb5b5cf5e6..f9db4662c8 100644 --- a/reset.c +++ b/reset.c @@ -7,11 +7,12 @@ PHP_FUNCTION(git_reset) { int result = 0, error = 0; - zval *repo = NULL, *target = NULL, *reset_type = NULL; + zval *repo = NULL, *target = NULL; php_git2_t *_repo = NULL, *_target = NULL; + long reset_type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &repo, &target, &reset_type) == FAILURE) { + "rrl", &repo, &target, &reset_type) == FAILURE) { return; } From 9f8c80315e01e63b0e44ef23f07e58f06828ad44 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 02:18:25 +0900 Subject: [PATCH 071/136] for now, add example --- example/clone.php | 2 ++ example/ref_lookup.php | 6 ++++++ example/revwalk.php | 8 ++++++++ example/walking.php | 8 ++++++++ reference.c | 5 +++-- 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 example/clone.php create mode 100644 example/ref_lookup.php create mode 100644 example/revwalk.php create mode 100644 example/walking.php diff --git a/example/clone.php b/example/clone.php new file mode 100644 index 0000000000..4b671805b1 --- /dev/null +++ b/example/clone.php @@ -0,0 +1,2 @@ +", &ref, &type) == FAILURE) { + "rl", &ref, &type) == FAILURE) { return; } From 0f9eade67fa9937e31b0d5c81080cb90310d011c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 06:40:19 +0900 Subject: [PATCH 072/136] [revparse] improve codes --- revparse.c | 60 ++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/revparse.c b/revparse.c index f21aeca18d..07b4ab8c58 100644 --- a/revparse.c +++ b/revparse.c @@ -6,13 +6,11 @@ */ PHP_FUNCTION(git_revparse_single) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_object *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; char *spec = NULL; - int spec_len = 0; - int error = 0; + int spec_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &spec, &spec_len) == FAILURE) { @@ -24,15 +22,14 @@ PHP_FUNCTION(git_revparse_single) if (php_git2_check_error(error, "git_revparse_single" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, object) = out; - result->type = PHP_GIT2_TYPE_OBJECT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto array git_revparse_ext(resource $repo, string $spec) */ PHP_FUNCTION(git_revparse_ext) @@ -58,23 +55,19 @@ PHP_FUNCTION(git_revparse_ext) RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_MAKE_RESOURCE(result2); MAKE_STD_ZVAL(array); MAKE_STD_ZVAL(a); MAKE_STD_ZVAL(b); - PHP_GIT2_V(result, object) = object_out; - result->type = PHP_GIT2_TYPE_OBJECT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(a, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, object_out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(a, GIT2_RVAL_P(result)); - PHP_GIT2_V(result2, reference) = reference_out; - result2->type = PHP_GIT2_TYPE_REFERENCE; - result2->resource_id = PHP_GIT2_LIST_INSERT(result2, git2_resource_handle); - result2->should_free_v = 0; - ZVAL_RESOURCE(b, result->resource_id); + if (php_git2_make_resource(&result2, PHP_GIT2_TYPE_REFERENCE, reference_out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(b, GIT2_RVAL_P(result2)); array_init(array); add_next_index_zval(array, a); @@ -108,20 +101,15 @@ PHP_FUNCTION(git_revparse) RETURN_FALSE; } MAKE_STD_ZVAL(result); - MAKE_STD_ZVAL(from); - MAKE_STD_ZVAL(to); - - PHP_GIT2_V(_from, object) = revspec.from; - _from->type = PHP_GIT2_TYPE_OBJECT; - _from->resource_id = PHP_GIT2_LIST_INSERT(_from, git2_resource_handle); - _from->should_free_v = 0; - ZVAL_RESOURCE(from, _from->resource_id); - - PHP_GIT2_V(_to, object) = revspec.to; - _to->type = PHP_GIT2_TYPE_OBJECT; - _to->resource_id = PHP_GIT2_LIST_INSERT(_to, git2_resource_handle); - _to->should_free_v = 0; - ZVAL_RESOURCE(to, _to->resource_id); + if (php_git2_make_resource(&_from, PHP_GIT2_TYPE_OBJECT, revspec.from, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(from, GIT2_RVAL_P(_from)); + + if (php_git2_make_resource(&_to, PHP_GIT2_TYPE_OBJECT, revspec.to, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(to, GIT2_RVAL_P(_to)); array_init(result); add_assoc_zval_ex(result, ZEND_STRS("from"), from); From 1176658d0e63f0ed4a6430764aa86f7ca2bc18ad Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 06:57:30 +0900 Subject: [PATCH 073/136] improve codes --- cred.c | 51 +++++++++++++++++++-------------------------------- merge.c | 35 ++++++++++++++--------------------- odb.c | 41 ++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 74 deletions(-) diff --git a/cred.c b/cred.c index 57ae1fb757..309bba93d3 100644 --- a/cred.c +++ b/cred.c @@ -28,11 +28,8 @@ PHP_FUNCTION(git_cred_userpass_plaintext_new) { php_git2_t *result = NULL; git_cred *out = NULL; - char *username = NULL; - int username_len = 0; - char *password = NULL; - int password_len = 0; - int error = 0; + char *username = NULL, *password = NULL; + int username_len = 0, password_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &username, &username_len, &password, &password_len) == FAILURE) { @@ -43,30 +40,22 @@ PHP_FUNCTION(git_cred_userpass_plaintext_new) if (php_git2_check_error(error, "git_cred_userpass_plaintext_new" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, cred) = out; - result->type = PHP_GIT2_TYPE_CRED; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CRED, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto resource git_cred_ssh_key_new(string $username, string $publickey, string $privatekey, string $passphrase) */ PHP_FUNCTION(git_cred_ssh_key_new) { php_git2_t *result = NULL; git_cred *out = NULL; - char *username = NULL; - int username_len = 0; - char *publickey = NULL; - int publickey_len = 0; - char *privatekey = NULL; - int privatekey_len = 0; - char *passphrase = NULL; - int passphrase_len = 0; - int error = 0; + char *username = NULL, *publickey = NULL, *privatekey = NULL, *passphrase = NULL; + int username_len = 0, publickey_len = 0, privatekey_len = 0, passphrase_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &username, &username_len, &publickey, &publickey_len, &privatekey, &privatekey_len, &passphrase, &passphrase_len) == FAILURE) { @@ -77,16 +66,15 @@ PHP_FUNCTION(git_cred_ssh_key_new) if (php_git2_check_error(error, "git_cred_ssh_key_new" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, cred) = out; - result->type = PHP_GIT2_TYPE_CRED; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CRED, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto resource git_cred_ssh_custom_new(username, publickey, publickey_len, sign_fn, sign_data) */ PHP_FUNCTION(git_cred_ssh_custom_new) @@ -121,16 +109,15 @@ PHP_FUNCTION(git_cred_default_new) if (php_git2_check_error(error, "git_cred_default_new" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, cred) = out; - result->type = PHP_GIT2_TYPE_CRED; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CRED, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ + /* {{{ proto resource git_cred_userpass(url, user_from_url, allowed_types, payload) */ PHP_FUNCTION(git_cred_userpass) diff --git a/merge.c b/merge.c index 32237b819f..b85f50587a 100644 --- a/merge.c +++ b/merge.c @@ -83,11 +83,9 @@ PHP_FUNCTION(git_merge_head_from_ref) if (php_git2_check_error(error, "git_merge_head_from_ref" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, merge_head) = out; - result->type = PHP_GIT2_TYPE_MERGE_HEAD; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } ZVAL_RESOURCE(return_value, result->resource_id); } /* }}} */ @@ -158,11 +156,9 @@ PHP_FUNCTION(git_merge_head_from_oid) if (php_git2_check_error(error, "git_merge_head_from_oid" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, merge_head) = out; - result->type = PHP_GIT2_TYPE_MERGE_HEAD; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } ZVAL_RESOURCE(return_value, result->resource_id); } /* }}} */ @@ -220,11 +216,9 @@ PHP_FUNCTION(git_merge_trees) if (php_git2_check_error(error, "git_merge_trees" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, index) = out; - result->type = PHP_GIT2_TYPE_INDEX; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } ZVAL_RESOURCE(return_value, result->resource_id); } /* }}} */ @@ -255,11 +249,9 @@ PHP_FUNCTION(git_merge) if (php_git2_check_error(error, "git_merge" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, merge_result) = out; - result->type = PHP_GIT2_TYPE_MERGE_RESULT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_RESULT, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } ZVAL_RESOURCE(return_value, result->resource_id); } /* }}} */ @@ -346,8 +338,9 @@ PHP_FUNCTION(git_merge_result_free) } ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_merge_result->should_free_v) { + if (GIT2_SHOULD_FREE(_merge_result)) { git_merge_result_free(PHP_GIT2_V(_merge_result, merge_result)); + GIT2_SHOULD_FREE(_merge_result) = 0; }; zval_ptr_dtor(&merge_result); } diff --git a/odb.c b/odb.c index 537256744e..0ceb30850c 100644 --- a/odb.c +++ b/odb.c @@ -241,31 +241,32 @@ PHP_FUNCTION(git_odb_foreach) if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { RETURN_FALSE; } + // TODO(chobie): implment callback */ //result = git_odb_foreach(PHP_GIT2_V(_db, odb), , cb); php_git2_cb_free(cb); RETURN_LONG(result); } /* }}} */ -/* {{{ proto resource git_odb_write(resource $odb, $data, long $len, $type) +/* {{{ proto resource git_odb_write(resource $odb, $data, $type) */ PHP_FUNCTION(git_odb_write) { php_git2_t *result = NULL, *_odb = NULL; git_oid out = {0}; - zval *odb = NULL, *type = NULL; + zval *odb = NULL; zval *data = NULL; - long len = 0; - int error = 0; + long type = 0; + int error = 0, data_len = 0; char buf[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rl", &odb, &data, &len, &type) == FAILURE) { + "rsl", &odb, &data, &data_len, &type) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_odb_write(&out, PHP_GIT2_V(_odb, odb), data, len, type); + error = git_odb_write(&out, PHP_GIT2_V(_odb, odb), data, data_len, type); if (php_git2_check_error(error, "git_odb_write" TSRMLS_CC)) { RETURN_FALSE; } @@ -280,12 +281,12 @@ PHP_FUNCTION(git_odb_open_wstream) { php_git2_t *result = NULL, *_db = NULL; git_odb_stream *out = NULL; - zval *db = NULL, *type = NULL; - long size = 0; + zval *db = NULL; + long size = 0, type = 0; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rl", &db, &size, &type) == FAILURE) { + "rll", &db, &size, &type) == FAILURE) { return; } @@ -301,7 +302,7 @@ PHP_FUNCTION(git_odb_open_wstream) } /* }}} */ -/* {{{ proto long git_odb_stream_write(resource $stream, string $buffer, long $len) +/* {{{ proto long git_odb_stream_write(resource $stream, string $buffer) */ PHP_FUNCTION(git_odb_stream_write) { @@ -309,15 +310,14 @@ PHP_FUNCTION(git_odb_stream_write) zval *stream = NULL; php_git2_t *_stream = NULL; char *buffer = NULL; - long len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsl", &stream, &buffer, &buffer_len, &len) == FAILURE) { + "rs", &stream, &buffer, &buffer_len) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_stream, php_git2_t*, &stream, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_odb_stream_write(PHP_GIT2_V(_stream, odb_stream), buffer, len); + result = git_odb_stream_write(PHP_GIT2_V(_stream, odb_stream), buffer, buffer_len); RETURN_LONG(result); } /* }}} */ @@ -452,23 +452,22 @@ PHP_FUNCTION(git_odb_write_pack) } /* }}} */ -/* {{{ proto resource git_odb_hash( $data, long $len, $type) +/* {{{ proto resource git_odb_hash(string $data, long $type) */ PHP_FUNCTION(git_odb_hash) { php_git2_t *result = NULL; git_oid out = {0}; zval *data = NULL; - long len = 0; - zval *type = NULL; - int error = 0; + int error = 0, data_len = 0; + long type = 0; char buf[41] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &data, &len, &type) == FAILURE) { + "sl", &data, &data_len, &type) == FAILURE) { return; } - error = git_odb_hash(&out, data, len, type); + error = git_odb_hash(&out, data, data_len, type); if (php_git2_check_error(error, "git_odb_hash" TSRMLS_CC)) { RETURN_FALSE; } @@ -485,11 +484,11 @@ PHP_FUNCTION(git_odb_hashfile) git_oid out = {0}; char *path = NULL; int path_len = 0, error = 0; - zval *type = NULL; char buf[41] = {0}; + long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len, &type) == FAILURE) { + "sl", &path, &path_len, &type) == FAILURE) { return; } error = git_odb_hashfile(&out, path, type); From f6a94674521f4ab5d2ff00aace765e82e6de0ca2 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 07:09:53 +0900 Subject: [PATCH 074/136] improve codes --- pathspec.c | 99 +++++-------- reference.c | 396 ++++++++++++++++++++++++---------------------------- 2 files changed, 216 insertions(+), 279 deletions(-) diff --git a/pathspec.c b/pathspec.c index 7c1d328848..2d1a5f029e 100644 --- a/pathspec.c +++ b/pathspec.c @@ -7,8 +7,9 @@ PHP_FUNCTION(git_pathspec_new) { php_git2_t *result = NULL; - git_pathspec *out; + git_pathspec *out = NULL; zval *pathspec = NULL; + git_strarray _pathspec = {0}; int error = 0; /* TODO(chobie): generate converter */ @@ -17,20 +18,18 @@ PHP_FUNCTION(git_pathspec_new) return; } + php_git2_array_to_strarray(&_pathspec, pathspec TSRMLS_CC); error = git_pathspec_new(&out, pathspec); if (php_git2_check_error(error, "git_pathspec_new" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, pathspec) = out; - result->type = PHP_GIT2_TYPE_PATHSPEC; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATHSPEC, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto void git_pathspec_free(resource $ps) */ PHP_FUNCTION(git_pathspec_free) @@ -44,8 +43,9 @@ PHP_FUNCTION(git_pathspec_free) } ZEND_FETCH_RESOURCE(_ps, php_git2_t*, &ps, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_ps->should_free_v) { + if (GIT2_SHOULD_FREE(_ps)) { git_pathspec_free(PHP_GIT2_V(_ps, pathspec)); + GIT2_SHOULD_FREE(_ps) = 0; }; zval_ptr_dtor(&ps); } @@ -56,13 +56,11 @@ PHP_FUNCTION(git_pathspec_free) */ PHP_FUNCTION(git_pathspec_matches_path) { - int result = 0; + int result = 0, path_len = 0, error = 0; zval *ps = NULL; php_git2_t *_ps = NULL; long flags = 0; char *path = NULL; - int path_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &ps, &flags, &path, &path_len) == FAILURE) { @@ -80,13 +78,10 @@ PHP_FUNCTION(git_pathspec_matches_path) */ PHP_FUNCTION(git_pathspec_match_workdir) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL, *_ps = NULL; git_pathspec_match_list *out = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; + zval *repo = NULL, *ps = NULL; long flags = 0; - zval *ps = NULL; - php_git2_t *_ps = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -100,27 +95,21 @@ PHP_FUNCTION(git_pathspec_match_workdir) if (php_git2_check_error(error, "git_pathspec_match_workdir" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, pathspec_match_list) = out; - result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_pathspec_match_index(resource $index, long $flags, resource $ps) */ PHP_FUNCTION(git_pathspec_match_index) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_index = NULL, *_ps = NULL; git_pathspec_match_list *out = NULL; - zval *index = NULL; - php_git2_t *_index = NULL; + zval *index = NULL, *ps = NULL; long flags = 0; - zval *ps = NULL; - php_git2_t *_ps = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -134,27 +123,21 @@ PHP_FUNCTION(git_pathspec_match_index) if (php_git2_check_error(error, "git_pathspec_match_index" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, pathspec_match_list) = out; - result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_pathspec_match_tree(resource $tree, long $flags, resource $ps) */ PHP_FUNCTION(git_pathspec_match_tree) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_tree = NULL, *_ps = NULL; git_pathspec_match_list *out = NULL; - zval *tree = NULL; - php_git2_t *_tree = NULL; + zval *tree = NULL, *ps = NULL; long flags = 0; - zval *ps = NULL; - php_git2_t *_ps = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -168,27 +151,21 @@ PHP_FUNCTION(git_pathspec_match_tree) if (php_git2_check_error(error, "git_pathspec_match_tree" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, pathspec_match_list) = out; - result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_pathspec_match_diff(resource $diff, long $flags, resource $ps) */ PHP_FUNCTION(git_pathspec_match_diff) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_diff = NULL, *_ps = NULL; git_pathspec_match_list *out = NULL; - zval *diff = NULL; - php_git2_t *_diff = NULL; + zval *diff = NULL, *ps = NULL; long flags = 0; - zval *ps = NULL; - php_git2_t *_ps = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -202,16 +179,13 @@ PHP_FUNCTION(git_pathspec_match_diff) if (php_git2_check_error(error, "git_pathspec_match_diff" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, pathspec_match_list) = out; - result->type = PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATHSPEC_MATCH_LIST, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto void git_pathspec_match_list_free(resource $m) */ PHP_FUNCTION(git_pathspec_match_list_free) @@ -225,8 +199,9 @@ PHP_FUNCTION(git_pathspec_match_list_free) } ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_m->should_free_v) { + if (GIT2_SHOULD_FREE(_m)) { git_pathspec_match_list_free(PHP_GIT2_V(_m, pathspec_match_list)); + GIT2_SHOULD_FREE(_m) = 0; }; zval_ptr_dtor(&m); } @@ -278,7 +253,7 @@ PHP_FUNCTION(git_pathspec_match_list_entry) */ PHP_FUNCTION(git_pathspec_match_list_diff_entry) { - const git_diff_delta *result = NULL; + const git_diff_delta *result = NULL; zval *m = NULL; php_git2_t *_m = NULL; long pos = 0; diff --git a/reference.c b/reference.c index b74f352813..3cf5fc4b07 100644 --- a/reference.c +++ b/reference.c @@ -54,37 +54,33 @@ static int php_git2_reference_foreach_name_cb(const char *name, void *payload) return retval; } - -/* {{{ proto resource git_reference_lookup(repo, name) -*/ +/* {{{ proto resource git_reference_lookup(resource $repo, string $name) + */ PHP_FUNCTION(git_reference_lookup) { - zval *repo; - php_git2_t *_repo, *result; - char *name = {0}; - int name_len; - git_reference *out; - int error; + php_git2_t *result = NULL, *_repo = NULL; + git_reference *out = NULL; + zval *repo = NULL; + char *name = NULL; + int name_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &name, &name_len) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_reference_lookup(&out, PHP_GIT2_V(_repo, repository), name); if (php_git2_check_error(error, "git_reference_lookup" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ + /* {{{ proto resource git_reference_name_to_id(repo, name) */ @@ -113,49 +109,43 @@ PHP_FUNCTION(git_reference_name_to_id) RETURN_STRING(out, 1); } -/* {{{ proto resource git_reference_dwim(repo, shorthand) -*/ +/* {{{ proto resource git_reference_dwim(resource $repo, string $shorthand) + */ PHP_FUNCTION(git_reference_dwim) { - zval *repo; - php_git2_t *_repo, *result; - char *shorthand = {0}; - int shorthand_len; - git_reference *out; - int error = 0; + php_git2_t *result = NULL, *_repo = NULL; + git_reference *out = NULL; + zval *repo = NULL; + char *shorthand = NULL; + int shorthand_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &shorthand, &shorthand_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_reference_dwim(&out, PHP_GIT2_V(_repo, repository), shorthand); if (php_git2_check_error(error, "git_reference_dwim" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_symbolic_create(repo, name, target, force) -*/ +/* {{{ proto resource git_reference_symbolic_create(resource $repo, string $name, string $target, long $force) + */ PHP_FUNCTION(git_reference_symbolic_create) { - zval *repo; - php_git2_t *_repo, *result; - char *name = {0}; - int name_len; - char *target = {0}; - int target_len; + php_git2_t *result = NULL, *_repo = NULL; + git_reference *out = NULL; + zval *repo = NULL; + char *name = NULL, *target = NULL; + int name_len = 0, target_len = 0, error = 0; long force = 0; - int error; - git_reference *out; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &repo, &name, &name_len, &target, &target_len, &force) == FAILURE) { @@ -164,83 +154,69 @@ PHP_FUNCTION(git_reference_symbolic_create) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_reference_symbolic_create(&out, PHP_GIT2_V(_repo, repository), name, target, force); - if (php_git2_check_error(error, "git_reference_lookup" TSRMLS_CC)) { - RETURN_FALSE + if (php_git2_check_error(error, "git_reference_symbolic_create" TSRMLS_CC)) { + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_create(repo, name, id, force) -*/ +/* {{{ proto resource git_reference_create(resource $repo, string $name, string $id, long $force) + */ PHP_FUNCTION(git_reference_create) { - zval *repo; - php_git2_t *_repo, *result; - char *name = {0}; - int name_len; - char *id = {0}; - int id_len; + php_git2_t *result = NULL, *_repo = NULL; + git_reference *out = NULL; + zval *repo = NULL; + char *name = NULL, *id = NULL; + int name_len = 0, id_len = 0, error = 0; + git_oid __id = {0}; long force = 0; - git_reference *out; - git_oid oid; - int error; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &repo, &name, &name_len, &id, &id_len, &force) == FAILURE) { return; } - if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { - return; - } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_reference_create(&out, PHP_GIT2_V(_repo, repository), name, &oid, force); - if (php_git2_check_error(error, "git_reference_lookup" TSRMLS_CC)) { + if (git_oid_fromstrn(&__id, id, id_len)) { RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + error = git_reference_create(&out, PHP_GIT2_V(_repo, repository), name, &__id, force); + if (php_git2_check_error(error, "git_reference_create" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_target(ref) -*/ + +/* {{{ proto resource git_reference_target(resource $ref) + */ PHP_FUNCTION(git_reference_target) { - zval *ref; - php_git2_t *_ref, *result; - const git_reference *out = NULL; + const git_oid *result = NULL; + zval *ref = NULL; + php_git2_t *_ref = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - out = git_reference_target(PHP_GIT2_V(_ref, reference)); - if (out = NULL) { - RETURN_FALSE; - } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reference_target(PHP_GIT2_V(_ref, reference)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); } +/* }}} */ /* {{{ proto resource git_reference_target_peel(ref) */ @@ -281,209 +257,192 @@ PHP_FUNCTION(git_reference_symbolic_target) } /* }}} */ - -/* {{{ proto resource git_reference_type(ref) -*/ +/* {{{ proto resource git_reference_type(resource $ref) + */ PHP_FUNCTION(git_reference_type) { - zval *ref; - php_git2_t *_ref; - git_ref_t type; + git_ref_t *result = NULL; + zval *ref = NULL; + php_git2_t *_ref = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - type = git_tree_entry_type(PHP_GIT2_V(_ref, reference)); - RETURN_LONG(type); + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reference_type(PHP_GIT2_V(_ref, reference)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_reference_name(ref) -*/ +/* {{{ proto string git_reference_name(resource $ref) + */ PHP_FUNCTION(git_reference_name) { - zval *ref; - php_git2_t *_ref; - const char *name; + const char *result = NULL; + zval *ref = NULL; + php_git2_t *_ref = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - name = git_reference_name(PHP_GIT2_V(_ref, reference)); - RETURN_STRING(name, 1); + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reference_name(PHP_GIT2_V(_ref, reference)); + RETURN_STRING(result, 1); } +/* }}} */ -/* {{{ proto resource git_reference_resolve(ref) -*/ +/* {{{ proto resource git_reference_resolve(resource $ref) + */ PHP_FUNCTION(git_reference_resolve) { - zval *ref; - php_git2_t *_ref, *result; - git_reference *out; + php_git2_t *result = NULL, *_ref = NULL; + git_reference *out = NULL; + zval *ref = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_reference_resolve(&out, PHP_GIT2_V(_ref, reference)); if (php_git2_check_error(error, "git_reference_resolve" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_owner(ref) -*/ +/* {{{ proto resource git_reference_owner(resource $ref) + */ PHP_FUNCTION(git_reference_owner) { - zval *ref; - php_git2_t *_ref, *result; - git_repository *repository; + git_repository *result = NULL; + zval *ref = NULL; + php_git2_t *_ref = NULL, *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - PHP_GIT2_MAKE_RESOURCE(result); - repository = git_reference_owner(PHP_GIT2_V(_ref, reference)); - - PHP_GIT2_V(result, repository) = repository; - result->type = PHP_GIT2_TYPE_REPOSITORY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reference_owner(PHP_GIT2_V(_ref, reference)); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_REFERENCE, result, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); } +/* }}} */ -/* {{{ proto resource git_reference_symbolic_set_target(ref, target) -*/ +/* {{{ proto resource git_reference_symbolic_set_target(resource $ref, string $target) + */ PHP_FUNCTION(git_reference_symbolic_set_target) { - zval *ref; - php_git2_t *_ref, *result; - char *target = {0}; - int target_len; - git_reference *out; - int error = 0; + php_git2_t *result = NULL, *_ref = NULL; + git_reference *out = NULL; + zval *ref = NULL; + char *target = NULL; + int target_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ref, &target, &target_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_reference_symbolic_set_target(&out, PHP_GIT2_V(_ref, reference), target); if (php_git2_check_error(error, "git_reference_symbolic_set_target" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_set_target(ref, id) -*/ + +/* {{{ proto resource git_reference_set_target(resource $ref, string $id) + */ PHP_FUNCTION(git_reference_set_target) { - zval *ref; - php_git2_t *_ref, *result; - char *id = {0}; - int id_len; - git_oid oid; - int error; - git_reference *out; + php_git2_t *result = NULL, *_ref = NULL; + git_reference *out = NULL; + zval *ref = NULL; + char *id = NULL; + int id_len = 0, error = 0; + git_oid __id = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ref, &id, &id_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { - return; + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; } - error = git_reference_set_target(&out, PHP_GIT2_V(_ref, reference), &oid); + error = git_reference_set_target(&out, PHP_GIT2_V(_ref, reference), &__id); if (php_git2_check_error(error, "git_reference_set_target" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_reference_rename(ref, new_name, force) -*/ +/* {{{ proto long git_reference_rename(resource $ref, string $new_name, long $force) + */ PHP_FUNCTION(git_reference_rename) { - zval *ref; - php_git2_t *_ref, *result; - char *new_name = {0}; - int new_name_len; + int result = 0, new_name_len = 0, error = 0; + git_reference *new_ref = NULL; + zval *ref = NULL; + php_git2_t *_ref = NULL; + char *new_name = NULL; long force = 0; - git_reference *out; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &ref, &new_name, &new_name_len, &force) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_reference_rename(&out, PHP_GIT2_V(_ref, reference), new_name, force); - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, reference) = out; - result->type = PHP_GIT2_TYPE_REFERENCE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_reference_rename(&new_ref, PHP_GIT2_V(_ref, reference), new_name, force); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_reference_delete(ref) -*/ +/* {{{ proto long git_reference_delete(resource $ref) + */ PHP_FUNCTION(git_reference_delete) { - zval *ref; - php_git2_t *_ref; - int error; + int result = 0, error = 0; + zval *ref = NULL; + php_git2_t *_ref = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_reference_delete(PHP_GIT2_V(_ref, reference)); - if (php_git2_check_error(error, "git_reference_delete" TSRMLS_CC)) { - RETURN_FALSE - } - zval_ptr_dtor(&ref); + result = git_reference_delete(PHP_GIT2_V(_ref, reference)); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_reference_list(repo) */ @@ -511,6 +470,7 @@ PHP_FUNCTION(git_reference_list) RETURN_ZVAL(result, 0, 1); } +/* }}} */ /* {{{ proto long git_reference_foreach(resource $repo, $callback, $payload) */ @@ -566,24 +526,26 @@ PHP_FUNCTION(git_reference_foreach_name) } /* }}} */ -/* {{{ proto void git_reference_free(ref) -*/ +/* {{{ proto void git_reference_free(resource $ref) + */ PHP_FUNCTION(git_reference_free) { - zval *ref; - php_git2_t *_ref; + zval *ref = NULL; + php_git2_t *_ref = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ref) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_ref->should_free_v) { + if (GIT2_SHOULD_FREE(_ref)) { git_reference_free(PHP_GIT2_V(_ref, reference)); - _ref->should_free_v = 0; - } + GIT2_SHOULD_FREE(_ref) = 0; + }; zval_ptr_dtor(&ref); } +/* }}} */ /* {{{ proto long git_reference_cmp(ref1, ref2) */ From 325445b880f8969775490f94a70b50772ff46e64 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 07:14:10 +0900 Subject: [PATCH 075/136] [reflog] implement git_reflog_entry_byindex --- reflog.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/reflog.c b/reflog.c index ffff200c09..197cdd2f1c 100644 --- a/reflog.c +++ b/reflog.c @@ -161,7 +161,7 @@ PHP_FUNCTION(git_reflog_entry_byindex) { const git_reflog_entry *result = NULL; zval *reflog = NULL; - php_git2_t *_reflog = NULL; + php_git2_t *_reflog = NULL, *_result; long idx = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -171,7 +171,10 @@ PHP_FUNCTION(git_reflog_entry_byindex) ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_reflog_entry_byindex(PHP_GIT2_V(_reflog, reflog), idx); - /* TODO(chobie): implement this */ + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_REFLOG_ENTRY, result, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT_RVAL_P(_result)); } /* }}} */ From 6fa2207f0e97099154f3635a705296ec18cfd0f8 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 07:18:38 +0900 Subject: [PATCH 076/136] rename harcoded value to macro --- branch.c | 10 +++++----- g_config.c | 8 ++++---- php_git2_priv.h | 2 ++ reference.c | 4 ++-- repository.c | 8 ++++---- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/branch.c b/branch.c index fa738b3a81..cbf361cc91 100644 --- a/branch.c +++ b/branch.c @@ -191,7 +191,7 @@ PHP_FUNCTION(git_branch_lookup) PHP_FUNCTION(git_branch_name) { php_git2_t *result = NULL; - char out[512] = {0}; + char out[GIT2_BUFFER_SIZE] = {0}; zval *ref = NULL; php_git2_t *_ref = NULL; int error = 0; @@ -242,8 +242,8 @@ PHP_FUNCTION(git_branch_upstream) PHP_FUNCTION(git_branch_upstream_name) { php_git2_t *result = NULL; - char tracking_branch_name_out[512] = {0}; - long buffer_size = 512; + char tracking_branch_name_out[GIT2_BUFFER_SIZE] = {0}; + long buffer_size = GIT2_BUFFER_SIZE; zval *repo = NULL; php_git2_t *_repo = NULL; char *canonical_branch_name = NULL; @@ -289,8 +289,8 @@ PHP_FUNCTION(git_branch_is_head) PHP_FUNCTION(git_branch_remote_name) { php_git2_t *result = NULL; - char remote_name_out[512] = {0}; - long buffer_size = 512; + char remote_name_out[GIT2_BUFFER_SIZE] = {0}; + long buffer_size = GIT2_BUFFER_SIZE; zval *repo = NULL; php_git2_t *_repo = NULL; char *canonical_branch_name = NULL; diff --git a/g_config.c b/g_config.c index f62afb1068..bfc4abe805 100644 --- a/g_config.c +++ b/g_config.c @@ -205,8 +205,8 @@ static void php_git2_config_entry_to_array(git_config_entry *entry, zval **resul */ PHP_FUNCTION(git_config_find_global) { - char buffer[512]; - size_t buffer_len = 512; + char buffer[GIT2_BUFFER_SIZE]; + size_t buffer_len = GIT2_BUFFER_SIZE; int error = 0; error = git_config_find_global(buffer, buffer_len); @@ -235,8 +235,8 @@ PHP_FUNCTION(git_config_find_xdg) */ PHP_FUNCTION(git_config_find_system) { - char buffer[512]; - size_t buffer_len = 512; + char buffer[GIT2_BUFFER_SIZE]; + size_t buffer_len = GIT2_BUFFER_SIZE; int error = 0; error = git_config_find_system(buffer, buffer_len); diff --git a/php_git2_priv.h b/php_git2_priv.h index b489d02b10..d105a8e2e1 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -70,6 +70,8 @@ do {\ } while (0);\ #define GIT2_OID_HEXSIZE (GIT_OID_HEXSZ+1) +#define GIT2_BUFFER_SIZE 512 + typedef struct php_git2_cb_t { zval *payload; diff --git a/reference.c b/reference.c index 3cf5fc4b07..8b08faf514 100644 --- a/reference.c +++ b/reference.c @@ -799,8 +799,8 @@ PHP_FUNCTION(git_reference_normalize_name) char *name = {0}; int name_len; long flags; - char buffer[512] = {0}; - size_t buffer_sz = 512; + char buffer[GIT2_BUFFER_SIZE] = {0}; + size_t buffer_sz = GIT2_BUFFER_SIZE; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/repository.c b/repository.c index 74310f97c1..33b90706c8 100644 --- a/repository.c +++ b/repository.c @@ -244,8 +244,8 @@ PHP_FUNCTION(git_repository_discover) char *ceiling_dirs = {0}; int ceiling_dirs_len; int error = 0; - char buffer[512]; - size_t buffer_len = 512; + char buffer[GIT2_BUFFER_SIZE]; + size_t buffer_len = GIT2_BUFFER_SIZE; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &start_path, &start_path_len, &across_fs, &ceiling_dirs, &ceiling_dirs_len) == FAILURE) { @@ -609,8 +609,8 @@ PHP_FUNCTION(git_repository_message) { zval *repo; php_git2_t *_repo; - char buffer[512]; - size_t buffer_len = 512; + char buffer[GIT2_BUFFER_SIZE]; + size_t buffer_len = GIT2_BUFFER_SIZE; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, From 56f675a5cec7bdd0e6ad84d2b15f129f03a089f3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 07:21:11 +0900 Subject: [PATCH 077/136] rename harcoded value to macro --- note.c | 2 +- odb.c | 8 ++++---- repository.c | 4 ++-- stash.c | 4 ++-- tag.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/note.c b/note.c index f79b9d5d2a..5a743f8860 100644 --- a/note.c +++ b/note.c @@ -151,7 +151,7 @@ PHP_FUNCTION(git_note_create) char *notes_ref = NULL, *oid = NULL, *note = NULL; int notes_ref_len = 0, oid_len = 0, note_len = 0, error = 0; long force = 0; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "raasssl", &repo, &author, &committer, ¬es_ref, ¬es_ref_len, &oid, &oid_len, ¬e, ¬e_len, &force) == FAILURE) { diff --git a/odb.c b/odb.c index 0ceb30850c..71bdd4059f 100644 --- a/odb.c +++ b/odb.c @@ -258,7 +258,7 @@ PHP_FUNCTION(git_odb_write) zval *data = NULL; long type = 0; int error = 0, data_len = 0; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &odb, &data, &data_len, &type) == FAILURE) { @@ -330,7 +330,7 @@ PHP_FUNCTION(git_odb_stream_finalize_write) git_oid out = {0}; zval *stream = NULL; int error = 0; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &stream) == FAILURE) { @@ -461,7 +461,7 @@ PHP_FUNCTION(git_odb_hash) zval *data = NULL; int error = 0, data_len = 0; long type = 0; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &type) == FAILURE) { @@ -484,7 +484,7 @@ PHP_FUNCTION(git_odb_hashfile) git_oid out = {0}; char *path = NULL; int path_len = 0, error = 0; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/repository.c b/repository.c index 33b90706c8..8513cff20c 100644 --- a/repository.c +++ b/repository.c @@ -13,7 +13,7 @@ static int php_git2_repository_fetchhead_foreach_cb(const char *ref_name, php_git2_cb_t *p = (php_git2_cb_t*)payload; int i = 0; long retval = 0; - char _oid[41] = {0}; + char _oid[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) git_oid_fmt(_oid, oid); @@ -50,7 +50,7 @@ static int php_git2_repository_mergehead_foreach_cb(const git_oid *oid, php_git2_cb_t *p = (php_git2_cb_t*)payload; int i = 0; long retval = 0; - char _oid[41] = {0}; + char _oid[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) git_oid_fmt(_oid, oid); diff --git a/stash.c b/stash.c index f4383d9f30..d6c1ffd087 100644 --- a/stash.c +++ b/stash.c @@ -12,7 +12,7 @@ static int php_git2_stash_cb(size_t index, php_git2_cb_t *p = (php_git2_cb_t*)payload; int i = 0; long retval = 0; - char _oid[41] = {0}; + char _oid[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) git_oid_fmt(_oid, stash_id); @@ -44,7 +44,7 @@ PHP_FUNCTION(git_stash_save) char *message = NULL; int message_len = 0, error = 0; long flags = 0; - char buf[41] = {0}; + char buf[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rasl", &repo, &stasher, &message, &message_len, &flags) == FAILURE) { diff --git a/tag.c b/tag.c index df9a35ac7e..b2859e0954 100644 --- a/tag.c +++ b/tag.c @@ -9,7 +9,7 @@ static int php_git2_tag_foreach_cb(const char *name, git_oid *oid, void *payload php_git2_cb_t *p = (php_git2_cb_t*)payload; int i = 0; long retval = 0; - char buffer[41] = {0}; + char buffer[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) git_oid_fmt(buffer, oid); From 76fc5facdf206f0aca0719a59e45792611e243c0 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 07:31:46 +0900 Subject: [PATCH 078/136] refactor objects --- ng.php | 4 + object.c | 284 +++++++++++++++++++++++++++---------------------------- 2 files changed, 141 insertions(+), 147 deletions(-) diff --git a/ng.php b/ng.php index 844838d32c..348e19bf57 100644 --- a/ng.php +++ b/ng.php @@ -193,6 +193,8 @@ public function getZendType() return "long"; } else if (preg_match("/git_oid/", $this->type)) { return "char"; + } else if (preg_match("/git_otype/", $this->type)) { + return "long"; } else if (preg_match("/^git_/", $this->type)) { return "zval"; } else if (preg_match("/payload/", $this->name)) { @@ -457,6 +459,8 @@ public function generateProto(Printer $printer, Func $f) $printer->put("array"); } else if (preg_match("/_cb$/", $arg->getType())) { $printer->put("Callable"); + } else if (preg_match("/git_otype/", $arg->getType())) { + $printer->put("long"); } else { error_log(sprintf("# unknown type (%s)", $arg->getType())); } diff --git a/object.c b/object.c index 76e8a39b34..012dc222eb 100644 --- a/object.c +++ b/object.c @@ -2,94 +2,91 @@ #include "php_git2_priv.h" #include "object.h" -/* {{{ proto resource git_object_lookup(repo, id, type) -*/ +/* {{{ proto long git_object_lookup(resource $repo, string $id, long $type) + */ PHP_FUNCTION(git_object_lookup) { - zval *repo; - php_git2_t *_repo, *result; - char *id = {0}; - int id_len; - zval *type; - php_git2_t *_type; - int error = 0; - git_object *object; - git_oid oid; + int result = 0, id_len = 0, error = 0; + git_object *object = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL; + char *id = NULL; + git_oid __id = {0}; + long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsr", &repo, &id, &id_len, &type) == FAILURE) { + "rsl", &repo, &id, &id_len, &type) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (git_oid_fromstrn(&oid, id, id_len) != GIT_OK) { - return; + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; } - error = git_object_lookup(&object, PHP_GIT2_V(_repo, repository), &oid, type); - if (php_git2_check_error(error, "git_object_lookup" TSRMLS_CC)) { - RETURN_FALSE - } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, object) = object; - result->type = PHP_GIT2_TYPE_OBJECT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + result = git_object_lookup(&object, PHP_GIT2_V(_repo, repository), &__id, type); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_object_lookup_prefix(repo, id, len, type) -*/ +/* {{{ proto resource git_object_lookup_prefix(resource $repo, string $id, long $len, long $type) + */ PHP_FUNCTION(git_object_lookup_prefix) { - zval *repo; - php_git2_t *_repo; - char *id = {0}; - int id_len; - zval *type; - php_git2_t *_type; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_object_lookup_prefix not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rsr", &repo, &id, &id_len, &len, &type) == FAILURE) { -// return; -// } + php_git2_t *result = NULL, *_repo = NULL; + git_object *object_out = NULL; + zval *repo = NULL; + char *id = NULL; + int id_len = 0, error = 0; + git_oid __id = {0}; + long len = 0, type = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsll", &repo, &id, &id_len, &len, &type) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + error = git_object_lookup_prefix(&object_out, PHP_GIT2_V(_repo, repository), &__id, len, type); + if (php_git2_check_error(error, "git_object_lookup_prefix" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, object_out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_object_lookup_bypath(treeish, path, type) -*/ +/* {{{ proto resource git_object_lookup_bypath(resource $treeish, string $path, long $type) + */ PHP_FUNCTION(git_object_lookup_bypath) { - zval *treeish; - php_git2_t *_treeish, *result; - char *path = {0}; - int path_len; - zval *type; - php_git2_t *_type; - git_object *object; - int error; + php_git2_t *result = NULL, *_treeish = NULL; + git_object *out = NULL; + zval *treeish = NULL; + char *path = NULL; + int path_len = 0, error = 0; + long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsr", &treeish, &path, &path_len, &type) == FAILURE) { + "rsl", &treeish, &path, &path_len, &type) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_treeish, php_git2_t*, &treeish, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - // TODO: cast object - error = git_object_lookup_bypath(&object, PHP_GIT2_V(_treeish, tree), path, type); + error = git_object_lookup_bypath(&out, PHP_GIT2_V(_treeish, object), path, type); if (php_git2_check_error(error, "git_object_lookup_bypath" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, object) = object; - result->type = PHP_GIT2_TYPE_OBJECT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ /* {{{ proto resource git_object_id(obj) */ @@ -109,84 +106,86 @@ PHP_FUNCTION(git_object_id) git_oid_fmt(buf, id); RETURN_STRING(buf, 1); } +/* }}} */ -/* {{{ proto resource git_object_type(obj) -*/ +/* {{{ proto resource git_object_type(resource $obj) + */ PHP_FUNCTION(git_object_type) { - zval *obj; - php_git2_t *_obj; - const git_otype *type; + git_otype *result = NULL; + zval *obj = NULL; + php_git2_t *_obj = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &obj) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - type = git_object_type(PHP_GIT2_V(_obj, object)); - RETURN_LONG(type); + result = git_object_type(PHP_GIT2_V(_obj, object)); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_object_owner(obj) -*/ +/* {{{ proto resource git_object_owner(resource $obj) + */ PHP_FUNCTION(git_object_owner) { - zval *obj; - php_git2_t *_obj, *result; - git_repository *repository; + git_repository *result = NULL; + zval *obj = NULL; + php_git2_t *_obj = NULL, *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &obj) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_obj, php_git2_t*, &obj, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - // TODO: consider cast - repository = git_object_owner(PHP_GIT2_V(_obj, object)); - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, repository) = repository; - result->type = PHP_GIT2_TYPE_REPOSITORY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + result = git_object_owner(PHP_GIT2_V(_obj, object)); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_OBJECT, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); } +/* }}} */ -/* {{{ proto void git_object_free(object) -*/ +/* {{{ proto void git_object_free(resource $object) + */ PHP_FUNCTION(git_object_free) { - zval *object; - php_git2_t *_object; + zval *object = NULL; + php_git2_t *_object = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &object) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_object->should_free_v) { + if (GIT2_SHOULD_FREE(_object)) { git_object_free(PHP_GIT2_V(_object, object)); - _object->should_free_v = 0; - } + GIT2_SHOULD_FREE(_object) = 0; + }; zval_ptr_dtor(&object); } +/* }}} */ -/* {{{ proto resource git_object_type2string(type) -*/ +/* {{{ proto string git_object_type2string(long $type) + */ PHP_FUNCTION(git_object_type2string) { - zval *type; - php_git2_t *_type; - const char *result; + const char *result = NULL; + long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &type) == FAILURE) { + "l", &type) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - // TODO: consider cast - result = git_object_type2string(PHP_GIT2_V(_type, object)); + + result = git_object_type2string(type); RETURN_STRING(result, 1); } +/* }}} */ /* {{{ proto resource git_object_string2type(str) */ @@ -203,26 +202,24 @@ PHP_FUNCTION(git_object_string2type) type = git_object_string2type(str); RETURN_LONG(type); } +/* }}} */ -/* {{{ proto long git_object_typeisloose(type) -*/ +/* {{{ proto long git_object_typeisloose(long $type) + */ PHP_FUNCTION(git_object_typeisloose) { - zval *type; - php_git2_t *_type; - int error = 0; + int result = 0, error = 0; + long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &type) == FAILURE) { + "l", &type) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_type, php_git2_t*, &type, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_object_typeisloose(PHP_GIT2_V(_type, object)); - if (php_git2_check_error(error, "git_object_typeisloose" TSRMLS_CC)) { - RETURN_FALSE - } - RETURN_TRUE; + + result = git_object_typeisloose(type); + RETURN_LONG(result); } +/* }}} */ /* {{{ proto resource git_object__size(type) */ @@ -239,56 +236,49 @@ PHP_FUNCTION(git_object__size) RETURN_LONG(size); } -/* {{{ proto resource git_object_peel(object, target_type) -*/ +/* {{{ proto long git_object_peel(resource $object, long $target_type) + */ PHP_FUNCTION(git_object_peel) { - zval *object; - php_git2_t *_object, *result; - zval *target_type; - php_git2_t *_target_type; - int error = 0; - git_object *out; - + int result = 0, error = 0; + git_object *peeled = NULL; + zval *object = NULL; + php_git2_t *_object = NULL, *_result; + long target_type = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &object, &target_type) == FAILURE) { + "rl", &object, &target_type) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_object_peel(&out, PHP_GIT2_V(_object, object), target_type); - if (php_git2_check_error(error, "git_object_peel" TSRMLS_CC)) { - RETURN_FALSE + result = git_object_peel(&peeled, PHP_GIT2_V(_object, object), target_type); + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_OBJECT, peeled, 1 TSRMLS_CC)) { + RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, object) = object; - result->type = PHP_GIT2_TYPE_OBJECT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + ZVAL_RESOURCE(return_value, GIT_RVAL_P(_result)); } +/* }}} */ -/* {{{ proto resource git_object_dup(source) -*/ +/* {{{ proto long git_object_dup(resource $source) + */ PHP_FUNCTION(git_object_dup) { - zval *source; - php_git2_t *_source, *result; - git_object *dest; - int error = 0; + int result = 0, error = 0; + git_object *dest = NULL; + zval *source = NULL; + php_git2_t *_source = NULL, *_result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &source) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_object_dup(&dest, PHP_GIT2_V(_source, object)); - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, object) = dest; - result->type = PHP_GIT2_TYPE_OBJECT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 1; - - ZVAL_RESOURCE(return_value, result->resource_id); + result = git_object_dup(&dest, PHP_GIT2_V(_source, object)); + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_OBJECT, dest, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT_RVAL_P(_result)); } - +/* }}} */ From 38cdbb05cb2fafe77060324ef9a677e131eb3b9a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 08:03:15 +0900 Subject: [PATCH 079/136] fix warnings --- diff.c | 6 +++--- helper.c | 5 +++-- object.c | 4 ++-- php_git2.c | 29 ++++++++++++++++++++++++++++- reflog.c | 2 +- transport.c | 2 +- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/diff.c b/diff.c index 2890060bbd..e0f34f6a5a 100644 --- a/diff.c +++ b/diff.c @@ -76,7 +76,7 @@ PHP_FUNCTION(git_diff_tree_to_index) if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT_RVAL_P(_diff)); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_diff)); } /* }}} */ @@ -101,7 +101,7 @@ PHP_FUNCTION(git_diff_index_to_workdir) if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT_RVAL_P(_diff)); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_diff)); } /* }}} */ @@ -147,7 +147,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT_RVAL_P(_diff)); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_diff)); } /* }}} */ diff --git a/helper.c b/helper.c index d72d200b72..ba3b4215bb 100644 --- a/helper.c +++ b/helper.c @@ -111,9 +111,10 @@ void php_git2_signature_to_array(const git_signature *signature, zval **out TSRM tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone TSRMLS_CC); tzobj->initialized = 1; tzobj->type = TIMELIB_ZONETYPE_OFFSET; - tzobj->tzi.utc_offset = -signature->when.offset; /* NOTE(chobie): probably this fine */ + tzobj->tzi.utc_offset = -signature->when.offset; // doesn't work - php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), NULL, 0, NULL, timezone, 0 TSRMLS_CC); + /* TODO(chobie): how do i set offset? */ + php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), time_str, strlen(time_str), NULL, timezone, 0 TSRMLS_CC); add_assoc_string_ex(result, ZEND_STRS("name"), signature->name, 1); add_assoc_string_ex(result, ZEND_STRS("email"), signature->email, 1); diff --git a/object.c b/object.c index 012dc222eb..3ccc98e758 100644 --- a/object.c +++ b/object.c @@ -256,7 +256,7 @@ PHP_FUNCTION(git_object_peel) if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_OBJECT, peeled, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT_RVAL_P(_result)); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ @@ -279,6 +279,6 @@ PHP_FUNCTION(git_object_dup) if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_OBJECT, dest, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT_RVAL_P(_result)); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ diff --git a/php_git2.c b/php_git2.c index 40425dab08..0ddb25b6a0 100644 --- a/php_git2.c +++ b/php_git2.c @@ -135,7 +135,7 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v PHP_GIT2_V(result, commit) = (git_commit*)resource; break; case PHP_GIT2_TYPE_TREE: - PHP_GIT2_V(result, commit) = (git_tree*)resource; + PHP_GIT2_V(result, tree) = (git_tree*)resource; break; case PHP_GIT2_TYPE_TREE_ENTRY: PHP_GIT2_V(result, tree_entry) = (git_tree_entry*)resource; @@ -236,6 +236,33 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v case PHP_GIT2_TYPE_NOTE_ITERATOR: PHP_GIT2_V(result, note_iterator) = (git_note_iterator*)resource; break; + case PHP_GIT2_TYPE_ODB_STREAM: + PHP_GIT2_V(result, odb_stream) = (git_odb_stream*)resource; + break; + case PHP_GIT2_TYPE_ODB_OBJECT: + PHP_GIT2_V(result, odb_object) = (git_odb_object*)resource; + break; + case PHP_GIT2_TYPE_ODB_WRITEPACK: + PHP_GIT2_V(result, odb_writepack) = (git_odb_writepack*)resource; + break; + case PHP_GIT2_TYPE_ODB_BACKEND: + PHP_GIT2_V(result, odb_backend) = (git_odb_backend*)resource; + break; + case PHP_GIT2_TYPE_REFLOG: + PHP_GIT2_V(result, reflog) = (git_reflog*)resource; + break; + case PHP_GIT2_TYPE_REFLOG_ENTRY: + PHP_GIT2_V(result, reflog_entry) = (git_reflog_entry*)resource; + break; + case PHP_GIT2_TYPE_BLAME: + PHP_GIT2_V(result, blame) = (git_blame*)resource; + break; + case PHP_GIT2_TYPE_PACKBUILDER: + PHP_GIT2_V(result, packbuilder) = (git_packbuilder*)resource; + break; + case PHP_GIT2_TYPE_SUBMODULE: + PHP_GIT2_V(result, submodule) = (git_submodule*)resource; + break; default: php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } diff --git a/reflog.c b/reflog.c index 197cdd2f1c..a0554e7f65 100644 --- a/reflog.c +++ b/reflog.c @@ -174,7 +174,7 @@ PHP_FUNCTION(git_reflog_entry_byindex) if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_REFLOG_ENTRY, result, 0 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT_RVAL_P(_result)); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ diff --git a/transport.c b/transport.c index 933368e775..e4589ba132 100644 --- a/transport.c +++ b/transport.c @@ -17,7 +17,7 @@ static int php_git2_transport_cb(git_transport **out, git_remote *owner, void *p if (php_git2_make_resource(&_param_owner, PHP_GIT2_TYPE_REMOTE, owner, 0 TSRMLS_CC)) { return 0; } - ZVAL_RESOURCE(param_owner, GIT_RVAL_P(_param_owner)); + ZVAL_RESOURCE(param_owner, GIT2_RVAL_P(_param_owner)); if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_owner, &p->payload)) { return GIT_EUSER; From 4eabc43c5ce8c3dd678e8d1f01c7f96bb6cd3bf4 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 08:14:14 +0900 Subject: [PATCH 080/136] [blob] improve codes --- blob.c | 186 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 128 insertions(+), 58 deletions(-) diff --git a/blob.c b/blob.c index 42f73a7714..32d142f68d 100644 --- a/blob.c +++ b/blob.c @@ -28,12 +28,40 @@ PHP_FUNCTION(git_blob_create_frombuffer) git_oid_fmt(out, &id); RETURN_STRING(out, 1); } +/* }}} */ -/* {{{ proto resource git_blob_create_fromchunks(resource $repository, string $hintpath, Callable $callback, mixed payload) -*/ +/* {{{ proto long git_blob_create_fromchunks(string $id, resource $repo, string $hintpath, Callable $callback, $payload) + */ PHP_FUNCTION(git_blob_create_fromchunks) { + int result = 0, id_len = 0, hintpath_len = 0, error = 0; + char *id = NULL, *hintpath = NULL; + git_oid __id = {0}; + zval *repo = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "srsfz", &id, &id_len, &repo, &hintpath, &hintpath_len, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + // TODO(chobie) implement this */ + //result = git_blob_create_fromchunks(__id, PHP_GIT2_V(_repo, repository), hintpath, , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto resource git_blob_create_fromdisk(resource $repository, string $path) */ @@ -62,6 +90,7 @@ PHP_FUNCTION(git_blob_create_fromdisk) git_oid_fmt(out, &id); RETURN_STRING(out, 1); } +/* }}} */ /* {{{ proto resource git_blob_create_fromworkdir(resource $repository, string $relative_path) */ @@ -90,32 +119,56 @@ PHP_FUNCTION(git_blob_create_fromworkdir) git_oid_fmt(out, &id); RETURN_STRING(out, 1); } +/* }}} */ -/* {{{ proto resource git_blob_filtered_content($blob, $as_path, $check_for_binary_data) -*/ +/* {{{ proto resource git_blob_filtered_content(resource $blob, string $as_path, long $check_for_binary_data) + */ PHP_FUNCTION(git_blob_filtered_content) { + php_git2_t *result = NULL, *_blob = NULL; + git_buf out = NULL; + zval *blob = NULL; + char *as_path = NULL; + int as_path_len = 0, error = 0; + long check_for_binary_data = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &blob, &as_path, &as_path_len, &check_for_binary_data) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_blob_filtered_content(&out, PHP_GIT2_V(_blob, blob), as_path, check_for_binary_data); + if (php_git2_check_error(error, "git_blob_filtered_content" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_blob_free(resource $blob) -*/ +/* {{{ proto void git_blob_free(resource $blob) + */ PHP_FUNCTION(git_blob_free) { - zval *blob; - php_git2_t *git2; + zval *blob = NULL; + php_git2_t *_blob = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &blob) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (git2->should_free_v) { - git_blob_free(PHP_GIT2_V(git2, blob)); - git2->should_free_v = 0; - } + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_blob)) { + git_blob_free(PHP_GIT2_V(_blob, blob)); + GIT2_SHOULD_FREE(_blob) = 0; + }; zval_ptr_dtor(&blob); } +/* }}} */ /* {{{ proto resource git_blob_id(resource $blob) */ @@ -137,6 +190,7 @@ PHP_FUNCTION(git_blob_id) git_oid_fmt(out, id); RETURN_STRING(out, 1); } +/* }}} */ /* {{{ proto resource git_blob_is_binary(resource $blob) */ @@ -155,75 +209,89 @@ PHP_FUNCTION(git_blob_is_binary) result = git_blob_is_binary(PHP_GIT2_V(git2, blob)); RETURN_BOOL(result); } +/* }}} */ -/* {{{ proto resource git_blob_lookup(resource $repository, string $oid) -*/ +/* {{{ proto long git_blob_lookup(resource $repo, string $id) + */ PHP_FUNCTION(git_blob_lookup) { - zval *repository; - php_git2_t *git2, *result; - git_blob *blob; - char *hash; - int hash_len; - int error; - git_oid id; + int result = 0, id_len = 0, error = 0; + git_blob *blob = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL, *_result = NULL; + char *id = NULL; + git_oid __id = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &repository, &hash, &hash_len) == FAILURE) { + "rs", &repo, &id, &id_len) == FAILURE) { return; } - if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { - return; + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; } - - ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - error = git_blob_lookup(&blob, PHP_GIT2_V(git2, repository), &id); - if (php_git2_check_error(error, "git_blob_lookup" TSRMLS_CC)) { - RETURN_FALSE + result = git_blob_lookup(&blob, PHP_GIT2_V(_repo, repository), &__id); + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_BLOB, result, 0 TSRMLS_CC)) { + RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, blob) = blob; - result->type = PHP_GIT2_TYPE_BLOB; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } +/* }}} */ -/* {{{ proto resource git_blob_lookup_prefix(resource $blob, string $oid) -*/ + +/* {{{ proto long git_blob_lookup_prefix(resource $repo, string $id, long $len) + */ PHP_FUNCTION(git_blob_lookup_prefix) { + int result = 0, id_len = 0, error = 0; + git_blob *blob = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL, *_result = NULL; + char *id = NULL; + git_oid __id = {0}; + long len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsl", &repo, &id, &id_len, &len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_blob_lookup_prefix(&blob, PHP_GIT2_V(_repo, repository), &__id, len); + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_BLOB, blob, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } +/* }}} */ -/* {{{ proto resource git_blob_owner(resource $blob, string $oid) -*/ + +/* {{{ proto resource git_blob_owner(resource $blob) + */ PHP_FUNCTION(git_blob_owner) { - zval *blob; - php_git2_t *git2, *result; - git_repository *repository; + git_repository *result = NULL; + zval *blob = NULL; + php_git2_t *_blob = NULL, *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &blob) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - PHP_GIT2_MAKE_RESOURCE(result); - repository = git_blob_owner(PHP_GIT2_V(git2, blob)); - - PHP_GIT2_V(result, repository) = repository; - result->type = PHP_GIT2_TYPE_REPOSITORY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_blob_owner(PHP_GIT2_V(_blob, blob)); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_BLOB, result, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); } +/* }}} */ + /* {{{ proto resource git_blob_rawcontent(resource $blob) */ @@ -248,6 +316,7 @@ PHP_FUNCTION(git_blob_rawcontent) size = git_blob_rawsize(PHP_GIT2_V(git2, blob)); RETURN_STRINGL(buffer, size, 1); } +/* }}} */ /* {{{ proto resource git_blob_rawsize(resource $blob, string $oid) */ @@ -265,4 +334,5 @@ PHP_FUNCTION(git_blob_rawsize) ZEND_FETCH_RESOURCE(git2, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); size = git_blob_rawsize(PHP_GIT2_V(git2, blob)); RETURN_LONG(size); -} \ No newline at end of file +} +/* }}} */ \ No newline at end of file From 5f0b5267a80a0e8062021624b721ba412d2d5391 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 08:15:15 +0900 Subject: [PATCH 081/136] fix compile error --- blob.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blob.c b/blob.c index 32d142f68d..21e057ba49 100644 --- a/blob.c +++ b/blob.c @@ -126,7 +126,7 @@ PHP_FUNCTION(git_blob_create_fromworkdir) PHP_FUNCTION(git_blob_filtered_content) { php_git2_t *result = NULL, *_blob = NULL; - git_buf out = NULL; + git_buf out = {0}; zval *blob = NULL; char *as_path = NULL; int as_path_len = 0, error = 0; @@ -142,7 +142,7 @@ PHP_FUNCTION(git_blob_filtered_content) if (php_git2_check_error(error, "git_blob_filtered_content" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, out, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, &out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); From 07f5b41817f0f57f6b76d794cb7a1ad80e43612c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Jan 2014 08:28:42 +0900 Subject: [PATCH 082/136] improve codes --- commit.c | 169 ++++++++++++++++++++++++++++--------------------------- diff.c | 103 +++++++++++++++++++++++++++++---- 2 files changed, 179 insertions(+), 93 deletions(-) diff --git a/commit.c b/commit.c index bd26cee7ab..7849baa2f6 100644 --- a/commit.c +++ b/commit.c @@ -2,41 +2,31 @@ #include "php_git2_priv.h" #include "commit.h" -/* {{{ proto resource git_commit_lookup(resource $repository, mixed $oid) -*/ +/* {{{ proto long git_commit_lookup(resource $repo, string $id) + */ PHP_FUNCTION(git_commit_lookup) { - zval *repository; - php_git2_t *git2, *result; - git_commit *commit; - char *hash; - int hash_len; - int error; - git_oid id; - + int result = 0, id_len = 0, error = 0; + git_commit *commit = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL, *_result = NULL; + char *id = NULL; + git_oid __id = {0}; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &repository, &hash, &hash_len) == FAILURE) { + "rs", &repo, &id, &id_len) == FAILURE) { return; } - - if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { - return; + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; } - - ZEND_FETCH_RESOURCE(git2, php_git2_t*, &repository, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - PHP_GIT2_MAKE_RESOURCE(result); - error = git_commit_lookup(&commit, PHP_GIT2_V(git2, repository), &id); - if (php_git2_check_error(error, "git_commit_lookup" TSRMLS_CC)) { - RETURN_FALSE + result = git_commit_lookup(&commit, PHP_GIT2_V(_repo, repository), &__id); + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_COMMIT, commit, 0 TSRMLS_CC)) { + RETURN_FALSE; } - - PHP_GIT2_V(result, commit) = commit; - result->type = PHP_GIT2_TYPE_COMMIT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ @@ -64,102 +54,103 @@ PHP_FUNCTION(git_commit_author) /* }}} */ /* {{{ proto resource git_commit_tree(resource $commit) -*/ + */ PHP_FUNCTION(git_commit_tree) { - zval *repository; - php_git2_t *git2, *result; - git_commit *commit; - git_tree *tree; - int error; + php_git2_t *result = NULL, *_commit = NULL; + git_tree *tree_out = NULL; + zval *commit = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &commit) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(git2, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - PHP_GIT2_MAKE_RESOURCE(result); - error = git_commit_tree(&tree, PHP_GIT2_V(git2, commit)); + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_commit_tree(&tree_out, PHP_GIT2_V(_commit, commit)); if (php_git2_check_error(error, "git_commit_tree" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - - PHP_GIT2_V(result, tree) = tree; - result->type = PHP_GIT2_TYPE_TREE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREE, tree_out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto resource git_commit_lookup_prefix(repo, id, len) -*/ +/* {{{ proto long git_commit_lookup_prefix(resource $repo, string $id, long $len) + */ PHP_FUNCTION(git_commit_lookup_prefix) { - zval *repo; - php_git2_t *_repo; - char *id = {0}; - int id_len; - long len; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_commit_lookup_prefix not implemented yet"); - return; + int result = 0, id_len = 0, error = 0; + git_commit *commit = NULL; + zval *repo = NULL; + php_git2_t *_repo = NULL, *_result = NULL; + char *id = NULL; + git_oid __id = {0}; + long len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &repo, &id, &id_len, &len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__id, id, id_len)) { + RETURN_FALSE; + } + result = git_commit_lookup_prefix(&commit, PHP_GIT2_V(_repo, repository), &__id, len); + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_COMMIT, commit, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } +/* }}} */ -/* {{{ proto resource git_commit_id(commit) -*/ +/* {{{ proto resource git_commit_id(resource $commit) + */ PHP_FUNCTION(git_commit_id) { - zval *commit; - php_git2_t *_commit; - char out[GIT2_OID_HEXSIZE] = {0}; - const git_oid *id; + const git_oid *result = NULL; + zval *commit = NULL; + php_git2_t *_commit = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &commit) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - id = git_blob_id(PHP_GIT2_V(_commit, commit)); - git_oid_fmt(out, id); - RETURN_STRING(out, 1); + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_commit_id(PHP_GIT2_V(_commit, commit)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); } +/* }}} */ -/* {{{ proto resource git_commit_owner(commit) -*/ +/* {{{ proto resource git_commit_owner(resource $commit) + */ PHP_FUNCTION(git_commit_owner) { - zval *commit; - php_git2_t *_commit, *result; - git_repository *repository; + git_repository *result = NULL; + zval *commit = NULL; + php_git2_t *_commit = NULL, *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &commit) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - - PHP_GIT2_MAKE_RESOURCE(result); - repository = git_commit_owner(PHP_GIT2_V(_commit, commit)); - - PHP_GIT2_V(result, repository) = repository; - result->type = PHP_GIT2_TYPE_REPOSITORY; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + ZEND_FETCH_RESOURCE(_commit, php_git2_t*, &commit, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_commit_owner(PHP_GIT2_V(_commit, commit)); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_COMMIT, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); } +/* }}} */ + /* {{{ proto resource git_commit_message_encoding(commit) */ @@ -177,6 +168,7 @@ PHP_FUNCTION(git_commit_message_encoding) encoding = git_commit_message_encoding(PHP_GIT2_V(_commit, commit)); RETURN_STRING(encoding, 1); } +/* }}} */ /* {{{ proto resource git_commit_message(commit) */ @@ -194,6 +186,7 @@ PHP_FUNCTION(git_commit_message) message = git_commit_message(PHP_GIT2_V(_commit, commit)); RETURN_STRING(message, 1); } +/* }}} */ /* {{{ proto resource git_commit_message_raw(commit) */ @@ -212,6 +205,7 @@ PHP_FUNCTION(git_commit_message_raw) message = git_commit_message_raw(PHP_GIT2_V(_commit, commit)); RETURN_STRING(message, 1); } +/* }}} */ /* {{{ proto resource git_commit_time(commit) */ @@ -231,6 +225,7 @@ PHP_FUNCTION(git_commit_time) /* NOTE(chobie) should this return as a string? */ RETURN_LONG(time); } +/* }}} */ /* {{{ proto long git_commit_time_offset(commit) */ @@ -248,6 +243,7 @@ PHP_FUNCTION(git_commit_time_offset) result = git_commit_time_offset(PHP_GIT2_V(_commit, commit)); RETURN_LONG(result); } +/* }}} */ /* {{{ proto resource git_commit_committer(commit) */ @@ -268,6 +264,7 @@ PHP_FUNCTION(git_commit_committer) php_git2_signature_to_array(committer, &result TSRMLS_CC); RETURN_ZVAL(result, 0, 1); } +/* }}} */ /* {{{ proto resource git_commit_raw_header(commit) */ @@ -286,6 +283,7 @@ PHP_FUNCTION(git_commit_raw_header) RETURN_STRING(header, 1); } +/* }}} */ /* {{{ proto resource git_commit_tree_id(commit) */ @@ -306,6 +304,7 @@ PHP_FUNCTION(git_commit_tree_id) git_oid_fmt(out, id); RETURN_STRING(out, 1); } +/* }}} */ /* {{{ proto resource git_commit_parentcount(commit) */ @@ -324,6 +323,7 @@ PHP_FUNCTION(git_commit_parentcount) count = git_commit_parentcount(PHP_GIT2_V(_commit, commit)); RETURN_LONG(count); } +/* }}} */ /* {{{ proto resource git_commit_parent(commit, n) */ @@ -353,6 +353,7 @@ PHP_FUNCTION(git_commit_parent) ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ /* {{{ proto resource git_commit_parent_id(commit, n) */ @@ -374,6 +375,7 @@ PHP_FUNCTION(git_commit_parent_id) RETURN_STRING(out, 1); } +/* }}} */ /* {{{ proto resource git_commit_nth_gen_ancestor(commit, n) */ @@ -405,6 +407,7 @@ PHP_FUNCTION(git_commit_nth_gen_ancestor) ZVAL_RESOURCE(return_value, result->resource_id); } +/* }}} */ /* {{{ proto resource git_commit_create( resource $repo, string $update_ref, array $author, array $committer, diff --git a/diff.c b/diff.c index e0f34f6a5a..cae870f978 100644 --- a/diff.c +++ b/diff.c @@ -23,7 +23,6 @@ PHP_FUNCTION(git_diff_free) } /* }}} */ - /* {{{ proto long git_diff_tree_to_tree(resource $repo, resource $old_tree, resource $new_tree, $opts) */ PHP_FUNCTION(git_diff_tree_to_tree) @@ -298,11 +297,31 @@ PHP_FUNCTION(git_diff_is_sorted_icase) /* }}} */ -/* {{{ proto long git_diff_foreach(diff, file_cb, hunk_cb, line_cb, payload) -*/ +/* {{{ proto long git_diff_foreach(resource $diff, Callable $file_cb, Callable $hunk_cb, Callable $line_cb, $payload) + */ PHP_FUNCTION(git_diff_foreach) { + int result = 0, error = 0; + zval *diff = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; + php_git2_t *_diff = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfffz", &diff, &fci, &fcc, &fci, &fcc, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_diff_foreach(PHP_GIT2_V(_diff, diff), , , , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ /* {{{ proto string git_diff_status_char( $status) */ @@ -321,21 +340,85 @@ PHP_FUNCTION(git_diff_status_char) } /* }}} */ -/* {{{ proto long git_diff_print(diff, format, print_cb, payload) -*/ +/* {{{ proto long git_diff_print(resource $diff, long $format, Callable $print_cb, $payload) + */ PHP_FUNCTION(git_diff_print) { + int result = 0, error = 0; + zval *diff = NULL, *print_cb = NULL, *payload = NULL; + php_git2_t *_diff = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + long format = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rlfz", &diff, &format, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_diff_print(PHP_GIT2_V(_diff, diff), format, , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_diff_blobs(old_blob, old_as_path, new_blob, new_as_path, options, file_cb, hunk_cb, line_cb, payload) -*/ +/* {{{ proto long git_diff_blobs(resource $old_blob, string $old_as_path, resource $new_blob, string $new_as_path, $options, Callable $file_cb, Callable $hunk_cb, Callable $line_cb, $payload) + */ PHP_FUNCTION(git_diff_blobs) { + int result = 0, old_as_path_len = 0, new_as_path_len = 0, error = 0; + zval *old_blob = NULL, *new_blob = NULL, *options = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; + php_git2_t *_old_blob = NULL, *_new_blob = NULL; + char *old_as_path = NULL, *new_as_path = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rsrsfffz", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &options, &fci, &fcc, &fci, &fcc, &fci, &fcc, &payload) == FAILURE) { +// return; +// } +// +// ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// ZEND_FETCH_RESOURCE(_new_blob, php_git2_t*, &new_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { +// RETURN_FALSE; +// } +// result = git_diff_blobs(PHP_GIT2_V(_old_blob, blob), old_as_path, PHP_GIT2_V(_new_blob, blob), new_as_path, options, , , , cb); +// php_git2_cb_free(cb); +// RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_diff_blob_to_buffer(old_blob, old_as_path, buffer, buffer_len, buffer_as_path, options, file_cb, hunk_cb, line_cb, payload) -*/ +/* {{{ proto long git_diff_blob_to_buffer(resource $old_blob, string $old_as_path, string $buffer, long $buffer_len, string $buffer_as_path, $options, Callable $file_cb, Callable $hunk_cb, Callable $line_cb, $payload) + */ PHP_FUNCTION(git_diff_blob_to_buffer) { + int result = 0, old_as_path_len = 0, buffer_len = 0, buffer_as_path_len = 0, error = 0; + zval *old_blob = NULL, *options = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; + php_git2_t *_old_blob = NULL; + char *old_as_path = NULL, *buffer = NULL, *buffer_as_path = NULL; +// long buffer_len = 0; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rsslsfffz", &old_blob, &old_as_path, &old_as_path_len, &buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &options, &fci, &fcc, &fci, &fcc, &fci, &fcc, &payload) == FAILURE) { +// return; +// } +// +// ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { +// RETURN_FALSE; +// } +// result = git_diff_blob_to_buffer(PHP_GIT2_V(_old_blob, blob), old_as_path, buffer, buffer_len, buffer_as_path, options, , , , cb); +// php_git2_cb_free(cb); +// RETURN_LONG(result); } - +/* }}} */ From 00cc5cfb2c74040d3775d32a885a5414894ee76f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 15 Jan 2014 01:01:40 +0900 Subject: [PATCH 083/136] [push] add stubs --- config.m4 | 2 +- ng.php | 1 + php_git2.c | 15 +++++ php_git2.h | 2 + push.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++ push.h | 111 ++++++++++++++++++++++++++++++ 6 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 push.c create mode 100644 push.h diff --git a/config.m4 b/config.m4 index 6c2b187a60..deab65c107 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c push.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/ng.php b/ng.php index 348e19bf57..b4981b80ee 100644 --- a/ng.php +++ b/ng.php @@ -392,6 +392,7 @@ public function shouldResource(Arg $arg) "git_blame", "git_packbuilder", "git_submodule", + "git_push", ); } diff --git a/php_git2.c b/php_git2.c index 0ddb25b6a0..420dcd2a93 100644 --- a/php_git2.c +++ b/php_git2.c @@ -63,6 +63,7 @@ #include "submodule.h" #include "attr.h" #include "giterr.h" +#include "push.h" int git2_resource_handle; @@ -263,6 +264,8 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v case PHP_GIT2_TYPE_SUBMODULE: PHP_GIT2_V(result, submodule) = (git_submodule*)resource; break; + case PHP_GIT2_TYPE_PUSH: + PHP_GIT2_V(result, push) = (git_push*)resource; default: php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } @@ -896,6 +899,18 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(giterr_set_str, arginfo_giterr_set_str) PHP_FE(giterr_set_oom, arginfo_giterr_set_oom) + /* push */ + PHP_FE(git_push_new, arginfo_git_push_new) + PHP_FE(git_push_set_options, arginfo_git_push_set_options) + PHP_FE(git_push_set_callbacks, arginfo_git_push_set_callbacks) + PHP_FE(git_push_add_refspec, arginfo_git_push_add_refspec) + PHP_FE(git_push_update_tips, arginfo_git_push_update_tips) + PHP_FE(git_push_finish, arginfo_git_push_finish) + PHP_FE(git_push_unpack_ok, arginfo_git_push_unpack_ok) + PHP_FE(git_push_status_foreach, arginfo_git_push_status_foreach) + PHP_FE(git_push_free, arginfo_git_push_free) + + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE_END diff --git a/php_git2.h b/php_git2.h index 757e80b52c..c6bbe65fd9 100644 --- a/php_git2.h +++ b/php_git2.h @@ -123,6 +123,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_BLAME, PHP_GIT2_TYPE_PACKBUILDER, PHP_GIT2_TYPE_SUBMODULE, + PHP_GIT2_TYPE_PUSH, }; typedef struct php_git2_t { @@ -173,6 +174,7 @@ typedef struct php_git2_t { git_blame *blame; git_packbuilder *packbuilder; git_submodule *submodule; + git_push *push; } v; int should_free_v; int resource_id; diff --git a/push.c b/push.c new file mode 100644 index 0000000000..6fe676e589 --- /dev/null +++ b/push.c @@ -0,0 +1,193 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "push.h" + +/* {{{ proto resource git_push_new(resource $remote) + */ +PHP_FUNCTION(git_push_new) +{ + php_git2_t *result = NULL, *_remote = NULL; + git_push *out = NULL; + zval *remote = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_push_new(&out, PHP_GIT2_V(_remote, remote)); + if (php_git2_check_error(error, "git_push_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PUSH, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto long git_push_set_options(resource $push, $opts) + */ +PHP_FUNCTION(git_push_set_options) +{ + int result = 0, error = 0; + zval *push = NULL, *opts = NULL; + php_git2_t *_push = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &push, &opts) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + //result = git_push_set_options(PHP_GIT2_V(_push, push), opts); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_push_set_callbacks(resource $push, $pack_progress_cb, $pack_progress_cb_payload, $transfer_progress_cb, $transfer_progress_cb_payload) + */ +PHP_FUNCTION(git_push_set_callbacks) +{ + int result = 0, error = 0; + zval *push = NULL, *pack_progress_cb = NULL, *pack_progress_cb_payload = NULL, *transfer_progress_cb = NULL, *transfer_progress_cb_payload = NULL; + php_git2_t *_push = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfzz", &push, &fci, &fcc, &pack_progress_cb_payload, &transfer_progress_cb, &transfer_progress_cb_payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { +// RETURN_FALSE; +// } + //result = git_push_set_callbacks(PHP_GIT2_V(_push, push), , cb, transfer_progress_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_push_add_refspec(resource $push, string $refspec) + */ +PHP_FUNCTION(git_push_add_refspec) +{ + int result = 0, refspec_len = 0, error = 0; + zval *push = NULL; + php_git2_t *_push = NULL; + char *refspec = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &push, &refspec, &refspec_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_push_add_refspec(PHP_GIT2_V(_push, push), refspec); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_push_update_tips(resource $push) + */ +PHP_FUNCTION(git_push_update_tips) +{ + int result = 0, error = 0; + zval *push = NULL; + php_git2_t *_push = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &push) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_push_update_tips(PHP_GIT2_V(_push, push)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_push_finish(resource $push) + */ +PHP_FUNCTION(git_push_finish) +{ + int result = 0, error = 0; + zval *push = NULL; + php_git2_t *_push = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &push) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_push_finish(PHP_GIT2_V(_push, push)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_push_unpack_ok(resource $push) + */ +PHP_FUNCTION(git_push_unpack_ok) +{ + int result = 0, error = 0; + zval *push = NULL; + php_git2_t *_push = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &push) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_push_unpack_ok(PHP_GIT2_V(_push, push)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_push_status_foreach(resource $push, string $ref, string $msg, $data), $data) + */ +PHP_FUNCTION(git_push_status_foreach) +{ + int result = 0, ref_len = 0, msg_len = 0, error = 0; + zval *push = NULL; + php_git2_t *_push = NULL; + char *ref = NULL, *msg = NULL; + +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "rss", &push, &ref, &ref_len, &msg, &msg_len, &data, &data) == FAILURE) { +// return; +// } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + //result = git_push_status_foreach(PHP_GIT2_V(_push, push), ref, msg, data); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto void git_push_free(resource $push) + */ +PHP_FUNCTION(git_push_free) +{ + zval *push = NULL; + php_git2_t *_push = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &push) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_push)) { + git_push_free(PHP_GIT2_V(_push, push)); + GIT2_SHOULD_FREE(_push) = 0; + }; + zval_ptr_dtor(&push); +} +/* }}} */ + diff --git a/push.h b/push.h new file mode 100644 index 0000000000..ccb18ba335 --- /dev/null +++ b/push.h @@ -0,0 +1,111 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_PUSH_H +#define PHP_GIT2_PUSH_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_new, 0, 0, 1) + ZEND_ARG_INFO(0, remote) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_set_options, 0, 0, 2) + ZEND_ARG_INFO(0, push) + ZEND_ARG_INFO(0, opts) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_set_callbacks, 0, 0, 5) + ZEND_ARG_INFO(0, push) + ZEND_ARG_INFO(0, pack_progress_cb) + ZEND_ARG_INFO(0, pack_progress_cb_payload) + ZEND_ARG_INFO(0, transfer_progress_cb) + ZEND_ARG_INFO(0, transfer_progress_cb_payload) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_add_refspec, 0, 0, 2) + ZEND_ARG_INFO(0, push) + ZEND_ARG_INFO(0, refspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_update_tips, 0, 0, 1) + ZEND_ARG_INFO(0, push) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_finish, 0, 0, 1) + ZEND_ARG_INFO(0, push) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_unpack_ok, 0, 0, 1) + ZEND_ARG_INFO(0, push) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_status_foreach, 0, 0, 5) + ZEND_ARG_INFO(0, push) + ZEND_ARG_INFO(0, ref) + ZEND_ARG_INFO(0, msg) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_free, 0, 0, 1) + ZEND_ARG_INFO(0, push) +ZEND_END_ARG_INFO() + +/* {{{ proto resource git_push_new(remote) +*/ +PHP_FUNCTION(git_push_new); + +/* {{{ proto long git_push_set_options(push, opts) +*/ +PHP_FUNCTION(git_push_set_options); + +/* {{{ proto long git_push_set_callbacks(push, pack_progress_cb, pack_progress_cb_payload, transfer_progress_cb, transfer_progress_cb_payload) +*/ +PHP_FUNCTION(git_push_set_callbacks); + +/* {{{ proto long git_push_add_refspec(push, refspec) +*/ +PHP_FUNCTION(git_push_add_refspec); + +/* {{{ proto long git_push_update_tips(push) +*/ +PHP_FUNCTION(git_push_update_tips); + +/* {{{ proto long git_push_finish(push) +*/ +PHP_FUNCTION(git_push_finish); + +/* {{{ proto long git_push_unpack_ok(push) +*/ +PHP_FUNCTION(git_push_unpack_ok); + +/* {{{ proto long git_push_status_foreach(push, ref, msg, data), data) +*/ +PHP_FUNCTION(git_push_status_foreach); + +/* {{{ proto void git_push_free(push) +*/ +PHP_FUNCTION(git_push_free); + +#endif From 8d9977d91572206045d475883eae40e0cbd040a9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 15 Jan 2014 03:01:41 +0900 Subject: [PATCH 084/136] [remote] wip --- ng.php | 3 +++ php_git2.c | 1 + push.c | 62 ++++++++++++++++++++++++++++++++++++------------------ remote.c | 28 +++++++++++++++++++----- 4 files changed, 69 insertions(+), 25 deletions(-) diff --git a/ng.php b/ng.php index b4981b80ee..56eb8c01ce 100644 --- a/ng.php +++ b/ng.php @@ -165,6 +165,9 @@ public function isCallback() if (preg_match("/packbuilder_progress/", $this->getType())) { return true; } + if (preg_match("/git_push_transfer_progress/", $this->getType())) { + return true; + } return false; } diff --git a/php_git2.c b/php_git2.c index 420dcd2a93..67c3f5d4a0 100644 --- a/php_git2.c +++ b/php_git2.c @@ -266,6 +266,7 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v break; case PHP_GIT2_TYPE_PUSH: PHP_GIT2_V(result, push) = (git_push*)resource; + break; default: php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } diff --git a/push.c b/push.c index 6fe676e589..6603a0504e 100644 --- a/push.c +++ b/push.c @@ -2,6 +2,13 @@ #include "php_git2_priv.h" #include "push.h" +static int php_git2_push_status_foreach_cb(const char *ref, const char *msg, void *data) +{ + fprintf(stderr, "ref: %s\n", ref); + fprintf(stderr, "msg: %s\n", msg); + return 0; +} + /* {{{ proto resource git_push_new(resource $remote) */ PHP_FUNCTION(git_push_new) @@ -54,25 +61,34 @@ PHP_FUNCTION(git_push_set_callbacks) int result = 0, error = 0; zval *push = NULL, *pack_progress_cb = NULL, *pack_progress_cb_payload = NULL, *transfer_progress_cb = NULL, *transfer_progress_cb_payload = NULL; php_git2_t *_push = NULL; - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache fcc = empty_fcall_info_cache; - php_git2_cb_t *cb = NULL; + zend_fcall_info pack_fci = empty_fcall_info; + zend_fcall_info_cache pack_fcc = empty_fcall_info_cache; + zend_fcall_info transfer_fci = empty_fcall_info; + zend_fcall_info_cache transfer_fcc = empty_fcall_info_cache; + php_git2_cb_t *pack_cb = NULL; + php_git2_cb_t *transfer_cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rfzz", &push, &fci, &fcc, &pack_progress_cb_payload, &transfer_progress_cb, &transfer_progress_cb_payload) == FAILURE) { + "rfzfz", &push, &pack_fci, &pack_fcc, &pack_progress_cb_payload, &transfer_fci, &transfer_fcc, &transfer_progress_cb_payload) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -// if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { -// RETURN_FALSE; -// } - //result = git_push_set_callbacks(PHP_GIT2_V(_push, push), , cb, transfer_progress_cb, cb); - php_git2_cb_free(cb); + if (php_git2_cb_init(&pack_cb, &pack_fci, &pack_fcc, pack_progress_cb_payload TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_cb_init(&transfer_cb, &transfer_fci, &transfer_fcc, transfer_progress_cb_payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_push_set_callbacks(PHP_GIT2_V(_push, push), NULL, pack_cb, NULL, transfer_cb); + php_git2_cb_free(pack_cb); + php_git2_cb_free(transfer_cb); RETURN_LONG(result); } /* }}} */ + + /* {{{ proto long git_push_add_refspec(resource $push, string $refspec) */ PHP_FUNCTION(git_push_add_refspec) @@ -150,22 +166,28 @@ PHP_FUNCTION(git_push_unpack_ok) } /* }}} */ -/* {{{ proto long git_push_status_foreach(resource $push, string $ref, string $msg, $data), $data) +/* {{{ proto long git_push_status_foreach(resource $push, Callable callback, mixed $payload) */ PHP_FUNCTION(git_push_status_foreach) { - int result = 0, ref_len = 0, msg_len = 0, error = 0; - zval *push = NULL; + int result = 0; + zval *push = NULL, *payload = NULL; php_git2_t *_push = NULL; - char *ref = NULL, *msg = NULL; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rss", &push, &ref, &ref_len, &msg, &msg_len, &data, &data) == FAILURE) { -// return; -// } + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfz", &push, &fci, &fcc, &payload) == FAILURE) { + return; + } ZEND_FETCH_RESOURCE(_push, php_git2_t*, &push, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - //result = git_push_status_foreach(PHP_GIT2_V(_push, push), ref, msg, data); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_push_status_foreach(PHP_GIT2_V(_push, push), php_git2_push_status_foreach_cb, cb); + php_git2_cb_free(cb); RETURN_LONG(result); } /* }}} */ diff --git a/remote.c b/remote.c index fec0680d60..fefe4e1ad3 100644 --- a/remote.c +++ b/remote.c @@ -753,6 +753,23 @@ PHP_FUNCTION(git_remote_set_transport) } /* }}} */ +static int cred_cb(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *data) +{ + fprintf(stderr, "url: %s\n", url); + fprintf(stderr, "name: %s\n", username_from_url); + fprintf(stderr, "types: %d\n", allowed_types); + + return 0; +} + +typedef struct php_git2_fcall_t { + zend_fcall_info fci; + zend_fcall_info_cache fcc; +} php_git2_fcall_t; +typedef struct php_git2_remote_cb_t { + php_git2_fcall_t callbacks[4]; + zval *payload; +} php_git2_remote_cb_t; /* {{{ proto long git_remote_set_callbacks(remote, callbacks) */ @@ -762,16 +779,17 @@ PHP_FUNCTION(git_remote_set_callbacks) php_git2_t *_remote; zval *callbacks; php_git2_t *_callbacks; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_set_callbacks not implemented yet"); - return; + struct git_remote_callbacks cb = GIT_REMOTE_CALLBACKS_INIT; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &remote, &callbacks) == FAILURE) { + "ra", &remote, &callbacks) == FAILURE) { return; } + + cb.credentials = cred_cb; + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + git_remote_set_callbacks(PHP_GIT2_V(_remote, remote), &cb); } /* {{{ proto resource git_remote_stats(resource $remote) From 6953b00da4b45fe195b4d34b503f72e30dd0aabc Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 15 Jan 2014 11:31:37 +0900 Subject: [PATCH 085/136] [remote] WIP: push --- example/push.php | 30 +++++++++++++++++++ example/reflog.php | 9 ++++++ php_git2.c | 7 +++++ push.c | 31 ++++++++++++++++++-- push.h | 8 ++---- remote.c | 72 ++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 example/push.php create mode 100644 example/reflog.php diff --git a/example/push.php b/example/push.php new file mode 100644 index 0000000000..8cadf9b182 --- /dev/null +++ b/example/push.php @@ -0,0 +1,30 @@ + function($url, $username_from_url, $allowed_types, &$payload) { + // NOTE(chobie): you need to build with LibSSH2 when communicating with ssh protocol. */ + if ($allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT) { + return git_cred_userpass_plaintext_new("chobie", getenv("GITHUB_TOKEN")); + } else { + error_log("not supported allowed types"); + } +}]; + +git_remote_set_callbacks($remote, $remote_callbacks); +if (git_remote_connect($remote, GIT_DIRECTION_PUSH)) { + $push = git_push_new($remote); + + git_push_add_refspec($push, "refs/heads/master:refs/heads/master"); + git_push_finish($push); + git_push_unpack_ok($push); + + git_push_status_foreach($push, function($ref, $name, &$payload){ + var_dump($ref, $name, $payload); + }, $payload); + + git_push_update_tips($push); + git_remote_disconnect($remote); +} diff --git a/example/reflog.php b/example/reflog.php new file mode 100644 index 0000000000..43e9c80f69 --- /dev/null +++ b/example/reflog.php @@ -0,0 +1,9 @@ +tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_ref); + MAKE_STD_ZVAL(param_msg); + ZVAL_NULL(param_ref); + ZVAL_NULL(param_msg); + + if (ref != NULL) { + ZVAL_STRING(param_ref, ref, 1); + } + if (msg != NULL) { + ZVAL_STRING(param_msg, msg, 1); + } + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, ¶m_ref, ¶m_msg, &p->payload)) { + zend_list_delete(result->resource_id); + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; } /* {{{ proto resource git_push_new(resource $remote) diff --git a/push.h b/push.h index ccb18ba335..fc4a131ace 100644 --- a/push.h +++ b/push.h @@ -60,12 +60,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_unpack_ok, 0, 0, 1) ZEND_ARG_INFO(0, push) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_status_foreach, 0, 0, 5) +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_status_foreach, 0, 0, 3) ZEND_ARG_INFO(0, push) - ZEND_ARG_INFO(0, ref) - ZEND_ARG_INFO(0, msg) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(1, data) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_push_free, 0, 0, 1) diff --git a/remote.c b/remote.c index fefe4e1ad3..9c40e147f5 100644 --- a/remote.c +++ b/remote.c @@ -753,40 +753,94 @@ PHP_FUNCTION(git_remote_set_transport) } /* }}} */ -static int cred_cb(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *data) -{ - fprintf(stderr, "url: %s\n", url); - fprintf(stderr, "name: %s\n", username_from_url); - fprintf(stderr, "types: %d\n", allowed_types); - - return 0; -} typedef struct php_git2_fcall_t { zend_fcall_info fci; zend_fcall_info_cache fcc; + zval *value; } php_git2_fcall_t; + typedef struct php_git2_remote_cb_t { php_git2_fcall_t callbacks[4]; zval *payload; + GIT2_TSRMLS_DECL } php_git2_remote_cb_t; +static int cred_cb(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *data) +{ + php_git2_t *result; + zval *param_url = NULL, *param_username_from_url = NULL, *param_allowed_types = NULL, *retval_ptr; + php_git2_remote_cb_t *cb = (php_git2_remote_cb_t*)data; + GIT2_TSRMLS_SET(cb->tsrm_ls); + int retval = 1; + + if (cb != NULL) { + MAKE_STD_ZVAL(param_url); + MAKE_STD_ZVAL(param_username_from_url); + MAKE_STD_ZVAL(param_allowed_types); + ZVAL_NULL(param_url); + ZVAL_NULL(param_username_from_url); + + if (url != NULL) { + ZVAL_STRING(param_url, url, 1); + } + if (username_from_url != NULL) { + ZVAL_STRING(param_username_from_url, username_from_url, 1); + } + ZVAL_LONG(param_allowed_types, allowed_types); + Z_ADDREF_P(cb->payload); + SEPARATE_ZVAL_TO_MAKE_IS_REF(&cb->payload); + + if (php_git2_call_function_v(&cb->callbacks[0].fci, &cb->callbacks[0].fcc TSRMLS_CC, &retval_ptr, 4, + ¶m_url, ¶m_username_from_url, ¶m_allowed_types, &cb->payload)) { + fprintf(stderr, "CALL FUNCTION ERROR"); + } + } + + if (retval_ptr && Z_TYPE_P(retval_ptr) == IS_RESOURCE) { + ZEND_FETCH_RESOURCE_NO_RETURN(result, php_git2_t*, &retval_ptr, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + *cred = PHP_GIT2_V(result, cred); + zval_ptr_dtor(&retval_ptr); + } + return retval; +} + /* {{{ proto long git_remote_set_callbacks(remote, callbacks) */ PHP_FUNCTION(git_remote_set_callbacks) { zval *remote; php_git2_t *_remote; - zval *callbacks; + zval *callbacks, *credentials_cb = NULL; php_git2_t *_callbacks; struct git_remote_callbacks cb = GIT_REMOTE_CALLBACKS_INIT; + php_git2_remote_cb_t *_payload = NULL, payload = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &remote, &callbacks) == FAILURE) { return; } + /* TODO(chobie): support other callbacks */ cb.credentials = cred_cb; + credentials_cb = php_git2_read_arrval(callbacks, ZEND_STRS("credentials") TSRMLS_CC); + + /* TODO(chobie): can we free payload? */ + _payload = emalloc(sizeof(php_git2_remote_cb_t)); + MAKE_STD_ZVAL(_payload->payload); + GIT2_TSRMLS_SET2(_payload, TSRMLS_C); + + if (credentials_cb != NULL) { + char *is_callable_error; + + if(zend_fcall_info_init(credentials_cb, 0, &(_payload->callbacks[0].fci), &(_payload->callbacks[0].fci), NULL, &is_callable_error TSRMLS_CC) == SUCCESS) { + if (is_callable_error) { + efree(is_callable_error); + } + } + Z_ADDREF_P(credentials_cb); + } + cb.payload = _payload; ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); git_remote_set_callbacks(PHP_GIT2_V(_remote, remote), &cb); From f34f0ab308987b2c6ef0a2d38724dd794bccb740 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 15 Jan 2014 22:07:24 +0900 Subject: [PATCH 086/136] add refspec stubs --- config.m4 | 2 +- ng.php | 148 ++++++++++++++++++++++++++++++++++++++++-- php_git2.c | 11 ++++ php_git2.h | 2 + refspec.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++ refspec.h | 109 +++++++++++++++++++++++++++++++ 6 files changed, 453 insertions(+), 6 deletions(-) create mode 100644 refspec.c create mode 100644 refspec.h diff --git a/config.m4 b/config.m4 index deab65c107..f6e3ef5b72 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c push.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c push.c refspec.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/ng.php b/ng.php index 56eb8c01ce..a59fc1c537 100644 --- a/ng.php +++ b/ng.php @@ -343,6 +343,15 @@ public function put($message/* $args */) } class Fashion { + protected $name; + protected $flag; + + public function __construct($name, $flag = false) + { + $this->name = basename($name, ".h"); + $this->flag = $flag; + } + public function shouldResource(Arg $arg) { static $types; @@ -396,6 +405,7 @@ public function shouldResource(Arg $arg) "git_packbuilder", "git_submodule", "git_push", + "git_refspec", ); } @@ -1058,12 +1068,22 @@ public function generateStrarrayConversion(Printer $printer, Func $f) } } + public function generateIncludes(Printer $printer, Func $f) + { + if ($this->flag) { + $printer->put("#include \"php_git2.h\"\n"); + $printer->put("#include \"php_git2_priv.h\"\n"); + $printer->put("#include \"`name`.h\"\n", "name", $this->name); + } + } + public function out(Func $f) { $stream = new StringStream(); $out = new ZeroCopyOutputStream($stream); $printer = new Printer($out, "`"); + $this->generateIncludes($printer, $f); $this->generateProto($printer, $f); $printer->put("PHP_FUNCTION(`function`)\n", "function", $f->getName()); @@ -1089,6 +1109,108 @@ public function out(Func $f) } } +class Header extends Fashion +{ + public function generateLicense(Printer $printer, Func $f) + { + if (!$this->flag) { + return; + } + $printer->put("/*\n"); + $printer->put(" * PHP Libgit2 Extension\n"); + $printer->put(" *\n"); + $printer->put(" * https://github.com/libgit2/php-git\n"); + $printer->put(" *\n"); + $printer->put(" * Copyright 2014 Shuhei Tanuma. All rights reserved.\n"); + $printer->put(" *\n"); + $printer->put(" * Permission is hereby granted, free of charge, to any person obtaining a copy\n"); + $printer->put(" * of this software and associated documentation files (the \"Software\"), to deal\n"); + $printer->put(" * in the Software without restriction, including without limitation the rights\n"); + $printer->put(" * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"); + $printer->put(" * copies of the Software, and to permit persons to whom the Software is\n"); + $printer->put(" * furnished to do so, subject to the following conditions:\n"); + $printer->put(" *\n"); + $printer->put(" * The above copyright notice and this permission notice shall be included in\n"); + $printer->put(" * all copies or substantial portions of the Software.\n"); + $printer->put(" *\n"); + $printer->put(" * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"); + $printer->put(" * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"); + $printer->put(" * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"); + $printer->put(" * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"); + $printer->put(" * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"); + $printer->put(" * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n"); + $printer->put(" * THE SOFTWARE.\n"); + $printer->put(" */\n"); + $printer->put("#ifndef PHP_GIT2_`file`_H\n", "file", strtoupper($this->name)); + $printer->put("#define PHP_GIT2_`file`_H\n", "file", strtoupper($this->name)); + $printer->put("\n"); + } + + public function generateArgInfo(Printer $printer, Func $f) + { + $printer->put("ZEND_BEGIN_ARG_INFO_EX(arginfo_`name`, `a`, `b`, `c`)\n", + "name", $f->getName(), + "a", 0, + "b", 0, + "c", count($f->getArguments()) + ); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + $printer->put("\tZEND_ARG_INFO(`is_ref`, `name`)\n", + "is_ref", 0, + "name", $arg->getName()); + } + $printer->put("ZEND_END_ARG_INFO()\n"); + $printer->put("\n"); + } + + public function out(Func $f) + { + $stream = new StringStream(); + $out = new ZeroCopyOutputStream($stream); + $printer = new Printer($out, "`"); + + $this->generateLicense($printer, $f); + $this->generateArgInfo($printer, $f); + + return $stream->__toString(); + } +} + +class Header2 extends Header +{ + public function generateArgInfo(Printer $printer, Func $f) + { + $printer->put("ZEND_BEGIN_ARG_INFO_EX(arginfo_`name`, `a`, `b`, `c`)\n", + "name", $f->getName(), + "a", 0, + "b", 0, + "c", count($f->getArguments()) + ); + foreach ($f->getArguments() as $arg) { + /** @var Arg $arg */ + $printer->put("\tZEND_ARG_INFO(`is_ref`, `name`)\n", + "is_ref", 0, + "name", $arg->getName()); + } + $printer->put("ZEND_END_ARG_INFO()\n"); + $printer->put("\n"); + } + + public function out(Func $f) + { + $stream = new StringStream(); + $out = new ZeroCopyOutputStream($stream); + $printer = new Printer($out, "`"); + + $this->generateProto($printer, $f); + $printer->put("PHP_FUNCTION(`func`);\n", "func", $f->getName()); + $printer->put("\n"); + + return $stream->__toString(); + } +} + $data = file_get_contents($_SERVER['argv'][1]); $table = array(); if (preg_match_all("/GIT_EXTERN\((.+?)\)\s*([a-zA-Z0-9_-]+)\((.+?)\);/s", $data, $match)) { @@ -1108,14 +1230,30 @@ public function out(Func $f) $table[$func->getName()] = $func; } } +if (getenv("PRINT_HEADER")) { + $flag = true; + foreach ($table as $name => $func) { + $printer = new Header($_SERVER['argv'][1], $flag); + echo $printer->out($func); + $flag = false; + } -if (isset($_SERVER['argv'][2])) { - $printer = new Fashion(); - echo $printer->out($table[$_SERVER['argv'][2]]); -} else { foreach ($table as $name => $func) { - $printer = new Fashion(); + $printer = new Header2($_SERVER['argv'][1], $flag); echo $printer->out($func); } + echo "#endif\n"; +} else { + if (isset($_SERVER['argv'][2])) { + $printer = new Fashion($_SERVER['argv'][1]); + echo $printer->out($table[$_SERVER['argv'][2]]); + } else { + $flag = true; + foreach ($table as $name => $func) { + $printer = new Fashion($_SERVER['argv'][1], $flag); + echo $printer->out($func); + $flag = false; + } + } } diff --git a/php_git2.c b/php_git2.c index aef6777b35..24427fa1b2 100644 --- a/php_git2.c +++ b/php_git2.c @@ -64,6 +64,7 @@ #include "attr.h" #include "giterr.h" #include "push.h" +#include "refspec.h" int git2_resource_handle; @@ -917,6 +918,16 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_push_status_foreach, arginfo_git_push_status_foreach) PHP_FE(git_push_free, arginfo_git_push_free) + /* refspec */ + PHP_FE(git_refspec_src, arginfo_git_refspec_src) + PHP_FE(git_refspec_dst, arginfo_git_refspec_dst) + PHP_FE(git_refspec_string, arginfo_git_refspec_string) + PHP_FE(git_refspec_force, arginfo_git_refspec_force) + PHP_FE(git_refspec_direction, arginfo_git_refspec_direction) + PHP_FE(git_refspec_src_matches, arginfo_git_refspec_src_matches) + PHP_FE(git_refspec_dst_matches, arginfo_git_refspec_dst_matches) + PHP_FE(git_refspec_transform, arginfo_git_refspec_transform) + PHP_FE(git_refspec_rtransform, arginfo_git_refspec_rtransform) /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) diff --git a/php_git2.h b/php_git2.h index c6bbe65fd9..6442aa763c 100644 --- a/php_git2.h +++ b/php_git2.h @@ -124,6 +124,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_PACKBUILDER, PHP_GIT2_TYPE_SUBMODULE, PHP_GIT2_TYPE_PUSH, + PHP_GIT2_TYPE_REFSPEC, }; typedef struct php_git2_t { @@ -175,6 +176,7 @@ typedef struct php_git2_t { git_packbuilder *packbuilder; git_submodule *submodule; git_push *push; + git_refspec *refspec; } v; int should_free_v; int resource_id; diff --git a/refspec.c b/refspec.c new file mode 100644 index 0000000000..ddb7d76603 --- /dev/null +++ b/refspec.c @@ -0,0 +1,187 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "refspec.h" + +/* {{{ proto string git_refspec_src(resource $refspec) + */ +PHP_FUNCTION(git_refspec_src) +{ + const char *result = NULL; + zval *refspec = NULL; + php_git2_t *_refspec = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &refspec) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_refspec, php_git2_t*, &refspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_refspec_src(PHP_GIT2_V(_refspec, refspec)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto string git_refspec_dst(resource $refspec) + */ +PHP_FUNCTION(git_refspec_dst) +{ + const char *result = NULL; + zval *refspec = NULL; + php_git2_t *_refspec = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &refspec) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_refspec, php_git2_t*, &refspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_refspec_dst(PHP_GIT2_V(_refspec, refspec)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto string git_refspec_string(resource $refspec) + */ +PHP_FUNCTION(git_refspec_string) +{ + const char *result = NULL; + zval *refspec = NULL; + php_git2_t *_refspec = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &refspec) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_refspec, php_git2_t*, &refspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_refspec_string(PHP_GIT2_V(_refspec, refspec)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto long git_refspec_force(resource $refspec) + */ +PHP_FUNCTION(git_refspec_force) +{ + int result = 0, error = 0; + zval *refspec = NULL; + php_git2_t *_refspec = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &refspec) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_refspec, php_git2_t*, &refspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_refspec_force(PHP_GIT2_V(_refspec, refspec)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_refspec_direction(resource $spec) + */ +PHP_FUNCTION(git_refspec_direction) +{ + git_direction *result = NULL; + zval *spec = NULL; + php_git2_t *_spec = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &spec) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_spec, php_git2_t*, &spec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_refspec_direction(PHP_GIT2_V(_spec, refspec)); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto long git_refspec_src_matches(resource $refspec, string $refname) + */ +PHP_FUNCTION(git_refspec_src_matches) +{ + int result = 0, refname_len = 0, error = 0; + zval *refspec = NULL; + php_git2_t *_refspec = NULL; + char *refname = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &refspec, &refname, &refname_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_refspec, php_git2_t*, &refspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_refspec_src_matches(PHP_GIT2_V(_refspec, refspec), refname); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_refspec_dst_matches(resource $refspec, string $refname) + */ +PHP_FUNCTION(git_refspec_dst_matches) +{ + int result = 0, refname_len = 0, error = 0; + zval *refspec = NULL; + php_git2_t *_refspec = NULL; + char *refname = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rs", &refspec, &refname, &refname_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_refspec, php_git2_t*, &refspec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_refspec_dst_matches(PHP_GIT2_V(_refspec, refspec), refname); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_refspec_transform(long $outlen, resource $spec, string $name) + */ +PHP_FUNCTION(git_refspec_transform) +{ + php_git2_t *result = NULL, *_spec = NULL; + char out = NULL, *name = NULL; + long outlen = 0; + zval *spec = NULL; + int name_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lrs", &outlen, &spec, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_spec, php_git2_t*, &spec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_refspec_transform(&out, outlen, PHP_GIT2_V(_spec, refspec), name); + if (php_git2_check_error(error, "git_refspec_transform" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(out, 1); +} +/* }}} */ + +/* {{{ proto resource git_refspec_rtransform(long $outlen, resource $spec, string $name) + */ +PHP_FUNCTION(git_refspec_rtransform) +{ + php_git2_t *result = NULL, *_spec = NULL; + char out = NULL, *name = NULL; + long outlen = 0; + zval *spec = NULL; + int name_len = 0, error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "lrs", &outlen, &spec, &name, &name_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_spec, php_git2_t*, &spec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_refspec_rtransform(&out, outlen, PHP_GIT2_V(_spec, refspec), name); + if (php_git2_check_error(error, "git_refspec_rtransform" TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_STRING(out, 1); +} +/* }}} */ + diff --git a/refspec.h b/refspec.h new file mode 100644 index 0000000000..4ca4118c50 --- /dev/null +++ b/refspec.h @@ -0,0 +1,109 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_REFSPEC_H +#define PHP_GIT2_REFSPEC_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_src, 0, 0, 1) + ZEND_ARG_INFO(0, refspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_dst, 0, 0, 1) + ZEND_ARG_INFO(0, refspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_string, 0, 0, 1) + ZEND_ARG_INFO(0, refspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_force, 0, 0, 1) + ZEND_ARG_INFO(0, refspec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_direction, 0, 0, 1) + ZEND_ARG_INFO(0, spec) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_src_matches, 0, 0, 2) + ZEND_ARG_INFO(0, refspec) + ZEND_ARG_INFO(0, refname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_dst_matches, 0, 0, 2) + ZEND_ARG_INFO(0, refspec) + ZEND_ARG_INFO(0, refname) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_transform, 0, 0, 4) + ZEND_ARG_INFO(0, out) + ZEND_ARG_INFO(0, outlen) + ZEND_ARG_INFO(0, spec) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_refspec_rtransform, 0, 0, 4) + ZEND_ARG_INFO(0, out) + ZEND_ARG_INFO(0, outlen) + ZEND_ARG_INFO(0, spec) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +/* {{{ proto string git_refspec_src(resource $refspec) + */ +PHP_FUNCTION(git_refspec_src); + +/* {{{ proto string git_refspec_dst(resource $refspec) + */ +PHP_FUNCTION(git_refspec_dst); + +/* {{{ proto string git_refspec_string(resource $refspec) + */ +PHP_FUNCTION(git_refspec_string); + +/* {{{ proto long git_refspec_force(resource $refspec) + */ +PHP_FUNCTION(git_refspec_force); + +/* {{{ proto resource git_refspec_direction(resource $spec) + */ +PHP_FUNCTION(git_refspec_direction); + +/* {{{ proto long git_refspec_src_matches(resource $refspec, string $refname) + */ +PHP_FUNCTION(git_refspec_src_matches); + +/* {{{ proto long git_refspec_dst_matches(resource $refspec, string $refname) + */ +PHP_FUNCTION(git_refspec_dst_matches); + +/* {{{ proto resource git_refspec_transform(long $outlen, resource $spec, string $name) + */ +PHP_FUNCTION(git_refspec_transform); + +/* {{{ proto resource git_refspec_rtransform(long $outlen, resource $spec, string $name) + */ +PHP_FUNCTION(git_refspec_rtransform); + +#endif From ea15c7b1435b82b303332860d39ef22e3ba70254 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 15 Jan 2014 22:19:15 +0900 Subject: [PATCH 087/136] add graph --- config.m4 | 2 +- graph.c | 37 +++++++++++++++++++++++++++++++++++++ graph.h | 39 +++++++++++++++++++++++++++++++++++++++ php_git2.c | 4 ++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 graph.c create mode 100644 graph.h diff --git a/config.m4 b/config.m4 index f6e3ef5b72..b14e42235c 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support, if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) - PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c push.c refspec.c, $ext_shared) + PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c attr.c reset.c message.c submodule.c giterr.c push.c refspec.c graph.c, $ext_shared) PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now diff --git a/graph.c b/graph.c new file mode 100644 index 0000000000..f8d352e649 --- /dev/null +++ b/graph.c @@ -0,0 +1,37 @@ +#include "php_git2.h" +#include "php_git2_priv.h" +#include "graph.h" +/* {{{ proto long git_graph_ahead_behind(resource $repo, string $local, string $upstream) + */ +PHP_FUNCTION(git_graph_ahead_behind) +{ + int result = 0, local_len = 0, upstream_len = 0, error = 0; + zval *repo = NULL, *array = NULL; + php_git2_t *_repo = NULL; + char *local = NULL, *upstream = NULL; + git_oid __local = {0}, __upstream = {0}; + size_t ahead = 0, behind = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rss", &ahead, &behind, &repo, &local, &local_len, &upstream, &upstream_len) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (git_oid_fromstrn(&__local, local, local_len)) { + RETURN_FALSE; + } + if (git_oid_fromstrn(&__upstream, upstream, upstream_len)) { + RETURN_FALSE; + } + result = git_graph_ahead_behind(&ahead, &behind, PHP_GIT2_V(_repo, repository), &__local, &__upstream); + + MAKE_STD_ZVAL(array); + array_init(array); + add_next_index_long(array, ahead); + add_next_index_long(array, behind); + + RETURN_ZVAL(array, 0, 1); +} +/* }}} */ + diff --git a/graph.h b/graph.h new file mode 100644 index 0000000000..3c1dbabc86 --- /dev/null +++ b/graph.h @@ -0,0 +1,39 @@ +/* + * PHP Libgit2 Extension + * + * https://github.com/libgit2/php-git + * + * Copyright 2014 Shuhei Tanuma. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef PHP_GIT2_GRAPH_H +#define PHP_GIT2_GRAPH_H + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_graph_ahead_behind, 0, 0, 3) + ZEND_ARG_INFO(0, repo) + ZEND_ARG_INFO(0, local) + ZEND_ARG_INFO(0, upstream) +ZEND_END_ARG_INFO() + +/* {{{ proto long git_graph_ahead_behind(long $ahead, long $behind, resource $repo, string $local, string $upstream) + */ +PHP_FUNCTION(git_graph_ahead_behind); + +#endif diff --git a/php_git2.c b/php_git2.c index 24427fa1b2..9c5e1edbb8 100644 --- a/php_git2.c +++ b/php_git2.c @@ -65,6 +65,7 @@ #include "giterr.h" #include "push.h" #include "refspec.h" +#include "graph.h" int git2_resource_handle; @@ -929,6 +930,9 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_refspec_transform, arginfo_git_refspec_transform) PHP_FE(git_refspec_rtransform, arginfo_git_refspec_rtransform) + /* graph */ + PHP_FE(git_graph_ahead_behind, arginfo_git_graph_ahead_behind) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE(git_libgit2_capabilities, NULL) From a9db5cf6011631a66ff41aa649610799e4f02155 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 01:32:12 +0900 Subject: [PATCH 088/136] [remote] implement several functions --- graph.c | 1 + refspec.c | 8 +-- remote.c | 177 +++++++++++++++++++++++++++++++++++++----------------- remote.h | 7 +-- 4 files changed, 130 insertions(+), 63 deletions(-) diff --git a/graph.c b/graph.c index f8d352e649..0d3c9265e6 100644 --- a/graph.c +++ b/graph.c @@ -1,6 +1,7 @@ #include "php_git2.h" #include "php_git2_priv.h" #include "graph.h" + /* {{{ proto long git_graph_ahead_behind(resource $repo, string $local, string $upstream) */ PHP_FUNCTION(git_graph_ahead_behind) diff --git a/refspec.c b/refspec.c index ddb7d76603..1cbd56f48e 100644 --- a/refspec.c +++ b/refspec.c @@ -78,7 +78,7 @@ PHP_FUNCTION(git_refspec_force) } /* }}} */ -/* {{{ proto resource git_refspec_direction(resource $spec) +/* {{{ proto long git_refspec_direction(resource $spec) */ PHP_FUNCTION(git_refspec_direction) { @@ -93,7 +93,7 @@ PHP_FUNCTION(git_refspec_direction) ZEND_FETCH_RESOURCE(_spec, php_git2_t*, &spec, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_refspec_direction(PHP_GIT2_V(_spec, refspec)); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ @@ -137,7 +137,7 @@ PHP_FUNCTION(git_refspec_dst_matches) } /* }}} */ -/* {{{ proto resource git_refspec_transform(long $outlen, resource $spec, string $name) +/* {{{ proto string git_refspec_transform(long $outlen, resource $spec, string $name) */ PHP_FUNCTION(git_refspec_transform) { @@ -161,7 +161,7 @@ PHP_FUNCTION(git_refspec_transform) } /* }}} */ -/* {{{ proto resource git_refspec_rtransform(long $outlen, resource $spec, string $name) +/* {{{ proto string git_refspec_rtransform(long $outlen, resource $spec, string $name) */ PHP_FUNCTION(git_refspec_rtransform) { diff --git a/remote.c b/remote.c index 9c40e147f5..164657088a 100644 --- a/remote.c +++ b/remote.c @@ -2,6 +2,25 @@ #include "php_git2_priv.h" #include "remote.h" +static void php_git2_git_transfer_progress_to_array(git_transfer_progress *progress, zval **out TSRMLS_DC) +{ + zval *result; + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("total_objects"), progress->total_objects); + add_assoc_long_ex(result, ZEND_STRS("indexed_objects"), progress->indexed_objects); + add_assoc_long_ex(result, ZEND_STRS("received_objects"), progress->received_objects); + add_assoc_long_ex(result, ZEND_STRS("local_objects"), progress->local_objects); + add_assoc_long_ex(result, ZEND_STRS("total_deltas"), progress->total_deltas); + add_assoc_long_ex(result, ZEND_STRS("indexed_deltas"), progress->indexed_deltas); + add_assoc_long_ex(result, ZEND_STRS("received_bytes"), progress->received_bytes); + + *out = result; +} + + /* {{{ proto resource git_remote_create(resource $repo, string $name, string $url) */ PHP_FUNCTION(git_remote_create) @@ -312,19 +331,21 @@ PHP_FUNCTION(git_remote_get_fetch_refspecs) PHP_FUNCTION(git_remote_set_fetch_refspecs) { int result = 0; - zval *remote = NULL; + zval *remote = NULL, *array = NULL; php_git2_t *_remote = NULL; - zval *array = NULL; int error = 0; + git_strarray out = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "ra", &remote, &array) == FAILURE) { + return; + } - /* TODO(chobie): implement this */ -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &remote, &array) == FAILURE) { -// return; -// } + php_git2_array_to_strarray(&out, array TSRMLS_CC); ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_remote_set_fetch_refspecs(PHP_GIT2_V(_remote, remote), array); + result = git_remote_set_fetch_refspecs(PHP_GIT2_V(_remote, remote), &out); + php_git2_strarray_free(&out); RETURN_LONG(result); } /* }}} */ @@ -348,7 +369,7 @@ PHP_FUNCTION(git_remote_add_push) ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_remote_add_push(PHP_GIT2_V(_remote, remote), refspec); - RETURN_BOOL(result); + RETURN_LONG(result); } /* }}} */ @@ -357,22 +378,22 @@ PHP_FUNCTION(git_remote_add_push) PHP_FUNCTION(git_remote_get_push_refspecs) { zval *result; - git_strarray array = {0}; - zval *remote = NULL; + git_strarray _array = {0}; + zval *remote = NULL, *array = NULL; php_git2_t *_remote = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &array, &remote) == FAILURE) { + "ar", &array, &remote) == FAILURE) { return; } + php_git2_strarray_to_array(&_array, array TSRMLS_CC); ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_remote_get_push_refspecs(&array, PHP_GIT2_V(_remote, remote)); - php_git2_strarray_to_array(&array, &result TSRMLS_CC); - git_strarray_free(&array); + error = git_remote_get_push_refspecs(&_array, PHP_GIT2_V(_remote, remote)); + git_strarray_free(&_array); - RETURN_ZVAL(result, 0, 1); + RETURN_LONG(error); } /* }}} */ @@ -382,19 +403,20 @@ PHP_FUNCTION(git_remote_get_push_refspecs) PHP_FUNCTION(git_remote_set_push_refspecs) { int result = 0; - zval *remote = NULL; + zval *remote = NULL, *array = NULL; php_git2_t *_remote = NULL; - zval *array = NULL; + git_strarray _array = {0}; int error = 0; - /* TODO(chobie): implement this */ -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "r", &remote, &array) == FAILURE) { -// return; -// } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &remote, &array) == FAILURE) { + return; + } + php_git2_strarray_to_array(&_array, array TSRMLS_CC); ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_remote_set_push_refspecs(PHP_GIT2_V(_remote, remote), array); + result = git_remote_set_push_refspecs(PHP_GIT2_V(_remote, remote), &_array); + git_strarray_free(&_array); RETURN_LONG(result); } /* }}} */ @@ -443,7 +465,7 @@ PHP_FUNCTION(git_remote_get_refspec) { const git_refspec *result = NULL; zval *remote = NULL; - php_git2_t *_remote = NULL; + php_git2_t *_remote = NULL, *out; long n = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -453,11 +475,13 @@ PHP_FUNCTION(git_remote_get_refspec) ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_remote_get_refspec(PHP_GIT2_V(_remote, remote), n); - /* TODO(chobie): implement this */ + if (php_git2_make_resource(&out, PHP_GIT2_TYPE_REFSPEC, result, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(out)); } /* }}} */ - /* {{{ proto bool git_remote_connect(resource $remote, long $direction) */ PHP_FUNCTION(git_remote_connect) @@ -479,28 +503,59 @@ PHP_FUNCTION(git_remote_connect) } /* }}} */ -/* {{{ proto resource git_remote_ls(long $size, resource $remote) +static void php_git2_git_remote_head_to_array(git_remote_head *head, zval **out TSRMLS_DC) +{ + zval *result = NULL; + char oid[41] = {0}, loid[41] = {0}; + + + git_oid_fmt(oid, &head->oid); + git_oid_fmt(loid, &head->loid); + + MAKE_STD_ZVAL(result); + array_init(result); + add_assoc_long_ex(result, ZEND_STRS("local"), head->local); + add_assoc_string_ex(result, ZEND_STRS("oid"), oid, 1); + add_assoc_string_ex(result, ZEND_STRS("loid"), loid, 1); + add_assoc_string_ex(result, ZEND_STRS("name"), head->name, 1); + + *out = result; +} + +/* {{{ proto resource git_remote_ls(resource $remote) */ PHP_FUNCTION(git_remote_ls) { php_git2_t *result = NULL; git_remote_head **out = NULL; - long size = 0; - zval *remote = NULL; + size_t size = 0; + zval *remote = NULL, *retval = NULL, *container = NULL; php_git2_t *_remote = NULL; - int error = 0; + int error = 0, i = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "lr", &size, &remote) == FAILURE) { + "r", &remote) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_remote_ls(&out, size, PHP_GIT2_V(_remote, remote)); + + if (git_remote_connected(PHP_GIT2_V(_remote, remote)) == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed git_remote hasn't been connected"); + RETURN_FALSE; + } + error = git_remote_ls(&out, &size, PHP_GIT2_V(_remote, remote)); if (php_git2_check_error(error, "git_remote_ls" TSRMLS_CC)) { RETURN_FALSE; } - /* TODO(chobie): implement this */ + + MAKE_STD_ZVAL(container); + array_init(container); + for (i = 0; i < size; i++) { + php_git2_git_remote_head_to_array(out[i], &retval TSRMLS_CC); + add_next_index_zval(container, retval); + } + RETURN_ZVAL(container, 0, 1); } /* }}} */ @@ -851,7 +906,7 @@ PHP_FUNCTION(git_remote_set_callbacks) PHP_FUNCTION(git_remote_stats) { const git_transfer_progress *result = NULL; - zval *remote = NULL; + zval *remote = NULL, *retval = NULL; php_git2_t *_remote = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -861,7 +916,8 @@ PHP_FUNCTION(git_remote_stats) ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_remote_stats(PHP_GIT2_V(_remote, remote)); - /* TODO(chobie): implement this */ + php_git2_git_transfer_progress_to_array(result, &retval TSRMLS_CC); + RETURN_ZVAL(retval, 0, 1); } /* }}} */ @@ -881,7 +937,7 @@ PHP_FUNCTION(git_remote_autotag) ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_remote_autotag(PHP_GIT2_V(_remote, remote)); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ @@ -892,9 +948,8 @@ PHP_FUNCTION(git_remote_set_autotag) zval *remote = NULL, *value = NULL; php_git2_t *_remote = NULL; - /* TODO(chobie):impelement this */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &remote, &value) == FAILURE) { + "rl", &remote, &value) == FAILURE) { return; } @@ -904,27 +959,39 @@ PHP_FUNCTION(git_remote_set_autotag) /* }}} */ -/* {{{ proto long git_remote_rename(remote, new_name, callback, payload) -*/ +static int php_git2_git_remote_rename_problem_cb(const char *problematic_refspec, void *payload) +{ + return 0; +} + + +/* {{{ proto long git_remote_rename(resource $remote, string $new_name, Callable $callback, $payload) + */ PHP_FUNCTION(git_remote_rename) { - zval *remote; - php_git2_t *_remote; - char *new_name = {0}; - int new_name_len; - zval *callback; - php_git2_t *_callback; + int result = 0, new_name_len = 0, error = 0; + zval *remote = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_remote = NULL; + char *new_name = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_remote_rename not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsfz", &remote, &new_name, &new_name_len, &fci, &fcc, &payload) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rsr", &remote, &new_name, &new_name_len, &callback, &payload) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_remote_rename(PHP_GIT2_V(_remote, remote), new_name, php_git2_git_remote_rename_problem_cb, cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_remote_update_fetchhead(resource $remote) */ diff --git a/remote.h b/remote.h index 7d8b17d871..c5d1f90d14 100644 --- a/remote.h +++ b/remote.h @@ -128,8 +128,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_connect, 0, 0, 2) ZEND_ARG_INFO(0, direction) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_ls, 0, 0, 2) - ZEND_ARG_INFO(0, size) +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_ls, 0, 0, 1) ZEND_ARG_INFO(0, remote) ZEND_END_ARG_INFO() @@ -205,7 +204,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_rename, 0, 0, 4) ZEND_ARG_INFO(0, remote) ZEND_ARG_INFO(0, new_name) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_remote_update_fetchhead, 0, 0, 1) @@ -305,7 +304,7 @@ PHP_FUNCTION(git_remote_get_refspec); */ PHP_FUNCTION(git_remote_connect); -/* {{{ proto resource git_remote_ls(size, remote) +/* {{{ proto resource git_remote_ls(remote) */ PHP_FUNCTION(git_remote_ls); From 3604ff32d6b0b4024a1c5db2eac98d3dd9d2c36c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 01:37:28 +0900 Subject: [PATCH 089/136] fix git_attr_value --- attr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/attr.c b/attr.c index 796a71a324..fce466b0d3 100644 --- a/attr.c +++ b/attr.c @@ -16,7 +16,7 @@ PHP_FUNCTION(git_attr_value) } result = git_attr_value(attr); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ @@ -92,6 +92,7 @@ PHP_FUNCTION(git_attr_foreach) if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { RETURN_FALSE; } + // TODO(chobie): implement this //result = git_attr_foreach(PHP_GIT2_V(_repo, repository), flags, path, , cb); php_git2_cb_free(cb); RETURN_LONG(result); From 29d3a487d948ddbcffec246f7c62abac1eb041aa Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 01:58:25 +0900 Subject: [PATCH 090/136] [patch] update code base --- patch.c | 158 +++++++++++++++++++++++--------------------------------- reset.c | 13 +++-- 2 files changed, 76 insertions(+), 95 deletions(-) diff --git a/patch.c b/patch.c index 392975b1f8..5345c2bfc6 100644 --- a/patch.c +++ b/patch.c @@ -6,10 +6,9 @@ */ PHP_FUNCTION(git_patch_from_diff) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_diff = NULL; git_patch *out = NULL; zval *diff = NULL; - php_git2_t *_diff = NULL; long idx = 0; int error = 0; @@ -23,12 +22,10 @@ PHP_FUNCTION(git_patch_from_diff) if (php_git2_check_error(error, "git_patch_from_diff" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, patch) = out; - result->type = PHP_GIT2_TYPE_PATCH; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATCH, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -37,18 +34,11 @@ PHP_FUNCTION(git_patch_from_diff) */ PHP_FUNCTION(git_patch_from_blobs) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_old_blob = NULL, *_new_blob = NULL; git_patch *out = NULL; - zval *old_blob = NULL; - php_git2_t *_old_blob = NULL; - char *old_as_path = NULL; - int old_as_path_len = 0; - zval *new_blob = NULL; - php_git2_t *_new_blob = NULL; - char *new_as_path = NULL; - int new_as_path_len = 0; - zval *opts = NULL; - int error = 0; + zval *old_blob = NULL, *new_blob = NULL, *opts = NULL; + char *old_as_path = NULL, *new_as_path = NULL; + int old_as_path_len = 0, new_as_path_len = 0, error = 0; /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -62,31 +52,23 @@ PHP_FUNCTION(git_patch_from_blobs) if (php_git2_check_error(error, "git_patch_from_blobs" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, patch) = out; - result->type = PHP_GIT2_TYPE_PATCH; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATCH, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ -/* {{{ proto resource git_patch_from_blob_and_buffer(resource $old_blob, string $old_as_path, string $buffer, string $buffer_as_path, $opts) + +/* {{{ proto resource git_patch_from_blob_and_buffer(resource $old_blob, string $old_as_path, string $buffer, string $buffer_as_path, $opts) */ PHP_FUNCTION(git_patch_from_blob_and_buffer) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_old_blob = NULL; git_patch *out = NULL; - zval *old_blob = NULL; - php_git2_t *_old_blob = NULL; - char *old_as_path = NULL; - int old_as_path_len = 0; - char *buffer = NULL; - int buffer_len = 0; - char *buffer_as_path = NULL; - int buffer_as_path_len = 0; - zval *opts = NULL; - int error = 0; + zval *old_blob = NULL, *opts = NULL; + char *old_as_path = NULL, *buffer = NULL, *buffer_as_path = NULL; + int old_as_path_len = 0, buffer_len = 0, buffer_as_path_len = 0, error = 0; /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -99,12 +81,10 @@ PHP_FUNCTION(git_patch_from_blob_and_buffer) if (php_git2_check_error(error, "git_patch_from_blob_and_buffer" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, patch) = out; - result->type = PHP_GIT2_TYPE_PATCH; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_PATCH, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -122,8 +102,9 @@ PHP_FUNCTION(git_patch_free) } ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_patch->should_free_v) { + if (GIT2_SHOULD_FREE(_patch)) { git_patch_free(PHP_GIT2_V(_patch, patch)); + GIT2_SHOULD_FREE(_patch) = 0; }; zval_ptr_dtor(&patch); } @@ -149,7 +130,6 @@ PHP_FUNCTION(git_patch_get_delta) } /* }}} */ - /* {{{ proto long git_patch_num_hunks(resource $patch) */ PHP_FUNCTION(git_patch_num_hunks) @@ -169,18 +149,14 @@ PHP_FUNCTION(git_patch_num_hunks) } /* }}} */ - /* {{{ proto long git_patch_line_stats(long $total_context, long $total_additions, long $total_deletions, resource $patch) */ PHP_FUNCTION(git_patch_line_stats) { - int result = 0; - long total_context = 0; - long total_additions = 0; - long total_deletions = 0; + int result = 0, error = 0; + long total_context = 0, total_additions = 0, total_deletions = 0; zval *patch = NULL; php_git2_t *_patch = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllr", &total_context, &total_additions, &total_deletions, &patch) == FAILURE) { @@ -193,17 +169,14 @@ PHP_FUNCTION(git_patch_line_stats) } /* }}} */ - /* {{{ proto resource git_patch_get_hunk(long $lines_in_hunk, resource $patch, long $hunk_idx) */ PHP_FUNCTION(git_patch_get_hunk) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_patch = NULL; git_diff_hunk *out = NULL; - long lines_in_hunk = 0; + long lines_in_hunk = 0, hunk_idx = 0; zval *patch = NULL; - php_git2_t *_patch = NULL; - long hunk_idx = 0; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -216,25 +189,21 @@ PHP_FUNCTION(git_patch_get_hunk) if (php_git2_check_error(error, "git_patch_get_hunk" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, diff_hunk) = out; - result->type = PHP_GIT2_TYPE_DIFF_HUNK; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_DIFF_HUNK, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto long git_patch_num_lines_in_hunk(resource $patch, long $hunk_idx) */ PHP_FUNCTION(git_patch_num_lines_in_hunk) { - int result = 0; + int result = 0, error = 0; zval *patch = NULL; php_git2_t *_patch = NULL; long hunk_idx = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &patch, &hunk_idx) == FAILURE) { @@ -251,12 +220,10 @@ PHP_FUNCTION(git_patch_num_lines_in_hunk) */ PHP_FUNCTION(git_patch_get_line_in_hunk) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_patch = NULL; git_diff_line *out = NULL; zval *patch = NULL; - php_git2_t *_patch = NULL; - long hunk_idx = 0; - long line_of_hunk = 0; + long hunk_idx = 0, line_of_hunk = 0; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -269,16 +236,13 @@ PHP_FUNCTION(git_patch_get_line_in_hunk) if (php_git2_check_error(error, "git_patch_get_line_in_hunk" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, diff_line) = out; - result->type = PHP_GIT2_TYPE_DIFF_LINE; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_DIFF_LINE, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto long git_patch_size(resource $patch, long $include_context, long $include_hunk_headers, long $include_file_headers) */ PHP_FUNCTION(git_patch_size) @@ -286,9 +250,7 @@ PHP_FUNCTION(git_patch_size) size_t result = 0; zval *patch = NULL; php_git2_t *_patch = NULL; - long include_context = 0; - long include_hunk_headers = 0; - long include_file_headers = 0; + long include_context = 0, include_hunk_headers = 0, include_file_headers = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &patch, &include_context, &include_hunk_headers, &include_file_headers) == FAILURE) { @@ -301,30 +263,42 @@ PHP_FUNCTION(git_patch_size) } /* }}} */ -/* {{{ proto long git_patch_print(patch, print_cb, payload) -*/ + +/* {{{ proto long git_patch_print(resource $patch, Callable $print_cb, $payload) + */ PHP_FUNCTION(git_patch_print) { - zval *patch; - php_git2_t *_patch; - zval *print_cb; - php_git2_t *_print_cb; + int result = 0, error = 0; + zval *patch = NULL, *print_cb = NULL, *payload = NULL; + php_git2_t *_patch = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_patch_print not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rfz", &patch, &fci, &fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_patch_print(PHP_GIT2_V(_patch, patch), , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ + /* {{{ proto long git_patch_to_str(string $string, resource $patch) */ PHP_FUNCTION(git_patch_to_str) { - int result = 0; + int result = 0, string_len = 0, error = 0; char *string = NULL; - int string_len = 0; zval *patch = NULL; php_git2_t *_patch = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr", &string, &string_len, &patch) == FAILURE) { @@ -332,7 +306,7 @@ PHP_FUNCTION(git_patch_to_str) } ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_patch_to_str(string, PHP_GIT2_V(_patch, patch)); + result = git_patch_to_str(&string, PHP_GIT2_V(_patch, patch)); RETURN_LONG(result); } /* }}} */ diff --git a/reset.c b/reset.c index f9db4662c8..48f39bc8eb 100644 --- a/reset.c +++ b/reset.c @@ -28,17 +28,24 @@ PHP_FUNCTION(git_reset) PHP_FUNCTION(git_reset_default) { int result = 0, error = 0; - zval *repo = NULL, *target = NULL, *pathspecs = NULL; + zval *repo = NULL, *target = NULL, *pathspecs = NULL, *array = NULL; php_git2_t *_repo = NULL, *_target = NULL; + git_strarray _pathspecs = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &target, &pathspecs) == FAILURE) { return; } - + if (zend_hash_num_elements(pathspecs) > 0) { + php_git2_array_to_strarray(&_pathspecs, pathspecs TSRMLS_CC); + } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_reset_default(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_target, object), pathspecs); + result = git_reset_default(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_target, object), &_pathspecs); + if (zend_hash_num_elements(pathspecs) > 0) { + git_strarray_free(&array); + } + RETURN_LONG(result); } /* }}} */ From f7adbdaaeff085b6a4cc7a890453d20633aafe66 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:00:46 +0900 Subject: [PATCH 091/136] [filter] update code base --- filter.c | 322 ++++++------------------------------------------------- 1 file changed, 34 insertions(+), 288 deletions(-) diff --git a/filter.c b/filter.c index ca43c4f682..d1b74e3d9d 100644 --- a/filter.c +++ b/filter.c @@ -6,22 +6,18 @@ */ PHP_FUNCTION(git_filter_list_load) { - int result = 0; + int result = 0, path_len = 0, error = 0; git_filter_list *filters = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *blob = NULL; - php_git2_t *_blob = NULL; + zval *repo = NULL, *blob = NULL; + php_git2_t *_repo = NULL, *_blob = NULL; char *path = NULL; - int path_len = 0; long mode = 0; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrsl", &repo, &blob, &path, &path_len, &mode) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_filter_list_load(&filters, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_blob, blob), path, mode); @@ -29,356 +25,106 @@ PHP_FUNCTION(git_filter_list_load) } /* }}} */ - /* {{{ proto resource git_filter_list_apply_to_data(resource $filters, resource $in) */ PHP_FUNCTION(git_filter_list_apply_to_data) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_filters = NULL, *_in = NULL; git_buf out = {0}; - zval *filters = NULL; - php_git2_t *_filters = NULL; - zval *in = NULL; - php_git2_t *_in = NULL; + zval *filters = NULL, *in = NULL; int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &filters, &in) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_in, php_git2_t*, &in, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_filter_list_apply_to_data(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_in, buf)); if (php_git2_check_error(error, "git_filter_list_apply_to_data" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, buf) = &out; - result->type = PHP_GIT2_TYPE_BUF; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, &out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_filter_list_apply_to_file(resource $filters, resource $repo, string $path) */ PHP_FUNCTION(git_filter_list_apply_to_file) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_filters = NULL, *_repo = NULL; git_buf out = {0}; - zval *filters = NULL; - php_git2_t *_filters = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; + zval *filters = NULL, *repo = NULL; char *path = NULL; - int path_len = 0; - int error = 0; - + int path_len = 0, error = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrs", &filters, &repo, &path, &path_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_filter_list_apply_to_file(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_repo, repository), path); if (php_git2_check_error(error, "git_filter_list_apply_to_file" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, buf) = &out; - result->type = PHP_GIT2_TYPE_BUF; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, &out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_filter_list_apply_to_blob(resource $filters, resource $blob) */ PHP_FUNCTION(git_filter_list_apply_to_blob) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_filters = NULL, *_blob = NULL; git_buf out = {0}; - zval *filters = NULL; - php_git2_t *_filters = NULL; - zval *blob = NULL; - php_git2_t *_blob = NULL; + zval *filters = NULL, *blob = NULL; int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &filters, &blob) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_filter_list_apply_to_blob(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_blob, blob)); if (php_git2_check_error(error, "git_filter_list_apply_to_blob" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, buf) = &out; - result->type = PHP_GIT2_TYPE_BUF; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, &out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto void git_filter_list_free(resource $filters) */ PHP_FUNCTION(git_filter_list_free) { zval *filters = NULL; php_git2_t *_filters = NULL; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &filters) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_filters->should_free_v) { + if (GIT2_SHOULD_FREE(_filters)) { git_filter_list_free(PHP_GIT2_V(_filters, filter_list)); + GIT2_SHOULD_FREE(_filters) = 0; }; zval_ptr_dtor(&filters); } /* }}} */ -/* {{{ proto resource git_filter_lookup(string $name) - */ -PHP_FUNCTION(git_filter_lookup) -{ - git_filter *result = NULL; - char *name = NULL; - int name_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &name, &name_len) == FAILURE) { - return; - } - - result = git_filter_lookup(name); - /* TODO(chobie): implement this */ -} -/* }}} */ - - -/* {{{ proto resource git_filter_list_new(resource $repo, $mode) - */ -PHP_FUNCTION(git_filter_list_new) -{ - php_git2_t *result = NULL; - git_filter_list *out = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - long mode = 0; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rl", &repo, &mode) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_filter_list_new(&out, PHP_GIT2_V(_repo, repository), mode); - if (php_git2_check_error(error, "git_filter_list_new" TSRMLS_CC)) { - RETURN_FALSE; - } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, filter_list) = out; - result->type = PHP_GIT2_TYPE_FILTER_LIST; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); -} -/* }}} */ - - -/* {{{ proto long git_filter_list_push(fl, filter, payload) -*/ -PHP_FUNCTION(git_filter_list_push) -{ - zval *fl; - php_git2_t *_fl; - zval *filter; - php_git2_t *_filter; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_filter_list_push not implemented yet"); - return; - -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rr", &fl, &filter, &payload) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -} - -/* {{{ proto long git_filter_list_length(resource $fl) - */ -PHP_FUNCTION(git_filter_list_length) -{ - size_t result = 0; - zval *fl = NULL; - php_git2_t *_fl = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &fl) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_filter_list_length(PHP_GIT2_V(_fl, filter_list)); - RETURN_LONG(result); -} -/* }}} */ - - -/* {{{ proto resource git_filter_source_repo(resource $src) - */ -PHP_FUNCTION(git_filter_source_repo) -{ - git_repository *result = NULL; - zval *src = NULL; - php_git2_t *_src = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &src) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_filter_source_repo(PHP_GIT2_V(_src, filter_source)); - /* TODO(chobie): implement this */ -} -/* }}} */ - - -/* {{{ proto string git_filter_source_path(resource $src) - */ -PHP_FUNCTION(git_filter_source_path) -{ - const char *result = NULL; - zval *src = NULL; - php_git2_t *_src = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &src) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_filter_source_path(PHP_GIT2_V(_src, filter_source)); - RETURN_STRING(result, 1); -} -/* }}} */ - - -/* {{{ proto long git_filter_source_filemode(resource $src) - */ -PHP_FUNCTION(git_filter_source_filemode) -{ - uint16_t result = 0; - zval *src = NULL; - php_git2_t *_src = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &src) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_filter_source_filemode(PHP_GIT2_V(_src, filter_source)); - RETURN_LONG(result); -} -/* }}} */ - - -/* {{{ proto resource git_filter_source_id(resource $src) - */ -PHP_FUNCTION(git_filter_source_id) -{ - const git_oid *result = NULL; - zval *src = NULL; - php_git2_t *_src = NULL; - char __result[GIT2_OID_HEXSIZE] = {0}; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &src) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_filter_source_id(PHP_GIT2_V(_src, filter_source)); - git_oid_fmt(__result, result); - RETURN_STRING(__result, 1); -} -/* }}} */ - - -/* {{{ proto resource git_filter_source_mode(resource $src) - */ -PHP_FUNCTION(git_filter_source_mode) -{ - git_filter_mode_t *result = NULL; - zval *src = NULL; - php_git2_t *_src = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &src) == FAILURE) { - return; - } - - ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_filter_source_mode(PHP_GIT2_V(_src, filter_source)); - RETURN_LONG(result); -} -/* }}} */ - - -/* {{{ proto long git_filter_register(string $name, $filter, long $priority) - */ -PHP_FUNCTION(git_filter_register) -{ - int result = 0; - char *name = NULL; - int name_len = 0; - zval *filter = NULL; - long priority = 0; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sal", &name, &name_len, &filter, &priority) == FAILURE) { - return; - } - - result = git_filter_register(name, filter, priority); - RETURN_LONG(result); -} -/* }}} */ - -/* {{{ proto long git_filter_unregister(string $name) - */ -PHP_FUNCTION(git_filter_unregister) -{ - int result = 0; - char *name = NULL; - int name_len = 0; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &name, &name_len) == FAILURE) { - return; - } - - result = git_filter_unregister(name); - RETURN_LONG(result); -} -/* }}} */ From bc114960c94b05e296238181aa538329b97c43a2 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:12:35 +0900 Subject: [PATCH 092/136] [merge] update code base --- filter.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ merge.c | 206 ++++++++++++++++++++++----------------------------- ng.php | 1 + 3 files changed, 309 insertions(+), 119 deletions(-) diff --git a/filter.c b/filter.c index d1b74e3d9d..fb39792c23 100644 --- a/filter.c +++ b/filter.c @@ -128,3 +128,224 @@ PHP_FUNCTION(git_filter_list_free) } /* }}} */ + +/* sys/filter */ + +/* {{{ proto resource git_filter_lookup(string $name) + */ +PHP_FUNCTION(git_filter_lookup) +{ + git_filter *result = NULL; + char *name = NULL; + int name_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &name, &name_len) == FAILURE) { + return; + } + + result = git_filter_lookup(name); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto resource git_filter_list_new(resource $repo, $mode) + */ +PHP_FUNCTION(git_filter_list_new) +{ + php_git2_t *result = NULL, *_repo = NULL; + git_filter_list *out = NULL; + zval *repo = NULL, *mode = NULL; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &repo, &mode) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_new(&out, PHP_GIT2_V(_repo, repository), mode); + if (php_git2_check_error(error, "git_filter_list_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_FILTER_LIST, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} +/* }}} */ + +/* {{{ proto long git_filter_list_push(resource $fl, resource $filter, $payload) + */ +PHP_FUNCTION(git_filter_list_push) +{ + int result = 0, error = 0; + zval *fl = NULL, *filter = NULL, *payload = NULL; + php_git2_t *_fl = NULL, *_filter = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rr", &fl, &filter, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_filter, php_git2_t*, &filter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + //result = git_filter_list_push(PHP_GIT2_V(_fl, filter_list), PHP_GIT2_V(_filter, filter), cb); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_filter_list_length(resource $fl) + */ +PHP_FUNCTION(git_filter_list_length) +{ + size_t result = 0; + zval *fl = NULL; + php_git2_t *_fl = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &fl) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_list_length(PHP_GIT2_V(_fl, filter_list)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_filter_source_repo(resource $src) + */ +PHP_FUNCTION(git_filter_source_repo) +{ + git_repository *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_repo(PHP_GIT2_V(_src, filter_source)); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto string git_filter_source_path(resource $src) + */ +PHP_FUNCTION(git_filter_source_path) +{ + const char *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_path(PHP_GIT2_V(_src, filter_source)); + RETURN_STRING(result, 1); +} +/* }}} */ + +/* {{{ proto long git_filter_source_filemode(resource $src) + */ +PHP_FUNCTION(git_filter_source_filemode) +{ + uint16_t result = 0; + zval *src = NULL; + php_git2_t *_src = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_filemode(PHP_GIT2_V(_src, filter_source)); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto resource git_filter_source_id(resource $src) + */ +PHP_FUNCTION(git_filter_source_id) +{ + const git_oid *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_id(PHP_GIT2_V(_src, filter_source)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); +} +/* }}} */ + +/* {{{ proto resource git_filter_source_mode(resource $src) + */ +PHP_FUNCTION(git_filter_source_mode) +{ + git_filter_mode_t *result = NULL; + zval *src = NULL; + php_git2_t *_src = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "r", &src) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_filter_source_mode(PHP_GIT2_V(_src, filter_source)); + /* TODO(chobie): implement this */ +} +/* }}} */ + +/* {{{ proto long git_filter_register(string $name, resource $filter, long $priority) + */ +PHP_FUNCTION(git_filter_register) +{ + int result = 0, name_len = 0, error = 0; + char *name = NULL; + zval *filter = NULL; + php_git2_t *_filter = NULL; + long priority = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "srl", &name, &name_len, &filter, &priority) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_filter, php_git2_t*, &filter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + //result = git_filter_register(name, PHP_GIT2_V(_filter, filter), priority); + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto long git_filter_unregister(string $name) + */ +PHP_FUNCTION(git_filter_unregister) +{ + int result = 0, name_len = 0, error = 0; + char *name = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &name, &name_len) == FAILURE) { + return; + } + + result = git_filter_unregister(name); + RETURN_LONG(result); +} +/* }}} */ + diff --git a/merge.c b/merge.c index b85f50587a..f18e160b19 100644 --- a/merge.c +++ b/merge.c @@ -1,28 +1,21 @@ #include "php_git2.h" #include "php_git2_priv.h" #include "merge.h" - /* {{{ proto resource git_merge_base(resource $repo, string $one, string $two) */ PHP_FUNCTION(git_merge_base) { - git_oid out = {0}; + php_git2_t *result = NULL, *_repo = NULL; + git_oid out = {0}, __one = {0}, __two = {0}; zval *repo = NULL; - php_git2_t *_repo = NULL; - char *one = NULL; - int one_len = 0; - git_oid __one; - char *two = NULL; - int two_len = 0; - git_oid __two; - int error = 0; - char result[GIT2_OID_HEXSIZE] = {0}; - + char *one = NULL, *two = NULL, oid[41] = {0}; + int one_len = 0, two_len = 0, error = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &repo, &one, &one_len, &two, &two_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); if (git_oid_fromstrn(&__one, one, one_len)) { RETURN_FALSE; @@ -34,59 +27,66 @@ PHP_FUNCTION(git_merge_base) if (php_git2_check_error(error, "git_merge_base" TSRMLS_CC)) { RETURN_FALSE; } - git_oid_fmt(result, &out); - RETURN_STRING(result, 1); + git_oid_fmt(oid, &out); + RETURN_STRING(oid, 1); } /* }}} */ - -/* {{{ proto resource git_merge_base_many(repo, length, input_array[]) -*/ +/* {{{ proto resource git_merge_base_many(resource $repo, long $length, string $input_array[]) + */ PHP_FUNCTION(git_merge_base_many) { -// zval *repo; -// php_git2_t *_repo; -// char *input_array[] = {0}; -// int input_array[]_len; -// -// /* TODO(chobie): implement this */ -// php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_merge_base_many not implemented yet"); -// return; -// +// php_git2_t *result = NULL, *_repo = NULL; +// git_oid out = {0}, __input_array[] = {0}; +// zval *repo = NULL; +// long length = 0; +// char *input_array[] = NULL; +// int input_array[]_len = 0, error = 0; + // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rs", &repo, &length, &input_array[], &input_array[]_len) == FAILURE) { +// "rls", &repo, &length, &input_array[], &input_array[]_len) == FAILURE) { // return; // } + // ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// if (git_oid_fromstrn(&__input_array[], input_array[], input_array[]_len)) { +// RETURN_FALSE; +// } +// error = git_merge_base_many(&__out, PHP_GIT2_V(_repo, repository), length, __input_array[]); +// if (php_git2_check_error(error, "git_merge_base_many" TSRMLS_CC)) { +// RETURN_FALSE; +// } +// if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OID, out, 1 TSRMLS_CC)) { +// RETURN_FALSE; +// } +// ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ /* {{{ proto resource git_merge_head_from_ref(resource $repo, resource $ref) */ PHP_FUNCTION(git_merge_head_from_ref) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL, *_ref = NULL; git_merge_head *out = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *ref = NULL; - php_git2_t *_ref = NULL; + zval *repo = NULL, *ref = NULL; int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &repo, &ref) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_merge_head_from_ref(&out, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_ref, reference)); if (php_git2_check_error(error, "git_merge_head_from_ref" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 0 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, result->resource_id); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -94,24 +94,18 @@ PHP_FUNCTION(git_merge_head_from_ref) */ PHP_FUNCTION(git_merge_head_from_fetchhead) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_merge_head *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; - char *branch_name = NULL; - int branch_name_len = 0; - char *remote_url = NULL; - int remote_url_len = 0; - char *oid = NULL; - int oid_len = 0; - git_oid __oid; - int error = 0; - + char *branch_name = NULL, *remote_url = NULL, *oid = NULL; + int branch_name_len = 0, remote_url_len = 0, oid_len = 0, error = 0; + git_oid __oid = {0}; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &repo, &branch_name, &branch_name_len, &remote_url, &remote_url_len, &oid, &oid_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); if (git_oid_fromstrn(&__oid, oid, oid_len)) { RETURN_FALSE; @@ -120,34 +114,29 @@ PHP_FUNCTION(git_merge_head_from_fetchhead) if (php_git2_check_error(error, "git_merge_head_from_fetchhead" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, merge_head) = out; - result->type = PHP_GIT2_TYPE_MERGE_HEAD; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_merge_head_from_oid(resource $repo, string $oid) */ PHP_FUNCTION(git_merge_head_from_oid) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_merge_head *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; char *oid = NULL; - int oid_len = 0; - git_oid __oid; - int error = 0; - + int oid_len = 0, error = 0; + git_oid __oid = {0}; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &oid, &oid_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); if (git_oid_fromstrn(&__oid, oid, oid_len)) { RETURN_FALSE; @@ -156,58 +145,48 @@ PHP_FUNCTION(git_merge_head_from_oid) if (php_git2_check_error(error, "git_merge_head_from_oid" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 0 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, result->resource_id); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto void git_merge_head_free(resource $head) */ PHP_FUNCTION(git_merge_head_free) { zval *head = NULL; php_git2_t *_head = NULL; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &head) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_head, php_git2_t*, &head, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_head->should_free_v) { + if (GIT2_SHOULD_FREE(_head)) { git_merge_head_free(PHP_GIT2_V(_head, merge_head)); + GIT2_SHOULD_FREE(_head) = 0; }; zval_ptr_dtor(&head); } /* }}} */ - /* {{{ proto resource git_merge_trees(resource $repo, resource $ancestor_tree, resource $our_tree, resource $their_tree, $opts) */ PHP_FUNCTION(git_merge_trees) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL, *_ancestor_tree = NULL, *_our_tree = NULL, *_their_tree = NULL; git_index *out = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *ancestor_tree = NULL; - php_git2_t *_ancestor_tree = NULL; - zval *our_tree = NULL; - php_git2_t *_our_tree = NULL; - zval *their_tree = NULL; - php_git2_t *_their_tree = NULL; - zval *opts = NULL; + zval *repo = NULL, *ancestor_tree = NULL, *our_tree = NULL, *their_tree = NULL, *opts = NULL; int error = 0; - - /* TODO(chobie): create array converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrrra", &repo, &ancestor_tree, &our_tree, &their_tree, &opts) == FAILURE) { + "rrrr", &repo, &ancestor_tree, &our_tree, &their_tree, &opts) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_ancestor_tree, php_git2_t*, &ancestor_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_our_tree, php_git2_t*, &our_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); @@ -216,112 +195,101 @@ PHP_FUNCTION(git_merge_trees) if (php_git2_check_error(error, "git_merge_trees" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX, out, 0 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX, out, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, result->resource_id); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - - /* {{{ proto resource git_merge(resource $repo, long $their_heads_len, $opts) */ PHP_FUNCTION(git_merge) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_merge_result *out = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; + zval *repo = NULL, *opts = NULL; git_merge_head *their_heads = NULL; long their_heads_len = 0; - zval *opts = NULL; int error = 0; - - /* TODO(chobie): implement converter */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rla", &repo, &their_heads_len, &opts) == FAILURE) { + "rl", &repo, &their_heads_len, &opts) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - //error = git_merge(&out, PHP_GIT2_V(_repo, repository), &their_heads, their_heads_len, opts); + error = git_merge(&out, PHP_GIT2_V(_repo, repository), &their_heads, their_heads_len, opts); if (php_git2_check_error(error, "git_merge" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_RESULT, out, 0 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_RESULT, out, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, result->resource_id); + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto long git_merge_result_is_uptodate(resource $merge_result) */ PHP_FUNCTION(git_merge_result_is_uptodate) { - int result = 0; + int result = 0, error = 0; zval *merge_result = NULL; php_git2_t *_merge_result = NULL; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_merge_result_is_uptodate(PHP_GIT2_V(_merge_result, merge_result)); RETURN_BOOL(result); } /* }}} */ - /* {{{ proto long git_merge_result_is_fastforward(resource $merge_result) */ PHP_FUNCTION(git_merge_result_is_fastforward) { - int result = 0; + int result = 0, error = 0; zval *merge_result = NULL; php_git2_t *_merge_result = NULL; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_merge_result_is_fastforward(PHP_GIT2_V(_merge_result, merge_result)); RETURN_BOOL(result); } /* }}} */ - /* {{{ proto resource git_merge_result_fastforward_oid(resource $merge_result) */ PHP_FUNCTION(git_merge_result_fastforward_oid) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_merge_result = NULL; git_oid out = {0}; zval *merge_result = NULL; - php_git2_t *_merge_result = NULL; int error = 0; - char buffer[GIT2_OID_HEXSIZE] = {0}; - + char buf[41] = {0}; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_merge_result_fastforward_oid(&out, PHP_GIT2_V(_merge_result, merge_result)); if (php_git2_check_error(error, "git_merge_result_fastforward_oid" TSRMLS_CC)) { RETURN_FALSE; } - git_oid_fmt(buffer, &out); - RETURN_STRING(buffer, 1); + git_oid_fmt(buf, &out); + RETURN_SRING(buf, 1); } /* }}} */ @@ -331,12 +299,12 @@ PHP_FUNCTION(git_merge_result_free) { zval *merge_result = NULL; php_git2_t *_merge_result = NULL; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &merge_result) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); if (GIT2_SHOULD_FREE(_merge_result)) { git_merge_result_free(PHP_GIT2_V(_merge_result, merge_result)); diff --git a/ng.php b/ng.php index a59fc1c537..16f469c338 100644 --- a/ng.php +++ b/ng.php @@ -406,6 +406,7 @@ public function shouldResource(Arg $arg) "git_submodule", "git_push", "git_refspec", + "git_filter", ); } From 384367d90ad58453bc6a24cbc27b3e532d3d865b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:15:51 +0900 Subject: [PATCH 093/136] [indexer] update code base --- indexer.c | 135 ++++++++++++++++++++++++++++++----------------------- indexer.h | 25 +++++----- ng.php | 1 + php_git2.h | 2 + 4 files changed, 92 insertions(+), 71 deletions(-) diff --git a/indexer.c b/indexer.c index b5da4bdc69..fcc4ff25c9 100644 --- a/indexer.c +++ b/indexer.c @@ -2,102 +2,119 @@ #include "php_git2_priv.h" #include "indexer.h" -/* {{{ proto resource git_indexer_new(path, mode, odb, progress_cb, progress_cb_payload) -*/ +/* {{{ proto resource git_indexer_new(string $path, long $mode, resource $odb, $progress_cb, $progress_cb_payload) + */ PHP_FUNCTION(git_indexer_new) { - char *path = {0}; - int path_len; - long mode; - zval *odb; - php_git2_t *_odb; - zval *progress_cb; - php_git2_t *_progress_cb; + php_git2_t *result = NULL, *_odb = NULL; + git_indexer *out = NULL; + char *path = NULL; + int path_len = 0, error = 0; + long mode = 0; + zval *odb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_new not implemented yet"); - return; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "slrfz", &path, &path_len, &mode, &odb, &fci, &fcc, &progress_cb_payload) == FAILURE) { + return; + } -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "slrr", &path, &path_len, &mode, &odb, &progress_cb, &progress_cb_payload) == FAILURE) { -// return; -// } -// ZEND_FETCH_RESOURCE(_path, php_git2_t*, &path, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, progress_cb_payload TSRMLS_CC)) { + RETURN_FALSE; + } + //error = git_indexer_new(&out, path, mode, PHP_GIT2_V(_odb, odb), progress_cb, cb); + if (php_git2_check_error(error, "git_indexer_new" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEXER, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ -/* {{{ proto long git_indexer_append(idx, data, size, stats) -*/ +/* {{{ proto long git_indexer_append(resource $idx, $data, long $size, $stats) + */ PHP_FUNCTION(git_indexer_append) { - zval *idx; - php_git2_t *_idx; - zval *stats; - php_git2_t *_stats; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_append not implemented yet"); - return; + int result = 0, error = 0; + zval *idx = NULL, *stats = NULL; + php_git2_t *_idx = NULL; + zval *data = NULL; + long size = 0; // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rr", &idx, &data, &size, &stats) == FAILURE) { +// "rl", &idx, &data, &size, &stats) == FAILURE) { // return; // } +// // ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// result = git_indexer_append(PHP_GIT2_V(_idx, indexer), data, size, stats); +// RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_indexer_commit(idx, stats) -*/ +/* {{{ proto long git_indexer_commit(resource $idx, $stats) + */ PHP_FUNCTION(git_indexer_commit) { - zval *idx; - php_git2_t *_idx; - zval *stats; - php_git2_t *_stats; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_commit not implemented yet"); - return; + int result = 0, error = 0; + zval *idx = NULL, *stats = NULL; + php_git2_t *_idx = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &idx, &stats) == FAILURE) { - return; - } - ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, +// "r", &idx, &stats) == FAILURE) { +// return; +// } +// +// ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); +// result = git_indexer_commit(PHP_GIT2_V(_idx, indexer), stats); +// RETURN_LONG(result); } +/* }}} */ -/* {{{ proto resource git_indexer_hash(idx) -*/ +/* {{{ proto resource git_indexer_hash(resource $idx) + */ PHP_FUNCTION(git_indexer_hash) { - zval *idx; - php_git2_t *_idx; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_hash not implemented yet"); - return; + const git_oid *result = NULL; + zval *idx = NULL; + php_git2_t *_idx = NULL; + char __result[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &idx) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_indexer_hash(PHP_GIT2_V(_idx, indexer)); + git_oid_fmt(__result, result); + RETURN_STRING(__result, 1); } +/* }}} */ -/* {{{ proto void git_indexer_free(idx) -*/ +/* {{{ proto void git_indexer_free(resource $idx) + */ PHP_FUNCTION(git_indexer_free) { - zval *idx; - php_git2_t *_idx; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_free not implemented yet"); - return; + zval *idx = NULL; + php_git2_t *_idx = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &idx) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (GIT2_SHOULD_FREE(_idx)) { + git_indexer_free(PHP_GIT2_V(_idx, indexer)); + GIT2_SHOULD_FREE(_idx) = 0; + }; + zval_ptr_dtor(&idx); } +/* }}} */ diff --git a/indexer.h b/indexer.h index 29106edf68..f159a870dc 100644 --- a/indexer.h +++ b/indexer.h @@ -26,7 +26,8 @@ #ifndef PHP_GIT2_INDEXER_H #define PHP_GIT2_INDEXER_H -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_new, 0, 0, 5) +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_new, 0, 0, 6) + ZEND_ARG_INFO(0, out) ZEND_ARG_INFO(0, path) ZEND_ARG_INFO(0, mode) ZEND_ARG_INFO(0, odb) @@ -54,24 +55,24 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_free, 0, 0, 1) ZEND_ARG_INFO(0, idx) ZEND_END_ARG_INFO() -/* {{{ proto resource git_indexer_new(path, mode, odb, progress_cb, progress_cb_payload) -*/ +/* {{{ proto resource git_indexer_new(string $path, long $mode, resource $odb, $progress_cb, $progress_cb_payload) + */ PHP_FUNCTION(git_indexer_new); -/* {{{ proto long git_indexer_append(idx, data, size, stats) -*/ +/* {{{ proto long git_indexer_append(resource $idx, $data, long $size, $stats) + */ PHP_FUNCTION(git_indexer_append); -/* {{{ proto long git_indexer_commit(idx, stats) -*/ +/* {{{ proto long git_indexer_commit(resource $idx, $stats) + */ PHP_FUNCTION(git_indexer_commit); -/* {{{ proto resource git_indexer_hash(idx) -*/ +/* {{{ proto resource git_indexer_hash(resource $idx) + */ PHP_FUNCTION(git_indexer_hash); -/* {{{ proto void git_indexer_free(idx) -*/ +/* {{{ proto void git_indexer_free(resource $idx) + */ PHP_FUNCTION(git_indexer_free); -#endif \ No newline at end of file +#endif diff --git a/ng.php b/ng.php index 16f469c338..3631c78e96 100644 --- a/ng.php +++ b/ng.php @@ -407,6 +407,7 @@ public function shouldResource(Arg $arg) "git_push", "git_refspec", "git_filter", + "git_indexer", ); } diff --git a/php_git2.h b/php_git2.h index 6442aa763c..4e39017c7a 100644 --- a/php_git2.h +++ b/php_git2.h @@ -125,6 +125,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_SUBMODULE, PHP_GIT2_TYPE_PUSH, PHP_GIT2_TYPE_REFSPEC, + PHP_GIT2_TYPE_INDEXER, }; typedef struct php_git2_t { @@ -177,6 +178,7 @@ typedef struct php_git2_t { git_submodule *submodule; git_push *push; git_refspec *refspec; + git_indexer *indexer; } v; int should_free_v; int resource_id; From 1d20679bfd2028baf64fee845767d5aad9b6643e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:21:17 +0900 Subject: [PATCH 094/136] [status] update code base --- status.c | 148 ++++++++++++++++++++++++++----------------------------- 1 file changed, 70 insertions(+), 78 deletions(-) diff --git a/status.c b/status.c index 3de69a464e..7b68db58f8 100644 --- a/status.c +++ b/status.c @@ -2,106 +2,102 @@ #include "php_git2_priv.h" #include "status.h" -/* {{{ proto long git_status_foreach(repo, callback, payload) -*/ +/* {{{ proto long git_status_foreach(resource $repo, Callable $callback, $payload) + */ PHP_FUNCTION(git_status_foreach) { - zval *repo; - php_git2_t *_repo; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_foreach not implemented yet"); - return; - + int result = 0, error = 0; + zval *repo = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrz", &repo, &callback, &payload) == FAILURE) { + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_status_foreach(PHP_GIT2_V(_repo, repository), , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_status_foreach_ext(repo, opts, callback, payload) -*/ +/* {{{ proto long git_status_foreach_ext(resource $repo, $opts, Callable $callback, $payload) + */ PHP_FUNCTION(git_status_foreach_ext) { - zval *repo; - php_git2_t *_repo; - zval *opts; - php_git2_t *_opts; - zval *callback; - php_git2_t *_callback; - zval *payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_status_foreach_ext not implemented yet"); - return; - + int result = 0, error = 0; + zval *repo = NULL, *opts = NULL, *callback = NULL, *payload = NULL; + php_git2_t *_repo = NULL; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrrz", &repo, &opts, &callback, &payload) == FAILURE) { + "rfz", &repo, &opts, &fci, &fcc, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + //result = git_status_foreach_ext(PHP_GIT2_V(_repo, repository), opts, , cb); + php_git2_cb_free(cb); + RETURN_LONG(result); } +/* }}} */ -/* {{{ proto long git_status_file(resource $repo, string $path) +/* {{{ proto long git_status_file(long $status_flags, resource $repo, string $path) */ PHP_FUNCTION(git_status_file) { - unsigned int status_flags = 0; + int result = 0, path_len = 0, error = 0; + long status_flags = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *path = NULL; - int path_len = 0; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &repo, &path, &path_len) == FAILURE) { + "lrs", &status_flags, &repo, &path, &path_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_status_file(status_flags, PHP_GIT2_V(_repo, repository), path); - if (php_git2_check_error(error, "git_status_file" TSRMLS_CC)) { - RETURN_FALSE; - } - RETURN_LONG(status_flags); + result = git_status_file(status_flags, PHP_GIT2_V(_repo, repository), path); + RETURN_LONG(result); } /* }}} */ - /* {{{ proto resource git_status_list_new(resource $repo, $opts) */ PHP_FUNCTION(git_status_list_new) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_status_list *out = NULL; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *opts = NULL; + zval *repo = NULL, *opts = NULL; int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rz", &repo, &opts) == FAILURE) { + "r", &repo, &opts) == FAILURE) { return; } - - /* TODO(chobie): convert arra to git_status_options */ - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_status_list_new(&out, PHP_GIT2_V(_repo, repository), opts); if (php_git2_check_error(error, "git_status_list_new" TSRMLS_CC)) { RETURN_FALSE; } - - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, status_list) = out; - result->type = PHP_GIT2_TYPE_STATUS_LIST; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_STATUS_LIST, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ @@ -112,12 +108,12 @@ PHP_FUNCTION(git_status_list_entrycount) size_t result = 0; zval *statuslist = NULL; php_git2_t *_statuslist = NULL; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &statuslist) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_status_list_entrycount(PHP_GIT2_V(_statuslist, status_list)); RETURN_LONG(result); @@ -128,16 +124,16 @@ PHP_FUNCTION(git_status_list_entrycount) */ PHP_FUNCTION(git_status_byindex) { - const git_status_entry *result = NULL; + const git_status_entry *result = NULL; zval *statuslist = NULL; php_git2_t *_statuslist = NULL; long idx = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &statuslist, &idx) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_status_byindex(PHP_GIT2_V(_statuslist, status_list), idx); /* TODO(chobie): implement this */ @@ -150,43 +146,39 @@ PHP_FUNCTION(git_status_list_free) { zval *statuslist = NULL; php_git2_t *_statuslist = NULL; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &statuslist) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (_statuslist->should_free_v) { + if (GIT2_SHOULD_FREE(_statuslist)) { git_status_list_free(PHP_GIT2_V(_statuslist, status_list)); + GIT2_SHOULD_FREE(_statuslist) = 0; }; zval_ptr_dtor(&statuslist); } /* }}} */ -/* {{{ proto long git_status_should_ignore(resource $repo, string $path) +/* {{{ proto long git_status_should_ignore(long $ignored, resource $repo, string $path) */ PHP_FUNCTION(git_status_should_ignore) { - int ignored = 0; + int result = 0, path_len = 0, error = 0; + long ignored = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *path = NULL; - int path_len = 0; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &repo, &path, &path_len) == FAILURE) { + "lrs", &ignored, &repo, &path, &path_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_status_should_ignore(&ignored, PHP_GIT2_V(_repo, repository), path); - if (php_git2_check_error(error, "git_status_should_ignore" TSRMLS_CC)) { - RETURN_FALSE; - } - - RETURN_LONG(ignored); + result = git_status_should_ignore(ignored, PHP_GIT2_V(_repo, repository), path); + RETURN_LONG(result); } /* }}} */ From cae14f97be1b68bb028ac20d2bc73e831c36257a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:23:55 +0900 Subject: [PATCH 095/136] [transport] update code base --- transport.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/transport.c b/transport.c index e4589ba132..1bb62c1e89 100644 --- a/transport.c +++ b/transport.c @@ -158,25 +158,32 @@ PHP_FUNCTION(git_transport_local) /* }}} */ -/* {{{ proto resource git_transport_smart(owner, payload) -*/ +/* {{{ proto resource git_transport_smart(resource $owner, $payload) + */ PHP_FUNCTION(git_transport_smart) { - zval *owner; - php_git2_t *_owner; - zval *payload; - php_git2_t *_payload; - - /* TODO(chobie): implement this */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_transport_smart not implemented yet"); - return; + php_git2_t *result = NULL, *_owner = NULL; + git_transport *out = NULL; + zval *owner = NULL, *payload = NULL; + int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &owner, &payload) == FAILURE) { + "r", &owner, &payload) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_owner, php_git2_t*, &owner, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_transport_smart(&out, PHP_GIT2_V(_owner, remote), payload); + if (php_git2_check_error(error, "git_transport_smart" TSRMLS_CC)) { + RETURN_FALSE; + } + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TRANSPORT, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } +/* }}} */ + /* {{{ proto resource git_smart_subtransport_http(resource $owner) */ From b687a5d84955303ba6747817f4f858d2fb08e0ca Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:31:06 +0900 Subject: [PATCH 096/136] [checkout, ignore] update code base --- checkout.c | 37 ++++++++++++++----------------------- ignore.c | 37 +++++++++++++------------------------ 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/checkout.c b/checkout.c index a3ebcd830c..b422147a6a 100644 --- a/checkout.c +++ b/checkout.c @@ -6,11 +6,9 @@ */ PHP_FUNCTION(git_checkout_head) { - int result = 0; - zval *repo = NULL; + zval *opts = NULL, *repo = NULL; php_git2_t *_repo = NULL; - zval *opts = NULL; - int error = 0, shoud_free = 0; + int result = 0, error = 0, shoud_free = 0; git_checkout_opts *options; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -41,15 +39,10 @@ PHP_FUNCTION(git_checkout_head) */ PHP_FUNCTION(git_checkout_index) { - int result = 0; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *index = NULL; - php_git2_t *_index = NULL; - zval *opts = NULL; - int error = 0; + int result = 0, error = 0; + zval *repo = NULL, *index = NULL, *opts = NULL; + php_git2_t *_repo = NULL, *_index = NULL; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &index, &opts) == FAILURE) { return; @@ -62,22 +55,18 @@ PHP_FUNCTION(git_checkout_index) } /* }}} */ + /* {{{ proto long git_checkout_tree(resource $repo, resource $treeish, $opts) */ PHP_FUNCTION(git_checkout_tree) { - int result = 0; - zval *repo = NULL; - php_git2_t *_repo = NULL; - zval *treeish = NULL; - php_git2_t *_treeish = NULL; - zval *opts = NULL; - int error = 0; - git_checkout_opts options = GIT_CHECKOUT_OPTS_INIT; - git_object *__treeish = NULL; + int result = 0, error = 0; + zval *repo = NULL, *treeish = NULL, *opts = NULL; + php_git2_t *_repo = NULL, *_treeish = NULL; + git_checkout_opts options = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r|ra", &repo, &treeish, &opts) == FAILURE) { + "rra", &repo, &treeish, &opts) == FAILURE) { return; } @@ -93,8 +82,10 @@ PHP_FUNCTION(git_checkout_tree) } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_checkout_tree(PHP_GIT2_V(_repo, repository), __treeish, &options); + ZEND_FETCH_RESOURCE(_treeish, php_git2_t*, &treeish, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + result = git_checkout_tree(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_treeish, object), opts); RETURN_LONG(result); } /* }}} */ + diff --git a/ignore.c b/ignore.c index c77e30754b..8af6a75ebe 100644 --- a/ignore.c +++ b/ignore.c @@ -6,70 +6,59 @@ */ PHP_FUNCTION(git_ignore_add_rule) { - int result = 0; + int result = 0, rules_len = 0, error = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *rules = NULL; - int rules_len = 0; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &rules, &rules_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_ignore_add_rule(PHP_GIT2_V(_repo, repository), rules); RETURN_LONG(result); } /* }}} */ - /* {{{ proto long git_ignore_clear_internal_rules(resource $repo) */ PHP_FUNCTION(git_ignore_clear_internal_rules) { - int result = 0; + int result = 0, error = 0; zval *repo = NULL; php_git2_t *_repo = NULL; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_ignore_clear_internal_rules(PHP_GIT2_V(_repo, repository)); RETURN_LONG(result); } /* }}} */ - -/* {{{ proto long git_ignore_path_is_ignored(resource $repo, string $path) +/* {{{ proto long git_ignore_path_is_ignored(long $ignored, resource $repo, string $path) */ PHP_FUNCTION(git_ignore_path_is_ignored) { - int result = 0; + int result = 0, path_len = 0, error = 0; long ignored = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *path = NULL; - int path_len = 0; - int error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &repo, &path, &path_len) == FAILURE) { + "lrs", &ignored, &repo, &path, &path_len) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_ignore_path_is_ignored(&ignored, PHP_GIT2_V(_repo, repository), path); - if (php_git2_check_error(error, "git_ignore_path_is_ignored" TSRMLS_CC)) { - RETURN_FALSE - } - - RETURN_LONG(ignored); + result = git_ignore_path_is_ignored(ignored, PHP_GIT2_V(_repo, repository), path); + RETURN_BOOL(result); } /* }}} */ From 1359d142abdbd56a5f2089a65ce6d6c5687b2971 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:56:30 +0900 Subject: [PATCH 097/136] update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1a302b93c0..21a3ddb811 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ php-git2 is a PHP bindings to the libgit2 linkable C Git library. 0.3.0 Alpha (switching to functions) +https://docs.google.com/spreadsheet/ccc?key=0AjvShWAWqvfHdDRneEtIUF9GRUZMNVVVR1hpdURiUWc&usp=sharing + ## For Contributors ##### Issue first. @@ -49,9 +51,7 @@ if you wanna try to work new file. please use gen.php and generate stubs. as dec (sometimes, this generator might output wrong headers. then just comment out or fix generator) ```` -php gen.php libgit2/include/git2/branch.h 0 > branch.h - -# improved code generator +PRINT_HEADER=1 php ng.php libgit2/include/git2/branch.h > branch.h php ng.php libgit2/include/git2/branch.h > branch.c ```` @@ -86,7 +86,7 @@ document will generate later. please check source code before publish docs. ##### policy -* don't create OOP interface for ease of maintenance. +* don't create OOP interface in extension for ease of maintenance. * follow latest libgit2 api. don't consider BC at this time. ## LICENSE From 80d3cffbef12b8d4fe6ecb0310bc20598a368cea Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 16 Jan 2014 02:59:06 +0900 Subject: [PATCH 098/136] add note for latest branch --- README.md | 7 ++++++- libgit2 | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b970b5e071..3ae801928d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ # PHP-Git2 - libgit2 bindings in PHP -php-git2 is a PHP bindings to the libgit2 linkable C Git library. +php-git2 is a PHP bindings to the libgit2 linkable C Git library. this extension are re-writing php-git as that code too dirty. +# Latest Branch + +v0.3.0 (switching to functions) +https://github.com/libgit2/php-git/tree/functions + # Important Notice php-git changed it's API drastically. this changes doesn't care about compatibility between old one. diff --git a/libgit2 b/libgit2 index eddc1f1ed7..43cb8b3242 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit eddc1f1ed78898a4ca41480045b1d0d5b075e773 +Subproject commit 43cb8b32428b1b29994874349ec22eb5372e152c From 8a59286a2c0bebb42f07ceaf1577f6db0a5eabfe Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 17 Jan 2014 04:32:46 +0900 Subject: [PATCH 099/136] improve codes --- pathspec.c | 3 +-- php_git2.c | 12 ++++++++++++ reflog.c | 2 +- remote.c | 2 -- repository.c | 38 +++++++++++++++++++++----------------- tag.c | 47 +++++++++++++++++------------------------------ 6 files changed, 52 insertions(+), 52 deletions(-) diff --git a/pathspec.c b/pathspec.c index 2d1a5f029e..1ef2309182 100644 --- a/pathspec.c +++ b/pathspec.c @@ -12,14 +12,13 @@ PHP_FUNCTION(git_pathspec_new) git_strarray _pathspec = {0}; int error = 0; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &pathspec) == FAILURE) { return; } php_git2_array_to_strarray(&_pathspec, pathspec TSRMLS_CC); - error = git_pathspec_new(&out, pathspec); + error = git_pathspec_new(&out, &pathspec); if (php_git2_check_error(error, "git_pathspec_new" TSRMLS_CC)) { RETURN_FALSE; } diff --git a/php_git2.c b/php_git2.c index 9c5e1edbb8..8166ae94dd 100644 --- a/php_git2.c +++ b/php_git2.c @@ -318,6 +318,17 @@ PHP_FUNCTION(git_libgit2_capabilities) } +PHP_FUNCTION(git_libgit2_version) +{ + char buf[32] = {0}; + int major, minor, rev; + + git_libgit2_version(&major, &minor, &rev); + snprintf(buf, 32, "%d.%d.%d", major, minor, rev); + + RETURN_STRING(buf, 1); +} + static zend_function_entry php_git2_functions[] = { /* repository */ PHP_FE(git_repository_new, arginfo_git_repository_new) @@ -936,6 +947,7 @@ static zend_function_entry php_git2_functions[] = { /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE(git_libgit2_capabilities, NULL) + PHP_FE(git_libgit2_version, NULL) PHP_FE_END }; diff --git a/reflog.c b/reflog.c index a0554e7f65..a31ab5795d 100644 --- a/reflog.c +++ b/reflog.c @@ -219,7 +219,7 @@ PHP_FUNCTION(git_reflog_entry_id_old) } /* }}} */ -/* {{{ proto resource git_reflog_entry_id_new(resource $entry) +/* {{{ proto string git_reflog_entry_id_new(resource $entry) */ PHP_FUNCTION(git_reflog_entry_id_new) { diff --git a/remote.c b/remote.c index 164657088a..3b70eaeb03 100644 --- a/remote.c +++ b/remote.c @@ -76,8 +76,6 @@ PHP_FUNCTION(git_remote_create_with_fetchspec) } /* }}} */ - - /* {{{ proto resource git_remote_create_inmemory(resource $repo, string $fetch, string $url) */ PHP_FUNCTION(git_remote_create_inmemory) diff --git a/repository.c b/repository.c index 8513cff20c..7647f39a2d 100644 --- a/repository.c +++ b/repository.c @@ -720,33 +720,31 @@ PHP_FUNCTION(git_repository_mergehead_foreach) /* }}} */ -/* {{{ proto resource git_repository_hashfile(repo, path, type, as_path) -*/ +/* {{{ proto string git_repository_hashfile(resource $repo, string $path, long $type, string $as_path) + */ PHP_FUNCTION(git_repository_hashfile) { - zval *repo; - php_git2_t *_repo; - char *path = {0}; - int path_len; - zval *type; - php_git2_t *_type; - char *as_path = {0}; - int as_path_len; - git_oid oid; - int error = 0; - char out[GIT2_OID_HEXSIZE] = {0}; + php_git2_t *result = NULL, *_repo = NULL; + git_oid out = {0}; + zval *repo = NULL; + char *path = NULL, *as_path = NULL, buf[41] = {0}; + int path_len = 0, as_path_len = 0, error = 0; + long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsrs", &repo, &path, &path_len, &type, &as_path, &as_path_len) == FAILURE) { + "rsls", &repo, &path, &path_len, &type, &as_path, &as_path_len) == FAILURE) { return; } + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); error = git_repository_hashfile(&out, PHP_GIT2_V(_repo, repository), path, type, as_path); if (php_git2_check_error(error, "git_repository_hashfile" TSRMLS_CC)) { - RETURN_FALSE + RETURN_FALSE; } - git_oid_fmt(out, &oid); + git_oid_fmt(buf, &out); + RETURN_STRING(buf, 1); } +/* }}} */ /* {{{ proto long git_repository_set_head(repo, refname) */ @@ -769,6 +767,7 @@ PHP_FUNCTION(git_repository_set_head) } RETURN_TRUE; } +/* }}} */ /* {{{ proto long git_repository_set_head_detached(repo, commitish) */ @@ -796,6 +795,7 @@ PHP_FUNCTION(git_repository_set_head_detached) } RETURN_TRUE; } +/* }}} */ /* {{{ proto long git_repository_detach_head(repo) */ @@ -816,6 +816,7 @@ PHP_FUNCTION(git_repository_detach_head) } RETURN_TRUE; } +/* }}} */ /* {{{ proto long git_repository_state(repo) */ @@ -834,6 +835,7 @@ PHP_FUNCTION(git_repository_state) RETURN_LONG(state); } +/* }}} */ /* {{{ proto long git_repository_set_namespace(repo, nmspace) */ @@ -856,6 +858,7 @@ PHP_FUNCTION(git_repository_set_namespace) } RETURN_TRUE; } +/* }}} */ /* {{{ proto long git_repository_is_shallow(repo) */ @@ -872,4 +875,5 @@ PHP_FUNCTION(git_repository_is_shallow) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); is_shallow = git_repository_is_shallow(PHP_GIT2_V(_repo, repository)); RETURN_LONG(is_shallow); -} \ No newline at end of file +} +/* }}} */ \ No newline at end of file diff --git a/tag.c b/tag.c index b2859e0954..1121ece3b8 100644 --- a/tag.c +++ b/tag.c @@ -33,19 +33,16 @@ static int php_git2_tag_foreach_cb(const char *name, git_oid *oid, void *payload return retval; } - /* {{{ proto resource git_tag_lookup(resource $repo, string $id) */ PHP_FUNCTION(git_tag_lookup) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_repo = NULL; git_tag *out = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; char *id = NULL; - int id_len = 0; - git_oid __id; - int error = 0; + int id_len = 0, error = 0; + git_oid __id = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &id, &id_len) == FAILURE) { @@ -60,16 +57,13 @@ PHP_FUNCTION(git_tag_lookup) if (php_git2_check_error(error, "git_tag_lookup" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, tag) = out; - result->type = PHP_GIT2_TYPE_TAG; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TAG, out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ - /* {{{ proto resource git_tag_lookup_prefix(resource $repo, string $id) */ PHP_FUNCTION(git_tag_lookup_prefix) @@ -152,8 +146,7 @@ PHP_FUNCTION(git_tag_owner) { git_repository *result = NULL; zval *tag = NULL; - php_git2_t *_tag = NULL; - php_git2_t *__result = NULL; + php_git2_t *_tag = NULL, *__result = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tag) == FAILURE) { @@ -162,12 +155,10 @@ PHP_FUNCTION(git_tag_owner) ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_tag_owner(PHP_GIT2_V(_tag, tag)); - PHP_GIT2_MAKE_RESOURCE(__result); - PHP_GIT2_V(__result, tag) = tag; - __result->type = PHP_GIT2_TYPE_TAG; - __result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - __result->should_free_v = 0; - ZVAL_RESOURCE(return_value, __result->resource_id); + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_TAG, result, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); } /* }}} */ @@ -433,7 +424,6 @@ PHP_FUNCTION(git_tag_create_lightweight) } /* }}} */ - /* {{{ proto long git_tag_delete(resource $repo, string $tag_name) */ PHP_FUNCTION(git_tag_delete) @@ -546,10 +536,9 @@ PHP_FUNCTION(git_tag_foreach) */ PHP_FUNCTION(git_tag_peel) { - php_git2_t *result = NULL; + php_git2_t *result = NULL, *_tag = NULL; git_object *tag_target_out = NULL; zval *tag = NULL; - php_git2_t *_tag = NULL; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -562,11 +551,9 @@ PHP_FUNCTION(git_tag_peel) if (php_git2_check_error(error, "git_tag_peel" TSRMLS_CC)) { RETURN_FALSE; } - PHP_GIT2_MAKE_RESOURCE(result); - PHP_GIT2_V(result, object) = tag_target_out; - result->type = PHP_GIT2_TYPE_OBJECT; - result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle); - result->should_free_v = 0; - ZVAL_RESOURCE(return_value, result->resource_id); + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, tag_target_out, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); } /* }}} */ From 23e12409b1c416f1632009ea4c477c888e0149f8 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 17 Jan 2014 07:35:02 +0900 Subject: [PATCH 100/136] [diff] add callbacks --- diff.c | 217 ++++++++++++++++++++++++++++++++++------------- diff.h | 4 +- example/diff.php | 12 +++ helper.c | 111 +++++++++++++++++++++++- helper.h | 11 +++ php_git2_priv.h | 13 +++ remote.c | 7 -- 7 files changed, 307 insertions(+), 68 deletions(-) create mode 100644 example/diff.php diff --git a/diff.c b/diff.c index cae870f978..2ef7621a4c 100644 --- a/diff.c +++ b/diff.c @@ -2,6 +2,79 @@ #include "php_git2_priv.h" #include "diff.h" +static int php_git2_git_diff_file_cb( + const git_diff_delta *delta, + float progress, + void *payload) +{ + php_git2_t *result; + zval *param_delta = NULL, *param_progress = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_progress); + ZVAL_DOUBLE(param_progress, progress); + php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); + if (php_git2_call_function_v(&p->callbacks[0].fci, &p->callbacks[0].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_progress, &p->payload)) { + return GIT_EUSER; + } + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + + return retval; +} + +static int php_git2_git_diff_hunk_cb( + const git_diff_delta *delta, + const git_diff_hunk *hunk, + void *payload) +{ + php_git2_t *result; + zval *param_delta = NULL, *param_hunk = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); + php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); + + if (php_git2_call_function_v(&p->callbacks[1].fci, &p->callbacks[1].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_hunk, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + +static int php_git2_git_diff_line_cb( + const git_diff_delta *delta, + const git_diff_hunk *hunk, + const git_diff_line *line, + void *payload) { + php_git2_t *result; + zval *param_delta = NULL, *param_hunk = NULL, *param_line = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); + php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); + php_git2_diff_line_to_array(line, ¶m_line TSRMLS_CC); + + if (php_git2_call_function_v(&p->callbacks[2].fci, &p->callbacks[2].fcc TSRMLS_CC, &retval_ptr, 4, ¶m_delta, ¶m_hunk, ¶m_line, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + /* {{{ proto void git_diff_free(resource $diff) */ PHP_FUNCTION(git_diff_free) @@ -101,7 +174,6 @@ PHP_FUNCTION(git_diff_index_to_workdir) RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_diff)); - } /* }}} */ @@ -112,17 +184,21 @@ PHP_FUNCTION(git_diff_tree_to_workdir) int result = 0, error = 0; git_diff *diff = NULL; zval *repo = NULL, *old_tree = NULL, *opts = NULL; - php_git2_t *_repo = NULL, *_old_tree = NULL; + php_git2_t *_repo = NULL, *_old_tree = NULL, *_result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &repo, &old_tree, &opts) == FAILURE) { + "rra", &repo, &old_tree, &opts) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts); - RETURN_LONG(result); + result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), NULL); + + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ @@ -192,7 +268,6 @@ PHP_FUNCTION(git_diff_find_similar) } /* }}} */ - /* {{{ proto long git_diff_options_init( $options, long $version) */ PHP_FUNCTION(git_diff_options_init) @@ -213,7 +288,6 @@ PHP_FUNCTION(git_diff_options_init) } /* }}} */ - /* {{{ proto long git_diff_num_deltas(resource $diff) */ PHP_FUNCTION(git_diff_num_deltas) @@ -233,7 +307,6 @@ PHP_FUNCTION(git_diff_num_deltas) } /* }}} */ - /* {{{ proto long git_diff_num_deltas_of_type(resource $diff, $type) */ PHP_FUNCTION(git_diff_num_deltas_of_type) @@ -254,13 +327,12 @@ PHP_FUNCTION(git_diff_num_deltas_of_type) } /* }}} */ - /* {{{ proto resource git_diff_get_delta(resource $diff, long $idx) */ PHP_FUNCTION(git_diff_get_delta) { const git_diff_delta *result = NULL; - zval *diff = NULL; + zval *diff = NULL, *_result; php_git2_t *_diff = NULL; long idx = 0; @@ -271,11 +343,11 @@ PHP_FUNCTION(git_diff_get_delta) ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_diff_get_delta(PHP_GIT2_V(_diff, diff), idx); - /* TODO(chobie): implement this */ + php_git2_git_diff_delta_to_array(result, &_result TSRMLS_CC); + RETURN_ZVAL(_result, 0, 1); } /* }}} */ - /* {{{ proto long git_diff_is_sorted_icase(resource $diff) */ PHP_FUNCTION(git_diff_is_sorted_icase) @@ -304,21 +376,28 @@ PHP_FUNCTION(git_diff_foreach) int result = 0, error = 0; zval *diff = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; php_git2_t *_diff = NULL; - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache fcc = empty_fcall_info_cache; - php_git2_cb_t *cb = NULL; + zend_fcall_info file_fci = empty_fcall_info; + zend_fcall_info_cache file_fcc = empty_fcall_info_cache; + zend_fcall_info hunk_fci = empty_fcall_info; + zend_fcall_info_cache hunk_fcc = empty_fcall_info_cache; + zend_fcall_info line_fci = empty_fcall_info; + zend_fcall_info_cache line_fcc = empty_fcall_info_cache; + php_git2_multi_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rfffz", &diff, &fci, &fcc, &fci, &fcc, &fci, &fcc, &payload) == FAILURE) { + "rfffz", &diff, &file_fci, &file_fcc, &hunk_fci, &hunk_fcc, &line_fci, &line_fcc, &payload) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { - RETURN_FALSE; - } - //result = git_diff_foreach(PHP_GIT2_V(_diff, diff), , , , cb); - php_git2_cb_free(cb); + php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3, + &file_fci, &file_fcc, + &hunk_fci, &hunk_fcc, + &line_fci, &line_fcc + ); + + result = git_diff_foreach(PHP_GIT2_V(_diff, diff), php_git2_git_diff_file_cb, php_git2_git_diff_hunk_cb, php_git2_git_diff_line_cb, cb); + php_git2_multi_cb_free(cb); RETURN_LONG(result); } /* }}} */ @@ -327,7 +406,7 @@ PHP_FUNCTION(git_diff_foreach) */ PHP_FUNCTION(git_diff_status_char) { - char *result = NULL; + char result; long status = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -336,7 +415,7 @@ PHP_FUNCTION(git_diff_status_char) } result = git_diff_status_char(status); - RETURN_STRING(result, 1); + RETURN_STRINGL(&result, 1, 1); } /* }}} */ @@ -349,7 +428,7 @@ PHP_FUNCTION(git_diff_print) php_git2_t *_diff = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; - php_git2_cb_t *cb = NULL; + php_git2_multi_cb_t *cb = NULL; long format = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -358,11 +437,11 @@ PHP_FUNCTION(git_diff_print) } ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + if (php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3, &empty_fcall_info, &empty_fcall_info_cache, &empty_fcall_info, &empty_fcall_info_cache, &fci, &fcc)) { RETURN_FALSE; } - //result = git_diff_print(PHP_GIT2_V(_diff, diff), format, , cb); - php_git2_cb_free(cb); + result = git_diff_print(PHP_GIT2_V(_diff, diff), format, php_git2_git_diff_line_cb, cb); + php_git2_multi_cb_free(cb); RETURN_LONG(result); } /* }}} */ @@ -375,23 +454,33 @@ PHP_FUNCTION(git_diff_blobs) zval *old_blob = NULL, *new_blob = NULL, *options = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; php_git2_t *_old_blob = NULL, *_new_blob = NULL; char *old_as_path = NULL, *new_as_path = NULL; - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache fcc = empty_fcall_info_cache; + zend_fcall_info file_fci = empty_fcall_info; + zend_fcall_info_cache file_fcc = empty_fcall_info_cache; + zend_fcall_info hunk_fci = empty_fcall_info; + zend_fcall_info_cache hunk_fcc = empty_fcall_info_cache; + zend_fcall_info line_fci = empty_fcall_info; + zend_fcall_info_cache line_fcc = empty_fcall_info_cache; php_git2_cb_t *cb = NULL; -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rsrsfffz", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &options, &fci, &fcc, &fci, &fcc, &fci, &fcc, &payload) == FAILURE) { -// return; -// } -// -// ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -// ZEND_FETCH_RESOURCE(_new_blob, php_git2_t*, &new_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -// if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { -// RETURN_FALSE; -// } -// result = git_diff_blobs(PHP_GIT2_V(_old_blob, blob), old_as_path, PHP_GIT2_V(_new_blob, blob), new_as_path, options, , , , cb); -// php_git2_cb_free(cb); -// RETURN_LONG(result); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsrsafffz", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &options, + &file_fci, &file_fcc, &hunk_fci, &hunk_fcc, &line_fci, &line_fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + ZEND_FETCH_RESOURCE(_new_blob, php_git2_t*, &new_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3, + &file_fci, &file_fcc, + &hunk_fci, &hunk_fcc, + &line_fci, &line_fcc + ); + result = git_diff_blobs( + PHP_GIT2_V(_old_blob, blob), old_as_path, + PHP_GIT2_V(_new_blob, blob), new_as_path, NULL, + php_git2_git_diff_file_cb, php_git2_git_diff_hunk_cb, php_git2_git_diff_line_cb, cb); + php_git2_multi_cb_free(cb); + RETURN_LONG(result); } /* }}} */ @@ -403,22 +492,34 @@ PHP_FUNCTION(git_diff_blob_to_buffer) zval *old_blob = NULL, *options = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; php_git2_t *_old_blob = NULL; char *old_as_path = NULL, *buffer = NULL, *buffer_as_path = NULL; -// long buffer_len = 0; - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache fcc = empty_fcall_info_cache; - php_git2_cb_t *cb = NULL; + zend_fcall_info file_fci = empty_fcall_info; + zend_fcall_info_cache file_fcc = empty_fcall_info_cache; + zend_fcall_info hunk_fci = empty_fcall_info; + zend_fcall_info_cache hunk_fcc = empty_fcall_info_cache; + zend_fcall_info line_fci = empty_fcall_info; + zend_fcall_info_cache line_fcc = empty_fcall_info_cache; + php_git2_multi_cb_t *cb = NULL; + git_diff_options opts = {0}; -// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, -// "rsslsfffz", &old_blob, &old_as_path, &old_as_path_len, &buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &options, &fci, &fcc, &fci, &fcc, &fci, &fcc, &payload) == FAILURE) { -// return; -// } -// -// ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); -// if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { -// RETURN_FALSE; -// } -// result = git_diff_blob_to_buffer(PHP_GIT2_V(_old_blob, blob), old_as_path, buffer, buffer_len, buffer_as_path, options, , , , cb); -// php_git2_cb_free(cb); -// RETURN_LONG(result); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "rsslsafffz", &old_blob, &old_as_path, &old_as_path_len, + &buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &options, + &file_fci, &file_fcc, &hunk_fci, &hunk_fcc, &line_fci, &line_fcc, &payload) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3, + &file_fci, &file_fcc, + &hunk_fci, &hunk_fcc, + &line_fci, &line_fcc + ); + result = git_diff_blob_to_buffer( + PHP_GIT2_V(_old_blob, blob), old_as_path, + buffer, buffer_len, buffer_as_path, + &opts, + php_git2_git_diff_file_cb, php_git2_git_diff_hunk_cb, php_git2_git_diff_line_cb, cb); + php_git2_multi_cb_free(cb); + RETURN_LONG(result); } /* }}} */ diff --git a/diff.h b/diff.h index 699e83ac64..ca5f8218a4 100644 --- a/diff.h +++ b/diff.h @@ -100,7 +100,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_foreach, 0, 0, 5) ZEND_ARG_INFO(0, file_cb) ZEND_ARG_INFO(0, hunk_cb) ZEND_ARG_INFO(0, line_cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_status_char, 0, 0, 1) @@ -111,7 +111,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_print, 0, 0, 4) ZEND_ARG_INFO(0, diff) ZEND_ARG_INFO(0, format) ZEND_ARG_INFO(0, print_cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_blobs, 0, 0, 9) diff --git a/example/diff.php b/example/diff.php new file mode 100644 index 0000000000..5050c5d561 --- /dev/null +++ b/example/diff.php @@ -0,0 +1,12 @@ +payload = payload; + cb->num_callbacks = num_callbacks; + GIT2_TSRMLS_SET2(cb, TSRMLS_C); + + cb->callbacks = emalloc(sizeof(php_git2_fcall_t) * num_callbacks); + memset(cb->callbacks, '\0', sizeof(php_git2_fcall_t) * num_callbacks); + va_start(ap, num_callbacks * 2); + for (i = 0; i < num_callbacks; i++) { + memcpy(&cb->callbacks[i].fci, va_arg(ap, zend_fcall_info*), sizeof(zend_fcall_info)); + memcpy(&cb->callbacks[i].fcc, va_arg(ap, zend_fcall_info_cache*), sizeof(zend_fcall_info_cache)); + } + va_end(ap); + + *out = cb; + return 0; +} + +void php_git2_multi_cb_free(php_git2_multi_cb_t *target) +{ + efree(target->callbacks); + efree(target); +} + +void php_git2_diff_line_to_array(git_diff_line *line, zval **out TSRMLS_DC) +{ + zval *result; + + MAKE_STD_ZVAL(result); + array_init(result); + add_assoc_stringl_ex(result, ZEND_STRS("origin"), &line->origin, 1, 1); + add_assoc_long_ex(result, ZEND_STRS("old_lineno"), line->old_lineno); + add_assoc_long_ex(result, ZEND_STRS("new_lineno"), line->new_lineno); + add_assoc_long_ex(result, ZEND_STRS("num_lines"), line->num_lines); + add_assoc_long_ex(result, ZEND_STRS("content_len"), line->content_len); + add_assoc_long_ex(result, ZEND_STRS("content_offset"), line->content_offset); + add_assoc_stringl_ex(result, ZEND_STRS("content"), line->content, line->content_len, 1); + + *out = result; +} + +void php_git2_diff_hunk_to_array(git_diff_hunk *hunk, zval **out TSRMLS_DC) +{ + zval *result; + + MAKE_STD_ZVAL(result); + if (hunk == NULL) { + ZVAL_NULL(result); + } else { + array_init(result); + add_assoc_long_ex(result, ZEND_STRS("old_start"), hunk->old_start); + add_assoc_long_ex(result, ZEND_STRS("old_lines"), hunk->old_lines); + add_assoc_long_ex(result, ZEND_STRS("new_start"), hunk->new_start); + add_assoc_long_ex(result, ZEND_STRS("new_lines"), hunk->new_lines); + add_assoc_stringl_ex(result, ZEND_STRS("header"), hunk->header, 128, 1); + } + + *out = result; +} + +void php_git2_diff_file_to_array(git_diff_file *file, zval **out TSRMLS_DC) +{ + zval *result; + char buf[41] = {0}; + + MAKE_STD_ZVAL(result); + array_init(result); + git_oid_fmt(buf, &file->oid); + + add_assoc_string_ex(result, ZEND_STRS("oid"), buf, 1); + add_assoc_string_ex(result, ZEND_STRS("path"), file->path, 1); + add_assoc_long_ex(result, ZEND_STRS("size"), file->size); + add_assoc_long_ex(result, ZEND_STRS("flags"), file->flags); + add_assoc_long_ex(result, ZEND_STRS("mode"), file->mode); + + *out = result; +} + +void php_git2_diff_delta_to_array(git_diff_delta *delta, zval **out TSRMLS_DC) +{ + zval *result, *old, *new; + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("status"), delta->status); + add_assoc_long_ex(result, ZEND_STRS("flags"), delta->flags); + add_assoc_long_ex(result, ZEND_STRS("similarity"), delta->similarity); + add_assoc_long_ex(result, ZEND_STRS("nfiles"), delta->nfiles); + + php_git2_diff_file_to_array(&delta->old_file, &old TSRMLS_CC); + php_git2_diff_file_to_array(&delta->new_file, &new TSRMLS_CC); + + add_assoc_zval_ex(result, ZEND_STRS("old_file"), old); + add_assoc_zval_ex(result, ZEND_STRS("new_file"), new); + + *out = result; +} diff --git a/helper.h b/helper.h index 5c9cfbda36..447c7d8d2f 100644 --- a/helper.h +++ b/helper.h @@ -59,4 +59,15 @@ void php_git_git_checkout_opts_free(git_checkout_opts *target TSRMLS_DC); int php_git2_array_to_git_checkout_opts(git_checkout_opts **out, zval *array TSRMLS_DC); +int php_git2_multi_cb_init(php_git2_multi_cb_t **out, void *payload TSRMLS_DC, int num_callbacks, ...); + +void php_git2_multi_cb_free(php_git2_multi_cb_t *target); + +void php_git2_diff_line_to_array(git_diff_line *line, zval **out TSRMLS_DC); + +void php_git2_diff_hunk_to_array(git_diff_hunk *hunk, zval **out TSRMLS_DC); + +void php_git2_diff_file_to_array(git_diff_file *file, zval **out TSRMLS_DC); + +void php_git2_diff_delta_to_array(git_diff_delta *delta, zval **out TSRMLS_DC); #endif \ No newline at end of file diff --git a/php_git2_priv.h b/php_git2_priv.h index d105a8e2e1..536243879c 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -80,6 +80,19 @@ typedef struct php_git2_cb_t { GIT2_TSRMLS_DECL } php_git2_cb_t; +typedef struct php_git2_fcall_t { + zend_fcall_info fci; + zend_fcall_info_cache fcc; + zval *value; +} php_git2_fcall_t; + +typedef struct php_git2_multi_cb_t { + int num_callbacks; + php_git2_fcall_t *callbacks; + zval *payload; + GIT2_TSRMLS_DECL +} php_git2_multi_cb_t; + int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC); #include "helper.h" diff --git a/remote.c b/remote.c index 3b70eaeb03..9145cf7405 100644 --- a/remote.c +++ b/remote.c @@ -806,13 +806,6 @@ PHP_FUNCTION(git_remote_set_transport) } /* }}} */ - -typedef struct php_git2_fcall_t { - zend_fcall_info fci; - zend_fcall_info_cache fcc; - zval *value; -} php_git2_fcall_t; - typedef struct php_git2_remote_cb_t { php_git2_fcall_t callbacks[4]; zval *payload; From b474be8a3f01ad27f24bdbd54b560040ba66aa4d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 17 Jan 2014 08:45:10 +0900 Subject: [PATCH 101/136] [diff] add diff_options interchange functions --- attr.h | 2 +- cred.h | 2 +- diff.c | 112 +++++++++++++++++++++++++++++++++++++++++++++----- diff.h | 4 +- filter.h | 2 +- g_config.h | 2 +- helper.c | 8 ++++ index.h | 6 +-- note.h | 2 +- odb.h | 2 +- packbuilder.h | 2 +- patch.h | 2 +- reference.h | 2 +- status.h | 4 +- submodule.h | 2 +- tag.h | 2 +- transport.h | 6 +-- 17 files changed, 130 insertions(+), 32 deletions(-) diff --git a/attr.h b/attr.h index 3faec01df9..946906f974 100644 --- a/attr.h +++ b/attr.h @@ -50,7 +50,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_foreach, 0, 0, 5) ZEND_ARG_INFO(0, flags) ZEND_ARG_INFO(0, path) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_attr_cache_flush, 0, 0, 1) diff --git a/cred.h b/cred.h index 657ffc3d05..d21c744600 100644 --- a/cred.h +++ b/cred.h @@ -57,7 +57,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_cred_userpass, 0, 0, 4) ZEND_ARG_INFO(0, url) ZEND_ARG_INFO(0, user_from_url) ZEND_ARG_INFO(0, allowed_types) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() /* {{{ proto long git_cred_has_username(cred) diff --git a/diff.c b/diff.c index 2ef7621a4c..0a846da71e 100644 --- a/diff.c +++ b/diff.c @@ -2,6 +2,79 @@ #include "php_git2_priv.h" #include "diff.h" + +static void php_git2_array_to_git_diff_options(git_diff_options *options, zval *array TSRMLS_DC) +{ + git_diff_options_init(options, GIT_DIFF_OPTIONS_VERSION); + + options->version = php_git2_read_arrval_long(array, ZEND_STRS("version") TSRMLS_CC); + options->flags = php_git2_read_arrval_long(array, ZEND_STRS("flags") TSRMLS_CC); + options->ignore_submodules = php_git2_read_arrval_long(array, ZEND_STRS("ignore_submodules") TSRMLS_CC); + + php_git2_array_to_strarray(&options->pathspec, php_git2_read_arrval(array, ZEND_STRS("pathspec") TSRMLS_CC) TSRMLS_CC); + // TODO(chobie): support notify cb + + + options->context_lines = php_git2_read_arrval_long(array, ZEND_STRS("context_lines") TSRMLS_CC); + options->interhunk_lines = php_git2_read_arrval_long(array, ZEND_STRS("interhunk_lines") TSRMLS_CC); + options->oid_abbrev = php_git2_read_arrval_long(array, ZEND_STRS("oid_abbrev") TSRMLS_CC); + options->max_size = php_git2_read_arrval_long(array, ZEND_STRS("max_size") TSRMLS_CC); + options->old_prefix = php_git2_read_arrval_string(array, ZEND_STRS("old_prefix") TSRMLS_CC); + options->new_prefix = php_git2_read_arrval_string(array, ZEND_STRS("new_prefix") TSRMLS_CC); +} + +static void php_git2_git_diff_options_free(git_diff_options *options) +{ + if (options->pathspec.count > 0) { + efree(options->pathspec.strings); + } +} + +static void php_git2_git_diff_options_to_array(git_diff_options *options, zval **out TSRMLS_DC) +{ + zval *result, *pathspec; + + MAKE_STD_ZVAL(result); + array_init(result); + add_assoc_long_ex(result, ZEND_STRS("version"), options->version); + add_assoc_long_ex(result, ZEND_STRS("flags"), options->flags); + add_assoc_long_ex(result, ZEND_STRS("ignore_submodules"), options->ignore_submodules); + + MAKE_STD_ZVAL(pathspec); + array_init(pathspec); + if (options->pathspec.count > 0) { + } else { + add_assoc_zval_ex(result, ZEND_STRS("pathspec"), pathspec); + } + + if (options->notify_cb) { + } else { + add_assoc_null_ex(result, ZEND_STRS("notify_cb")); + } + + add_assoc_long_ex(result, ZEND_STRS("context_lines"), options->context_lines); + add_assoc_long_ex(result, ZEND_STRS("interhunk_lines"), options->interhunk_lines); + add_assoc_long_ex(result, ZEND_STRS("oid_abbrev"), options->oid_abbrev); + add_assoc_long_ex(result, ZEND_STRS("max_size"), options->max_size); + if (options->notify_payload) { + } else { + add_assoc_null_ex(result, ZEND_STRS("notify_payload")); + } + if (options->old_prefix) { + add_assoc_string_ex(result, ZEND_STRS("old_prefix"), options->old_prefix, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("old_prefix")); + } + if (options->new_prefix) { + add_assoc_string_ex(result, ZEND_STRS("new_prefix"), options->new_prefix, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("new_prefix")); + } + + *out = result; +} + + static int php_git2_git_diff_file_cb( const git_diff_delta *delta, float progress, @@ -110,8 +183,8 @@ PHP_FUNCTION(git_diff_tree_to_tree) php_git2_t *_new_tree = NULL; zval *opts = NULL; int error = 0; + git_diff_options options = {0}; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrra", &repo, &old_tree, &new_tree, &opts) == FAILURE) { return; @@ -120,7 +193,9 @@ PHP_FUNCTION(git_diff_tree_to_tree) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_new_tree, php_git2_t*, &new_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); result = git_diff_tree_to_tree(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), PHP_GIT2_V(_new_tree, tree), opts); + php_git2_git_diff_options_free(&options); RETURN_LONG(result); } /* }}} */ @@ -134,8 +209,8 @@ PHP_FUNCTION(git_diff_tree_to_index) git_diff *diff = NULL; zval *repo = NULL, *old_tree = NULL, *index = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_old_tree = NULL, *_index = NULL, *_diff = NULL; + git_diff_options options = {0}; - /* TODO(chobie): convert options */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrra", &repo, &old_tree, &index, &opts) == FAILURE) { return; @@ -144,7 +219,9 @@ PHP_FUNCTION(git_diff_tree_to_index) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); result = git_diff_tree_to_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), PHP_GIT2_V(_index, index), opts); + php_git2_git_diff_options_free(&options); if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { RETURN_FALSE; } @@ -161,6 +238,7 @@ PHP_FUNCTION(git_diff_index_to_workdir) git_diff *diff = NULL; zval *repo = NULL, *index = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_index = NULL, *_diff = NULL; + git_diff_options options = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &index, &opts) == FAILURE) { @@ -169,7 +247,9 @@ PHP_FUNCTION(git_diff_index_to_workdir) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); result = git_diff_index_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_index, index), opts); + php_git2_git_diff_options_free(&options); if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { RETURN_FALSE; } @@ -185,6 +265,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir) git_diff *diff = NULL; zval *repo = NULL, *old_tree = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_old_tree = NULL, *_result; + git_diff_options options = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &old_tree, &opts) == FAILURE) { @@ -193,7 +274,9 @@ PHP_FUNCTION(git_diff_tree_to_workdir) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), NULL); + php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); + result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), &options); + php_git2_git_diff_options_free(&options); if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { RETURN_FALSE; @@ -210,6 +293,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) git_diff *diff = NULL; zval *repo = NULL, *old_tree = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_old_tree = NULL, *_diff = NULL; + git_diff_options options = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &old_tree, &opts) == FAILURE) { @@ -218,7 +302,9 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); result = git_diff_tree_to_workdir_with_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts); + php_git2_git_diff_options_free(&options); if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { RETURN_FALSE; } @@ -255,6 +341,7 @@ PHP_FUNCTION(git_diff_find_similar) php_git2_t *_diff = NULL; zval *options = NULL; int error = 0; + git_diff_options _options = {0}; /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -263,28 +350,31 @@ PHP_FUNCTION(git_diff_find_similar) } ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_diff_find_similar(PHP_GIT2_V(_diff, diff), options); + php_git2_array_to_git_diff_options(&_options, options TSRMLS_CC); + result = git_diff_find_similar(PHP_GIT2_V(_diff, diff), &_options); + php_git2_git_diff_options_free(&_options); RETURN_LONG(result); } /* }}} */ -/* {{{ proto long git_diff_options_init( $options, long $version) +/* {{{ proto long git_diff_options_init(long $version) */ PHP_FUNCTION(git_diff_options_init) { int result = 0; - zval *options = NULL; - long version = 0; + git_diff_options options = {0}; + long version = GIT_DIFF_OPTIONS_VERSION; + zval *out; int error = 0; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "al", &options, &version) == FAILURE) { + "|l", &version) == FAILURE) { return; } - result = git_diff_options_init(options, version); - RETURN_LONG(result); + result = git_diff_options_init(&options, version); + php_git2_git_diff_options_to_array(&options, &out TSRMLS_CC); + RETURN_ZVAL(out, 0, 1); } /* }}} */ diff --git a/diff.h b/diff.h index ca5f8218a4..2f3b99c872 100644 --- a/diff.h +++ b/diff.h @@ -123,7 +123,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_blobs, 0, 0, 9) ZEND_ARG_INFO(0, file_cb) ZEND_ARG_INFO(0, hunk_cb) ZEND_ARG_INFO(0, line_cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_blob_to_buffer, 0, 0, 10) @@ -136,7 +136,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_diff_blob_to_buffer, 0, 0, 10) ZEND_ARG_INFO(0, file_cb) ZEND_ARG_INFO(0, hunk_cb) ZEND_ARG_INFO(0, line_cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() /* {{{ proto void git_diff_free(diff) diff --git a/filter.h b/filter.h index ae02e0ddb5..b5a328b35c 100644 --- a/filter.h +++ b/filter.h @@ -66,7 +66,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_push, 0, 0, 3) ZEND_ARG_INFO(0, fl) ZEND_ARG_INFO(0, filter) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_length, 0, 0, 1) diff --git a/g_config.h b/g_config.h index 80313a7f21..c4874a8ecc 100644 --- a/g_config.h +++ b/g_config.h @@ -101,7 +101,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_get_multivar_foreach, 0, 0, 5) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, regexp) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_multivar_iterator_new, 0, 0, 4) diff --git a/helper.c b/helper.c index c185b4134f..14e24ade4d 100644 --- a/helper.c +++ b/helper.c @@ -132,6 +132,7 @@ void php_git2_strarray_to_array(git_strarray *array, zval **out TSRMLS_DC) MAKE_STD_ZVAL(result); array_init(result); + for (i = 0; i < array->count; i++) { add_next_index_string(result, array->strings[i], 1); } @@ -212,6 +213,13 @@ void php_git2_array_to_strarray(git_strarray *out, zval *array TSRMLS_DC) HashPosition pos; zval **value; + if (Z_TYPE_P(array) != IS_ARRAY){ + return; + } + if (zend_hash_num_elements(Z_ARRVAL_P(array)) == 0) { + return; + } + elements = zend_hash_num_elements(Z_ARRVAL_P(array)); out->strings = (char**)emalloc(sizeof(char*) * elements); out->count = elements; diff --git a/index.h b/index.h index 56bce30f54..80f1ea6000 100644 --- a/index.h +++ b/index.h @@ -103,21 +103,21 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_add_all, 0, 0, 5) ZEND_ARG_INFO(0, pathspec) ZEND_ARG_INFO(0, flags) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_remove_all, 0, 0, 4) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, pathspec) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_update_all, 0, 0, 4) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, pathspec) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_find, 0, 0, 3) diff --git a/note.h b/note.h index 6efc2a5daa..51de3a2a82 100644 --- a/note.h +++ b/note.h @@ -85,7 +85,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_note_foreach, 0, 0, 4) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, notes_ref) ZEND_ARG_INFO(0, note_cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() /* {{{ proto resource git_note_iterator_new(repo, notes_ref) diff --git a/odb.h b/odb.h index c58fbac008..cadf753809 100644 --- a/odb.h +++ b/odb.h @@ -71,7 +71,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_foreach, 0, 0, 3) ZEND_ARG_INFO(0, db) ZEND_ARG_INFO(0, cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_write, 0, 0, 4) diff --git a/packbuilder.h b/packbuilder.h index 3337b9e788..7e53799120 100644 --- a/packbuilder.h +++ b/packbuilder.h @@ -65,7 +65,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_foreach, 0, 0, 3) ZEND_ARG_INFO(0, pb) ZEND_ARG_INFO(0, cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_object_count, 0, 0, 1) diff --git a/patch.h b/patch.h index 0be24e9138..2e666d9d22 100644 --- a/patch.h +++ b/patch.h @@ -94,7 +94,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_print, 0, 0, 3) ZEND_ARG_INFO(0, patch) ZEND_ARG_INFO(0, print_cb) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_patch_to_str, 0, 0, 1) diff --git a/reference.h b/reference.h index 70f0a12f4c..086fc43d01 100644 --- a/reference.h +++ b/reference.h @@ -154,7 +154,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_foreach_glob, 0, 0, 4) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, glob) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_has_log, 0, 0, 1) diff --git a/status.h b/status.h index d2a7f9f2c7..bc5e8274b5 100644 --- a/status.h +++ b/status.h @@ -29,14 +29,14 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_foreach, 0, 0, 3) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_foreach_ext, 0, 0, 4) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, opts) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_status_file, 0, 0, 3) diff --git a/submodule.h b/submodule.h index ca48b7810f..8459e42c18 100644 --- a/submodule.h +++ b/submodule.h @@ -35,7 +35,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_foreach, 0, 0, 5) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, sm) ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_add_setup, 0, 0, 4) diff --git a/tag.h b/tag.h index 0b6d4a742c..015502fcce 100644 --- a/tag.h +++ b/tag.h @@ -122,7 +122,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_foreach, 0, 0, 3) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_peel, 0, 0, 1) diff --git a/transport.h b/transport.h index d297adbf23..075210dbcc 100644 --- a/transport.h +++ b/transport.h @@ -45,17 +45,17 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_dummy, 0, 0, 2) ZEND_ARG_INFO(0, owner) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_local, 0, 0, 2) ZEND_ARG_INFO(0, owner) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_transport_smart, 0, 0, 2) ZEND_ARG_INFO(0, owner) - ZEND_ARG_INFO(0, payload) + ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_smart_subtransport_http, 0, 0, 1) From d93e25ea625beca9859696b64c52a9dc568278b7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 17 Jan 2014 15:09:06 +0900 Subject: [PATCH 102/136] [blame] implement functions --- blame.c | 134 +++++++++++++++++++++++++++++++++++++++++++--- blame.h | 7 +++ blob.c | 2 +- diff.c | 3 +- example/blame.php | 25 +++++++++ helper.c | 12 ++++- php_git2.c | 10 ++++ 7 files changed, 181 insertions(+), 12 deletions(-) create mode 100644 example/blame.php diff --git a/blame.c b/blame.c index fee8f31a50..87035a6558 100644 --- a/blame.c +++ b/blame.c @@ -2,6 +2,105 @@ #include "php_git2_priv.h" #include "blame.h" +static void php_git2_array_to_git_blame_options(git_blame_options *options, zval *array TSRMLS_DC) +{ + zval *tmp; + + options->version = php_git2_read_arrval_long(array, ZEND_STRS("version") TSRMLS_CC); + options->flags = php_git2_read_arrval_long(array, ZEND_STRS("flags") TSRMLS_CC); + options->min_match_characters = php_git2_read_arrval_long(array, ZEND_STRS("min_match_characters") TSRMLS_CC); + tmp = php_git2_read_arrval(array, ZEND_STRS("newest_commit") TSRMLS_CC); + if (Z_TYPE_P(tmp) != NULL) { + if (Z_TYPE_P(tmp) != IS_STRING) { + convert_to_string(tmp); + } + if (git_oid_fromstrn(&options->newest_commit, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)) != GIT_OK) { + return; + } + } + + tmp = php_git2_read_arrval(array, ZEND_STRS("oldest_commit") TSRMLS_CC); + if (Z_TYPE_P(tmp) != NULL) { + if (Z_TYPE_P(tmp) != IS_STRING) { + convert_to_string(tmp); + } + if (git_oid_fromstrn(&options->newest_commit, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)) != GIT_OK) { + return; + } + } + + options->min_line = php_git2_read_arrval_long(array, ZEND_STRS("min_line") TSRMLS_CC); + options->max_line = php_git2_read_arrval_long(array, ZEND_STRS("max_line") TSRMLS_CC); + +} + +static void php_git2_git_blame_options_to_array(git_blame_options *options, zval **out TSRMLS_DC) +{ + zval *result = NULL; + char buf[41] = {0}; + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("version"), options->version); + add_assoc_long_ex(result, ZEND_STRS("flags"), options->flags); + add_assoc_long_ex(result, ZEND_STRS("min_match_characters"), options->min_match_characters); + + if (git_oid_iszero(&options->newest_commit) != 1) { + git_oid_fmt(buf, &options->newest_commit); + add_assoc_string_ex(result, ZEND_STRS("newest_commit"), out, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("newest_commit")); + } + + if (git_oid_iszero(&options->oldest_commit) != 1) { + git_oid_fmt(buf, &options->oldest_commit); + add_assoc_string_ex(result, ZEND_STRS("oldest_commit"), out, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("oldest_commit")); + } + + add_assoc_long_ex(result, ZEND_STRS("min_line"), options->min_line); + add_assoc_long_ex(result, ZEND_STRS("max_line"), options->max_line); + *out = result; +} + +static void php_git2_git_blame_hunk_to_array(git_blame_hunk *hunk, zval **out TSRMLS_DC) +{ + zval *result = NULL, *final = NULL, *orig = NULL; + char buf[41] = {0}; + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("lines_in_hunk"), hunk->lines_in_hunk); + + git_oid_fmt(buf, &hunk->final_commit_id); + add_assoc_string_ex(result, ZEND_STRS("final_commit_id"), buf, 1); + + php_git2_signature_to_array(hunk->final_signature, &final TSRMLS_CC); + add_assoc_zval_ex(result, ZEND_STRS("final_signature"), final); + + add_assoc_long_ex(result, ZEND_STRS("final_start_line_number"), hunk->final_start_line_number); + + git_oid_fmt(buf, &hunk->orig_commit_id); + add_assoc_string_ex(result, ZEND_STRS("orig_commit_id"), buf, 1); + add_assoc_string_ex(result, ZEND_STRS("orig_path"), hunk->orig_path, 1); + + add_assoc_long_ex(result, ZEND_STRS("orig_start_line_number"), hunk->orig_start_line_number); + if (hunk->orig_signature) { + php_git2_signature_to_array(hunk->orig_signature, &orig TSRMLS_CC); + } else { + MAKE_STD_ZVAL(orig); + ZVAL_NULL(orig); + } + add_assoc_zval_ex(result, ZEND_STRS("orig_signature"), orig); + + add_assoc_stringl_ex(result, ZEND_STRS("boundary"), &hunk->boundary, 1, 1); + + *out = result; +} + /* {{{ proto long git_blame_get_hunk_count(resource $blame) */ PHP_FUNCTION(git_blame_get_hunk_count) @@ -26,7 +125,7 @@ PHP_FUNCTION(git_blame_get_hunk_count) PHP_FUNCTION(git_blame_get_hunk_byindex) { const git_blame_hunk *result = NULL; - zval *blame = NULL; + zval *blame = NULL, *array = NULL; php_git2_t *_blame = NULL; long index = 0; @@ -37,7 +136,11 @@ PHP_FUNCTION(git_blame_get_hunk_byindex) ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_blame_get_hunk_byindex(PHP_GIT2_V(_blame, blame), index); - /* TODO(chobie): implement this */ + if (result == NULL) { + RETURN_FALSE; + } + php_git2_git_blame_hunk_to_array(result, &array TSRMLS_CC); + RETURN_ZVAL(array, 0, 1); } /* }}} */ @@ -46,7 +149,7 @@ PHP_FUNCTION(git_blame_get_hunk_byindex) PHP_FUNCTION(git_blame_get_hunk_byline) { const git_blame_hunk *result = NULL; - zval *blame = NULL; + zval *blame = NULL, *array = NULL; php_git2_t *_blame = NULL; long lineno = 0; @@ -57,7 +160,11 @@ PHP_FUNCTION(git_blame_get_hunk_byline) ZEND_FETCH_RESOURCE(_blame, php_git2_t*, &blame, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_blame_get_hunk_byline(PHP_GIT2_V(_blame, blame), lineno); - /* TODO(chobie): implement this */ + if (result == NULL) { + RETURN_FALSE; + } + php_git2_git_blame_hunk_to_array(result, &array TSRMLS_CC); + RETURN_ZVAL(array, 0, 1); } /* }}} */ @@ -68,16 +175,18 @@ PHP_FUNCTION(git_blame_file) php_git2_t *result = NULL, *_repo = NULL; git_blame *out = NULL; zval *repo = NULL, *options = NULL; + git_blame_options opts = GIT_BLAME_OPTIONS_INIT; char *path = NULL; int path_len = 0, error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &repo, &path, &path_len, &options) == FAILURE) { + "rsa", &repo, &path, &path_len, &options) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_blame_file(&out, PHP_GIT2_V(_repo, repository), path, options); + php_git2_array_to_git_blame_options(&opts, options TSRMLS_CC); + error = git_blame_file(&out, PHP_GIT2_V(_repo, repository), path, &opts); if (php_git2_check_error(error, "git_blame_file" TSRMLS_CC)) { RETURN_FALSE; } @@ -136,3 +245,14 @@ PHP_FUNCTION(git_blame_free) } /* }}} */ +/* {{{ proto void git_blame_options_new() + */ +PHP_FUNCTION(git_blame_options_new) +{ + zval *result; + git_blame_options options = GIT_BLAME_OPTIONS_INIT; + + php_git2_git_blame_options_to_array(&options, &result TSRMLS_CC); + RETURN_ZVAL(result, 0, 1); +} +/* }}} */ diff --git a/blame.h b/blame.h index 19a1ef7cff..44fd4761b5 100644 --- a/blame.h +++ b/blame.h @@ -56,6 +56,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_free, 0, 0, 1) ZEND_ARG_INFO(0, blame) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blame_options_new, 0, 0, 0) +ZEND_END_ARG_INFO() + /* {{{ proto resource git_blame_get_hunk_count(blame) */ PHP_FUNCTION(git_blame_get_hunk_count); @@ -80,4 +83,8 @@ PHP_FUNCTION(git_blame_buffer); */ PHP_FUNCTION(git_blame_free); +/* {{{ proto void git_blame_options_new() + */ +PHP_FUNCTION(git_blame_options_new); + #endif \ No newline at end of file diff --git a/blob.c b/blob.c index 21e057ba49..0eb5d35a15 100644 --- a/blob.c +++ b/blob.c @@ -232,7 +232,7 @@ PHP_FUNCTION(git_blob_lookup) RETURN_FALSE; } result = git_blob_lookup(&blob, PHP_GIT2_V(_repo, repository), &__id); - if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_BLOB, result, 0 TSRMLS_CC)) { + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_BLOB, blob, 0 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); diff --git a/diff.c b/diff.c index 0a846da71e..21c80f6df7 100644 --- a/diff.c +++ b/diff.c @@ -14,7 +14,7 @@ static void php_git2_array_to_git_diff_options(git_diff_options *options, zval * php_git2_array_to_strarray(&options->pathspec, php_git2_read_arrval(array, ZEND_STRS("pathspec") TSRMLS_CC) TSRMLS_CC); // TODO(chobie): support notify cb - + options->context_lines = php_git2_read_arrval_long(array, ZEND_STRS("context_lines") TSRMLS_CC); options->interhunk_lines = php_git2_read_arrval_long(array, ZEND_STRS("interhunk_lines") TSRMLS_CC); options->oid_abbrev = php_git2_read_arrval_long(array, ZEND_STRS("oid_abbrev") TSRMLS_CC); @@ -343,7 +343,6 @@ PHP_FUNCTION(git_diff_find_similar) int error = 0; git_diff_options _options = {0}; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &diff, &options) == FAILURE) { return; diff --git a/example/blame.php b/example/blame.php new file mode 100644 index 0000000000..66e6ca70b3 --- /dev/null +++ b/example/blame.php @@ -0,0 +1,25 @@ +", $hunk['final_signature']['name'], $hunk['final_signature']['email']); + printf("%s ( %-30s, %4d) %s\n", substr($hunk['final_commit_id'], 10), + $sig, + $i+1, + $data + ); + $i++; +} \ No newline at end of file diff --git a/helper.c b/helper.c index 14e24ade4d..09a6953901 100644 --- a/helper.c +++ b/helper.c @@ -116,8 +116,16 @@ void php_git2_signature_to_array(const git_signature *signature, zval **out TSRM /* TODO(chobie): how do i set offset? */ php_date_initialize(zend_object_store_get_object(datetime TSRMLS_CC), time_str, strlen(time_str), NULL, timezone, 0 TSRMLS_CC); - add_assoc_string_ex(result, ZEND_STRS("name"), signature->name, 1); - add_assoc_string_ex(result, ZEND_STRS("email"), signature->email, 1); + if (signature->name == NULL) { + add_assoc_null_ex(result, ZEND_STRS("name")); + } else { + add_assoc_string_ex(result, ZEND_STRS("name"), signature->name, 1); + } + if (signature->email == NULL) { + add_assoc_null_ex(result, ZEND_STRS("email")); + } else { + add_assoc_string_ex(result, ZEND_STRS("email"), signature->email, 1); + } add_assoc_zval_ex(result, ZEND_STRS("time"), datetime); zval_ptr_dtor(&timezone); diff --git a/php_git2.c b/php_git2.c index 8166ae94dd..e13f7abbf1 100644 --- a/php_git2.c +++ b/php_git2.c @@ -66,6 +66,7 @@ #include "push.h" #include "refspec.h" #include "graph.h" +#include "blame.h" int git2_resource_handle; @@ -944,6 +945,15 @@ static zend_function_entry php_git2_functions[] = { /* graph */ PHP_FE(git_graph_ahead_behind, arginfo_git_graph_ahead_behind) + /* blame */ + PHP_FE(git_blame_get_hunk_count, arginfo_git_blame_get_hunk_count) + PHP_FE(git_blame_get_hunk_byindex, arginfo_git_blame_get_hunk_byindex) + PHP_FE(git_blame_get_hunk_byline, arginfo_git_blame_get_hunk_byline) + PHP_FE(git_blame_file, arginfo_git_blame_file) + PHP_FE(git_blame_buffer, arginfo_git_blame_buffer) + PHP_FE(git_blame_free, arginfo_git_blame_free) + PHP_FE(git_blame_options_new, arginfo_git_blame_options_new) + /* misc */ PHP_FE(git_resource_type, arginfo_git_resource_type) PHP_FE(git_libgit2_capabilities, NULL) From 7ecff2fd789f86050f6439281bb9d7ddecbcfd2a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 17 Jan 2014 15:39:27 +0900 Subject: [PATCH 103/136] [pathspec] implement git_pathspec_match_list_diff_entry --- pathspec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pathspec.c b/pathspec.c index 1ef2309182..82687a5135 100644 --- a/pathspec.c +++ b/pathspec.c @@ -253,7 +253,7 @@ PHP_FUNCTION(git_pathspec_match_list_entry) PHP_FUNCTION(git_pathspec_match_list_diff_entry) { const git_diff_delta *result = NULL; - zval *m = NULL; + zval *m = NULL, *_result = NULL; php_git2_t *_m = NULL; long pos = 0; @@ -264,7 +264,11 @@ PHP_FUNCTION(git_pathspec_match_list_diff_entry) ZEND_FETCH_RESOURCE(_m, php_git2_t*, &m, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_pathspec_match_list_diff_entry(PHP_GIT2_V(_m, pathspec_match_list), pos); - /* TODO(chobie): implement this */ + if (result == NULL) { + RETURN_FALSE; + } + php_git2_diff_delta_to_array(result, &_result TSRMLS_CC); + RETURN_ZVAL(_result, 0, 1); } /* }}} */ From c3b172cda6993b06e8ae6b1bc7f1364968e112c9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 17 Jan 2014 20:25:08 +0900 Subject: [PATCH 104/136] [pathspec] implement several functions --- config.m4 | 4 +- diff.c | 153 ++----------------------------------------- example/diff.php | 2 +- example/pathspec.php | 8 +++ helper.c | 147 +++++++++++++++++++++++++++++++++++++++++ helper.h | 22 +++++++ patch.c | 61 ++++++++++------- pathspec.c | 5 +- repository.c | 2 +- 9 files changed, 228 insertions(+), 176 deletions(-) create mode 100644 example/pathspec.php diff --git a/config.m4 b/config.m4 index b14e42235c..fed1775bce 100644 --- a/config.m4 +++ b/config.m4 @@ -11,14 +11,14 @@ if test $PHP_GIT2 != "no"; then PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) # for now - CFLAGS=" $CFLAGS -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Winline -Wunused-macros -Wredundant-decls -Wstrict-aliasing=2 -Wswitch-enum -Wdeclaration-after-statement" + CFLAGS=" $CFLAGS -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Winline -Wunused-macros -Wredundant-decls -Wstrict-aliasing=2 -Wswitch-enum -Wdeclaration-after-statement -Wl,libgit2/build/libgit2.a" if test "$PHP_GIT2_DEBUG" != "no"; then CFLAGS="-g -O0 $CFLAGS" fi PHP_ADD_LIBPATH($ext_srcdir/libgit2/build, GIT2_SHARED_LIBADD) - PHP_ADD_LIBRARY(git2,, GIT2_SHARED_LIBADD) + #PHP_ADD_LIBRARY(git2,, GIT2_SHARED_LIBADD) PHP_SUBST([CFLAGS]) ifdef([PHP_ADD_EXTENSION_DEP], diff --git a/diff.c b/diff.c index 21c80f6df7..8ec95fe2c0 100644 --- a/diff.c +++ b/diff.c @@ -2,152 +2,6 @@ #include "php_git2_priv.h" #include "diff.h" - -static void php_git2_array_to_git_diff_options(git_diff_options *options, zval *array TSRMLS_DC) -{ - git_diff_options_init(options, GIT_DIFF_OPTIONS_VERSION); - - options->version = php_git2_read_arrval_long(array, ZEND_STRS("version") TSRMLS_CC); - options->flags = php_git2_read_arrval_long(array, ZEND_STRS("flags") TSRMLS_CC); - options->ignore_submodules = php_git2_read_arrval_long(array, ZEND_STRS("ignore_submodules") TSRMLS_CC); - - php_git2_array_to_strarray(&options->pathspec, php_git2_read_arrval(array, ZEND_STRS("pathspec") TSRMLS_CC) TSRMLS_CC); - // TODO(chobie): support notify cb - - - options->context_lines = php_git2_read_arrval_long(array, ZEND_STRS("context_lines") TSRMLS_CC); - options->interhunk_lines = php_git2_read_arrval_long(array, ZEND_STRS("interhunk_lines") TSRMLS_CC); - options->oid_abbrev = php_git2_read_arrval_long(array, ZEND_STRS("oid_abbrev") TSRMLS_CC); - options->max_size = php_git2_read_arrval_long(array, ZEND_STRS("max_size") TSRMLS_CC); - options->old_prefix = php_git2_read_arrval_string(array, ZEND_STRS("old_prefix") TSRMLS_CC); - options->new_prefix = php_git2_read_arrval_string(array, ZEND_STRS("new_prefix") TSRMLS_CC); -} - -static void php_git2_git_diff_options_free(git_diff_options *options) -{ - if (options->pathspec.count > 0) { - efree(options->pathspec.strings); - } -} - -static void php_git2_git_diff_options_to_array(git_diff_options *options, zval **out TSRMLS_DC) -{ - zval *result, *pathspec; - - MAKE_STD_ZVAL(result); - array_init(result); - add_assoc_long_ex(result, ZEND_STRS("version"), options->version); - add_assoc_long_ex(result, ZEND_STRS("flags"), options->flags); - add_assoc_long_ex(result, ZEND_STRS("ignore_submodules"), options->ignore_submodules); - - MAKE_STD_ZVAL(pathspec); - array_init(pathspec); - if (options->pathspec.count > 0) { - } else { - add_assoc_zval_ex(result, ZEND_STRS("pathspec"), pathspec); - } - - if (options->notify_cb) { - } else { - add_assoc_null_ex(result, ZEND_STRS("notify_cb")); - } - - add_assoc_long_ex(result, ZEND_STRS("context_lines"), options->context_lines); - add_assoc_long_ex(result, ZEND_STRS("interhunk_lines"), options->interhunk_lines); - add_assoc_long_ex(result, ZEND_STRS("oid_abbrev"), options->oid_abbrev); - add_assoc_long_ex(result, ZEND_STRS("max_size"), options->max_size); - if (options->notify_payload) { - } else { - add_assoc_null_ex(result, ZEND_STRS("notify_payload")); - } - if (options->old_prefix) { - add_assoc_string_ex(result, ZEND_STRS("old_prefix"), options->old_prefix, 1); - } else { - add_assoc_null_ex(result, ZEND_STRS("old_prefix")); - } - if (options->new_prefix) { - add_assoc_string_ex(result, ZEND_STRS("new_prefix"), options->new_prefix, 1); - } else { - add_assoc_null_ex(result, ZEND_STRS("new_prefix")); - } - - *out = result; -} - - -static int php_git2_git_diff_file_cb( - const git_diff_delta *delta, - float progress, - void *payload) -{ - php_git2_t *result; - zval *param_delta = NULL, *param_progress = NULL, *retval_ptr = NULL; - php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; - int i = 0, retval = 0; - GIT2_TSRMLS_SET(p->tsrm_ls) - - Z_ADDREF_P(p->payload); - MAKE_STD_ZVAL(param_progress); - ZVAL_DOUBLE(param_progress, progress); - php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); - if (php_git2_call_function_v(&p->callbacks[0].fci, &p->callbacks[0].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_progress, &p->payload)) { - return GIT_EUSER; - } - retval = Z_LVAL_P(retval_ptr); - zval_ptr_dtor(&retval_ptr); - - return retval; -} - -static int php_git2_git_diff_hunk_cb( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - void *payload) -{ - php_git2_t *result; - zval *param_delta = NULL, *param_hunk = NULL, *retval_ptr = NULL; - php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; - int i = 0, retval = 0; - GIT2_TSRMLS_SET(p->tsrm_ls) - - Z_ADDREF_P(p->payload); - php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); - php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); - - if (php_git2_call_function_v(&p->callbacks[1].fci, &p->callbacks[1].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_hunk, &p->payload)) { - return GIT_EUSER; - } - - retval = Z_LVAL_P(retval_ptr); - zval_ptr_dtor(&retval_ptr); - return retval; -} - -static int php_git2_git_diff_line_cb( - const git_diff_delta *delta, - const git_diff_hunk *hunk, - const git_diff_line *line, - void *payload) { - php_git2_t *result; - zval *param_delta = NULL, *param_hunk = NULL, *param_line = NULL, *retval_ptr = NULL; - php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; - int i = 0, retval = 0; - GIT2_TSRMLS_SET(p->tsrm_ls) - - Z_ADDREF_P(p->payload); - php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); - php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); - php_git2_diff_line_to_array(line, ¶m_line TSRMLS_CC); - - if (php_git2_call_function_v(&p->callbacks[2].fci, &p->callbacks[2].fcc TSRMLS_CC, &retval_ptr, 4, ¶m_delta, ¶m_hunk, ¶m_line, &p->payload)) { - return GIT_EUSER; - } - - retval = Z_LVAL_P(retval_ptr); - zval_ptr_dtor(&retval_ptr); - return retval; -} - /* {{{ proto void git_diff_free(resource $diff) */ PHP_FUNCTION(git_diff_free) @@ -238,7 +92,7 @@ PHP_FUNCTION(git_diff_index_to_workdir) git_diff *diff = NULL; zval *repo = NULL, *index = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_index = NULL, *_diff = NULL; - git_diff_options options = {0}; + git_diff_options options = GIT_DIFF_OPTIONS_INIT; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rra", &repo, &index, &opts) == FAILURE) { @@ -276,6 +130,11 @@ PHP_FUNCTION(git_diff_tree_to_workdir) ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), &options); + if (php_git2_check_error(result, "git_diff_tree_to_workdir" TSRMLS_CC)) { + php_git2_git_diff_options_free(&options); + RETURN_FALSE + } + php_git2_git_diff_options_free(&options); if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { diff --git a/example/diff.php b/example/diff.php index 5050c5d561..74f5770df5 100644 --- a/example/diff.php +++ b/example/diff.php @@ -1,7 +1,7 @@ version = php_git2_read_arrval_long(array, ZEND_STRS("version") TSRMLS_CC); + options->flags = php_git2_read_arrval_long(array, ZEND_STRS("flags") TSRMLS_CC); + options->ignore_submodules = php_git2_read_arrval_long(array, ZEND_STRS("ignore_submodules") TSRMLS_CC); + + php_git2_array_to_strarray(&options->pathspec, php_git2_read_arrval(array, ZEND_STRS("pathspec") TSRMLS_CC) TSRMLS_CC); + // TODO(chobie): support notify cb + + options->context_lines = php_git2_read_arrval_long(array, ZEND_STRS("context_lines") TSRMLS_CC); + options->interhunk_lines = php_git2_read_arrval_long(array, ZEND_STRS("interhunk_lines") TSRMLS_CC); + options->oid_abbrev = php_git2_read_arrval_long(array, ZEND_STRS("oid_abbrev") TSRMLS_CC); + options->max_size = php_git2_read_arrval_long(array, ZEND_STRS("max_size") TSRMLS_CC); + options->old_prefix = php_git2_read_arrval_string(array, ZEND_STRS("old_prefix") TSRMLS_CC); + options->new_prefix = php_git2_read_arrval_string(array, ZEND_STRS("new_prefix") TSRMLS_CC); +} + +void php_git2_git_diff_options_free(git_diff_options *options) +{ + if (options->pathspec.count > 0) { + efree(options->pathspec.strings); + } +} + +void php_git2_git_diff_options_to_array(git_diff_options *options, zval **out TSRMLS_DC) +{ + zval *result, *pathspec; + + MAKE_STD_ZVAL(result); + array_init(result); + add_assoc_long_ex(result, ZEND_STRS("version"), options->version); + add_assoc_long_ex(result, ZEND_STRS("flags"), options->flags); + add_assoc_long_ex(result, ZEND_STRS("ignore_submodules"), options->ignore_submodules); + + MAKE_STD_ZVAL(pathspec); + array_init(pathspec); + if (options->pathspec.count > 0) { + } else { + add_assoc_zval_ex(result, ZEND_STRS("pathspec"), pathspec); + } + + if (options->notify_cb) { + } else { + add_assoc_null_ex(result, ZEND_STRS("notify_cb")); + } + + add_assoc_long_ex(result, ZEND_STRS("context_lines"), options->context_lines); + add_assoc_long_ex(result, ZEND_STRS("interhunk_lines"), options->interhunk_lines); + add_assoc_long_ex(result, ZEND_STRS("oid_abbrev"), options->oid_abbrev); + add_assoc_long_ex(result, ZEND_STRS("max_size"), options->max_size); + if (options->notify_payload) { + } else { + add_assoc_null_ex(result, ZEND_STRS("notify_payload")); + } + if (options->old_prefix) { + add_assoc_string_ex(result, ZEND_STRS("old_prefix"), options->old_prefix, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("old_prefix")); + } + if (options->new_prefix) { + add_assoc_string_ex(result, ZEND_STRS("new_prefix"), options->new_prefix, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("new_prefix")); + } + + *out = result; +} + +int php_git2_git_diff_file_cb( + const git_diff_delta *delta, + float progress, + void *payload) +{ + php_git2_t *result; + zval *param_delta = NULL, *param_progress = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_progress); + ZVAL_DOUBLE(param_progress, progress); + php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); + if (php_git2_call_function_v(&p->callbacks[0].fci, &p->callbacks[0].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_progress, &p->payload)) { + return GIT_EUSER; + } + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + + return retval; +} + +int php_git2_git_diff_hunk_cb( + const git_diff_delta *delta, + const git_diff_hunk *hunk, + void *payload) +{ + php_git2_t *result; + zval *param_delta = NULL, *param_hunk = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); + php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); + + if (php_git2_call_function_v(&p->callbacks[1].fci, &p->callbacks[1].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_hunk, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + +int php_git2_git_diff_line_cb( + const git_diff_delta *delta, + const git_diff_hunk *hunk, + const git_diff_line *line, + void *payload) { + php_git2_t *result; + zval *param_delta = NULL, *param_hunk = NULL, *param_line = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); + php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); + php_git2_diff_line_to_array(line, ¶m_line TSRMLS_CC); + + if (php_git2_call_function_v(&p->callbacks[2].fci, &p->callbacks[2].fcc TSRMLS_CC, &retval_ptr, 4, ¶m_delta, ¶m_hunk, ¶m_line, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + diff --git a/helper.h b/helper.h index 447c7d8d2f..1aa7b1c8c1 100644 --- a/helper.h +++ b/helper.h @@ -70,4 +70,26 @@ void php_git2_diff_hunk_to_array(git_diff_hunk *hunk, zval **out TSRMLS_DC); void php_git2_diff_file_to_array(git_diff_file *file, zval **out TSRMLS_DC); void php_git2_diff_delta_to_array(git_diff_delta *delta, zval **out TSRMLS_DC); + +void php_git2_array_to_git_diff_options(git_diff_options *options, zval *array TSRMLS_DC); + +void php_git2_git_diff_options_free(git_diff_options *options); + +void php_git2_git_diff_options_to_array(git_diff_options *options, zval **out TSRMLS_DC); + +int php_git2_git_diff_file_cb( + const git_diff_delta *delta, + float progress, + void *payload); + +int php_git2_git_diff_hunk_cb( + const git_diff_delta *delta, + const git_diff_hunk *hunk, + void *payload); +int php_git2_git_diff_line_cb( + const git_diff_delta *delta, + const git_diff_hunk *hunk, + const git_diff_line *line, + void *payload); + #endif \ No newline at end of file diff --git a/patch.c b/patch.c index 5345c2bfc6..e51513404a 100644 --- a/patch.c +++ b/patch.c @@ -29,18 +29,17 @@ PHP_FUNCTION(git_patch_from_diff) } /* }}} */ - /* {{{ proto resource git_patch_from_blobs(resource $old_blob, string $old_as_path, resource $new_blob, string $new_as_path, $opts) */ PHP_FUNCTION(git_patch_from_blobs) { php_git2_t *result = NULL, *_old_blob = NULL, *_new_blob = NULL; git_patch *out = NULL; + git_diff_options options = GIT_DIFF_OPTIONS_INIT; zval *old_blob = NULL, *new_blob = NULL, *opts = NULL; char *old_as_path = NULL, *new_as_path = NULL; int old_as_path_len = 0, new_as_path_len = 0, error = 0; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrsa", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &opts) == FAILURE) { return; @@ -48,7 +47,9 @@ PHP_FUNCTION(git_patch_from_blobs) ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_new_blob, php_git2_t*, &new_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_patch_from_blobs(&out, PHP_GIT2_V(_old_blob, blob), old_as_path, PHP_GIT2_V(_new_blob, blob), new_as_path, opts); + php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); + error = git_patch_from_blobs(&out, PHP_GIT2_V(_old_blob, blob), old_as_path, PHP_GIT2_V(_new_blob, blob), new_as_path, &options); + php_git2_git_diff_options_free(&options); if (php_git2_check_error(error, "git_patch_from_blobs" TSRMLS_CC)) { RETURN_FALSE; } @@ -69,15 +70,17 @@ PHP_FUNCTION(git_patch_from_blob_and_buffer) zval *old_blob = NULL, *opts = NULL; char *old_as_path = NULL, *buffer = NULL, *buffer_as_path = NULL; int old_as_path_len = 0, buffer_len = 0, buffer_as_path_len = 0, error = 0; + git_diff_options options = GIT_DIFF_OPTIONS_INIT; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsslsa", &old_blob, &old_as_path, &old_as_path_len, &buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &opts) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_patch_from_blob_and_buffer(&out, PHP_GIT2_V(_old_blob, blob), old_as_path, buffer, buffer_len, buffer_as_path, opts); + php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); + error = git_patch_from_blob_and_buffer(&out, PHP_GIT2_V(_old_blob, blob), old_as_path, buffer, buffer_len, buffer_as_path, &options); + php_git2_git_diff_options_free(&options); if (php_git2_check_error(error, "git_patch_from_blob_and_buffer" TSRMLS_CC)) { RETURN_FALSE; } @@ -116,7 +119,7 @@ PHP_FUNCTION(git_patch_free) PHP_FUNCTION(git_patch_get_delta) { const git_diff_delta *result = NULL; - zval *patch = NULL; + zval *patch = NULL, *out = NULL; php_git2_t *_patch = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -126,7 +129,8 @@ PHP_FUNCTION(git_patch_get_delta) ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_patch_get_delta(PHP_GIT2_V(_patch, patch)); - /* TODO(chobie): implement this */ + php_git2_diff_delta_to_array(result, &out TSRMLS_CC); + RETURN_ZVAL(out, 0, 1); } /* }}} */ @@ -149,23 +153,28 @@ PHP_FUNCTION(git_patch_num_hunks) } /* }}} */ -/* {{{ proto long git_patch_line_stats(long $total_context, long $total_additions, long $total_deletions, resource $patch) +/* {{{ proto long git_patch_line_stats(resource $patch) */ PHP_FUNCTION(git_patch_line_stats) { int result = 0, error = 0; - long total_context = 0, total_additions = 0, total_deletions = 0; - zval *patch = NULL; + size_t total_context = 0, total_additions = 0, total_deletions = 0; + zval *patch = NULL, *out = NULL; php_git2_t *_patch = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "lllr", &total_context, &total_additions, &total_deletions, &patch) == FAILURE) { + "r", &patch) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_patch_line_stats(total_context, total_additions, total_deletions, PHP_GIT2_V(_patch, patch)); - RETURN_LONG(result); + result = git_patch_line_stats(&total_context, &total_additions, &total_deletions, PHP_GIT2_V(_patch, patch)); + MAKE_STD_ZVAL(out); + array_init(out); + add_assoc_long_ex(out, ZEND_STRS("total_context"), total_context); + add_assoc_long_ex(out, ZEND_STRS("total_additions"), total_additions); + add_assoc_long_ex(out, ZEND_STRS("total_deletions"), total_deletions); + RETURN_ZVAL(out, 0, 1); } /* }}} */ @@ -263,7 +272,6 @@ PHP_FUNCTION(git_patch_size) } /* }}} */ - /* {{{ proto long git_patch_print(resource $patch, Callable $print_cb, $payload) */ PHP_FUNCTION(git_patch_print) @@ -273,7 +281,7 @@ PHP_FUNCTION(git_patch_print) php_git2_t *_patch = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; - php_git2_cb_t *cb = NULL; + php_git2_multi_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rfz", &patch, &fci, &fcc, &payload) == FAILURE) { @@ -281,17 +289,19 @@ PHP_FUNCTION(git_patch_print) } ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { - RETURN_FALSE; - } - //result = git_patch_print(PHP_GIT2_V(_patch, patch), , cb); - php_git2_cb_free(cb); + php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3, + &empty_fcall_info, &empty_fcall_info_cache, + &empty_fcall_info, &empty_fcall_info_cache, + &fci, &fcc + ); + result = git_patch_print(PHP_GIT2_V(_patch, patch), php_git2_git_diff_line_cb, cb); + php_git2_multi_cb_free(cb); RETURN_LONG(result); } /* }}} */ -/* {{{ proto long git_patch_to_str(string $string, resource $patch) +/* {{{ proto long git_patch_to_str(resource $patch) */ PHP_FUNCTION(git_patch_to_str) { @@ -301,12 +311,17 @@ PHP_FUNCTION(git_patch_to_str) php_git2_t *_patch = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sr", &string, &string_len, &patch) == FAILURE) { + "r", &patch) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_patch, php_git2_t*, &patch, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_patch_to_str(&string, PHP_GIT2_V(_patch, patch)); - RETURN_LONG(result); + if (result != 0) { + RETURN_FALSE; + } + + RETVAL_STRING(string, 1); + free(string); } /* }}} */ diff --git a/pathspec.c b/pathspec.c index 82687a5135..00b6377bae 100644 --- a/pathspec.c +++ b/pathspec.c @@ -18,7 +18,8 @@ PHP_FUNCTION(git_pathspec_new) } php_git2_array_to_strarray(&_pathspec, pathspec TSRMLS_CC); - error = git_pathspec_new(&out, &pathspec); + error = git_pathspec_new(&out, &_pathspec); + php_git2_strarray_free(&_pathspec); if (php_git2_check_error(error, "git_pathspec_new" TSRMLS_CC)) { RETURN_FALSE; } @@ -78,7 +79,7 @@ PHP_FUNCTION(git_pathspec_matches_path) PHP_FUNCTION(git_pathspec_match_workdir) { php_git2_t *result = NULL, *_repo = NULL, *_ps = NULL; - git_pathspec_match_list *out = NULL; + git_pathspec_match_list *out; zval *repo = NULL, *ps = NULL; long flags = 0; int error = 0; diff --git a/repository.c b/repository.c index 7647f39a2d..c44dee8af0 100644 --- a/repository.c +++ b/repository.c @@ -596,7 +596,7 @@ PHP_FUNCTION(git_repository_index) if (php_git2_check_error(error, "git_repository_index" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); From 7a66238ef5f12f754b511f0dfec891c061dbc2e0 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 17 Jan 2014 21:50:31 +0900 Subject: [PATCH 105/136] [repository] implement git_repository_init_ext --- php_git2.c | 1 + repository.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++---- repository.h | 4 +++ 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/php_git2.c b/php_git2.c index e13f7abbf1..36954248a4 100644 --- a/php_git2.c +++ b/php_git2.c @@ -366,6 +366,7 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_repository_state, arginfo_git_repository_state) PHP_FE(git_repository_set_namespace, arginfo_git_repository_set_namespace) PHP_FE(git_repository_is_shallow, arginfo_git_repository_is_shallow) + PHP_FE(git_repository_init_options_new, NULL) /* index */ PHP_FE(git_index_open, arginfo_git_index_open) diff --git a/repository.c b/repository.c index c44dee8af0..9504603b88 100644 --- a/repository.c +++ b/repository.c @@ -2,6 +2,67 @@ #include "php_git2_priv.h" #include "repository.h" +static void php_git2_array_to_git_repository_init_options(git_repository_init_options *opts, zval *array TSRMLS_DC) +{ + long lval; + + lval = php_git2_read_arrval_long(array, ZEND_STRS("version") TSRMLS_CC); + if (lval > 0) { + opts->version = lval; + } + opts->flags = php_git2_read_arrval_long(array, ZEND_STRS("flags") TSRMLS_CC); + opts->mode = php_git2_read_arrval_long(array, ZEND_STRS("mode") TSRMLS_CC); + + opts->workdir_path = php_git2_read_arrval_string(array, ZEND_STRS("workdir_path") TSRMLS_CC); + opts->description = php_git2_read_arrval_string(array, ZEND_STRS("description") TSRMLS_CC); + opts->template_path = php_git2_read_arrval_string(array, ZEND_STRS("template_path") TSRMLS_CC); + opts->initial_head = php_git2_read_arrval_string(array, ZEND_STRS("initial_head") TSRMLS_CC); + opts->origin_url = php_git2_read_arrval_string(array, ZEND_STRS("origin_url") TSRMLS_CC); +} + +static void php_git2_git_repository_init_options_to_array(git_repository_init_options *opts, zval **out TSRMLS_DC) +{ + zval *result; + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("version"), opts->version); + add_assoc_long_ex(result, ZEND_STRS("flags"), opts->flags); + add_assoc_long_ex(result, ZEND_STRS("mode"), opts->mode); + + if (opts->workdir_path != NULL) { + add_assoc_string_ex(result, ZEND_STRS("workdir_path"), opts->workdir_path, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("workdir_path")); + } + + if (opts->workdir_path != NULL) { + add_assoc_string_ex(result, ZEND_STRS("description"), opts->description, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("description")); + } + + if (opts->workdir_path != NULL) { + add_assoc_string_ex(result, ZEND_STRS("template_path"), opts->template_path, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("template_path")); + } + + if (opts->workdir_path != NULL) { + add_assoc_string_ex(result, ZEND_STRS("initial_head"), opts->initial_head, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("initial_head")); + } + + if (opts->workdir_path != NULL) { + add_assoc_string_ex(result, ZEND_STRS("origin_url"), opts->origin_url, 1); + } else { + add_assoc_null_ex(result, ZEND_STRS("origin_url")); + } + *out = result; +} + + static int php_git2_repository_fetchhead_foreach_cb(const char *ref_name, const char *remote_url, const git_oid *oid, @@ -310,25 +371,24 @@ PHP_FUNCTION(git_repository_free) } /* }}} */ - /* {{{ proto resource git_repository_init_ext(string $repo_path, $opts) */ PHP_FUNCTION(git_repository_init_ext) { + git_repository_init_options options = GIT_REPOSITORY_INIT_OPTIONS_INIT; php_git2_t *result = NULL; git_repository *out = NULL; char *repo_path = NULL; - int repo_path_len = 0; + int repo_path_len = 0, error = 0; zval *opts = NULL; - int error = 0; - /* TODO(chobie): generate converter */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &repo_path, &repo_path_len, &opts) == FAILURE) { return; } - error = git_repository_init_ext(&out, repo_path, opts); + php_git2_array_to_git_repository_init_options(&options, opts TSRMLS_CC); + error = git_repository_init_ext(&out, repo_path, &options); if (php_git2_check_error(error, "git_repository_init_ext" TSRMLS_CC)) { RETURN_FALSE; } @@ -876,4 +936,16 @@ PHP_FUNCTION(git_repository_is_shallow) is_shallow = git_repository_is_shallow(PHP_GIT2_V(_repo, repository)); RETURN_LONG(is_shallow); } +/* }}} */ + +/* {{{ proto array git_repository_init_options_new() +*/ +PHP_FUNCTION(git_repository_init_options_new) +{ + git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; + zval *result; + + php_git2_git_repository_init_options_to_array(&opts, &result TSRMLS_CC); + RETURN_ZVAL(result, 0, 1); +} /* }}} */ \ No newline at end of file diff --git a/repository.h b/repository.h index 9d0ce642a0..d6ff40b191 100644 --- a/repository.h +++ b/repository.h @@ -317,4 +317,8 @@ PHP_FUNCTION(git_repository_set_namespace); */ PHP_FUNCTION(git_repository_is_shallow); +/* {{{ proto array git_repository_init_options_new() +*/ +PHP_FUNCTION(git_repository_init_options_new); + #endif \ No newline at end of file From f77bba37aba74ee45c068fa9a6a452592676c8af Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 18 Jan 2014 09:01:52 +0900 Subject: [PATCH 106/136] [packbuilder] add callbacks --- example/packbuilder.php | 21 ++++++++ example/patch.php | 13 +++++ helper.c | 17 +++++++ helper.h | 2 + packbuilder.c | 106 +++++++++++++++++++++++++++++++++++++--- packbuilder.h | 7 +-- remote.c | 19 ------- 7 files changed, 156 insertions(+), 29 deletions(-) create mode 100644 example/packbuilder.php create mode 100644 example/patch.php diff --git a/example/packbuilder.php b/example/packbuilder.php new file mode 100644 index 0000000000..3a4414878a --- /dev/null +++ b/example/packbuilder.php @@ -0,0 +1,21 @@ +total_objects); + add_assoc_long_ex(result, ZEND_STRS("indexed_objects"), progress->indexed_objects); + add_assoc_long_ex(result, ZEND_STRS("received_objects"), progress->received_objects); + add_assoc_long_ex(result, ZEND_STRS("local_objects"), progress->local_objects); + add_assoc_long_ex(result, ZEND_STRS("total_deltas"), progress->total_deltas); + add_assoc_long_ex(result, ZEND_STRS("indexed_deltas"), progress->indexed_deltas); + add_assoc_long_ex(result, ZEND_STRS("received_bytes"), progress->received_bytes); + + *out = result; +} diff --git a/helper.h b/helper.h index 1aa7b1c8c1..06dc7db0a8 100644 --- a/helper.h +++ b/helper.h @@ -92,4 +92,6 @@ int php_git2_git_diff_line_cb( const git_diff_line *line, void *payload); +void php_git2_git_transfer_progress_to_array(git_transfer_progress *progress, zval **out TSRMLS_DC); + #endif \ No newline at end of file diff --git a/packbuilder.c b/packbuilder.c index 4c4e04008e..195950a1e7 100644 --- a/packbuilder.c +++ b/packbuilder.c @@ -2,6 +2,92 @@ #include "php_git2_priv.h" #include "packbuilder.h" +static int php_git2_git_packbuilder_progress( + int stage, + unsigned int current, + unsigned int total, + void *payload) +{ + php_git2_t *result; + zval *param_stage = NULL, *param_current = NULL, *param_total = NULL, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_stage); + MAKE_STD_ZVAL(param_current); + MAKE_STD_ZVAL(param_total); + ZVAL_LONG(param_stage, stage); + ZVAL_LONG(param_current, current); + ZVAL_LONG(param_total, total); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 4, + ¶m_stage, ¶m_current, ¶m_total, &p->payload)) { + return GIT_EUSER; + } + + if (retval_ptr) { + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + } + return retval; +} + +static int php_git2_git_packbuilder_foreach_cb(void *buf, size_t size, void *payload) +{ + php_git2_t *result; + zval *param_buf= NULL, *param_size = NULL, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_buf); + MAKE_STD_ZVAL(param_size); + ZVAL_STRINGL(param_buf, buf, size, 1); + ZVAL_LONG(param_size, size); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, + ¶m_buf, ¶m_size, &p->payload)) { + return GIT_EUSER; + } + + if (retval_ptr) { + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + } + return retval; +} + + +static int php_git2_git_transfer_progress_callback(const git_transfer_progress *stats, void *payload) +{ + php_git2_t *result; + zval *param_stats = NULL, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + php_git2_git_transfer_progress_to_array(stats, ¶m_stats TSRMLS_CC); + + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, + ¶m_stats, &p->payload)) { + return GIT_EUSER; + } + + if (retval_ptr) { + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + } + return retval; +} + /* {{{ proto resource git_packbuilder_new(resource $repo) */ PHP_FUNCTION(git_packbuilder_new) @@ -142,7 +228,7 @@ PHP_FUNCTION(git_packbuilder_write) if (php_git2_cb_init(&cb, &fci, &fcc, progress_cb_payload TSRMLS_CC)) { RETURN_FALSE; } - //result = git_packbuilder_write(PHP_GIT2_V(_pb, packbuilder), path, mode, , cb); + result = git_packbuilder_write(PHP_GIT2_V(_pb, packbuilder), path, mode, php_git2_git_transfer_progress_callback, cb); php_git2_cb_free(cb); RETURN_LONG(result); } @@ -169,6 +255,7 @@ PHP_FUNCTION(git_packbuilder_hash) } /* }}} */ + /* {{{ proto long git_packbuilder_foreach(resource $pb, Callable $cb, $payload) */ PHP_FUNCTION(git_packbuilder_foreach) @@ -189,7 +276,7 @@ PHP_FUNCTION(git_packbuilder_foreach) if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { RETURN_FALSE; } - //result = git_packbuilder_foreach(PHP_GIT2_V(_pb, packbuilder), , cb); + result = git_packbuilder_foreach(PHP_GIT2_V(_pb, packbuilder), php_git2_git_packbuilder_foreach_cb, cb); php_git2_cb_free(cb); RETURN_LONG(result); } @@ -240,8 +327,8 @@ PHP_FUNCTION(git_packbuilder_set_callbacks) int result = 0, error = 0; zval *pb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL; php_git2_t *_pb = NULL; - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache fcc = empty_fcall_info_cache; + zend_fcall_info fci = empty_fcall_info, *_fci; + zend_fcall_info_cache fcc = empty_fcall_info_cache, *_fcc; php_git2_cb_t *cb = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -250,11 +337,16 @@ PHP_FUNCTION(git_packbuilder_set_callbacks) } ZEND_FETCH_RESOURCE(_pb, php_git2_t*, &pb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - if (php_git2_cb_init(&cb, &fci, &fcc, progress_cb_payload TSRMLS_CC)) { + _fci = emalloc(sizeof(zend_fcall_info)); + _fcc = emalloc(sizeof(zend_fcall_info_cache)); + memcpy(_fci, &fci, sizeof(zend_fcall_info)); + memcpy(_fcc, &fcc, sizeof(zend_fcall_info_cache)); + + /* TODO(chobie): free memory when the resource removed */ + if (php_git2_cb_init(&cb, &_fci, &_fcc, progress_cb_payload TSRMLS_CC)) { RETURN_FALSE; } - //result = git_packbuilder_set_callbacks(PHP_GIT2_V(_pb, packbuilder), , cb); - php_git2_cb_free(cb); + result = git_packbuilder_set_callbacks(PHP_GIT2_V(_pb, packbuilder), php_git2_git_packbuilder_progress, cb); RETURN_LONG(result); } /* }}} */ diff --git a/packbuilder.h b/packbuilder.h index 7e53799120..5e8123f0de 100644 --- a/packbuilder.h +++ b/packbuilder.h @@ -51,11 +51,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_insert_commit, 0, 0, 2) ZEND_ARG_INFO(0, id) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_write, 0, 0, 4) +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_write, 0, 0, 5) + ZEND_ARG_INFO(0, pb) ZEND_ARG_INFO(0, path) ZEND_ARG_INFO(0, mode) ZEND_ARG_INFO(0, progress_cb) - ZEND_ARG_INFO(0, progress_cb_payload) + ZEND_ARG_INFO(1, progress_cb_payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_hash, 0, 0, 1) @@ -79,7 +80,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_set_callbacks, 0, 0, 3) ZEND_ARG_INFO(0, pb) ZEND_ARG_INFO(0, progress_cb) - ZEND_ARG_INFO(0, progress_cb_payload) + ZEND_ARG_INFO(1, progress_cb_payload) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_packbuilder_free, 0, 0, 1) diff --git a/remote.c b/remote.c index 9145cf7405..2ce4b76f64 100644 --- a/remote.c +++ b/remote.c @@ -2,25 +2,6 @@ #include "php_git2_priv.h" #include "remote.h" -static void php_git2_git_transfer_progress_to_array(git_transfer_progress *progress, zval **out TSRMLS_DC) -{ - zval *result; - - MAKE_STD_ZVAL(result); - array_init(result); - - add_assoc_long_ex(result, ZEND_STRS("total_objects"), progress->total_objects); - add_assoc_long_ex(result, ZEND_STRS("indexed_objects"), progress->indexed_objects); - add_assoc_long_ex(result, ZEND_STRS("received_objects"), progress->received_objects); - add_assoc_long_ex(result, ZEND_STRS("local_objects"), progress->local_objects); - add_assoc_long_ex(result, ZEND_STRS("total_deltas"), progress->total_deltas); - add_assoc_long_ex(result, ZEND_STRS("indexed_deltas"), progress->indexed_deltas); - add_assoc_long_ex(result, ZEND_STRS("received_bytes"), progress->received_bytes); - - *out = result; -} - - /* {{{ proto resource git_remote_create(resource $repo, string $name, string $url) */ PHP_FUNCTION(git_remote_create) From 4ef6d037b110ebea836543a3cc334bd88652c255 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 18 Jan 2014 16:45:49 +0900 Subject: [PATCH 107/136] fix merge functions --- merge.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/merge.c b/merge.c index f18e160b19..d31baa54e0 100644 --- a/merge.c +++ b/merge.c @@ -1,6 +1,7 @@ #include "php_git2.h" #include "php_git2_priv.h" #include "merge.h" + /* {{{ proto resource git_merge_base(resource $repo, string $one, string $two) */ PHP_FUNCTION(git_merge_base) @@ -202,24 +203,30 @@ PHP_FUNCTION(git_merge_trees) } /* }}} */ -/* {{{ proto resource git_merge(resource $repo, long $their_heads_len, $opts) +/* {{{ proto resource git_merge(resource $repo, array $their_heads, array $opts) */ PHP_FUNCTION(git_merge) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *result = NULL, *_repo = NULL, *_their_head = NULL; git_merge_result *out = NULL; - zval *repo = NULL, *opts = NULL; + zval *repo = NULL, *opts = NULL, *theirhead = NULL; git_merge_head *their_heads = NULL; + git_merge_head *heads[1]; long their_heads_len = 0; int error = 0; + git_merge_opts options = GIT_MERGE_OPTS_INIT; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rl", &repo, &their_heads_len, &opts) == FAILURE) { + "rza", &repo, &theirhead, &opts) == FAILURE) { return; } - + ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_merge(&out, PHP_GIT2_V(_repo, repository), &their_heads, their_heads_len, opts); + ZEND_FETCH_RESOURCE(_their_head, php_git2_t*, &theirhead, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + heads[0] = PHP_GIT2_V(_their_head, merge_head); + options.merge_flags = GIT_MERGE_NO_FASTFORWARD; + + error = git_merge(&out, PHP_GIT2_V(_repo, repository), heads, 1, &options); if (php_git2_check_error(error, "git_merge" TSRMLS_CC)) { RETURN_FALSE; } @@ -289,7 +296,7 @@ PHP_FUNCTION(git_merge_result_fastforward_oid) RETURN_FALSE; } git_oid_fmt(buf, &out); - RETURN_SRING(buf, 1); + RETURN_STRING(buf, 1); } /* }}} */ From b79c3018a78226cf6cd5ec46300090be451120d4 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 19 Jan 2014 23:15:35 +0900 Subject: [PATCH 108/136] [filter] add callbacks --- README.md | 19 +++ example/filter.php | 46 +++++++ filter.c | 312 +++++++++++++++++++++++++++++++++++++++++---- filter.h | 10 +- helper.c | 23 +++- helper.h | 4 + php_git2.c | 15 +++ php_git2.h | 38 ++++++ php_git2_priv.h | 31 ----- 9 files changed, 440 insertions(+), 58 deletions(-) create mode 100644 example/filter.php diff --git a/README.md b/README.md index 21a3ddb811..e96c64d5c4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,25 @@ php-git2 is a PHP bindings to the libgit2 linkable C Git library. https://docs.google.com/spreadsheet/ccc?key=0AjvShWAWqvfHdDRneEtIUF9GRUZMNVVVR1hpdURiUWc&usp=sharing +## How to build + +``` +# build libgit2.a +git submodule init && git submodule update +mkdir libgit2/build +cd libgit2/build +cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF . +cmake --build . + +# build php-git2 +cd ../../ +phpize +./configure --enable-git2-debug +make +make install +# add extension=git2.so to your php.ini +``` + ## For Contributors ##### Issue first. diff --git a/example/filter.php b/example/filter.php new file mode 100644 index 0000000000..f0e5c06b14 --- /dev/null +++ b/example/filter.php @@ -0,0 +1,46 @@ + "chobie filter", + "initialize" => function () { + echo "\e[32m# Initialize\e[m\n"; + }, + "check" => function ($payload, $src, $attr) { + echo "\e[32m# Check\e[m\n"; + var_dump($src); + var_dump($attr); + + // return true means apply filter to this file. + return true; + }, + "apply" => function ($payload, $from, $src) { + echo "\e[32m# Apply\e[m\n"; + // apply function should return string or GIT_PASSTHROUGH + return preg_replace("/\s/", "", $from); + }, + "shutdown" => function () { + echo "\n\e[32m# Shutdown\e[m\n"; + }, + "cleanup" => function () { + echo "\e[32m# clean up\e[m\n"; + } +); + +$v = git_filter_new($a); +git_filter_register("chobie", $v, 100); + +$blob = git_blob_lookup($repo, "74f5770df516cbbef16372a7628a9528277637d6"); +$l = git_filter_list_load($repo, $blob, "example/diff.php", GIT_FILTER_SMUDGE); + +echo "\e[32m# <<< ORIGINAL CONTENT >>>\e[m\n"; +echo git_blob_rawcontent($blob); + +echo "\e[32m# <<< FILTERED CONTENT >>>\e[m\n"; +$out = git_filter_list_apply_to_blob($l, $blob); +echo $out; diff --git a/filter.c b/filter.c index fb39792c23..e85eb810f2 100644 --- a/filter.c +++ b/filter.c @@ -2,6 +2,191 @@ #include "php_git2_priv.h" #include "filter.h" + +static int php_git2_git_filter_check_fn( + git_filter *self, + void **payload, + const git_filter_source *src, + const char **attr_values) +{ + php_git2_filter *filter = (php_git2_filter*)self; + php_git2_t *result, *filter_source; + zval *param_payload = NULL, *param_source = NULL, *param_attr = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = filter->multi; + int i = 0, retval = 0; + const unsigned char *ptr = self->attributes; + int last_is_space = 0; + int attribute_count = 0, len = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + if (self->attributes != NULL) { + while (*ptr != '\0') { + if (*ptr == 0x09 || *ptr == 0x20 && last_is_space == 0) { + attribute_count++; + } + + if (*ptr == 0x09 || *ptr == 0x20) { + last_is_space = 1; + } else { + last_is_space = 0; + } + ptr++; + len++; + } + if (len > 0) { + attribute_count++; + } + } + + MAKE_STD_ZVAL(param_payload); + MAKE_STD_ZVAL(param_source); + MAKE_STD_ZVAL(param_attr); + ZVAL_NULL(param_payload); + if (php_git2_make_resource(&filter_source, PHP_GIT2_TYPE_FILTER_SOURCE, src, 0 TSRMLS_CC)) { + return GIT_EUSER; + } + ZVAL_RESOURCE(param_source, GIT2_RVAL_P(filter_source)); + + array_init(param_attr); + + if (attribute_count > 0) { + int y = 0; + for (y = 0; y < attribute_count; y++) { + if (GIT_ATTR_TRUE(attr_values[y])) { + add_next_index_bool(param_attr, 1); + } else if (GIT_ATTR_FALSE(attr_values[y])) { + add_next_index_bool(param_attr, 0); + } else if (GIT_ATTR_UNSPECIFIED(attr_values[y])) { + add_next_index_null(param_attr); + } else { + add_next_index_string(param_attr, attr_values[y], 1); + } + } + } else { + } + + if (php_git2_call_function_v(&p->callbacks[2].fci, &p->callbacks[2].fcc TSRMLS_CC, &retval_ptr, 3, + ¶m_payload, ¶m_source, ¶m_attr)) { + return GIT_EUSER; + } + + if (retval_ptr) { + result = Z_LVAL_P(retval_ptr); + + /* NOTE(chobie): adjust return value */ + if (result == 0) { + result = GIT_PASSTHROUGH; + } else if (result == 1) { + result = 0; + } + } + zval_ptr_dtor(&retval_ptr); + + return result; +} + +static void php_git2_git_filter_shutdown_fn(git_filter *self) +{ + php_git2_t *result; + zval *param_self = NULL, *param_payload = NULL, *retval_ptr = NULL; + php_git2_filter *filter = (php_git2_filter*)self; + php_git2_multi_cb_t *p = filter->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + MAKE_STD_ZVAL(param_self); + MAKE_STD_ZVAL(param_payload); + ZVAL_NULL(param_self); + ZVAL_NULL(param_payload); + + if (php_git2_call_function_v(&p->callbacks[1].fci, &p->callbacks[1].fcc TSRMLS_CC, &retval_ptr, 2, ¶m_self, ¶m_payload)) { + } + zval_ptr_dtor(&retval_ptr); +} + +static int php_git2_git_filter_init_fn(git_filter *self) +{ + php_git2_t *result; + zval *param_self = NULL, *param_payload = NULL, *retval_ptr = NULL; + php_git2_filter *filter = (php_git2_filter*)self; + php_git2_multi_cb_t *p = filter->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + MAKE_STD_ZVAL(param_self); + MAKE_STD_ZVAL(param_payload); + ZVAL_NULL(param_self); + ZVAL_NULL(param_payload); + + if (php_git2_call_function_v(&p->callbacks[0].fci, &p->callbacks[0].fcc TSRMLS_CC, &retval_ptr, 2, ¶m_self, ¶m_payload)) { + } + zval_ptr_dtor(&retval_ptr); +} + +static int php_git2_git_filter_apply_fn( + git_filter *self, + void **payload, /* may be read and/or set */ + git_buf *to, + const git_buf *from, + const git_filter_source *src) +{ + php_git2_filter *filter = (php_git2_filter*)self; + php_git2_t *result, *filter_source; + zval *param_payload = NULL, *param_from = NULL, *param_src = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = filter->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + MAKE_STD_ZVAL(param_payload); + MAKE_STD_ZVAL(param_from); + MAKE_STD_ZVAL(param_src); + ZVAL_NULL(param_payload); + ZVAL_STRINGL(param_from, from->ptr, from->size, 1); + if (php_git2_make_resource(&filter_source, PHP_GIT2_TYPE_FILTER_SOURCE, src, 0 TSRMLS_CC)) { + return GIT_EUSER; + } + ZVAL_RESOURCE(param_src, GIT2_RVAL_P(filter_source)); + + if (php_git2_call_function_v(&p->callbacks[3].fci, &p->callbacks[3].fcc TSRMLS_CC, &retval_ptr, 3, + ¶m_payload, ¶m_from, ¶m_src)) { + return GIT_EUSER; + } + + if (retval_ptr) { + if (Z_TYPE_P(retval_ptr) == IS_LONG) { + retval = Z_LVAL_P(retval_ptr); + } else { + if (Z_TYPE_P(retval_ptr) != IS_STRING) { + convert_to_string(retval_ptr); + } + git_buf_set(to, Z_STRVAL_P(retval_ptr), Z_STRLEN_P(retval_ptr)); + } + } + + zval_ptr_dtor(&retval_ptr); + return retval; +} + +static void php_git2_git_filter_cleanup_fn( + git_filter *self, + void *payload) +{ + php_git2_t *result; + zval *param_self = NULL, *param_payload = NULL, *retval_ptr = NULL; + php_git2_filter *filter = (php_git2_filter*)self; + php_git2_multi_cb_t *p = filter->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + MAKE_STD_ZVAL(param_self); + MAKE_STD_ZVAL(param_payload); + ZVAL_NULL(param_self); + ZVAL_NULL(param_payload); + + if (php_git2_call_function_v(&p->callbacks[4].fci, &p->callbacks[4].fcc TSRMLS_CC, &retval_ptr, 2, ¶m_self, ¶m_payload)) { + } +} + /* {{{ proto long git_filter_list_load(resource $repo, resource $blob, string $path, $mode) */ PHP_FUNCTION(git_filter_list_load) @@ -9,19 +194,31 @@ PHP_FUNCTION(git_filter_list_load) int result = 0, path_len = 0, error = 0; git_filter_list *filters = NULL; zval *repo = NULL, *blob = NULL; - php_git2_t *_repo = NULL, *_blob = NULL; + php_git2_t *_repo = NULL, *_blob = NULL, *_result; char *path = NULL; long mode = 0; + git_blob *__blob = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rrsl", &repo, &blob, &path, &path_len, &mode) == FAILURE) { + "r|zsl", &repo, &blob, &path, &path_len, &mode) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_filter_list_load(&filters, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_blob, blob), path, mode); - RETURN_LONG(result); + + if (blob != NULL && Z_TYPE_P(blob) == IS_RESOURCE) { + ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + __blob = PHP_GIT2_V(_blob, blob); + } + + result = git_filter_list_load(&filters, PHP_GIT2_V(_repo, repository), blob, path, mode); + if (php_git2_check_error(result, "git_filter_list_load" TSRMLS_CC)) { + RETURN_FALSE + } + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_FILTER_LIST, filters, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ @@ -45,10 +242,8 @@ PHP_FUNCTION(git_filter_list_apply_to_data) if (php_git2_check_error(error, "git_filter_list_apply_to_data" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, &out, 1 TSRMLS_CC)) { - RETURN_FALSE; - } - ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); + RETVAL_STRINGL(out.ptr, out.size, 1); + git_buf_free(&out); } /* }}} */ @@ -73,10 +268,8 @@ PHP_FUNCTION(git_filter_list_apply_to_file) if (php_git2_check_error(error, "git_filter_list_apply_to_file" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, &out, 1 TSRMLS_CC)) { - RETURN_FALSE; - } - ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); + RETVAL_STRINGL(out.ptr, out.size, 1); + git_buf_free(&out); } /* }}} */ @@ -96,6 +289,7 @@ PHP_FUNCTION(git_filter_list_apply_to_blob) ZEND_FETCH_RESOURCE(_filters, php_git2_t*, &filters, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_blob, php_git2_t*, &blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + error = git_filter_list_apply_to_blob(&out, PHP_GIT2_V(_filters, filter_list), PHP_GIT2_V(_blob, blob)); if (php_git2_check_error(error, "git_filter_list_apply_to_blob" TSRMLS_CC)) { RETURN_FALSE; @@ -103,7 +297,8 @@ PHP_FUNCTION(git_filter_list_apply_to_blob) if (php_git2_make_resource(&result, PHP_GIT2_TYPE_BUF, &out, 1 TSRMLS_CC)) { RETURN_FALSE; } - ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); + RETVAL_STRINGL(out.ptr, out.size, 1); + git_buf_free(&out); } /* }}} */ @@ -138,6 +333,7 @@ PHP_FUNCTION(git_filter_lookup) git_filter *result = NULL; char *name = NULL; int name_len = 0; + zval *filter; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { @@ -145,7 +341,14 @@ PHP_FUNCTION(git_filter_lookup) } result = git_filter_lookup(name); - /* TODO(chobie): implement this */ + if (result == NULL) { + RETURN_FALSE; + } + MAKE_STD_ZVAL(filter); + array_init(filter); + add_assoc_long_ex(filter, ZEND_STRS("version"), result->version); + + RETURN_ZVAL(filter, 0, 1); } /* }}} */ @@ -155,11 +358,12 @@ PHP_FUNCTION(git_filter_list_new) { php_git2_t *result = NULL, *_repo = NULL; git_filter_list *out = NULL; - zval *repo = NULL, *mode = NULL; + zval *repo = NULL; + long mode = 0; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &repo, &mode) == FAILURE) { + "rl", &repo, &mode) == FAILURE) { return; } @@ -175,7 +379,7 @@ PHP_FUNCTION(git_filter_list_new) } /* }}} */ -/* {{{ proto long git_filter_list_push(resource $fl, resource $filter, $payload) +/* {{{ proto long git_filter_list_push(resource $fl, resource $filter, mixed $payload) */ PHP_FUNCTION(git_filter_list_push) { @@ -184,13 +388,13 @@ PHP_FUNCTION(git_filter_list_push) php_git2_t *_fl = NULL, *_filter = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rr", &fl, &filter, &payload) == FAILURE) { + "rr|z", &fl, &filter, &payload) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_fl, php_git2_t*, &fl, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); ZEND_FETCH_RESOURCE(_filter, php_git2_t*, &filter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - //result = git_filter_list_push(PHP_GIT2_V(_fl, filter_list), PHP_GIT2_V(_filter, filter), cb); + result = git_filter_list_push(PHP_GIT2_V(_fl, filter_list), PHP_GIT2_V(_filter, filter), NULL); RETURN_LONG(result); } /* }}} */ @@ -220,7 +424,7 @@ PHP_FUNCTION(git_filter_source_repo) { git_repository *result = NULL; zval *src = NULL; - php_git2_t *_src = NULL; + php_git2_t *_src = NULL, *_result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &src) == FAILURE) { @@ -229,7 +433,10 @@ PHP_FUNCTION(git_filter_source_repo) ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_filter_source_repo(PHP_GIT2_V(_src, filter_source)); - /* TODO(chobie): implement this */ + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_REPOSITORY, result, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ @@ -292,7 +499,7 @@ PHP_FUNCTION(git_filter_source_id) } /* }}} */ -/* {{{ proto resource git_filter_source_mode(resource $src) +/* {{{ proto long git_filter_source_mode(resource $src) */ PHP_FUNCTION(git_filter_source_mode) { @@ -307,7 +514,7 @@ PHP_FUNCTION(git_filter_source_mode) ZEND_FETCH_RESOURCE(_src, php_git2_t*, &src, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_filter_source_mode(PHP_GIT2_V(_src, filter_source)); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ @@ -327,7 +534,7 @@ PHP_FUNCTION(git_filter_register) } ZEND_FETCH_RESOURCE(_filter, php_git2_t*, &filter, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - //result = git_filter_register(name, PHP_GIT2_V(_filter, filter), priority); + result = git_filter_register(name, PHP_GIT2_V(_filter, filter), priority); RETURN_LONG(result); } /* }}} */ @@ -349,3 +556,58 @@ PHP_FUNCTION(git_filter_unregister) } /* }}} */ +PHP_FUNCTION(git_filter_new) +{ + git_filter *filter = NULL; + php_git2_t *result = NULL; + php_git2_filter *_filter = NULL; + zval *mixed = NULL, *tmp = NULL; + zend_fcall_info initialize_fci, shutdown_fci, check_fci, apply_fci, cleanup_fci; + zend_fcall_info_cache initialize_fcc, shutdown_fcc, check_fcc, apply_fcc, cleanup_fcc; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "a", &mixed) == FAILURE) { + return; + } + + _filter = (php_git2_filter*)ecalloc(1, sizeof(php_git2_filter)); + filter = (git_filter*)&_filter->super; + filter->version = GIT_FILTER_VERSION; + filter->attributes = php_git2_read_arrval_string(mixed, ZEND_STRS("attributes") TSRMLS_CC); + + if (tmp = php_git2_read_arrval(mixed, ZEND_STRS("initialize") TSRMLS_CC)) { + php_git2_fcall_info_wrapper2(tmp, &initialize_fci, &initialize_fcc TSRMLS_CC); + } + if (tmp = php_git2_read_arrval(mixed, ZEND_STRS("shutdown") TSRMLS_CC)) { + php_git2_fcall_info_wrapper2(tmp, &shutdown_fci, &shutdown_fcc TSRMLS_CC); + } + if (tmp = php_git2_read_arrval(mixed, ZEND_STRS("check") TSRMLS_CC)) { + php_git2_fcall_info_wrapper2(tmp, &check_fci, &check_fcc TSRMLS_CC); + } + if (tmp = php_git2_read_arrval(mixed, ZEND_STRS("apply") TSRMLS_CC)) { + php_git2_fcall_info_wrapper2(tmp, &apply_fci, &apply_fcc TSRMLS_CC); + } + if (tmp = php_git2_read_arrval(mixed, ZEND_STRS("cleanup") TSRMLS_CC)) { + php_git2_fcall_info_wrapper2(tmp, &cleanup_fci, &cleanup_fcc TSRMLS_CC); + } + + filter->initialize = php_git2_git_filter_init_fn; + filter->shutdown = php_git2_git_filter_shutdown_fn; + filter->check = php_git2_git_filter_check_fn; + filter->apply = php_git2_git_filter_apply_fn; + filter->cleanup = php_git2_git_filter_cleanup_fn; + + Z_ADDREF_P(mixed); + php_git2_multi_cb_init(&_filter->multi, mixed TSRMLS_CC, 5, + &initialize_fci, &initialize_fcc, + &shutdown_fci, &shutdown_fcc, + &check_fci, &check_fcc, + &apply_fci, &apply_fcc, + &cleanup_fci, &cleanup_fcc + ); + + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_FILTER, filter, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} \ No newline at end of file diff --git a/filter.h b/filter.h index b5a328b35c..c24bc8a056 100644 --- a/filter.h +++ b/filter.h @@ -26,7 +26,7 @@ #ifndef PHP_GIT2_FILTER_H #define PHP_GIT2_FILTER_H -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_load, 0, 0, 4) +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_list_load, 0, 0, 1) ZEND_ARG_INFO(0, repo) ZEND_ARG_INFO(0, blob) ZEND_ARG_INFO(0, path) @@ -103,6 +103,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_unregister, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_filter_new, 0, 0, 1) + ZEND_ARG_INFO(0, payload) +ZEND_END_ARG_INFO() + /* {{{ proto resource git_filter_list_load(repo, blob, path, mode) */ PHP_FUNCTION(git_filter_list_load); @@ -167,4 +171,8 @@ PHP_FUNCTION(git_filter_register); */ PHP_FUNCTION(git_filter_unregister); +/* {{{ proto resource git_filter_new(payload) +*/ +PHP_FUNCTION(git_filter_new); + #endif diff --git a/helper.c b/helper.c index 38f9b7b91c..f963842c7c 100644 --- a/helper.c +++ b/helper.c @@ -391,7 +391,7 @@ void php_git2_git_checkout_progress_cb(const char *path, } -static void php_git2_fcall_info_wrapper(zval *target, zend_fcall_info **out_fci, zend_fcall_info_cache **out_fcc TSRMLS_DC) +void php_git2_fcall_info_wrapper(zval *target, zend_fcall_info **out_fci, zend_fcall_info_cache **out_fcc TSRMLS_DC) { char *is_callable_error = NULL; zend_fcall_info *fci = NULL; @@ -417,6 +417,27 @@ static void php_git2_fcall_info_wrapper(zval *target, zend_fcall_info **out_fci, *out_fcc = fcc; } +void php_git2_fcall_info_wrapper2(zval *target, zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC) +{ + char *is_callable_error = NULL; + + memcpy(fci, &empty_fcall_info, sizeof(zend_fcall_info)); + memcpy(fcc, &empty_fcall_info_cache, sizeof(zend_fcall_info_cache)); + + if (zend_fcall_info_init(target, 0, fci, fcc, NULL, &is_callable_error TSRMLS_CC) == SUCCESS) { + if (is_callable_error) { + efree(is_callable_error); + } + } else { + fprintf(stderr, "FAILED"); + efree(fci); + efree(fcc); + return; + } +} + + + int php_git2_array_to_git_checkout_opts(git_checkout_opts **out, zval *array TSRMLS_DC) { const char *target_directory, *our_label, *their_label; diff --git a/helper.h b/helper.h index 06dc7db0a8..de09422ba9 100644 --- a/helper.h +++ b/helper.h @@ -94,4 +94,8 @@ int php_git2_git_diff_line_cb( void php_git2_git_transfer_progress_to_array(git_transfer_progress *progress, zval **out TSRMLS_DC); +void php_git2_fcall_info_wrapper(zval *target, zend_fcall_info **out_fci, zend_fcall_info_cache **out_fcc TSRMLS_DC); + +void php_git2_fcall_info_wrapper2(zval *target, zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC); + #endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 36954248a4..b40f257a04 100644 --- a/php_git2.c +++ b/php_git2.c @@ -105,6 +105,17 @@ void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) case PHP_GIT2_TYPE_OBJECT: git_object_free(PHP_GIT2_V(resource, object)); break; + case PHP_GIT2_TYPE_FILTER: + { + php_git2_filter *filter = (php_git2_filter*)PHP_GIT2_V(resource, filter); + zval_ptr_dtor(&filter->multi->payload); + php_git2_multi_cb_free(filter->multi); + efree(filter); + break; + } + case PHP_GIT2_TYPE_FILTER_LIST: + git_filter_list_free(PHP_GIT2_V(resource, filter_list)); + break; } } @@ -270,6 +281,9 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v case PHP_GIT2_TYPE_PUSH: PHP_GIT2_V(result, push) = (git_push*)resource; break; + case PHP_GIT2_TYPE_FILTER: + PHP_GIT2_V(result, filter) = (git_filter*)resource; + break; default: php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug."); } @@ -706,6 +720,7 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_filter_source_mode, arginfo_git_filter_source_mode) PHP_FE(git_filter_register, arginfo_git_filter_register) PHP_FE(git_filter_unregister, arginfo_git_filter_unregister) + PHP_FE(git_filter_new, arginfo_git_filter_new) /* ignore */ PHP_FE(git_ignore_add_rule, arginfo_git_ignore_add_rule) diff --git a/php_git2.h b/php_git2.h index 4e39017c7a..f59ee21f39 100644 --- a/php_git2.h +++ b/php_git2.h @@ -77,6 +77,17 @@ ZEND_EXTERN_MODULE_GLOBALS(git2) #define PHP_GIT2_RESOURCE_NAME "git2" + +#ifdef ZTS +#define GIT2_TSRMLS_SET(target) void ***tsrm_ls = target; +#define GIT2_TSRMLS_DECL void ***tsrm_ls; +#define GIT2_TSRMLS_SET2(target, value) target->tsrm_ls = value; +#else +#define GIT2_TSRMLS_SET(target) +#define GIT2_TSRMLS_SET2(target, value) +#define GIT2_TSRMLS_DECL +#endif + enum php_git2_resource_type { PHP_GIT2_TYPE_REPOSITORY, PHP_GIT2_TYPE_COMMIT, @@ -126,6 +137,7 @@ enum php_git2_resource_type { PHP_GIT2_TYPE_PUSH, PHP_GIT2_TYPE_REFSPEC, PHP_GIT2_TYPE_INDEXER, + PHP_GIT2_TYPE_FILTER, /* for conventional reason */ }; typedef struct php_git2_t { @@ -179,10 +191,36 @@ typedef struct php_git2_t { git_push *push; git_refspec *refspec; git_indexer *indexer; + git_filter *filter; } v; int should_free_v; int resource_id; int mutable; } php_git2_t; +typedef struct php_git2_cb_t { + zval *payload; + zend_fcall_info *fci; + zend_fcall_info_cache *fcc; + GIT2_TSRMLS_DECL +} php_git2_cb_t; + +typedef struct php_git2_fcall_t { + zend_fcall_info fci; + zend_fcall_info_cache fcc; + zval *value; +} php_git2_fcall_t; + +typedef struct php_git2_multi_cb_t { + int num_callbacks; + php_git2_fcall_t *callbacks; + zval *payload; + GIT2_TSRMLS_DECL +} php_git2_multi_cb_t; + +typedef struct php_git2_filter { + git_filter super; + php_git2_multi_cb_t *multi; +} php_git2_filter; + #endif /* PHP_GIT2_H */ \ No newline at end of file diff --git a/php_git2_priv.h b/php_git2_priv.h index 536243879c..b2a03a7145 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -38,16 +38,6 @@ extern int git2_resource_handle; #define GIT2_RVAL_P(git2) git2->resource_id #define GIT2_SHOULD_FREE(git2) git2->should_free_v -#ifdef ZTS -#define GIT2_TSRMLS_SET(target) void ***tsrm_ls = target; -#define GIT2_TSRMLS_DECL void ***tsrm_ls; -#define GIT2_TSRMLS_SET2(target, value) target->tsrm_ls = value; -#else -#define GIT2_TSRMLS_SET(target) -#define GIT2_TSRMLS_SET2(target, value) -#define GIT2_TSRMLS_DECL -#endif - #define PHP_GIT2_MAKE_RESOURCE(val) \ do {\ val = (php_git2_t *)emalloc(sizeof(php_git2_t));\ @@ -72,27 +62,6 @@ do {\ #define GIT2_OID_HEXSIZE (GIT_OID_HEXSZ+1) #define GIT2_BUFFER_SIZE 512 - -typedef struct php_git2_cb_t { - zval *payload; - zend_fcall_info *fci; - zend_fcall_info_cache *fcc; - GIT2_TSRMLS_DECL -} php_git2_cb_t; - -typedef struct php_git2_fcall_t { - zend_fcall_info fci; - zend_fcall_info_cache fcc; - zval *value; -} php_git2_fcall_t; - -typedef struct php_git2_multi_cb_t { - int num_callbacks; - php_git2_fcall_t *callbacks; - zval *payload; - GIT2_TSRMLS_DECL -} php_git2_multi_cb_t; - int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, void *resource, int should_free TSRMLS_DC); #include "helper.h" From 516fe0a394a2e33dab1509cdec89327933946507 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 20 Jan 2014 01:35:36 +0900 Subject: [PATCH 109/136] [status] implement git_status --- example/status.php | 68 ++++++++++++++++++++++++++ helper.c | 13 +++++ helper.h | 2 + php_git2.c | 1 + status.c | 118 ++++++++++++++++++++++++++++++++++++++++++--- status.h | 2 + 6 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 example/status.php diff --git a/example/status.php b/example/status.php new file mode 100644 index 0000000000..be7c1eed53 --- /dev/null +++ b/example/status.php @@ -0,0 +1,68 @@ +...\" to unstage)\n"); +printf("#\n"); + +$cnt = git_status_list_entrycount($list); +for ($i = 0; $i < $cnt; $i++) { + $entry = git_status_byindex($list, $i); + $flags = $entry['status']; + $stat = getStat($flags); + + if (is_array($entry['head_to_index'])) { + printf("# %15s %s\n", $stat, $entry['head_to_index']['new_file']['path']); + } +} + +printf("#\n"); +printf("# Changes not staged for commit:\n"); +printf("# (use \"git add ...\" to update what will be committed)\n"); +printf("# (use \"git checkout -- ...\" to discard changes in working directory)\n"); +printf("#\n"); + +for ($i = 0; $i < $cnt; $i++) { + $entry = git_status_byindex($list, $i); + $flags = $entry['status']; + $stat = getStat($flags); + + if (is_array($entry['index_to_workdir'])) { + printf("# %15s %s\n", $stat, $entry['index_to_workdir']['new_file']['path']); + } +} +printf("#\n"); + + +function getStat($flags) +{ + $stat = ""; + if ($flags & GIT_STATUS_IGNORED) { + return; + } + if ($flags == GIT_STATUS_CURRENT) { + return; + } + if ($flags & GIT_STATUS_INDEX_NEW){ + $stat = "new file:"; + } + if ($flags & GIT_STATUS_WT_NEW) { + $stat = "untracked:"; + } + if ($flags & GIT_STATUS_INDEX_MODIFIED ||$flags & GIT_STATUS_WT_MODIFIED) { + $stat = "modified:"; + } + if ($flags & GIT_STATUS_INDEX_DELETED || $flags & GIT_STATUS_WT_DELETED) { + $stat = "deleted:"; + } + if ($flags & GIT_STATUS_INDEX_RENAMED || $flags & GIT_STATUS_WT_RENAMED) { + $stat = "renamed:"; + } + if ($flags & GIT_STATUS_INDEX_TYPECHANGE || $flags & GIT_STATUS_WT_TYPECHANGE) { + $stat = "typechange:"; + } + return $stat; +} \ No newline at end of file diff --git a/helper.c b/helper.c index f963842c7c..79150f34a9 100644 --- a/helper.c +++ b/helper.c @@ -43,6 +43,19 @@ zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC) return result; } +long php_git2_read_arrval_long2(zval *array, char *name, size_t name_len, long value TSRMLS_DC) +{ + zval *tmp; + long result = value; + + tmp = php_git2_read_arrval(array, name, name_len TSRMLS_CC); + if (tmp) { + result = Z_LVAL_P(tmp); + } + + return result; +} + long php_git2_read_arrval_long(zval *array, char *name, size_t name_len TSRMLS_DC) { zval *tmp; diff --git a/helper.h b/helper.h index de09422ba9..424f1c3f89 100644 --- a/helper.h +++ b/helper.h @@ -32,6 +32,8 @@ int php_git2_check_error(int error_code, const char *action TSRMLS_DC); zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC); +long php_git2_read_arrval_long2(zval *array, char *name, size_t name_len, long value TSRMLS_DC); + long php_git2_read_arrval_long(zval *array, char *name, size_t name_len TSRMLS_DC); const char* php_git2_read_arrval_string(zval *array, char *name, size_t name_len TSRMLS_DC); diff --git a/php_git2.c b/php_git2.c index b40f257a04..3ba3d3e1a8 100644 --- a/php_git2.c +++ b/php_git2.c @@ -664,6 +664,7 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_status_byindex, arginfo_git_status_byindex) PHP_FE(git_status_list_free, arginfo_git_status_list_free) PHP_FE(git_status_should_ignore, arginfo_git_status_should_ignore) + PHP_FE(git_status_options_new, NULL) /* transport */ PHP_FE(git_transport_new, arginfo_git_transport_new) diff --git a/status.c b/status.c index 7b68db58f8..260e01f3da 100644 --- a/status.c +++ b/status.c @@ -2,6 +2,86 @@ #include "php_git2_priv.h" #include "status.h" +static void php_git2_git_status_options_to_array(git_status_options *options, zval **out TSRMLS_DC) +{ + zval *result, *pathspec; + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("version"), options->version); + add_assoc_long_ex(result, ZEND_STRS("show"), options->show); + add_assoc_long_ex(result, ZEND_STRS("flags"), options->flags); + php_git2_strarray_to_array(&options->pathspec, &pathspec TSRMLS_CC); + add_assoc_zval_ex(result, ZEND_STRS("pathspec"), pathspec); + + *out = result; +} + +static void php_git2_array_to_git_status_options(git_status_options *options, zval *array TSRMLS_DC) +{ + zval *tmp; + options->version = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 1 TSRMLS_CC); + options->show = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 0 TSRMLS_CC); + options->flags = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 0 TSRMLS_CC); + + php_git2_array_to_strarray(&options->pathspec, php_git2_read_arrval(array, ZEND_STRS("pathspec") TSRMLS_CC) TSRMLS_CC); +} + +static void php_git2_git_status_entry_to_array(git_status_entry *entry, zval **out TSRMLS_DC) +{ + zval *result, *head_to_index, *index_to_workdir; + + MAKE_STD_ZVAL(result); + array_init(result); + + if (entry->head_to_index) { + php_git2_diff_delta_to_array(entry->head_to_index, &head_to_index TSRMLS_CC); + } else { + MAKE_STD_ZVAL(head_to_index); + ZVAL_NULL(head_to_index); + } + + if (entry->index_to_workdir) { + php_git2_diff_delta_to_array(entry->index_to_workdir, &index_to_workdir TSRMLS_CC); + } else { + MAKE_STD_ZVAL(index_to_workdir); + ZVAL_NULL(index_to_workdir); + } + + add_assoc_long_ex(result, ZEND_STRS("status"), entry->status); + add_assoc_zval_ex(result, ZEND_STRS("head_to_index"), head_to_index); + add_assoc_zval_ex(result, ZEND_STRS("index_to_workdir"), index_to_workdir); + + *out = result; +} + +static int php_git2_git_status_cb( + const char *path, unsigned int status_flags, void *payload) +{ + php_git2_t *result; + zval *param_path, *param_status_flags, *retval_ptr = NULL; + php_git2_cb_t *p = (php_git2_cb_t*)payload; + int i = 0; + long retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_path); + MAKE_STD_ZVAL(param_status_flags); + ZVAL_STRING(param_path, path, 1); + ZVAL_LONG(param_status_flags, status_flags); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, + ¶m_path, ¶m_status_flags, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + /* {{{ proto long git_status_foreach(resource $repo, Callable $callback, $payload) */ PHP_FUNCTION(git_status_foreach) @@ -12,7 +92,7 @@ PHP_FUNCTION(git_status_foreach) zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; php_git2_cb_t *cb = NULL; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; @@ -22,7 +102,7 @@ PHP_FUNCTION(git_status_foreach) if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { RETURN_FALSE; } - //result = git_status_foreach(PHP_GIT2_V(_repo, repository), , cb); + result = git_status_foreach(PHP_GIT2_V(_repo, repository), php_git2_git_status_cb, cb); php_git2_cb_free(cb); RETURN_LONG(result); } @@ -38,18 +118,23 @@ PHP_FUNCTION(git_status_foreach_ext) zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; php_git2_cb_t *cb = NULL; + git_status_options options = GIT_STATUS_OPTIONS_INIT; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rfz", &repo, &opts, &fci, &fcc, &payload) == FAILURE) { + "rafz", &repo, &opts, &fci, &fcc, &payload) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); + php_git2_array_to_git_status_options(&options, opts TSRMLS_CC); if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { RETURN_FALSE; } - //result = git_status_foreach_ext(PHP_GIT2_V(_repo, repository), opts, , cb); + result = git_status_foreach_ext(PHP_GIT2_V(_repo, repository), &options, php_git2_git_status_cb, cb); php_git2_cb_free(cb); + if (options.pathspec.count > 0) { + php_git2_strarray_free(&options.pathspec); + } RETURN_LONG(result); } /* }}} */ @@ -82,15 +167,20 @@ PHP_FUNCTION(git_status_list_new) php_git2_t *result = NULL, *_repo = NULL; git_status_list *out = NULL; zval *repo = NULL, *opts = NULL; + git_status_options options = GIT_STATUS_OPTIONS_INIT; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &repo, &opts) == FAILURE) { + "ra", &repo, &opts) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - error = git_status_list_new(&out, PHP_GIT2_V(_repo, repository), opts); + php_git2_array_to_git_status_options(&options, opts TSRMLS_CC); + error = git_status_list_new(&out, PHP_GIT2_V(_repo, repository), &options); + if (options.pathspec.count > 0) { + php_git2_strarray_free(&options.pathspec); + } if (php_git2_check_error(error, "git_status_list_new" TSRMLS_CC)) { RETURN_FALSE; } @@ -125,7 +215,7 @@ PHP_FUNCTION(git_status_list_entrycount) PHP_FUNCTION(git_status_byindex) { const git_status_entry *result = NULL; - zval *statuslist = NULL; + zval *statuslist = NULL, *out; php_git2_t *_statuslist = NULL; long idx = 0; @@ -136,7 +226,11 @@ PHP_FUNCTION(git_status_byindex) ZEND_FETCH_RESOURCE(_statuslist, php_git2_t*, &statuslist, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_status_byindex(PHP_GIT2_V(_statuslist, status_list), idx); - /* TODO(chobie): implement this */ + if (result == NULL) { + RETURN_FALSE; + } + php_git2_git_status_entry_to_array(result, &out TSRMLS_CC); + RETURN_ZVAL(out, 0, 1); } /* }}} */ @@ -182,3 +276,11 @@ PHP_FUNCTION(git_status_should_ignore) } /* }}} */ +PHP_FUNCTION(git_status_options_new) +{ + git_status_options options = GIT_STATUS_OPTIONS_INIT; + zval *result; + + php_git2_git_status_options_to_array(&options, &result TSRMLS_CC); + RETURN_ZVAL(result, 0, 1); +} \ No newline at end of file diff --git a/status.h b/status.h index bc5e8274b5..8ff95a1e16 100644 --- a/status.h +++ b/status.h @@ -101,4 +101,6 @@ PHP_FUNCTION(git_status_list_free); */ PHP_FUNCTION(git_status_should_ignore); +PHP_FUNCTION(git_status_options_new); + #endif \ No newline at end of file From c02db9d7fed98b9283b895cac6a233c6a4b892a6 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 20 Jan 2014 02:21:41 +0900 Subject: [PATCH 110/136] [submodule] implement submodule functions --- example/submodule.php | 9 +++++ submodule.c | 84 +++++++++++++++++++++++++++++++------------ submodule.h | 5 ++- 3 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 example/submodule.php diff --git a/example/submodule.php b/example/submodule.php new file mode 100644 index 0000000000..23313573fe --- /dev/null +++ b/example/submodule.php @@ -0,0 +1,9 @@ +tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_sm); + MAKE_STD_ZVAL(param_name); + if (php_git2_make_resource(&submodule, PHP_GIT2_TYPE_SUBMODULE, sm, 0 TSRMLS_CC)) { + return GIT_EUSER; + } + ZVAL_RESOURCE(param_sm, GIT2_RVAL_P(submodule)); + + ZVAL_STRING(param_name, name, 1); + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 3, + ¶m_sm, ¶m_name, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; + + +} + /* {{{ proto long git_submodule_lookup(resource $repo, string $name) */ PHP_FUNCTION(git_submodule_lookup) @@ -9,7 +39,7 @@ PHP_FUNCTION(git_submodule_lookup) int result = 0, name_len = 0, error = 0; git_submodule *submodule = NULL; zval *repo = NULL; - php_git2_t *_repo = NULL; + php_git2_t *_repo = NULL, *_result = NULL; char *name = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -19,27 +49,35 @@ PHP_FUNCTION(git_submodule_lookup) ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_submodule_lookup(&submodule, PHP_GIT2_V(_repo, repository), name); - RETURN_LONG(result); + if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_SUBMODULE, submodule, 0 TSRMLS_CC)) { + RETURN_FALSE; + } + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result)); } /* }}} */ -/* {{{ proto long git_submodule_foreach(resource $repo, long $sm, string $name, $payload) +/* {{{ proto long git_submodule_foreach(resource $repo, Callable $callback, $payload) */ PHP_FUNCTION(git_submodule_foreach) { int result = 0, name_len = 0, error = 0; zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; - long sm = 0; - char *name = NULL; - + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; + php_git2_cb_t *cb = NULL; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rls", &repo, &sm, &name, &name_len, &payload) == FAILURE) { + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - //result = git_submodule_foreach(PHP_GIT2_V(_repo, repository), sm, name, cb); + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { + RETURN_FALSE; + } + result = git_submodule_foreach(PHP_GIT2_V(_repo, repository), php_git2_git_submodule_foreach_cb, cb); + php_git2_cb_free(cb); RETURN_LONG(result); } /* }}} */ @@ -139,7 +177,7 @@ PHP_FUNCTION(git_submodule_owner) ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_submodule_owner(PHP_GIT2_V(_submodule, submodule)); - if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_SUBMODULE, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_REPOSITORY, result, 0 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result)); @@ -223,7 +261,7 @@ PHP_FUNCTION(git_submodule_set_url) } /* }}} */ -/* {{{ proto resource git_submodule_index_id(resource $submodule) +/* {{{ proto string git_submodule_index_id(resource $submodule) */ PHP_FUNCTION(git_submodule_index_id) { @@ -244,7 +282,7 @@ PHP_FUNCTION(git_submodule_index_id) } /* }}} */ -/* {{{ proto resource git_submodule_head_id(resource $submodule) +/* {{{ proto string git_submodule_head_id(resource $submodule) */ PHP_FUNCTION(git_submodule_head_id) { @@ -265,7 +303,7 @@ PHP_FUNCTION(git_submodule_head_id) } /* }}} */ -/* {{{ proto resource git_submodule_wd_id(resource $submodule) +/* {{{ proto string git_submodule_wd_id(resource $submodule) */ PHP_FUNCTION(git_submodule_wd_id) { @@ -286,7 +324,7 @@ PHP_FUNCTION(git_submodule_wd_id) } /* }}} */ -/* {{{ proto resource git_submodule_ignore(resource $submodule) +/* {{{ proto long git_submodule_ignore(resource $submodule) */ PHP_FUNCTION(git_submodule_ignore) { @@ -301,26 +339,27 @@ PHP_FUNCTION(git_submodule_ignore) ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_submodule_ignore(PHP_GIT2_V(_submodule, submodule)); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ -/* {{{ proto resource git_submodule_set_ignore(resource $submodule, $ignore) +/* {{{ proto long git_submodule_set_ignore(resource $submodule, $ignore) */ PHP_FUNCTION(git_submodule_set_ignore) { git_submodule_ignore_t *result = NULL; - zval *submodule = NULL, *ignore = NULL; + zval *submodule = NULL; php_git2_t *_submodule = NULL; + long ignore = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &submodule, &ignore) == FAILURE) { + "rl", &submodule, &ignore) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_submodule_set_ignore(PHP_GIT2_V(_submodule, submodule), ignore); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ @@ -339,7 +378,7 @@ PHP_FUNCTION(git_submodule_update) ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_submodule_update(PHP_GIT2_V(_submodule, submodule)); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ @@ -348,17 +387,18 @@ PHP_FUNCTION(git_submodule_update) PHP_FUNCTION(git_submodule_set_update) { git_submodule_update_t *result = NULL; - zval *submodule = NULL, *update = NULL; + zval *submodule = NULL; php_git2_t *_submodule = NULL; + long update = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "r", &submodule, &update) == FAILURE) { + "rl", &submodule, &update) == FAILURE) { return; } ZEND_FETCH_RESOURCE(_submodule, php_git2_t*, &submodule, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_submodule_set_update(PHP_GIT2_V(_submodule, submodule), update); - /* TODO(chobie): implement this */ + RETURN_LONG(result); } /* }}} */ diff --git a/submodule.h b/submodule.h index 8459e42c18..a7439e53ed 100644 --- a/submodule.h +++ b/submodule.h @@ -31,10 +31,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_lookup, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_foreach, 0, 0, 5) +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_submodule_foreach, 0, 0, 3) ZEND_ARG_INFO(0, repo) - ZEND_ARG_INFO(0, sm) - ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, callback) ZEND_ARG_INFO(1, payload) ZEND_END_ARG_INFO() From 77de574407f45dd94275979c1c1326cc2807ec08 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 20 Jan 2014 04:27:52 +0900 Subject: [PATCH 111/136] [odb] wip: backend --- example/odb_backend.php | 66 ++++++++++++++ odb.c | 191 +++++++++++++++++++++++++++++++++++++++- odb.h | 6 ++ php_git2.c | 10 +++ php_git2.h | 6 ++ repository.c | 14 +-- 6 files changed, 284 insertions(+), 9 deletions(-) create mode 100644 example/odb_backend.php diff --git a/example/odb_backend.php b/example/odb_backend.php new file mode 100644 index 0000000000..8dc10bb087 --- /dev/null +++ b/example/odb_backend.php @@ -0,0 +1,66 @@ + function($oid){ + echo "\e[32m# read $oid\e[m\n"; + return array( + Pool::$pool[$oid][0], + Pool::$pool[$oid][1], + ); + }, + "read_prefix" => function(){ + echo "Helo WOrld"; + + }, + "read_header" => function() { + echo "Helo WOrld"; + + }, + "write" => function($oid, $buffer, $otype) { + echo "\e[32m# write $oid\e[m\n"; + Pool::$pool[$oid] = array($buffer, $otype); + }, + "writestream" => function() { + + }, + "readstream" => function() { + + }, + "exists" => function($oid) { + $retval = 0; + if (isset(Pool::$pool[$oid])) { + $retval = 1; + } + + echo "\e[32m# exists $retval\e[m\n"; + + return $retval; + }, + "refresh" => function() { + + }, + "foreach" => function() { + + }, + "writepack" => function() { + + }, + "free" => function() { + } +); +$memory_backend = git_odb_backend_new($a); + +$repo = git_repository_open("."); +$odb = git_repository_odb($repo); +git_odb_add_backend($odb, $memory_backend, 1000); + +$oid = git_odb_write($odb, "Helo World(php memory backend)", GIT_OBJ_BLOB); +$obj = git_odb_read($odb, $oid); + +echo git_odb_object_data($obj); +exit; diff --git a/odb.c b/odb.c index 71bdd4059f..13079553ca 100644 --- a/odb.c +++ b/odb.c @@ -107,7 +107,7 @@ PHP_FUNCTION(git_odb_read) if (git_oid_fromstrn(&__id, id, id_len)) { RETURN_FALSE; } - error = git_odb_read(&out, PHP_GIT2_V(_db, odb),& __id); + error = git_odb_read(&out, PHP_GIT2_V(_db, odb),&__id); if (php_git2_check_error(error, "git_odb_read" TSRMLS_CC)) { RETURN_FALSE; } @@ -568,6 +568,7 @@ PHP_FUNCTION(git_odb_object_data) { zval *object = NULL; php_git2_t *_object = NULL; + const char *buffer; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &object) == FAILURE) { @@ -575,7 +576,8 @@ PHP_FUNCTION(git_odb_object_data) } ZEND_FETCH_RESOURCE(_object, php_git2_t*, &object, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - git_odb_object_data(PHP_GIT2_V(_object, odb_object)); + buffer = git_odb_object_data(PHP_GIT2_V(_object, odb_object)); + RETURN_STRINGL(buffer, git_odb_object_size(PHP_GIT2_V(_object, odb_object)), 1); } /* }}} */ @@ -705,3 +707,188 @@ PHP_FUNCTION(git_odb_get_backend) } /* }}} */ +static int php_git2_odb_backend_read(void **buffer, size_t *size, git_otype *type, git_odb_backend *backend, const git_oid *oid) +{ + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; + zval *param_oid = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + char buf[41] = {0}; + + git_oid_fmt(buf, oid); + MAKE_STD_ZVAL(param_oid); + ZVAL_STRING(param_oid, buf, 1); + + if (php_git2_call_function_v(&p->callbacks[0].fci, &p->callbacks[0].fcc TSRMLS_CC, &retval_ptr, 1, ¶m_oid)) { + return GIT_EUSER; + } + if (Z_TYPE_P(retval_ptr) == IS_ARRAY) { + zval **value, **otype; + char *pp; + + if (zend_hash_num_elements(Z_ARRVAL_P(retval_ptr)) != 2) { + return GIT_ENOTFOUND; + } + + zend_hash_get_current_data(Z_ARRVAL_P(retval_ptr), (void **)&value); + pp = git_odb_backend_malloc(backend, Z_STRLEN_PP(value)); + memset(pp, '\0', Z_STRLEN_PP(value)); + memcpy(pp, Z_STRVAL_PP(value), Z_STRLEN_PP(value)); + + *buffer = pp; + *size = Z_STRLEN_PP(value); + + zend_hash_move_forward(Z_ARRVAL_P(retval_ptr)); + zend_hash_get_current_data(Z_ARRVAL_P(retval_ptr), (void **)&otype); + *type = Z_LVAL_PP(otype); + } else { + retval = GIT_ENOTFOUND; + } + + zval_ptr_dtor(&retval_ptr); + return retval; +} +static int php_git2_odb_backend_write(git_odb_backend *backend, const git_oid *oid, const void *buffer, size_t size, git_otype type) +{ + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; + zval *param_oid = NULL, *param_buffer = NULL, *param_otype = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + char buf[41] = {0}; + + git_oid_fmt(buf, oid); + MAKE_STD_ZVAL(param_oid); + MAKE_STD_ZVAL(param_buffer); + MAKE_STD_ZVAL(param_otype); + + ZVAL_STRING(param_oid, buf, 1); + ZVAL_STRINGL(param_buffer, buffer, size, 1); + ZVAL_LONG(param_otype, type); + + if (php_git2_call_function_v(&p->callbacks[1].fci, &p->callbacks[1].fcc TSRMLS_CC, &retval_ptr, 3, + ¶m_oid, ¶m_buffer, ¶m_otype)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} +static int php_git2_odb_backend_read_prefix(git_oid *out_oid, + void **buffer_p, + size_t *len_p, + git_otype *type_p, + git_odb_backend *backend, + const git_oid *short_oid, + size_t len) +{ + fprintf(stderr, "READ_PREFIX"); +} + +static int php_git2_odb_backend_read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) +{ +} +static int php_git2_odb_backend_writestream(git_odb_stream **stream_out, git_odb_backend *_backend, size_t length, git_otype type) +{ + fprintf(stderr, "WRITES"); +} +static int php_git2_odb_backend_exists(git_odb_backend *backend, const git_oid *oid) +{ + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; + zval *param_oid = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + char buf[41] = {0}; + + git_oid_fmt(buf, oid); + MAKE_STD_ZVAL(param_oid); + ZVAL_STRING(param_oid, buf, 1); + + if (php_git2_call_function_v(&p->callbacks[5].fci, &p->callbacks[5].fcc TSRMLS_CC, &retval_ptr, 1, + ¶m_oid)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + if (retval == 1) { + retval = 0; + } else { + retval = GIT_ENOTFOUND; + } + zval_ptr_dtor(&retval_ptr); + return !retval; + +} +static int php_git2_odb_backend_foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data) +{ +} +static void php_git2_odb_backend_free(git_odb_backend *_backend) +{ +} + +PHP_FUNCTION(git_odb_backend_new) +{ + php_git2_odb_backend *backend; + php_git2_t *result; + zval *callbacks, *tmp; + zend_fcall_info read_fci, write_fci, read_prefix_fci, read_header_fci, writestream_fci, + exists_fci, foreach_fci, free_fci; + zend_fcall_info_cache read_fcc, write_fcc, read_prefix_fcc, read_header_fcc, writestream_fcc, + exists_fcc, foreach_fcc, free_fcc; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "a", &callbacks) == FAILURE) { + return; + } + + backend = ecalloc(1, sizeof(php_git2_odb_backend)); + + backend->parent.version = GIT_ODB_BACKEND_VERSION; + backend->parent.read = &php_git2_odb_backend_read; + backend->parent.write = &php_git2_odb_backend_write; + backend->parent.read_prefix = &php_git2_odb_backend_read_prefix; + backend->parent.read_header = &php_git2_odb_backend_read_header; + backend->parent.writestream = &php_git2_odb_backend_writestream; + backend->parent.exists = &php_git2_odb_backend_exists; + backend->parent.foreach = &php_git2_odb_backend_foreach; + backend->parent.free = &php_git2_odb_backend_free; + + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("read") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &read_fci, &read_fcc TSRMLS_CC); + } + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("write") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &write_fci, &write_fcc TSRMLS_CC); + } + + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("exists") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &exists_fci, &exists_fcc TSRMLS_CC); + } + + + Z_ADDREF_P(callbacks); + php_git2_multi_cb_init(&backend->multi, callbacks TSRMLS_CC, 8, + &read_fci, &read_fcc, + &write_fci, &write_fcc, + &read_prefix_fci, &read_prefix_fcc, + &read_header_fci, &read_header_fcc, + &writestream_fci, &writestream_fcc, + &exists_fci, &exists_fcc, + &foreach_fci, &foreach_fcc, + &free_fci, &free_fcc + ); + + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_BACKEND, backend, 1 TSRMLS_CC)) { + RETURN_FALSE; + } + + ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); +} \ No newline at end of file diff --git a/odb.h b/odb.h index cadf753809..0adbe34029 100644 --- a/odb.h +++ b/odb.h @@ -173,6 +173,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_get_backend, 0, 0, 2) ZEND_ARG_INFO(0, pos) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_backend_new, 0, 0, 1) + ZEND_ARG_INFO(0, callbacks) +ZEND_END_ARG_INFO() + /* {{{ proto resource git_odb_new() */ PHP_FUNCTION(git_odb_new); @@ -293,4 +297,6 @@ PHP_FUNCTION(git_odb_num_backends); */ PHP_FUNCTION(git_odb_get_backend); +PHP_FUNCTION(git_odb_backend_new); + #endif \ No newline at end of file diff --git a/php_git2.c b/php_git2.c index 3ba3d3e1a8..4f09d0223f 100644 --- a/php_git2.c +++ b/php_git2.c @@ -116,6 +116,14 @@ void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) case PHP_GIT2_TYPE_FILTER_LIST: git_filter_list_free(PHP_GIT2_V(resource, filter_list)); break; + case PHP_GIT2_TYPE_ODB_BACKEND: + { + php_git2_odb_backend *backend = (php_git2_odb_backend*)PHP_GIT2_V(resource, odb_backend); + zval_ptr_dtor(&backend->multi->payload); + php_git2_multi_cb_free(backend->multi); + efree(PHP_GIT2_V(resource, odb_backend)); + break; + } } } @@ -846,6 +854,8 @@ static zend_function_entry php_git2_functions[] = { PHP_FE(git_odb_num_backends, arginfo_git_odb_num_backends) PHP_FE(git_odb_get_backend, arginfo_git_odb_get_backend) + PHP_FE(git_odb_backend_new, arginfo_git_odb_backend_new) + /* reflog */ PHP_FE(git_reflog_read, arginfo_git_reflog_read) PHP_FE(git_reflog_write, arginfo_git_reflog_write) diff --git a/php_git2.h b/php_git2.h index f59ee21f39..f26a1c0fd8 100644 --- a/php_git2.h +++ b/php_git2.h @@ -52,6 +52,7 @@ #include "git2/odb_backend.h" #include "git2/trace.h" #include "git2/sys/filter.h" +#include "git2/sys/odb_backend.h" #include "date/php_date.h" @@ -223,4 +224,9 @@ typedef struct php_git2_filter { php_git2_multi_cb_t *multi; } php_git2_filter; +typedef struct php_git2_odb_backend { + git_odb_backend parent; + php_git2_multi_cb_t *multi; +} php_git2_odb_backend; + #endif /* PHP_GIT2_H */ \ No newline at end of file diff --git a/repository.c b/repository.c index 9504603b88..3ecb51f088 100644 --- a/repository.c +++ b/repository.c @@ -287,7 +287,7 @@ PHP_FUNCTION(git_repository_wrap_odb) if (php_git2_check_error(error, "git_repository_wrap_odb" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); @@ -343,7 +343,7 @@ PHP_FUNCTION(git_repository_open_ext) if (php_git2_check_error(error, "git_repository_open_ext" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); @@ -392,7 +392,7 @@ PHP_FUNCTION(git_repository_init_ext) if (php_git2_check_error(error, "git_repository_init_ext" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REPOSITORY, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); @@ -420,7 +420,7 @@ PHP_FUNCTION(git_repository_head) if (php_git2_check_error(error, "git_repository_head" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFERENCE, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); @@ -573,7 +573,7 @@ PHP_FUNCTION(git_repository_config) if (php_git2_check_error(error, "git_repository_config" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CONFIG, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_CONFIG, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); @@ -601,7 +601,7 @@ PHP_FUNCTION(git_repository_odb) if (php_git2_check_error(error, "git_repository_odb" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); @@ -629,7 +629,7 @@ PHP_FUNCTION(git_repository_refdb) if (php_git2_check_error(error, "git_repository_refdb" TSRMLS_CC)) { RETURN_FALSE; } - if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFDB, result, 1 TSRMLS_CC)) { + if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFDB, out, 1 TSRMLS_CC)) { RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); From 5d5a4ef05910f56ab8078dc7336fbc3e7d5c561d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 20 Jan 2014 14:23:58 +0900 Subject: [PATCH 112/136] [odb_backend] add read_header callback --- README.md | 2 +- example/odb_backend.php | 23 ++++++++++++++----- odb.c | 50 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e96c64d5c4..829a68e3f0 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ https://docs.google.com/spreadsheet/ccc?key=0AjvShWAWqvfHdDRneEtIUF9GRUZMNVVVR1h git submodule init && git submodule update mkdir libgit2/build cd libgit2/build -cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF . +cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF .. cmake --build . # build php-git2 diff --git a/example/odb_backend.php b/example/odb_backend.php index 8dc10bb087..fe34a9e759 100644 --- a/example/odb_backend.php +++ b/example/odb_backend.php @@ -13,13 +13,20 @@ class Pool Pool::$pool[$oid][1], ); }, - "read_prefix" => function(){ - echo "Helo WOrld"; - + "read_prefix" => function($short_oid){ + echo "Helo World"; + return array( + "Buffer", + "type", + "actual_oid", + ); }, - "read_header" => function() { - echo "Helo WOrld"; - + "read_header" => function($oid) { + echo "\e[32m# read header$oid\e[m\n"; + return array( + strlen(Pool::$pool[$oid][0]), + Pool::$pool[$oid][1], + ); }, "write" => function($oid, $buffer, $otype) { echo "\e[32m# write $oid\e[m\n"; @@ -63,4 +70,8 @@ class Pool $obj = git_odb_read($odb, $oid); echo git_odb_object_data($obj); +echo "\n"; + +$header = git_odb_read_header($odb, $oid); +var_dump($header); // size, otype exit; diff --git a/odb.c b/odb.c index 13079553ca..d8b582b36c 100644 --- a/odb.c +++ b/odb.c @@ -156,13 +156,14 @@ PHP_FUNCTION(git_odb_read_header) { php_git2_t *result = NULL, *_db = NULL; size_t len_out = NULL; - zval *type_out = NULL, *db = NULL; + zval *db = NULL, *_result = NULL; + git_otype type_out; char *id = NULL; int id_len = 0, error = 0; git_oid __id = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &type_out, &db, &id, &id_len) == FAILURE) { + "rs", &db, &id, &id_len) == FAILURE) { return; } @@ -170,11 +171,15 @@ PHP_FUNCTION(git_odb_read_header) if (git_oid_fromstrn(&__id, id, id_len)) { RETURN_FALSE; } - error = git_odb_read_header(&len_out, type_out, PHP_GIT2_V(_db, odb), &__id); + error = git_odb_read_header(&len_out, &type_out, PHP_GIT2_V(_db, odb), &__id); if (php_git2_check_error(error, "git_odb_read_header" TSRMLS_CC)) { RETURN_FALSE; } - RETURN_LONG(len_out); + MAKE_STD_ZVAL(_result); + array_init(_result); + add_next_index_long(_result, len_out); + add_next_index_long(_result, type_out); + RETURN_ZVAL(_result, 0, 1); } /* }}} */ @@ -791,6 +796,39 @@ static int php_git2_odb_backend_read_prefix(git_oid *out_oid, static int php_git2_odb_backend_read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) { + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; + zval *param_oid = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + char buf[41] = {0}; + + git_oid_fmt(buf, oid); + MAKE_STD_ZVAL(param_oid); + ZVAL_STRING(param_oid, buf, 1); + + if (php_git2_call_function_v(&p->callbacks[3].fci, &p->callbacks[3].fcc TSRMLS_CC, &retval_ptr, 1, ¶m_oid)) { + return GIT_EUSER; + } + if (Z_TYPE_P(retval_ptr) == IS_ARRAY) { + zval **value, **otype; + + if (zend_hash_num_elements(Z_ARRVAL_P(retval_ptr)) != 2) { + return GIT_ENOTFOUND; + } + + zend_hash_get_current_data(Z_ARRVAL_P(retval_ptr), (void **)&value); + *len_p = Z_LVAL_PP(value); + zend_hash_move_forward(Z_ARRVAL_P(retval_ptr)); + zend_hash_get_current_data(Z_ARRVAL_P(retval_ptr), (void **)&otype); + *type_p = Z_LVAL_PP(otype); + } else { + retval = GIT_ENOTFOUND; + } + + zval_ptr_dtor(&retval_ptr); + return retval; } static int php_git2_odb_backend_writestream(git_odb_stream **stream_out, git_odb_backend *_backend, size_t length, git_otype type) { @@ -868,6 +906,10 @@ PHP_FUNCTION(git_odb_backend_new) php_git2_fcall_info_wrapper2(tmp, &write_fci, &write_fcc TSRMLS_CC); } + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("read_header") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &read_header_fci, &read_header_fcc TSRMLS_CC); + } tmp = php_git2_read_arrval(callbacks, ZEND_STRS("exists") TSRMLS_CC); if (tmp) { php_git2_fcall_info_wrapper2(tmp, &exists_fci, &exists_fcc TSRMLS_CC); From 1aa83959b7dc2baa09abe5bfa67b14785f761e5e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 20 Jan 2014 16:47:17 +0900 Subject: [PATCH 113/136] [odb_backend] add read_prefix callback --- example/odb_backend.php | 21 ++++++++++--- odb.c | 70 +++++++++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/example/odb_backend.php b/example/odb_backend.php index fe34a9e759..cb686dbfa7 100644 --- a/example/odb_backend.php +++ b/example/odb_backend.php @@ -14,11 +14,20 @@ class Pool ); }, "read_prefix" => function($short_oid){ - echo "Helo World"; + echo "\e[32m# read_prefix $short_oid\e[m\n"; + + $actual_oid = null; + foreach (Pool::$pool as $key => $value) { + if (preg_match("/^{$short_oid}/", $key)) { + $actual_oid = $key; + break; + } + } + return array( - "Buffer", - "type", - "actual_oid", + Pool::$pool[$actual_oid][0], + Pool::$pool[$actual_oid][1], + $actual_oid, ); }, "read_header" => function($oid) { @@ -45,7 +54,6 @@ class Pool } echo "\e[32m# exists $retval\e[m\n"; - return $retval; }, "refresh" => function() { @@ -74,4 +82,7 @@ class Pool $header = git_odb_read_header($odb, $oid); var_dump($header); // size, otype + +$obj = git_odb_read_prefix($odb, substr($oid, 0, 10)); +var_dump($obj); exit; diff --git a/odb.c b/odb.c index d8b582b36c..cfd323c0cb 100644 --- a/odb.c +++ b/odb.c @@ -118,7 +118,7 @@ PHP_FUNCTION(git_odb_read) } /* }}} */ -/* {{{ proto resource git_odb_read_prefix(resource $db, string $short_id, long $len) +/* {{{ proto resource git_odb_read_prefix(resource $db, string $short_id) */ PHP_FUNCTION(git_odb_read_prefix) { @@ -131,7 +131,7 @@ PHP_FUNCTION(git_odb_read_prefix) long len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rsl", &db, &short_id, &short_id_len, &len) == FAILURE) { + "rs", &db, &short_id, &short_id_len) == FAILURE) { return; } @@ -139,7 +139,7 @@ PHP_FUNCTION(git_odb_read_prefix) if (git_oid_fromstrn(&__short_id, short_id, short_id_len)) { RETURN_FALSE; } - error = git_odb_read_prefix(&out, PHP_GIT2_V(_db, odb), &__short_id, len); + error = git_odb_read_prefix(&out, PHP_GIT2_V(_db, odb), &__short_id, short_id_len); if (php_git2_check_error(error, "git_odb_read_prefix" TSRMLS_CC)) { RETURN_FALSE; } @@ -784,14 +784,60 @@ static int php_git2_odb_backend_write(git_odb_backend *backend, const git_oid *o return retval; } static int php_git2_odb_backend_read_prefix(git_oid *out_oid, - void **buffer_p, - size_t *len_p, - git_otype *type_p, - git_odb_backend *backend, - const git_oid *short_oid, - size_t len) + void **buffer_p, + size_t *len_p, + git_otype *type_p, + git_odb_backend *backend, + const git_oid *short_oid, + size_t len) { - fprintf(stderr, "READ_PREFIX"); + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; + zval *param_short_oid = NULL, *retval_ptr = NULL; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + char buf[41] = {0}; + + git_oid_nfmt(buf, len, short_oid); + MAKE_STD_ZVAL(param_short_oid); + ZVAL_STRING(param_short_oid, buf, 1); + + if (php_git2_call_function_v(&p->callbacks[2].fci, &p->callbacks[2].fcc TSRMLS_CC, &retval_ptr, 1, ¶m_short_oid)) { + return GIT_EUSER; + } + + if (Z_TYPE_P(retval_ptr) == IS_ARRAY) { + zval **value, **otype, **_oid; + char *pp; + + if (zend_hash_num_elements(Z_ARRVAL_P(retval_ptr)) != 3) { + return GIT_ENOTFOUND; + } + + zend_hash_get_current_data(Z_ARRVAL_P(retval_ptr), (void **)&value); + pp = git_odb_backend_malloc(backend, Z_STRLEN_PP(value)); + memset(pp, '\0', Z_STRLEN_PP(value)); + memcpy(pp, Z_STRVAL_PP(value), Z_STRLEN_PP(value)); + + *buffer_p = pp; + *len_p = Z_STRLEN_PP(value); + + zend_hash_move_forward(Z_ARRVAL_P(retval_ptr)); + zend_hash_get_current_data(Z_ARRVAL_P(retval_ptr), (void **)&otype); + *type_p = Z_LVAL_PP(otype); + + zend_hash_move_forward(Z_ARRVAL_P(retval_ptr)); + zend_hash_get_current_data(Z_ARRVAL_P(retval_ptr), (void **)&_oid); + if (git_oid_fromstrn(out_oid, Z_STRVAL_PP(_oid), Z_STRLEN_PP(_oid)) != GIT_OK) { + return GIT_EUSER; + } + } else { + retval = GIT_ENOTFOUND; + } + + zval_ptr_dtor(&retval_ptr); + return retval; } static int php_git2_odb_backend_read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) @@ -910,6 +956,10 @@ PHP_FUNCTION(git_odb_backend_new) if (tmp) { php_git2_fcall_info_wrapper2(tmp, &read_header_fci, &read_header_fcc TSRMLS_CC); } + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("read_prefix") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &read_prefix_fci, &read_prefix_fcc TSRMLS_CC); + } tmp = php_git2_read_arrval(callbacks, ZEND_STRS("exists") TSRMLS_CC); if (tmp) { php_git2_fcall_info_wrapper2(tmp, &exists_fci, &exists_fcc TSRMLS_CC); From 2d352b36986bd0ac76a0e6977296634a2acaf90c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 21 Jan 2014 13:04:30 +0900 Subject: [PATCH 114/136] [odb] add foreach callback --- example/odb_foreach.php | 8 ++++++++ odb.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 example/odb_foreach.php diff --git a/example/odb_foreach.php b/example/odb_foreach.php new file mode 100644 index 0000000000..f3655fb318 --- /dev/null +++ b/example/odb_foreach.php @@ -0,0 +1,8 @@ +tsrm_ls) + + Z_ADDREF_P(p->payload); + MAKE_STD_ZVAL(param_oid); + + git_oid_fmt(buf, id); + ZVAL_STRING(param_oid, buf, 1); + + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_oid, &p->payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; +} + /* {{{ proto resource git_odb_new() */ PHP_FUNCTION(git_odb_new) @@ -246,8 +271,7 @@ PHP_FUNCTION(git_odb_foreach) if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { RETURN_FALSE; } - // TODO(chobie): implment callback */ - //result = git_odb_foreach(PHP_GIT2_V(_db, odb), , cb); + result = git_odb_foreach(PHP_GIT2_V(_db, odb), php_git2_git_odb_foreach_cb, cb); php_git2_cb_free(cb); RETURN_LONG(result); } @@ -964,6 +988,10 @@ PHP_FUNCTION(git_odb_backend_new) if (tmp) { php_git2_fcall_info_wrapper2(tmp, &exists_fci, &exists_fcc TSRMLS_CC); } + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("foreach") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &foreach_fci, &foreach_fcc TSRMLS_CC); + } Z_ADDREF_P(callbacks); From 50d095bf810c6e8bf906715c06a3e3f463f96278 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 21 Jan 2014 13:34:59 +0900 Subject: [PATCH 115/136] [odb] wip: backend_foreach_callback --- example/odb_backend.php | 15 +++++++++++++-- odb.c | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/example/odb_backend.php b/example/odb_backend.php index cb686dbfa7..6b269f50d7 100644 --- a/example/odb_backend.php +++ b/example/odb_backend.php @@ -59,8 +59,13 @@ class Pool "refresh" => function() { }, - "foreach" => function() { - + "foreach" => function($foreach_cb, &$payload) { // this payload was passed by git_odb_foreach callback. + foreach (Pool::$pool as $oid => $value) { + $retval = $foreach_cb($oid, $payload); + if ($retval == GIT_EUSER) { + return $retval; + } + } }, "writepack" => function() { @@ -85,4 +90,10 @@ class Pool $obj = git_odb_read_prefix($odb, substr($oid, 0, 10)); var_dump($obj); + + +$payload = array(); +git_odb_foreach($odb, function($oid, &$payload) { + echo $oid . PHP_EOL; +}, $payload); exit; diff --git a/odb.c b/odb.c index 5396e2d141..86452e824f 100644 --- a/odb.c +++ b/odb.c @@ -933,8 +933,27 @@ static int php_git2_odb_backend_exists(git_odb_backend *backend, const git_oid * return !retval; } -static int php_git2_odb_backend_foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data) +static int php_git2_odb_backend_foreach(git_odb_backend *backend, git_odb_foreach_cb cb, void *data) { + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; + zval *param_callback = NULL, *retval_ptr = NULL, *param_payload = (zval*)data; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + + MAKE_STD_ZVAL(param_callback); + // TODO(chobie): wrap git_odb_foreach_cb with closure + // see zend_create_closure + + if (php_git2_call_function_v(&p->callbacks[6].fci, &p->callbacks[6].fcc TSRMLS_CC, &retval_ptr, 2, + ¶m_callback, ¶m_payload)) { + return GIT_EUSER; + } + + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + return retval; } static void php_git2_odb_backend_free(git_odb_backend *_backend) { From 8d6e46d3bd4c686f75f59987d81b37439722915a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 21 Jan 2014 23:49:11 +0900 Subject: [PATCH 116/136] [odb_backend] implement foreach callback. slightly tricky --- example/odb_backend.php | 5 ++-- odb.c | 65 +++++++++++++++++++++++++++++++++++++---- php_git2.c | 23 +++++++++++++++ php_git2.h | 8 +++++ php_git2_priv.h | 29 ++++++++++++++++++ 5 files changed, 123 insertions(+), 7 deletions(-) diff --git a/example/odb_backend.php b/example/odb_backend.php index 6b269f50d7..48b7c2da44 100644 --- a/example/odb_backend.php +++ b/example/odb_backend.php @@ -60,12 +60,14 @@ class Pool }, "foreach" => function($foreach_cb, &$payload) { // this payload was passed by git_odb_foreach callback. + echo "\e[32m# foreach (iterate all backends)\e[m\n"; foreach (Pool::$pool as $oid => $value) { $retval = $foreach_cb($oid, $payload); if ($retval == GIT_EUSER) { return $retval; } } + return 0; }, "writepack" => function() { @@ -91,9 +93,8 @@ class Pool $obj = git_odb_read_prefix($odb, substr($oid, 0, 10)); var_dump($obj); - $payload = array(); git_odb_foreach($odb, function($oid, &$payload) { - echo $oid . PHP_EOL; + echo "."; }, $payload); exit; diff --git a/odb.c b/odb.c index 86452e824f..a5ca22f0b6 100644 --- a/odb.c +++ b/odb.c @@ -933,21 +933,76 @@ static int php_git2_odb_backend_exists(git_odb_backend *backend, const git_oid * return !retval; } + +static const zend_arg_info arginfo_git_odb_backend_foreach_callback[] = { + ZEND_ARG_INFO(0, oid) + ZEND_ARG_INFO(1, payload) +}; + +static void git_ex_cb(INTERNAL_FUNCTION_PARAMETERS) +{ + zval *payload, *this = getThis(); + php_git2_odb_backend_foreach_callback *_callback; + char *oid; + int oid_len, retval = 0; + git_oid _oid; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sz", &oid, &oid_len, &payload) == FAILURE) { + return; + } + + if (git_oid_fromstrn(&_oid, oid, oid_len) != GIT_OK) { + return; + } + + _callback = (php_git2_odb_backend_foreach_callback*)zend_object_store_get_object(this TSRMLS_CC); + _callback->payload->payload = payload; + retval = _callback->callback(&_oid, _callback->payload); + RETURN_LONG(retval); +} + static int php_git2_odb_backend_foreach(git_odb_backend *backend, git_odb_foreach_cb cb, void *data) { php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; - zval *param_callback = NULL, *retval_ptr = NULL, *param_payload = (zval*)data; + zval *param_callback = NULL, *callback = NULL, *retval_ptr = NULL, *param_payload = (zval*)data; php_git2_multi_cb_t *p = php_backend->multi; + zend_function function = {0}; + php_git2_odb_backend_foreach_callback *_callback; + php_git2_cb_t *__cb = (php_git2_cb_t*)data; int i = 0, retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); + MAKE_STD_ZVAL(callback); + object_init_ex(callback, php_git2_odb_backend_foreach_callback_class_entry); + _callback = (php_git2_odb_backend_foreach_callback*)zend_object_store_get_object(callback TSRMLS_CC); + _callback->callback = cb; + _callback->payload = __cb; + Z_ADDREF_P(callback); + + function.type = ZEND_INTERNAL_FUNCTION; + function.common.function_name = "callback"; + function.common.fn_flags = ZEND_ACC_CLOSURE; + function.common.num_args = 2; + function.common.required_num_args = 2; + function.common.arg_info = &arginfo_git_odb_backend_foreach_callback; + function.common.scope = php_git2_odb_backend_foreach_callback_class_entry; + function.internal_function.type = ZEND_INTERNAL_FUNCTION; + function.internal_function.scope = php_git2_odb_backend_foreach_callback_class_entry; + function.internal_function.fn_flags = ZEND_ACC_CLOSURE; + function.internal_function.handler = git_ex_cb; + function.internal_function.module = &git2_module_entry; + function.internal_function.num_args = 2; + function.internal_function.required_num_args = 2; + function.internal_function.arg_info = &arginfo_git_odb_backend_foreach_callback; + MAKE_STD_ZVAL(param_callback); - // TODO(chobie): wrap git_odb_foreach_cb with closure - // see zend_create_closure + zend_create_closure(param_callback, &function, php_git2_odb_backend_foreach_callback_class_entry, callback TSRMLS_CC); + Z_ADDREF_P(__cb->payload); if (php_git2_call_function_v(&p->callbacks[6].fci, &p->callbacks[6].fcc TSRMLS_CC, &retval_ptr, 2, - ¶m_callback, ¶m_payload)) { + ¶m_callback, &__cb->payload)) { return GIT_EUSER; } @@ -955,6 +1010,7 @@ static int php_git2_odb_backend_foreach(git_odb_backend *backend, git_odb_foreac zval_ptr_dtor(&retval_ptr); return retval; } + static void php_git2_odb_backend_free(git_odb_backend *_backend) { } @@ -1012,7 +1068,6 @@ PHP_FUNCTION(git_odb_backend_new) php_git2_fcall_info_wrapper2(tmp, &foreach_fci, &foreach_fcc TSRMLS_CC); } - Z_ADDREF_P(callbacks); php_git2_multi_cb_init(&backend->multi, callbacks TSRMLS_CC, 8, &read_fci, &read_fcc, diff --git a/php_git2.c b/php_git2.c index 4f09d0223f..2f07f43714 100644 --- a/php_git2.c +++ b/php_git2.c @@ -70,6 +70,8 @@ int git2_resource_handle; +zend_class_entry *php_git2_odb_backend_foreach_callback_class_entry; + void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC) { php_git2_t *resource = (php_git2_t *)rsrc->ptr; @@ -1016,10 +1018,31 @@ static PHP_GSHUTDOWN_FUNCTION(git2) { } + +static void php_git2_odb_backend_foreach_callback_free_storage(php_git2_odb_backend_foreach_callback *object TSRMLS_DC) +{ + zend_object_std_dtor(&object->zo TSRMLS_CC); + efree(object); +} + +zend_object_value php_git2_odb_backend_foreach_callback_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + PHP_GIT2_STD_CREATE_OBJECT(php_git2_odb_backend_foreach_callback); + return retval; +} + PHP_MINIT_FUNCTION(git2) { + zend_class_entry ce; REGISTER_INI_ENTRIES(); + + INIT_CLASS_ENTRY(ce, "Git2ODBBackendForeachCallback", 0); + php_git2_odb_backend_foreach_callback_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + zend_register_class_alias_ex(ZEND_NS_NAME("Git2\\ODB\\Backend", "ForeachCallback"), sizeof(ZEND_NS_NAME("Git2\\ODB\\Backend", "ForeachCallback"))-1, php_git2_odb_backend_foreach_callback_class_entry TSRMLS_CC); + php_git2_odb_backend_foreach_callback_class_entry->create_object = php_git2_odb_backend_foreach_callback_new; + git2_resource_handle = zend_register_list_destructors_ex(destruct_git2, NULL, PHP_GIT2_RESOURCE_NAME, module_number); REGISTER_LONG_CONSTANT("GIT_TYPE_REPOSITORY", PHP_GIT2_TYPE_REPOSITORY, CONST_CS | CONST_PERSISTENT); diff --git a/php_git2.h b/php_git2.h index f26a1c0fd8..78a3f0f76e 100644 --- a/php_git2.h +++ b/php_git2.h @@ -229,4 +229,12 @@ typedef struct php_git2_odb_backend { php_git2_multi_cb_t *multi; } php_git2_odb_backend; +typedef struct php_git2_odb_backend_foreach_callback { + zend_object zo; + git_odb_foreach_cb callback; + php_git2_cb_t *payload; +} php_git2_odb_backend_foreach_callback; + +extern zend_class_entry *php_git2_odb_backend_foreach_callback_class_entry; + #endif /* PHP_GIT2_H */ \ No newline at end of file diff --git a/php_git2_priv.h b/php_git2_priv.h index b2a03a7145..31bd3f2b30 100644 --- a/php_git2_priv.h +++ b/php_git2_priv.h @@ -34,6 +34,35 @@ extern int git2_resource_handle; #define PHP_GIT2_LIST_INSERT(type, handle) zend_list_insert(type, handle) #endif +# if ZEND_MODULE_API_NO >= 20100525 +# define PHP_GIT2_STD_CREATE_OBJECT(STRUCT_NAME) \ + STRUCT_NAME *object;\ + \ + object = (STRUCT_NAME*)ecalloc(1, sizeof(*object));\ + zend_object_std_init(&object->zo, ce TSRMLS_CC);\ + object_properties_init(&object->zo, ce);\ + \ + retval.handle = zend_objects_store_put(object,\ + (zend_objects_store_dtor_t)zend_objects_destroy_object,\ + (zend_objects_free_object_storage_t) STRUCT_NAME##_free_storage ,\ + NULL TSRMLS_CC);\ + retval.handlers = zend_get_std_object_handlers(); +# else +# define PHP_GIT2_STD_CREATE_OBJECT(STRUCT_NAME) \ + STRUCT_NAME *object;\ + zval *tmp = NULL;\ + \ + object = (STRUCT_NAME*)ecalloc(1, sizeof(*object));\ + zend_object_std_init(&object->zo, ce TSRMLS_CC);\ + zend_hash_copy(object->zo.properties, &ce->default_properties, (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); \ + \ + retval.handle = zend_objects_store_put(object,\ + (zend_objects_store_dtor_t)zend_objects_destroy_object,\ + (zend_objects_free_object_storage_t) STRUCT_NAME##_free_storage ,\ + NULL TSRMLS_CC);\ + retval.handlers = zend_get_std_object_handlers(); +# endif + #define PHP_GIT2_V(git2, type) git2->v.type #define GIT2_RVAL_P(git2) git2->resource_id #define GIT2_SHOULD_FREE(git2) git2->should_free_v From 5d3a8cd80bc34561bd681f2b46690e9fff583d8f Mon Sep 17 00:00:00 2001 From: Gerry Date: Wed, 22 Jan 2014 01:13:20 +0800 Subject: [PATCH 117/136] Add missing part in path Git clone creates a directory named after the project you are cloning. The initial step to change directory assumed we were already in the cloned directory, which would not be the case if you had just run the command above it. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ae801928d..76f30050b6 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ you need to install libgit2 before make php-git. ```` git clone https://github.com/libgit2/php-git.git --recursive -cd libgit2 +cd php-git/libgit2 mkdir build && cd build cmake .. cmake -DBUILD_SHARED_LIBS=OFF -build . From e4fc2516513099cefe96d95f393af57ec642cc7f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 22 Jan 2014 09:09:44 +0900 Subject: [PATCH 118/136] [odb_backend] add refresh callback --- example/odb_backend.php | 5 ++++- odb.c | 46 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/example/odb_backend.php b/example/odb_backend.php index 48b7c2da44..fc83a8225a 100644 --- a/example/odb_backend.php +++ b/example/odb_backend.php @@ -57,7 +57,7 @@ class Pool return $retval; }, "refresh" => function() { - + echo "\e[32m# refreshed!\e[m\n"; }, "foreach" => function($foreach_cb, &$payload) { // this payload was passed by git_odb_foreach callback. echo "\e[32m# foreach (iterate all backends)\e[m\n"; @@ -73,6 +73,7 @@ class Pool }, "free" => function() { + echo "\e[32m# free'd!\e[m\n"; } ); $memory_backend = git_odb_backend_new($a); @@ -97,4 +98,6 @@ class Pool git_odb_foreach($odb, function($oid, &$payload) { echo "."; }, $payload); +echo PHP_EOL; +git_odb_refresh($odb); exit; diff --git a/odb.c b/odb.c index a5ca22f0b6..46bde23e07 100644 --- a/odb.c +++ b/odb.c @@ -931,7 +931,6 @@ static int php_git2_odb_backend_exists(git_odb_backend *backend, const git_oid * } zval_ptr_dtor(&retval_ptr); return !retval; - } static const zend_arg_info arginfo_git_odb_backend_foreach_callback[] = { @@ -1013,17 +1012,44 @@ static int php_git2_odb_backend_foreach(git_odb_backend *backend, git_odb_foreac static void php_git2_odb_backend_free(git_odb_backend *_backend) { + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)_backend; + zval *retval_ptr = NULL; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + if (php_git2_call_function_v(&p->callbacks[7].fci, &p->callbacks[7].fcc TSRMLS_CC, &retval_ptr, 0)) { + return; + } + + zval_ptr_dtor(&retval_ptr); + return; } +static void php_git2_odb_refresh(git_odb_backend *_backend) +{ + php_git2_t *result; + php_git2_odb_backend *php_backend = (php_git2_odb_backend*)_backend; + zval *retval_ptr = NULL; + php_git2_multi_cb_t *p = php_backend->multi; + int i = 0, retval = 0; + GIT2_TSRMLS_SET(p->tsrm_ls); + if (php_git2_call_function_v(&p->callbacks[8].fci, &p->callbacks[8].fcc TSRMLS_CC, &retval_ptr, 0)) { + return; + } + + zval_ptr_dtor(&retval_ptr); + return; +} PHP_FUNCTION(git_odb_backend_new) { php_git2_odb_backend *backend; php_git2_t *result; zval *callbacks, *tmp; zend_fcall_info read_fci, write_fci, read_prefix_fci, read_header_fci, writestream_fci, - exists_fci, foreach_fci, free_fci; + exists_fci, foreach_fci, free_fci, refresh_fci; zend_fcall_info_cache read_fcc, write_fcc, read_prefix_fcc, read_header_fcc, writestream_fcc, - exists_fcc, foreach_fcc, free_fcc; + exists_fcc, foreach_fcc, free_fcc, refresh_fcc; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &callbacks) == FAILURE) { @@ -1041,6 +1067,7 @@ PHP_FUNCTION(git_odb_backend_new) backend->parent.exists = &php_git2_odb_backend_exists; backend->parent.foreach = &php_git2_odb_backend_foreach; backend->parent.free = &php_git2_odb_backend_free; + backend->parent.refresh = &php_git2_odb_refresh; tmp = php_git2_read_arrval(callbacks, ZEND_STRS("read") TSRMLS_CC); if (tmp) { @@ -1067,9 +1094,17 @@ PHP_FUNCTION(git_odb_backend_new) if (tmp) { php_git2_fcall_info_wrapper2(tmp, &foreach_fci, &foreach_fcc TSRMLS_CC); } + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("free") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &free_fci, &free_fcc TSRMLS_CC); + } + tmp = php_git2_read_arrval(callbacks, ZEND_STRS("refresh") TSRMLS_CC); + if (tmp) { + php_git2_fcall_info_wrapper2(tmp, &refresh_fci, &refresh_fcc TSRMLS_CC); + } Z_ADDREF_P(callbacks); - php_git2_multi_cb_init(&backend->multi, callbacks TSRMLS_CC, 8, + php_git2_multi_cb_init(&backend->multi, callbacks TSRMLS_CC, 9, &read_fci, &read_fcc, &write_fci, &write_fcc, &read_prefix_fci, &read_prefix_fcc, @@ -1077,7 +1112,8 @@ PHP_FUNCTION(git_odb_backend_new) &writestream_fci, &writestream_fcc, &exists_fci, &exists_fcc, &foreach_fci, &foreach_fcc, - &free_fci, &free_fcc + &free_fci, &free_fcc, + &refresh_fci, &refresh_fcc ); if (php_git2_make_resource(&result, PHP_GIT2_TYPE_ODB_BACKEND, backend, 1 TSRMLS_CC)) { From 6a5f0907425f7b8b6ea3e2f5857356a06c83cbca Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 22 Jan 2014 09:45:07 +0900 Subject: [PATCH 119/136] [odb_backend] don't support stream at this time --- README.md | 5 +++-- odb.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 829a68e3f0..a2ba044ddb 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ php-git2 is a PHP bindings to the libgit2 linkable C Git library. +* API Documentation: http://libgit2.github.com/libgit2/#v0.20.0 (also see Signature conversions section) +* IRC: #php-git on irc.freenode.net. + ## Status 0.3.0 Alpha (switching to functions) @@ -55,8 +58,6 @@ resource|bool function git_repository_init(string $path, long $is_bare); public struct (e.g: git_config_entry) should consider return as an array. ```` -see libgit2.github.com/libgit2/#v0.20.0 - ##### file name rules. basically, we rely libgit2 grouping at this time. (`branch` group functions should be in branch.c) diff --git a/odb.c b/odb.c index 46bde23e07..d4912f8c05 100644 --- a/odb.c +++ b/odb.c @@ -1063,7 +1063,7 @@ PHP_FUNCTION(git_odb_backend_new) backend->parent.write = &php_git2_odb_backend_write; backend->parent.read_prefix = &php_git2_odb_backend_read_prefix; backend->parent.read_header = &php_git2_odb_backend_read_header; - backend->parent.writestream = &php_git2_odb_backend_writestream; + //backend->parent.writestream = &php_git2_odb_backend_writestream; backend->parent.exists = &php_git2_odb_backend_exists; backend->parent.foreach = &php_git2_odb_backend_foreach; backend->parent.free = &php_git2_odb_backend_free; From e5aeb5b0dda582cc193b6adf771c15b11139c1f8 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 23 Jan 2014 08:40:21 +0900 Subject: [PATCH 120/136] [reset] remove needles variables --- reset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reset.c b/reset.c index 48f39bc8eb..f46a616bb7 100644 --- a/reset.c +++ b/reset.c @@ -6,7 +6,7 @@ */ PHP_FUNCTION(git_reset) { - int result = 0, error = 0; + int result = 0; zval *repo = NULL, *target = NULL; php_git2_t *_repo = NULL, *_target = NULL; long reset_type = 0; @@ -27,7 +27,7 @@ PHP_FUNCTION(git_reset) */ PHP_FUNCTION(git_reset_default) { - int result = 0, error = 0; + int result = 0; zval *repo = NULL, *target = NULL, *pathspecs = NULL, *array = NULL; php_git2_t *_repo = NULL, *_target = NULL; git_strarray _pathspecs = {0}; From fdeeddadc0a2fe5b3ca6a860b27794b95b3b5a1c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 23 Jan 2014 09:13:45 +0900 Subject: [PATCH 121/136] remove unused variables --- attr.c | 10 +++++----- blob.c | 8 ++++---- branch.c | 5 ----- checkout.c | 6 +++--- commit.c | 8 +++----- cred.c | 12 ------------ diff.c | 30 +++++++++++++---------------- filter.c | 23 ++++++++-------------- g_config.c | 30 +++++++++-------------------- giterr.c | 2 +- graph.c | 2 +- helper.c | 11 +++-------- ignore.c | 6 +++--- index.c | 23 ++++++++++------------ indexer.c | 10 +--------- merge.c | 10 ++++------ message.c | 1 - note.c | 12 ++++++------ object.c | 8 ++++---- odb.c | 53 ++++++++++++++++++--------------------------------- packbuilder.c | 22 ++++++++------------- patch.c | 10 +++++----- pathspec.c | 2 +- php_git2.c | 1 - push.c | 15 +++++++-------- reference.c | 22 ++++++++++----------- reflog.c | 12 ++++++------ refspec.c | 10 +++++----- remote.c | 26 +++---------------------- revwalk.c | 10 +++++----- signature.c | 4 +--- stash.c | 10 ++++------ status.c | 15 ++++++--------- tag.c | 12 +++--------- transport.c | 6 ++---- tree.c | 3 +-- treebuilder.c | 3 +-- 37 files changed, 165 insertions(+), 288 deletions(-) diff --git a/attr.c b/attr.c index fce466b0d3..4ed054a571 100644 --- a/attr.c +++ b/attr.c @@ -24,7 +24,7 @@ PHP_FUNCTION(git_attr_value) */ PHP_FUNCTION(git_attr_get) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; char *value_out = NULL, *path = NULL, *name = NULL; zval *repo = NULL; long flags = 0; @@ -48,7 +48,7 @@ PHP_FUNCTION(git_attr_get) */ PHP_FUNCTION(git_attr_get_many) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; char *values_out = NULL, *path = NULL; zval *repo = NULL, *names = NULL; long flags = 0, num_attr = 0; @@ -74,8 +74,8 @@ PHP_FUNCTION(git_attr_get_many) */ PHP_FUNCTION(git_attr_foreach) { - int result = 0, path_len = 0, error = 0; - zval *repo = NULL, *callback = NULL, *payload = NULL; + int result = 0, path_len = 0; + zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; long flags = 0; char *path = NULL; @@ -120,7 +120,7 @@ PHP_FUNCTION(git_attr_cache_flush) */ PHP_FUNCTION(git_attr_add_macro) { - int result = 0, name_len = 0, values_len = 0, error = 0; + int result = 0, name_len = 0, values_len = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *name = NULL, *values = NULL; diff --git a/blob.c b/blob.c index 0eb5d35a15..dd3bb5ba25 100644 --- a/blob.c +++ b/blob.c @@ -34,10 +34,10 @@ PHP_FUNCTION(git_blob_create_frombuffer) */ PHP_FUNCTION(git_blob_create_fromchunks) { - int result = 0, id_len = 0, hintpath_len = 0, error = 0; + int result = 0, id_len = 0, hintpath_len = 0; char *id = NULL, *hintpath = NULL; git_oid __id = {0}; - zval *repo = NULL, *callback = NULL, *payload = NULL; + zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -215,7 +215,7 @@ PHP_FUNCTION(git_blob_is_binary) */ PHP_FUNCTION(git_blob_lookup) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; git_blob *blob = NULL; zval *repo = NULL; php_git2_t *_repo = NULL, *_result = NULL; @@ -244,7 +244,7 @@ PHP_FUNCTION(git_blob_lookup) */ PHP_FUNCTION(git_blob_lookup_prefix) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; git_blob *blob = NULL; zval *repo = NULL; php_git2_t *_repo = NULL, *_result = NULL; diff --git a/branch.c b/branch.c index cbf361cc91..9d19d0fec0 100644 --- a/branch.c +++ b/branch.c @@ -39,7 +39,6 @@ PHP_FUNCTION(git_branch_delete) int result = 0; zval *branch = NULL; php_git2_t *_branch = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &branch) == FAILURE) { @@ -190,7 +189,6 @@ PHP_FUNCTION(git_branch_lookup) */ PHP_FUNCTION(git_branch_name) { - php_git2_t *result = NULL; char out[GIT2_BUFFER_SIZE] = {0}; zval *ref = NULL; php_git2_t *_ref = NULL; @@ -241,7 +239,6 @@ PHP_FUNCTION(git_branch_upstream) */ PHP_FUNCTION(git_branch_upstream_name) { - php_git2_t *result = NULL; char tracking_branch_name_out[GIT2_BUFFER_SIZE] = {0}; long buffer_size = GIT2_BUFFER_SIZE; zval *repo = NULL; @@ -271,7 +268,6 @@ PHP_FUNCTION(git_branch_is_head) int result = 0; zval *branch = NULL; php_git2_t *_branch = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &branch) == FAILURE) { @@ -288,7 +284,6 @@ PHP_FUNCTION(git_branch_is_head) */ PHP_FUNCTION(git_branch_remote_name) { - php_git2_t *result = NULL; char remote_name_out[GIT2_BUFFER_SIZE] = {0}; long buffer_size = GIT2_BUFFER_SIZE; zval *repo = NULL; diff --git a/checkout.c b/checkout.c index b422147a6a..e5f0ef763a 100644 --- a/checkout.c +++ b/checkout.c @@ -8,7 +8,7 @@ PHP_FUNCTION(git_checkout_head) { zval *opts = NULL, *repo = NULL; php_git2_t *_repo = NULL; - int result = 0, error = 0, shoud_free = 0; + int result = 0, shoud_free = 0; git_checkout_opts *options; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -39,7 +39,7 @@ PHP_FUNCTION(git_checkout_head) */ PHP_FUNCTION(git_checkout_index) { - int result = 0, error = 0; + int result = 0; zval *repo = NULL, *index = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_index = NULL; @@ -60,7 +60,7 @@ PHP_FUNCTION(git_checkout_index) */ PHP_FUNCTION(git_checkout_tree) { - int result = 0, error = 0; + int result = 0; zval *repo = NULL, *treeish = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_treeish = NULL; git_checkout_opts options = {0}; diff --git a/commit.c b/commit.c index 7849baa2f6..1f38036672 100644 --- a/commit.c +++ b/commit.c @@ -6,7 +6,7 @@ */ PHP_FUNCTION(git_commit_lookup) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; git_commit *commit = NULL; zval *repo = NULL; php_git2_t *_repo = NULL, *_result = NULL; @@ -34,7 +34,6 @@ PHP_FUNCTION(git_commit_lookup) */ PHP_FUNCTION(git_commit_author) { - zval *repository; php_git2_t *git2; zval *commit; git_signature *author; @@ -83,7 +82,7 @@ PHP_FUNCTION(git_commit_tree) */ PHP_FUNCTION(git_commit_lookup_prefix) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; git_commit *commit = NULL; zval *repo = NULL; php_git2_t *_repo = NULL, *_result = NULL; @@ -418,7 +417,7 @@ PHP_FUNCTION(git_commit_create) zval *repo, *tree, *parents, *committer, *author, **element; char *update_ref = {0}, *message_encoding = {0}, *message = {0}; int update_ref_len, message_encoding_len, message_len, parent_count = 0, error = 0, i; - php_git2_t *_repo, *_author, *_committer, *_tree; + php_git2_t *_repo, *_tree; git_signature __author, __committer; char out[GIT2_OID_HEXSIZE] = {0}; git_oid oid; @@ -452,7 +451,6 @@ PHP_FUNCTION(git_commit_create) zend_hash_move_forward_ex(Z_ARRVAL_P(parents), &pos) ) { git_commit *p = NULL; - git_oid parent_oid; if (Z_TYPE_PP(element) == IS_STRING) { error = git_oid_fromstr(&oid, Z_STRVAL_PP(element)); diff --git a/cred.c b/cred.c index 309bba93d3..d3a2f1c95d 100644 --- a/cred.c +++ b/cred.c @@ -9,7 +9,6 @@ PHP_FUNCTION(git_cred_has_username) int result = 0; zval *cred = NULL; php_git2_t *_cred = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &cred) == FAILURE) { @@ -79,12 +78,6 @@ PHP_FUNCTION(git_cred_ssh_key_new) */ PHP_FUNCTION(git_cred_ssh_custom_new) { - char *username = {0}; - int username_len; - char *publickey = {0}; - int publickey_len; - zval *sign_fn; - php_git2_t *_sign_fn; /* TODO(chobie): implement this */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_ssh_custom_new not implemented yet"); @@ -122,11 +115,6 @@ PHP_FUNCTION(git_cred_default_new) */ PHP_FUNCTION(git_cred_userpass) { - char *url = {0}; - int url_len; - char *user_from_url = {0}; - int user_from_url_len; - long allowed_types; /* TODO(chobie): implement this */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_cred_userpass not implemented yet"); diff --git a/diff.c b/diff.c index 8ec95fe2c0..68002ec878 100644 --- a/diff.c +++ b/diff.c @@ -36,7 +36,6 @@ PHP_FUNCTION(git_diff_tree_to_tree) zval *new_tree = NULL; php_git2_t *_new_tree = NULL; zval *opts = NULL; - int error = 0; git_diff_options options = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -59,7 +58,7 @@ PHP_FUNCTION(git_diff_tree_to_tree) */ PHP_FUNCTION(git_diff_tree_to_index) { - int result = 0, error = 0; + int result = 0; git_diff *diff = NULL; zval *repo = NULL, *old_tree = NULL, *index = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_old_tree = NULL, *_index = NULL, *_diff = NULL; @@ -88,7 +87,7 @@ PHP_FUNCTION(git_diff_tree_to_index) */ PHP_FUNCTION(git_diff_index_to_workdir) { - int result = 0, error = 0; + int result = 0; git_diff *diff = NULL; zval *repo = NULL, *index = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_index = NULL, *_diff = NULL; @@ -115,7 +114,7 @@ PHP_FUNCTION(git_diff_index_to_workdir) */ PHP_FUNCTION(git_diff_tree_to_workdir) { - int result = 0, error = 0; + int result = 0; git_diff *diff = NULL; zval *repo = NULL, *old_tree = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_old_tree = NULL, *_result; @@ -148,7 +147,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir) */ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) { - int result = 0, error = 0; + int result = 0; git_diff *diff = NULL; zval *repo = NULL, *old_tree = NULL, *opts = NULL; php_git2_t *_repo = NULL, *_old_tree = NULL, *_diff = NULL; @@ -175,7 +174,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index) */ PHP_FUNCTION(git_diff_merge) { - int result = 0, error = 0; + int result = 0; zval *onto = NULL, *from = NULL; php_git2_t *_onto = NULL, *_from = NULL; @@ -199,7 +198,6 @@ PHP_FUNCTION(git_diff_find_similar) zval *diff = NULL; php_git2_t *_diff = NULL; zval *options = NULL; - int error = 0; git_diff_options _options = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -223,7 +221,6 @@ PHP_FUNCTION(git_diff_options_init) git_diff_options options = {0}; long version = GIT_DIFF_OPTIONS_VERSION; zval *out; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &version) == FAILURE) { @@ -303,7 +300,6 @@ PHP_FUNCTION(git_diff_is_sorted_icase) int result = 0; zval *diff = NULL; php_git2_t *_diff = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &diff) == FAILURE) { @@ -321,8 +317,8 @@ PHP_FUNCTION(git_diff_is_sorted_icase) */ PHP_FUNCTION(git_diff_foreach) { - int result = 0, error = 0; - zval *diff = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; + int result = 0; + zval *diff = NULL, *payload = NULL; php_git2_t *_diff = NULL; zend_fcall_info file_fci = empty_fcall_info; zend_fcall_info_cache file_fcc = empty_fcall_info_cache; @@ -371,8 +367,8 @@ PHP_FUNCTION(git_diff_status_char) */ PHP_FUNCTION(git_diff_print) { - int result = 0, error = 0; - zval *diff = NULL, *print_cb = NULL, *payload = NULL; + int result = 0; + zval *diff = NULL, *payload = NULL; php_git2_t *_diff = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -398,8 +394,8 @@ PHP_FUNCTION(git_diff_print) */ PHP_FUNCTION(git_diff_blobs) { - int result = 0, old_as_path_len = 0, new_as_path_len = 0, error = 0; - zval *old_blob = NULL, *new_blob = NULL, *options = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; + int result = 0, old_as_path_len = 0, new_as_path_len = 0; + zval *old_blob = NULL, *new_blob = NULL, *options = NULL, *payload = NULL; php_git2_t *_old_blob = NULL, *_new_blob = NULL; char *old_as_path = NULL, *new_as_path = NULL; zend_fcall_info file_fci = empty_fcall_info; @@ -436,8 +432,8 @@ PHP_FUNCTION(git_diff_blobs) */ PHP_FUNCTION(git_diff_blob_to_buffer) { - int result = 0, old_as_path_len = 0, buffer_len = 0, buffer_as_path_len = 0, error = 0; - zval *old_blob = NULL, *options = NULL, *file_cb = NULL, *hunk_cb = NULL, *line_cb = NULL, *payload = NULL; + int result = 0, old_as_path_len = 0, buffer_len = 0, buffer_as_path_len = 0; + zval *old_blob = NULL, *options = NULL, *payload = NULL; php_git2_t *_old_blob = NULL; char *old_as_path = NULL, *buffer = NULL, *buffer_as_path = NULL; zend_fcall_info file_fci = empty_fcall_info; diff --git a/filter.c b/filter.c index e85eb810f2..9f140d58b1 100644 --- a/filter.c +++ b/filter.c @@ -13,7 +13,6 @@ static int php_git2_git_filter_check_fn( php_git2_t *result, *filter_source; zval *param_payload = NULL, *param_source = NULL, *param_attr = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = filter->multi; - int i = 0, retval = 0; const unsigned char *ptr = self->attributes; int last_is_space = 0; int attribute_count = 0, len = 0; @@ -87,11 +86,9 @@ static int php_git2_git_filter_check_fn( static void php_git2_git_filter_shutdown_fn(git_filter *self) { - php_git2_t *result; zval *param_self = NULL, *param_payload = NULL, *retval_ptr = NULL; php_git2_filter *filter = (php_git2_filter*)self; php_git2_multi_cb_t *p = filter->multi; - int i = 0, retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) MAKE_STD_ZVAL(param_self); @@ -106,11 +103,9 @@ static void php_git2_git_filter_shutdown_fn(git_filter *self) static int php_git2_git_filter_init_fn(git_filter *self) { - php_git2_t *result; zval *param_self = NULL, *param_payload = NULL, *retval_ptr = NULL; php_git2_filter *filter = (php_git2_filter*)self; php_git2_multi_cb_t *p = filter->multi; - int i = 0, retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) MAKE_STD_ZVAL(param_self); @@ -131,10 +126,10 @@ static int php_git2_git_filter_apply_fn( const git_filter_source *src) { php_git2_filter *filter = (php_git2_filter*)self; - php_git2_t *result, *filter_source; + php_git2_t *filter_source; zval *param_payload = NULL, *param_from = NULL, *param_src = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = filter->multi; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) MAKE_STD_ZVAL(param_payload); @@ -171,11 +166,9 @@ static void php_git2_git_filter_cleanup_fn( git_filter *self, void *payload) { - php_git2_t *result; zval *param_self = NULL, *param_payload = NULL, *retval_ptr = NULL; php_git2_filter *filter = (php_git2_filter*)self; php_git2_multi_cb_t *p = filter->multi; - int i = 0, retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) MAKE_STD_ZVAL(param_self); @@ -191,7 +184,7 @@ static void php_git2_git_filter_cleanup_fn( */ PHP_FUNCTION(git_filter_list_load) { - int result = 0, path_len = 0, error = 0; + int result = 0, path_len = 0; git_filter_list *filters = NULL; zval *repo = NULL, *blob = NULL; php_git2_t *_repo = NULL, *_blob = NULL, *_result; @@ -226,7 +219,7 @@ PHP_FUNCTION(git_filter_list_load) */ PHP_FUNCTION(git_filter_list_apply_to_data) { - php_git2_t *result = NULL, *_filters = NULL, *_in = NULL; + php_git2_t *_filters = NULL, *_in = NULL; git_buf out = {0}; zval *filters = NULL, *in = NULL; int error = 0; @@ -251,7 +244,7 @@ PHP_FUNCTION(git_filter_list_apply_to_data) */ PHP_FUNCTION(git_filter_list_apply_to_file) { - php_git2_t *result = NULL, *_filters = NULL, *_repo = NULL; + php_git2_t *_filters = NULL, *_repo = NULL; git_buf out = {0}; zval *filters = NULL, *repo = NULL; char *path = NULL; @@ -383,7 +376,7 @@ PHP_FUNCTION(git_filter_list_new) */ PHP_FUNCTION(git_filter_list_push) { - int result = 0, error = 0; + int result = 0; zval *fl = NULL, *filter = NULL, *payload = NULL; php_git2_t *_fl = NULL, *_filter = NULL; @@ -522,7 +515,7 @@ PHP_FUNCTION(git_filter_source_mode) */ PHP_FUNCTION(git_filter_register) { - int result = 0, name_len = 0, error = 0; + int result = 0, name_len = 0; char *name = NULL; zval *filter = NULL; php_git2_t *_filter = NULL; @@ -543,7 +536,7 @@ PHP_FUNCTION(git_filter_register) */ PHP_FUNCTION(git_filter_unregister) { - int result = 0, name_len = 0, error = 0; + int result = 0, name_len = 0; char *name = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/g_config.c b/g_config.c index bfc4abe805..29fdcf8a8a 100644 --- a/g_config.c +++ b/g_config.c @@ -16,7 +16,6 @@ static int php_git2_config_foreach_cb(const git_config_entry *entry, void *paylo php_git2_t *result; zval *param_config_entry, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -159,7 +158,6 @@ static void php_git2_config_parse_with(INTERNAL_FUNCTION_PARAMETERS, enum php_gi { char *value = {0}; int value_len; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) { @@ -496,8 +494,8 @@ PHP_FUNCTION(git_config_get_string) */ PHP_FUNCTION(git_config_get_multivar_foreach) { - int result = 0, name_len = 0, regexp_len = 0, error = 0; - zval *cfg = NULL, *callback = NULL, *payload = NULL; + int result = 0, name_len = 0, regexp_len = 0; + zval *cfg = NULL, *payload = NULL; php_git2_t *_cfg = NULL; char *name = NULL, *regexp = NULL; zend_fcall_info fci = empty_fcall_info; @@ -551,7 +549,7 @@ PHP_FUNCTION(git_config_multivar_iterator_new) */ PHP_FUNCTION(git_config_next) { - int result = 0, error = 0; + int result = 0; git_config_entry *entry = NULL; zval *iter = NULL; php_git2_t *_iter = NULL; @@ -625,7 +623,7 @@ PHP_FUNCTION(git_config_set_string) */ PHP_FUNCTION(git_config_set_multivar) { - int result = 0, name_len = 0, regexp_len = 0, value_len = 0, error = 0; + int result = 0, name_len = 0, regexp_len = 0, value_len = 0; zval *cfg = NULL; php_git2_t *_cfg = NULL; char *name = NULL, *regexp = NULL, *value = NULL; @@ -669,7 +667,7 @@ PHP_FUNCTION(git_config_delete_entry) */ PHP_FUNCTION(git_config_delete_multivar) { - int result = 0, name_len = 0, regexp_len = 0, error = 0; + int result = 0, name_len = 0, regexp_len = 0; zval *cfg = NULL; php_git2_t *_cfg = NULL; char *name = NULL, *regexp = NULL; @@ -689,8 +687,8 @@ PHP_FUNCTION(git_config_delete_multivar) */ PHP_FUNCTION(git_config_foreach) { - int result = 0, error = 0; - zval *cfg = NULL, *callback = NULL; + int result = 0; + zval *cfg = NULL; php_git2_t *_cfg = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -770,8 +768,8 @@ PHP_FUNCTION(git_config_iterator_glob_new) */ PHP_FUNCTION(git_config_foreach_match) { - int result = 0, regexp_len = 0, error = 0; - zval *cfg = NULL, *callback = NULL, *payload = NULL; + int result = 0, regexp_len = 0; + zval *cfg = NULL, *payload = NULL; php_git2_t *_cfg = NULL; char *regexp = NULL; zend_fcall_info fci = empty_fcall_info; @@ -798,12 +796,6 @@ PHP_FUNCTION(git_config_foreach_match) */ PHP_FUNCTION(git_config_get_mapped) { - zval *cfg; - php_git2_t *_cfg; - char *name = {0}; - int name_len; - zval *maps; - php_git2_t *_maps; /* TODO(chobie): implement this */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_get_mapped not implemented yet"); @@ -822,8 +814,6 @@ PHP_FUNCTION(git_config_lookup_map_value) { zval *maps; php_git2_t *_maps; - char *value = {0}; - int value_len; /* TODO(chobie): implement this */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_lookup_map_value not implemented yet"); @@ -863,8 +853,6 @@ PHP_FUNCTION(git_config_backend_foreach_match) { zval *backend; php_git2_t *_backend; - char *regexp = {0}; - int regexp_len; long ; /* TODO(chobie): implement this */ diff --git a/giterr.c b/giterr.c index b09be1e2e6..23229485a8 100644 --- a/giterr.c +++ b/giterr.c @@ -44,7 +44,7 @@ PHP_FUNCTION(giterr_clear) */ PHP_FUNCTION(giterr_detach) { - int result = 0, error = 0; + int result = 0; git_error cpy; zval *array; diff --git a/graph.c b/graph.c index 0d3c9265e6..cd2463d619 100644 --- a/graph.c +++ b/graph.c @@ -6,7 +6,7 @@ */ PHP_FUNCTION(git_graph_ahead_behind) { - int result = 0, local_len = 0, upstream_len = 0, error = 0; + int result = 0, local_len = 0, upstream_len = 0; zval *repo = NULL, *array = NULL; php_git2_t *_repo = NULL; char *local = NULL, *upstream = NULL; diff --git a/helper.c b/helper.c index 79150f34a9..84c898d2f1 100644 --- a/helper.c +++ b/helper.c @@ -379,7 +379,6 @@ void php_git2_git_checkout_progress_cb(const char *path, size_t total_steps, void *payload) { - php_git2_t *result; zval *param_path, *param_completed_steps, *param_total_steps, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; GIT2_TSRMLS_SET(p->tsrm_ls); @@ -457,7 +456,6 @@ int php_git2_array_to_git_checkout_opts(git_checkout_opts **out, zval *array TSR git_checkout_opts *opts = NULL, def = GIT_CHECKOUT_OPTS_INIT; php_git2_cb_t *notify_payload = NULL, *progress_payload= NULL; zval *notify_cb = NULL, *progress_cb = NULL; - char *tmp; opts = (git_checkout_opts*)emalloc(sizeof(struct git_checkout_opts)); memcpy(opts, &def, sizeof(git_checkout_opts)); @@ -704,10 +702,9 @@ int php_git2_git_diff_file_cb( float progress, void *payload) { - php_git2_t *result; zval *param_delta = NULL, *param_progress = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) Z_ADDREF_P(p->payload); @@ -728,10 +725,9 @@ int php_git2_git_diff_hunk_cb( const git_diff_hunk *hunk, void *payload) { - php_git2_t *result; zval *param_delta = NULL, *param_hunk = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) Z_ADDREF_P(p->payload); @@ -752,10 +748,9 @@ int php_git2_git_diff_line_cb( const git_diff_hunk *hunk, const git_diff_line *line, void *payload) { - php_git2_t *result; zval *param_delta = NULL, *param_hunk = NULL, *param_line = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) Z_ADDREF_P(p->payload); diff --git a/ignore.c b/ignore.c index 8af6a75ebe..56dab079ae 100644 --- a/ignore.c +++ b/ignore.c @@ -6,7 +6,7 @@ */ PHP_FUNCTION(git_ignore_add_rule) { - int result = 0, rules_len = 0, error = 0; + int result = 0, rules_len = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *rules = NULL; @@ -26,7 +26,7 @@ PHP_FUNCTION(git_ignore_add_rule) */ PHP_FUNCTION(git_ignore_clear_internal_rules) { - int result = 0, error = 0; + int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; @@ -45,7 +45,7 @@ PHP_FUNCTION(git_ignore_clear_internal_rules) */ PHP_FUNCTION(git_ignore_path_is_ignored) { - int result = 0, path_len = 0, error = 0; + int result = 0, path_len = 0; long ignored = 0; zval *repo = NULL; php_git2_t *_repo = NULL; diff --git a/index.c b/index.c index f7f4915ad0..4e7d5be4e7 100644 --- a/index.c +++ b/index.c @@ -4,10 +4,8 @@ static int php_git2_index_matched_path_cb(const char *path, const char *matched_pathspec, void *payload) { - php_git2_t *result; zval *param_path, *param_matched_pathspec, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -335,7 +333,6 @@ PHP_FUNCTION(git_index_write_tree_to) zval *repo; php_git2_t *_repo; git_oid id; - char out[GIT2_OID_HEXSIZE]= {0}; int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -570,8 +567,8 @@ PHP_FUNCTION(git_index_remove_bypath) */ PHP_FUNCTION(git_index_add_all) { - int result = 0, error = 0; - zval *index = NULL, *pathspec = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *index = NULL, *pathspec = NULL, *payload = NULL; php_git2_t *_index = NULL; git_strarray _pathspec = {0}; long flags = 0; @@ -601,8 +598,8 @@ PHP_FUNCTION(git_index_add_all) */ PHP_FUNCTION(git_index_remove_all) { - int result = 0, error = 0; - zval *index = NULL, *pathspec = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *index = NULL, *pathspec = NULL, *payload = NULL; php_git2_t *_index = NULL; git_strarray _pathspec = {0}; zend_fcall_info fci = empty_fcall_info; @@ -631,8 +628,8 @@ PHP_FUNCTION(git_index_remove_all) */ PHP_FUNCTION(git_index_update_all) { - int result = 0, error = 0; - zval *index = NULL, *pathspec = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *index = NULL, *pathspec = NULL, *payload = NULL; php_git2_t *_index = NULL; git_strarray _pathspec = {0}; zend_fcall_info fci = empty_fcall_info; @@ -681,7 +678,7 @@ PHP_FUNCTION(git_index_find) */ PHP_FUNCTION(git_index_conflict_add) { - int result = 0, error = 0; + int result = 0; zval *index = NULL, *ancestor_entry = NULL, *our_entry = NULL, *their_entry = NULL; php_git2_t *_index = NULL; git_index_entry ancestor = {0}, our = {0}, their = {0}; @@ -705,7 +702,7 @@ PHP_FUNCTION(git_index_conflict_add) */ PHP_FUNCTION(git_index_conflict_get) { - php_git2_t *result = NULL, *_index = NULL; + php_git2_t *_index = NULL; git_index_entry *ancestor_out = NULL, *our_out = NULL, *their_out = NULL; zval *index = NULL, *ancestor, *our, *their, *container; char *path = NULL; @@ -738,7 +735,7 @@ PHP_FUNCTION(git_index_conflict_get) */ PHP_FUNCTION(git_index_conflict_remove) { - int result = 0, path_len = 0, error = 0; + int result = 0, path_len = 0; zval *index = NULL; php_git2_t *_index = NULL; char *path = NULL; @@ -818,7 +815,7 @@ PHP_FUNCTION(git_index_conflict_iterator_new) */ PHP_FUNCTION(git_index_conflict_next) { - php_git2_t *result = NULL, *_iterator = NULL; + php_git2_t *_iterator = NULL; git_index_entry *ancestor_out = NULL, *our_out = NULL, *their_out = NULL; zval *iterator = NULL, *ancestor, *our, *their, *container; int error = 0; diff --git a/indexer.c b/indexer.c index fcc4ff25c9..e5184eea97 100644 --- a/indexer.c +++ b/indexer.c @@ -11,7 +11,7 @@ PHP_FUNCTION(git_indexer_new) char *path = NULL; int path_len = 0, error = 0; long mode = 0; - zval *odb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL; + zval *odb = NULL, *progress_cb_payload = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; php_git2_cb_t *cb = NULL; @@ -40,11 +40,6 @@ PHP_FUNCTION(git_indexer_new) */ PHP_FUNCTION(git_indexer_append) { - int result = 0, error = 0; - zval *idx = NULL, *stats = NULL; - php_git2_t *_idx = NULL; - zval *data = NULL; - long size = 0; // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, // "rl", &idx, &data, &size, &stats) == FAILURE) { @@ -61,9 +56,6 @@ PHP_FUNCTION(git_indexer_append) */ PHP_FUNCTION(git_indexer_commit) { - int result = 0, error = 0; - zval *idx = NULL, *stats = NULL; - php_git2_t *_idx = NULL; // if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, // "r", &idx, &stats) == FAILURE) { diff --git a/merge.c b/merge.c index d31baa54e0..37c88e9f00 100644 --- a/merge.c +++ b/merge.c @@ -6,7 +6,7 @@ */ PHP_FUNCTION(git_merge_base) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; git_oid out = {0}, __one = {0}, __two = {0}; zval *repo = NULL; char *one = NULL, *two = NULL, oid[41] = {0}; @@ -210,9 +210,7 @@ PHP_FUNCTION(git_merge) php_git2_t *result = NULL, *_repo = NULL, *_their_head = NULL; git_merge_result *out = NULL; zval *repo = NULL, *opts = NULL, *theirhead = NULL; - git_merge_head *their_heads = NULL; git_merge_head *heads[1]; - long their_heads_len = 0; int error = 0; git_merge_opts options = GIT_MERGE_OPTS_INIT; @@ -241,7 +239,7 @@ PHP_FUNCTION(git_merge) */ PHP_FUNCTION(git_merge_result_is_uptodate) { - int result = 0, error = 0; + int result = 0; zval *merge_result = NULL; php_git2_t *_merge_result = NULL; @@ -260,7 +258,7 @@ PHP_FUNCTION(git_merge_result_is_uptodate) */ PHP_FUNCTION(git_merge_result_is_fastforward) { - int result = 0, error = 0; + int result = 0; zval *merge_result = NULL; php_git2_t *_merge_result = NULL; @@ -279,7 +277,7 @@ PHP_FUNCTION(git_merge_result_is_fastforward) */ PHP_FUNCTION(git_merge_result_fastforward_oid) { - php_git2_t *result = NULL, *_merge_result = NULL; + php_git2_t *_merge_result = NULL; git_oid out = {0}; zval *merge_result = NULL; int error = 0; diff --git a/message.c b/message.c index c9be40e316..f23b00cbb4 100644 --- a/message.c +++ b/message.c @@ -6,7 +6,6 @@ */ PHP_FUNCTION(git_message_prettify) { - php_git2_t *result = NULL; char *out = NULL, *message = NULL; long out_size = 0, strip_comments = 0; int message_len = 0, error = 0; diff --git a/note.c b/note.c index 5a743f8860..595fb70ee2 100644 --- a/note.c +++ b/note.c @@ -54,7 +54,7 @@ PHP_FUNCTION(git_note_iterator_free) */ PHP_FUNCTION(git_note_next) { - int result = 0, note_id_len = 0, annotated_id_len = 0, error = 0; + int result = 0, note_id_len = 0, annotated_id_len = 0; char *note_id = NULL, *annotated_id = NULL; zval *it = NULL; php_git2_t *_it = NULL; @@ -145,7 +145,7 @@ PHP_FUNCTION(git_note_oid) */ PHP_FUNCTION(git_note_create) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; git_oid out = {0}, __oid = {0}; zval *repo = NULL, *author = NULL, *committer = NULL; char *notes_ref = NULL, *oid = NULL, *note = NULL; @@ -175,7 +175,7 @@ PHP_FUNCTION(git_note_create) */ PHP_FUNCTION(git_note_remove) { - int result = 0, notes_ref_len = 0, oid_len = 0, error = 0; + int result = 0, notes_ref_len = 0, oid_len = 0; zval *repo = NULL, *author = NULL, *committer = NULL; php_git2_t *_repo = NULL; char *notes_ref = NULL, *oid = NULL; @@ -220,7 +220,7 @@ PHP_FUNCTION(git_note_free) */ PHP_FUNCTION(git_note_default_ref) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; char *out = NULL; zval *repo = NULL; int error = 0; @@ -243,8 +243,8 @@ PHP_FUNCTION(git_note_default_ref) */ PHP_FUNCTION(git_note_foreach) { - int result = 0, notes_ref_len = 0, error = 0; - zval *repo = NULL, *note_cb = NULL, *payload = NULL; + int result = 0, notes_ref_len = 0; + zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; char *notes_ref = NULL; zend_fcall_info fci = empty_fcall_info; diff --git a/object.c b/object.c index 3ccc98e758..d95b64c1a6 100644 --- a/object.c +++ b/object.c @@ -6,7 +6,7 @@ */ PHP_FUNCTION(git_object_lookup) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; git_object *object = NULL; zval *repo = NULL; php_git2_t *_repo = NULL; @@ -208,7 +208,7 @@ PHP_FUNCTION(git_object_string2type) */ PHP_FUNCTION(git_object_typeisloose) { - int result = 0, error = 0; + int result = 0; long type = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -240,7 +240,7 @@ PHP_FUNCTION(git_object__size) */ PHP_FUNCTION(git_object_peel) { - int result = 0, error = 0; + int result = 0; git_object *peeled = NULL; zval *object = NULL; php_git2_t *_object = NULL, *_result; @@ -264,7 +264,7 @@ PHP_FUNCTION(git_object_peel) */ PHP_FUNCTION(git_object_dup) { - int result = 0, error = 0; + int result = 0; git_object *dest = NULL; zval *source = NULL; php_git2_t *_source = NULL, *_result = NULL; diff --git a/odb.c b/odb.c index d4912f8c05..35fa1d2651 100644 --- a/odb.c +++ b/odb.c @@ -4,10 +4,8 @@ static int php_git2_git_odb_foreach_cb(const git_oid *id, void *payload) { - php_git2_t *result; zval *param_oid, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; char buf[41] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -75,7 +73,7 @@ PHP_FUNCTION(git_odb_open) */ PHP_FUNCTION(git_odb_add_disk_alternate) { - int result = 0, path_len = 0, error = 0; + int result = 0, path_len = 0; zval *odb = NULL; php_git2_t *_odb = NULL; char *path = NULL; @@ -153,7 +151,6 @@ PHP_FUNCTION(git_odb_read_prefix) char *short_id = NULL; int short_id_len = 0, error = 0; git_oid __short_id = {0}; - long len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &db, &short_id, &short_id_len) == FAILURE) { @@ -179,7 +176,7 @@ PHP_FUNCTION(git_odb_read_prefix) */ PHP_FUNCTION(git_odb_read_header) { - php_git2_t *result = NULL, *_db = NULL; + php_git2_t *_db = NULL; size_t len_out = NULL; zval *db = NULL, *_result = NULL; git_otype type_out; @@ -212,7 +209,7 @@ PHP_FUNCTION(git_odb_read_header) */ PHP_FUNCTION(git_odb_exists) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; zval *db = NULL; php_git2_t *_db = NULL; char *id = NULL; @@ -236,7 +233,7 @@ PHP_FUNCTION(git_odb_exists) */ PHP_FUNCTION(git_odb_refresh) { - int result = 0, error = 0; + int result = 0; zval *db = NULL; php_git2_t *_db = NULL; @@ -255,7 +252,7 @@ PHP_FUNCTION(git_odb_refresh) */ PHP_FUNCTION(git_odb_foreach) { - int result = 0, error = 0; + int result = 0; zval *db = NULL, *payload = NULL; php_git2_t *_db = NULL; zend_fcall_info fci = empty_fcall_info; @@ -281,7 +278,7 @@ PHP_FUNCTION(git_odb_foreach) */ PHP_FUNCTION(git_odb_write) { - php_git2_t *result = NULL, *_odb = NULL; + php_git2_t *_odb = NULL; git_oid out = {0}; zval *odb = NULL; zval *data = NULL; @@ -335,7 +332,7 @@ PHP_FUNCTION(git_odb_open_wstream) */ PHP_FUNCTION(git_odb_stream_write) { - int result = 0, buffer_len = 0, error = 0; + int result = 0, buffer_len = 0; zval *stream = NULL; php_git2_t *_stream = NULL; char *buffer = NULL; @@ -355,7 +352,7 @@ PHP_FUNCTION(git_odb_stream_write) */ PHP_FUNCTION(git_odb_stream_finalize_write) { - php_git2_t *result = NULL, *_stream = NULL; + php_git2_t *_stream = NULL; git_oid out = {0}; zval *stream = NULL; int error = 0; @@ -380,7 +377,7 @@ PHP_FUNCTION(git_odb_stream_finalize_write) */ PHP_FUNCTION(git_odb_stream_read) { - int result = 0, buffer_len = 0, error = 0; + int result = 0, buffer_len = 0; zval *stream = NULL; php_git2_t *_stream = NULL; char *buffer = NULL; @@ -485,7 +482,6 @@ PHP_FUNCTION(git_odb_write_pack) */ PHP_FUNCTION(git_odb_hash) { - php_git2_t *result = NULL; git_oid out = {0}; zval *data = NULL; int error = 0, data_len = 0; @@ -509,7 +505,6 @@ PHP_FUNCTION(git_odb_hash) */ PHP_FUNCTION(git_odb_hashfile) { - php_git2_t *result = NULL; git_oid out = {0}; char *path = NULL; int path_len = 0, error = 0; @@ -533,7 +528,7 @@ PHP_FUNCTION(git_odb_hashfile) */ PHP_FUNCTION(git_odb_object_dup) { - int result = 0, error = 0; + int result = 0; git_odb_object *dest = NULL; zval *source = NULL; php_git2_t *_source = NULL; @@ -652,7 +647,7 @@ PHP_FUNCTION(git_odb_object_type) */ PHP_FUNCTION(git_odb_add_backend) { - int result = 0, error = 0; + int result = 0; zval *odb = NULL, *backend = NULL; php_git2_t *_odb = NULL, *_backend = NULL; long priority = 0; @@ -673,7 +668,7 @@ PHP_FUNCTION(git_odb_add_backend) */ PHP_FUNCTION(git_odb_add_alternate) { - int result = 0, error = 0; + int result = 0; zval *odb = NULL, *backend = NULL; php_git2_t *_odb = NULL, *_backend = NULL; long priority = 0; @@ -738,11 +733,10 @@ PHP_FUNCTION(git_odb_get_backend) static int php_git2_odb_backend_read(void **buffer, size_t *size, git_otype *type, git_odb_backend *backend, const git_oid *oid) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; zval *param_oid = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); char buf[41] = {0}; @@ -781,11 +775,10 @@ static int php_git2_odb_backend_read(void **buffer, size_t *size, git_otype *typ } static int php_git2_odb_backend_write(git_odb_backend *backend, const git_oid *oid, const void *buffer, size_t size, git_otype type) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; zval *param_oid = NULL, *param_buffer = NULL, *param_otype = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); char buf[41] = {0}; @@ -815,11 +808,10 @@ static int php_git2_odb_backend_read_prefix(git_oid *out_oid, const git_oid *short_oid, size_t len) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; zval *param_short_oid = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); char buf[41] = {0}; @@ -866,11 +858,10 @@ static int php_git2_odb_backend_read_prefix(git_oid *out_oid, static int php_git2_odb_backend_read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; zval *param_oid = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); char buf[41] = {0}; @@ -906,11 +897,10 @@ static int php_git2_odb_backend_writestream(git_odb_stream **stream_out, git_odb } static int php_git2_odb_backend_exists(git_odb_backend *backend, const git_oid *oid) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; zval *param_oid = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); char buf[41] = {0}; @@ -963,14 +953,13 @@ static void git_ex_cb(INTERNAL_FUNCTION_PARAMETERS) static int php_git2_odb_backend_foreach(git_odb_backend *backend, git_odb_foreach_cb cb, void *data) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)backend; - zval *param_callback = NULL, *callback = NULL, *retval_ptr = NULL, *param_payload = (zval*)data; + zval *param_callback = NULL, *callback = NULL, *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; zend_function function = {0}; php_git2_odb_backend_foreach_callback *_callback; php_git2_cb_t *__cb = (php_git2_cb_t*)data; - int i = 0, retval = 0; + int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); MAKE_STD_ZVAL(callback); @@ -1012,11 +1001,9 @@ static int php_git2_odb_backend_foreach(git_odb_backend *backend, git_odb_foreac static void php_git2_odb_backend_free(git_odb_backend *_backend) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)_backend; zval *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; - int i = 0, retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); if (php_git2_call_function_v(&p->callbacks[7].fci, &p->callbacks[7].fcc TSRMLS_CC, &retval_ptr, 0)) { return; @@ -1028,11 +1015,9 @@ static void php_git2_odb_backend_free(git_odb_backend *_backend) static void php_git2_odb_refresh(git_odb_backend *_backend) { - php_git2_t *result; php_git2_odb_backend *php_backend = (php_git2_odb_backend*)_backend; zval *retval_ptr = NULL; php_git2_multi_cb_t *p = php_backend->multi; - int i = 0, retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls); if (php_git2_call_function_v(&p->callbacks[8].fci, &p->callbacks[8].fcc TSRMLS_CC, &retval_ptr, 0)) { return; diff --git a/packbuilder.c b/packbuilder.c index 195950a1e7..4fafa08cb3 100644 --- a/packbuilder.c +++ b/packbuilder.c @@ -8,10 +8,8 @@ static int php_git2_git_packbuilder_progress( unsigned int total, void *payload) { - php_git2_t *result; zval *param_stage = NULL, *param_current = NULL, *param_total = NULL, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -37,10 +35,8 @@ static int php_git2_git_packbuilder_progress( static int php_git2_git_packbuilder_foreach_cb(void *buf, size_t size, void *payload) { - php_git2_t *result; zval *param_buf= NULL, *param_size = NULL, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -65,10 +61,8 @@ static int php_git2_git_packbuilder_foreach_cb(void *buf, size_t size, void *pay static int php_git2_git_transfer_progress_callback(const git_transfer_progress *stats, void *payload) { - php_git2_t *result; zval *param_stats = NULL, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -138,7 +132,7 @@ PHP_FUNCTION(git_packbuilder_set_threads) */ PHP_FUNCTION(git_packbuilder_insert) { - int result = 0, id_len = 0, name_len = 0, error = 0; + int result = 0, id_len = 0, name_len = 0; zval *pb = NULL; php_git2_t *_pb = NULL; char *id = NULL, *name = NULL; @@ -162,7 +156,7 @@ PHP_FUNCTION(git_packbuilder_insert) */ PHP_FUNCTION(git_packbuilder_insert_tree) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; zval *pb = NULL; php_git2_t *_pb = NULL; char *id = NULL; @@ -186,7 +180,7 @@ PHP_FUNCTION(git_packbuilder_insert_tree) */ PHP_FUNCTION(git_packbuilder_insert_commit) { - int result = 0, id_len = 0, error = 0; + int result = 0, id_len = 0; zval *pb = NULL; php_git2_t *_pb = NULL; char *id = NULL; @@ -210,8 +204,8 @@ PHP_FUNCTION(git_packbuilder_insert_commit) */ PHP_FUNCTION(git_packbuilder_write) { - int result = 0, path_len = 0, error = 0; - zval *pb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL; + int result = 0, path_len = 0; + zval *pb = NULL, *progress_cb_payload = NULL; php_git2_t *_pb = NULL; char *path = NULL; long mode = 0; @@ -260,7 +254,7 @@ PHP_FUNCTION(git_packbuilder_hash) */ PHP_FUNCTION(git_packbuilder_foreach) { - int result = 0, error = 0; + int result = 0; zval *pb = NULL, *payload = NULL; php_git2_t *_pb = NULL; zend_fcall_info fci = empty_fcall_info; @@ -324,8 +318,8 @@ PHP_FUNCTION(git_packbuilder_written) */ PHP_FUNCTION(git_packbuilder_set_callbacks) { - int result = 0, error = 0; - zval *pb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL; + int result = 0; + zval *pb = NULL, *progress_cb_payload = NULL; php_git2_t *_pb = NULL; zend_fcall_info fci = empty_fcall_info, *_fci; zend_fcall_info_cache fcc = empty_fcall_info_cache, *_fcc; diff --git a/patch.c b/patch.c index e51513404a..267025424c 100644 --- a/patch.c +++ b/patch.c @@ -157,7 +157,7 @@ PHP_FUNCTION(git_patch_num_hunks) */ PHP_FUNCTION(git_patch_line_stats) { - int result = 0, error = 0; + int result = 0; size_t total_context = 0, total_additions = 0, total_deletions = 0; zval *patch = NULL, *out = NULL; php_git2_t *_patch = NULL; @@ -209,7 +209,7 @@ PHP_FUNCTION(git_patch_get_hunk) */ PHP_FUNCTION(git_patch_num_lines_in_hunk) { - int result = 0, error = 0; + int result = 0; zval *patch = NULL; php_git2_t *_patch = NULL; long hunk_idx = 0; @@ -276,8 +276,8 @@ PHP_FUNCTION(git_patch_size) */ PHP_FUNCTION(git_patch_print) { - int result = 0, error = 0; - zval *patch = NULL, *print_cb = NULL, *payload = NULL; + int result = 0; + zval *patch = NULL, *payload = NULL; php_git2_t *_patch = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -305,7 +305,7 @@ PHP_FUNCTION(git_patch_print) */ PHP_FUNCTION(git_patch_to_str) { - int result = 0, string_len = 0, error = 0; + int result = 0; char *string = NULL; zval *patch = NULL; php_git2_t *_patch = NULL; diff --git a/pathspec.c b/pathspec.c index 00b6377bae..05bc5b0470 100644 --- a/pathspec.c +++ b/pathspec.c @@ -56,7 +56,7 @@ PHP_FUNCTION(git_pathspec_free) */ PHP_FUNCTION(git_pathspec_matches_path) { - int result = 0, path_len = 0, error = 0; + int result = 0, path_len = 0; zval *ps = NULL; php_git2_t *_ps = NULL; long flags = 0; diff --git a/php_git2.c b/php_git2.c index 2f07f43714..033a987a8e 100644 --- a/php_git2.c +++ b/php_git2.c @@ -314,7 +314,6 @@ ZEND_END_ARG_INFO() */ PHP_FUNCTION(git_resource_type) { - int result = 0; zval *resource = NULL; php_git2_t *_resource= NULL; diff --git a/push.c b/push.c index 7bc1f6cc63..2e678f026a 100644 --- a/push.c +++ b/push.c @@ -7,7 +7,6 @@ static int php_git2_push_status_foreach_cb(const char *ref, const char *msg, voi php_git2_t *result; zval *param_ref, *param_msg, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)data; - int i = 0; int retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -64,7 +63,7 @@ PHP_FUNCTION(git_push_new) */ PHP_FUNCTION(git_push_set_options) { - int result = 0, error = 0; + int result = 0; zval *push = NULL, *opts = NULL; php_git2_t *_push = NULL; @@ -83,8 +82,8 @@ PHP_FUNCTION(git_push_set_options) */ PHP_FUNCTION(git_push_set_callbacks) { - int result = 0, error = 0; - zval *push = NULL, *pack_progress_cb = NULL, *pack_progress_cb_payload = NULL, *transfer_progress_cb = NULL, *transfer_progress_cb_payload = NULL; + int result = 0; + zval *push = NULL, *pack_progress_cb_payload = NULL, *transfer_progress_cb_payload = NULL; php_git2_t *_push = NULL; zend_fcall_info pack_fci = empty_fcall_info; zend_fcall_info_cache pack_fcc = empty_fcall_info_cache; @@ -118,7 +117,7 @@ PHP_FUNCTION(git_push_set_callbacks) */ PHP_FUNCTION(git_push_add_refspec) { - int result = 0, refspec_len = 0, error = 0; + int result = 0, refspec_len = 0; zval *push = NULL; php_git2_t *_push = NULL; char *refspec = NULL; @@ -138,7 +137,7 @@ PHP_FUNCTION(git_push_add_refspec) */ PHP_FUNCTION(git_push_update_tips) { - int result = 0, error = 0; + int result = 0; zval *push = NULL; php_git2_t *_push = NULL; @@ -157,7 +156,7 @@ PHP_FUNCTION(git_push_update_tips) */ PHP_FUNCTION(git_push_finish) { - int result = 0, error = 0; + int result = 0; zval *push = NULL; php_git2_t *_push = NULL; @@ -176,7 +175,7 @@ PHP_FUNCTION(git_push_finish) */ PHP_FUNCTION(git_push_unpack_ok) { - int result = 0, error = 0; + int result = 0; zval *push = NULL; php_git2_t *_push = NULL; diff --git a/reference.c b/reference.c index 8b08faf514..adae07a77e 100644 --- a/reference.c +++ b/reference.c @@ -7,7 +7,6 @@ static int php_git2_reference_foreach_cb(git_reference *reference, void *payload php_git2_t *result; zval *param_reference, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -34,7 +33,6 @@ static int php_git2_reference_foreach_name_cb(const char *name, void *payload) php_git2_t *result; zval *param_name, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -406,7 +404,7 @@ PHP_FUNCTION(git_reference_set_target) */ PHP_FUNCTION(git_reference_rename) { - int result = 0, new_name_len = 0, error = 0; + int result = 0, new_name_len = 0; git_reference *new_ref = NULL; zval *ref = NULL; php_git2_t *_ref = NULL; @@ -428,7 +426,7 @@ PHP_FUNCTION(git_reference_rename) */ PHP_FUNCTION(git_reference_delete) { - int result = 0, error = 0; + int result = 0; zval *ref = NULL; php_git2_t *_ref = NULL; @@ -452,7 +450,7 @@ PHP_FUNCTION(git_reference_list) php_git2_t *_repo; git_strarray list; zval *result; - int error, i; + int error; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { @@ -476,8 +474,8 @@ PHP_FUNCTION(git_reference_list) */ PHP_FUNCTION(git_reference_foreach) { - int result = 0, error = 0; - zval *repo = NULL, *callback = NULL; + int result = 0; + zval *repo = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -503,8 +501,8 @@ PHP_FUNCTION(git_reference_foreach) */ PHP_FUNCTION(git_reference_foreach_name) { - int result = 0, error = 0; - zval *repo = NULL, *callback = NULL; + int result = 0; + zval *repo = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -653,7 +651,7 @@ PHP_FUNCTION(git_reference_next) */ PHP_FUNCTION(git_reference_next_name) { - php_git2_t *result = NULL, *_iter = NULL; + php_git2_t *_iter = NULL; const char *out = NULL; zval *iter = NULL; int error = 0; @@ -698,8 +696,8 @@ PHP_FUNCTION(git_reference_iterator_free) */ PHP_FUNCTION(git_reference_foreach_glob) { - int result = 0, glob_len = 0, error = 0; - zval *repo = NULL, *callback = NULL; + int result = 0, glob_len = 0; + zval *repo = NULL; php_git2_t *_repo = NULL; char *glob = NULL; zend_fcall_info fci = empty_fcall_info; diff --git a/reflog.c b/reflog.c index a31ab5795d..35d95fdec1 100644 --- a/reflog.c +++ b/reflog.c @@ -33,7 +33,7 @@ PHP_FUNCTION(git_reflog_read) */ PHP_FUNCTION(git_reflog_write) { - int result = 0, error = 0; + int result = 0; zval *reflog = NULL; php_git2_t *_reflog = NULL; @@ -52,7 +52,7 @@ PHP_FUNCTION(git_reflog_write) */ PHP_FUNCTION(git_reflog_append) { - int result = 0, id_len = 0, msg_len = 0, error = 0; + int result = 0, id_len = 0, msg_len = 0; zval *reflog = NULL, *committer = NULL; php_git2_t *_reflog = NULL; char *id = NULL, *msg = NULL; @@ -76,7 +76,7 @@ PHP_FUNCTION(git_reflog_append) */ PHP_FUNCTION(git_reflog_append_to) { - int result = 0, name_len = 0, id_len = 0, msg_len = 0, error = 0; + int result = 0, name_len = 0, id_len = 0, msg_len = 0; zval *repo = NULL, *committer = NULL; php_git2_t *_repo = NULL; char *name = NULL, *id = NULL, *msg = NULL; @@ -100,7 +100,7 @@ PHP_FUNCTION(git_reflog_append_to) */ PHP_FUNCTION(git_reflog_rename) { - int result = 0, old_name_len = 0, name_len = 0, error = 0; + int result = 0, old_name_len = 0, name_len = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *old_name = NULL, *name = NULL; @@ -120,7 +120,7 @@ PHP_FUNCTION(git_reflog_rename) */ PHP_FUNCTION(git_reflog_delete) { - int result = 0, name_len = 0, error = 0; + int result = 0, name_len = 0; zval *repo = NULL; php_git2_t *_repo = NULL; char *name = NULL; @@ -182,7 +182,7 @@ PHP_FUNCTION(git_reflog_entry_byindex) */ PHP_FUNCTION(git_reflog_drop) { - int result = 0, error = 0; + int result = 0; zval *reflog = NULL; php_git2_t *_reflog = NULL; long idx = 0, rewrite_previous_entry = 0; diff --git a/refspec.c b/refspec.c index 1cbd56f48e..72506b1f0d 100644 --- a/refspec.c +++ b/refspec.c @@ -63,7 +63,7 @@ PHP_FUNCTION(git_refspec_string) */ PHP_FUNCTION(git_refspec_force) { - int result = 0, error = 0; + int result = 0; zval *refspec = NULL; php_git2_t *_refspec = NULL; @@ -101,7 +101,7 @@ PHP_FUNCTION(git_refspec_direction) */ PHP_FUNCTION(git_refspec_src_matches) { - int result = 0, refname_len = 0, error = 0; + int result = 0, refname_len = 0; zval *refspec = NULL; php_git2_t *_refspec = NULL; char *refname = NULL; @@ -121,7 +121,7 @@ PHP_FUNCTION(git_refspec_src_matches) */ PHP_FUNCTION(git_refspec_dst_matches) { - int result = 0, refname_len = 0, error = 0; + int result = 0, refname_len = 0; zval *refspec = NULL; php_git2_t *_refspec = NULL; char *refname = NULL; @@ -141,7 +141,7 @@ PHP_FUNCTION(git_refspec_dst_matches) */ PHP_FUNCTION(git_refspec_transform) { - php_git2_t *result = NULL, *_spec = NULL; + php_git2_t *_spec = NULL; char out = NULL, *name = NULL; long outlen = 0; zval *spec = NULL; @@ -165,7 +165,7 @@ PHP_FUNCTION(git_refspec_transform) */ PHP_FUNCTION(git_refspec_rtransform) { - php_git2_t *result = NULL, *_spec = NULL; + php_git2_t *_spec = NULL; char out = NULL, *name = NULL; long outlen = 0; zval *spec = NULL; diff --git a/remote.c b/remote.c index 2ce4b76f64..48ebf89aed 100644 --- a/remote.c +++ b/remote.c @@ -119,7 +119,6 @@ PHP_FUNCTION(git_remote_save) int result = 0; zval *remote = NULL; php_git2_t *_remote = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { @@ -220,7 +219,6 @@ PHP_FUNCTION(git_remote_set_url) php_git2_t *_remote = NULL; char *url = NULL; int url_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &url, &url_len) == FAILURE) { @@ -242,7 +240,6 @@ PHP_FUNCTION(git_remote_set_pushurl) php_git2_t *_remote = NULL; char *url = NULL; int url_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &url, &url_len) == FAILURE) { @@ -265,7 +262,6 @@ PHP_FUNCTION(git_remote_add_fetch) php_git2_t *_remote = NULL; char *refspec = NULL; int refspec_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &refspec, &refspec_len) == FAILURE) { @@ -312,7 +308,6 @@ PHP_FUNCTION(git_remote_set_fetch_refspecs) int result = 0; zval *remote = NULL, *array = NULL; php_git2_t *_remote = NULL; - int error = 0; git_strarray out = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -339,7 +334,6 @@ PHP_FUNCTION(git_remote_add_push) php_git2_t *_remote = NULL; char *refspec = NULL; int refspec_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &remote, &refspec, &refspec_len) == FAILURE) { @@ -356,7 +350,6 @@ PHP_FUNCTION(git_remote_add_push) */ PHP_FUNCTION(git_remote_get_push_refspecs) { - zval *result; git_strarray _array = {0}; zval *remote = NULL, *array = NULL; php_git2_t *_remote = NULL; @@ -385,7 +378,6 @@ PHP_FUNCTION(git_remote_set_push_refspecs) zval *remote = NULL, *array = NULL; php_git2_t *_remote = NULL; git_strarray _array = {0}; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote, &array) == FAILURE) { @@ -469,7 +461,6 @@ PHP_FUNCTION(git_remote_connect) zval *remote = NULL; php_git2_t *_remote = NULL; long direction = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &remote, &direction) == FAILURE) { @@ -505,7 +496,6 @@ static void php_git2_git_remote_head_to_array(git_remote_head *head, zval **out */ PHP_FUNCTION(git_remote_ls) { - php_git2_t *result = NULL; git_remote_head **out = NULL; size_t size = 0; zval *remote = NULL, *retval = NULL, *container = NULL; @@ -546,7 +536,6 @@ PHP_FUNCTION(git_remote_download) int result = 0; zval *remote = NULL; php_git2_t *_remote = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { @@ -567,7 +556,6 @@ PHP_FUNCTION(git_remote_connected) int result = 0; zval *remote = NULL; php_git2_t *_remote = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { @@ -643,7 +631,6 @@ PHP_FUNCTION(git_remote_update_tips) int result = 0; zval *remote = NULL; php_git2_t *_remote = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { @@ -664,7 +651,6 @@ PHP_FUNCTION(git_remote_fetch) int result = 0; zval *remote = NULL; php_git2_t *_remote = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { @@ -684,7 +670,6 @@ PHP_FUNCTION(git_remote_valid_url) int result = 0; char *url = NULL; int url_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &url_len) == FAILURE) { @@ -703,7 +688,6 @@ PHP_FUNCTION(git_remote_supported_url) int result = 0; char *url = NULL; int url_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &url_len) == FAILURE) { @@ -773,7 +757,6 @@ PHP_FUNCTION(git_remote_set_transport) php_git2_t *_remote = NULL; zval *transport = NULL; php_git2_t *_transport = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &remote, &transport) == FAILURE) { @@ -839,9 +822,8 @@ PHP_FUNCTION(git_remote_set_callbacks) zval *remote; php_git2_t *_remote; zval *callbacks, *credentials_cb = NULL; - php_git2_t *_callbacks; struct git_remote_callbacks cb = GIT_REMOTE_CALLBACKS_INIT; - php_git2_remote_cb_t *_payload = NULL, payload = {0}; + php_git2_remote_cb_t *_payload = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &remote, &callbacks) == FAILURE) { @@ -941,8 +923,8 @@ static int php_git2_git_remote_rename_problem_cb(const char *problematic_refspec */ PHP_FUNCTION(git_remote_rename) { - int result = 0, new_name_len = 0, error = 0; - zval *remote = NULL, *callback = NULL, *payload = NULL; + int result = 0, new_name_len = 0; + zval *remote = NULL, *payload = NULL; php_git2_t *_remote = NULL; char *new_name = NULL; zend_fcall_info fci = empty_fcall_info; @@ -972,7 +954,6 @@ PHP_FUNCTION(git_remote_update_fetchhead) int result = 0; zval *remote = NULL; php_git2_t *_remote = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &remote) == FAILURE) { @@ -1010,7 +991,6 @@ PHP_FUNCTION(git_remote_is_valid_name) int result = 0; char *remote_name = NULL; int remote_name_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &remote_name, &remote_name_len) == FAILURE) { diff --git a/revwalk.c b/revwalk.c index 221a2ca2ac..1d261356b5 100644 --- a/revwalk.c +++ b/revwalk.c @@ -73,7 +73,7 @@ PHP_FUNCTION(git_revwalk_push) */ PHP_FUNCTION(git_revwalk_push_glob) { - int result = 0, glob_len = 0, error = 0; + int result = 0, glob_len = 0; zval *walk = NULL; php_git2_t *_walk = NULL; char *glob = NULL; @@ -146,7 +146,7 @@ PHP_FUNCTION(git_revwalk_hide) */ PHP_FUNCTION(git_revwalk_hide_glob) { - int result = 0, glob_len = 0, error = 0; + int result = 0, glob_len = 0; zval *walk = NULL; php_git2_t *_walk = NULL; char *glob = NULL; @@ -189,7 +189,7 @@ PHP_FUNCTION(git_revwalk_hide_head) */ PHP_FUNCTION(git_revwalk_push_ref) { - int result = 0, refname_len = 0, error = 0; + int result = 0, refname_len = 0; zval *walk = NULL; php_git2_t *_walk = NULL; char *refname = NULL; @@ -210,7 +210,7 @@ PHP_FUNCTION(git_revwalk_push_ref) */ PHP_FUNCTION(git_revwalk_hide_ref) { - int result = 0, refname_len = 0, error = 0; + int result = 0, refname_len = 0; zval *walk = NULL; php_git2_t *_walk = NULL; char *refname = NULL; @@ -274,7 +274,7 @@ PHP_FUNCTION(git_revwalk_sorting) */ PHP_FUNCTION(git_revwalk_push_range) { - int result = 0, range_len = 0, error = 0; + int result = 0, range_len = 0; zval *walk = NULL; php_git2_t *_walk = NULL; char *range = NULL; diff --git a/signature.c b/signature.c index 4a6a6017ca..e609e845f4 100644 --- a/signature.c +++ b/signature.c @@ -6,7 +6,6 @@ */ PHP_FUNCTION(git_signature_new) { - php_git2_t *result = NULL; git_signature *out = NULL; char *name = NULL, *email = NULL; int name_len = 0, email_len = 0, error = 0; @@ -32,7 +31,6 @@ PHP_FUNCTION(git_signature_new) */ PHP_FUNCTION(git_signature_now) { - php_git2_t *result = NULL; git_signature *out = NULL; char *name = NULL, *email = NULL; int name_len = 0, email_len = 0, error = 0; @@ -57,7 +55,7 @@ PHP_FUNCTION(git_signature_now) */ PHP_FUNCTION(git_signature_default) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; git_signature *out = NULL; zval *repo = NULL, *signature = NULL; int error = 0; diff --git a/stash.c b/stash.c index d6c1ffd087..1a9832a8b2 100644 --- a/stash.c +++ b/stash.c @@ -7,10 +7,8 @@ static int php_git2_stash_cb(size_t index, const git_oid *stash_id, void *payload) { - php_git2_t *result; zval *param_index, *param_message,*param_stash_id, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; char _oid[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -38,7 +36,7 @@ static int php_git2_stash_cb(size_t index, */ PHP_FUNCTION(git_stash_save) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; git_oid out = {0}; zval *repo = NULL, *stasher = NULL; char *message = NULL; @@ -65,8 +63,8 @@ PHP_FUNCTION(git_stash_save) */ PHP_FUNCTION(git_stash_foreach) { - int result = 0, error = 0; - zval *repo = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -91,7 +89,7 @@ PHP_FUNCTION(git_stash_foreach) */ PHP_FUNCTION(git_stash_drop) { - int result = 0, error = 0; + int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; long index = 0; diff --git a/status.c b/status.c index 260e01f3da..4f9c9670da 100644 --- a/status.c +++ b/status.c @@ -20,7 +20,6 @@ static void php_git2_git_status_options_to_array(git_status_options *options, zv static void php_git2_array_to_git_status_options(git_status_options *options, zval *array TSRMLS_DC) { - zval *tmp; options->version = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 1 TSRMLS_CC); options->show = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 0 TSRMLS_CC); options->flags = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 0 TSRMLS_CC); @@ -59,10 +58,8 @@ static void php_git2_git_status_entry_to_array(git_status_entry *entry, zval **o static int php_git2_git_status_cb( const char *path, unsigned int status_flags, void *payload) { - php_git2_t *result; zval *param_path, *param_status_flags, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -86,8 +83,8 @@ static int php_git2_git_status_cb( */ PHP_FUNCTION(git_status_foreach) { - int result = 0, error = 0; - zval *repo = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -112,8 +109,8 @@ PHP_FUNCTION(git_status_foreach) */ PHP_FUNCTION(git_status_foreach_ext) { - int result = 0, error = 0; - zval *repo = NULL, *opts = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *repo = NULL, *opts = NULL, *payload = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -143,7 +140,7 @@ PHP_FUNCTION(git_status_foreach_ext) */ PHP_FUNCTION(git_status_file) { - int result = 0, path_len = 0, error = 0; + int result = 0, path_len = 0; long status_flags = 0; zval *repo = NULL; php_git2_t *_repo = NULL; @@ -259,7 +256,7 @@ PHP_FUNCTION(git_status_list_free) */ PHP_FUNCTION(git_status_should_ignore) { - int result = 0, path_len = 0, error = 0; + int result = 0, path_len = 0; long ignored = 0; zval *repo = NULL; php_git2_t *_repo = NULL; diff --git a/tag.c b/tag.c index 1121ece3b8..7e788498af 100644 --- a/tag.c +++ b/tag.c @@ -7,7 +7,6 @@ static int php_git2_tag_foreach_cb(const char *name, git_oid *oid, void *payload php_git2_t *result; zval *param_name, *param_oid, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; char buffer[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -297,7 +296,7 @@ PHP_FUNCTION(git_tag_create) int result = 0; git_oid __oid; zval *repo = NULL; - php_git2_t *_repo = NULL, *out = NULL; + php_git2_t *_repo = NULL; char *tag_name = NULL; int tag_name_len = 0; zval *target = NULL; @@ -306,7 +305,6 @@ PHP_FUNCTION(git_tag_create) char *message = NULL; int message_len = 0; long force = 0; - int error = 0; char buffer[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -342,7 +340,6 @@ PHP_FUNCTION(git_tag_annotation_create) zval *tagger = NULL; char *message = NULL; int message_len = 0; - int error = 0; char buffer[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -373,7 +370,6 @@ PHP_FUNCTION(git_tag_create_frombuffer) char *buffer = NULL; int buffer_len = 0; long force = 0; - int error = 0; char oid[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -405,7 +401,6 @@ PHP_FUNCTION(git_tag_create_lightweight) zval *target = NULL; php_git2_t *_target = NULL; long force = 0; - int error = 0; char oid[GIT2_OID_HEXSIZE] = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -433,7 +428,6 @@ PHP_FUNCTION(git_tag_delete) php_git2_t *_repo = NULL; char *tag_name = NULL; int tag_name_len = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &repo, &tag_name, &tag_name_len) == FAILURE) { @@ -508,8 +502,8 @@ PHP_FUNCTION(git_tag_list_match) */ PHP_FUNCTION(git_tag_foreach) { - int result = 0, error = 0; - zval *repo = NULL, *callback = NULL; + int result = 0; + zval *repo = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; diff --git a/transport.c b/transport.c index 1bb62c1e89..4904517ab5 100644 --- a/transport.c +++ b/transport.c @@ -4,11 +4,9 @@ static int php_git2_transport_cb(git_transport **out, git_remote *owner, void *param) { - php_git2_t *result; zval *param_owner, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)param; php_git2_t *_param_owner; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -62,7 +60,7 @@ PHP_FUNCTION(git_transport_new) */ PHP_FUNCTION(git_transport_register) { - int result = 0, prefix_len = 0, error = 0; + int result = 0, prefix_len = 0; char *prefix = NULL; long priority = NULL; zval *param = NULL; @@ -89,7 +87,7 @@ PHP_FUNCTION(git_transport_register) */ PHP_FUNCTION(git_transport_unregister) { - int result = 0, prefix_len = 0, error = 0; + int result = 0, prefix_len = 0; char *prefix = NULL; long priority = 0; diff --git a/tree.c b/tree.c index 1fc2f40048..3d92ba75d9 100644 --- a/tree.c +++ b/tree.c @@ -14,7 +14,6 @@ static int tree_walk_cb(const char *root, const git_tree_entry *entry, void *pay php_git2_t *result; zval *param_root, *param_rsrc, *retval_ptr = NULL; struct tree_walk_cb_t *p = (struct tree_walk_cb_t*)payload; - int i = 0; GIT2_TSRMLS_SET(p->tsrm_ls) Z_ADDREF_P(p->payload); @@ -463,7 +462,7 @@ PHP_FUNCTION(git_tree_owner) PHP_FUNCTION(git_tree_walk) { zval *tree, *payload; - php_git2_t *git2, *result; + php_git2_t *git2; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; long mode = GIT_TREEWALK_PRE; diff --git a/treebuilder.c b/treebuilder.c index e09ee599c7..09cabd2162 100644 --- a/treebuilder.c +++ b/treebuilder.c @@ -7,7 +7,6 @@ static int php_git2_treebuilder_filter_cb(const git_tree_entry *entry, void *pay php_git2_t *result; zval *param_tree_entry, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -203,7 +202,7 @@ PHP_FUNCTION(git_treebuilder_remove) */ PHP_FUNCTION(git_treebuilder_filter) { - zval *bld = NULL, *filter = NULL; + zval *bld = NULL; php_git2_t *_bld = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; From 43f366c85ab2ddd61da40b666fad12a7ee875d76 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 23 Jan 2014 09:15:38 +0900 Subject: [PATCH 122/136] [repository] remove unused variables --- repository.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/repository.c b/repository.c index 3ecb51f088..49415fedb4 100644 --- a/repository.c +++ b/repository.c @@ -69,10 +69,8 @@ static int php_git2_repository_fetchhead_foreach_cb(const char *ref_name, unsigned int is_merge, void *payload) { - php_git2_t *result; zval *param_ref_name, *param_remote_url, *param_oid, *param_is_merge, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; char _oid[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -106,10 +104,8 @@ static int php_git2_repository_fetchhead_foreach_cb(const char *ref_name, static int php_git2_repository_mergehead_foreach_cb(const git_oid *oid, void *payload) { - php_git2_t *result; zval *param_oid, *retval_ptr = NULL; php_git2_cb_t *p = (php_git2_cb_t*)payload; - int i = 0; long retval = 0; char _oid[GIT2_OID_HEXSIZE] = {0}; GIT2_TSRMLS_SET(p->tsrm_ls) @@ -435,7 +431,6 @@ PHP_FUNCTION(git_repository_head_detached) int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { @@ -455,7 +450,6 @@ PHP_FUNCTION(git_repository_head_unborn) int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { @@ -476,7 +470,6 @@ PHP_FUNCTION(git_repository_is_empty) int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { @@ -520,7 +513,6 @@ PHP_FUNCTION(git_repository_set_workdir) char *workdir = NULL; int workdir_len = 0; long update_gitlink = 0; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &repo, &workdir, &workdir_len, &update_gitlink) == FAILURE) { @@ -540,7 +532,6 @@ PHP_FUNCTION(git_repository_is_bare) int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { @@ -694,7 +685,6 @@ PHP_FUNCTION(git_repository_message_remove) int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { @@ -714,7 +704,6 @@ PHP_FUNCTION(git_repository_merge_cleanup) int result = 0; zval *repo = NULL; php_git2_t *_repo = NULL; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &repo) == FAILURE) { @@ -731,8 +720,8 @@ PHP_FUNCTION(git_repository_merge_cleanup) */ PHP_FUNCTION(git_repository_fetchhead_foreach) { - int result = 0, error = 0; - zval *repo = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -757,8 +746,8 @@ PHP_FUNCTION(git_repository_fetchhead_foreach) */ PHP_FUNCTION(git_repository_mergehead_foreach) { - int result = 0, error = 0; - zval *repo = NULL, *callback = NULL, *payload = NULL; + int result = 0; + zval *repo = NULL, *payload = NULL; php_git2_t *_repo = NULL; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; @@ -784,7 +773,7 @@ PHP_FUNCTION(git_repository_mergehead_foreach) */ PHP_FUNCTION(git_repository_hashfile) { - php_git2_t *result = NULL, *_repo = NULL; + php_git2_t *_repo = NULL; git_oid out = {0}; zval *repo = NULL; char *path = NULL, *as_path = NULL, buf[41] = {0}; From d30bac08eeed7ef9d483e455c6719ff0829f849a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 23 Jan 2014 09:17:31 +0900 Subject: [PATCH 123/136] add simple clang warning based unused variables fixer --- fixer.php | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 fixer.php diff --git a/fixer.php b/fixer.php new file mode 100644 index 0000000000..3a7ccafe09 --- /dev/null +++ b/fixer.php @@ -0,0 +1,265 @@ + error.log +// grep "unused variables" error.log > error2.log +// php fixer.php +$data = file_get_contents("error2.log"); +$result = array(); +foreach (explode("\n", $data) as $line) { + if (preg_match("!(.+?):(\d+):(\d+): warning: unused variable '(.+?)'!", $line, $match)) { + $filename = basename($match[1]); + $line = $match[2]; + $columns = $match[3]; + $name = $match[4]; + + if ($filename == $target) { + $result[$filename][] = array( + "line" => $line, + "columns" => $columns, + "name" => $name, + ); + } + } +} + +//var_dump($result); +$file = file_get_contents($target); +$lines = explode("\n", $file); +if (!isset($result[$target])) { + echo "nothing"; + exit; +} +foreach ($result[$target] as $value) { + //echo $lines[$value['line']-1] . PHP_EOL; + + $line = $lines[$value['line']-1]; + $l = parseLine($line); + $l->remove($value['name']); + $hhh = $l->toLine(); + $lines[$value['line']-1] = $hhh; +} +$buffer = ""; +for ($i = 0; $i < count($lines); $i++) { + $line = $lines[$i]; + if ($line == "==========REMOVED==========") { + continue; + } + $buffer .= $line; + if ($i + 1 < count($lines)) { + $buffer .= "\n"; + } +} +//echo $buffer;exit; +file_put_contents($target, $buffer); + +function parseLine($line) +{ + for ($i = 0; $i < strlen($line); $i++) { + if ($line[$i] == "\t") { + continue; + } else { + break; + } + } + + $l = new Line($i); + $arg = substr($line, $i); + $type = null; + $args = array(); + $tmp = null; + $base = null; + foreach (explode(",", $arg) as $arg2) { + $tokens = preg_split("/(\s+|;)/", $arg2); + + $cnt = count($tokens); + $state = 0; + for ($i = 0; $i < $cnt; $i++) { + if ($state == 0) { + if (empty($tokens[$i])) { + continue; + } + if (!$type) { + if ($tokens[$i] != "const") { + $type = $tokens[$i]; + $state = 1; + if (!$tmp) { + $tmp = new Variable(); + $tmp->setType($tokens[$i]); + $base = clone $tmp; + } + } else { + $tmp = new Variable(); + $tmp->is_const = 1; + $tmp->setType($tokens[$i+1]); + $i++; + $state = 1; + $base = clone $tmp; + } + } else { + $state = 1; + $tmp = clone $base; + $tmp->setName($tokens[$i]); + } + } else if ($state == 1) { + if ($tokens[$i] == "=") { + $state = 2; + } else { + $tmp->setName($tokens[$i]); + } + } else if ($state == 2) { + $tmp->setDefault($tokens[$i]); + $l->add($tmp); + unset($tmp); + $state = 0; + } + } + if (isset($tmp)) { + $l->add($tmp); + } + } + + return $l; +} + +class Line +{ + public $indent; + public $variables = array(); + + public function __construct($indent) + { + $this->indent = $indent; + } + + public function add(Variable $var) + { + $this->variables[] = $var; + } + + public function remove($name) + { + foreach ($this->variables as $o => $var) { + if ($var->name == $name) { + unset($this->variables[$o]); + } + } + } + + public function isEmpty() + { + if (count($this->variables)) { + return false; + } else { + return true; + } + } + + public function toLine() + { + $type = null; + $buffer = str_repeat("\t", $this->indent); + $values = array(); + foreach ($this->variables as $var) { + if (!$type) { + if ($var->getNameWithPtr() === "") { + continue; + } + + $type = $var->type; + if ($var->is_const) { + $buffer .= "const "; + } + $buffer .= sprintf("%s ", $var->type); + + if ($var->default !== NULL) { + $values[] = sprintf("%s = %s", $var->getNameWithPtr(), $var->default); + } else { + $values[] = $var->getNameWithPtr(); + } + } else { + if ($var->getNameWithPtr() === "") { + continue; + } + + + if ($var->default !== NULL) { + $values[] = sprintf("%s = %s", $var->getNameWithPtr(), $var->default); + } else { + $values[] = $var->getNameWithPtr(); + } + } + } + + if (count($values)) { + $buffer .= join(", ", $values); + } else { + return "==========REMOVED=========="; + } + if (strlen($buffer) > $this->indent) { + $buffer .= ";"; + } + + $check = trim($buffer, " \t"); + if (!$check) { + return "==========REMOVED=========="; + } + + return $buffer; + } +} + +class Variable +{ + public $name; + public $type; + public $default; + public $is_static; + public $is_const; + public $ptr = 0; + + public function __construct() + { + } + + public function setType($type) + { + $this->type = $type; + } + + public function setName($name) + { + $ptr = 0; + for ($i =0; $i < strlen($name); $i++) { + if ($name[$i] == '*') { + $ptr++; + } + } + + $this->name = substr($name, $ptr); + if ($ptr) { + $this->ptr = $ptr; + } + } + + public function setPtr($ptr) + { + $this->ptr = $ptr; + } + + public function setDefault($default) + { + $this->default = $default; + } + + public function getNameWithPtr() + { + if ($this->name) { + return str_repeat("*", $this->ptr) . $this->name; + } else { + return ""; + } + } +} From e82c1158503e801374df6c9263ca1a7f4c445b6f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 23 Jan 2014 09:26:26 +0900 Subject: [PATCH 124/136] [refspec] add note --- refspec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/refspec.c b/refspec.c index 72506b1f0d..9e8de411ac 100644 --- a/refspec.c +++ b/refspec.c @@ -141,12 +141,13 @@ PHP_FUNCTION(git_refspec_dst_matches) */ PHP_FUNCTION(git_refspec_transform) { + // TODO(chobie): fix this implementation php_git2_t *_spec = NULL; char out = NULL, *name = NULL; long outlen = 0; zval *spec = NULL; int name_len = 0, error = 0; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lrs", &outlen, &spec, &name, &name_len) == FAILURE) { return; @@ -165,6 +166,7 @@ PHP_FUNCTION(git_refspec_transform) */ PHP_FUNCTION(git_refspec_rtransform) { + // TODO(chobie): fix this implementation php_git2_t *_spec = NULL; char out = NULL, *name = NULL; long outlen = 0; From 8953e587d778a8211e9ea5c332cfe25ad4cf5561 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 16 Feb 2014 02:05:29 -0800 Subject: [PATCH 125/136] fixes #59. correct variable declarations --- attr.c | 2 +- filter.c | 4 ++-- object.c | 2 +- odb.c | 4 ++-- reference.c | 2 +- refspec.c | 2 +- remote.c | 4 ++-- submodule.c | 8 ++++---- tag.c | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/attr.c b/attr.c index 4ed054a571..fd894261f8 100644 --- a/attr.c +++ b/attr.c @@ -6,7 +6,7 @@ */ PHP_FUNCTION(git_attr_value) { - git_attr_t *result = NULL; + git_attr_t result; char *attr = NULL; int attr_len = 0; diff --git a/filter.c b/filter.c index 9f140d58b1..2704d3d194 100644 --- a/filter.c +++ b/filter.c @@ -496,7 +496,7 @@ PHP_FUNCTION(git_filter_source_id) */ PHP_FUNCTION(git_filter_source_mode) { - git_filter_mode_t *result = NULL; + git_filter_mode_t result; zval *src = NULL; php_git2_t *_src = NULL; @@ -603,4 +603,4 @@ PHP_FUNCTION(git_filter_new) RETURN_FALSE; } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); -} \ No newline at end of file +} diff --git a/object.c b/object.c index d95b64c1a6..247d021031 100644 --- a/object.c +++ b/object.c @@ -112,7 +112,7 @@ PHP_FUNCTION(git_object_id) */ PHP_FUNCTION(git_object_type) { - git_otype *result = NULL; + git_otype result; zval *obj = NULL; php_git2_t *_obj = NULL; diff --git a/odb.c b/odb.c index 35fa1d2651..75be76cf12 100644 --- a/odb.c +++ b/odb.c @@ -628,7 +628,7 @@ PHP_FUNCTION(git_odb_object_size) */ PHP_FUNCTION(git_odb_object_type) { - git_otype *result = NULL; + git_otype result; zval *object = NULL; php_git2_t *_object = NULL; @@ -1106,4 +1106,4 @@ PHP_FUNCTION(git_odb_backend_new) } ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result)); -} \ No newline at end of file +} diff --git a/reference.c b/reference.c index adae07a77e..2befa063b9 100644 --- a/reference.c +++ b/reference.c @@ -259,7 +259,7 @@ PHP_FUNCTION(git_reference_symbolic_target) */ PHP_FUNCTION(git_reference_type) { - git_ref_t *result = NULL; + git_ref_t result; zval *ref = NULL; php_git2_t *_ref = NULL; diff --git a/refspec.c b/refspec.c index 9e8de411ac..956d2474f2 100644 --- a/refspec.c +++ b/refspec.c @@ -82,7 +82,7 @@ PHP_FUNCTION(git_refspec_force) */ PHP_FUNCTION(git_refspec_direction) { - git_direction *result = NULL; + git_direction result; zval *spec = NULL; php_git2_t *_spec = NULL; diff --git a/remote.c b/remote.c index 48ebf89aed..6820d3e6e5 100644 --- a/remote.c +++ b/remote.c @@ -880,7 +880,7 @@ PHP_FUNCTION(git_remote_stats) */ PHP_FUNCTION(git_remote_autotag) { - git_remote_autotag_option_t *result = NULL; + git_remote_autotag_option_t result; zval *remote = NULL; php_git2_t *_remote = NULL; @@ -908,7 +908,7 @@ PHP_FUNCTION(git_remote_set_autotag) } ZEND_FETCH_RESOURCE(_remote, php_git2_t*, &remote, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - git_remote_set_autotag(PHP_GIT2_V(_remote, remote), value); + git_remote_set_autotag(PHP_GIT2_V(_remote, remote), Z_LVAL_P(value)); } /* }}} */ diff --git a/submodule.c b/submodule.c index 6879dd07bb..1619a9fec9 100644 --- a/submodule.c +++ b/submodule.c @@ -328,7 +328,7 @@ PHP_FUNCTION(git_submodule_wd_id) */ PHP_FUNCTION(git_submodule_ignore) { - git_submodule_ignore_t *result = NULL; + git_submodule_ignore_t result; zval *submodule = NULL; php_git2_t *_submodule = NULL; @@ -347,7 +347,7 @@ PHP_FUNCTION(git_submodule_ignore) */ PHP_FUNCTION(git_submodule_set_ignore) { - git_submodule_ignore_t *result = NULL; + git_submodule_ignore_t result; zval *submodule = NULL; php_git2_t *_submodule = NULL; long ignore = 0; @@ -367,7 +367,7 @@ PHP_FUNCTION(git_submodule_set_ignore) */ PHP_FUNCTION(git_submodule_update) { - git_submodule_update_t *result = NULL; + git_submodule_update_t result; zval *submodule = NULL; php_git2_t *_submodule = NULL; @@ -386,7 +386,7 @@ PHP_FUNCTION(git_submodule_update) */ PHP_FUNCTION(git_submodule_set_update) { - git_submodule_update_t *result = NULL; + git_submodule_update_t result; zval *submodule = NULL; php_git2_t *_submodule = NULL; long update = 0; diff --git a/tag.c b/tag.c index 7e788498af..a7c54e8c4b 100644 --- a/tag.c +++ b/tag.c @@ -215,7 +215,7 @@ PHP_FUNCTION(git_tag_target_id) */ PHP_FUNCTION(git_tag_target_type) { - git_otype *result = NULL; + git_otype result; zval *tag = NULL; php_git2_t *_tag = NULL; From 04e41d08567df0234f5b5139d2db3dee5b404ae2 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 19 Feb 2014 01:44:00 +0900 Subject: [PATCH 126/136] add requirements --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e1f19a6717..2e9395d73f 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ php-git2 is a PHP bindings to the libgit2 linkable C Git library. * API Documentation: http://libgit2.github.com/libgit2/#v0.20.0 (also see Signature conversions section) * IRC: #php-git on irc.freenode.net. +## Requirements + +PHP 5.3 above + ## Status 0.3.0 Alpha (switching to functions) From 96e71175c3d5b040c9946cc6618a2ac47e6fd078 Mon Sep 17 00:00:00 2001 From: "Gary A. Mort" Date: Fri, 21 Feb 2014 15:45:24 -0500 Subject: [PATCH 127/136] Fix for unknown symbol convert_to_bool when running under Ubuntu Raring, PHP 5.4.9 --- g_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g_config.c b/g_config.c index 29fdcf8a8a..cb15c30ad5 100644 --- a/g_config.c +++ b/g_config.c @@ -119,7 +119,7 @@ static void php_git2_config_set_with(INTERNAL_FUNCTION_PARAMETERS, enum php_git2 } case PHP_GIT2_CONFIG_BOOL: { if (Z_TYPE_P(value) != IS_BOOL) { - convert_to_bool(value); + convert_to_boolean(value); } error = git_config_set_bool(PHP_GIT2_V(_cfg, config), name, Z_LVAL_P(value)); if (php_git2_check_error(error, "git_config_set_bool" TSRMLS_CC)) { From 5ce464e8183bb48f3f417d2a2d87f8bde865aebe Mon Sep 17 00:00:00 2001 From: "Gary A. Mort" Date: Fri, 21 Feb 2014 15:51:01 -0500 Subject: [PATCH 128/136] Fix for php_git2_diff_delta_to_array --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 68002ec878..7acd39a64c 100644 --- a/diff.c +++ b/diff.c @@ -288,7 +288,7 @@ PHP_FUNCTION(git_diff_get_delta) ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); result = git_diff_get_delta(PHP_GIT2_V(_diff, diff), idx); - php_git2_git_diff_delta_to_array(result, &_result TSRMLS_CC); + php_git2_diff_delta_to_array(result, &_result TSRMLS_CC); RETURN_ZVAL(_result, 0, 1); } /* }}} */ From 20b6bef24896b1946b8359106c7d028cc855342f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 4 Mar 2014 12:09:53 +0900 Subject: [PATCH 129/136] add stub file --- ref.php | 19 ++ stubs/git2.php | 549 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 568 insertions(+) create mode 100644 ref.php create mode 100644 stubs/git2.php diff --git a/ref.php b/ref.php new file mode 100644 index 0000000000..0235eeea8d --- /dev/null +++ b/ref.php @@ -0,0 +1,19 @@ +getFunctions() as $func) { + /** @var ReflectionFunction $func */ + + $name = $func->getName(); + $result[$name] = array(); + foreach ($func->getParameters() as $param) { + /** @var ReflectionParameter $param */ + $result[$name][] = '$' . $param->getName(); + } +} + +echo " $params) { + printf("function %s(%s){}\n", $func, join(", ", $params)); +} diff --git a/stubs/git2.php b/stubs/git2.php new file mode 100644 index 0000000000..7b1229e428 --- /dev/null +++ b/stubs/git2.php @@ -0,0 +1,549 @@ + Date: Mon, 14 Apr 2014 17:41:06 +0200 Subject: [PATCH 130/136] Adding missing & --- status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/status.c b/status.c index 4f9c9670da..072d713895 100644 --- a/status.c +++ b/status.c @@ -152,7 +152,7 @@ PHP_FUNCTION(git_status_file) } ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); - result = git_status_file(status_flags, PHP_GIT2_V(_repo, repository), path); + result = git_status_file(&status_flags, PHP_GIT2_V(_repo, repository), path); RETURN_LONG(result); } /* }}} */ @@ -280,4 +280,4 @@ PHP_FUNCTION(git_status_options_new) php_git2_git_status_options_to_array(&options, &result TSRMLS_CC); RETURN_ZVAL(result, 0, 1); -} \ No newline at end of file +} From 2c4cce504ef10419a4ff241bdff931dad870d1f3 Mon Sep 17 00:00:00 2001 From: Philippe Gaultier Date: Mon, 14 Apr 2014 22:13:35 +0200 Subject: [PATCH 131/136] Allow clone options bare and ignore_cert --- clone.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/clone.c b/clone.c index 6bd6337883..095aa5dc38 100644 --- a/clone.c +++ b/clone.c @@ -2,25 +2,50 @@ #include "php_git2_priv.h" #include "clone.h" +static void php_git2_git_clone_options_to_array(git_clone_options *options, zval **out TSRMLS_DC) +{ + zval *result, *pathspec; + + MAKE_STD_ZVAL(result); + array_init(result); + + add_assoc_long_ex(result, ZEND_STRS("version"), options->version); + add_assoc_long_ex(result, ZEND_STRS("bare"), options->bare); + add_assoc_long_ex(result, ZEND_STRS("ignore_cert_errors"), options->ignore_cert_errors); + /* TODO: make other options available */ + *out = result; +} + +static void php_git2_array_to_git_clone_options(git_clone_options *options, zval *array TSRMLS_DC) +{ + options->version = php_git2_read_arrval_long2(array, ZEND_STRS("version"), 1 TSRMLS_CC); + options->bare = php_git2_read_arrval_long2(array, ZEND_STRS("bare"), 0 TSRMLS_CC); + options->ignore_cert_errors = php_git2_read_arrval_long2(array, ZEND_STRS("ignore_cert_errors"), 0 TSRMLS_CC); +} + /* {{{ proto resource git_clone(string $url, string $localpath[, array $options]) */ PHP_FUNCTION(git_clone) { char *url, *localpath; int url_len, localpath_len; - zval *options;// = GIT_OPTIONS_INIT; + zval *opts = NULL;// = GIT_OPTIONS_INIT; php_git2_t *git2; git_repository *repository; int error; + git_clone_options options = GIT_CLONE_OPTIONS_INIT; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ss|a", &url, &url_len, &localpath, &localpath_len, &options) == FAILURE) { + "ss|a", &url, &url_len, &localpath, &localpath_len, &opts) == FAILURE) { return; } /* TODO(chobie): convert options to git_clone_options */ - error = git_clone(&repository, url, localpath, NULL); + php_git2_array_to_git_clone_options(&options, opts TSRMLS_CC); + + + error = git_clone(&repository, url, localpath, &options); if (php_git2_check_error(error, "git_clone" TSRMLS_CC)) { RETURN_FALSE } From 9e707b4797c13399de760e191975598e3209ade0 Mon Sep 17 00:00:00 2001 From: Gary Mort Date: Mon, 12 May 2014 21:17:25 -0400 Subject: [PATCH 132/136] Modified README for 64bit compile instructions --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e9395d73f..175ec8fcc2 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,22 @@ https://docs.google.com/spreadsheet/ccc?key=0AjvShWAWqvfHdDRneEtIUF9GRUZMNVVVR1h ``` # build libgit2.a +## For 32bit systems git submodule init && git submodule update mkdir libgit2/build cd libgit2/build cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF .. cmake --build . +# For 64bit systems +git submodule init && git submodule update +mkdir libgit2/build +cd libgit2/build +cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF +-DCMAKE_C_FLAGS=-fPIC .. +cmake --build . + + # build php-git2 cd ../../ phpize @@ -115,4 +125,4 @@ document will generate later. please check source code before publish docs. ## LICENSE -MIT License \ No newline at end of file +MIT License From 6b60e8f6aa0cab3557ccef3ea96d427d79ce19f6 Mon Sep 17 00:00:00 2001 From: Gary Mort Date: Mon, 12 May 2014 21:36:57 -0400 Subject: [PATCH 133/136] Fix test for change in blob create return --- tests/blob/git_blob_create_frombuffer.phpt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/blob/git_blob_create_frombuffer.phpt diff --git a/tests/blob/git_blob_create_frombuffer.phpt b/tests/blob/git_blob_create_frombuffer.phpt new file mode 100644 index 0000000000..97cf4692bf --- /dev/null +++ b/tests/blob/git_blob_create_frombuffer.phpt @@ -0,0 +1,17 @@ +--TEST-- +Check for git_blob_create_frombuffer presence +--SKIPIF-- + +--FILE-- + Date: Wed, 14 May 2014 00:37:07 +0900 Subject: [PATCH 134/136] fix test case --- tests/blob/git_blob_create_frombuffer.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/blob/git_blob_create_frombuffer.phpt b/tests/blob/git_blob_create_frombuffer.phpt index 97cf4692bf..ff0d61ef52 100644 --- a/tests/blob/git_blob_create_frombuffer.phpt +++ b/tests/blob/git_blob_create_frombuffer.phpt @@ -5,7 +5,7 @@ Check for git_blob_create_frombuffer presence --FILE-- Date: Tue, 13 May 2014 15:06:36 -0400 Subject: [PATCH 135/136] Added testing for tree --- tests/init.php | 52 +++++++++++++++++++++++++++++++++ tests/tree/git_tree_lookup.phpt | 37 +++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 tests/init.php create mode 100644 tests/tree/git_tree_lookup.phpt diff --git a/tests/init.php b/tests/init.php new file mode 100644 index 0000000000..23a9035a7d --- /dev/null +++ b/tests/init.php @@ -0,0 +1,52 @@ + +--FILE-- + Date: Fri, 16 May 2014 01:51:49 +0900 Subject: [PATCH 136/136] add travis.yml --- .travis.yml | 26 ++++++++++++++++++++++++++ script/cibuild.sh | 13 +++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .travis.yml create mode 100755 script/cibuild.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..bfe6af5ccf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + +install: + - sudo apt-get -qq update + - sudo apt-get -qq install cmake libssh2-1-dev openssh-client openssh-server + +script: + - script/cibuild.sh + +notifications: + irc: + channels: + - irc.freenode.net#php-git + on_success: change + on_failure: always + use_notice: true + skip_join: true + slack: + on_success: always + on_failure: always + secure: KH9+7GLccFrGWe+E6RhSqHxh+w5DIdsVxn41Iqb2C8rfm5rrnK0KVDTWJXk2BDHc2B1ab28o6m/Vcd8C/lgURd7yx4QfUASQRrHEn4FfpsB7UgES+/aENb59ma3DVz5PqVDUSVSvABU9OCqEkLmN/9w2mL/q3rW4slUq4LzMweI= diff --git a/script/cibuild.sh b/script/cibuild.sh new file mode 100755 index 0000000000..720213790d --- /dev/null +++ b/script/cibuild.sh @@ -0,0 +1,13 @@ +export NO_INTERACTION=1 +export TESTS="--show-diff -q" + +mkdir $TRAVIS_BUILD_DIR/libgit2/build +cd $TRAVIS_BUILD_DIR/libgit2/build +cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF -DCMAKE_C_FLAGS=-fPIC .. +cmake --build . +cd $TRAVIS_BUILD_DIR + +phpize +./configure +make +make test