From 68672d085e799fb6a4a65c5710ecdca9f6ea8b48 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 20:16:04 +0900 Subject: [PATCH 001/300] temporary commit for libgit2:72a3fe42fb7208712bbe8f0981f4c6274c05e9c3 --- src/config.m4 | 2 +- src/php_git.c | 3 +- src/php_git.h | 9 +- src/rawobject.c | 128 --------------------------- src/repository.c | 8 +- src/tree.c | 2 +- src/tree_entry.c | 2 +- tests/GitBackendTest.php | 78 ----------------- tests/GitCommitTest.php | 80 ----------------- tests/GitODBTest.php | 62 -------------- tests/GitTagTest.php | 56 ------------ tests/GitTest.php | 181 --------------------------------------- 12 files changed, 9 insertions(+), 602 deletions(-) delete mode 100644 src/rawobject.c delete mode 100644 tests/GitBackendTest.php delete mode 100644 tests/GitCommitTest.php delete mode 100644 tests/GitODBTest.php delete mode 100644 tests/GitTagTest.php delete mode 100644 tests/GitTest.php diff --git a/src/config.m4 b/src/config.m4 index c9c7304a80..69141c5386 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -29,7 +29,7 @@ if test $PHP_GIT != "no"; then PHP_ADD_LIBRARY_WITH_PATH(git2, $LIBGIT2_LIBDIR, GIT_SHARED_LIBADD) PHP_SUBST(GIT_SHARED_LIBADD) - PHP_NEW_EXTENSION(git,php_git.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c rawobject.c tag.c odb.c backend.c, $ext_shared) + PHP_NEW_EXTENSION(git,php_git.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], [ diff --git a/src/php_git.c b/src/php_git.c index ff9b4243c1..cd24110543 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -142,11 +142,10 @@ PHP_MINIT_FUNCTION(git) { git_init_tree(TSRMLS_C); git_init_commit(TSRMLS_C); git_init_tree_entry(TSRMLS_C); - git_init_rawobject(TSRMLS_C); git_init_tag(TSRMLS_C); git_init_blob(TSRMLS_C); git_init_odb(TSRMLS_C); - git_init_backend(TSRMLS_C); + //git_init_backend(TSRMLS_C); git_init_reference_manager(TSRMLS_C); REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_NONE", 0, CONST_CS | CONST_PERSISTENT); diff --git a/src/php_git.h b/src/php_git.h index b8d9834a50..cbc1a5605a 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -59,11 +59,10 @@ extern PHPAPI zend_class_entry *git_tree_iterator_class_entry; extern PHPAPI zend_class_entry *git_tree_entry_class_entry; extern PHPAPI zend_class_entry *git_commit_class_entry; extern PHPAPI zend_class_entry *git_signature_class_entry; -extern PHPAPI zend_class_entry *git_rawobject_class_entry; extern PHPAPI zend_class_entry *git_tag_class_entry; extern PHPAPI zend_class_entry *git_blob_class_entry; extern PHPAPI zend_class_entry *git_odb_class_entry; -extern PHPAPI zend_class_entry *git_backend_class_entry; +PHPAPI zend_class_entry *git_backend_class_entry; typedef struct{ zend_object zo; @@ -117,12 +116,6 @@ typedef struct{ git_odb *odb; } php_git_odb_t; - -typedef struct{ - zend_object zo; - git_rawobj *object; -} php_git_rawobject_t; - typedef struct{ zend_object zo; git_index_entry *object; diff --git a/src/rawobject.c b/src/rawobject.c deleted file mode 100644 index caf30e670e..0000000000 --- a/src/rawobject.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_rawobject_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_rawobject_set_content, 0, 0, 1) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_rawobject__construct, 0, 0, 2) - ZEND_ARG_INFO(0, type) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, len) -ZEND_END_ARG_INFO() - -static void php_git_rawobject_free_storage(php_git_rawobject_t *obj TSRMLS_DC) -{ -/* - if(obj->object->data){ - efree(obj->object->data); - obj->object->data = NULL; - } - - if(obj->object){ - efree(obj->object); - obj->object= NULL; - } -*/ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - efree(obj); -} - -zend_object_value php_git_rawobject_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_rawobject_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_rawobject_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -PHP_METHOD(git_raw_object, __construct) -{ - char *data; - int data_len = 0; - int type = 0; - int len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "lsl", &type, &data, &data_len, &len) == FAILURE){ - return; - } - php_git_rawobject_t *this= (php_git_rawobject_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - this->object = emalloc(sizeof(git_rawobj)); - this->object->data = NULL; - this->object->type = type; - this->object->len = len; - this->object->data = emalloc(len); - memcpy(this->object->data,data,len); - - add_property_stringl_ex(getThis(), "data",sizeof("data"),data,len,1 TSRMLS_CC); - add_property_long(getThis(), "type",type); - add_property_long(getThis(), "len",len); -} - -PHP_METHOD(git_raw_object, getId) -{ - php_git_rawobject_t *this = (php_git_rawobject_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_oid oid; - char out[GIT_OID_HEXSZ+1] = {0}; - - git_rawobj_hash(&oid,this->object); - git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); - - RETVAL_STRING(out,1); -} - - -PHPAPI function_entry php_git_rawobject_methods[] = { - PHP_ME(git_raw_object, __construct, arginfo_git_rawobject__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_raw_object, getId, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_rawobject(TSRMLS_D) -{ - zend_class_entry git_rawobject_ce; - INIT_NS_CLASS_ENTRY(git_rawobject_ce, PHP_GIT_NS,"RawObject", php_git_rawobject_methods); - - git_rawobject_class_entry = zend_register_internal_class(&git_rawobject_ce TSRMLS_CC); - git_rawobject_class_entry->create_object = php_git_rawobject_new; -} \ No newline at end of file diff --git a/src/repository.c b/src/repository.c index b20d234bf9..b45779ffd4 100644 --- a/src/repository.c +++ b/src/repository.c @@ -401,7 +401,7 @@ PHP_METHOD(git_repository, getWalker) RETURN_ZVAL(walker_object,0,0); } - +/* PHP_METHOD(git_repository, addAlternate) { php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); @@ -445,7 +445,7 @@ PHP_METHOD(git_repository, addBackend) odb = git_repository_database(this->repository); int ret = php_git_odb_add_backend(&odb, backend, priority); } - +*/ PHP_METHOD(git_repository, lookupRef) { @@ -639,8 +639,8 @@ PHPAPI function_entry php_git_repository_methods[] = { PHP_ME(git_repository, getWalker, arginfo_git_walker, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getTree, arginfo_git_get_tree, ZEND_ACC_PUBLIC) PHP_ME(git_repository, init, arginfo_git_init, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(git_repository, addBackend, arginfo_git_add_backend, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, addAlternate, arginfo_git_add_alternate, ZEND_ACC_PUBLIC) + //PHP_ME(git_repository, addBackend, arginfo_git_add_backend, ZEND_ACC_PUBLIC) + //PHP_ME(git_repository, addAlternate, arginfo_git_add_alternate, ZEND_ACC_PUBLIC) PHP_ME(git_repository, open3, arginfo_git_open3, ZEND_ACC_PUBLIC) PHP_ME(git_repository, open2, arginfo_git_open2, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getReferences, arginfo_git_get_references, ZEND_ACC_PUBLIC) diff --git a/src/tree.c b/src/tree.c index 4b51f04d27..6b277cbbcd 100644 --- a/src/tree.c +++ b/src/tree.c @@ -105,7 +105,7 @@ PHP_METHOD(git_tree, path) if(entry == NULL){ return; }else{ - ret = git_tree_entry_2object(&object, entry); + ret = git_tree_entry_2object(&object,git_object_owner(this->object), entry); if (ret != GIT_SUCCESS) { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"something uncaught error happend."); diff --git a/src/tree_entry.c b/src/tree_entry.c index c50fb5336e..96af343a9b 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -91,7 +91,7 @@ PHP_METHOD(git_tree_entry, toObject) git_object *object; git_otype type; - int ret = git_tree_entry_2object(&object, this->entry); + int ret = git_tree_entry_2object(&object, git_object_owner(this->entry), this->entry); if(ret == GIT_SUCCESS){ type = git_object_type(object); diff --git a/tests/GitBackendTest.php b/tests/GitBackendTest.php deleted file mode 100644 index 0013e03f03..0000000000 --- a/tests/GitBackendTest.php +++ /dev/null @@ -1,78 +0,0 @@ -getMethod("read"); - $this->assertEquals(true,$method->isPublic()); - - $parameters = $method->getParameters(); - - $this->assertEquals(1,count($parameters)); - $this->assertEquals("key",$parameters[0]->getname()); - } - - public function testWriteMethodExists() - { - $reflection = new \ReflectionClass("Git\\Backend"); - $method = $reflection->getMethod("write"); - $this->assertEquals(true,$method->isPublic()); - - $parameters = $method->getParameters(); - - $this->assertEquals(1,count($parameters)); - $this->assertEquals("object",$parameters[0]->getname()); - } - - public function testExistsMethodExists() - { - $reflection = new \ReflectionClass("Git\\Backend"); - $method = $reflection->getMethod("exists"); - $this->assertEquals(true,$method->isPublic()); - - $parameters = $method->getParameters(); - - $this->assertEquals(1,count($parameters)); - $this->assertEquals("key",$parameters[0]->getname()); - } - - public function testReadHeaderMethodExists() - { - $reflection = new \ReflectionClass("Git\\Backend"); - $method = $reflection->getMethod("read_header"); - $this->assertEquals(true,$method->isPublic()); - - $parameters = $method->getParameters(); - - $this->assertEquals(1,count($parameters)); - $this->assertEquals("key",$parameters[0]->getname()); - } - - public function testConstructMethodExists() - { - $reflection = new \ReflectionClass("Git\\Backend"); - $method = $reflection->getMethod("__construct"); - $this->assertEquals(true,$method->isPublic()); - - $parameters = $method->getParameters(); - - $this->assertEquals(0,count($parameters)); - } -} diff --git a/tests/GitCommitTest.php b/tests/GitCommitTest.php deleted file mode 100644 index f71fd79315..0000000000 --- a/tests/GitCommitTest.php +++ /dev/null @@ -1,80 +0,0 @@ -setAuthor(new Git\Signature("Someone Else","someone@example.com",new DateTime("@1293956764"))); - $author = $commit->getAuthor(); - $this->assertEquals("Someone Else",$author->name); - $this->assertEquals("someone@example.com",$author->email); - $this->assertEquals(1293956764,$author->time->getTimestamp()); - } - - public function testGitCommitCommitterSignature() - { - $commit = new Git\Commit(new Git\Repository(PHP_GIT_FIXTURE_DIR . "/fixture.git")); - $commit->setCommitter(new Git\Signature("Someone Else","someone@example.com",new DateTime("@1293956764"))); - $committer = $commit->getCommitter(); - $this->assertEquals("Someone Else",$committer->name); - $this->assertEquals("someone@example.com",$committer->email); - $this->assertEquals(1293956764,$committer->time->getTimestamp()); - } - - public function testGitGetCommitFlomRepository() - { - $repository = new Git\Repository(".git"); - $commit = $repository->getCommit("1f27eed71970a0dbc0ca758f449e4b68c4c91bd8"); - - $author = $commit->getAuthor(); - - $this->assertEquals("Shuhei Tanuma",$author->name); - $this->assertEquals("shuhei.tanuma@gmail.com",$author->email); - - - $committer = $commit->getCommitter(); - $this->assertEquals("Shuhei Tanuma",$committer->name); - $this->assertEquals("shuhei.tanuma@gmail.com",$committer->email); - $this->assertEquals("1f27eed71970a0dbc0ca758f449e4b68c4c91bd8", $commit->getId()); - - $tree = $commit->getTree(); - $entry1 = $tree->getEntry(0); - $this->assertEquals("EXPERIMENTAL",$entry1->name); - $this->assertEquals("35a136e7e190505e46367a04f730e827062b13cc",$entry1->oid); - - $entry2 = $tree->getEntry(1); - $this->assertEquals("README.md",$entry2->name); - $this->assertEquals("a1a07d27e9d8a78e3bc6fb8a6d8308d358ff9b07",$entry2->oid); - - $commit = $repository->getCommit("bba0bb972cbdc72d908ebd7c89157d7e207f5e92"); - $parent = $commit->getParent(); - $this->assertEquals("b500d73e7125ae105ce125b96390ad09d6174629",$parent->getId()); - - $author = $parent->getAuthor(); - $this->assertEquals("Shuhei Tanuma",$author->name); - $this->assertEquals("shuhei.tanuma@gmail.com",$author->email); - - $committer = $parent->getCommitter(); - $this->assertEquals("Shuhei Tanuma",$committer->name); - $this->assertEquals("shuhei.tanuma@gmail.com",$committer->email); - } -} \ No newline at end of file diff --git a/tests/GitODBTest.php b/tests/GitODBTest.php deleted file mode 100644 index 2bfe4b71c3..0000000000 --- a/tests/GitODBTest.php +++ /dev/null @@ -1,62 +0,0 @@ -markTestSkipped('Requires extension memcached'); - } - - $odb = new Git\ODB(); - $this->assertInstanceof('Git\\ODB', $odb); - } - - public function testAddBackend() - { - if (!extension_loaded('memcached')) { - $this->markTestSkipped('Requires extension memcached'); - } - - $odb = new Git\ODB(); - $memcached = new Git\Backend\Memcached(); - $odb->addBackend($memcached, 5); - $this->assertInstanceof('Git\\ODB', $odb); - } - - public function testMemoryBackend() - { - $odb = new Git\ODB(); - $memory = new Git\Backend\Memory(); - $odb->addBackend($memory, 5); - $this->assertInstanceof('Git\\ODB', $odb); - } - - public function testAddAlternate() - { - $odb = new Git\ODB(); - $memory = new Git\Backend\Memory(); - $odb->addAlternate($memory, 5); - $this->assertInstanceof('Git\\ODB', $odb); - } -} \ No newline at end of file diff --git a/tests/GitTagTest.php b/tests/GitTagTest.php deleted file mode 100644 index ab7b66fc64..0000000000 --- a/tests/GitTagTest.php +++ /dev/null @@ -1,56 +0,0 @@ -setMessage("Hello World"); - $this->assertEquals("Hello World", $tag->getMessage()); - } - - public function testGitTagSetNameGetName() - { - $repo = new Git\Repository("./.git"); - $tag = new Git\Tag($repo); - $tag->setName("version 1.0"); - $this->assertEquals("version 1.0", $tag->getName()); - } - -} \ No newline at end of file diff --git a/tests/GitTest.php b/tests/GitTest.php deleted file mode 100644 index 5e846b86a1..0000000000 --- a/tests/GitTest.php +++ /dev/null @@ -1,181 +0,0 @@ -lookupRef(self::$reference_name); - $commit = $git->getCommit($ref->getId()); - - $this->assertInstanceof("Git\\Reference",$ref,"can't lookup reference"); - $this->assertInstanceof("Git\\Commit",$commit,"reference can't return commit object"); - } - - - public function testGetBlob() - { - $git = new Git\Repository(dirname(__DIR__) . "/.git/"); - $blob = $git->getObject("5b4a19f66f8271d7457839f0e8554b3fe5aa6fd0"); - $this->assertEquals("5b4a19f66f8271d7457839f0e8554b3fe5aa6fd0",$blob->getId()); - } - - public function testGetTree() - { - $git = new Git\Repository(dirname(__DIR__) . "/.git/"); - $tree= $git->getTree("c40b970eb68bd1c8980f1f97b57396f4c7ae107f"); - $this->assertInstanceof("Git\\Tree",$tree); - $this->assertEquals("c40b970eb68bd1c8980f1f97b57396f4c7ae107f",$tree->getId()); - foreach($tree->getIterator() as $entry){ - $object = $entry->toObject(); - $this->assertInstanceof("Git\\Object",$object); - if($object->getType() == GIT\Object\Blob){ - $this->assertInstanceof("Git\\Blob",$object); - }else if($object->getType() == GIT\Object\Tree) { - $this->assertInstanceof("Git\\Tree",$object); - }else { - $this->fail("unhandled object found."); - } - } - } - - public function testRepositoryInit() - { - $this->rmdir(__DIR__ . "/init_sample"); - $repo = Git\Repository::init(__DIR__ . "/init_sample",1); - $this->assertTrue(file_exists(__DIR__ . "/init_sample")); - $this->assertInstanceof("Git\\Repository",$repo); - $this->rmdir(__DIR__ . "/init_sample"); - } - - public function testConstruct() - { - - try{ - $git = new Git\Repository(dirname(__DIR__) . "/.git/"); - $this->assertInstanceof("Git\\Repository",$git); - unset($git); - }catch(\Exception $e){ - $this->fail(); - } - - try{ - $git = new Git\Repository("./.git"); - $this->assertInstanceof("Git\\Repository",$git,"Git\\Repository::__construct allowed null parameter. refs #127"); - }catch(\Exception $e){ - $this->fail(); - } - } - - public function testInitRepository() - { - require_once __DIR__ . "/lib/MemoryBackend.php"; - //require_once __DIR__ . "/lib/MemcachedBackend.php"; - - - $this->rmdir(__DIR__ . "/git_init_test"); - mkdir(__DIR__ . "/git_init_test",0755); - - - $backend = new Git\Backend\Memory(); - $repository = Git\Repository::init(__DIR__ . "/git_init_test",true); - $repository->addBackend($backend,5); - - $blob = new Git\Blob($repository); - $blob->setContent("First Object1"); - $hash = $blob->write(); - - $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $hash,"First Object1 write correctly"); - $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $blob->getid(),"rawobject and blob hash are same."); - $data = $backend->read($hash); - if($backend->read($hash)){ - $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $backend->read($hash)->getId(),"Backend return same rawobject"); - } - - $tree = new Git\Tree($repository); - $tree->add($hash,"README",100644); - $tree_hash = $tree->write(); - $this->assertEquals("3c7493d000f58ae3eed94b0a3bc77d60694d33b4",$tree_hash, "tree writing"); - - $data = $backend->read("3c7493d000f58ae3eed94b0a3bc77d60694d33b4"); - if($data){ - $this->assertEquals("3c7493d000f58ae3eed94b0a3bc77d60694d33b4",$data->getId(), "Backend return same tree raw"); - } - - $commit = new Git\Commit($repository); - $commit->setAuthor(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - $commit->setCommitter(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - $commit->setTree($tree->getId()); - // when first commit. you dont call setParent. - //$commit->setParent(""); - $commit->setMessage("initial import"); - - $master_hash = $commit->write(); - - //$this->markTestIncomplete("this test does not implemente yet."); - $this->assertEquals("c12883a96cf60d1b2edba971183ffaca6d1b077e",$master_hash,"commit writing"); - -/* - $re = new Git\Reference($repository); - $re->setName("refs/heads/master"); - //$re->setTarget("refs/heads/master"); - // you can't use setOid if setTarget called. - $re->setOID("c12883a96cf60d1b2edba971183ffaca6d1b077e"); - $re->write(); -*/ - - $this->rmdir(__DIR__ . "/git_init_test"); - } - - protected function rmdir($dir) - { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir."/".$object) == "dir") $this->rmdir($dir."/".$object); else unlink($dir."/".$object); - } - } - reset($objects); - rmdir($dir); - } - } -} \ No newline at end of file From 8e1150ba5a891bfb41428934356c7f2673142038 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 20:32:59 +0900 Subject: [PATCH 002/300] removed unsupport methods. [removed] Git\Tree::add Git\Tree::__construct Git\Tree::remove Git\Tree\Entry::setId --- src/tree.c | 65 ------------------------------------------------ src/tree_entry.c | 25 ------------------- 2 files changed, 90 deletions(-) diff --git a/src/tree.c b/src/tree.c index 6b277cbbcd..81f52b1d02 100644 --- a/src/tree.c +++ b/src/tree.c @@ -154,35 +154,6 @@ PHP_METHOD(git_tree, path) } } -PHP_METHOD(git_tree, add) -{ - zval *object = getThis(); - git_tree_entry *entry; - char *filename; - char *entry_oid; - int entry_oid_len; - int filename_len = 0; - int attr = 0; - - git_oid oid; - git_tree *tree; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ssl", &entry_oid, &entry_oid_len,&filename,&filename_len,&attr) == FAILURE){ - return; - } - - git_oid_mkstr(&oid, entry_oid); - php_git_tree_t *myobj = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int ret = git_tree_add_entry(&entry, myobj->object, &oid, filename, attr); - if(ret != GIT_SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "can't add tree entry"); - RETURN_FALSE; - } - - RETURN_TRUE; -} - PHP_METHOD(git_tree, __construct) { zval *z_repository; @@ -194,13 +165,6 @@ PHP_METHOD(git_tree, __construct) php_git_repository_t *git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC); php_git_tree_t *obj = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - - int ret = git_tree_new(&obj->object,git->repository); - - if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_ERROR, "can't create new tree"); - RETURN_FALSE; - } } PHP_METHOD(git_tree, getIterator) @@ -233,33 +197,6 @@ PHP_METHOD(git_tree, getEntry) RETURN_ZVAL(git_tree_entry,0, 0); } -PHP_METHOD(git_tree, remove) -{ - php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *path; - int path_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE){ - return; - } - - git_tree_entry *entry = git_tree_entry_byname(this->object,path); - if(entry == NULL){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified path does not exist."); - RETURN_FALSE; - } - - int result = git_tree_remove_entry_byname(this->object, path); - if(result != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't remove tree entry"); - RETURN_FALSE - } - RETURN_TRUE; -} - PHP_METHOD(git_tree, getEntries) { php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); @@ -287,8 +224,6 @@ PHPAPI function_entry php_git_tree_methods[] = { PHP_ME(git_tree, getIterator, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree, count, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree, path, arginfo_git_tree_path, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, add, arginfo_git_tree_add, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, remove, arginfo_git_tree_remove, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; diff --git a/src/tree_entry.c b/src/tree_entry.c index 96af343a9b..d173e50083 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -60,30 +60,6 @@ zend_object_value php_git_tree_entry_new(zend_class_entry *ce TSRMLS_DC) return retval; } -PHP_METHOD(git_tree_entry, setId) -{ - php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *hash; - int hash_len = 0; - git_oid oid; - - int ret = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - git_oid_mkstr(&oid,hash); - git_tree_entry_set_id(this->entry,&oid); - - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid_to_string(out,GIT_OID_HEXSZ+1,git_tree_entry_id(this->entry)); - - add_property_string(getThis(), "oid", hash, 1); - - RETVAL_STRING(hash, 1); -} - PHP_METHOD(git_tree_entry, toObject) { @@ -169,7 +145,6 @@ PHP_METHOD(git_tree_entry, isBlob) PHPAPI function_entry php_git_tree_entry_methods[] = { PHP_ME(git_tree_entry, __construct, NULL, ZEND_ACC_PRIVATE) - PHP_ME(git_tree_entry, setId, arginfo_git_tree_entry_set_id, ZEND_ACC_PUBLIC) PHP_ME(git_tree_entry, toObject, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree_entry, isTree, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree_entry, isBlob, NULL, ZEND_ACC_PUBLIC) From 5ba2d4e736c3b4b6c3a234838649b4245d51e75b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 20:37:17 +0900 Subject: [PATCH 003/300] removed unsupport method. Git\Tag::getTarget Git\Tag::setMessage Git\Tag::setName --- src/tag.c | 57 ------------------------------------------------------- 1 file changed, 57 deletions(-) diff --git a/src/tag.c b/src/tag.c index 6a3f5fa77b..4ff4012ef6 100644 --- a/src/tag.c +++ b/src/tag.c @@ -101,59 +101,6 @@ PHP_METHOD(git_tag, getTarget) */ } -PHP_METHOD(git_tag, setTarget) -{ - php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *target; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &target) == FAILURE){ - return; - } - - if(!instanceof_function(Z_OBJCE_P(target), git_object_class_entry TSRMLS_CC)){ - // FIXME - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Git\\Tag::setTarget only allow Git\\Object."); - return; - } - php_git_object_t *obj = (php_git_object_t *) zend_object_store_get_object(target TSRMLS_CC); - - git_tag_set_target(this->object, obj->object); -} - - -PHP_METHOD(git_tag, setMessage) -{ - php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *message; - int message_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &message, &message_len) == FAILURE){ - return; - } - - git_tag_set_message(this->object, message); - add_property_string_ex(getThis() ,"message",sizeof("message"),message,1 TSRMLS_CC); -} - -PHP_METHOD(git_tag, setName) -{ - php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *name; - int name_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &name, &name_len) == FAILURE){ - return; - } - - git_tag_set_name(this->object, name); - add_property_string_ex(getThis() ,"name",sizeof("name"),name, 1 TSRMLS_CC); -} - - - PHP_METHOD(git_tag, __construct) { php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC); @@ -186,10 +133,6 @@ PHPAPI function_entry php_git_tag_methods[] = { PHP_ME(git_tag, getMessage, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tag, getName, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tag, getTarget, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(git_tag, setMessage, arginfo_git_tag_set_message, ZEND_ACC_PUBLIC) - PHP_ME(git_tag, setName, arginfo_git_tag_set_name, ZEND_ACC_PUBLIC) - PHP_ME(git_tag, setTarget, arginfo_git_tag_set_target, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; From db562bdc6bcf13a80bc4ef9e083f047070c628cf Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 20:49:11 +0900 Subject: [PATCH 004/300] removed unsupport methods. Git\Commit::setCommitter Git\Commit::setParent Git\Commit::setAuthor Git\Commit::setTree Git\Commit::setMessage --- src/commit.c | 208 +++------------------------------------------------ 1 file changed, 9 insertions(+), 199 deletions(-) diff --git a/src/commit.c b/src/commit.c index 74cec9b488..50936660c4 100644 --- a/src/commit.c +++ b/src/commit.c @@ -37,26 +37,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit__construct, 0, 0, 1) ZEND_ARG_INFO(0, repository) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_committer, 0, 0, 1) - ZEND_ARG_INFO(0, committer) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_parent, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_author, 0, 0, 1) - ZEND_ARG_INFO(0, author) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_tree, 0, 0, 1) - ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_message, 0, 0, 1) - ZEND_ARG_INFO(0, message) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_get_parent, 0, 0, 1) ZEND_ARG_INFO(0, offset) ZEND_END_ARG_INFO() @@ -64,8 +44,6 @@ ZEND_END_ARG_INFO() static void php_git_commit_free_storage(php_git_commit_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); - - //RepositoryでFreeされるよ obj->object = NULL; obj->repository = NULL; efree(obj); @@ -73,20 +51,20 @@ static void php_git_commit_free_storage(php_git_commit_t *obj TSRMLS_DC) zend_object_value php_git_commit_new(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; - php_git_commit_t *obj; - zval *tmp; + zend_object_value retval; + php_git_commit_t *obj; + zval *tmp; - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + obj = ecalloc(1, sizeof(*obj)); + zend_object_std_init( &obj->zo, ce TSRMLS_CC ); + zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - retval.handle = zend_objects_store_put(obj, + retval.handle = zend_objects_store_put(obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_git_commit_free_storage, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; + retval.handlers = zend_get_std_object_handlers(); + return retval; } PHP_METHOD(git_commit, __construct) @@ -106,37 +84,7 @@ PHP_METHOD(git_commit, __construct) php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC); - ret = git_commit_new(&commit,myobj->repository); - if(ret != GIT_SUCCESS){ - //FIXME - RETURN_FALSE; - } cobj->repository = myobj->repository; - cobj->object = commit; -} - - - -PHP_METHOD(git_commit, setCommitter) -{ - zval *this = getThis(); - zval *z_signature; - git_signature *signature; - php_git_commit_t *c_obj; - php_git_signature_t *s_obj; - git_commit *commit; - zval *object = getThis(); - int ret; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &z_signature) == FAILURE){ - return; - } - - c_obj = (php_git_commit_t *) zend_object_store_get_object(this TSRMLS_CC); - s_obj = (php_git_signature_t *) zend_object_store_get_object(z_signature TSRMLS_CC); - git_commit_set_author(c_obj->object, s_obj->signature); - add_property_zval_ex(object,"committer",10,z_signature TSRMLS_CC); } PHP_METHOD(git_commit, getCommitter) @@ -148,139 +96,6 @@ PHP_METHOD(git_commit, getCommitter) RETURN_ZVAL(signature,0, 0); } -PHP_METHOD(git_commit, setParent) -{ - zval *this = getThis(); - php_git_commit_t *c_obj; - php_git_signature_t *s_obj; - git_commit *commit; - git_oid oid; - char *hash; - int hash_len = 0; - int ret; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - - git_oid_mkstr(&oid, hash); - - c_obj = (php_git_commit_t *) zend_object_store_get_object(this TSRMLS_CC); - - git_commit_lookup(&commit,c_obj->repository,&oid); - git_commit_add_parent(c_obj->object, commit); - //FIXME: not parent. parents. - add_property_string_ex(this,"parent",sizeof("parent"),hash, 1 TSRMLS_CC); -} - - -PHP_METHOD(git_commit, setAuthor) -{ - zval *this = getThis(); - zval *z_signature; - git_signature *signature; - php_git_commit_t *c_obj; - php_git_signature_t *s_obj; - git_commit *commit; - zval *object = getThis(); - int ret; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &z_signature) == FAILURE){ - return; - } - - c_obj = (php_git_commit_t *) zend_object_store_get_object(this TSRMLS_CC); - s_obj = (php_git_signature_t *) zend_object_store_get_object(z_signature TSRMLS_CC); - git_commit_set_committer(c_obj->object, s_obj->signature); - add_property_zval_ex(object,"author",sizeof("author"),z_signature TSRMLS_CC); -} - -PHP_METHOD(git_commit, setTree) -{ - zval *object = getThis(); - char *hash; - int hash_len; - char *filename; - git_oid oid; - git_tree *tree; - git_repository *repository; - git_object *git_obj; - int attr; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - - php_git_commit_t *myobj = (php_git_commit_t *) zend_object_store_get_object(object TSRMLS_CC); - repository = myobj->repository; - - git_oid_mkstr(&oid, hash); - git_object_lookup ((git_object **)&tree, repository, &oid, GIT_OBJ_TREE); - git_commit_set_tree(myobj->object,tree); - - if(tree){ - //コピペ - zval *git_tree; - zval *entries; - git_tree_entry *entry; - MAKE_STD_ZVAL(git_tree); - MAKE_STD_ZVAL(entries); - array_init(entries); - object_init_ex(git_tree, git_tree_class_entry); - - int r = git_tree_entrycount(tree); - int i = 0; - char mbuf[41] = {0}; - char *offset; - const git_oid *moid; - zval *array_ptr; - - for(i; i < r; i++){ - entry = git_tree_entry_byindex(tree,i); - moid = git_tree_entry_id(entry); - git_oid_to_string(mbuf,41,moid); - - MAKE_STD_ZVAL(array_ptr); - object_init_ex(array_ptr, git_tree_entry_class_entry); - - add_property_string(array_ptr, "name", (char *)git_tree_entry_name(entry), 1); - add_property_string(array_ptr, "oid", mbuf, 1); - add_property_long(array_ptr, "mode", git_tree_entry_attributes(entry)); - - add_next_index_zval(entries, array_ptr); - } - - //add_property_long(git_tree, "entry", git_tree_entrycount(tree)); - add_property_zval(git_tree,"entries", entries); - add_property_zval(object,"tree",git_tree); - // - - RETURN_TRUE; - } - // -} - -PHP_METHOD(git_commit, setMessage) -{ - php_git_commit_t *this; - char *message; - int message_len = 0; - int ret; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &message, &message_len) == FAILURE){ - return; - } - this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_commit_set_message(this->object,message); - - RETURN_TRUE; -} - - PHP_METHOD(git_commit, getMessage) { php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); @@ -388,16 +203,11 @@ PHP_METHOD(git_commit, getParent) PHPAPI function_entry php_git_commit_methods[] = { PHP_ME(git_commit, __construct, arginfo_git_commit__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setTree, arginfo_git_commit_set_tree, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getTree, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setAuthor, arginfo_git_commit_set_author, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getAuthor, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setCommitter, arginfo_git_commit_set_committer,ZEND_ACC_PUBLIC) PHP_ME(git_commit, getCommitter, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setMessage, arginfo_git_commit_set_message, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getMessage, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getShortMessage, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setParent, arginfo_git_commit_set_parent, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getParent, arginfo_git_commit_get_parent, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; From 4a317450b878c97572ff68cf74921702681fb6d3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 20:55:42 +0900 Subject: [PATCH 005/300] removed unsupport method. Git\Blob::setContent --- src/blob.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/blob.c b/src/blob.c index a46e066e70..8c27339303 100644 --- a/src/blob.c +++ b/src/blob.c @@ -89,29 +89,8 @@ PHP_METHOD(git_blob, __construct) } -PHP_METHOD(git_blob, setContent) -{ - char *string; - size_t string_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &string, &string_len) == FAILURE){ - return; - } - - php_git_blob_t *obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - - int ret = git_blob_set_rawcontent(obj->object,string, string_len); - if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't set content!"); - return; - } - add_property_string_ex(getThis(), "data", sizeof("data"),string, 1 TSRMLS_CC); -} - PHPAPI function_entry php_git_blob_methods[] = { PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_blob, setContent, arginfo_git_blob_set_content, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; From a892f801dd1c4f2beb88ea5cabe2536c4b4b6de5 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 20:57:32 +0900 Subject: [PATCH 006/300] removed unsupport method. Git\Object::write --- src/object.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/object.c b/src/object.c index d651e10fd8..7bacd8ced0 100644 --- a/src/object.c +++ b/src/object.c @@ -35,6 +35,7 @@ static void php_git_object_free_storage(php_git_object_t *obj TSRMLS_DC) zend_object_std_dtor(&obj->zo TSRMLS_CC); if(obj->object){ + git_object_close(obj->object); obj->object = NULL; } @@ -82,30 +83,9 @@ PHP_METHOD(git_object, getType) RETVAL_LONG(type); } -PHP_METHOD(git_object, write) -{ - php_git_object_t *this = (php_git_object_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - const git_oid *oid; - char out[GIT_OID_HEXSZ+1] = {0}; - int ret = 0; - - ret = git_object_write((git_object *)this->object); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, - "Can't write object: %d",ret); - RETURN_FALSE; - } - - oid = git_object_id((git_object *)this->object); - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - - RETVAL_STRING(out,1); -} - PHPAPI function_entry php_git_object_methods[] = { PHP_ME(git_object, getId, NULL,ZEND_ACC_PUBLIC) PHP_ME(git_object, getType, NULL,ZEND_ACC_PUBLIC) - PHP_ME(git_object, write, NULL,ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; From fe8c40d6bb974fb3967eb17bc62c952e90efbfa5 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 21:04:04 +0900 Subject: [PATCH 007/300] following libgit2 version. php-git can compile below libgit2 version. libgit2:72a3fe42fb7208712bbe8f0981f4c6274c05e9c3 but not working properly. please wait updating. --- LIBGIT2_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION index dd5438b53b..009b49fb67 100644 --- a/LIBGIT2_VERSION +++ b/LIBGIT2_VERSION @@ -1 +1 @@ -7064938bd5e7ef47bfd79a685a62c1e2649e2ce7 \ No newline at end of file +72a3fe42fb7208712bbe8f0981f4c6274c05e9c3 \ No newline at end of file From 77a513efa930700dc89f273b58d6cb59389c5907 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 2 Apr 2011 22:17:26 +0900 Subject: [PATCH 008/300] fix Git\Tree\Entry::toObject. --- src/blob.c | 4 ---- src/commit.c | 3 ++- src/php_git.h | 3 +++ src/repository.c | 7 +++++-- src/tree.c | 7 ++++--- src/tree_entry.c | 7 ++++--- src/tree_iterator.c | 4 ++-- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/blob.c b/src/blob.c index 8c27339303..426670a34b 100644 --- a/src/blob.c +++ b/src/blob.c @@ -34,10 +34,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob__construct, 0, 0, 1) ZEND_ARG_INFO(0, repository) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_set_content, 0, 0, 1) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); diff --git a/src/commit.c b/src/commit.c index 50936660c4..d7b72b24f4 100644 --- a/src/commit.c +++ b/src/commit.c @@ -28,7 +28,7 @@ #include #include -extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry); +extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repository *repository); extern zend_object_value php_git_repository_new(zend_class_entry *ce TSRMLS_DC); PHPAPI zend_class_entry *git_commit_class_entry; @@ -136,6 +136,7 @@ PHP_METHOD(git_commit, getTree) object_init_ex(git_tree, git_tree_class_entry); php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); tobj->object = tree; + tobj->repository = this->repository; /* int r = git_tree_entrycount(tree); diff --git a/src/php_git.h b/src/php_git.h index cbc1a5605a..2278989be2 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -82,6 +82,7 @@ typedef struct{ typedef struct{ zend_object zo; + git_repository *repository; git_tree_entry *entry; } php_git_tree_entry_t; @@ -89,6 +90,7 @@ typedef struct{ zend_object zo; git_tree *tree; long offset; + git_repository *repository; } php_git_tree_iterator_t; typedef struct{ @@ -136,6 +138,7 @@ typedef struct{ typedef struct{ zend_object zo; git_tree *object; + git_repository *repository; } php_git_tree_t; typedef struct{ diff --git a/src/repository.c b/src/repository.c index b45779ffd4..2e4025d6b7 100644 --- a/src/repository.c +++ b/src/repository.c @@ -236,7 +236,7 @@ PHP_METHOD(git_repository, getObject) } -void create_tree_entry_from_entry(zval **object, git_tree_entry *entry) +void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repository *repository) { TSRMLS_FETCH(); char buf[41] = {0}; @@ -246,6 +246,7 @@ void create_tree_entry_from_entry(zval **object, git_tree_entry *entry) php_git_tree_entry_t *entry_obj = (php_git_tree_entry_t *) zend_object_store_get_object(*object TSRMLS_CC); entry_obj->entry = entry; + entry_obj->repository = repository; oid = git_tree_entry_id(entry); git_oid_to_string(buf,41,oid); @@ -289,7 +290,7 @@ PHP_METHOD(git_repository, getCommit) if(ret == GIT_SUCCESS){ zval *author; zval *committer; - git_commit *commit = (git_commit *)blob; + git_commit *commit = (git_commit *)blob; create_signature_from_commit(&author, git_commit_author(commit)); create_signature_from_commit(&committer, git_commit_committer(commit)); @@ -299,6 +300,7 @@ PHP_METHOD(git_repository, getCommit) php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(git_commit_object TSRMLS_CC); cobj->object = commit; + cobj->repository = repository; add_property_zval(git_commit_object,"author", author); add_property_zval(git_commit_object,"committer", committer); @@ -379,6 +381,7 @@ PHP_METHOD(git_repository, getTree) php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); tobj->object = tree; + tobj->repository = myobj->repository; RETURN_ZVAL(git_tree,0,0); } diff --git a/src/tree.c b/src/tree.c index 81f52b1d02..516176a007 100644 --- a/src/tree.c +++ b/src/tree.c @@ -130,7 +130,7 @@ PHP_METHOD(git_tree, path) int r = git_tree_entrycount(tree); int i = 0; for(i; i < r; i++){ - create_tree_entry_from_entry(&entry,git_tree_entry_byindex(tree,i)); + create_tree_entry_from_entry(&entry,git_tree_entry_byindex(tree,i),this->repository); add_next_index_zval(entries, entry); } add_property_zval(git_tree,"entries", entries); @@ -176,6 +176,7 @@ PHP_METHOD(git_tree, getIterator) object_init_ex(iterator,git_tree_iterator_class_entry); php_git_tree_iterator_t *obj = (php_git_tree_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC); obj->tree = this->object; + obj->repository = this->repository; obj->offset = 0; RETURN_ZVAL(iterator,0,0); } @@ -193,7 +194,7 @@ PHP_METHOD(git_tree, getEntry) } entry = git_tree_entry_byindex(this->object,offset); - create_tree_entry_from_entry(&git_tree_entry, entry); + create_tree_entry_from_entry(&git_tree_entry, entry,this->repository); RETURN_ZVAL(git_tree_entry,0, 0); } @@ -209,7 +210,7 @@ PHP_METHOD(git_tree, getEntries) array_init(entries); zval *array_ptr; for(i = 0; i < r; i++){ - create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(this->object,i)); + create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(this->object,i),this->repository); add_next_index_zval(entries, array_ptr); } diff --git a/src/tree_entry.c b/src/tree_entry.c index d173e50083..e84030a947 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -66,8 +66,8 @@ PHP_METHOD(git_tree_entry, toObject) php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_object *object; git_otype type; - - int ret = git_tree_entry_2object(&object, git_object_owner(this->entry), this->entry); + + int ret = git_tree_entry_2object(&object, this->repository, this->entry); if(ret == GIT_SUCCESS){ type = git_object_type(object); @@ -98,11 +98,12 @@ PHP_METHOD(git_tree_entry, toObject) zval *array_ptr; for(i; i < r; i++){ - create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(tree,i)); + create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(tree,i),this->repository); add_next_index_zval(entries, array_ptr); } php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); tobj->object = tree; + tobj->repository = this->repository; add_property_zval(git_tree,"entries", entries); RETURN_ZVAL(git_tree,0,0); diff --git a/src/tree_iterator.c b/src/tree_iterator.c index 287a2aa978..9d785cd4d6 100644 --- a/src/tree_iterator.c +++ b/src/tree_iterator.c @@ -28,7 +28,7 @@ #include #include -extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry); +extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry,git_repository *repository); PHPAPI zend_class_entry *git_tree_iterator_class_entry; extern void php_tree_index_entry_create(zval **index, git_tree_entry *entry); @@ -74,7 +74,7 @@ PHP_METHOD(git_tree_iterator, current) "specified offset does not exist. %d"); RETURN_FALSE; } - create_tree_entry_from_entry(&git_tree_entry,entry); + create_tree_entry_from_entry(&git_tree_entry,entry,this->repository); RETURN_ZVAL(git_tree_entry,0,0); } From e827fc3013a5bf3a2e10a5125e10057022e30931 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 3 Apr 2011 20:23:42 +0900 Subject: [PATCH 009/300] added Blob methods. bool Git\Blob::loadFile(string $path); bool Git\Blob::loadString(string contents); string hash Git\Blob::write(); e.g) $repo = new Git\Repository("/path/to/repos/.git"); $blob = new Git\Blob($repo); $blob->loadString("Hello World"); $hash = $blob->write(); --- src/blob.c | 104 +++++++++++++++++++++++++++++++++++++++++--------- src/php_git.h | 8 ++++ 2 files changed, 95 insertions(+), 17 deletions(-) diff --git a/src/blob.c b/src/blob.c index 426670a34b..9e65548358 100644 --- a/src/blob.c +++ b/src/blob.c @@ -34,32 +34,48 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob__construct, 0, 0, 1) ZEND_ARG_INFO(0, repository) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_load_string, 0, 0, 1) + ZEND_ARG_INFO(0, string) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_load_file, 0, 0, 1) + ZEND_ARG_INFO(0, string) +ZEND_END_ARG_INFO() + + static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); - //obj->object will free by git_repository. - obj->object = NULL; + if (obj->object != NULL) { + git_object_close(obj->object); + obj->object = NULL; + } + if(obj->contents != NULL) { + efree(obj->contents); + obj->contents = NULL; + } + efree(obj); } zend_object_value php_git_blob_new(zend_class_entry *ce TSRMLS_DC) { zend_object_value retval; - php_git_repository_t *obj; - zval *tmp; + php_git_repository_t *obj; + zval *tmp; - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + obj = ecalloc(1, sizeof(*obj)); + zend_object_std_init( &obj->zo, ce TSRMLS_CC ); + zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - retval.handle = zend_objects_store_put(obj, + retval.handle = zend_objects_store_put(obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_git_blob_free_storage, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); + retval.handlers = zend_get_std_object_handlers(); - return retval; + return retval; } @@ -75,18 +91,73 @@ PHP_METHOD(git_blob, __construct) php_git_repository_t *git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC); php_git_blob_t *obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + obj->repository = git->repository; +} + +static int php_git_blob_common_load(enum php_git_blob_write_type type,INTERNAL_FUNCTION_PARAMETERS) +{ + php_git_blob_t *this = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + char *contents; + int contents_len = 0; - int ret = git_blob_new(&obj->object,git->repository); + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &contents, &contents_len) == FAILURE) { + return -1; + } - if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Can't create new blob!"); - return; + if(contents_len <= 0) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't set null string."); + return -1; } + + this->type = type; + this->contents = estrndup(contents,contents_len); + this->contents_len = contents_len; + + return 0; } +PHP_METHOD(git_blob, loadFile) +{ + php_git_blob_common_load(PHP_GIT_LOAD_FROM_FILE,INTERNAL_FUNCTION_PARAM_PASSTHRU); + RETURN_TRUE; +} + +PHP_METHOD(git_blob, loadString) +{ + php_git_blob_common_load(PHP_GIT_LOAD_FROM_STRING,INTERNAL_FUNCTION_PARAM_PASSTHRU); + RETURN_TRUE; +} + +PHP_METHOD(git_blob, write) +{ + php_git_blob_t *this = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + git_oid out; + int ret = 0; + + if (this->type == PHP_GIT_LOAD_FROM_STRING) { + ret = git_blob_create_frombuffer(&out,this->repository,this->contents,this->contents_len); + if(ret != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't write blob."); + RETURN_FALSE; + } + } else if(this->type == PHP_GIT_LOAD_FROM_FILE) { + ret = git_blob_create_fromfile(&out,this->repository,this->contents); + if(ret != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't write blob."); + RETURN_FALSE; + } + } + + char oid_str[GIT_OID_HEXSZ+1] = {0}; + git_oid_to_string(oid_str,GIT_OID_HEXSZ+1,&out); + RETVAL_STRING(oid_str,1); +} PHPAPI function_entry php_git_blob_methods[] = { - PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC) + PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC) + PHP_ME(git_blob, loadString, arginfo_git_blob_load_string, ZEND_ACC_PUBLIC) + PHP_ME(git_blob, loadFile, arginfo_git_blob_load_file, ZEND_ACC_PUBLIC) + PHP_ME(git_blob, write, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -96,6 +167,5 @@ void git_init_blob(TSRMLS_D) INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Blob", php_git_blob_methods); git_blob_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry, NULL TSRMLS_CC); - git_blob_class_entry->create_object = php_git_blob_new; - + git_blob_class_entry->create_object = php_git_blob_new; } \ No newline at end of file diff --git a/src/php_git.h b/src/php_git.h index 2278989be2..ae876c741e 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -146,10 +146,18 @@ typedef struct{ git_tag *object; } php_git_tag_t; +enum php_git_blob_write_type{ + PHP_GIT_LOAD_FROM_FILE, + PHP_GIT_LOAD_FROM_STRING +}; typedef struct{ zend_object zo; git_blob *object; + git_repository *repository; + enum php_git_blob_write_type type; + char *contents; + int contents_len; } php_git_blob_t; typedef struct{ From 49b577050d8632554387f8d1e6ef1be045301251 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 4 Apr 2011 22:04:40 +0900 Subject: [PATCH 010/300] change Git\Index API. i'll add new commit API soon. please wait updating. [renamed] Git\Index::write() => Git\Index::update() [added] Git\Index::writeTree(); e.g) $idx = $repo->getIndex(); $idx->add("somefile"); $idx->update(); // write an index object from memory back to disk. $treeHash = $idx->writeTree(); // write a tree object `from disk`. these API names comes from git plumbing commands. e.g ) git write-tree, git update-index. --- LIBGIT2_VERSION | 2 +- src/index.c | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION index 009b49fb67..914a82a4bc 100644 --- a/LIBGIT2_VERSION +++ b/LIBGIT2_VERSION @@ -1 +1 @@ -72a3fe42fb7208712bbe8f0981f4c6274c05e9c3 \ No newline at end of file +b153589be2b3b9aea1f90a68891564ddeb12083c \ No newline at end of file diff --git a/src/index.c b/src/index.c index 9b3b1ed787..c9a46d866d 100644 --- a/src/index.c +++ b/src/index.c @@ -226,7 +226,7 @@ PHP_METHOD(git_index, remove) } -PHP_METHOD(git_index, write) +PHP_METHOD(git_index, update) { php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); @@ -262,6 +262,24 @@ PHP_METHOD(git_index, getIterator) obj->offset = 0; RETURN_ZVAL(iterator,0,0); } + +PHP_METHOD(git_index, writeTree) +{ + php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + git_oid oid; + char out[GIT_OID_HEXSZ+1]; + + int ret = git_tree_create_fromindex(&oid, this->index); + if(ret != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "can't write tree from index."); + RETURN_FALSE + } + + git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); + RETVAL_STRING(out,1); +} + /* PHP_METHOD(git_index, __construct) { @@ -324,7 +342,8 @@ PHPAPI function_entry php_git_index_methods[] = { PHP_ME(git_index, add, arginfo_git_index_add, ZEND_ACC_PUBLIC) PHP_ME(git_index, remove, arginfo_git_index_remove, ZEND_ACC_PUBLIC) PHP_ME(git_index, refresh, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index, write, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_index, update, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_index, writeTree, NULL, ZEND_ACC_PUBLIC) //PHP_ME(git_index, insert, arginfo_git_index_insert, ZEND_ACC_PUBLIC) // Countable PHP_ME(git_index, count, NULL, ZEND_ACC_PUBLIC) From 9997d5386a21bf4502116476f7e674d26a2dfd28 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 4 Apr 2011 23:57:29 +0900 Subject: [PATCH 011/300] added libgit2 version to php_info. --- src/php_git.c | 6 +++--- src/php_git.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/php_git.c b/src/php_git.c index cd24110543..f59b4a23d2 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -166,10 +166,10 @@ PHP_MINIT_FUNCTION(git) { PHP_MINFO_FUNCTION(git) { - php_printf("PHP Git Extension\n"); + php_printf("PHP libgit2 Extension\n"); php_info_print_table_start(); - php_info_print_table_row(2,"Version", PHP_GIT_EXTVER " (1st alpha development)"); - php_info_print_table_row(2, "Authors", "Shuhei Tanuma 'stanuma@zynga.co.jp' (lead)\n"); + php_info_print_table_row(2,"Version", PHP_GIT_EXTVER "-dev"); + php_info_print_table_row(2,"libgit2 version", LIBGIT2_VERSION); php_info_print_table_end(); } diff --git a/src/php_git.h b/src/php_git.h index ae876c741e..2799f52bce 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -27,7 +27,7 @@ #define PHP_GIT_H #define PHP_GIT_EXTNAME "git" -#define PHP_GIT_EXTVER "0.1" +#define PHP_GIT_EXTVER "0.2.1" #ifdef HAVE_CONFIG_H #include "config.h" From a8a88d62d9d748c8b4c01a2f69cb08f7824cf5f9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 5 Apr 2011 08:43:12 +0900 Subject: [PATCH 012/300] temporary added Git\TreeBuilder. e.g) $builder = new Git\TreeBuilder($tree); $builder->add("filename",attributes); $hash = $builder->write(); --- src/config.m4 | 2 +- src/php_git.c | 1 + src/php_git.h | 7 ++ src/tree_builder.c | 163 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 src/tree_builder.c diff --git a/src/config.m4 b/src/config.m4 index 69141c5386..e07f201135 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -29,7 +29,7 @@ if test $PHP_GIT != "no"; then PHP_ADD_LIBRARY_WITH_PATH(git2, $LIBGIT2_LIBDIR, GIT_SHARED_LIBADD) PHP_SUBST(GIT_SHARED_LIBADD) - PHP_NEW_EXTENSION(git,php_git.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) + PHP_NEW_EXTENSION(git,php_git.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], [ diff --git a/src/php_git.c b/src/php_git.c index f59b4a23d2..e4485016c2 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -138,6 +138,7 @@ PHP_MINIT_FUNCTION(git) { git_index_init(TSRMLS_C); git_init_signature(TSRMLS_C); git_init_walker(TSRMLS_C); + git_tree_builder_init(TSRMLS_C); git_tree_iterator_init(TSRMLS_C); git_init_tree(TSRMLS_C); git_init_commit(TSRMLS_C); diff --git a/src/php_git.h b/src/php_git.h index 2799f52bce..d06ca69789 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -55,6 +55,7 @@ extern PHPAPI zend_class_entry *git_index_iterator_class_entry; extern PHPAPI zend_class_entry *git_index_entry_class_entry; extern PHPAPI zend_class_entry *git_walker_class_entry; extern PHPAPI zend_class_entry *git_tree_class_entry; +extern PHPAPI zend_class_entry *git_tree_builder_class_entry; extern PHPAPI zend_class_entry *git_tree_iterator_class_entry; extern PHPAPI zend_class_entry *git_tree_entry_class_entry; extern PHPAPI zend_class_entry *git_commit_class_entry; @@ -80,6 +81,12 @@ typedef struct{ git_repository *repository; } php_git_repository_t; +typedef struct{ + zend_object zo; + git_treebuilder *builder; + git_repository *repository; +} php_git_tree_builder_t; + typedef struct{ zend_object zo; git_repository *repository; diff --git a/src/tree_builder.c b/src/tree_builder.c new file mode 100644 index 0000000000..eec664e245 --- /dev/null +++ b/src/tree_builder.c @@ -0,0 +1,163 @@ +/* + * The MIT License + * + * Copyright (c) 2010 - 2011 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_git.h" +#include +#include +#include +#include + +extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry,git_repository *repository); + +PHPAPI zend_class_entry *git_tree_builder_class_entry; +extern void php_tree_index_entry_create(zval **index, git_tree_entry *entry); + +static void php_git_tree_builder_free_storage(php_git_tree_builder_t *obj TSRMLS_DC) +{ + if(obj->builder){ + git_treebuilder_free(obj->builder); + } + if(obj->repository){ + obj->repository = NULL; + } + zend_object_std_dtor(&obj->zo TSRMLS_CC); + efree(obj); +} + +zend_object_value php_git_tree_builder_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + php_git_tree_builder_t *obj; + zval *tmp; + + obj = ecalloc(1, sizeof(*obj)); + zend_object_std_init( &obj->zo, ce TSRMLS_CC ); + zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + + retval.handle = zend_objects_store_put(obj, + (zend_objects_store_dtor_t)zend_objects_destroy_object, + (zend_objects_free_object_storage_t)php_git_tree_builder_free_storage, + NULL TSRMLS_CC); + retval.handlers = zend_get_std_object_handlers(); + return retval; +} + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder__construct, 0, 0, 1) + ZEND_ARG_INFO(0, tree) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder_add, 0, 0, 2) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, attribute) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder_remove, 0, 0, 1) + ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + + +PHP_METHOD(git_tree_builder, __construct) +{ + php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + zval *ztree; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z", &ztree) == FAILURE){ + return; + } + php_git_tree_t *tree = (php_git_tree_t *) zend_object_store_get_object(ztree TSRMLS_CC); + + git_treebuilder *builder; + git_treebuilder_create(&builder,tree->object); + this->builder = builder; + this->repository = tree->repository; +} + + +PHP_METHOD(git_tree_builder,add) +{ + php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + int ret = 0; + char *path; + int path_len = 0; + unsigned int attributes; + git_tree_entry *entry; + git_oid id; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sl", &path,&path_len,&attributes) == FAILURE){ + return; + } + + ret = git_treebuilder_insert(&entry,this->builder,path,&id,attributes); + if(ret == GIT_SUCCESS) { + RETURN_TRUE; + } +} + +PHP_METHOD(git_tree_builder,remove) +{ + php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + int ret = 0; + char *path; + int path_len = 0; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "sl", &path,&path_len) == FAILURE){ + return; + } + + ret = git_treebuilder_remove(this->builder,path); + if(ret == GIT_SUCCESS) { + RETURN_TRUE; + } +} + +PHP_METHOD(git_tree_builder,write) +{ + php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + git_oid oid; + char out[GIT_OID_HEXSZ+1]; + + int ret = git_treebuilder_write(&oid,this->repository,this->builder); + if(ret == GIT_SUCCESS) { + git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); + RETVAL_STRING(out, 1); + } +} + +PHPAPI function_entry php_git_tree_builder_methods[] = { + PHP_ME(git_tree_builder, __construct, arginfo_git_tree_builder__construct,ZEND_ACC_PUBLIC) + PHP_ME(git_tree_builder, add, arginfo_git_tree_builder_add, ZEND_ACC_PUBLIC) + PHP_ME(git_tree_builder, remove, arginfo_git_tree_builder_remove, ZEND_ACC_PUBLIC) + PHP_ME(git_tree_builder, write, NULL, ZEND_ACC_PUBLIC) +}; + +void git_tree_builder_init(TSRMLS_D) +{ + zend_class_entry git_tree_builder_ce; + INIT_NS_CLASS_ENTRY(git_tree_builder_ce, PHP_GIT_NS,"TreeBuilder", php_git_tree_builder_methods); + git_tree_builder_class_entry = zend_register_internal_class(&git_tree_builder_ce TSRMLS_CC); + git_tree_builder_class_entry->create_object = php_git_tree_builder_new; +} From a356f9d5b37da698a677777c9030d0d3f667675e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 6 Apr 2011 02:40:07 +0900 Subject: [PATCH 013/300] more TreeBuilder implementation. --- src/tree_builder.c | 68 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/src/tree_builder.c b/src/tree_builder.c index eec664e245..945d1c08ca 100644 --- a/src/tree_builder.c +++ b/src/tree_builder.c @@ -28,10 +28,7 @@ #include #include -extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry,git_repository *repository); - PHPAPI zend_class_entry *git_tree_builder_class_entry; -extern void php_tree_index_entry_create(zval **index, git_tree_entry *entry); static void php_git_tree_builder_free_storage(php_git_tree_builder_t *obj TSRMLS_DC) { @@ -68,6 +65,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder__construct, 0, 0, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder_add, 0, 0, 2) + ZEND_ARG_INFO(0, hash) ZEND_ARG_INFO(0, path) ZEND_ARG_INFO(0, attribute) ZEND_END_ARG_INFO() @@ -76,7 +74,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder_remove, 0, 0, 1) ZEND_ARG_INFO(0, path) ZEND_END_ARG_INFO() - PHP_METHOD(git_tree_builder, __construct) { php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); @@ -86,10 +83,20 @@ PHP_METHOD(git_tree_builder, __construct) "z", &ztree) == FAILURE){ return; } + + if(!instanceof_function(Z_OBJCE_P(ztree), git_tree_class_entry TSRMLS_CC)){ + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"argment does not Git\\Tree instance."); + RETURN_LONG(GIT_ERROR); + } + php_git_tree_t *tree = (php_git_tree_t *) zend_object_store_get_object(ztree TSRMLS_CC); git_treebuilder *builder; - git_treebuilder_create(&builder,tree->object); + if(git_treebuilder_create(&builder,tree->object) != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create tree builder instance"); + RETURN_LONG(GIT_ERROR); + } + this->builder = builder; this->repository = tree->repository; } @@ -98,53 +105,74 @@ PHP_METHOD(git_tree_builder, __construct) PHP_METHOD(git_tree_builder,add) { php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int ret = 0; + int error = GIT_ERROR; char *path; + char *hash; int path_len = 0; + int hash_len = 0; unsigned int attributes; - git_tree_entry *entry; git_oid id; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sl", &path,&path_len,&attributes) == FAILURE){ + "ssl", &hash,&hash_len,&path,&path_len,&attributes) == FAILURE){ return; } - ret = git_treebuilder_insert(&entry,this->builder,path,&id,attributes); - if(ret == GIT_SUCCESS) { - RETURN_TRUE; + error = git_oid_mkstr(&id, hash); + if (error != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create object id."); + RETURN_FALSE; } + + error = git_treebuilder_insert(NULL,this->builder,path,&id,attributes); + if (error != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't add entry"); + RETURN_FALSE; + } + RETURN_TRUE; } PHP_METHOD(git_tree_builder,remove) { php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int ret = 0; char *path; int path_len = 0; + int error = GIT_ERROR; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "sl", &path,&path_len) == FAILURE){ + "s", &path,&path_len) == FAILURE){ return; } + + if (path_len < 1) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"must specify target."); + RETURN_FALSE; + } + + error = git_treebuilder_remove(this->builder,path); - ret = git_treebuilder_remove(this->builder,path); - if(ret == GIT_SUCCESS) { + if (error == GIT_SUCCESS) { RETURN_TRUE; + } else { + RETURN_FALSE; } } PHP_METHOD(git_tree_builder,write) { php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_oid oid; char out[GIT_OID_HEXSZ+1]; + git_oid oid; + int error = GIT_ERROR; - int ret = git_treebuilder_write(&oid,this->repository,this->builder); - if(ret == GIT_SUCCESS) { - git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); - RETVAL_STRING(out, 1); + error = git_treebuilder_write(&oid,this->repository,this->builder); + if(error != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't write tree"); + RETURN_FALSE; } + + git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); + RETVAL_STRING(out, 1); } PHPAPI function_entry php_git_tree_builder_methods[] = { From 12ddbd766f430988f632f133c5161dee7f3961dc Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 8 Apr 2011 23:32:42 +0900 Subject: [PATCH 014/300] fix segmentation fault when calling Git\Tree\Entry::toObject() sorry, its my typo --- src/blob.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blob.c b/src/blob.c index 9e65548358..1e2e4bb39e 100644 --- a/src/blob.c +++ b/src/blob.c @@ -46,7 +46,7 @@ ZEND_END_ARG_INFO() static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); - + if (obj->object != NULL) { git_object_close(obj->object); obj->object = NULL; @@ -61,8 +61,8 @@ static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC) zend_object_value php_git_blob_new(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; - php_git_repository_t *obj; + zend_object_value retval; + php_git_blob_t *obj; zval *tmp; obj = ecalloc(1, sizeof(*obj)); From 9b9de59735872de58f6ecd25e62a1df58bbd0c52 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 3 May 2011 22:41:16 +0900 Subject: [PATCH 015/300] fix variable declaration. --- src/index.c | 1 - src/php_git.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.c b/src/index.c index c9a46d866d..d10f04793a 100644 --- a/src/index.c +++ b/src/index.c @@ -29,7 +29,6 @@ #include PHPAPI zend_class_entry *git_index_class_entry; -PHPAPI zend_class_entry *git_index_iterator_class_entry; static void php_git_index_free_storage(php_git_index_t *obj TSRMLS_DC) { diff --git a/src/php_git.h b/src/php_git.h index d06ca69789..3dca583917 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -63,7 +63,7 @@ extern PHPAPI zend_class_entry *git_signature_class_entry; extern PHPAPI zend_class_entry *git_tag_class_entry; extern PHPAPI zend_class_entry *git_blob_class_entry; extern PHPAPI zend_class_entry *git_odb_class_entry; -PHPAPI zend_class_entry *git_backend_class_entry; +extern PHPAPI zend_class_entry *git_backend_class_entry; typedef struct{ zend_object zo; From d3d90cd1010b3b4530c4f3b7e1f5a81644e9e590 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 13:56:12 +0900 Subject: [PATCH 016/300] forgot function terminator. --- src/tree_builder.c | 1 + src/tree_iterator.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/tree_builder.c b/src/tree_builder.c index 945d1c08ca..dd898f78b4 100644 --- a/src/tree_builder.c +++ b/src/tree_builder.c @@ -180,6 +180,7 @@ PHPAPI function_entry php_git_tree_builder_methods[] = { PHP_ME(git_tree_builder, add, arginfo_git_tree_builder_add, ZEND_ACC_PUBLIC) PHP_ME(git_tree_builder, remove, arginfo_git_tree_builder_remove, ZEND_ACC_PUBLIC) PHP_ME(git_tree_builder, write, NULL, ZEND_ACC_PUBLIC) + {NULL,NULL,NULL} }; void git_tree_builder_init(TSRMLS_D) diff --git a/src/tree_iterator.c b/src/tree_iterator.c index 9d785cd4d6..8034541ab8 100644 --- a/src/tree_iterator.c +++ b/src/tree_iterator.c @@ -132,6 +132,7 @@ PHPAPI function_entry php_git_tree_iterator_methods[] = { PHP_ME(git_tree_iterator, next, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree_iterator, rewind, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree_iterator, valid, NULL, ZEND_ACC_PUBLIC) + {NULL,NULL,NULL} }; void git_tree_iterator_init(TSRMLS_D) From 045c826557b63e59a43c5961e89135d546ce8f51 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 13:56:56 +0900 Subject: [PATCH 017/300] temporary disabled odb & backend. --- src/odb.c | 8 ++++---- src/php_git.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/odb.c b/src/odb.c index 4dfa12bd0c..464c12d1b7 100644 --- a/src/odb.c +++ b/src/odb.c @@ -78,7 +78,7 @@ PHP_METHOD(git_odb, __construct) } } - +/* int php_git_odb_add_alternate(git_odb **odb, zval *backend, int priority) { TSRMLS_FETCH(); @@ -148,12 +148,12 @@ PHP_METHOD(git_odb, addAlternate) php_git_odb_add_alternate(&this->odb,backend, priority); } - +*/ PHPAPI function_entry php_git_odb_methods[] = { PHP_ME(git_odb, __construct, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_odb, addBackend, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) - PHP_ME(git_odb, addAlternate, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) +// PHP_ME(git_odb, addBackend, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) +// PHP_ME(git_odb, addAlternate, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; diff --git a/src/php_git.h b/src/php_git.h index 3dca583917..bddf48daae 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -63,7 +63,7 @@ extern PHPAPI zend_class_entry *git_signature_class_entry; extern PHPAPI zend_class_entry *git_tag_class_entry; extern PHPAPI zend_class_entry *git_blob_class_entry; extern PHPAPI zend_class_entry *git_odb_class_entry; -extern PHPAPI zend_class_entry *git_backend_class_entry; +//extern PHPAPI zend_class_entry *git_backend_class_entry; typedef struct{ zend_object zo; From 8ee4e138e429d93323a09d38de83ec0ca5b14a0c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 14:02:45 +0900 Subject: [PATCH 018/300] added Git\Repository::getWorkdir(); --- src/repository.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/repository.c b/src/repository.c index 2e4025d6b7..8da83a9e49 100644 --- a/src/repository.c +++ b/src/repository.c @@ -632,6 +632,17 @@ PHP_METHOD(git_repository, open2) RETURN_TRUE; } +PHP_METHOD(git_repository, getWorkdir) +{ + php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + + if(this->repository != NULL) { + char *git_workdir; + git_workdir = git_repository_workdir(this->repository); + RETVAL_STRING(git_workdir,1); + } +} + PHPAPI function_entry php_git_repository_methods[] = { PHP_ME(git_repository, __construct, arginfo_git_construct, ZEND_ACC_PUBLIC) @@ -647,6 +658,7 @@ PHPAPI function_entry php_git_repository_methods[] = { PHP_ME(git_repository, open3, arginfo_git_open3, ZEND_ACC_PUBLIC) PHP_ME(git_repository, open2, arginfo_git_open2, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getReferences, arginfo_git_get_references, ZEND_ACC_PUBLIC) + PHP_ME(git_repository, getWorkdir, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; From 6fc57eaf204b0729330b7f0661aab0c650ef773f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 14:06:21 +0900 Subject: [PATCH 019/300] added Git\Repository::empty(); --- src/repository.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/repository.c b/src/repository.c index 8da83a9e49..771d3d85ec 100644 --- a/src/repository.c +++ b/src/repository.c @@ -643,6 +643,20 @@ PHP_METHOD(git_repository, getWorkdir) } } +PHP_METHOD(git_repository, empty) +{ + php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + if (this->repository != NULL) { + if (git_repository_is_empty(this->repository)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } + } else { + RETURN_TRUE; + } +} + PHPAPI function_entry php_git_repository_methods[] = { PHP_ME(git_repository, __construct, arginfo_git_construct, ZEND_ACC_PUBLIC) @@ -659,6 +673,7 @@ PHPAPI function_entry php_git_repository_methods[] = { PHP_ME(git_repository, open2, arginfo_git_open2, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getReferences, arginfo_git_get_references, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getWorkdir, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_repository, empty, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; From c89f79bc7970738792505c1502f91260d3e45e94 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 14:22:04 +0900 Subject: [PATCH 020/300] temporary enabled odb & backend. im re-writing backend :D --- src/backend.c | 224 -------------------------------------------------- src/commit.c | 2 +- src/config.m4 | 2 +- src/odb.c | 8 +- src/php_git.h | 2 +- 5 files changed, 7 insertions(+), 231 deletions(-) diff --git a/src/backend.c b/src/backend.c index c95a6741ae..aa5417dd29 100644 --- a/src/backend.c +++ b/src/backend.c @@ -30,22 +30,6 @@ PHPAPI zend_class_entry *git_backend_class_entry; -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read, 0, 0, 1) - ZEND_ARG_INFO(0, key) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read_header, 0, 0, 1) - ZEND_ARG_INFO(0, key) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_exists, 0, 0, 1) - ZEND_ARG_INFO(0, key) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_write, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - static void php_git_backend_free_storage(php_git_backend_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); @@ -55,191 +39,6 @@ static void php_git_backend_free_storage(php_git_backend_t *obj TSRMLS_DC) efree(obj); } -int php_git_backend__exists(git_odb_backend *_backend, const git_oid *oid) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - - zval *retval; - zval *params[1]; - zval func; - int result; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - ZVAL_STRING(&func,"exists", 1); - MAKE_STD_ZVAL(params[0]); - ZVAL_STRING(params[0],out, 1); - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call exists method"); - return 0; - } - result = Z_BVAL_P(retval); - zval_ptr_dtor(&retval); - zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - - if(result){ - return 1; - }else{ - return 0; - } -} -int php_git_backend__write(git_oid *id, git_odb_backend *_backend, git_rawobj *obj) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - int ret = 0; - zval *retval; - zval *params[1]; - zval func; - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - ZVAL_STRING(&func,"write", 1); - - - MAKE_STD_ZVAL(params[0]); - object_init_ex(params[0],git_rawobject_class_entry); - - add_property_stringl_ex(params[0],"data",sizeof("data"),obj->data,obj->len,1 TSRMLS_CC); - add_property_long(params[0],"type",obj->type); - add_property_long(params[0],"len",obj->len); - - php_git_rawobject_t *raw = (php_git_rawobject_t *) zend_object_store_get_object(params[0] TSRMLS_CC); - raw->object = obj; - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call write method"); - return GIT_ERROR; - } - if(strlen(Z_STRVAL_P(retval)) == 40){ - git_oid_mkstr(id,Z_STRVAL_P(retval)); - ret = GIT_SUCCESS; - }else{ - ret = GIT_ERROR; - } - - zval_ptr_dtor(&retval); - //do not free Git\RawObject here. - //zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - - return ret; -} -int php_git_backend__read(git_rawobj *obj, git_odb_backend *_backend, const git_oid *oid) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - - zval *retval; - zval *params[1]; - zval func; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - - ZVAL_STRING(&func,"read", 1); - - MAKE_STD_ZVAL(params[0]); - ZVAL_STRING(params[0],out, 1); - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call read method"); - return GIT_ERROR; - } - - if(!instanceof_function(Z_OBJCE_P(retval), git_rawobject_class_entry TSRMLS_CC)){ - fprintf(stderr,"read interface must return Git\\Rawobject"); - return GIT_ENOTFOUND; - } - - zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC); - - // do not use ecalloc. obj->data will free by git_rawobject_close() - obj->data = calloc(1,strlen(Z_STRVAL_P(str))); - obj->len = strlen(Z_STRVAL_P(str)); - obj->type = GIT_OBJ_BLOB; - memcpy(obj->data, Z_STRVAL_P(str),obj->len); - - zval_ptr_dtor(&retval); - zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - - return GIT_SUCCESS; -} -int php_git_backend__read_header(git_rawobj *obj, git_odb_backend *_backend, const git_oid *oid) -{ - TSRMLS_FETCH(); - char out[GIT_OID_HEXSZ+1] = {0} ; - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - - zval *retval; - zval *params[1]; - zval func; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - - ZVAL_STRING(&func,"read", 1); - - MAKE_STD_ZVAL(params[0]); - ZVAL_STRING(params[0],out, 1); - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call read_header method"); - return GIT_ERROR; - } - - if(!instanceof_function(Z_OBJCE_P(retval), git_rawobject_class_entry TSRMLS_CC)){ - fprintf(stderr,"read interface must return Git\\Rawobject"); - return GIT_ENOTFOUND; - } - - zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",sizeof("data"), 0 TSRMLS_CC); - - obj->data = NULL; - obj->len = strlen(Z_STRVAL_P(str)); - obj->type = GIT_OBJ_BLOB; - - zval_ptr_dtor(&retval); - zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - - return GIT_SUCCESS; -} - -void php_git_backend__free(git_odb_backend *backend) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)backend; - - zval *retval; - zval func; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - - ZVAL_STRING(&func,"free", 1); - - if(call_user_function(NULL,&object->self,&func,retval,0,NULL TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call free method"); - return 0; - } - - zval_ptr_dtor(&retval); - zval_dtor(&func); -} zend_object_value php_git_backend_new(zend_class_entry *ce TSRMLS_DC) { @@ -261,30 +60,7 @@ zend_object_value php_git_backend_new(zend_class_entry *ce TSRMLS_DC) return retval; } - -PHP_METHOD(git_backend, __construct) -{ - php_git_backend_t *this = (php_git_backend_t *)zend_object_store_get_object(getThis() TSRMLS_CC); - php_git_backend_internal *internal; - - internal = ecalloc(1,sizeof(php_git_backend_internal)); - internal->parent.read = &php_git_backend__read; - internal->parent.read_header = &php_git_backend__read_header; - internal->parent.write = &php_git_backend__write; - internal->parent.exists = &php_git_backend__exists; - internal->parent.free = &php_git_backend__free; - internal->self = getThis(); - - this->backend = internal; -} - PHPAPI function_entry php_git_backend_methods[] = { - PHP_ME(git_backend, __construct, NULL, ZEND_ACC_PUBLIC) - PHP_ABSTRACT_ME(git_backend, read, arginfo_git_backend_read) - PHP_ABSTRACT_ME(git_backend, read_header, arginfo_git_backend_read_header) - PHP_ABSTRACT_ME(git_backend, exists, arginfo_git_backend_exists) - PHP_ABSTRACT_ME(git_backend, write, arginfo_git_backend_write) - PHP_ABSTRACT_ME(git_backend, free, NULL) {NULL, NULL, NULL} }; diff --git a/src/commit.c b/src/commit.c index d7b72b24f4..7f5c83acb5 100644 --- a/src/commit.c +++ b/src/commit.c @@ -219,7 +219,7 @@ void git_init_commit(TSRMLS_C) INIT_NS_CLASS_ENTRY(git_commit_ce, PHP_GIT_NS,"Commit", php_git_commit_methods); git_commit_class_entry = zend_register_internal_class_ex(&git_commit_ce,git_object_class_entry,NULL TSRMLS_CC); - git_commit_class_entry->create_object = php_git_commit_new; + git_commit_class_entry->create_object = php_git_commit_new; zend_declare_property_null(git_commit_class_entry, "author", sizeof("author")-1, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_commit_class_entry, "committer",sizeof("committer")-1, ZEND_ACC_PUBLIC TSRMLS_CC); } \ No newline at end of file diff --git a/src/config.m4 b/src/config.m4 index e07f201135..3dc29f6f26 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -29,7 +29,7 @@ if test $PHP_GIT != "no"; then PHP_ADD_LIBRARY_WITH_PATH(git2, $LIBGIT2_LIBDIR, GIT_SHARED_LIBADD) PHP_SUBST(GIT_SHARED_LIBADD) - PHP_NEW_EXTENSION(git,php_git.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) + PHP_NEW_EXTENSION(git,php_git.c backend.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], [ diff --git a/src/odb.c b/src/odb.c index 464c12d1b7..4dfa12bd0c 100644 --- a/src/odb.c +++ b/src/odb.c @@ -78,7 +78,7 @@ PHP_METHOD(git_odb, __construct) } } -/* + int php_git_odb_add_alternate(git_odb **odb, zval *backend, int priority) { TSRMLS_FETCH(); @@ -148,12 +148,12 @@ PHP_METHOD(git_odb, addAlternate) php_git_odb_add_alternate(&this->odb,backend, priority); } -*/ + PHPAPI function_entry php_git_odb_methods[] = { PHP_ME(git_odb, __construct, NULL, ZEND_ACC_PUBLIC) -// PHP_ME(git_odb, addBackend, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) -// PHP_ME(git_odb, addAlternate, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) + PHP_ME(git_odb, addBackend, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) + PHP_ME(git_odb, addAlternate, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; diff --git a/src/php_git.h b/src/php_git.h index bddf48daae..3dca583917 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -63,7 +63,7 @@ extern PHPAPI zend_class_entry *git_signature_class_entry; extern PHPAPI zend_class_entry *git_tag_class_entry; extern PHPAPI zend_class_entry *git_blob_class_entry; extern PHPAPI zend_class_entry *git_odb_class_entry; -//extern PHPAPI zend_class_entry *git_backend_class_entry; +extern PHPAPI zend_class_entry *git_backend_class_entry; typedef struct{ zend_object zo; From 9369ff7117ea69fd8852859357e20e946f0c85a7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 16:02:08 +0900 Subject: [PATCH 021/300] temporary commit for re-writing backends --- src/backend.c | 237 ++++++++++++++++++++++ src/config.m4 | 2 +- src/php_git.c | 393 ++++++++++++++++++------------------ src/php_git.h | 1 + src/rawobject.c | 42 ++++ tests/lib/MemoryBackend.php | 17 +- 6 files changed, 484 insertions(+), 208 deletions(-) create mode 100644 src/rawobject.c diff --git a/src/backend.c b/src/backend.c index aa5417dd29..92ce8142b5 100644 --- a/src/backend.c +++ b/src/backend.c @@ -30,6 +30,30 @@ PHPAPI zend_class_entry *git_backend_class_entry; +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read, 0, 0, 1) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read_header, 0, 0, 1) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_exists, 0, 0, 1) + ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_write, 0, 0, 1) + ZEND_ARG_INFO(0, object) +ZEND_END_ARG_INFO() + + +int php_git_backend__exists(git_odb_backend *backend, const git_oid *oid); +int php_git_backend__write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type); +int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id); +int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id); +void php_git_backend__free(git_odb_backend *backend); + + static void php_git_backend_free_storage(php_git_backend_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); @@ -60,7 +84,220 @@ zend_object_value php_git_backend_new(zend_class_entry *ce TSRMLS_DC) return retval; } +int php_git_backend__exists(git_odb_backend *_backend, const git_oid *oid) +{ + TSRMLS_FETCH(); + php_git_backend_internal *object = (php_git_backend_internal *)_backend; + char out[GIT_OID_HEXSZ+1] = {0}; + git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); + + zval *retval; + zval *params[1]; + zval func; + int result; + + MAKE_STD_ZVAL(retval); + ZVAL_NULL(retval); + ZVAL_STRING(&func,"exists", 1); + MAKE_STD_ZVAL(params[0]); + ZVAL_STRING(params[0],out, 1); + + if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "can't call exists method"); + return 0; + } + result = Z_BVAL_P(retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(¶ms[0]); + zval_dtor(&func); + + if(result){ + return 1; + }else{ + return 0; + } +} +int php_git_backend__write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type) +{ + TSRMLS_FETCH(); + php_git_backend_internal *object = (php_git_backend_internal *)_backend; + int ret = 0; + char out[GIT_OID_HEXSZ+1] = {0}; + zval *retval; + zval *params[1]; + zval func; + MAKE_STD_ZVAL(retval); + ZVAL_NULL(retval); + ZVAL_STRING(&func,"write", 1); + + + MAKE_STD_ZVAL(params[0]); + object_init_ex(params[0],git_rawobject_class_entry); + + git_oid_to_string(out,GIT_OID_HEXSZ,id); + + add_property_stringl_ex(params[0],"data",sizeof("data"),(char *)buffer,size,1 TSRMLS_CC); + add_property_stringl_ex(params[0],"id", sizeof("id"), (char *)out, GIT_OID_HEXSZ,1 TSRMLS_CC); + add_property_long(params[0],"type",type); + add_property_long(params[0],"len",size); + + if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "can't call write method"); + return GIT_ERROR; + } + if (Z_BVAL_P(retval)) { + ret = GIT_SUCCESS; + } else { + ret = GIT_ERROR; + } + + zval_ptr_dtor(&retval); + + // do not free Git\RawObject here. + //zval_ptr_dtor(¶ms[0]); + zval_dtor(&func); + + return ret; +} +int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *oid) +{ + TSRMLS_FETCH(); + php_git_backend_internal *object = (php_git_backend_internal *)_backend; + char out[GIT_OID_HEXSZ+1] = {0}; + git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); + + zval *retval; + zval *params[1]; + zval func; + + MAKE_STD_ZVAL(retval); + ZVAL_NULL(retval); + + ZVAL_STRING(&func,"read", 1); + + MAKE_STD_ZVAL(params[0]); + ZVAL_STRING(params[0],out, 1); + + if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "can't call read method"); + return GIT_ERROR; + } + + if(!instanceof_function(Z_OBJCE_P(retval), git_rawobject_class_entry TSRMLS_CC)){ + fprintf(stderr,"read interface must return Git\\RawObject"); + return GIT_ENOTFOUND; + } + + zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC); + zval *len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); + zval *tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); + + buffer = calloc(1,Z_LVAL_P(len)); + memcpy(buffer,Z_STRVAL_P(str),Z_LVAL_P(len)); + type = Z_LVAL_P(tp); + size = Z_LVAL_P(len); + + zval_ptr_dtor(&retval); + zval_ptr_dtor(¶ms[0]); + zval_dtor(&func); + + return GIT_SUCCESS; +} + +int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *oid) +{ + TSRMLS_FETCH(); + php_git_backend_internal *object = (php_git_backend_internal *)_backend; + char out[GIT_OID_HEXSZ+1] = {0}; + git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); + + zval *retval; + zval *params[1]; + zval func; + + MAKE_STD_ZVAL(retval); + ZVAL_NULL(retval); + + ZVAL_STRING(&func,"read", 1); + + MAKE_STD_ZVAL(params[0]); + ZVAL_STRING(params[0],out, 1); + + if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "can't call read method"); + return GIT_ERROR; + } + + if(!instanceof_function(Z_OBJCE_P(retval), git_rawobject_class_entry TSRMLS_CC)){ + fprintf(stderr,"read interface must return Git\\RawObject"); + return GIT_ENOTFOUND; + } + + zval *len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); + zval *tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); + + type = Z_LVAL_P(tp); + size = Z_LVAL_P(len); + + zval_ptr_dtor(&retval); + zval_ptr_dtor(¶ms[0]); + zval_dtor(&func); + + return GIT_SUCCESS; +} + +void php_git_backend__free(git_odb_backend *backend) +{ + TSRMLS_FETCH(); + php_git_backend_internal *object = (php_git_backend_internal *)backend; + + zval *retval; + zval func; + + MAKE_STD_ZVAL(retval); + ZVAL_NULL(retval); + + ZVAL_STRING(&func,"free", 1); + + if(call_user_function(NULL,&object->self,&func,retval,0,NULL TSRMLS_CC) == FAILURE){ + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, + "can't call free method"); + + return; + } + + zval_ptr_dtor(&retval); + zval_dtor(&func); +} + + +PHP_METHOD(git_backend, __construct) +{ + php_git_backend_t *this = (php_git_backend_t *)zend_object_store_get_object(getThis() TSRMLS_CC); + php_git_backend_internal *internal; + + internal = ecalloc(1,sizeof(php_git_backend_internal)); + internal->parent.read = &php_git_backend__read; + internal->parent.read_header = &php_git_backend__read_header; + internal->parent.write = &php_git_backend__write; + internal->parent.exists = &php_git_backend__exists; + internal->parent.free = &php_git_backend__free; + internal->self = getThis(); + + this->backend = internal; +} + PHPAPI function_entry php_git_backend_methods[] = { + PHP_ME(git_backend, __construct, NULL, ZEND_ACC_PUBLIC) + PHP_ABSTRACT_ME(git_backend, read, arginfo_git_backend_read) + PHP_ABSTRACT_ME(git_backend, read_header, arginfo_git_backend_read_header) + PHP_ABSTRACT_ME(git_backend, exists, arginfo_git_backend_exists) + PHP_ABSTRACT_ME(git_backend, write, arginfo_git_backend_write) + PHP_ABSTRACT_ME(git_backend, free, NULL) {NULL, NULL, NULL} }; diff --git a/src/config.m4 b/src/config.m4 index 3dc29f6f26..c051c1ebd2 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -29,7 +29,7 @@ if test $PHP_GIT != "no"; then PHP_ADD_LIBRARY_WITH_PATH(git2, $LIBGIT2_LIBDIR, GIT_SHARED_LIBADD) PHP_SUBST(GIT_SHARED_LIBADD) - PHP_NEW_EXTENSION(git,php_git.c backend.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) + PHP_NEW_EXTENSION(git,php_git.c rawobject.c backend.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], [ diff --git a/src/php_git.c b/src/php_git.c index e4485016c2..bda0ef8e90 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -1,196 +1,197 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_string_to_type, 0, 0, 1) - ZEND_ARG_INFO(0, string_type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_type_to_string, 0, 0, 1) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_hex_to_raw, 0, 0, 1) - ZEND_ARG_INFO(0, hex) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_raw_to_hex, 0, 0, 1) - ZEND_ARG_INFO(0, raw) -ZEND_END_ARG_INFO() - -PHP_FUNCTION(git_string_to_type) -{ - const char *string_type = NULL; - int string_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &string_type, &string_len) == FAILURE){ - return; - } - - RETVAL_LONG(git_object_string2type(string_type)) -} - -PHP_FUNCTION(git_type_to_string) -{ - git_otype t; - int type; - const char *str; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &type) == FAILURE){ - return; - } - t = (git_otype)type; - str = git_object_type2string(t); - - RETVAL_STRING(str,1); -} - -PHP_FUNCTION(git_hex_to_raw) -{ - git_oid oid; - - const char *hex = NULL; - int hex_len = 0; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hex, &hex_len) == FAILURE){ - return; - } - - git_oid_mkstr(&oid, hex); - RETVAL_STRINGL((&oid)->id,GIT_OID_RAWSZ,1); -} - -PHP_FUNCTION(git_raw_to_hex) -{ - git_oid oid; - const char *raw = NULL; - char out[GIT_OID_HEXSZ]; - int raw_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s", - &raw, &raw_len) == FAILURE){ - return; - } - - git_oid_mkraw(&oid, raw); - git_oid_fmt(out, &oid); - - RETVAL_STRINGL(out,GIT_OID_HEXSZ,1); -} - -PHPAPI function_entry php_git_methods[] = { - {NULL, NULL, NULL} -}; - -// Git Global Functions -PHPAPI function_entry php_git_functions[] = { - PHP_FE(git_hex_to_raw, arginfo_git_hex_to_raw) - PHP_FE(git_raw_to_hex, arginfo_git_raw_to_hex) - PHP_FE(git_type_to_string, arginfo_git_type_to_string) - PHP_FE(git_string_to_type, arginfo_git_string_to_type) - {NULL, NULL, NULL} -}; - -void git_init(TSRMLS_D) -{ - zend_class_entry git_ce; - INIT_NS_CLASS_ENTRY(git_ce, PHP_GIT_NS,"Git", php_git_methods); - git_class_entry = zend_register_internal_class(&git_ce TSRMLS_CC); -} - -PHP_MINIT_FUNCTION(git) { - git_init(TSRMLS_C); - git_init_object(TSRMLS_C); - git_init_reference(TSRMLS_C); - php_git_repository_init(TSRMLS_C); - git_index_iterator_init(TSRMLS_C); - git_index_entry_init(TSRMLS_C); - git_index_init(TSRMLS_C); - git_init_signature(TSRMLS_C); - git_init_walker(TSRMLS_C); - git_tree_builder_init(TSRMLS_C); - git_tree_iterator_init(TSRMLS_C); - git_init_tree(TSRMLS_C); - git_init_commit(TSRMLS_C); - git_init_tree_entry(TSRMLS_C); - git_init_tag(TSRMLS_C); - git_init_blob(TSRMLS_C); - git_init_odb(TSRMLS_C); - //git_init_backend(TSRMLS_C); - git_init_reference_manager(TSRMLS_C); - - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_NONE", 0, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_TOPO", 1, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_DATE", 2, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_REVERSE", 4, CONST_CS | CONST_PERSISTENT); - - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Any", GIT_OBJ_ANY, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Bad", GIT_OBJ_BAD, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Commit", GIT_OBJ_COMMIT, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Tree", GIT_OBJ_TREE, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Blob", GIT_OBJ_BLOB, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Tag", GIT_OBJ_TAG, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; -} - - -PHP_MINFO_FUNCTION(git) -{ - php_printf("PHP libgit2 Extension\n"); - php_info_print_table_start(); - php_info_print_table_row(2,"Version", PHP_GIT_EXTVER "-dev"); - php_info_print_table_row(2,"libgit2 version", LIBGIT2_VERSION); - php_info_print_table_end(); -} - -zend_module_entry git_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 - STANDARD_MODULE_HEADER, -#endif - PHP_GIT_EXTNAME, - php_git_functions, /* Functions */ - PHP_MINIT(git), /* MINIT */ - NULL, /* MSHUTDOWN */ - NULL, /* RINIT */ - NULL, /* RSHUTDOWN */ - PHP_MINFO(git), /* MINFO */ -#if ZEND_MODULE_API_NO >= 20010901 - PHP_GIT_EXTVER, -#endif - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_GIT -ZEND_GET_MODULE(git) -#endif +/* + * The MIT License + * + * Copyright (c) 2010 - 2011 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_git.h" +#include +#include +#include +#include + +PHPAPI zend_class_entry *git_class_entry; + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_string_to_type, 0, 0, 1) + ZEND_ARG_INFO(0, string_type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_type_to_string, 0, 0, 1) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_hex_to_raw, 0, 0, 1) + ZEND_ARG_INFO(0, hex) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_raw_to_hex, 0, 0, 1) + ZEND_ARG_INFO(0, raw) +ZEND_END_ARG_INFO() + +PHP_FUNCTION(git_string_to_type) +{ + const char *string_type = NULL; + int string_len = 0; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &string_type, &string_len) == FAILURE){ + return; + } + + RETVAL_LONG(git_object_string2type(string_type)) +} + +PHP_FUNCTION(git_type_to_string) +{ + git_otype t; + int type; + const char *str; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "l", &type) == FAILURE){ + return; + } + t = (git_otype)type; + str = git_object_type2string(t); + + RETVAL_STRING(str,1); +} + +PHP_FUNCTION(git_hex_to_raw) +{ + git_oid oid; + + const char *hex = NULL; + int hex_len = 0; + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &hex, &hex_len) == FAILURE){ + return; + } + + git_oid_mkstr(&oid, hex); + RETVAL_STRINGL((&oid)->id,GIT_OID_RAWSZ,1); +} + +PHP_FUNCTION(git_raw_to_hex) +{ + git_oid oid; + const char *raw = NULL; + char out[GIT_OID_HEXSZ]; + int raw_len = 0; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s", + &raw, &raw_len) == FAILURE){ + return; + } + + git_oid_mkraw(&oid, raw); + git_oid_fmt(out, &oid); + + RETVAL_STRINGL(out,GIT_OID_HEXSZ,1); +} + +PHPAPI function_entry php_git_methods[] = { + {NULL, NULL, NULL} +}; + +// Git Global Functions +PHPAPI function_entry php_git_functions[] = { + PHP_FE(git_hex_to_raw, arginfo_git_hex_to_raw) + PHP_FE(git_raw_to_hex, arginfo_git_raw_to_hex) + PHP_FE(git_type_to_string, arginfo_git_type_to_string) + PHP_FE(git_string_to_type, arginfo_git_string_to_type) + {NULL, NULL, NULL} +}; + +void git_init(TSRMLS_D) +{ + zend_class_entry git_ce; + INIT_NS_CLASS_ENTRY(git_ce, PHP_GIT_NS,"Git", php_git_methods); + git_class_entry = zend_register_internal_class(&git_ce TSRMLS_CC); +} + +PHP_MINIT_FUNCTION(git) { + git_init(TSRMLS_C); + git_init_object(TSRMLS_C); + git_init_reference(TSRMLS_C); + php_git_repository_init(TSRMLS_C); + git_index_iterator_init(TSRMLS_C); + git_index_entry_init(TSRMLS_C); + git_index_init(TSRMLS_C); + git_init_signature(TSRMLS_C); + git_init_walker(TSRMLS_C); + git_tree_builder_init(TSRMLS_C); + git_tree_iterator_init(TSRMLS_C); + git_init_tree(TSRMLS_C); + git_init_commit(TSRMLS_C); + git_init_tree_entry(TSRMLS_C); + git_init_tag(TSRMLS_C); + git_init_blob(TSRMLS_C); + git_init_odb(TSRMLS_C); + git_init_rawobject(TSRMLS_C); + git_init_backend(TSRMLS_C); + git_init_reference_manager(TSRMLS_C); + + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_NONE", 0, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_TOPO", 1, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_DATE", 2, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_REVERSE", 4, CONST_CS | CONST_PERSISTENT); + + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Any", GIT_OBJ_ANY, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Bad", GIT_OBJ_BAD, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Commit", GIT_OBJ_COMMIT, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Tree", GIT_OBJ_TREE, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Blob", GIT_OBJ_BLOB, CONST_CS | CONST_PERSISTENT); + REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Tag", GIT_OBJ_TAG, CONST_CS | CONST_PERSISTENT); + + return SUCCESS; +} + + +PHP_MINFO_FUNCTION(git) +{ + php_printf("PHP libgit2 Extension\n"); + php_info_print_table_start(); + php_info_print_table_row(2,"Version", PHP_GIT_EXTVER "-dev"); + php_info_print_table_row(2,"libgit2 version", LIBGIT2_VERSION); + php_info_print_table_end(); +} + +zend_module_entry git_module_entry = { +#if ZEND_MODULE_API_NO >= 20010901 + STANDARD_MODULE_HEADER, +#endif + PHP_GIT_EXTNAME, + php_git_functions, /* Functions */ + PHP_MINIT(git), /* MINIT */ + NULL, /* MSHUTDOWN */ + NULL, /* RINIT */ + NULL, /* RSHUTDOWN */ + PHP_MINFO(git), /* MINFO */ +#if ZEND_MODULE_API_NO >= 20010901 + PHP_GIT_EXTVER, +#endif + STANDARD_MODULE_PROPERTIES +}; + +#ifdef COMPILE_DL_GIT +ZEND_GET_MODULE(git) +#endif diff --git a/src/php_git.h b/src/php_git.h index 3dca583917..2600b8b4c6 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -64,6 +64,7 @@ extern PHPAPI zend_class_entry *git_tag_class_entry; extern PHPAPI zend_class_entry *git_blob_class_entry; extern PHPAPI zend_class_entry *git_odb_class_entry; extern PHPAPI zend_class_entry *git_backend_class_entry; +extern PHPAPI zend_class_entry *git_rawobject_class_entry; typedef struct{ zend_object zo; diff --git a/src/rawobject.c b/src/rawobject.c new file mode 100644 index 0000000000..1dd9133632 --- /dev/null +++ b/src/rawobject.c @@ -0,0 +1,42 @@ +/* + * The MIT License + * + * Copyright (c) 2010 - 2011 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_git.h" +PHPAPI zend_class_entry *git_rawobject_class_entry; + +PHPAPI function_entry php_git_rawobject_methods[] = { + {NULL, NULL, NULL} +}; + +void git_init_rawobject(TSRMLS_D) +{ + zend_class_entry ce; + INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"RawObject", php_git_rawobject_methods); + git_rawobject_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + + zend_declare_property_null(git_rawobject_class_entry, "id", sizeof("id"), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_rawobject_class_entry, "data", sizeof("data"), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_rawobject_class_entry, "type", sizeof("type"), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_rawobject_class_entry, "len", sizeof("len"), ZEND_ACC_PUBLIC TSRMLS_CC); +} \ No newline at end of file diff --git a/tests/lib/MemoryBackend.php b/tests/lib/MemoryBackend.php index 150cba3b1e..55cfd51e14 100644 --- a/tests/lib/MemoryBackend.php +++ b/tests/lib/MemoryBackend.php @@ -18,7 +18,7 @@ public function get($key){ if(isset($this->memory[$key])){ $obj = $this->memory[$key]; - return new \Git\RawObject($obj->type,$obj->data,$obj->len); + return $obj; }else{ return false; } @@ -50,7 +50,7 @@ public function read($key){ */ public function read_header($key){ if(isset($this->memory[$key])){ - return new \Git\RawObject($obj->type,"",$obj->len); + return $this->memory[$key]; } } @@ -76,16 +76,11 @@ public function exists($key){ * * @param string $key sha1 hash. * @param Git\RawObject $object. - * @return hash + * @return bool */ - public function write($object){ - $key = $object->getId(); - $std = new \Stdclass(); - $std->data = $object->data; - $std->type = $object->type; - $std->len = $object->len; - $this->memory[$key] = $std; - return $key; + public function write(Git\RawObject $object){ + $this->memory[$object->getId()] = $object; + return true; } public function free() From e7d7b2b461623b09c8a45870ca11d7b199c1a935 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 17:21:33 +0900 Subject: [PATCH 022/300] remove phpunit & add phpt files. [misc] + added Git\Index::write() method --- .gitignore | 2 + build.xml | 4 - phpunit.xml.dist | 22 ---- src/index.c | 16 +++ src/tests/001.phpt | 9 ++ .../002_functions_git_string_to_type.phpt | 17 +++ src/tests/002_functions_hex_to_raw.phpt | 10 ++ src/tests/002_functions_raw_to_hex.phpt | 10 ++ src/tests/002_functions_type_to_string.phpt | 17 +++ src/tests/003_signature_behavior.phpt | 16 +++ src/tests/007_index.phpt | 92 ++++++++++++++ src/tests/git_repository_new.phpt | 9 ++ {tests => src/tests}/lib/MemoryBackend.php | 0 tests/GitFunctionsTest.php | 69 ----------- tests/GitIndexTest.php | 104 ---------------- tests/GitObjectManagementTest.php | 79 ------------ tests/GitSignatureTest.php | 30 ----- tests/lib/MemcachedBackend.php | 116 ------------------ 18 files changed, 198 insertions(+), 424 deletions(-) delete mode 100644 phpunit.xml.dist create mode 100644 src/tests/001.phpt create mode 100644 src/tests/002_functions_git_string_to_type.phpt create mode 100644 src/tests/002_functions_hex_to_raw.phpt create mode 100644 src/tests/002_functions_raw_to_hex.phpt create mode 100644 src/tests/002_functions_type_to_string.phpt create mode 100644 src/tests/003_signature_behavior.phpt create mode 100644 src/tests/007_index.phpt create mode 100644 src/tests/git_repository_new.phpt rename {tests => src/tests}/lib/MemoryBackend.php (100%) delete mode 100644 tests/GitFunctionsTest.php delete mode 100644 tests/GitIndexTest.php delete mode 100644 tests/GitObjectManagementTest.php delete mode 100644 tests/GitSignatureTest.php delete mode 100644 tests/lib/MemcachedBackend.php diff --git a/.gitignore b/.gitignore index 556e477bae..81a91b2d6c 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ src/Makefile* src/modules src/ltmain.sh src/*.la +src/tmp-php.ini +src/php_test_results* diff --git a/build.xml b/build.xml index 69f2e62b5c..4926d8d18b 100644 --- a/build.xml +++ b/build.xml @@ -23,8 +23,4 @@ - - - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index c327737a7d..0000000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - ./tests/ - - - diff --git a/src/index.c b/src/index.c index d10f04793a..4d15a98b3e 100644 --- a/src/index.c +++ b/src/index.c @@ -279,6 +279,21 @@ PHP_METHOD(git_index, writeTree) RETVAL_STRING(out,1); } +PHP_METHOD(git_index, write) +{ + php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + int ret = GIT_ERROR; + + if (this->index != NULL) { + ret = git_index_write(this->index); + if(ret == GIT_SUCCESS) { + RETURN_TRUE + } + } + + RETURN_FALSE; +} + /* PHP_METHOD(git_index, __construct) { @@ -343,6 +358,7 @@ PHPAPI function_entry php_git_index_methods[] = { PHP_ME(git_index, refresh, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_index, update, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_index, writeTree, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_index, write, NULL, ZEND_ACC_PUBLIC) //PHP_ME(git_index, insert, arginfo_git_index_insert, ZEND_ACC_PUBLIC) // Countable PHP_ME(git_index, count, NULL, ZEND_ACC_PUBLIC) diff --git a/src/tests/001.phpt b/src/tests/001.phpt new file mode 100644 index 0000000000..2487533dbc --- /dev/null +++ b/src/tests/001.phpt @@ -0,0 +1,9 @@ +--TEST-- +Check for php-git presence +--SKIPIF-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- + +--FILE-- +name . PHP_EOL; +echo $signature->email . PHP_EOL; +echo $signature->time->getTimestamp() . PHP_EOL; + +--EXPECT-- +Name +sample@example.com +1294147094 \ No newline at end of file diff --git a/src/tests/007_index.phpt b/src/tests/007_index.phpt new file mode 100644 index 0000000000..4c9e957071 --- /dev/null +++ b/src/tests/007_index.phpt @@ -0,0 +1,92 @@ +--TEST-- +Check Git\Index behavior +--SKIPIF-- + +--FILE-- +getIndex(); +echo ($index instanceof Git\Index) ? "true" : "false"; +echo PHP_EOL; + +file_put_contents(__DIR__ . REPOSITORY_NAME . "/example","Hello World"); +$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); +$index = $repository->getIndex(); +$index->add("example"); +$entry = $index->find("example"); +echo ($entry->path == "example") ? "ok": "couldn't add index"; +echo PHP_EOL; +$index->refresh(); + + +$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); +$index = $repository->getIndex(); +$index->add("example"); +$index->write(); +$data = file_get_contents(__DIR__ . REPOSITORY_NAME . "/.git/index"); +echo (strpos($data,"example") !== false) ? "ok" : "couldn't write index"; +echo PHP_EOL; + + + +$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); +$index = $repository->getIndex(); +$index->add("example"); +$index->remove("example"); +$index->write(); +$data = file_get_contents(__DIR__ . REPOSITORY_NAME . "/.git/index"); +echo (strpos($data,"example") === false) ? "ok" : "couldn't remove index"; +echo PHP_EOL; + + +$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); +$index = $repository->getIndex(); +$index->add("example"); +$index->write(); +$entry = $index->getEntry(0); +echo ($entry->path == "example") ? "ok" : "couldn't get specified index"; +echo PHP_EOL; + + +$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); +$index = $repository->getIndex(); +$index->add("example"); +$index->write(); +$it = $index->getIterator(); +echo ($it instanceof Iterator) ? "ok" : "couldn't get iterator instance"; + + +tmp_rmdir(__DIR__ . REPOSITORY_NAME); + +--EXPECT-- +true +ok +ok +ok +ok +ok \ No newline at end of file diff --git a/src/tests/git_repository_new.phpt b/src/tests/git_repository_new.phpt new file mode 100644 index 0000000000..2487533dbc --- /dev/null +++ b/src/tests/git_repository_new.phpt @@ -0,0 +1,9 @@ +--TEST-- +Check for php-git presence +--SKIPIF-- + +--FILE-- +assertEquals( - "WZlVWG2hw61RTz5l8QgdIBLshi0=", - base64_encode($raw), - "Hex to raw conversion" - ); - } - - public function testRawToHex() - { - $raw = base64_decode("WZlVWG2hw61RTz5l8QgdIBLshi0="); - $hex = git_raw_to_hex($raw); - - $this->assertEquals( - "599955586da1c3ad514f3e65f1081d2012ec862d", - $hex, - "Raw to hex conversion" - ); - } -} \ No newline at end of file diff --git a/tests/GitIndexTest.php b/tests/GitIndexTest.php deleted file mode 100644 index 54d8db4b25..0000000000 --- a/tests/GitIndexTest.php +++ /dev/null @@ -1,104 +0,0 @@ -getIndex(); - $this->assertInstanceOf("Git\\Index",$index); - } - - - public function testAddIndex() - { - file_put_contents(__DIR__ . self::REPOSITORY_NAME . "/example","Hello World"); - - $repository = new Repository(__DIR__ . self::REPOSITORY_NAME . "/.git"); - $index = $repository->getIndex(); - $index->add("example"); - $entry = $index->find("example"); - $this->assertEquals($entry->path, "example","couldn't add index"); - $index->refresh(); - } - - public function testWriteIndex() - { - $repository = new Repository(__DIR__ . self::REPOSITORY_NAME . "/.git"); - $index = $repository->getIndex(); - $index->add("example"); - $index->write(); - $data = file_get_contents(__DIR__ . self::REPOSITORY_NAME . "/.git/index"); - $this->assertTrue((strpos($data,"example") !== false),"couldn't write index"); - } - - public function testRemoveIndex() - { - $repository = new Repository(__DIR__ . self::REPOSITORY_NAME . "/.git"); - $index = $repository->getIndex(); - $index->add("example"); - $index->remove("example"); - $index->write(); - $data = file_get_contents(__DIR__ . self::REPOSITORY_NAME . "/.git/index"); - $this->assertTrue((strpos($data,"example") === false),"couldn't remove index"); - } - - public function testGetEntry() - { - $repository = new Repository(__DIR__ . self::REPOSITORY_NAME . "/.git"); - $index = $repository->getIndex(); - $index->add("example"); - $index->write(); - $entry = $index->getEntry(0); - $this->assertEquals($entry->path,"example","couldn't get specified index"); - } - - public function testGetIterator() - { - $repository = new Repository(__DIR__ . self::REPOSITORY_NAME . "/.git"); - $index = $repository->getIndex(); - $index->add("example"); - $index->write(); - $it = $index->getIterator(); - - $this->assertInstanceOf("Iterator",$it); - } - - public static function rmdir($dir) - { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir."/".$object) == "dir") self::rmdir($dir."/".$object); else unlink($dir."/".$object); - } - } - reset($objects); - rmdir($dir); - } - } -} \ No newline at end of file diff --git a/tests/GitObjectManagementTest.php b/tests/GitObjectManagementTest.php deleted file mode 100644 index 8395cd481d..0000000000 --- a/tests/GitObjectManagementTest.php +++ /dev/null @@ -1,79 +0,0 @@ -markTestIncomplete("getObjectで問題が発生している"); - $obj = $git->getObject("6c4a06776164f960307341033a7e5271c0b2c669"); - $this->assertEquals("6c4a06776164f960307341033a7e5271c0b2c669", $obj->getId()); - } - - /** - * @dataProvider getStringToTypeSpecifications - */ - public function testStringToType($expected, $str_type, $comment) - { - $this->assertEquals($expected, git_string_to_type($str_type), $comment); - } - - public function getStringToTypeSpecifications() - { - $array = array(); - $array[] = array(Git\Object\Commit,"commit","commit type id"); - $array[] = array(Git\Object\Blob, "blob", "blob type id"); - $array[] = array(Git\Object\Tree, "tree", "tree type id"); - $array[] = array(Git\Object\Tag, "tag", "tag type id"); - - return $array; - } - - /** - * @dataProvider getTypeToStringSpecifications - */ - public function testTypeToString($expected, $type, $comment) - { - $this->assertEquals($expected, git_type_to_string($type), $comment); - } - - public function getTypeToStringSpecifications() - { - $array = array(); - $array[] = array("commit",Git\Object\Commit,"commit type string"); - $array[] = array("blob", Git\Object\Blob, "blob type string"); - $array[] = array("tree", Git\Object\Tree, "tree type string"); - $array[] = array("tag", Git\Object\Tag, "tag type string"); - return $array; - } - -} \ No newline at end of file diff --git a/tests/GitSignatureTest.php b/tests/GitSignatureTest.php deleted file mode 100644 index cef4499ad4..0000000000 --- a/tests/GitSignatureTest.php +++ /dev/null @@ -1,30 +0,0 @@ -assertEquals("Name",$signature->name); - $this->assertEquals("sample@example.com",$signature->email); - $this->assertEquals(1294147094,$signature->time->getTimestamp()); - } - } \ No newline at end of file diff --git a/tests/lib/MemcachedBackend.php b/tests/lib/MemcachedBackend.php deleted file mode 100644 index d8cc0b72d7..0000000000 --- a/tests/lib/MemcachedBackend.php +++ /dev/null @@ -1,116 +0,0 @@ -memcached->set($key, $this->serialize($value)); - } - - protected function get($key){ - $data = $this->memcached->get($key); - if($data){ - return $this->unserialize($data); - }else{ - return false; - } - } - - public function __construct($address = "127.0.0.1", $port = 11211){ - $memcached = new \Memcached(); - $memcached->addServer($address,$port); - $this->memcached = $memcached; - - parent::__construct(); - } - - /** - * Read Data - * - * @param string $key sha1 hash. - * @return Git\RawObject - * - * Note: libgit2 usualy use internal cache. - * so this method does not call anytime. - */ - public function read($key){ - $data = $this->get($key); - if($data){ - $raw = new \Git\RawObject(); - $raw->data = $data->data; - $raw->type = $data->type; - } - - return $raw; - } - - /** - * Read Header - * - * @param string $key sha1 hash. - * @return Git\RawObject - * - */ - public function read_header($key){ - $data = $this->get($key); - if($data){ - $raw = new \Git\RawObject(); - $raw->data = null; - $raw->type = $data->type; - } - - return $raw; - } - - /** - * check specified contents. - * - * @param string $key sha1 hash. - * @return boolean - * - */ - public function exists($key){ - $data = $this->get($key); - if($data){ - return true; - }else{ - return false; - } - } - - /** - * write contents - * - * you have to write key,data,type your storage engine. - * - * @param Git\RawObject $object. - * @return string rawobject hash. - */ - public function write($object){ - $key = $object->getid(); - $this->set($key, $object); - - return $key; - } - - public function free() - { - unset($this->memcached); - } -} From 49aee81b5388558cd3ba1724bd7d41b8f57ceb6c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 4 May 2011 17:32:16 +0900 Subject: [PATCH 023/300] update LIBGIT2_VERSION. php-git is still under developement. please wait implementing. --- LIBGIT2_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION index 914a82a4bc..0b7a9d8d2d 100644 --- a/LIBGIT2_VERSION +++ b/LIBGIT2_VERSION @@ -1 +1 @@ -b153589be2b3b9aea1f90a68891564ddeb12083c \ No newline at end of file +cc3b82e376e0216c1af4ad46d24327d61e9efd99 \ No newline at end of file From db2ac895e9a36b2812e2a0514f0024a122c4a528 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 5 May 2011 02:15:11 +0900 Subject: [PATCH 024/300] temporary added Git\Commit::write() features. Git\Commit:: setAuthor(Git\Signature author) setCommitter(Git\Signature committer) setParents(array parent_ids) setTree(string tree_id) setMessage(string message) write(string update_ref = HEAD) [todo] * error_check * more simple code. --- src/commit.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 203 insertions(+), 14 deletions(-) diff --git a/src/commit.c b/src/commit.c index 7f5c83acb5..4ed4e6450b 100644 --- a/src/commit.c +++ b/src/commit.c @@ -41,6 +41,30 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_get_parent, 0, 0, 1) ZEND_ARG_INFO(0, offset) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_author, 0, 0, 1) + ZEND_ARG_INFO(0, author) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_committer, 0, 0, 1) + ZEND_ARG_INFO(0, committer) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_parents, 0, 0, 1) + ZEND_ARG_INFO(0, parents) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_message, 0, 0, 1) + ZEND_ARG_INFO(0, message) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_tree, 0, 0, 1) + ZEND_ARG_INFO(0, tree) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_write, 0, 0, 1) + ZEND_ARG_INFO(0, update_ref) +ZEND_END_ARG_INFO() + static void php_git_commit_free_storage(php_git_commit_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); @@ -138,20 +162,176 @@ PHP_METHOD(git_commit, getTree) tobj->object = tree; tobj->repository = this->repository; -/* - int r = git_tree_entrycount(tree); - int i = 0; + RETURN_ZVAL(git_tree,0,0); +} + +PHP_METHOD(git_commit, setAuthor) +{ + php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + zval *author; - for(i; i < r; i++){ - create_tree_entry_from_entry(&entry,git_tree_entry_byindex(tree,i)); - add_next_index_zval(entries, entry); + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z", &author) == FAILURE){ + return; } - add_property_zval(git_tree,"entries", entries); -*/ - RETURN_ZVAL(git_tree,0,0); + if(!instanceof_function(Z_OBJCE_P(author), git_signature_class_entry TSRMLS_CC)){ + fprintf(stderr,"Git\\Commit::setAuthor() requires Git\\Signature"); + return; + } + + add_property_zval(getThis(),"author", author); +} + +PHP_METHOD(git_commit, setCommitter) +{ + php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + zval *committer; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z", &committer) == FAILURE){ + return; + } + + if(!instanceof_function(Z_OBJCE_P(committer), git_signature_class_entry TSRMLS_CC)){ + fprintf(stderr,"Git\\Commit::setCommitter() requires Git\\Signature"); + return; + } + + add_property_zval(getThis(),"committer", committer); +} + +PHP_METHOD(git_commit, setTree) +{ + php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + char *tree; + int tree_len; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &tree,&tree_len) == FAILURE){ + return; + } + + add_property_string(getThis(),"tree", tree,1); } + +PHP_METHOD(git_commit, setParents) +{ + php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + zval *parents; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z", &parents) == FAILURE){ + return; + } + + add_property_zval(getThis(),"parents", parents); +} + +PHP_METHOD(git_commit, write) +{ + php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + git_oid oid; + php_git_signature_t *author; + php_git_signature_t *committer; + + char *update_ref = NULL; + int update_ref_len = 0; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "|s", &update_ref,&update_ref_len) == FAILURE){ + return; + } + + if(ZEND_NUM_ARGS() == 0) { + git_reference *ref; + if(git_reference_lookup(&ref,this->repository,"HEAD")==GIT_SUCCESS){ + if (git_reference_type(ref) == GIT_REF_SYMBOLIC) { + git_reference *ref2; + git_reference_resolve(&ref2,ref); + update_ref = (char *)git_reference_name(ref2); + } else { + update_ref = (char *)git_reference_name(ref); + } + } + } + + + git_oid tree_oid; + char *tree_oid_str = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"tree",sizeof("tree")-1, 0 TSRMLS_CC)); + git_oid_mkstr(&tree_oid, tree_oid_str); + + zval *z_author = zend_read_property(git_commit_class_entry, getThis(),"author",sizeof("author")-1, 0 TSRMLS_CC); + author = (php_git_signature_t *) zend_object_store_get_object(z_author TSRMLS_CC); + + zval *z_committer = zend_read_property(git_commit_class_entry, getThis(),"committer",sizeof("committer")-1, 0 TSRMLS_CC); + committer = (php_git_signature_t *) zend_object_store_get_object(z_committer TSRMLS_CC); + + zval *z_parents = zend_read_property(git_commit_class_entry, getThis(),"parents",sizeof("parents")-1, 0 TSRMLS_CC); + + int count = zend_hash_num_elements(Z_ARRVAL_P(z_parents)); + + + HashTable *array_hash = Z_ARRVAL_P(z_parents); + HashPosition pointer; + git_oid *tmp; + zval **data; + git_oid **p; + git_oid **parents = (git_oid**)calloc(count,sizeof(git_oid)); + p = parents; + + for (zend_hash_internal_pointer_reset_ex(array_hash, &pointer); + zend_hash_has_more_elements_ex(array_hash,&pointer) == SUCCESS; + zend_hash_move_forward_ex(array_hash,&pointer) + ) { + tmp = (git_oid *)malloc(sizeof(git_oid)); + zend_hash_get_current_data_ex(array_hash, (void **)&data, &pointer); + git_oid_mkstr(tmp,Z_STRVAL_PP(data)); + + *p = tmp; + p++; + } + + char *message = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"message",sizeof("message")-1, 0 TSRMLS_CC)); + git_commit_create(&oid, + this->repository, + update_ref, + author->signature, + committer->signature, + message, + &tree_oid, + count, + parents + ); + + char out[GIT_OID_HEXSZ+1]; + git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); + + int i; + for(i = 0; i < count;i++){ + free(parents[i]); + } + free(parents); + + RETVAL_STRING(out,1); +} + +PHP_METHOD(git_commit, setMessage) +{ + php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + char *message; + int message_len; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &message,&message_len) == FAILURE){ + return; + } + + add_property_string(getThis(),"message", message, 1); +} + + PHP_METHOD(git_commit, getAuthor) { zval *object = getThis(); @@ -204,6 +384,12 @@ PHP_METHOD(git_commit, getParent) PHPAPI function_entry php_git_commit_methods[] = { PHP_ME(git_commit, __construct, arginfo_git_commit__construct, ZEND_ACC_PUBLIC) + PHP_ME(git_commit, setAuthor, arginfo_git_commit_set_author, ZEND_ACC_PUBLIC) + PHP_ME(git_commit, setCommitter, arginfo_git_commit_set_committer,ZEND_ACC_PUBLIC) + PHP_ME(git_commit, setParents, arginfo_git_commit_set_parents, ZEND_ACC_PUBLIC) + PHP_ME(git_commit, setMessage, arginfo_git_commit_set_message, ZEND_ACC_PUBLIC) + PHP_ME(git_commit, setTree, arginfo_git_commit_set_tree, ZEND_ACC_PUBLIC) + PHP_ME(git_commit, write, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getTree, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getAuthor, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getCommitter, NULL, ZEND_ACC_PUBLIC) @@ -213,13 +399,16 @@ PHPAPI function_entry php_git_commit_methods[] = { {NULL, NULL, NULL} }; -void git_init_commit(TSRMLS_C) +void git_init_commit(TSRMLS_D) { - zend_class_entry git_commit_ce; - INIT_NS_CLASS_ENTRY(git_commit_ce, PHP_GIT_NS,"Commit", php_git_commit_methods); - - git_commit_class_entry = zend_register_internal_class_ex(&git_commit_ce,git_object_class_entry,NULL TSRMLS_CC); + zend_class_entry ce; + INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Commit", php_git_commit_methods); + git_commit_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_commit_class_entry->create_object = php_git_commit_new; + zend_declare_property_null(git_commit_class_entry, "author", sizeof("author")-1, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_commit_class_entry, "committer",sizeof("committer")-1, ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "parents", sizeof("parents")-1, ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "message", sizeof("message")-1, ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "tree", sizeof("tree")-1, ZEND_ACC_PUBLIC TSRMLS_CC); } \ No newline at end of file From a8af1b26de42176668d6c2a891542ce9bd807b09 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 8 May 2011 21:12:49 +0900 Subject: [PATCH 025/300] fix unfree'd walker object. --- src/repository.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repository.c b/src/repository.c index 771d3d85ec..f60a8e9197 100644 --- a/src/repository.c +++ b/src/repository.c @@ -401,7 +401,7 @@ PHP_METHOD(git_repository, getWalker) php_git_walker_t *wobj = (php_git_walker_t *) zend_object_store_get_object(walker_object TSRMLS_CC); wobj->walker = walk; - RETURN_ZVAL(walker_object,0,0); + RETURN_ZVAL(walker_object,0,1); } /* From 5d5f3da48fcc3043eab4fd58d11cb13efd06bf12 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 8 May 2011 22:48:49 +0900 Subject: [PATCH 026/300] integrate commit object structure. * Git\Walker::next() and Git\Repository::getCommit() returns same Git\Commit structure. this changes for latest Git\Commit object. * fix memory leak when using `create_signature_from_commit`. --- src/repository.c | 25 ++++++++++++++++++++----- src/signature.c | 3 ++- src/walker.c | 19 ++++++++++++++++++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/repository.c b/src/repository.c index f60a8e9197..16b36fcdea 100644 --- a/src/repository.c +++ b/src/repository.c @@ -266,7 +266,7 @@ PHP_METHOD(git_repository, getCommit) git_odb *odb; git_object *blob; git_oid oid; - char out[41] = {0}; + char out[GIT_OID_HEXSZ+1] = {0}; char *hash; int hash_len = 0; int ret = 0; @@ -305,10 +305,25 @@ PHP_METHOD(git_repository, getCommit) add_property_zval(git_commit_object,"author", author); add_property_zval(git_commit_object,"committer", committer); - RETURN_ZVAL(git_commit_object,1,0); - efree(git_commit_object); - efree(author); - efree(committer); + add_property_string_ex(git_commit_object,"tree",sizeof("tree"),git_oid_allocfmt(git_commit_tree_oid(commit)), 1 TSRMLS_CC); + + int parent_count = git_commit_parentcount(commit); + int i; + zval *parents; + + MAKE_STD_ZVAL(parents); + array_init(parents); + for (i = 0; i < parent_count; i++) { + add_next_index_string(parents,git_oid_allocfmt(git_commit_parent_oid(commit,i)),1); + } + + add_property_string_ex(git_commit_object,"message",sizeof("message"),git_commit_message(commit), 1 TSRMLS_CC); + add_property_zval_ex(git_commit_object,"parents",sizeof("parents"),parents TSRMLS_CC); + + RETVAL_ZVAL(git_commit_object,0,1); + zval_ptr_dtor(&parents); + zval_ptr_dtor(&author); + zval_ptr_dtor(&committer); }else{ RETURN_FALSE; } diff --git a/src/signature.c b/src/signature.c index 26037f662a..7b33be092f 100644 --- a/src/signature.c +++ b/src/signature.c @@ -119,7 +119,8 @@ void create_signature_from_commit(zval **signature, git_signature *sig) ZVAL_LONG(params[0],sig->when.time); call_user_function(NULL,&datetime,&method,&result,1,params TSRMLS_CC); add_property_zval(*signature, "time", datetime); - + + zval_ptr_dtor(&datetime); zval_ptr_dtor(¶ms[0]); } diff --git a/src/walker.c b/src/walker.c index fe020deb77..c35850e59f 100644 --- a/src/walker.c +++ b/src/walker.c @@ -121,6 +121,7 @@ PHP_METHOD(git_walker, push) git_revwalk_push(walker,&oid); } + PHP_METHOD(git_walker, next) { zval *git_commit_object; @@ -130,6 +131,7 @@ PHP_METHOD(git_walker, next) git_commit *commit; git_revwalk *walker; git_signature *signature; + zval *parents; php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); walker = myobj->walker; @@ -158,7 +160,22 @@ PHP_METHOD(git_walker, next) add_property_zval(git_commit_object,"author", author); add_property_zval(git_commit_object,"committer", committer); - RETURN_ZVAL(git_commit_object,0,0); + + add_property_string_ex(git_commit_object,"tree",sizeof("tree"),git_oid_allocfmt(git_commit_tree_oid(commit)), 1 TSRMLS_CC); + + int parent_count = git_commit_parentcount(commit); + int i; + + MAKE_STD_ZVAL(parents); + array_init(parents); + for (i = 0; i < parent_count; i++) { + add_next_index_string(parents,git_oid_allocfmt(git_commit_parent_oid(commit,i)),1); + } + + add_property_string_ex(git_commit_object,"message",sizeof("message"),git_commit_message(commit), 1 TSRMLS_CC); + add_property_zval_ex(git_commit_object,"parents",sizeof("parents"),parents TSRMLS_CC); + + RETURN_ZVAL(git_commit_object,0,1); } From 94dcab28e393fde9338a970e6d62f5a34cbd6a2b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 8 May 2011 22:57:11 +0900 Subject: [PATCH 027/300] fix memory leaks. --- src/index.c | 6 +++--- src/repository.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.c b/src/index.c index 4d15a98b3e..df9d727fd7 100644 --- a/src/index.c +++ b/src/index.c @@ -147,7 +147,7 @@ PHP_METHOD(git_index, find) return; } php_git_index_entry_create(&z_git_index_entry, entry); - RETURN_ZVAL(z_git_index_entry,0,0); + RETURN_ZVAL(z_git_index_entry,0,1); } PHP_METHOD(git_index, getEntry) @@ -164,7 +164,7 @@ PHP_METHOD(git_index, getEntry) entry = git_index_get(this->index,offset); php_git_index_entry_create(&git_index_entry, entry); - RETURN_ZVAL(git_index_entry,0, 0); + RETURN_ZVAL(git_index_entry,0, 1); } PHP_METHOD(git_index, add) @@ -259,7 +259,7 @@ PHP_METHOD(git_index, getIterator) php_git_index_iterator_t *obj = (php_git_index_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC); obj->index = this->index; obj->offset = 0; - RETURN_ZVAL(iterator,0,0); + RETURN_ZVAL(iterator,0,1); } PHP_METHOD(git_index, writeTree) diff --git a/src/repository.c b/src/repository.c index 16b36fcdea..6d62f1dfd9 100644 --- a/src/repository.c +++ b/src/repository.c @@ -184,8 +184,9 @@ PHP_METHOD(git_repository, getIndex) //Todo: Read from Git object. //add_property_string_ex(index_object, "path",5,index->index_file_path, 1 TSRMLS_CC); //add_property_long(index_object, "entry_count",git_index_entrycount(index)); + //zval_ptr_dtor(&index_object); - RETURN_ZVAL(index_object,0,0); + RETURN_ZVAL(index_object,0,1); } From 20a03573c4bb0f9a5b78e6b1d2bf82a0df900eef Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 8 May 2011 23:02:54 +0900 Subject: [PATCH 028/300] added timezone setting for testcase. --- src/tests/003_signature_behavior.phpt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/003_signature_behavior.phpt b/src/tests/003_signature_behavior.phpt index 8a0ef1da72..5ff17d091e 100644 --- a/src/tests/003_signature_behavior.phpt +++ b/src/tests/003_signature_behavior.phpt @@ -4,7 +4,8 @@ Check Git\Signature behavior --FILE-- name . PHP_EOL; echo $signature->email . PHP_EOL; From 7001ea499e7b0b720db0ba9f6926f7bd7ed2f7f1 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 8 May 2011 23:56:46 +0900 Subject: [PATCH 029/300] temporary commit for Git\Backend. --- src/backend.c | 24 +++++++++++++++++++----- src/repository.c | 8 ++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/backend.c b/src/backend.c index 92ce8142b5..798cbc6bc7 100644 --- a/src/backend.c +++ b/src/backend.c @@ -57,8 +57,11 @@ void php_git_backend__free(git_odb_backend *backend); static void php_git_backend_free_storage(php_git_backend_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); + if(obj->backend) { php_git_backend_internal *backend = obj->backend; + efree(obj->backend); + obj->backend = NULL; } efree(obj); } @@ -167,6 +170,7 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba php_git_backend_internal *object = (php_git_backend_internal *)_backend; char out[GIT_OID_HEXSZ+1] = {0}; git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); + int result = GIT_ERROR; zval *retval; zval *params[1]; @@ -183,12 +187,19 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "can't call read method"); - return GIT_ERROR; + result = GIT_ERROR; + goto cleanup; + } + + if(Z_BVAL_P(retval) == false) { + result = GIT_ERROR; + goto cleanup; } if(!instanceof_function(Z_OBJCE_P(retval), git_rawobject_class_entry TSRMLS_CC)){ fprintf(stderr,"read interface must return Git\\RawObject"); - return GIT_ENOTFOUND; + result = GIT_ERROR; + goto cleanup; } zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC); @@ -199,12 +210,15 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba memcpy(buffer,Z_STRVAL_P(str),Z_LVAL_P(len)); type = Z_LVAL_P(tp); size = Z_LVAL_P(len); - + + result = GIT_SUCCESS; + + +cleanup: zval_ptr_dtor(&retval); zval_ptr_dtor(¶ms[0]); zval_dtor(&func); - - return GIT_SUCCESS; + return result; } int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *oid) diff --git a/src/repository.c b/src/repository.c index 6d62f1dfd9..6a4e9fdf16 100644 --- a/src/repository.c +++ b/src/repository.c @@ -420,7 +420,7 @@ PHP_METHOD(git_repository, getWalker) RETURN_ZVAL(walker_object,0,1); } -/* + PHP_METHOD(git_repository, addAlternate) { php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); @@ -464,7 +464,7 @@ PHP_METHOD(git_repository, addBackend) odb = git_repository_database(this->repository); int ret = php_git_odb_add_backend(&odb, backend, priority); } -*/ + PHP_METHOD(git_repository, lookupRef) { @@ -683,8 +683,8 @@ PHPAPI function_entry php_git_repository_methods[] = { PHP_ME(git_repository, getWalker, arginfo_git_walker, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getTree, arginfo_git_get_tree, ZEND_ACC_PUBLIC) PHP_ME(git_repository, init, arginfo_git_init, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - //PHP_ME(git_repository, addBackend, arginfo_git_add_backend, ZEND_ACC_PUBLIC) - //PHP_ME(git_repository, addAlternate, arginfo_git_add_alternate, ZEND_ACC_PUBLIC) + PHP_ME(git_repository, addBackend, arginfo_git_add_backend, ZEND_ACC_PUBLIC) + PHP_ME(git_repository, addAlternate, arginfo_git_add_alternate, ZEND_ACC_PUBLIC) PHP_ME(git_repository, open3, arginfo_git_open3, ZEND_ACC_PUBLIC) PHP_ME(git_repository, open2, arginfo_git_open2, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getReferences, arginfo_git_get_references, ZEND_ACC_PUBLIC) From 5e7671be051404bbf9d7412d400c252ff7dc782f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 9 May 2011 09:00:08 +0900 Subject: [PATCH 030/300] Git\Repository includes Git\ODB. this changes for gracefull destroy backend. Git\Repository { Git\ODB odb{ } } * Git\Repository::getOdb() return current Git\ODB instance. work in progress :D --- src/backend.c | 2 ++ src/odb.c | 5 ++--- src/repository.c | 32 +++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/backend.c b/src/backend.c index 798cbc6bc7..b85f0b6a8f 100644 --- a/src/backend.c +++ b/src/backend.c @@ -321,4 +321,6 @@ void git_init_backend(TSRMLS_D) INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Backend", php_git_backend_methods); git_backend_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_backend_class_entry->create_object = php_git_backend_new; + + zend_declare_property_null(git_backend_class_entry, "backends",sizeof("backends")-1,ZEND_ACC_PUBLIC TSRMLS_CC); } \ No newline at end of file diff --git a/src/odb.c b/src/odb.c index 4dfa12bd0c..2e9a91f056 100644 --- a/src/odb.c +++ b/src/odb.c @@ -40,11 +40,10 @@ ZEND_END_ARG_INFO() static void php_git_odb_free_storage(php_git_odb_t *obj TSRMLS_DC) { - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - if(obj->odb){ + if(obj->odb != NULL){ obj->odb = NULL; } + zend_object_std_dtor(&obj->zo TSRMLS_CC); efree(obj); } diff --git a/src/repository.c b/src/repository.c index 6a4e9fdf16..424e0c21b0 100644 --- a/src/repository.c +++ b/src/repository.c @@ -93,7 +93,13 @@ ZEND_END_ARG_INFO() static void php_git_repository_free_storage(php_git_repository_t *obj TSRMLS_DC) { - // if added some backend. free backend before free zend_object. + zval **data; + if(zend_hash_exists(obj->zo.properties,"odb",sizeof("odb"))) { + zend_hash_find(obj->zo.properties,"odb",sizeof("odb"),(void **)&data); + zval_ptr_dtor(data); + //zend_hash_del(obj->zo.properties,"odb",sizeof("odb")); + } + if(obj->repository){ git_repository_free(obj->repository); obj->repository = NULL; @@ -339,6 +345,7 @@ PHP_METHOD(git_repository, __construct) int arg_len = 0; git_repository *repository; zval *object = getThis(); + zval *odb; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &repository_path, &arg_len) == FAILURE){ @@ -356,6 +363,13 @@ PHP_METHOD(git_repository, __construct) } myobj->repository = repository; add_property_string_ex(object, "path",sizeof("path"),(char *)repository_path, 1 TSRMLS_CC); + + MAKE_STD_ZVAL(odb); + object_init_ex(odb,git_odb_class_entry); + php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(odb TSRMLS_CC); + odb_t->odb = git_repository_database(myobj->repository); + + add_property_zval_ex(object, "odb",sizeof("odb"),odb TSRMLS_CC); }else{ myobj->repository = NULL; } @@ -673,12 +687,26 @@ PHP_METHOD(git_repository, empty) } } +PHP_METHOD(git_repository, getOdb) +{ + zval *obj = getThis(); + HashTable *hash = Z_OBJPROP_P(obj); + zval **odb; + + if(zend_hash_exists(hash,"odb",sizeof("odb"))) { + if(zend_hash_find(hash,"odb",sizeof("odb"),(void *)&odb) == SUCCESS) { + RETURN_ZVAL(*odb,0,0); + } + } +} + PHPAPI function_entry php_git_repository_methods[] = { PHP_ME(git_repository, __construct, arginfo_git_construct, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getCommit, arginfo_git_get_commit, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getObject, arginfo_git_get_object, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getIndex, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_repository, getOdb, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_repository, lookupRef, arginfo_git_lookup_ref, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getWalker, arginfo_git_walker, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getTree, arginfo_git_get_tree, ZEND_ACC_PUBLIC) @@ -699,4 +727,6 @@ void php_git_repository_init(TSRMLS_D) INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Repository", php_git_repository_methods); git_repository_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_repository_class_entry->create_object = php_git_repository_new; + + zend_declare_property_null(git_repository_class_entry, "odb",sizeof("odb")-1,ZEND_ACC_PUBLIC TSRMLS_CC); } From ab28a8d855a14a62fa19b1d8d33c8721d06f2c97 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 10 May 2011 02:01:02 +0900 Subject: [PATCH 031/300] some fix and improvements. * `Git\Backend::$backends` removed because missunderstood declaration. * fix memory leaks when using Git\Backend. Git\ODB gracefully free backends. * `Git\Repository::addBackend` transparently add backend instance to internal Git\ODB. --- src/backend.c | 2 -- src/odb.c | 26 ++++++++++++++++++++++++++ src/repository.c | 27 +++++++++++++++++++++------ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/backend.c b/src/backend.c index b85f0b6a8f..798cbc6bc7 100644 --- a/src/backend.c +++ b/src/backend.c @@ -321,6 +321,4 @@ void git_init_backend(TSRMLS_D) INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Backend", php_git_backend_methods); git_backend_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_backend_class_entry->create_object = php_git_backend_new; - - zend_declare_property_null(git_backend_class_entry, "backends",sizeof("backends")-1,ZEND_ACC_PUBLIC TSRMLS_CC); } \ No newline at end of file diff --git a/src/odb.c b/src/odb.c index 2e9a91f056..0020e39bc3 100644 --- a/src/odb.c +++ b/src/odb.c @@ -40,6 +40,24 @@ ZEND_END_ARG_INFO() static void php_git_odb_free_storage(php_git_odb_t *obj TSRMLS_DC) { + zval **data; + if(zend_hash_find(obj->zo.properties,"backends",sizeof("backends"),(void **)&data) == SUCCESS) { + int count = zend_hash_num_elements(Z_ARRVAL_P(*data)); + HashTable *array_hash = Z_ARRVAL_P(*data); + HashPosition pointer; + zval **val; + + for (zend_hash_internal_pointer_reset_ex(array_hash, &pointer); + zend_hash_has_more_elements_ex(array_hash,&pointer) == SUCCESS; + zend_hash_move_forward_ex(array_hash,&pointer) + ) { + zend_hash_get_current_data_ex(array_hash, (void **)&val, &pointer); + zval_ptr_dtor(val); + } + + zval_ptr_dtor(data); + } + if(obj->odb != NULL){ obj->odb = NULL; } @@ -70,11 +88,17 @@ PHP_METHOD(git_odb, __construct) { php_git_odb_t *this = (php_git_odb_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_odb *odb; + zval *backends; + int ret = 0; ret = git_odb_new(&this->odb); if(ret != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create Git\\ODB"); } + + MAKE_STD_ZVAL(backends); + array_init(backends); + add_property_zval_ex(getThis(),"backends",sizeof("backends"),backends TSRMLS_CC); } @@ -162,4 +186,6 @@ void git_init_odb(TSRMLS_D) INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"ODB", php_git_odb_methods); git_odb_class_entry = zend_register_internal_class_ex(&ce, git_odb_class_entry,NULL TSRMLS_CC); git_odb_class_entry->create_object = php_git_odb_new; + + zend_declare_property_null(git_odb_class_entry, "backends",sizeof("backends")-1,ZEND_ACC_PUBLIC TSRMLS_CC); } \ No newline at end of file diff --git a/src/repository.c b/src/repository.c index 424e0c21b0..566fc85e6f 100644 --- a/src/repository.c +++ b/src/repository.c @@ -94,8 +94,7 @@ ZEND_END_ARG_INFO() static void php_git_repository_free_storage(php_git_repository_t *obj TSRMLS_DC) { zval **data; - if(zend_hash_exists(obj->zo.properties,"odb",sizeof("odb"))) { - zend_hash_find(obj->zo.properties,"odb",sizeof("odb"),(void **)&data); + if(zend_hash_find(obj->zo.properties,"odb",sizeof("odb"),(void **)&data) == SUCCESS) { zval_ptr_dtor(data); //zend_hash_del(obj->zo.properties,"odb",sizeof("odb")); } @@ -363,12 +362,16 @@ PHP_METHOD(git_repository, __construct) } myobj->repository = repository; add_property_string_ex(object, "path",sizeof("path"),(char *)repository_path, 1 TSRMLS_CC); - + MAKE_STD_ZVAL(odb); object_init_ex(odb,git_odb_class_entry); php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(odb TSRMLS_CC); odb_t->odb = git_repository_database(myobj->repository); + + zval *backends; + array_init(backends); + add_property_zval_ex(odb,"backends",sizeof("backends"),backends TSRMLS_CC); add_property_zval_ex(object, "odb",sizeof("odb"),odb TSRMLS_CC); }else{ myobj->repository = NULL; @@ -464,6 +467,7 @@ PHP_METHOD(git_repository, addBackend) zval *backend; git_odb *odb; git_odb_backend *odb_backend; + zval **data; int priority = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){ @@ -474,9 +478,20 @@ PHP_METHOD(git_repository, addBackend) "parameter does not extends Git\\Backend"); return; } - - odb = git_repository_database(this->repository); - int ret = php_git_odb_add_backend(&odb, backend, priority); + + if(zend_hash_exists(Z_OBJPROP_P(getThis()),"odb",sizeof("odb"))) { + if (zend_hash_find(Z_OBJPROP_P(getThis()),"odb",sizeof("odb"),(void **)&data) == SUCCESS) { + php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(*data TSRMLS_CC); + php_git_odb_add_backend(&odb_t->odb,backend, priority); + + zval **hash; + if (zend_hash_find(Z_OBJPROP_P(*data),"backends",sizeof("backends"),(void **)&hash) == SUCCESS) { + add_next_index_zval(*hash,backend); + } + } else { + RETURN_FALSE; + } + } } From edfe8bfbe4ec25b64d8a83ee8871564480d9b06b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 10 May 2011 08:40:54 +0900 Subject: [PATCH 032/300] fix memory leak when calling Git\Repository::Init. and, Git\Repository::Init returns correct Git\Repository Object (including Git\ODB) --- src/repository.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/repository.c b/src/repository.c index 566fc85e6f..329d5a12a3 100644 --- a/src/repository.c +++ b/src/repository.c @@ -99,7 +99,7 @@ static void php_git_repository_free_storage(php_git_repository_t *obj TSRMLS_DC) //zend_hash_del(obj->zo.properties,"odb",sizeof("odb")); } - if(obj->repository){ + if(obj->repository != NULL){ git_repository_free(obj->repository); obj->repository = NULL; } @@ -152,9 +152,22 @@ PHP_METHOD(git_repository, init) object_init_ex(obj, git_repository_class_entry); php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(obj TSRMLS_CC); myobj->repository = repository; - add_property_string_ex(obj, "path",sizeof("path"),path, 1 TSRMLS_CC); - RETURN_ZVAL(obj, 1, 1); + + + zval *odb; + MAKE_STD_ZVAL(odb); + object_init_ex(odb,git_odb_class_entry); + php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(odb TSRMLS_CC); + odb_t->odb = git_repository_database(myobj->repository); + + zval *backends; + MAKE_STD_ZVAL(backends); + array_init(backends); + add_property_zval_ex(odb,"backends",sizeof("backends"),backends TSRMLS_CC); + add_property_zval_ex(obj, "odb",sizeof("odb"),odb TSRMLS_CC); + + RETVAL_ZVAL(obj, 1, 1); } PHP_METHOD(git_repository, getIndex) From eee55e9d188a90847971c5729c5f40d033b6aab7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 11 May 2011 08:55:59 +0900 Subject: [PATCH 033/300] change Git\Repository::$odb visibility to protected. i'll change proper object properties. --- src/repository.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/repository.c b/src/repository.c index 329d5a12a3..961fecaf9a 100644 --- a/src/repository.c +++ b/src/repository.c @@ -94,10 +94,14 @@ ZEND_END_ARG_INFO() static void php_git_repository_free_storage(php_git_repository_t *obj TSRMLS_DC) { zval **data; - if(zend_hash_find(obj->zo.properties,"odb",sizeof("odb"),(void **)&data) == SUCCESS) { + char *prop_name; + int prop_name_len; + zend_mangle_property_name(&prop_name, &prop_name_len, "*", 1, "odb", sizeof("odb"), 0); + if(zend_hash_find(obj->zo.properties,prop_name,prop_name_len,(void **)&data) == SUCCESS) { zval_ptr_dtor(data); //zend_hash_del(obj->zo.properties,"odb",sizeof("odb")); } + efree(prop_name); if(obj->repository != NULL){ git_repository_free(obj->repository); @@ -165,7 +169,12 @@ PHP_METHOD(git_repository, init) MAKE_STD_ZVAL(backends); array_init(backends); add_property_zval_ex(odb,"backends",sizeof("backends"),backends TSRMLS_CC); - add_property_zval_ex(obj, "odb",sizeof("odb"),odb TSRMLS_CC); + + char *prop_name; + int prop_name_len; + zend_mangle_property_name(&prop_name, &prop_name_len, "*", 1, "odb", sizeof("odb"), 0); + add_property_zval_ex(obj, prop_name,prop_name_len,odb TSRMLS_CC); + efree(prop_name); RETVAL_ZVAL(obj, 1, 1); } @@ -385,7 +394,14 @@ PHP_METHOD(git_repository, __construct) zval *backends; array_init(backends); add_property_zval_ex(odb,"backends",sizeof("backends"),backends TSRMLS_CC); - add_property_zval_ex(object, "odb",sizeof("odb"),odb TSRMLS_CC); + + char *prop_name; + long prop_len = 0; + + zend_mangle_property_name(&prop_name, &prop_len, "*", 1, "odb", sizeof("odb"), 0); + HashTable *prop = Z_OBJPROP_P(object); + zend_hash_update(prop,prop_name,prop_len, &odb, sizeof(zval *), NULL); + efree(prop_name); }else{ myobj->repository = NULL; } @@ -720,12 +736,15 @@ PHP_METHOD(git_repository, getOdb) zval *obj = getThis(); HashTable *hash = Z_OBJPROP_P(obj); zval **odb; - - if(zend_hash_exists(hash,"odb",sizeof("odb"))) { - if(zend_hash_find(hash,"odb",sizeof("odb"),(void *)&odb) == SUCCESS) { - RETURN_ZVAL(*odb,0,0); + char *prop_name; + int prop_name_len; + zend_mangle_property_name(&prop_name, &prop_name_len, "*", 1, "odb", sizeof("odb"), 0); + if(zend_hash_exists(hash,prop_name,prop_name_len)) { + if(zend_hash_find(hash,prop_name,prop_name_len,(void *)&odb) == SUCCESS) { + RETVAL_ZVAL(*odb,0,0); } } + efree(prop_name); } @@ -756,5 +775,5 @@ void php_git_repository_init(TSRMLS_D) git_repository_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_repository_class_entry->create_object = php_git_repository_new; - zend_declare_property_null(git_repository_class_entry, "odb",sizeof("odb")-1,ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_repository_class_entry, "odb",sizeof("odb")-1,ZEND_ACC_PROTECTED TSRMLS_CC); } From 4cd75708ff162d3335f882bb6d47198993f94128 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 15 May 2011 13:53:10 +0900 Subject: [PATCH 034/300] change Git\Repository::$path visibility to protected. --- src/repository.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/repository.c b/src/repository.c index 961fecaf9a..36824fa0cf 100644 --- a/src/repository.c +++ b/src/repository.c @@ -93,21 +93,11 @@ ZEND_END_ARG_INFO() static void php_git_repository_free_storage(php_git_repository_t *obj TSRMLS_DC) { - zval **data; - char *prop_name; - int prop_name_len; - zend_mangle_property_name(&prop_name, &prop_name_len, "*", 1, "odb", sizeof("odb"), 0); - if(zend_hash_find(obj->zo.properties,prop_name,prop_name_len,(void **)&data) == SUCCESS) { - zval_ptr_dtor(data); - //zend_hash_del(obj->zo.properties,"odb",sizeof("odb")); - } - efree(prop_name); - + zend_object_std_dtor(&obj->zo TSRMLS_CC); if(obj->repository != NULL){ git_repository_free(obj->repository); obj->repository = NULL; } - zend_object_std_dtor(&obj->zo TSRMLS_CC); efree(obj); } @@ -383,7 +373,15 @@ PHP_METHOD(git_repository, __construct) RETURN_FALSE; } myobj->repository = repository; - add_property_string_ex(object, "path",sizeof("path"),(char *)repository_path, 1 TSRMLS_CC); + + zval *path; + MAKE_STD_ZVAL(path); + char *p_name; + long p_len = 0; + zend_mangle_property_name(&p_name,&p_len,"*",1,"path",sizeof("path"),0); + ZVAL_STRING(path,git_repository_path(repository),1); + zend_hash_update(Z_OBJPROP_P(object),p_name,p_len,&path,sizeof(zval *),NULL); + efree(p_name); MAKE_STD_ZVAL(odb); object_init_ex(odb,git_odb_class_entry); @@ -392,6 +390,7 @@ PHP_METHOD(git_repository, __construct) zval *backends; + MAKE_STD_ZVAL(backends); array_init(backends); add_property_zval_ex(odb,"backends",sizeof("backends"),backends TSRMLS_CC); @@ -701,7 +700,16 @@ PHP_METHOD(git_repository, open2) RETURN_FALSE; } - add_property_string_ex(getThis(), "path",sizeof("path"),(char *)git_dir, 1 TSRMLS_CC); + + zval *path; + MAKE_STD_ZVAL(path); + char *p_name; + long p_len = 0; + zend_mangle_property_name(&p_name,&p_len,"*",1,"path",sizeof("path"),0); + ZVAL_STRING(path,git_dir,1); + zend_hash_update(Z_OBJPROP_P(getThis()),p_name,p_len,&path,sizeof(zval *),NULL); + efree(p_name); + this->repository = repository; RETURN_TRUE; } @@ -776,4 +784,5 @@ void php_git_repository_init(TSRMLS_D) git_repository_class_entry->create_object = php_git_repository_new; zend_declare_property_null(git_repository_class_entry, "odb",sizeof("odb")-1,ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(git_repository_class_entry, "path",sizeof("path")-1,ZEND_ACC_PROTECTED TSRMLS_CC); } From 318033d0a7399c9b08cd6099529d37d3280c350f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 15 May 2011 16:01:59 +0900 Subject: [PATCH 035/300] little odb tweaks. --- src/odb.c | 20 +------- src/php_git.c | 71 ++++++++++++++++++++++++++ src/php_git.h | 6 +++ src/repository.c | 129 +++++++++++------------------------------------ 4 files changed, 108 insertions(+), 118 deletions(-) diff --git a/src/odb.c b/src/odb.c index 0020e39bc3..5c0791b67d 100644 --- a/src/odb.c +++ b/src/odb.c @@ -40,24 +40,6 @@ ZEND_END_ARG_INFO() static void php_git_odb_free_storage(php_git_odb_t *obj TSRMLS_DC) { - zval **data; - if(zend_hash_find(obj->zo.properties,"backends",sizeof("backends"),(void **)&data) == SUCCESS) { - int count = zend_hash_num_elements(Z_ARRVAL_P(*data)); - HashTable *array_hash = Z_ARRVAL_P(*data); - HashPosition pointer; - zval **val; - - for (zend_hash_internal_pointer_reset_ex(array_hash, &pointer); - zend_hash_has_more_elements_ex(array_hash,&pointer) == SUCCESS; - zend_hash_move_forward_ex(array_hash,&pointer) - ) { - zend_hash_get_current_data_ex(array_hash, (void **)&val, &pointer); - zval_ptr_dtor(val); - } - - zval_ptr_dtor(data); - } - if(obj->odb != NULL){ obj->odb = NULL; } @@ -187,5 +169,5 @@ void git_init_odb(TSRMLS_D) git_odb_class_entry = zend_register_internal_class_ex(&ce, git_odb_class_entry,NULL TSRMLS_CC); git_odb_class_entry->create_object = php_git_odb_new; - zend_declare_property_null(git_odb_class_entry, "backends",sizeof("backends")-1,ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_odb_class_entry, "backends",sizeof("backends")-1,ZEND_ACC_PROTECTED TSRMLS_CC); } \ No newline at end of file diff --git a/src/php_git.c b/src/php_git.c index bda0ef8e90..84eb4f60c1 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -28,6 +28,77 @@ #include #include +zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC) +{ + zval **data; + char *key; + long *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 (zval *)*data; +} + +int php_git_add_protected_property_string_ex(zval *object, char *name, int name_length, char *data, zend_bool duplicate TSRMLS_DC) +{ + zval *tmp; + char *key; + long *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_git_add_protected_property_zval_ex(zval *object, char *name, int name_length, zval *data TSRMLS_DC) +{ + char *key; + long *length; + zend_mangle_property_name(&key,&length,"*",1,name,name_length,0); + zend_hash_update(Z_OBJPROP_P(object),key,length,&data,sizeof(zval *),NULL); + efree(key); + + return SUCCESS; +} + +void php_git_throw_exception(zend_class_entry *exception,int error_code, char *message TSRMLS_DC) +{ + if(exception == NULL) { + //will be fix soon. + exception = spl_ce_RuntimeException; + } + + if(message != NULL) { + zend_throw_exception_ex(exception, 0 TSRMLS_CC, message); + } else { + zend_throw_exception_ex(exception, 0 TSRMLS_CC, git_strerror(error_code)); + } +} + +int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC) +{ + zval *backends; + + MAKE_STD_ZVAL(*object); + object_init_ex(*object,git_odb_class_entry); + php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(*object TSRMLS_CC); + odb_t->odb = database; + + MAKE_STD_ZVAL(backends); + array_init(backends); + + php_git_add_protected_property_zval_ex(*object,"backends",sizeof("backends"),backends TSRMLS_CC); + + return SUCCESS; +} + + PHPAPI zend_class_entry *git_class_entry; ZEND_BEGIN_ARG_INFO_EX(arginfo_git_string_to_type, 0, 0, 1) diff --git a/src/php_git.h b/src/php_git.h index 2600b8b4c6..4fd52416bf 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -45,6 +45,12 @@ extern zend_module_entry git_module_entry; #define phpext_git_ptr &git_module_entry; #define PHP_GIT_NS "Git" +void php_git_throw_exception(zend_class_entry *exception,int error_code, char *message TSRMLS_DC); +int php_git_add_protected_property_zval_ex(zval *object, char *name, int name_length, zval *data TSRMLS_DC); +int php_git_add_protected_property_string_ex(zval *object, char *name, int name_length, char *data, zend_bool duplicate TSRMLS_DC); +int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC); +zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); + extern PHPAPI zend_class_entry *git_class_entry; extern PHPAPI zend_class_entry *git_reference_class_entry; extern PHPAPI zend_class_entry *git_reference_manager_class_entry; diff --git a/src/repository.c b/src/repository.c index 36824fa0cf..a90a8b5213 100644 --- a/src/repository.c +++ b/src/repository.c @@ -124,21 +124,20 @@ zend_object_value php_git_repository_new(zend_class_entry *ce TSRMLS_DC) PHP_METHOD(git_repository, init) { git_repository *repository; + zval *obj,*backends,*odb; char *path = NULL; int path_len = 0; int is_bare = 0; int ret; - zval *obj; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"sl", &path, &path_len, &is_bare) == FAILURE){ return; } - int suc = git_repository_init(&repository,path,is_bare); - - if(suc != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't create repository\n"); + int error = git_repository_init(&repository,path,is_bare); + if(error != GIT_SUCCESS){ + php_git_throw_exception(NULL,error,NULL TSRMLS_CC); return; } @@ -146,27 +145,12 @@ PHP_METHOD(git_repository, init) object_init_ex(obj, git_repository_class_entry); php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(obj TSRMLS_CC); myobj->repository = repository; - add_property_string_ex(obj, "path",sizeof("path"),path, 1 TSRMLS_CC); - - - zval *odb; - MAKE_STD_ZVAL(odb); - object_init_ex(odb,git_odb_class_entry); - php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(odb TSRMLS_CC); - odb_t->odb = git_repository_database(myobj->repository); - - zval *backends; - MAKE_STD_ZVAL(backends); - array_init(backends); - add_property_zval_ex(odb,"backends",sizeof("backends"),backends TSRMLS_CC); - char *prop_name; - int prop_name_len; - zend_mangle_property_name(&prop_name, &prop_name_len, "*", 1, "odb", sizeof("odb"), 0); - add_property_zval_ex(obj, prop_name,prop_name_len,odb TSRMLS_CC); - efree(prop_name); + php_git_odb_init(&odb, git_repository_database(repository) TSRMLS_CC); + php_git_add_protected_property_zval_ex(obj,"odb",sizeof("odb"),odb TSRMLS_CC); + php_git_add_protected_property_string_ex(obj,"path",sizeof("path"),path,1 TSRMLS_CC); - RETVAL_ZVAL(obj, 1, 1); + RETVAL_ZVAL(obj, 0, 1); } PHP_METHOD(git_repository, getIndex) @@ -174,28 +158,23 @@ PHP_METHOD(git_repository, getIndex) zval *object = getThis(); git_repository *repository; git_index *index; - zval *index_object; - int ret = 0; + int error = 0; php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); + error = git_repository_index(&index,myobj->repository); - ret = git_repository_index(&index,myobj->repository); - - if (ret == GIT_EBAREINDEX) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "The index file is not backed up by an existing repository."); - RETURN_FALSE; - } else if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "specified index cannot be opend"); + if (error != GIT_SUCCESS) { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,git_strerror(error)); RETURN_FALSE; } + MAKE_STD_ZVAL(index_object); object_init_ex(index_object, git_index_class_entry); php_git_index_t *iobj = (php_git_index_t *) zend_object_store_get_object(index_object TSRMLS_CC); iobj->index = index; - git_index_read(index); //Todo: Read from Git object. @@ -257,7 +236,7 @@ PHP_METHOD(git_repository, getObject) void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repository *repository) { TSRMLS_FETCH(); - char buf[41] = {0}; + char buf[GIT_OID_HEXSZ+1] = {0}; const git_oid *oid; MAKE_STD_ZVAL(*object); object_init_ex(*object, git_tree_entry_class_entry); @@ -266,15 +245,13 @@ void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repo entry_obj->entry = entry; entry_obj->repository = repository; oid = git_tree_entry_id(entry); - git_oid_to_string(buf,41,oid); + git_oid_to_string(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, "mode", git_tree_entry_attributes(entry)); } - - PHP_METHOD(git_repository, getCommit) { zval *object = getThis(); @@ -348,7 +325,6 @@ PHP_METHOD(git_repository, getCommit) } } - PHP_METHOD(git_repository, __construct) { const char *repository_path = NULL; @@ -356,7 +332,7 @@ PHP_METHOD(git_repository, __construct) int arg_len = 0; git_repository *repository; zval *object = getThis(); - zval *odb; + zval *odb, *backends; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &repository_path, &arg_len) == FAILURE){ @@ -368,39 +344,14 @@ PHP_METHOD(git_repository, __construct) if(arg_len > 0){ ret = git_repository_open(&repository,repository_path); if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified repository does not exist."); + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,git_strerror(ret)); RETURN_FALSE; } myobj->repository = repository; - - zval *path; - MAKE_STD_ZVAL(path); - char *p_name; - long p_len = 0; - zend_mangle_property_name(&p_name,&p_len,"*",1,"path",sizeof("path"),0); - ZVAL_STRING(path,git_repository_path(repository),1); - zend_hash_update(Z_OBJPROP_P(object),p_name,p_len,&path,sizeof(zval *),NULL); - efree(p_name); - - MAKE_STD_ZVAL(odb); - object_init_ex(odb,git_odb_class_entry); - php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(odb TSRMLS_CC); - odb_t->odb = git_repository_database(myobj->repository); - - - zval *backends; - MAKE_STD_ZVAL(backends); - array_init(backends); - add_property_zval_ex(odb,"backends",sizeof("backends"),backends TSRMLS_CC); - - char *prop_name; - long prop_len = 0; - - zend_mangle_property_name(&prop_name, &prop_len, "*", 1, "odb", sizeof("odb"), 0); - HashTable *prop = Z_OBJPROP_P(object); - zend_hash_update(prop,prop_name,prop_len, &odb, sizeof(zval *), NULL); - efree(prop_name); + + php_git_odb_init(&odb, git_repository_database(myobj->repository) TSRMLS_CC); + php_git_add_protected_property_zval_ex(object,"odb",sizeof("odb"),odb TSRMLS_CC); + php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository),1 TSRMLS_CC); }else{ myobj->repository = NULL; } @@ -674,10 +625,8 @@ PHP_METHOD(git_repository, open3) PHP_METHOD(git_repository, open2) { php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *git_dir; - char *git_object_directory; - char *git_index_file; - char *git_work_tree; + char *git_dir,*git_object_directory,*git_index_file,*git_work_tree; + int git_dir_len = 0; int git_object_directory_len = 0; int git_index_file_len = 0; @@ -696,30 +645,22 @@ PHP_METHOD(git_repository, open2) int ret = git_repository_open2(&repository,git_dir, git_object_directory, git_index_file, git_work_tree); if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't open specified directories"); + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,git_strerror(ret)); RETURN_FALSE; } - zval *path; - MAKE_STD_ZVAL(path); - char *p_name; - long p_len = 0; - zend_mangle_property_name(&p_name,&p_len,"*",1,"path",sizeof("path"),0); - ZVAL_STRING(path,git_dir,1); - zend_hash_update(Z_OBJPROP_P(getThis()),p_name,p_len,&path,sizeof(zval *),NULL); - efree(p_name); - + php_git_add_protected_property_string_ex(getThis(),"path",sizeof("path"),git_dir,1 TSRMLS_CC); this->repository = repository; RETURN_TRUE; } PHP_METHOD(git_repository, getWorkdir) { - php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - + php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + char *git_workdir; + if(this->repository != NULL) { - char *git_workdir; git_workdir = git_repository_workdir(this->repository); RETVAL_STRING(git_workdir,1); } @@ -741,18 +682,8 @@ PHP_METHOD(git_repository, empty) PHP_METHOD(git_repository, getOdb) { - zval *obj = getThis(); - HashTable *hash = Z_OBJPROP_P(obj); - zval **odb; - char *prop_name; - int prop_name_len; - zend_mangle_property_name(&prop_name, &prop_name_len, "*", 1, "odb", sizeof("odb"), 0); - if(zend_hash_exists(hash,prop_name,prop_name_len)) { - if(zend_hash_find(hash,prop_name,prop_name_len,(void *)&odb) == SUCCESS) { - RETVAL_ZVAL(*odb,0,0); - } - } - efree(prop_name); + zval *odb = php_git_read_protected_property(git_repository_class_entry,getThis(),"odb",sizeof("odb") TSRMLS_CC); + RETVAL_ZVAL(odb,0,0); } From 697880b416d88c28cb26d57995ebf5552ad6550b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 15 May 2011 18:45:03 +0900 Subject: [PATCH 036/300] fix undefined `false` --- src/backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend.c b/src/backend.c index 798cbc6bc7..39980f7b62 100644 --- a/src/backend.c +++ b/src/backend.c @@ -191,7 +191,7 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba goto cleanup; } - if(Z_BVAL_P(retval) == false) { + if(Z_BVAL_P(retval) == 0) { result = GIT_ERROR; goto cleanup; } From ba7d62308255bb7d5710b4c03cfa9d4f57129fb1 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 15 May 2011 18:46:15 +0900 Subject: [PATCH 037/300] change Git\Commit visibilities to protected. --- src/commit.c | 10 +++++----- src/php_git.c | 33 +++++++++++++++++++++++++++++++- src/php_git.h | 1 + src/repository.c | 49 +++++------------------------------------------- src/walker.c | 34 +-------------------------------- 5 files changed, 44 insertions(+), 83 deletions(-) diff --git a/src/commit.c b/src/commit.c index 4ed4e6450b..9d9ea9aca0 100644 --- a/src/commit.c +++ b/src/commit.c @@ -406,9 +406,9 @@ void git_init_commit(TSRMLS_D) git_commit_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_commit_class_entry->create_object = php_git_commit_new; - zend_declare_property_null(git_commit_class_entry, "author", sizeof("author")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "committer",sizeof("committer")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "parents", sizeof("parents")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "message", sizeof("message")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "tree", sizeof("tree")-1, ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "author", sizeof("author")-1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "committer",sizeof("committer")-1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "parents", sizeof("parents")-1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "message", sizeof("message")-1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(git_commit_class_entry, "tree", sizeof("tree")-1, ZEND_ACC_PROTECTED TSRMLS_CC); } \ No newline at end of file diff --git a/src/php_git.c b/src/php_git.c index 84eb4f60c1..c1d848843f 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -63,7 +63,7 @@ int php_git_add_protected_property_zval_ex(zval *object, char *name, int name_le zend_mangle_property_name(&key,&length,"*",1,name,name_length,0); zend_hash_update(Z_OBJPROP_P(object),key,length,&data,sizeof(zval *),NULL); efree(key); - + return SUCCESS; } @@ -98,6 +98,37 @@ int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC) return SUCCESS; } +void php_git_commit_init(zval **object, git_commit *commit, git_repository *repository TSRMLS_DC) +{ + zval *author, *committer; + + MAKE_STD_ZVAL(*object); + object_init_ex(*object,git_commit_class_entry); + + create_signature_from_commit(&author, git_commit_author(commit)); + create_signature_from_commit(&committer, git_commit_committer(commit)); + + php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(*object TSRMLS_CC); + cobj->object = commit; + cobj->repository = repository; + + + int parent_count = git_commit_parentcount(commit); + int i; + zval *parents; + MAKE_STD_ZVAL(parents); + array_init(parents); + for (i = 0; i < parent_count; i++) { + add_next_index_string(parents,git_oid_allocfmt(git_commit_parent_oid(commit,i)),1); + } + + php_git_add_protected_property_zval_ex(*object,"author",sizeof("author"),author TSRMLS_CC); + php_git_add_protected_property_zval_ex(*object,"committer",sizeof("committer"),committer TSRMLS_CC); + php_git_add_protected_property_string_ex(*object,"tree",sizeof("tree"),git_oid_allocfmt(git_commit_tree_oid(commit)),1 TSRMLS_CC); + php_git_add_protected_property_string_ex(*object,"message",sizeof("message"),git_commit_message(commit), 1 TSRMLS_CC); + php_git_add_protected_property_zval_ex(*object,"parents",sizeof("parents"),parents TSRMLS_CC); +} + PHPAPI zend_class_entry *git_class_entry; diff --git a/src/php_git.h b/src/php_git.h index 4fd52416bf..79f85058fb 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -50,6 +50,7 @@ int php_git_add_protected_property_zval_ex(zval *object, char *name, int name_le int php_git_add_protected_property_string_ex(zval *object, char *name, int name_length, char *data, zend_bool duplicate TSRMLS_DC); int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC); zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); +void php_git_commit_init(zval **object, git_commit *commit, git_repository *repository TSRMLS_DC); extern PHPAPI zend_class_entry *git_class_entry; extern PHPAPI zend_class_entry *git_reference_class_entry; diff --git a/src/repository.c b/src/repository.c index a90a8b5213..69ec63d601 100644 --- a/src/repository.c +++ b/src/repository.c @@ -254,10 +254,10 @@ void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repo PHP_METHOD(git_repository, getCommit) { - zval *object = getThis(); + php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); zval *git_commit_object; - php_git_tree_entry_t *entry_obj; git_repository *repository; + git_odb *odb; git_object *blob; git_oid oid; @@ -272,53 +272,14 @@ PHP_METHOD(git_repository, getCommit) } git_oid_mkstr(&oid, hash); - - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); - repository = myobj->repository; - odb = git_repository_database(repository); - + odb = git_repository_database(this->repository); if(!git_odb_exists(odb,&oid)){ RETURN_FALSE; }else{ - ret = git_object_lookup((git_object **)&blob, repository,&oid , GIT_OBJ_COMMIT); - + ret = git_object_lookup((git_object **)&blob, this->repository,&oid , GIT_OBJ_COMMIT); if(ret == GIT_SUCCESS){ - zval *author; - zval *committer; - git_commit *commit = (git_commit *)blob; - - create_signature_from_commit(&author, git_commit_author(commit)); - create_signature_from_commit(&committer, git_commit_committer(commit)); - - MAKE_STD_ZVAL(git_commit_object); - object_init_ex(git_commit_object,git_commit_class_entry); - - php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(git_commit_object TSRMLS_CC); - cobj->object = commit; - cobj->repository = repository; - - add_property_zval(git_commit_object,"author", author); - add_property_zval(git_commit_object,"committer", committer); - - add_property_string_ex(git_commit_object,"tree",sizeof("tree"),git_oid_allocfmt(git_commit_tree_oid(commit)), 1 TSRMLS_CC); - - int parent_count = git_commit_parentcount(commit); - int i; - zval *parents; - - MAKE_STD_ZVAL(parents); - array_init(parents); - for (i = 0; i < parent_count; i++) { - add_next_index_string(parents,git_oid_allocfmt(git_commit_parent_oid(commit,i)),1); - } - - add_property_string_ex(git_commit_object,"message",sizeof("message"),git_commit_message(commit), 1 TSRMLS_CC); - add_property_zval_ex(git_commit_object,"parents",sizeof("parents"),parents TSRMLS_CC); - + php_git_commit_init(&git_commit_object, (git_commit*)blob, this->repository TSRMLS_CC); RETVAL_ZVAL(git_commit_object,0,1); - zval_ptr_dtor(&parents); - zval_ptr_dtor(&author); - zval_ptr_dtor(&committer); }else{ RETURN_FALSE; } diff --git a/src/walker.c b/src/walker.c index c35850e59f..975f3347b8 100644 --- a/src/walker.c +++ b/src/walker.c @@ -141,39 +141,7 @@ PHP_METHOD(git_walker, next) RETURN_FALSE; } git_object_lookup((git_object **)&commit, git_revwalk_repository(walker), &oid, GIT_OBJ_COMMIT); - - MAKE_STD_ZVAL(git_commit_object); - object_init_ex(git_commit_object,git_commit_class_entry); - - zval *author; - zval *committer; - - create_signature_from_commit(&author, git_commit_author(commit)); - create_signature_from_commit(&committer, git_commit_committer(commit)); - - MAKE_STD_ZVAL(git_commit_object); - object_init_ex(git_commit_object,git_commit_class_entry); - - php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(git_commit_object TSRMLS_CC); - cobj->object = commit; - - add_property_zval(git_commit_object,"author", author); - add_property_zval(git_commit_object,"committer", committer); - - - add_property_string_ex(git_commit_object,"tree",sizeof("tree"),git_oid_allocfmt(git_commit_tree_oid(commit)), 1 TSRMLS_CC); - - int parent_count = git_commit_parentcount(commit); - int i; - - MAKE_STD_ZVAL(parents); - array_init(parents); - for (i = 0; i < parent_count; i++) { - add_next_index_string(parents,git_oid_allocfmt(git_commit_parent_oid(commit,i)),1); - } - - add_property_string_ex(git_commit_object,"message",sizeof("message"),git_commit_message(commit), 1 TSRMLS_CC); - add_property_zval_ex(git_commit_object,"parents",sizeof("parents"),parents TSRMLS_CC); + php_git_commit_init(&git_commit_object, (git_commit*)commit, git_revwalk_repository(walker) TSRMLS_CC); RETURN_ZVAL(git_commit_object,0,1); } From b28bc143e3fb09069ea006f5a3f00dcb76f20f02 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 15 May 2011 20:50:31 +0900 Subject: [PATCH 038/300] fix memory leak. added Git\Tree\Entry::toHeader() --- src/commit.c | 2 +- src/repository.c | 2 +- src/tree.c | 6 +++--- src/tree_entry.c | 31 ++++++++++++++++++++++++++++--- src/tree_iterator.c | 2 +- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/commit.c b/src/commit.c index 9d9ea9aca0..45dae07247 100644 --- a/src/commit.c +++ b/src/commit.c @@ -162,7 +162,7 @@ PHP_METHOD(git_commit, getTree) tobj->object = tree; tobj->repository = this->repository; - RETURN_ZVAL(git_tree,0,0); + RETURN_ZVAL(git_tree,0,1); } PHP_METHOD(git_commit, setAuthor) diff --git a/src/repository.c b/src/repository.c index 69ec63d601..5f0a6a6927 100644 --- a/src/repository.c +++ b/src/repository.c @@ -483,7 +483,7 @@ PHP_METHOD(git_repository, lookupRef) git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); - RETURN_ZVAL(ref,0,0); + RETURN_ZVAL(ref,0,1); } PHP_METHOD(git_repository, getReferences) diff --git a/src/tree.c b/src/tree.c index 516176a007..108e42c9f4 100644 --- a/src/tree.c +++ b/src/tree.c @@ -178,7 +178,7 @@ PHP_METHOD(git_tree, getIterator) obj->tree = this->object; obj->repository = this->repository; obj->offset = 0; - RETURN_ZVAL(iterator,0,0); + RETURN_ZVAL(iterator,0,1); } PHP_METHOD(git_tree, getEntry) @@ -195,7 +195,7 @@ PHP_METHOD(git_tree, getEntry) entry = git_tree_entry_byindex(this->object,offset); create_tree_entry_from_entry(&git_tree_entry, entry,this->repository); - RETURN_ZVAL(git_tree_entry,0, 0); + RETURN_ZVAL(git_tree_entry,0, 1); } PHP_METHOD(git_tree, getEntries) @@ -214,7 +214,7 @@ PHP_METHOD(git_tree, getEntries) add_next_index_zval(entries, array_ptr); } - RETURN_ZVAL(entries,0,0); + RETURN_ZVAL(entries,0,1); } diff --git a/src/tree_entry.c b/src/tree_entry.c index e84030a947..761dbf9a09 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -142,13 +142,38 @@ PHP_METHOD(git_tree_entry, isBlob) } } +PHP_METHOD(git_tree_entry, toHeader) +{ + php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + git_odb *odb; + git_oid oid; + int length; + + char *id = Z_STRVAL_P(zend_read_property(git_tree_entry_class_entry, getThis(),"oid",sizeof("oid")-1, 0 TSRMLS_CC)); + git_oid_mkstr(&oid, id); + git_otype type; + git_odb_read_header(&length,&type,git_repository_database(this->repository),&oid); + + if (type == GIT_OBJ_BLOB) { + zval *git_raw_object; + MAKE_STD_ZVAL(git_raw_object); + object_init_ex(git_raw_object, git_blob_class_entry); + + add_property_string_ex(git_raw_object,"data", sizeof("data"), "", 1 TSRMLS_CC); + add_property_long_ex(git_raw_object,"size", sizeof("size"), length TSRMLS_CC); + RETURN_ZVAL(git_raw_object,0,1); + } else { + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"Git\\Tree\\Entry::toHeader can convert GIT_OBJ_BLOB only for now. unhandled object type %d found.", type); + } +} PHPAPI function_entry php_git_tree_entry_methods[] = { PHP_ME(git_tree_entry, __construct, NULL, ZEND_ACC_PRIVATE) - PHP_ME(git_tree_entry, toObject, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_entry, isTree, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_entry, isBlob, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_tree_entry, toHeader, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_tree_entry, toObject, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_tree_entry, isTree, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_tree_entry, isBlob, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; diff --git a/src/tree_iterator.c b/src/tree_iterator.c index 8034541ab8..8fe30519d1 100644 --- a/src/tree_iterator.c +++ b/src/tree_iterator.c @@ -75,7 +75,7 @@ PHP_METHOD(git_tree_iterator, current) RETURN_FALSE; } create_tree_entry_from_entry(&git_tree_entry,entry,this->repository); - RETURN_ZVAL(git_tree_entry,0,0); + RETURN_ZVAL(git_tree_entry,0,1); } PHP_METHOD(git_tree_iterator, key) From b9b9ff9426501bd67de8ecf3eb9443a8c0239d88 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 15 May 2011 21:46:41 +0900 Subject: [PATCH 039/300] fix `Git\Tree\Entry::toObject()` --- src/tree_entry.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/tree_entry.c b/src/tree_entry.c index 761dbf9a09..e44966fdd3 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -80,32 +80,19 @@ PHP_METHOD(git_tree_entry, toObject) blobobj->object = (git_blob *)object; add_property_stringl_ex(git_raw_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); - RETURN_ZVAL(git_raw_object,0,0); + RETURN_ZVAL(git_raw_object,0,1); } else if(type == GIT_OBJ_TREE) { git_tree *tree = (git_tree *)object; + zval *git_tree; - zval *entries; MAKE_STD_ZVAL(git_tree); - MAKE_STD_ZVAL(entries); - array_init(entries); object_init_ex(git_tree, git_tree_class_entry); - int r = git_tree_entrycount(tree); - int i = 0; - char buf[GIT_OID_HEXSZ+1] = {0}; - char *offset; - git_oid *moid; - zval *array_ptr; - - for(i; i < r; i++){ - create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(tree,i),this->repository); - add_next_index_zval(entries, array_ptr); - } php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); tobj->object = tree; tobj->repository = this->repository; - add_property_zval(git_tree,"entries", entries); - RETURN_ZVAL(git_tree,0,0); + + RETURN_ZVAL(git_tree,0,1); } else{ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, From 3ae0712a4119e80f145213a9f6e5d28673afb7a6 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 15 May 2011 23:43:25 +0900 Subject: [PATCH 040/300] fix Git\Commit. added Git\Commit::getId(); --- src/commit.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/commit.c b/src/commit.c index 45dae07247..b2a2f338a5 100644 --- a/src/commit.c +++ b/src/commit.c @@ -363,27 +363,25 @@ PHP_METHOD(git_commit, getParent) RETURN_FALSE; } - - MAKE_STD_ZVAL(zcommit); - object_init_ex(zcommit,git_commit_class_entry); - obj = (php_git_commit_t *) zend_object_store_get_object(zcommit TSRMLS_CC); - obj->object = commit; - - create_signature_from_commit(&author, git_commit_author(obj->object)); - create_signature_from_commit(&committer, git_commit_committer(obj->object)); - - add_property_zval(zcommit,"author", author); - add_property_zval(zcommit,"committer", committer); + php_git_commit_init(&zcommit, commit, this->repository TSRMLS_CC); - RETURN_ZVAL(zcommit,1,0); + RETURN_ZVAL(zcommit,0,1); +} - efree(zcommit); - efree(author); - efree(committer); +PHP_METHOD(git_commit, getId) +{ + php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + git_oid *oid = git_commit_id(this->object); + char id[GIT_OID_HEXSZ+1] = {0}; + + git_oid_to_string(id,GIT_OID_HEXSZ+1,oid); + + RETURN_STRING(id,1); } PHPAPI function_entry php_git_commit_methods[] = { PHP_ME(git_commit, __construct, arginfo_git_commit__construct, ZEND_ACC_PUBLIC) + PHP_ME(git_commit, getId, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_commit, setAuthor, arginfo_git_commit_set_author, ZEND_ACC_PUBLIC) PHP_ME(git_commit, setCommitter, arginfo_git_commit_set_committer,ZEND_ACC_PUBLIC) PHP_ME(git_commit, setParents, arginfo_git_commit_set_parents, ZEND_ACC_PUBLIC) From 8932cfef3bf49778b6d3b1437e00ee736f985513 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 16 May 2011 01:19:10 +0900 Subject: [PATCH 041/300] added convention method `Git\Tree::resolve()` this method recursive resolve filename. --- src/php_git.c | 44 ++++++++++++++++++++++++++++++++++++++++ src/php_git.h | 1 + src/tree.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/src/php_git.c b/src/php_git.c index c1d848843f..d700119bd4 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -129,6 +129,50 @@ void php_git_commit_init(zval **object, git_commit *commit, git_repository *repo php_git_add_protected_property_zval_ex(*object,"parents",sizeof("parents"),parents TSRMLS_CC); } +int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_repository *repository, const char *path) +{ + const git_tree_entry *entry; + git_tree *tmp = tree; + int attribute, length, offset, position, len; + char buffer[256]; + char *p; + offset = 0; + position = 0; + len = 0; + length = strlen(path); + p = path; + + int ret = GIT_ERROR; + + while (position < length) { + if(path[position] == '/') { + memcpy(buffer,p, position-offset); + buffer[position-offset] = '\0'; + + offset = position+1; + p+=offset; + + entry = git_tree_entry_byname(tmp,buffer); + attribute = git_tree_entry_attributes(entry); + ret = git_tree_entry_2object(&tmp,repository,entry); + if(ret != GIT_SUCCESS) { + fprintf(stderr,"[Error]:%s\n",git_strerror(ret)); + } + } else if (position == length-1) { + memcpy(buffer,p, position+1-offset); + buffer[position+1-offset] = '\0'; + + entry = git_tree_entry_byname(tmp,buffer); + if(ret != GIT_SUCCESS) { + fprintf(stderr,"[Error]:%s\n",git_strerror(ret)); + } + } + position++; + } + *object = entry; +} + + PHPAPI zend_class_entry *git_class_entry; diff --git a/src/php_git.h b/src/php_git.h index 79f85058fb..9ee4f7cb2e 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -51,6 +51,7 @@ int php_git_add_protected_property_string_ex(zval *object, char *name, int name_ int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC); zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); void php_git_commit_init(zval **object, git_commit *commit, git_repository *repository TSRMLS_DC); +int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_repository* repository, const char *path); extern PHPAPI zend_class_entry *git_class_entry; extern PHPAPI zend_class_entry *git_reference_class_entry; diff --git a/src/tree.c b/src/tree.c index 108e42c9f4..411551e5e2 100644 --- a/src/tree.c +++ b/src/tree.c @@ -52,6 +52,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_remove, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_resolve, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + + static void php_git_tree_free_storage(php_git_tree_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); @@ -218,7 +223,58 @@ PHP_METHOD(git_tree, getEntries) } +PHP_METHOD(git_tree, resolve) +{ + php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + git_tree_entry *entry; + git_object *object; + git_otype type; + char *path; + int path_len; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &path, &path_len) == FAILURE){ + return; + } + + git_tree_entry_resolve_byname(&entry, this->object, this->repository, path); + + int ret = git_tree_entry_2object(&object, this->repository, entry); + + type = git_object_type(object); + if (type == GIT_OBJ_BLOB) { + + zval *git_raw_object; + MAKE_STD_ZVAL(git_raw_object); + object_init_ex(git_raw_object, git_blob_class_entry); + php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_raw_object TSRMLS_CC); + blobobj->object = (git_blob *)object; + + add_property_stringl_ex(git_raw_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); + RETURN_ZVAL(git_raw_object,0,1); + } else if(type == GIT_OBJ_TREE) { + git_tree *tree = (git_tree *)object; + + zval *git_tree; + MAKE_STD_ZVAL(git_tree); + object_init_ex(git_tree, git_tree_class_entry); + + php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); + tobj->object = tree; + tobj->repository = this->repository; + + RETURN_ZVAL(git_tree,0,1); + + } else{ + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, + "Git\\Tree\\Entry::toObject can convert GIT_OBJ_TREE or GIT_OBJ_BLOB. unhandled object type %d found.", git_object_type(object)); + RETURN_FALSE; + } + +} + PHPAPI function_entry php_git_tree_methods[] = { + PHP_ME(git_tree, resolve, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree, __construct, arginfo_git_tree__construct, ZEND_ACC_PUBLIC) PHP_ME(git_tree, getEntry, arginfo_git_tree_get_entry, ZEND_ACC_PUBLIC) PHP_ME(git_tree, getEntries, NULL, ZEND_ACC_PUBLIC) From 969e97947539b4f5c9b9eccea7b95bb9b9965aa7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 16 May 2011 01:29:49 +0900 Subject: [PATCH 042/300] fix error handling --- src/php_git.c | 5 +++++ src/tree.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/php_git.c b/src/php_git.c index d700119bd4..bacdea51c3 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -170,6 +170,11 @@ int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_r position++; } *object = entry; + if(entry == NULL) { + return GIT_ERROR; + } else { + return GIT_SUCCESS; + } } diff --git a/src/tree.c b/src/tree.c index 411551e5e2..a58d67a48c 100644 --- a/src/tree.c +++ b/src/tree.c @@ -229,6 +229,7 @@ PHP_METHOD(git_tree, resolve) git_tree_entry *entry; git_object *object; git_otype type; + int ret; char *path; int path_len; @@ -237,9 +238,15 @@ PHP_METHOD(git_tree, resolve) return; } - git_tree_entry_resolve_byname(&entry, this->object, this->repository, path); + ret = git_tree_entry_resolve_byname(&entry, this->object, this->repository, path); + if(ret != GIT_SUCCESS) { + RETURN_FALSE; + } - int ret = git_tree_entry_2object(&object, this->repository, entry); + ret = git_tree_entry_2object(&object, this->repository, entry); + if(ret != GIT_SUCCESS) { + RETURN_FALSE; + } type = git_object_type(object); if (type == GIT_OBJ_BLOB) { From cb035b55c1bd561c5f275a7d1367e4b27ef98ff2 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 17 May 2011 21:50:04 +0900 Subject: [PATCH 043/300] tempolary added git_tree_entry_resolve_byname --- src/php_git.c | 25 +++++++++++++++++++------ src/tree.c | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/php_git.c b/src/php_git.c index bacdea51c3..5f9bade383 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -129,12 +129,14 @@ void php_git_commit_init(zval **object, git_commit *commit, git_repository *repo php_git_add_protected_property_zval_ex(*object,"parents",sizeof("parents"),parents TSRMLS_CC); } +// probably this method will be deplicated. int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_repository *repository, const char *path) { const git_tree_entry *entry; git_tree *tmp = tree; int attribute, length, offset, position, len; char buffer[256]; + memset(buffer,'\0',256); char *p; offset = 0; position = 0; @@ -153,22 +155,34 @@ int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_r p+=offset; entry = git_tree_entry_byname(tmp,buffer); + if(entry == NULL) { + RETURN_FALSE; + } + attribute = git_tree_entry_attributes(entry); + tmp = NULL; ret = git_tree_entry_2object(&tmp,repository,entry); if(ret != GIT_SUCCESS) { - fprintf(stderr,"[Error]:%s\n",git_strerror(ret)); + RETURN_FALSE; } } else if (position == length-1) { + memset(buffer,'\0',256); memcpy(buffer,p, position+1-offset); - buffer[position+1-offset] = '\0'; - entry = git_tree_entry_byname(tmp,buffer); - if(ret != GIT_SUCCESS) { - fprintf(stderr,"[Error]:%s\n",git_strerror(ret)); + int c = git_tree_entrycount(tmp); + int i = 0; + for(i =0; i < c; i++){ + git_tree_entry *e = git_tree_entry_byindex(tmp,i); + } + //entry_sort_cmp + entry = git_tree_entry_byname(tmp,"git2.h"); + if(entry == NULL) { + RETURN_FALSE; } } position++; } + *object = entry; if(entry == NULL) { return GIT_ERROR; @@ -178,7 +192,6 @@ int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_r } - PHPAPI zend_class_entry *git_class_entry; ZEND_BEGIN_ARG_INFO_EX(arginfo_git_string_to_type, 0, 0, 1) diff --git a/src/tree.c b/src/tree.c index a58d67a48c..a4e51e54cd 100644 --- a/src/tree.c +++ b/src/tree.c @@ -222,7 +222,7 @@ PHP_METHOD(git_tree, getEntries) RETURN_ZVAL(entries,0,1); } - +// probably this method will be deplicated. PHP_METHOD(git_tree, resolve) { php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); From 604a914f442d4f3da76866c77049c853792c745b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 26 May 2011 22:44:45 +0900 Subject: [PATCH 044/300] fixed return value --- src/php_git.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/php_git.c b/src/php_git.c index 5f9bade383..62357d4e3d 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -156,14 +156,14 @@ int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_r entry = git_tree_entry_byname(tmp,buffer); if(entry == NULL) { - RETURN_FALSE; + return GIT_ERROR; } attribute = git_tree_entry_attributes(entry); tmp = NULL; ret = git_tree_entry_2object(&tmp,repository,entry); if(ret != GIT_SUCCESS) { - RETURN_FALSE; + return GIT_ERROR; } } else if (position == length-1) { memset(buffer,'\0',256); @@ -177,7 +177,7 @@ int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_r //entry_sort_cmp entry = git_tree_entry_byname(tmp,"git2.h"); if(entry == NULL) { - RETURN_FALSE; + return GIT_ERROR; } } position++; From 89728a95e59cb8f30ad049d46f9c0ddf3df56bc8 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 27 May 2011 01:50:07 +0900 Subject: [PATCH 045/300] added Git\Config class. array Git\Config::parseFile(string config_file_path); this static method still work in progres. --- src/config.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/config.m4 | 2 +- src/php_git.c | 1 + src/php_git.h | 6 ++ 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/config.c diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000000..544bc4ae1f --- /dev/null +++ b/src/config.c @@ -0,0 +1,160 @@ +/* + * The MIT License + * + * Copyright (c) 2010 - 2011 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_git.h" +#include +#include +#include +#include + +PHPAPI zend_class_entry *git_config_class_entry; + +static void php_git_config_free_storage(php_git_config_t *obj TSRMLS_DC) +{ + zend_object_std_dtor(&obj->zo TSRMLS_CC); + efree(obj); +} + +zend_object_value php_git_config_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + php_git_config_t *obj; + zval *tmp; + + obj = ecalloc(1, sizeof(*obj)); + zend_object_std_init( &obj->zo, ce TSRMLS_CC ); + zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + + retval.handle = zend_objects_store_put(obj, + (zend_objects_store_dtor_t)zend_objects_destroy_object, + (zend_objects_free_object_storage_t)php_git_config_free_storage, + NULL TSRMLS_CC); + retval.handlers = zend_get_std_object_handlers(); + return retval; +} + +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_parse_file, 0, 0, 1) + ZEND_ARG_INFO(0, file) +ZEND_END_ARG_INFO() + +typedef struct{ + zval *array; + git_config *config +} git_config_foreach_t; + + +static int php_git_config_foreach(const char *key, void *data) +{ + zval *config = ((git_config_foreach_t*)data)->array; + HashTable *hash = Z_ARRVAL_P(config); + zval **target_key; + zval *moe_key; + + char *tmp = estrdup(key); + + char *current_key; + char *uu; + char *value; + + git_config_get_string(((git_config_foreach_t *)data)->config,key,&value); + + current_key = strtok(tmp, "."); + while (current_key != NULL) { + uu = current_key; + current_key = strtok(NULL, "."); + if(current_key != NULL) { + if(zend_hash_exists(hash,uu,strlen(uu)+1)) { + if (zend_hash_find(hash,uu,strlen(uu)+1,(void **)&target_key) == SUCCESS) { + hash = Z_ARRVAL_P(*target_key); + } + } else { + MAKE_STD_ZVAL(moe_key); + array_init(moe_key); + zend_hash_add(hash,uu,strlen(uu)+1,(void **)&moe_key,sizeof(moe_key),NULL); + hash = Z_ARRVAL_P(moe_key); + } + } + } + + if(uu != NULL) { + zval *moe; + MAKE_STD_ZVAL(moe); + ZVAL_STRING(moe,value,1); + zval_copy_ctor(&moe); + zend_hash_add(hash,uu,strlen(uu)+1,(void **)&moe,sizeof(moe),NULL); + } + + efree(tmp); + + return GIT_SUCCESS; +} + +PHP_METHOD(git_config, parseFile) +{ + git_config_foreach_t t; + git_config *config; + zval *zconf; + + char *path; + int path_len = 0; + int ret = GIT_ERROR; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &path,&path_len) == FAILURE){ + return; + } + + ret = git_config_open_file(&config, path); + if(ret != GIT_SUCCESS) { + php_git_throw_exception(NULL,ret,NULL TSRMLS_CC); + return; + } + + MAKE_STD_ZVAL(zconf); + array_init(zconf); + + t.array = zconf; + t.config = config; + + git_config_foreach(config,php_git_config_foreach,&t); + + t.array = NULL; + t.config = NULL; + git_config_free(config); + + RETURN_ZVAL(zconf,0,1); +} + +PHPAPI function_entry php_git_config_methods[] = { + PHP_ME(git_config, parseFile, arginfo_git_config_parse_file, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + {NULL,NULL,NULL} +}; + +void git_config_init(TSRMLS_D) +{ + zend_class_entry ce; + INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Config", php_git_config_methods); + git_config_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + git_config_class_entry->create_object = php_git_config_new; +} diff --git a/src/config.m4 b/src/config.m4 index c051c1ebd2..f09a5ca823 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -29,7 +29,7 @@ if test $PHP_GIT != "no"; then PHP_ADD_LIBRARY_WITH_PATH(git2, $LIBGIT2_LIBDIR, GIT_SHARED_LIBADD) PHP_SUBST(GIT_SHARED_LIBADD) - PHP_NEW_EXTENSION(git,php_git.c rawobject.c backend.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c, $ext_shared) + PHP_NEW_EXTENSION(git,php_git.c rawobject.c backend.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c config.c, $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], [ diff --git a/src/php_git.c b/src/php_git.c index 62357d4e3d..9a0ae8df35 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -302,6 +302,7 @@ PHP_MINIT_FUNCTION(git) { git_index_init(TSRMLS_C); git_init_signature(TSRMLS_C); git_init_walker(TSRMLS_C); + git_config_init(TSRMLS_C); git_tree_builder_init(TSRMLS_C); git_tree_iterator_init(TSRMLS_C); git_init_tree(TSRMLS_C); diff --git a/src/php_git.h b/src/php_git.h index 9ee4f7cb2e..fa5fadedac 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -73,6 +73,7 @@ extern PHPAPI zend_class_entry *git_blob_class_entry; extern PHPAPI zend_class_entry *git_odb_class_entry; extern PHPAPI zend_class_entry *git_backend_class_entry; extern PHPAPI zend_class_entry *git_rawobject_class_entry; +extern PHPAPI zend_class_entry *git_config_class_entry; typedef struct{ zend_object zo; @@ -186,5 +187,10 @@ typedef struct{ git_repository *repository; } php_git_reference_manager_t; +typedef struct{ + zend_object zo; + git_config *config +} php_git_config_t; + #endif /* PHP_GIT_H */ \ No newline at end of file From 36928247b8261631f8a04cd1cd3a8a5001e45fa7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 3 Jun 2011 21:44:22 +0900 Subject: [PATCH 046/300] update libgit2 version. --- LIBGIT2_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION index 0b7a9d8d2d..e07c9859d2 100644 --- a/LIBGIT2_VERSION +++ b/LIBGIT2_VERSION @@ -1 +1 @@ -cc3b82e376e0216c1af4ad46d24327d61e9efd99 \ No newline at end of file +1e9b7a09ff3d16c3d7a132cfaacb9d68b253e924 From 50e6edbe0b26238a14144f486908b0350d357a70 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 3 Jun 2011 21:49:42 +0900 Subject: [PATCH 047/300] using `php_strtok_r` instead of `strtok`. --- src/config.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 544bc4ae1f..88134595c1 100644 --- a/src/config.c +++ b/src/config.c @@ -78,11 +78,13 @@ static int php_git_config_foreach(const char *key, void *data) char *value; git_config_get_string(((git_config_foreach_t *)data)->config,key,&value); - - current_key = strtok(tmp, "."); + + char *savedptr; + + current_key = php_strtok_r(tmp, ".",&savedptr); while (current_key != NULL) { uu = current_key; - current_key = strtok(NULL, "."); + current_key = php_strtok_r(NULL, ".",&savedptr); if(current_key != NULL) { if(zend_hash_exists(hash,uu,strlen(uu)+1)) { if (zend_hash_find(hash,uu,strlen(uu)+1,(void **)&target_key) == SUCCESS) { From 682e6a125ff74e96fd75565686ea4fec1f6b8e19 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 18 Jun 2011 00:23:28 +0900 Subject: [PATCH 048/300] rename git_oid_from* functions and adjust git_repository_path signature. we have to enable -DBUILD_SHRARED_LIB when compiling libgit2. waf command was out of date. --- LIBGIT2_VERSION | 2 +- src/backend.c | 2 +- src/blob.c | 2 +- src/commit.c | 6 +++--- src/index_entry.c | 2 +- src/object.c | 2 +- src/odb.c | 2 +- src/php_git.c | 4 ++-- src/php_git.h | 2 +- src/rawobject.c | 2 +- src/reference.c | 4 ++-- src/reference_manager.c | 4 ++-- src/repository.c | 9 +++++---- src/tag.c | 2 +- src/tree.c | 2 +- src/tree_builder.c | 2 +- src/tree_entry.c | 4 ++-- src/walker.c | 4 ++-- 18 files changed, 29 insertions(+), 28 deletions(-) diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION index e07c9859d2..dcc54828e8 100644 --- a/LIBGIT2_VERSION +++ b/LIBGIT2_VERSION @@ -1 +1 @@ -1e9b7a09ff3d16c3d7a132cfaacb9d68b253e924 +cb75ffea80c358323738bdc2e1763cfa15f0bb87 diff --git a/src/backend.c b/src/backend.c index 39980f7b62..e7864fd0e8 100644 --- a/src/backend.c +++ b/src/backend.c @@ -321,4 +321,4 @@ void git_init_backend(TSRMLS_D) INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Backend", php_git_backend_methods); git_backend_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_backend_class_entry->create_object = php_git_backend_new; -} \ No newline at end of file +} diff --git a/src/blob.c b/src/blob.c index 1e2e4bb39e..aa6ca008b0 100644 --- a/src/blob.c +++ b/src/blob.c @@ -168,4 +168,4 @@ void git_init_blob(TSRMLS_D) git_blob_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry, NULL TSRMLS_CC); git_blob_class_entry->create_object = php_git_blob_new; -} \ No newline at end of file +} diff --git a/src/commit.c b/src/commit.c index b2a2f338a5..a494ae6e8b 100644 --- a/src/commit.c +++ b/src/commit.c @@ -260,7 +260,7 @@ PHP_METHOD(git_commit, write) git_oid tree_oid; char *tree_oid_str = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"tree",sizeof("tree")-1, 0 TSRMLS_CC)); - git_oid_mkstr(&tree_oid, tree_oid_str); + git_oid_fromstr(&tree_oid, tree_oid_str); zval *z_author = zend_read_property(git_commit_class_entry, getThis(),"author",sizeof("author")-1, 0 TSRMLS_CC); author = (php_git_signature_t *) zend_object_store_get_object(z_author TSRMLS_CC); @@ -287,7 +287,7 @@ PHP_METHOD(git_commit, write) ) { tmp = (git_oid *)malloc(sizeof(git_oid)); zend_hash_get_current_data_ex(array_hash, (void **)&data, &pointer); - git_oid_mkstr(tmp,Z_STRVAL_PP(data)); + git_oid_fromstr(tmp,Z_STRVAL_PP(data)); *p = tmp; p++; @@ -409,4 +409,4 @@ void git_init_commit(TSRMLS_D) zend_declare_property_null(git_commit_class_entry, "parents", sizeof("parents")-1, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(git_commit_class_entry, "message", sizeof("message")-1, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(git_commit_class_entry, "tree", sizeof("tree")-1, ZEND_ACC_PROTECTED TSRMLS_CC); -} \ No newline at end of file +} diff --git a/src/index_entry.c b/src/index_entry.c index f1a21bc2a8..8919846c8d 100644 --- a/src/index_entry.c +++ b/src/index_entry.c @@ -79,4 +79,4 @@ void git_index_entry_init(TSRMLS_D) zend_declare_property_null(git_index_entry_class_entry , "flags_extended",sizeof("flags_extended")-1, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_index_entry_class_entry , "ctime",sizeof("ctime")-1, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_index_entry_class_entry , "mtime",sizeof("mtime")-1, ZEND_ACC_PUBLIC TSRMLS_CC); -} \ No newline at end of file +} diff --git a/src/object.c b/src/object.c index 7bacd8ced0..7eab325a21 100644 --- a/src/object.c +++ b/src/object.c @@ -95,4 +95,4 @@ void git_init_object(TSRMLS_D) INIT_NS_CLASS_ENTRY(git_object_ce, PHP_GIT_NS,"Object", php_git_object_methods); git_object_class_entry = zend_register_internal_class(&git_object_ce TSRMLS_CC); git_object_class_entry->create_object = php_git_object_new; -} \ No newline at end of file +} diff --git a/src/odb.c b/src/odb.c index 5c0791b67d..409090a430 100644 --- a/src/odb.c +++ b/src/odb.c @@ -170,4 +170,4 @@ void git_init_odb(TSRMLS_D) git_odb_class_entry->create_object = php_git_odb_new; zend_declare_property_null(git_odb_class_entry, "backends",sizeof("backends")-1,ZEND_ACC_PROTECTED TSRMLS_CC); -} \ No newline at end of file +} diff --git a/src/php_git.c b/src/php_git.c index 9a0ae8df35..920c847e69 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -250,7 +250,7 @@ PHP_FUNCTION(git_hex_to_raw) return; } - git_oid_mkstr(&oid, hex); + git_oid_fromstr(&oid, hex); RETVAL_STRINGL((&oid)->id,GIT_OID_RAWSZ,1); } @@ -266,7 +266,7 @@ PHP_FUNCTION(git_raw_to_hex) return; } - git_oid_mkraw(&oid, raw); + git_oid_fromraw(&oid, raw); git_oid_fmt(out, &oid); RETVAL_STRINGL(out,GIT_OID_HEXSZ,1); diff --git a/src/php_git.h b/src/php_git.h index fa5fadedac..77ea30511d 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -193,4 +193,4 @@ typedef struct{ } php_git_config_t; -#endif /* PHP_GIT_H */ \ No newline at end of file +#endif /* PHP_GIT_H */ diff --git a/src/rawobject.c b/src/rawobject.c index 1dd9133632..f8a70956ca 100644 --- a/src/rawobject.c +++ b/src/rawobject.c @@ -39,4 +39,4 @@ void git_init_rawobject(TSRMLS_D) zend_declare_property_null(git_rawobject_class_entry, "data", sizeof("data"), ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_rawobject_class_entry, "type", sizeof("type"), ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_rawobject_class_entry, "len", sizeof("len"), ZEND_ACC_PUBLIC TSRMLS_CC); -} \ No newline at end of file +} diff --git a/src/reference.c b/src/reference.c index c5c9f77503..6fe03b56e4 100644 --- a/src/reference.c +++ b/src/reference.c @@ -166,7 +166,7 @@ PHP_METHOD(git_reference, setOID) return; } - git_oid_mkstr(&out, oid); + git_oid_fromstr(&out, oid); git_reference_set_oid(this->object, &out); add_property_string_ex(getThis() ,"oid",sizeof("oid"),oid, 1 TSRMLS_CC); @@ -244,4 +244,4 @@ void git_init_reference(TSRMLS_D) zend_declare_property_null(git_reference_class_entry, "oid", sizeof("oid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_reference_class_entry, "name", sizeof("name")-1, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_reference_class_entry, "target", sizeof("target")-1, ZEND_ACC_PUBLIC TSRMLS_CC); -} \ No newline at end of file +} diff --git a/src/reference_manager.c b/src/reference_manager.c index ce216df59a..27869983be 100644 --- a/src/reference_manager.c +++ b/src/reference_manager.c @@ -232,7 +232,7 @@ PHP_METHOD(git_reference_manager, create) RETURN_FALSE; } - git_oid_mkstr(&id, oid); + git_oid_fromstr(&id, oid); git_odb *odb; odb = git_repository_database(this->repository); @@ -293,4 +293,4 @@ void git_init_reference_manager(TSRMLS_D) git_reference_manager_class_entry = zend_register_internal_class(&ce TSRMLS_CC); git_reference_manager_class_entry->create_object = php_git_reference_manager_new; -} \ No newline at end of file +} diff --git a/src/repository.c b/src/repository.c index 5f0a6a6927..8ca8b8e51a 100644 --- a/src/repository.c +++ b/src/repository.c @@ -205,7 +205,7 @@ PHP_METHOD(git_repository, getObject) return; } - git_oid_mkstr(&oid, hash); + git_oid_fromstr(&oid, hash); php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); repository = myobj->repository; @@ -271,7 +271,7 @@ PHP_METHOD(git_repository, getCommit) return; } - git_oid_mkstr(&oid, hash); + git_oid_fromstr(&oid, hash); odb = git_repository_database(this->repository); if(!git_odb_exists(odb,&oid)){ RETURN_FALSE; @@ -292,6 +292,7 @@ PHP_METHOD(git_repository, __construct) int ret = 0; int arg_len = 0; git_repository *repository; + git_repository_pathid id; zval *object = getThis(); zval *odb, *backends; @@ -312,7 +313,7 @@ PHP_METHOD(git_repository, __construct) php_git_odb_init(&odb, git_repository_database(myobj->repository) TSRMLS_CC); php_git_add_protected_property_zval_ex(object,"odb",sizeof("odb"),odb TSRMLS_CC); - php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository),1 TSRMLS_CC); + php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository,id),1 TSRMLS_CC); }else{ myobj->repository = NULL; } @@ -339,7 +340,7 @@ PHP_METHOD(git_repository, getTree) return; } - git_oid_mkstr(&oid, hash); + git_oid_fromstr(&oid, hash); php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); ret = git_tree_lookup(&tree, myobj->repository, &oid); diff --git a/src/tag.c b/src/tag.c index 4ff4012ef6..e0ffb04d92 100644 --- a/src/tag.c +++ b/src/tag.c @@ -147,4 +147,4 @@ void git_init_tag(TSRMLS_D) zend_declare_property_null(git_tag_class_entry, "name", sizeof("name"), ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_tag_class_entry, "tagger", sizeof("tagger"), ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_tag_class_entry, "message",sizeof("message"), ZEND_ACC_PUBLIC TSRMLS_CC); -} \ No newline at end of file +} diff --git a/src/tree.c b/src/tree.c index a4e51e54cd..6094e70783 100644 --- a/src/tree.c +++ b/src/tree.c @@ -299,4 +299,4 @@ void git_init_tree(TSRMLS_D) git_tree_class_entry->create_object = php_git_tree_new; zend_class_implements(git_tree_class_entry TSRMLS_CC, 2, spl_ce_Countable,zend_ce_aggregate); -} \ No newline at end of file +} diff --git a/src/tree_builder.c b/src/tree_builder.c index dd898f78b4..01263e96fb 100644 --- a/src/tree_builder.c +++ b/src/tree_builder.c @@ -118,7 +118,7 @@ PHP_METHOD(git_tree_builder,add) return; } - error = git_oid_mkstr(&id, hash); + error = git_oid_fromstr(&id, hash); if (error != GIT_SUCCESS) { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create object id."); RETURN_FALSE; diff --git a/src/tree_entry.c b/src/tree_entry.c index e44966fdd3..4a5942237b 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -138,7 +138,7 @@ PHP_METHOD(git_tree_entry, toHeader) char *id = Z_STRVAL_P(zend_read_property(git_tree_entry_class_entry, getThis(),"oid",sizeof("oid")-1, 0 TSRMLS_CC)); - git_oid_mkstr(&oid, id); + git_oid_fromstr(&oid, id); git_otype type; git_odb_read_header(&length,&type,git_repository_database(this->repository),&oid); @@ -175,4 +175,4 @@ void git_init_tree_entry(TSRMLS_D) zend_declare_property_null(git_tree_entry_class_entry, "oid",sizeof("oid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(git_tree_entry_class_entry, "mode",sizeof("mode")-1, ZEND_ACC_PUBLIC TSRMLS_CC); -} \ No newline at end of file +} diff --git a/src/walker.c b/src/walker.c index 975f3347b8..1b27e3f3b7 100644 --- a/src/walker.c +++ b/src/walker.c @@ -93,7 +93,7 @@ PHP_METHOD(git_walker, hide) repository = git_revwalk_repository(walker); - git_oid_mkstr(&oid,hash); + git_oid_fromstr(&oid,hash); git_revwalk_hide(walker,&oid); } @@ -116,7 +116,7 @@ PHP_METHOD(git_walker, push) walker = myobj->walker; repository = git_revwalk_repository(walker); - git_oid_mkstr(&oid,hash); + git_oid_fromstr(&oid,hash); git_revwalk_push(walker,&oid); } From 10760ac812dfb3f4bdd31a226bd9cff9d9db2083 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 18 Jun 2011 00:36:54 +0900 Subject: [PATCH 049/300] i missunderstood usage of `git_repository_path`. --- src/repository.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/repository.c b/src/repository.c index 8ca8b8e51a..a7ac2db4f4 100644 --- a/src/repository.c +++ b/src/repository.c @@ -292,7 +292,6 @@ PHP_METHOD(git_repository, __construct) int ret = 0; int arg_len = 0; git_repository *repository; - git_repository_pathid id; zval *object = getThis(); zval *odb, *backends; @@ -313,7 +312,7 @@ PHP_METHOD(git_repository, __construct) php_git_odb_init(&odb, git_repository_database(myobj->repository) TSRMLS_CC); php_git_add_protected_property_zval_ex(object,"odb",sizeof("odb"),odb TSRMLS_CC); - php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository,id),1 TSRMLS_CC); + php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository,GIT_REPO_PATH),1 TSRMLS_CC); }else{ myobj->repository = NULL; } From 325b0b5360b188cd3bc30ad570cd83302500460c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 19 Jun 2011 23:30:31 +0900 Subject: [PATCH 050/300] to adjust Git\Repository::getWorkDir method --- LIBGIT2_VERSION | 2 +- src/repository.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION index dcc54828e8..c20f8f0a11 100644 --- a/LIBGIT2_VERSION +++ b/LIBGIT2_VERSION @@ -1 +1 @@ -cb75ffea80c358323738bdc2e1763cfa15f0bb87 +37172582ec7ff9cb47c43c5d5b2334bf8c547569 \ No newline at end of file diff --git a/src/repository.c b/src/repository.c index a7ac2db4f4..3c606641c4 100644 --- a/src/repository.c +++ b/src/repository.c @@ -622,7 +622,7 @@ PHP_METHOD(git_repository, getWorkdir) char *git_workdir; if(this->repository != NULL) { - git_workdir = git_repository_workdir(this->repository); + git_workdir = git_repository_path(this->repository,GIT_REPO_PATH_WORKDIR); RETVAL_STRING(git_workdir,1); } } From 9528478a1130b537f51f30b1ae482cecf5a39f78 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Mon, 1 Aug 2011 12:56:44 +0100 Subject: [PATCH 051/300] Fix for issue #11 where the git_reference_create_oid method signature had changed. --- src/reference_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reference_manager.c b/src/reference_manager.c index 27869983be..beec6cec5b 100644 --- a/src/reference_manager.c +++ b/src/reference_manager.c @@ -243,7 +243,7 @@ PHP_METHOD(git_reference_manager, create) } git_reference *reference; - int ret = git_reference_create_oid(&reference, this->repository, name, &id); + int ret = git_reference_create_oid(&reference, this->repository, name, &id, 0); if(ret != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "can't add reference"); From 93ba7d8fd03c2f696007bbb01d8d352e18fcb7ce Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 2 Aug 2011 08:49:15 +0100 Subject: [PATCH 052/300] Issue #11 added optional force boolean parameter to reference manager create method --- src/reference_manager.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/reference_manager.c b/src/reference_manager.c index beec6cec5b..3d98423ffa 100644 --- a/src/reference_manager.c +++ b/src/reference_manager.c @@ -42,6 +42,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager_create, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, oid) + ZEND_ARG_INFO(0, force) ZEND_END_ARG_INFO() static void php_git_reference_manager_free_storage(php_git_reference_manager_t *obj TSRMLS_DC) @@ -221,9 +222,10 @@ PHP_METHOD(git_reference_manager, create) char *oid; int oid_len = 0; git_oid id; + zend_bool force = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ss", &name, &name_len, &oid, &oid_len) == FAILURE){ + "ss|b", &name, &name_len, &oid, &oid_len, &force) == FAILURE){ return; } if(oid_len != GIT_OID_HEXSZ){ @@ -243,10 +245,10 @@ PHP_METHOD(git_reference_manager, create) } git_reference *reference; - int ret = git_reference_create_oid(&reference, this->repository, name, &id, 0); + int ret = git_reference_create_oid(&reference, this->repository, name, &id, force); if(ret != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't add reference"); + "can't add reference, maybe try setting force to boolean true"); RETURN_FALSE; } From caa241e2c810861bb5a1a7728b14ada004d5b59e Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 2 Aug 2011 09:15:04 +0100 Subject: [PATCH 053/300] Convert getParent error into exception for easier catching (as this is not a fatal error really) --- src/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commit.c b/src/commit.c index a494ae6e8b..0e713e7c99 100644 --- a/src/commit.c +++ b/src/commit.c @@ -359,7 +359,7 @@ PHP_METHOD(git_commit, getParent) ret = git_commit_parent(&commit, this->object,offset); if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_ERROR, "specified offset not found."); + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "specified offset not found"); RETURN_FALSE; } From 435679309a1ca7635b42430c7828a0c6adb361ad Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 10 Aug 2011 22:17:00 +0900 Subject: [PATCH 054/300] adjust git_signature_new signature and update libgit2 version. --- LIBGIT2_VERSION | 2 +- src/signature.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION index c20f8f0a11..d026b09c32 100644 --- a/LIBGIT2_VERSION +++ b/LIBGIT2_VERSION @@ -1 +1 @@ -37172582ec7ff9cb47c43c5d5b2334bf8c547569 \ No newline at end of file +c24ceffe61f15e0cb499de80b052a906ea5dc7cc \ No newline at end of file diff --git a/src/signature.c b/src/signature.c index 7b33be092f..80e4024957 100644 --- a/src/signature.c +++ b/src/signature.c @@ -177,7 +177,7 @@ int php_git_signature_create(zval *object, char *name, int name_len, char *email ZVAL_NULL(offset); ZVAL_STRING(&func2,"getOffset", 1); call_user_function(NULL,&time,&func2,offset,0,NULL TSRMLS_CC); - this->signature = git_signature_new(name,email,Z_LVAL_P(retval),Z_LVAL_P(offset)/60); + git_signature_new(&this->signature, name,email,Z_LVAL_P(retval),Z_LVAL_P(offset)/60); add_property_string_ex(object,"name", sizeof("name"), name, 1 TSRMLS_CC); add_property_string_ex(object,"email",sizeof("email"), email, 1 TSRMLS_CC); From c56b4633b17f7e3e0c7adb56b5428199c9763810 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 10 Aug 2011 22:24:07 +0900 Subject: [PATCH 055/300] use zend_function_entry insated of function_entry. --- src/backend.c | 2 +- src/blob.c | 2 +- src/commit.c | 2 +- src/config.c | 2 +- src/index.c | 2 +- src/index_entry.c | 2 +- src/index_iterator.c | 2 +- src/object.c | 2 +- src/odb.c | 2 +- src/php_git.c | 4 ++-- src/rawobject.c | 2 +- src/reference.c | 2 +- src/reference_manager.c | 2 +- src/repository.c | 2 +- src/signature.c | 2 +- src/tag.c | 2 +- src/tree.c | 2 +- src/tree_builder.c | 2 +- src/tree_entry.c | 2 +- src/tree_iterator.c | 2 +- src/walker.c | 2 +- 21 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/backend.c b/src/backend.c index e7864fd0e8..ef1127f614 100644 --- a/src/backend.c +++ b/src/backend.c @@ -305,7 +305,7 @@ PHP_METHOD(git_backend, __construct) this->backend = internal; } -PHPAPI function_entry php_git_backend_methods[] = { +static zend_function_entry php_git_backend_methods[] = { PHP_ME(git_backend, __construct, NULL, ZEND_ACC_PUBLIC) PHP_ABSTRACT_ME(git_backend, read, arginfo_git_backend_read) PHP_ABSTRACT_ME(git_backend, read_header, arginfo_git_backend_read_header) diff --git a/src/blob.c b/src/blob.c index aa6ca008b0..19ffa95d4e 100644 --- a/src/blob.c +++ b/src/blob.c @@ -153,7 +153,7 @@ PHP_METHOD(git_blob, write) RETVAL_STRING(oid_str,1); } -PHPAPI function_entry php_git_blob_methods[] = { +static zend_function_entry php_git_blob_methods[] = { PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC) PHP_ME(git_blob, loadString, arginfo_git_blob_load_string, ZEND_ACC_PUBLIC) PHP_ME(git_blob, loadFile, arginfo_git_blob_load_file, ZEND_ACC_PUBLIC) diff --git a/src/commit.c b/src/commit.c index 0e713e7c99..ab8575020f 100644 --- a/src/commit.c +++ b/src/commit.c @@ -379,7 +379,7 @@ PHP_METHOD(git_commit, getId) RETURN_STRING(id,1); } -PHPAPI function_entry php_git_commit_methods[] = { +static zend_function_entry php_git_commit_methods[] = { PHP_ME(git_commit, __construct, arginfo_git_commit__construct, ZEND_ACC_PUBLIC) PHP_ME(git_commit, getId, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_commit, setAuthor, arginfo_git_commit_set_author, ZEND_ACC_PUBLIC) diff --git a/src/config.c b/src/config.c index 88134595c1..9507ba501a 100644 --- a/src/config.c +++ b/src/config.c @@ -148,7 +148,7 @@ PHP_METHOD(git_config, parseFile) RETURN_ZVAL(zconf,0,1); } -PHPAPI function_entry php_git_config_methods[] = { +static zend_function_entry php_git_config_methods[] = { PHP_ME(git_config, parseFile, arginfo_git_config_parse_file, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) {NULL,NULL,NULL} }; diff --git a/src/index.c b/src/index.c index df9d727fd7..4d776b54dd 100644 --- a/src/index.c +++ b/src/index.c @@ -349,7 +349,7 @@ PHP_METHOD(git_index, insert) } */ -PHPAPI function_entry php_git_index_methods[] = { +static zend_function_entry php_git_index_methods[] = { //PHP_ME(git_index, __construct, arginfo_git_index__construct,ZEND_ACC_PUBLIC) PHP_ME(git_index, getEntry, arginfo_git_index_get_entry, ZEND_ACC_PUBLIC) PHP_ME(git_index, find, arginfo_git_index_find, ZEND_ACC_PUBLIC) diff --git a/src/index_entry.c b/src/index_entry.c index 8919846c8d..319199619c 100644 --- a/src/index_entry.c +++ b/src/index_entry.c @@ -56,7 +56,7 @@ zend_object_value php_git_index_entry_new(zend_class_entry *ce TSRMLS_DC) return retval; } -PHPAPI function_entry php_git_index_entry_methods[] = { +static zend_function_entry php_git_index_entry_methods[] = { {NULL, NULL, NULL} }; diff --git a/src/index_iterator.c b/src/index_iterator.c index 08477cdc59..39b1db8abf 100644 --- a/src/index_iterator.c +++ b/src/index_iterator.c @@ -123,7 +123,7 @@ PHP_METHOD(git_index_iterator, __construct) this->offset = 0; } -PHPAPI function_entry php_git_index_iterator_methods[] = { +static zend_function_entry php_git_index_iterator_methods[] = { PHP_ME(git_index_iterator, __construct, arginfo_git_index_iterator__construct,ZEND_ACC_PUBLIC) PHP_ME(git_index_iterator, current, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_index_iterator, key, NULL, ZEND_ACC_PUBLIC) diff --git a/src/object.c b/src/object.c index 7eab325a21..32a9a1fcbb 100644 --- a/src/object.c +++ b/src/object.c @@ -83,7 +83,7 @@ PHP_METHOD(git_object, getType) RETVAL_LONG(type); } -PHPAPI function_entry php_git_object_methods[] = { +static zend_function_entry php_git_object_methods[] = { PHP_ME(git_object, getId, NULL,ZEND_ACC_PUBLIC) PHP_ME(git_object, getType, NULL,ZEND_ACC_PUBLIC) {NULL, NULL, NULL} diff --git a/src/odb.c b/src/odb.c index 409090a430..df82e1e1c2 100644 --- a/src/odb.c +++ b/src/odb.c @@ -155,7 +155,7 @@ PHP_METHOD(git_odb, addAlternate) } -PHPAPI function_entry php_git_odb_methods[] = { +static zend_function_entry php_git_odb_methods[] = { PHP_ME(git_odb, __construct, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_odb, addBackend, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) PHP_ME(git_odb, addAlternate, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) diff --git a/src/php_git.c b/src/php_git.c index 920c847e69..f05f9976b8 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -272,12 +272,12 @@ PHP_FUNCTION(git_raw_to_hex) RETVAL_STRINGL(out,GIT_OID_HEXSZ,1); } -PHPAPI function_entry php_git_methods[] = { +static zend_function_entry php_git_methods[] = { {NULL, NULL, NULL} }; // Git Global Functions -PHPAPI function_entry php_git_functions[] = { +static zend_function_entry php_git_functions[] = { PHP_FE(git_hex_to_raw, arginfo_git_hex_to_raw) PHP_FE(git_raw_to_hex, arginfo_git_raw_to_hex) PHP_FE(git_type_to_string, arginfo_git_type_to_string) diff --git a/src/rawobject.c b/src/rawobject.c index f8a70956ca..a5004d4b88 100644 --- a/src/rawobject.c +++ b/src/rawobject.c @@ -25,7 +25,7 @@ #include "php_git.h" PHPAPI zend_class_entry *git_rawobject_class_entry; -PHPAPI function_entry php_git_rawobject_methods[] = { +static zend_function_entry php_git_rawobject_methods[] = { {NULL, NULL, NULL} }; diff --git a/src/reference.c b/src/reference.c index 6fe03b56e4..628c347572 100644 --- a/src/reference.c +++ b/src/reference.c @@ -221,7 +221,7 @@ PHP_METHOD(git_reference, getId) RETURN_STRINGL(&out,GIT_OID_HEXSZ, 1); } -PHPAPI function_entry php_git_reference_methods[] = { +static zend_function_entry php_git_reference_methods[] = { PHP_ME(git_reference, __construct, arginfo_git_reference__construct, ZEND_ACC_PUBLIC) PHP_ME(git_reference, getTarget, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_reference, getType, NULL, ZEND_ACC_PUBLIC) diff --git a/src/reference_manager.c b/src/reference_manager.c index 3d98423ffa..982a8dd3bd 100644 --- a/src/reference_manager.c +++ b/src/reference_manager.c @@ -279,7 +279,7 @@ PHP_METHOD(git_reference_manager, create) RETURN_ZVAL(ref,0,0); } -PHPAPI function_entry php_git_reference_manager_methods[] = { +static zend_function_entry php_git_reference_manager_methods[] = { PHP_ME(git_reference_manager, __construct, arginfo_git_reference_manager__construct, ZEND_ACC_PUBLIC) PHP_ME(git_reference_manager, getList, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_reference_manager, lookup, arginfo_git_reference_manager_lookup, ZEND_ACC_PUBLIC) diff --git a/src/repository.c b/src/repository.c index 3c606641c4..711f27c06e 100644 --- a/src/repository.c +++ b/src/repository.c @@ -648,7 +648,7 @@ PHP_METHOD(git_repository, getOdb) } -PHPAPI function_entry php_git_repository_methods[] = { +static zend_function_entry php_git_repository_methods[] = { PHP_ME(git_repository, __construct, arginfo_git_construct, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getCommit, arginfo_git_get_commit, ZEND_ACC_PUBLIC) PHP_ME(git_repository, getObject, arginfo_git_get_object, ZEND_ACC_PUBLIC) diff --git a/src/signature.c b/src/signature.c index 80e4024957..f72fe1f346 100644 --- a/src/signature.c +++ b/src/signature.c @@ -49,7 +49,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature__construct, 0, 0, 3) ZEND_ARG_INFO(0, when) ZEND_END_ARG_INFO() -PHPAPI function_entry php_git_signature_methods[] = { +static zend_function_entry php_git_signature_methods[] = { PHP_ME(git_signature, __construct, arginfo_git_signature__construct, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; diff --git a/src/tag.c b/src/tag.c index e0ffb04d92..d63c2dabfe 100644 --- a/src/tag.c +++ b/src/tag.c @@ -128,7 +128,7 @@ PHP_METHOD(git_tag, __construct) } -PHPAPI function_entry php_git_tag_methods[] = { +static zend_function_entry php_git_tag_methods[] = { PHP_ME(git_tag, __construct, arginfo_git_tag__construct, ZEND_ACC_PUBLIC) PHP_ME(git_tag, getMessage, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tag, getName, NULL, ZEND_ACC_PUBLIC) diff --git a/src/tree.c b/src/tree.c index 6094e70783..2f913aa814 100644 --- a/src/tree.c +++ b/src/tree.c @@ -280,7 +280,7 @@ PHP_METHOD(git_tree, resolve) } -PHPAPI function_entry php_git_tree_methods[] = { +static zend_function_entry php_git_tree_methods[] = { PHP_ME(git_tree, resolve, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree, __construct, arginfo_git_tree__construct, ZEND_ACC_PUBLIC) PHP_ME(git_tree, getEntry, arginfo_git_tree_get_entry, ZEND_ACC_PUBLIC) diff --git a/src/tree_builder.c b/src/tree_builder.c index 01263e96fb..5426ada091 100644 --- a/src/tree_builder.c +++ b/src/tree_builder.c @@ -175,7 +175,7 @@ PHP_METHOD(git_tree_builder,write) RETVAL_STRING(out, 1); } -PHPAPI function_entry php_git_tree_builder_methods[] = { +static zend_function_entry php_git_tree_builder_methods[] = { PHP_ME(git_tree_builder, __construct, arginfo_git_tree_builder__construct,ZEND_ACC_PUBLIC) PHP_ME(git_tree_builder, add, arginfo_git_tree_builder_add, ZEND_ACC_PUBLIC) PHP_ME(git_tree_builder, remove, arginfo_git_tree_builder_remove, ZEND_ACC_PUBLIC) diff --git a/src/tree_entry.c b/src/tree_entry.c index 4a5942237b..a55cfb3596 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -155,7 +155,7 @@ PHP_METHOD(git_tree_entry, toHeader) } } -PHPAPI function_entry php_git_tree_entry_methods[] = { +static zend_function_entry php_git_tree_entry_methods[] = { PHP_ME(git_tree_entry, __construct, NULL, ZEND_ACC_PRIVATE) PHP_ME(git_tree_entry, toHeader, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree_entry, toObject, NULL, ZEND_ACC_PUBLIC) diff --git a/src/tree_iterator.c b/src/tree_iterator.c index 8fe30519d1..f7ec89b7a3 100644 --- a/src/tree_iterator.c +++ b/src/tree_iterator.c @@ -125,7 +125,7 @@ PHP_METHOD(git_tree_iterator, __construct) } -PHPAPI function_entry php_git_tree_iterator_methods[] = { +static zend_function_entry php_git_tree_iterator_methods[] = { PHP_ME(git_tree_iterator, __construct, arginfo_git_tree_iterator__construct,ZEND_ACC_PUBLIC) PHP_ME(git_tree_iterator, current, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_tree_iterator, key, NULL, ZEND_ACC_PUBLIC) diff --git a/src/walker.c b/src/walker.c index 1b27e3f3b7..d80af15227 100644 --- a/src/walker.c +++ b/src/walker.c @@ -168,7 +168,7 @@ PHP_METHOD(git_walker, sort) RETURN_TRUE; } -PHPAPI function_entry php_git_walker_methods[] = { +static zend_function_entry php_git_walker_methods[] = { PHP_ME(git_walker, __construct, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_walker, push, arginfo_git_walker_push, ZEND_ACC_PUBLIC) PHP_ME(git_walker, next, NULL, ZEND_ACC_PUBLIC) From 48df8735ef8f8fafa04f72d47daa66e5ff9ac83c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 10 Aug 2011 23:24:48 +0900 Subject: [PATCH 056/300] adjusting ANSI-C syntax. (work in progress). C99 does not accept on Windows environment. so i'm adjusting these horrible variable declarations. --- src/backend.c | 31 ++++++----------- src/blob.c | 2 +- src/commit.c | 51 +++++++++++++--------------- src/config.c | 23 ++++--------- src/index.c | 31 ++++++++--------- src/index_iterator.c | 3 +- src/object.c | 2 +- src/odb.c | 2 +- src/php_git.c | 25 ++++++-------- src/php_git.h | 2 +- src/reference.c | 9 +++-- src/reference_manager.c | 41 +++++++++++----------- src/repository.c | 75 +++++++++++++++-------------------------- src/signature.c | 26 ++++++-------- src/tag.c | 22 ++++++------ src/tree.c | 39 ++++++++++----------- src/tree_builder.c | 6 ++-- src/tree_entry.c | 27 ++++++++------- src/tree_iterator.c | 4 ++- src/walker.c | 17 ++++++---- 20 files changed, 193 insertions(+), 245 deletions(-) diff --git a/src/backend.c b/src/backend.c index ef1127f614..92083a9f1b 100644 --- a/src/backend.c +++ b/src/backend.c @@ -93,10 +93,7 @@ int php_git_backend__exists(git_odb_backend *_backend, const git_oid *oid) php_git_backend_internal *object = (php_git_backend_internal *)_backend; char out[GIT_OID_HEXSZ+1] = {0}; git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - - zval *retval; - zval *params[1]; - zval func; + zval *retval, *params[1], func; int result; MAKE_STD_ZVAL(retval); @@ -130,11 +127,11 @@ int php_git_backend__write(git_oid *id, git_odb_backend *_backend, const void *b zval *retval; zval *params[1]; zval func; + MAKE_STD_ZVAL(retval); ZVAL_NULL(retval); ZVAL_STRING(&func,"write", 1); - MAKE_STD_ZVAL(params[0]); object_init_ex(params[0],git_rawobject_class_entry); @@ -171,10 +168,7 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba char out[GIT_OID_HEXSZ+1] = {0}; git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); int result = GIT_ERROR; - - zval *retval; - zval *params[1]; - zval func; + zval *str, *len, *tp, *retval, *params[1], func; MAKE_STD_ZVAL(retval); ZVAL_NULL(retval); @@ -202,9 +196,9 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba goto cleanup; } - zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC); - zval *len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); - zval *tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); + str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC); + len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); + tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); buffer = calloc(1,Z_LVAL_P(len)); memcpy(buffer,Z_STRVAL_P(str),Z_LVAL_P(len)); @@ -227,10 +221,7 @@ int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend * php_git_backend_internal *object = (php_git_backend_internal *)_backend; char out[GIT_OID_HEXSZ+1] = {0}; git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - - zval *retval; - zval *params[1]; - zval func; + zval *len, *tp, *retval, *params[1], func; MAKE_STD_ZVAL(retval); ZVAL_NULL(retval); @@ -251,8 +242,8 @@ int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend * return GIT_ENOTFOUND; } - zval *len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); - zval *tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); + len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); + tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); type = Z_LVAL_P(tp); size = Z_LVAL_P(len); @@ -267,11 +258,9 @@ int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend * void php_git_backend__free(git_odb_backend *backend) { TSRMLS_FETCH(); + zval func, *retval; php_git_backend_internal *object = (php_git_backend_internal *)backend; - zval *retval; - zval func; - MAKE_STD_ZVAL(retval); ZVAL_NULL(retval); diff --git a/src/blob.c b/src/blob.c index 19ffa95d4e..67c10c005b 100644 --- a/src/blob.c +++ b/src/blob.c @@ -131,6 +131,7 @@ PHP_METHOD(git_blob, loadString) PHP_METHOD(git_blob, write) { php_git_blob_t *this = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + char oid_str[GIT_OID_HEXSZ+1] = {0}; git_oid out; int ret = 0; @@ -148,7 +149,6 @@ PHP_METHOD(git_blob, write) } } - char oid_str[GIT_OID_HEXSZ+1] = {0}; git_oid_to_string(oid_str,GIT_OID_HEXSZ+1,&out); RETVAL_STRING(oid_str,1); } diff --git a/src/commit.c b/src/commit.c index ab8575020f..f1cfeb8a57 100644 --- a/src/commit.c +++ b/src/commit.c @@ -93,10 +93,10 @@ zend_object_value php_git_commit_new(zend_class_entry *ce TSRMLS_DC) PHP_METHOD(git_commit, __construct) { + zval *object = getThis(); zval *z_repository; git_commit *commit; git_repository *repository; - zval *object = getThis(); int ret; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -141,20 +141,19 @@ PHP_METHOD(git_commit, getShortMessage) PHP_METHOD(git_commit, getTree) { php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_tree *ref_tree; + git_tree *ref_tree, *tree; + git_oid *tree_oid; + zval *git_tree, *entry; + + const git_oid *oid = git_object_id((git_object*)ref_tree); git_commit_tree(&ref_tree, this->object); - const git_oid *oid = git_object_id((git_object*)ref_tree); - git_tree *tree; int ret = git_object_lookup((git_object **)&tree, git_object_owner((git_object*)this->object),oid, GIT_OBJ_TREE); if(ret != GIT_SUCCESS) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "specified tree not found."); return; } - git_oid *tree_oid; - zval *git_tree; - zval *entry; MAKE_STD_ZVAL(git_tree); object_init_ex(git_tree, git_tree_class_entry); @@ -232,12 +231,16 @@ PHP_METHOD(git_commit, setParents) PHP_METHOD(git_commit, write) { php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_oid oid; - php_git_signature_t *author; - php_git_signature_t *committer; + git_oid oid, tree_oid, **parents, **p, *tmp; + php_git_signature_t *author, *committer; + zval *z_author, *z_committer, *z_parents, **data; + char *update_ref, *message, *tree_oid_str = NULL; + char out[GIT_OID_HEXSZ+1]; + int count, i, update_ref_len = 0; + git_reference *ref; - char *update_ref = NULL; - int update_ref_len = 0; + HashTable *array_hash; + HashPosition pointer; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &update_ref,&update_ref_len) == FAILURE){ @@ -245,7 +248,6 @@ PHP_METHOD(git_commit, write) } if(ZEND_NUM_ARGS() == 0) { - git_reference *ref; if(git_reference_lookup(&ref,this->repository,"HEAD")==GIT_SUCCESS){ if (git_reference_type(ref) == GIT_REF_SYMBOLIC) { git_reference *ref2; @@ -258,27 +260,22 @@ PHP_METHOD(git_commit, write) } - git_oid tree_oid; - char *tree_oid_str = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"tree",sizeof("tree")-1, 0 TSRMLS_CC)); + tree_oid_str = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"tree",sizeof("tree")-1, 0 TSRMLS_CC)); git_oid_fromstr(&tree_oid, tree_oid_str); - zval *z_author = zend_read_property(git_commit_class_entry, getThis(),"author",sizeof("author")-1, 0 TSRMLS_CC); + z_author = zend_read_property(git_commit_class_entry, getThis(),"author",sizeof("author")-1, 0 TSRMLS_CC); author = (php_git_signature_t *) zend_object_store_get_object(z_author TSRMLS_CC); - zval *z_committer = zend_read_property(git_commit_class_entry, getThis(),"committer",sizeof("committer")-1, 0 TSRMLS_CC); + z_committer = zend_read_property(git_commit_class_entry, getThis(),"committer",sizeof("committer")-1, 0 TSRMLS_CC); committer = (php_git_signature_t *) zend_object_store_get_object(z_committer TSRMLS_CC); - zval *z_parents = zend_read_property(git_commit_class_entry, getThis(),"parents",sizeof("parents")-1, 0 TSRMLS_CC); + z_parents = zend_read_property(git_commit_class_entry, getThis(),"parents",sizeof("parents")-1, 0 TSRMLS_CC); - int count = zend_hash_num_elements(Z_ARRVAL_P(z_parents)); + count = zend_hash_num_elements(Z_ARRVAL_P(z_parents)); - HashTable *array_hash = Z_ARRVAL_P(z_parents); - HashPosition pointer; - git_oid *tmp; - zval **data; - git_oid **p; - git_oid **parents = (git_oid**)calloc(count,sizeof(git_oid)); + array_hash = Z_ARRVAL_P(z_parents); + parents = (git_oid**)calloc(count,sizeof(git_oid)); p = parents; for (zend_hash_internal_pointer_reset_ex(array_hash, &pointer); @@ -293,7 +290,7 @@ PHP_METHOD(git_commit, write) p++; } - char *message = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"message",sizeof("message")-1, 0 TSRMLS_CC)); + message = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"message",sizeof("message")-1, 0 TSRMLS_CC)); git_commit_create(&oid, this->repository, update_ref, @@ -305,10 +302,8 @@ PHP_METHOD(git_commit, write) parents ); - char out[GIT_OID_HEXSZ+1]; git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); - int i; for(i = 0; i < count;i++){ free(parents[i]); } diff --git a/src/config.c b/src/config.c index 9507ba501a..eb8ead2d40 100644 --- a/src/config.c +++ b/src/config.c @@ -60,27 +60,21 @@ ZEND_END_ARG_INFO() typedef struct{ zval *array; - git_config *config + git_config *config; } git_config_foreach_t; static int php_git_config_foreach(const char *key, void *data) { - zval *config = ((git_config_foreach_t*)data)->array; - HashTable *hash = Z_ARRVAL_P(config); - zval **target_key; - zval *moe_key; - - char *tmp = estrdup(key); - - char *current_key; - char *uu; - char *value; + HashTable *hash; + zval *config, *moe_key, *moe, **target_key; + char *savedptr, *current_key, *uu, *value, *tmp; + config = ((git_config_foreach_t*)data)->array; + hash = Z_ARRVAL_P(config); + tmp = estrdup(key); git_config_get_string(((git_config_foreach_t *)data)->config,key,&value); - char *savedptr; - current_key = php_strtok_r(tmp, ".",&savedptr); while (current_key != NULL) { uu = current_key; @@ -100,7 +94,6 @@ static int php_git_config_foreach(const char *key, void *data) } if(uu != NULL) { - zval *moe; MAKE_STD_ZVAL(moe); ZVAL_STRING(moe,value,1); zval_copy_ctor(&moe); @@ -108,7 +101,6 @@ static int php_git_config_foreach(const char *key, void *data) } efree(tmp); - return GIT_SUCCESS; } @@ -117,7 +109,6 @@ PHP_METHOD(git_config, parseFile) git_config_foreach_t t; git_config *config; zval *zconf; - char *path; int path_len = 0; int ret = GIT_ERROR; diff --git a/src/index.c b/src/index.c index 4d776b54dd..75a24df076 100644 --- a/src/index.c +++ b/src/index.c @@ -91,8 +91,9 @@ ZEND_END_ARG_INFO() void php_git_index_entry_create(zval **index, git_index_entry *entry) { TSRMLS_FETCH(); - MAKE_STD_ZVAL(*index); char oid[GIT_OID_HEXSZ+1] = {0}; + + MAKE_STD_ZVAL(*index); object_init_ex(*index,git_index_entry_class_entry); git_oid_to_string(oid,GIT_OID_HEXSZ+1,&entry->oid); @@ -120,9 +121,8 @@ PHP_METHOD(git_index, count) PHP_METHOD(git_index, find) { - int offset = 0; + int offset, path_len = 0; char *path; - int path_len = 0; git_index *index = NULL; git_index_entry *entry; zval *z_git_index_entry; @@ -169,11 +169,10 @@ PHP_METHOD(git_index, getEntry) PHP_METHOD(git_index, add) { - int offset = 0; + int path_len, success, offset = 0; + long stage = 0; char *path; - int path_len = 0; git_index *index = NULL; - long stage = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &path_len, &stage) == FAILURE){ @@ -183,11 +182,8 @@ PHP_METHOD(git_index, add) php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); index = myobj->index; - //FIXME: examine stage value. - // 0 => new file - // 1 => deleted ? - // 2 => ? - int success = git_index_add(index,path,stage); + // Todo: check stage status. + success = git_index_add(index,path,stage); if(success != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "can't add specified index."); @@ -200,22 +196,22 @@ PHP_METHOD(git_index, add) PHP_METHOD(git_index, remove) { php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + int path_len, offset, result = 0; char *path; - int path_len = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE){ return; } - int offset = git_index_find(this->index,path); + offset = git_index_find(this->index,path); if(offset < 0){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "specified path does not exist."); RETURN_FALSE; } - int result = git_index_remove(this->index, offset); + result = git_index_remove(this->index, offset); if(result != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "specified offset does not exist."); @@ -228,8 +224,8 @@ PHP_METHOD(git_index, remove) PHP_METHOD(git_index, update) { php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int success = git_index_write(myobj->index); + if(success != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "can't write index"); @@ -244,8 +240,8 @@ PHP_METHOD(git_index, refresh) { git_index *index = NULL; php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - index = myobj->index; + index = myobj->index; git_index_read(index); } @@ -267,8 +263,9 @@ PHP_METHOD(git_index, writeTree) php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_oid oid; char out[GIT_OID_HEXSZ+1]; + int ret; - int ret = git_tree_create_fromindex(&oid, this->index); + ret = git_tree_create_fromindex(&oid, this->index); if(ret != GIT_SUCCESS) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "can't write tree from index."); diff --git a/src/index_iterator.c b/src/index_iterator.c index 39b1db8abf..312ce23b39 100644 --- a/src/index_iterator.c +++ b/src/index_iterator.c @@ -112,12 +112,13 @@ PHP_METHOD(git_index_iterator, __construct) { php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); zval *php_git_index; + php_git_index_t *idx; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &php_git_index) == FAILURE){ return; } - php_git_index_t *idx = (php_git_index_t *) zend_object_store_get_object(php_git_index TSRMLS_CC); + idx = (php_git_index_t *) zend_object_store_get_object(php_git_index TSRMLS_CC); this->index = idx->index; this->offset = 0; diff --git a/src/object.c b/src/object.c index 32a9a1fcbb..55cedd98b8 100644 --- a/src/object.c +++ b/src/object.c @@ -64,8 +64,8 @@ zend_object_value php_git_object_new(zend_class_entry *ce TSRMLS_DC) PHP_METHOD(git_object, getId) { php_git_object_t *this = (php_git_object_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + char out[GIT_OID_HEXSZ+1] = {0}; const git_oid *oid; - char out[41] = {0}; oid = git_object_id((git_object *)this->object); git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); diff --git a/src/odb.c b/src/odb.c index df82e1e1c2..461991eeb9 100644 --- a/src/odb.c +++ b/src/odb.c @@ -71,8 +71,8 @@ PHP_METHOD(git_odb, __construct) php_git_odb_t *this = (php_git_odb_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_odb *odb; zval *backends; - int ret = 0; + ret = git_odb_new(&this->odb); if(ret != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create Git\\ODB"); diff --git a/src/php_git.c b/src/php_git.c index f05f9976b8..5064f646cf 100644 --- a/src/php_git.c +++ b/src/php_git.c @@ -101,6 +101,8 @@ int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC) void php_git_commit_init(zval **object, git_commit *commit, git_repository *repository TSRMLS_DC) { zval *author, *committer; + int i, parent_count; + zval *parents; MAKE_STD_ZVAL(*object); object_init_ex(*object,git_commit_class_entry); @@ -112,10 +114,7 @@ void php_git_commit_init(zval **object, git_commit *commit, git_repository *repo cobj->object = commit; cobj->repository = repository; - - int parent_count = git_commit_parentcount(commit); - int i; - zval *parents; + parent_count = git_commit_parentcount(commit); MAKE_STD_ZVAL(parents); array_init(parents); for (i = 0; i < parent_count; i++) { @@ -134,18 +133,14 @@ int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_r { const git_tree_entry *entry; git_tree *tmp = tree; - int attribute, length, offset, position, len; + int c, i, attribute, length, offset, position, len = 0; char buffer[256]; - memset(buffer,'\0',256); char *p; - offset = 0; - position = 0; - len = 0; + int ret = GIT_ERROR; length = strlen(path); p = path; - int ret = GIT_ERROR; - + memset(buffer,'\0',256); while (position < length) { if(path[position] == '/') { memcpy(buffer,p, position-offset); @@ -169,8 +164,8 @@ int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_r memset(buffer,'\0',256); memcpy(buffer,p, position+1-offset); - int c = git_tree_entrycount(tmp); - int i = 0; + c = git_tree_entrycount(tmp); + i = 0; for(i =0; i < c; i++){ git_tree_entry *e = git_tree_entry_byindex(tmp,i); } @@ -242,9 +237,9 @@ PHP_FUNCTION(git_type_to_string) PHP_FUNCTION(git_hex_to_raw) { git_oid oid; - const char *hex = NULL; int hex_len = 0; + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hex, &hex_len) == FAILURE){ return; @@ -258,7 +253,7 @@ PHP_FUNCTION(git_raw_to_hex) { git_oid oid; const char *raw = NULL; - char out[GIT_OID_HEXSZ]; + char out[GIT_OID_HEXSZ+1]; int raw_len = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s", diff --git a/src/php_git.h b/src/php_git.h index 77ea30511d..48dd5421e0 100644 --- a/src/php_git.h +++ b/src/php_git.h @@ -189,7 +189,7 @@ typedef struct{ typedef struct{ zend_object zo; - git_config *config + git_config *config; } php_git_config_t; diff --git a/src/reference.c b/src/reference.c index 628c347572..11807eb0bb 100644 --- a/src/reference.c +++ b/src/reference.c @@ -78,10 +78,11 @@ PHP_METHOD(git_reference, getTarget) { php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_rtype type; + const char *target; type = git_reference_type(this->object); if(type == GIT_REF_SYMBOLIC) { - const char *target = git_reference_target(this->object); + target = git_reference_target(this->object); // FIXME: this method only available if the reference is symbolic. if(target != NULL) { add_property_string_ex(getThis() ,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); @@ -180,6 +181,7 @@ PHP_METHOD(git_reference, __construct) git_rtype type; git_reference *refs; int res = 0; + const char *target; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_repo) == FAILURE){ @@ -200,7 +202,7 @@ PHP_METHOD(git_reference, __construct) type = git_reference_type(refs); if(type == GIT_REF_SYMBOLIC) { - const char *target = git_reference_target(refs); + target = git_reference_target(refs); if(target != NULL) { add_property_string_ex(getThis() ,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); RETVAL_STRING(Z_STRVAL_P(zend_read_property(git_reference_class_entry,getThis(),"target",sizeof("target")-1,1 TSRMLS_CC)),0); @@ -214,9 +216,10 @@ PHP_METHOD(git_reference, __construct) PHP_METHOD(git_reference, getId) { php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_oid *oid = git_reference_oid(this->object); char out[GIT_OID_HEXSZ+1] = {0}; + git_oid *oid; + oid = git_reference_oid(this->object); git_oid_to_string(&out, GIT_OID_HEXSZ+1, oid); RETURN_STRINGL(&out,GIT_OID_HEXSZ, 1); } diff --git a/src/reference_manager.c b/src/reference_manager.c index 982a8dd3bd..3410fdb8f5 100644 --- a/src/reference_manager.c +++ b/src/reference_manager.c @@ -74,6 +74,8 @@ PHP_METHOD(git_reference_manager, __construct) { php_git_reference_manager_t *this= (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); zval *repository; + php_git_repository_t *repo; + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &repository) == FAILURE){ return; @@ -83,7 +85,8 @@ PHP_METHOD(git_reference_manager, __construct) "argument does not Git\\Repository"); RETURN_FALSE; } - php_git_repository_t *repo = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC); + + repo = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC); if(repo->repository == NULL){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "repository didn't ready"); @@ -96,20 +99,19 @@ PHP_METHOD(git_reference_manager, getList) { php_git_reference_manager_t *this= (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_strarray *list = malloc(sizeof(git_strarray)); - int result; - int i = 0; + int rr, result, i = 0; git_reference *reference; zval *references; git_rtype type; + const char *target; char out[GIT_OID_HEXSZ+1] = {0}; + zval *ref; git_reference_listall(list,this->repository,GIT_REF_LISTALL); MAKE_STD_ZVAL(references); array_init(references); for(i = 0; i < list->count; i++){ - zval *ref; - // FIXME result = git_reference_lookup(&reference, this->repository, list->strings[i]); if(result != GIT_SUCCESS) { @@ -127,11 +129,11 @@ PHP_METHOD(git_reference_manager, getList) type = git_reference_type(reference); if(type == GIT_REF_SYMBOLIC) { - const char *target = git_reference_target(reference); + target = git_reference_target(reference); if(target != NULL) { add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); } - int rr = git_reference_resolve(&refobj->object,reference); + rr = git_reference_resolve(&refobj->object,reference); if(rr != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "something wrong"); @@ -142,7 +144,6 @@ PHP_METHOD(git_reference_manager, getList) git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); memset(out,'\0',GIT_OID_HEXSZ+1); - // add_next_index_zval(references, ref); } @@ -167,8 +168,7 @@ PHP_METHOD(git_reference_manager, lookup) { php_git_reference_manager_t *this = (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); char *name; - int name_len = 0; - int result; + int rr, result, name_len = 0; zval *ref; char out[GIT_OID_HEXSZ+1] = {0}; git_oid *oid; @@ -200,7 +200,7 @@ PHP_METHOD(git_reference_manager, lookup) if(target != NULL) { add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); } - int rr = git_reference_resolve(&refobj->object,reference); + rr = git_reference_resolve(&refobj->object,reference); if(rr != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "something wrong"); @@ -220,9 +220,15 @@ PHP_METHOD(git_reference_manager, create) char *name; int name_len = 0; char *oid; - int oid_len = 0; + int ret,rr, oid_len = 0; git_oid id; zend_bool force = 0; + git_odb *odb; + git_reference *reference; + char out[GIT_OID_HEXSZ+1] = {0}; + git_rtype type; + zval *ref; + const char *target; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &name, &name_len, &oid, &oid_len, &force) == FAILURE){ @@ -235,7 +241,6 @@ PHP_METHOD(git_reference_manager, create) } git_oid_fromstr(&id, oid); - git_odb *odb; odb = git_repository_database(this->repository); if(!git_odb_exists(odb,&id)){ @@ -244,17 +249,13 @@ PHP_METHOD(git_reference_manager, create) RETURN_FALSE; } - git_reference *reference; - int ret = git_reference_create_oid(&reference, this->repository, name, &id, force); + ret = git_reference_create_oid(&reference, this->repository, name, &id, force); if(ret != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "can't add reference, maybe try setting force to boolean true"); RETURN_FALSE; } - char out[GIT_OID_HEXSZ+1] = {0}; - git_rtype type; - zval *ref; MAKE_STD_ZVAL(ref); object_init_ex(ref, git_reference_class_entry); php_git_reference_t *refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC); @@ -263,11 +264,11 @@ PHP_METHOD(git_reference_manager, create) add_property_string_ex(ref,"name", sizeof("name"), name, 1 TSRMLS_CC); type = git_reference_type(reference); if(type == GIT_REF_SYMBOLIC) { - const char *target = git_reference_target(reference); + target = git_reference_target(reference); if(target != NULL) { add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); } - int rr = git_reference_resolve(&refobj->object,reference); + rr = git_reference_resolve(&refobj->object,reference); if(rr != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "something wrong"); diff --git a/src/repository.c b/src/repository.c index 711f27c06e..cbc3f682cf 100644 --- a/src/repository.c +++ b/src/repository.c @@ -126,9 +126,7 @@ PHP_METHOD(git_repository, init) git_repository *repository; zval *obj,*backends,*odb; char *path = NULL; - int path_len = 0; - int is_bare = 0; - int ret; + int ret, is_bare, path_len = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"sl", &path, &path_len, &is_bare) == FAILURE){ @@ -156,12 +154,13 @@ PHP_METHOD(git_repository, init) PHP_METHOD(git_repository, getIndex) { zval *object = getThis(); + php_git_repository_t *myobj; git_repository *repository; git_index *index; zval *index_object; int error = 0; - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); + myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); error = git_repository_index(&index,myobj->repository); if (error != GIT_SUCCESS) { @@ -197,8 +196,7 @@ PHP_METHOD(git_repository, getObject) git_oid oid; char *hash; - int hash_len = 0; - int ret = 0; + int ret, hash_len = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE){ @@ -238,6 +236,7 @@ void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repo TSRMLS_FETCH(); char buf[GIT_OID_HEXSZ+1] = {0}; const git_oid *oid; + MAKE_STD_ZVAL(*object); object_init_ex(*object, git_tree_entry_class_entry); php_git_tree_entry_t *entry_obj = (php_git_tree_entry_t *) zend_object_store_get_object(*object TSRMLS_CC); @@ -257,14 +256,12 @@ PHP_METHOD(git_repository, getCommit) php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); zval *git_commit_object; git_repository *repository; - git_odb *odb; git_object *blob; git_oid oid; char out[GIT_OID_HEXSZ+1] = {0}; char *hash; - int hash_len = 0; - int ret = 0; + int ret, hash_len = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE){ @@ -289,11 +286,10 @@ PHP_METHOD(git_repository, getCommit) PHP_METHOD(git_repository, __construct) { const char *repository_path = NULL; - int ret = 0; - int arg_len = 0; + int arg_len, ret = 0; git_repository *repository; - zval *object = getThis(); - zval *odb, *backends; + zval *odb, *backends, *object; + object = getThis(); if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &repository_path, &arg_len) == FAILURE){ @@ -324,15 +320,13 @@ PHP_METHOD(git_repository, getTree) zval *object = getThis(); git_tree *tree; zval *git_tree; - + php_git_tree_t *tobj; git_oid oid; char *hash; - int hash_len = 0; - int ret = 0; + int i, ret, hash_len = 0; git_tree_entry *entry; php_git_tree_entry_t *te; char buf[GIT_OID_HEXSZ+1] = {0}; - int i = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE){ @@ -352,7 +346,7 @@ PHP_METHOD(git_repository, getTree) MAKE_STD_ZVAL(git_tree); object_init_ex(git_tree, git_tree_class_entry); - php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); + tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); tobj->object = tree; tobj->repository = myobj->repository; @@ -384,7 +378,7 @@ PHP_METHOD(git_repository, addAlternate) zval *backend; git_odb *odb; git_odb_backend *odb_backend; - int priority = 0; + int ret, priority = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){ return; @@ -397,17 +391,16 @@ PHP_METHOD(git_repository, addAlternate) } odb = git_repository_database(this->repository); - int ret = php_git_odb_add_alternate(&odb, backend, priority); + ret = php_git_odb_add_alternate(&odb, backend, priority); } PHP_METHOD(git_repository, addBackend) { php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *backend; + zval **data, *backend; git_odb *odb; git_odb_backend *odb_backend; - zval **data; int priority = 0; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){ @@ -439,8 +432,7 @@ PHP_METHOD(git_repository, lookupRef) { php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); char *name; - int name_len = 0; - int result; + int rr, result, name_len = 0; zval *ref; char out[GIT_OID_HEXSZ+1] = {0}; git_oid *oid; @@ -472,7 +464,7 @@ PHP_METHOD(git_repository, lookupRef) if(target != NULL) { add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); } - int rr = git_reference_resolve(&refobj->object,reference); + rr = git_reference_resolve(&refobj->object,reference); if(rr != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "something wrong"); @@ -490,21 +482,19 @@ PHP_METHOD(git_repository, getReferences) { php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_strarray *list = malloc(sizeof(git_strarray)); - int result; - int i = 0; + int rr, i, result = 0; git_reference *reference; zval *references; git_rtype type; char out[GIT_OID_HEXSZ+1] = {0}; + const char *target; + zval *ref; git_reference_listall(list,this->repository,GIT_REF_LISTALL); MAKE_STD_ZVAL(references); array_init(references); for(i = 0; i < list->count; i++){ - zval *ref; - - // FIXME result = git_reference_lookup(&reference, this->repository, list->strings[i]); if(result != GIT_SUCCESS) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, @@ -521,11 +511,11 @@ PHP_METHOD(git_repository, getReferences) type = git_reference_type(reference); if(type == GIT_REF_SYMBOLIC) { - const char *target = git_reference_target(reference); + target = git_reference_target(reference); if(target != NULL) { add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); } - int rr = git_reference_resolve(&refobj->object,reference); + rr = git_reference_resolve(&refobj->object,reference); if(rr != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "something wrong"); @@ -536,7 +526,6 @@ PHP_METHOD(git_repository, getReferences) git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); memset(out,'\0',GIT_OID_HEXSZ+1); - // add_next_index_zval(references, ref); } @@ -548,15 +537,9 @@ PHP_METHOD(git_repository, getReferences) PHP_METHOD(git_repository, open3) { php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - - char *git_dir; - int git_dir_len = 0; + char *git_dir, *tree, *index = NULL; + int git_dir_len, index_len, ret, tree_len = 0; zval *z_odb; - char *index = NULL; - int index_len = 0; - char *tree = NULL; - int tree_len = 0; - int ret = 0; php_git_odb_t *odbt = NULL; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -587,11 +570,7 @@ PHP_METHOD(git_repository, open2) { php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); char *git_dir,*git_object_directory,*git_index_file,*git_work_tree; - - int git_dir_len = 0; - int git_object_directory_len = 0; - int git_index_file_len = 0; - int git_work_tree_len = 0; + int ret, git_work_tree_len, git_index_file_len, git_object_directory_len, git_dir_len = 0; git_repository *repository; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -604,7 +583,7 @@ PHP_METHOD(git_repository, open2) return; } - int ret = git_repository_open2(&repository,git_dir, git_object_directory, git_index_file, git_work_tree); + ret = git_repository_open2(&repository,git_dir, git_object_directory, git_index_file, git_work_tree); if(ret != GIT_SUCCESS){ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,git_strerror(ret)); RETURN_FALSE; @@ -618,8 +597,8 @@ PHP_METHOD(git_repository, open2) PHP_METHOD(git_repository, getWorkdir) { - php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); char *git_workdir; + php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); if(this->repository != NULL) { git_workdir = git_repository_path(this->repository,GIT_REPO_PATH_WORKDIR); diff --git a/src/signature.c b/src/signature.c index f72fe1f346..712d030b47 100644 --- a/src/signature.c +++ b/src/signature.c @@ -56,10 +56,8 @@ static zend_function_entry php_git_signature_methods[] = { PHP_METHOD(git_signature, __construct) { - char *name; - char *email; - int name_len = 0; - int email_len = 0; + char *email, *name; + int email_len, name_len = 0; zval *time; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -94,21 +92,20 @@ void git_init_signature(TSRMLS_D) void create_signature_from_commit(zval **signature, git_signature *sig) { TSRMLS_FETCH(); - zval *datetime; + zval *params[1], *datetime, constructor, method, result; + php_git_signature_t *object; + MAKE_STD_ZVAL(*signature); object_init_ex(*signature,git_signature_class_entry); - php_git_signature_t *object = (php_git_signature_t *) zend_object_store_get_object(*signature TSRMLS_CC); + object = (php_git_signature_t *) zend_object_store_get_object(*signature TSRMLS_CC); object->signature = sig; add_property_string_ex(*signature,"name",sizeof("name"), sig->name,1 TSRMLS_CC); add_property_string_ex(*signature,"email",sizeof("email"),sig->email,1 TSRMLS_CC); MAKE_STD_ZVAL(datetime); - zval constructor; - zval method; - zval result; - zval *params[1]; + ZVAL_STRING(&constructor,"__construct",0); ZVAL_STRING(&method,"setTimestamp", 0); @@ -161,13 +158,10 @@ int php_git_signature_create(zval *object, char *name, int name_len, char *email { TSRMLS_FETCH(); php_git_signature_t *this = (php_git_signature_t *) zend_object_store_get_object(object TSRMLS_CC); + zval *retval, *offset, func, func2; int ret = 0; - // Todo: should use `zend_fcall*` instead of `call_user-function` for performance improvement. - zval *retval; - zval *offset; - zval func; - zval func2; + // Todo: should use `zend_fcall*` instead of `call_user-function` for performance improvement. ZVAL_STRING(&func,"getTimestamp", 1); MAKE_STD_ZVAL(retval); ZVAL_NULL(retval); @@ -177,7 +171,7 @@ int php_git_signature_create(zval *object, char *name, int name_len, char *email ZVAL_NULL(offset); ZVAL_STRING(&func2,"getOffset", 1); call_user_function(NULL,&time,&func2,offset,0,NULL TSRMLS_CC); - git_signature_new(&this->signature, name,email,Z_LVAL_P(retval),Z_LVAL_P(offset)/60); + git_signature_new(&this->signature, name,email,Z_LVAL_P(retval),Z_LVAL_P(offset)/60); add_property_string_ex(object,"name", sizeof("name"), name, 1 TSRMLS_CC); add_property_string_ex(object,"email",sizeof("email"), email, 1 TSRMLS_CC); diff --git a/src/tag.c b/src/tag.c index d63c2dabfe..4384ed2c96 100644 --- a/src/tag.c +++ b/src/tag.c @@ -60,20 +60,20 @@ static void php_git_tag_free_storage(php_git_tag_t *obj TSRMLS_DC) zend_object_value php_git_tag_new(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; - php_git_tag_t *obj; - zval *tmp; + zend_object_value retval; + php_git_tag_t *obj; + zval *tmp; - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + obj = ecalloc(1, sizeof(*obj)); + zend_object_std_init( &obj->zo, ce TSRMLS_CC ); + zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - retval.handle = zend_objects_store_put(obj, + retval.handle = zend_objects_store_put(obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)php_git_tag_free_storage, NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; + retval.handlers = zend_get_std_object_handlers(); + return retval; } PHP_METHOD(git_tag, getMessage) @@ -106,6 +106,7 @@ PHP_METHOD(git_tag, __construct) php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC); php_git_repository_t *r_obj; zval *repository; + int ret; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &repository) == FAILURE){ @@ -119,8 +120,7 @@ PHP_METHOD(git_tag, __construct) return; } r_obj = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC); - - int ret = git_tag_new(&this->object,r_obj->repository); + ret = git_tag_new(&this->object,r_obj->repository); if(ret != GIT_SUCCESS){ php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't create Git\\Tag."); diff --git a/src/tree.c b/src/tree.c index 2f913aa814..7264713529 100644 --- a/src/tree.c +++ b/src/tree.c @@ -93,13 +93,15 @@ PHP_METHOD(git_tree, count) PHP_METHOD(git_tree, path) { - //TODO php_git_tree_t *this= (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); char *path; - int path_len= 0; + git_tree *tree; + int ret, path_len= 0; git_tree_entry *entry; - int ret = 0; git_object *object; + php_git_blob_t *blobobj; + zval *git_tree, *entries, *git_object; + git_oid *tree_oid; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE){ @@ -120,11 +122,7 @@ PHP_METHOD(git_tree, path) if(type == GIT_OBJ_TREE) { // Todo: refactoring below block - git_tree *tree = (git_tree*)object; - git_oid *tree_oid; - zval *git_tree; - zval *entries; - zval *entry; + tree = object; MAKE_STD_ZVAL(git_tree); MAKE_STD_ZVAL(entries); @@ -143,10 +141,9 @@ PHP_METHOD(git_tree, path) }else if(type == GIT_OBJ_BLOB){ // Todo: refactoring below block - zval *git_object; MAKE_STD_ZVAL(git_object); object_init_ex(git_object, git_blob_class_entry); - php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC); + blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC); blobobj->object = (git_blob *)object; add_property_stringl_ex(git_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); @@ -207,13 +204,13 @@ PHP_METHOD(git_tree, getEntries) { php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_tree_entry *entry; - int i; + zval *array_ptr,*entries; + int i, r; - int r = git_tree_entrycount(this->object); - zval *entries; + r = git_tree_entrycount(this->object); + MAKE_STD_ZVAL(entries); array_init(entries); - zval *array_ptr; for(i = 0; i < r; i++){ create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(this->object,i),this->repository); add_next_index_zval(entries, array_ptr); @@ -229,10 +226,12 @@ PHP_METHOD(git_tree, resolve) git_tree_entry *entry; git_object *object; git_otype type; - int ret; + git_tree *tree; + php_git_tree_t *tobj; + int path_len, ret; char *path; - int path_len; - + zval *git_raw_object, *git_tree; + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE){ return; @@ -251,7 +250,6 @@ PHP_METHOD(git_tree, resolve) type = git_object_type(object); if (type == GIT_OBJ_BLOB) { - zval *git_raw_object; MAKE_STD_ZVAL(git_raw_object); object_init_ex(git_raw_object, git_blob_class_entry); php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_raw_object TSRMLS_CC); @@ -260,13 +258,12 @@ PHP_METHOD(git_tree, resolve) add_property_stringl_ex(git_raw_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); RETURN_ZVAL(git_raw_object,0,1); } else if(type == GIT_OBJ_TREE) { - git_tree *tree = (git_tree *)object; + tree = object; - zval *git_tree; MAKE_STD_ZVAL(git_tree); object_init_ex(git_tree, git_tree_class_entry); - php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); + tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); tobj->object = tree; tobj->repository = this->repository; diff --git a/src/tree_builder.c b/src/tree_builder.c index 5426ada091..023386fde2 100644 --- a/src/tree_builder.c +++ b/src/tree_builder.c @@ -106,10 +106,8 @@ PHP_METHOD(git_tree_builder,add) { php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); int error = GIT_ERROR; - char *path; - char *hash; - int path_len = 0; - int hash_len = 0; + char *hash, *path; + int hash_len, path_len = 0; unsigned int attributes; git_oid id; diff --git a/src/tree_entry.c b/src/tree_entry.c index a55cfb3596..9ff680f2a9 100644 --- a/src/tree_entry.c +++ b/src/tree_entry.c @@ -63,17 +63,20 @@ zend_object_value php_git_tree_entry_new(zend_class_entry *ce TSRMLS_DC) PHP_METHOD(git_tree_entry, toObject) { - php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + php_git_tree_entry_t *this; git_object *object; git_otype type; + zval *git_raw_object, *git_tree; + php_git_tree_t *tobj; + int ret; - int ret = git_tree_entry_2object(&object, this->repository, this->entry); + this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + + ret = git_tree_entry_2object(&object, this->repository, this->entry); if(ret == GIT_SUCCESS){ type = git_object_type(object); if (type == GIT_OBJ_BLOB) { - - zval *git_raw_object; MAKE_STD_ZVAL(git_raw_object); object_init_ex(git_raw_object, git_blob_class_entry); php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_raw_object TSRMLS_CC); @@ -82,19 +85,17 @@ PHP_METHOD(git_tree_entry, toObject) add_property_stringl_ex(git_raw_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); RETURN_ZVAL(git_raw_object,0,1); } else if(type == GIT_OBJ_TREE) { - git_tree *tree = (git_tree *)object; - zval *git_tree; MAKE_STD_ZVAL(git_tree); object_init_ex(git_tree, git_tree_class_entry); - php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); - tobj->object = tree; + tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); + tobj->object = object; tobj->repository = this->repository; RETURN_ZVAL(git_tree,0,1); - } else{ + } else { zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Git\\Tree\\Entry::toObject can convert GIT_OBJ_TREE or GIT_OBJ_BLOB. unhandled object type %d found.", git_object_type(object)); RETURN_FALSE; @@ -111,6 +112,7 @@ PHP_METHOD(git_tree_entry, isTree) { php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); int attribute = git_tree_entry_attributes(this->entry); + if(attribute & 040000){ RETURN_TRUE; }else{ @@ -134,16 +136,17 @@ PHP_METHOD(git_tree_entry, toHeader) php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_odb *odb; git_oid oid; + git_otype type; + zval *git_raw_object; int length; + char *id; - char *id = Z_STRVAL_P(zend_read_property(git_tree_entry_class_entry, getThis(),"oid",sizeof("oid")-1, 0 TSRMLS_CC)); + id = Z_STRVAL_P(zend_read_property(git_tree_entry_class_entry, getThis(),"oid",sizeof("oid")-1, 0 TSRMLS_CC)); git_oid_fromstr(&oid, id); - git_otype type; git_odb_read_header(&length,&type,git_repository_database(this->repository),&oid); if (type == GIT_OBJ_BLOB) { - zval *git_raw_object; MAKE_STD_ZVAL(git_raw_object); object_init_ex(git_raw_object, git_blob_class_entry); diff --git a/src/tree_iterator.c b/src/tree_iterator.c index f7ec89b7a3..7bc50fe00c 100644 --- a/src/tree_iterator.c +++ b/src/tree_iterator.c @@ -102,6 +102,7 @@ PHP_METHOD(git_tree_iterator, valid) { php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); int entry_count = git_tree_entrycount(this->tree); + if(this->offset < entry_count && this->offset >= 0){ RETURN_TRUE; }else{ @@ -113,12 +114,13 @@ PHP_METHOD(git_tree_iterator, __construct) { php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); zval *php_tree_index; + php_git_tree_t *tree; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &php_tree_index) == FAILURE){ return; } - php_git_tree_t *tree = (php_git_tree_t *) zend_object_store_get_object(php_tree_index TSRMLS_CC); + tree = (php_git_tree_t *) zend_object_store_get_object(php_tree_index TSRMLS_CC); this->tree = tree->object; this->offset = 0; diff --git a/src/walker.c b/src/walker.c index d80af15227..b217b2e77b 100644 --- a/src/walker.c +++ b/src/walker.c @@ -82,13 +82,14 @@ PHP_METHOD(git_walker, hide) git_commit *commit; git_repository *repository; git_oid oid; + php_git_walker_t *myobj; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE){ return; } - php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); walker = myobj->walker; repository = git_revwalk_repository(walker); @@ -106,13 +107,14 @@ PHP_METHOD(git_walker, push) git_commit *head; git_revwalk *walker; git_repository *repository; + php_git_walker_t *myobj; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE){ return; } - php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); walker = myobj->walker; repository = git_revwalk_repository(walker); @@ -126,17 +128,18 @@ PHP_METHOD(git_walker, next) { zval *git_commit_object; char *hash; - int hash_len = 0; + int ret, hash_len = 0; git_oid oid; git_commit *commit; git_revwalk *walker; git_signature *signature; zval *parents; + php_git_walker_t *myobj; - php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); walker = myobj->walker; - int ret = git_revwalk_next(&oid,walker); + ret = git_revwalk_next(&oid,walker); if(ret != GIT_SUCCESS){ RETURN_FALSE; } @@ -157,13 +160,13 @@ PHP_METHOD(git_walker, reset) PHP_METHOD(git_walker, sort) { int mode = 0; - + php_git_walker_t *myobj; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode) == FAILURE){ return; } - php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); + myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_revwalk_sorting(myobj->walker, mode); RETURN_TRUE; } From 6194c1fa3f7c4ba29c2e675fee1a7577ccef0b93 Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Mon, 26 Sep 2011 00:59:03 +1000 Subject: [PATCH 057/300] Fixed compile error against latest libgit2 for git_commit_create() missing message encoding. --- src/commit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commit.c b/src/commit.c index f1cfeb8a57..e228a2a9e3 100644 --- a/src/commit.c +++ b/src/commit.c @@ -296,6 +296,7 @@ PHP_METHOD(git_commit, write) update_ref, author->signature, committer->signature, + NULL, // Message encoding (Should probably fix this at some point) message, &tree_oid, count, From c3e019cd78b301fdbb3fd9d0c900f4e87786f6cf Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 18 Oct 2011 00:09:55 +0900 Subject: [PATCH 058/300] fixed #16 could not obtain tree object. i aplogize this suck mistake. thank you for reporting msierks. --- src/commit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commit.c b/src/commit.c index e228a2a9e3..741e8b57bc 100644 --- a/src/commit.c +++ b/src/commit.c @@ -144,9 +144,10 @@ PHP_METHOD(git_commit, getTree) git_tree *ref_tree, *tree; git_oid *tree_oid; zval *git_tree, *entry; + const git_oid *oid; - const git_oid *oid = git_object_id((git_object*)ref_tree); git_commit_tree(&ref_tree, this->object); + oid = git_object_id((git_object*)ref_tree); int ret = git_object_lookup((git_object **)&tree, git_object_owner((git_object*)this->object),oid, GIT_OBJ_TREE); if(ret != GIT_SUCCESS) { From 98348af389ed35c8f4c013468ca76c60cb9cc933 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 29 Nov 2011 15:28:13 -0800 Subject: [PATCH 059/300] fixed compile error --- src/repository.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/repository.c b/src/repository.c index cbc3f682cf..e9af625ee6 100644 --- a/src/repository.c +++ b/src/repository.c @@ -308,7 +308,7 @@ PHP_METHOD(git_repository, __construct) php_git_odb_init(&odb, git_repository_database(myobj->repository) TSRMLS_CC); php_git_add_protected_property_zval_ex(object,"odb",sizeof("odb"),odb TSRMLS_CC); - php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository,GIT_REPO_PATH),1 TSRMLS_CC); + php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository),1 TSRMLS_CC); }else{ myobj->repository = NULL; } @@ -601,7 +601,7 @@ PHP_METHOD(git_repository, getWorkdir) php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); if(this->repository != NULL) { - git_workdir = git_repository_path(this->repository,GIT_REPO_PATH_WORKDIR); + git_workdir = git_repository_workdir(this->repository); RETVAL_STRING(git_workdir,1); } } From 0f4dff7c1033c1bbe306d56c907df0567266bfc7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 29 Nov 2011 16:00:44 -0800 Subject: [PATCH 060/300] for now, fixed odb issue. apologies no commit few month. finally, i've completed my marriage and honeymoon :) well, there are so many changes on libgit2. php-git will do many changes. please wait my improving. --- src/repository.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/repository.c b/src/repository.c index e9af625ee6..9abadd7d2f 100644 --- a/src/repository.c +++ b/src/repository.c @@ -269,17 +269,12 @@ PHP_METHOD(git_repository, getCommit) } git_oid_fromstr(&oid, hash); - odb = git_repository_database(this->repository); - if(!git_odb_exists(odb,&oid)){ - RETURN_FALSE; + ret = git_object_lookup((git_object **)&blob, this->repository,&oid , GIT_OBJ_COMMIT); + if(ret == GIT_SUCCESS){ + php_git_commit_init(&git_commit_object, (git_commit*)blob, this->repository TSRMLS_CC); + RETVAL_ZVAL(git_commit_object,0,1); }else{ - ret = git_object_lookup((git_object **)&blob, this->repository,&oid , GIT_OBJ_COMMIT); - if(ret == GIT_SUCCESS){ - php_git_commit_init(&git_commit_object, (git_commit*)blob, this->repository TSRMLS_CC); - RETVAL_ZVAL(git_commit_object,0,1); - }else{ - RETURN_FALSE; - } + RETURN_FALSE; } } @@ -306,8 +301,6 @@ PHP_METHOD(git_repository, __construct) } myobj->repository = repository; - php_git_odb_init(&odb, git_repository_database(myobj->repository) TSRMLS_CC); - php_git_add_protected_property_zval_ex(object,"odb",sizeof("odb"),odb TSRMLS_CC); php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository),1 TSRMLS_CC); }else{ myobj->repository = NULL; From 9048db6fc96c115e87b0b5adb0e9c31f7c07004a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 1 Dec 2011 05:43:20 -0800 Subject: [PATCH 061/300] adjusted api name. --- src/blob.c | 2 +- src/object.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/blob.c b/src/blob.c index 67c10c005b..eeb11de4d7 100644 --- a/src/blob.c +++ b/src/blob.c @@ -48,7 +48,7 @@ static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC) zend_object_std_dtor(&obj->zo TSRMLS_CC); if (obj->object != NULL) { - git_object_close(obj->object); + git_object_free(obj->object); obj->object = NULL; } if(obj->contents != NULL) { diff --git a/src/object.c b/src/object.c index 55cedd98b8..9712752d75 100644 --- a/src/object.c +++ b/src/object.c @@ -35,7 +35,7 @@ static void php_git_object_free_storage(php_git_object_t *obj TSRMLS_DC) zend_object_std_dtor(&obj->zo TSRMLS_CC); if(obj->object){ - git_object_close(obj->object); + git_object_free(obj->object); obj->object = NULL; } From dc0a0cf25b7becf8b13bef07605be5e2e2b4662b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 2 Dec 2011 03:42:01 -0800 Subject: [PATCH 062/300] change Git\Reference\Manger::getList signature --- src/reference_manager.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/reference_manager.c b/src/reference_manager.c index 3410fdb8f5..3a74a77498 100644 --- a/src/reference_manager.c +++ b/src/reference_manager.c @@ -45,6 +45,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager_create, 0, 0, 2) ZEND_ARG_INFO(0, force) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager_get_list, 0, 0, 1) + ZEND_ARG_INFO(0, flag) +ZEND_END_ARG_INFO() + static void php_git_reference_manager_free_storage(php_git_reference_manager_t *obj TSRMLS_DC) { zend_object_std_dtor(&obj->zo TSRMLS_CC); @@ -100,6 +104,7 @@ PHP_METHOD(git_reference_manager, getList) php_git_reference_manager_t *this= (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); git_strarray *list = malloc(sizeof(git_strarray)); int rr, result, i = 0; + int flags = GIT_REF_LISTALL; git_reference *reference; zval *references; git_rtype type; @@ -107,7 +112,12 @@ PHP_METHOD(git_reference_manager, getList) char out[GIT_OID_HEXSZ+1] = {0}; zval *ref; - git_reference_listall(list,this->repository,GIT_REF_LISTALL); + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "|l", &flags) == FAILURE){ + return; + } + + git_reference_listall(list,this->repository,flags); MAKE_STD_ZVAL(references); array_init(references); @@ -282,7 +292,7 @@ PHP_METHOD(git_reference_manager, create) static zend_function_entry php_git_reference_manager_methods[] = { PHP_ME(git_reference_manager, __construct, arginfo_git_reference_manager__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_reference_manager, getList, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git_reference_manager, getList, arginfo_git_reference_manager_get_list, ZEND_ACC_PUBLIC) PHP_ME(git_reference_manager, lookup, arginfo_git_reference_manager_lookup, ZEND_ACC_PUBLIC) PHP_ME(git_reference_manager, pack, NULL, ZEND_ACC_PUBLIC) PHP_ME(git_reference_manager, create, arginfo_git_reference_manager_create, ZEND_ACC_PUBLIC) From 243e8187ae3d51aa3258c670e7e6d9468769582e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 10 Dec 2011 03:52:04 -0800 Subject: [PATCH 063/300] don't throw exception when calling getParent() --- src/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commit.c b/src/commit.c index 741e8b57bc..4f534deeff 100644 --- a/src/commit.c +++ b/src/commit.c @@ -356,7 +356,7 @@ PHP_METHOD(git_commit, getParent) ret = git_commit_parent(&commit, this->object,offset); if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "specified offset not found"); + //zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "specified offset not found"); RETURN_FALSE; } From 4ff3d724fa14ab2f8d7571123a71bb7e7f8de50c Mon Sep 17 00:00:00 2001 From: Cameron Eagans Date: Thu, 22 Dec 2011 12:24:35 -0700 Subject: [PATCH 064/300] Add installation instructions to README --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 5fb25c805a..82728c24a2 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,15 @@ INSTALL see php-git Wiki: +== Quick Instructions + +* Install libgit2, pcre, and a build chain (Ubuntu: build-essential; Mac: xcode) +* `git clone git://github.com/libgit2/php-git.git && cd php-git/src` +* `phpize` +* `./configure` +* `make` +* `sudo make install` +* Add the extension to your /etc/php.ini Documents ======================================================= From 8720486d9cb58e0ec20974e27fbe4aa9a9c58d73 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 23 Dec 2011 09:11:48 +0900 Subject: [PATCH 065/300] fixed documentation pages --- README.md | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 82728c24a2..94e64c07ca 100644 --- a/README.md +++ b/README.md @@ -10,37 +10,10 @@ How Can I Contribute? -* create topic branch on your repository (contributors looking issue -themselves) - -e.g. fix-repository-xxxx-bug, fix-barerepository-detection-bug. - - topic branch desirable minimum change. - - or post probrem to Github issues feature. - https://github.com/libgit2/php-git/issues - - then i'll fix as possible. - -* send a pull request to me. i'll check and response in a few days. - - Current Development Status ======================================================= -*first Alpha development*. -(development started at 2010-12-30) - -*notice* do not use this extenstion on any production server. this extension not fully tested. - -*1st alpha development release: (2011/1/17) -just work on php. not fully tested. classes and methods may changed. - -*2nd alpha development release: (2011/2) -added some unit test. libgit2 feature fully support. -(i'm busy my work, 1 or 2 week delayed) - -i'll follow libgit2 changes as possible as :) +* EXPERIMENTAL DEPENDENCIES ======================================================= @@ -52,8 +25,6 @@ DEPENDENCIES INSTALL ======================================================= -see php-git Wiki: - == Quick Instructions * Install libgit2, pcre, and a build chain (Ubuntu: build-essential; Mac: xcode) @@ -63,17 +34,24 @@ see php-git Wiki: * `make` * `sudo make install` * Add the extension to your /etc/php.ini +```` +extension=git.so +```` Documents ======================================================= -see php-git Documents: +see php-git Documents: you can build with sphinx. - cd docs - make html +```` +# if you haven't installed php-domain yet, please install sphinxcontrib-phpdomain first. +# sudo easy_install -U sphinxcontrib-phpdomain +cd docs +make html +```` AUTHORS ======================================================= @@ -89,4 +67,4 @@ Links ======================================================= * libgit2: -* php-git documents: \ No newline at end of file +* php-git documents: From 5f076e2c2cb8a842b745bda401e29900cc41dd40 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Fri, 23 Dec 2011 10:11:30 +0900 Subject: [PATCH 066/300] added github extension for sphinx --- docs/conf.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 7f0d1b616c..a6e201f08c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,10 @@ # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinxcontrib.phpdomain'] +extensions = ['sphinxcontrib.phpdomain','sphinxtogithub'] + +sphinx_to_github = True +sphinx_to_github_verbose = True # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] From 0bc5d73a957992153841005b83e543fbd3c7fff3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 23 Jan 2012 23:13:50 +0900 Subject: [PATCH 067/300] throw away old codes --- .gitignore | 38 - CREDITS | 2 - EXPERIMENTAL | 5 - LIBGIT2_VERSION | 1 - LICENSE | 21 - README.md | 70 -- build.xml | 26 - docs/Makefile | 130 ---- docs/_build/.gitignore | 0 docs/_static/.gitignore | 0 docs/_templates/.gitignore | 0 docs/classes/backend/__construct.rst | 26 - docs/classes/backend/exists.rst | 30 - docs/classes/backend/free.rst | 26 - docs/classes/backend/index.rst | 12 - docs/classes/backend/read.rst | 30 - docs/classes/backend/read_header.rst | 30 - docs/classes/backend/write.rst | 30 - docs/classes/blob/__construct.rst | 28 - docs/classes/blob/get_id.rst | 26 - docs/classes/blob/get_type.rst | 26 - docs/classes/blob/index.rst | 9 - docs/classes/blob/is_blob.rst | 26 - docs/classes/blob/is_tree.rst | 26 - docs/classes/blob/set_content.rst | 28 - docs/classes/blob/write.rst | 26 - docs/classes/commit/__construct.rst | 42 -- docs/classes/commit/get_author.rst | 40 -- docs/classes/commit/get_committer.rst | 40 -- docs/classes/commit/get_id.rst | 26 - docs/classes/commit/get_message.rst | 38 - docs/classes/commit/get_parent.rst | 31 - docs/classes/commit/get_short_message.rst | 32 - docs/classes/commit/get_tree.rst | 39 -- docs/classes/commit/index.rst | 9 - docs/classes/commit/set_author.rst | 42 -- docs/classes/commit/set_committer.rst | 41 -- docs/classes/commit/set_message.rst | 46 -- docs/classes/commit/set_parent.rst | 61 -- docs/classes/commit/set_tree.rst | 29 - docs/classes/commit/write.rst | 32 - docs/classes/entry/__construct.rst | 26 - docs/classes/entry/index.rst | 9 - docs/classes/entry/to_object.rst | 26 - docs/classes/git/index.rst | 9 - docs/classes/index/add.rst | 40 -- docs/classes/index/count.rst | 36 - docs/classes/index/find.rst | 41 -- docs/classes/index/get_entry.rst | 70 -- docs/classes/index/get_iterator.rst | 34 - docs/classes/index/index.rst | 10 - docs/classes/index/refresh.rst | 38 - docs/classes/index/write.rst | 35 - docs/classes/manager/__construct.rst | 39 -- docs/classes/manager/create.rst | 48 -- docs/classes/manager/get_list.rst | 39 -- docs/classes/manager/index.rst | 9 - docs/classes/manager/lookup.rst | 48 -- docs/classes/manager/pack.rst | 37 - docs/classes/object/get_id.rst | 26 - docs/classes/object/get_type.rst | 46 -- docs/classes/object/index.rst | 10 - docs/classes/object/is_blob.rst | 43 -- docs/classes/object/is_tree.rst | 48 -- docs/classes/object/write.rst | 26 - docs/classes/odb/__construct.rst | 26 - docs/classes/odb/add_alternate.rst | 28 - docs/classes/odb/add_backend.rst | 28 - docs/classes/odb/index.rst | 9 - docs/classes/rawobject/__construct.rst | 34 - docs/classes/rawobject/get_id.rst | 26 - docs/classes/rawobject/index.rst | 11 - docs/classes/reference/__construct.rst | 28 - docs/classes/reference/get_id.rst | 26 - docs/classes/reference/get_name.rst | 26 - docs/classes/reference/get_target.rst | 26 - docs/classes/reference/get_type.rst | 26 - docs/classes/reference/index.rst | 11 - docs/classes/reference/is_blob.rst | 26 - docs/classes/reference/is_tree.rst | 26 - docs/classes/reference/write.rst | 26 - docs/classes/repository/__construct.rst | 35 - docs/classes/repository/add_alternate.rst | 37 - docs/classes/repository/add_backend.rst | 119 ---- docs/classes/repository/get_commit.rst | 41 -- docs/classes/repository/get_index.rst | 36 - docs/classes/repository/get_object.rst | 44 -- docs/classes/repository/get_references.rst | 43 -- docs/classes/repository/get_tree.rst | 40 -- docs/classes/repository/get_walker.rst | 44 -- docs/classes/repository/index.rst | 10 - docs/classes/repository/init.rst | 45 -- docs/classes/repository/lookup_ref.rst | 40 -- docs/classes/repository/open2.rst | 53 -- docs/classes/repository/open3.rst | 37 - docs/classes/revwalk/__construct.rst | 29 - docs/classes/revwalk/hide.rst | 52 -- docs/classes/revwalk/index.rst | 9 - docs/classes/revwalk/next.rst | 40 -- docs/classes/revwalk/push.rst | 46 -- docs/classes/revwalk/reset.rst | 39 -- docs/classes/revwalk/sort.rst | 42 -- docs/classes/signature/__construct.rst | 49 -- docs/classes/signature/index.rst | 9 - docs/classes/tag/__construct.rst | 28 - docs/classes/tag/get_id.rst | 26 - docs/classes/tag/get_message.rst | 26 - docs/classes/tag/get_name.rst | 26 - docs/classes/tag/get_target.rst | 26 - docs/classes/tag/get_type.rst | 26 - docs/classes/tag/index.rst | 12 - docs/classes/tag/is_blob.rst | 26 - docs/classes/tag/is_tree.rst | 26 - docs/classes/tag/set_message.rst | 28 - docs/classes/tag/set_name.rst | 28 - docs/classes/tag/set_target.rst | 28 - docs/classes/tag/write.rst | 26 - docs/classes/tree/__construct.rst | 28 - docs/classes/tree/add.rst | 56 -- docs/classes/tree/count.rst | 39 -- docs/classes/tree/get_entries.rst | 35 - docs/classes/tree/get_entry.rst | 39 -- docs/classes/tree/get_id.rst | 37 - docs/classes/tree/get_iterator.rst | 35 - docs/classes/tree/get_type.rst | 29 - docs/classes/tree/index.rst | 10 - docs/classes/tree/path.rst | 46 -- docs/classes/tree/remove.rst | 40 -- docs/classes/tree/write.rst | 37 - docs/conf.py | 219 ------ docs/constants.rst | 18 - docs/docgen.php | 138 ---- docs/examples.rst | 131 ---- docs/index.rst | 29 - docs/ini.rst | 4 - docs/installation.rst | 24 - docs/intro.rst | 6 - docs/requirements.rst | 7 - docs/resources.rst | 4 - docs/setup.rst | 12 - src/backend.c | 313 --------- src/blob.c | 171 ----- src/commit.c | 409 ----------- src/config.c | 153 ---- src/config.m4 | 39 -- src/index.c | 374 ---------- src/index_entry.c | 82 --- src/index_iterator.c | 143 ---- src/object.c | 98 --- src/odb.c | 173 ----- src/php_git.c | 357 ---------- src/php_git.h | 196 ------ src/rawobject.c | 42 -- src/reference.c | 250 ------- src/reference_manager.c | 309 --------- src/repository.c | 652 ------------------ src/signature.c | 187 ----- src/tag.c | 150 ---- src/tests/001.phpt | 9 - .../002_functions_git_string_to_type.phpt | 17 - src/tests/002_functions_hex_to_raw.phpt | 10 - src/tests/002_functions_raw_to_hex.phpt | 10 - src/tests/002_functions_type_to_string.phpt | 17 - src/tests/003_signature_behavior.phpt | 17 - src/tests/007_index.phpt | 92 --- src/tests/git_repository_new.phpt | 9 - src/tests/lib/MemoryBackend.php | 90 --- src/tree.c | 299 -------- src/tree_builder.c | 190 ----- src/tree_entry.c | 181 ----- src/tree_iterator.c | 147 ---- src/walker.c | 190 ----- tests/GitReferenceTest.php | 91 --- tests/GitRevwalkTest.php | 74 -- tests/GitTreeTest.php | 86 --- tests/fixtures/fixture.git/HEAD | 0 tests/fixtures/fixture.git/index | Bin 248 -> 0 bytes .../08/dcc094241a93be371a6bf79a535231bd49df97 | Bin 133 -> 0 bytes .../26/3414f423d0e4d70dae8fe53fa34614ff3e2860 | Bin 51 -> 0 bytes .../2f/8c78fd5867e71b20d29df99a0fec29e2d2f43b | Bin 34 -> 0 bytes .../48/167ccfeeacdd14caa7d13fbc58bce17c1e13e6 | Bin 19 -> 0 bytes .../55/7db03de997c86a4a028e1ebd3a1ceb225be238 | Bin 28 -> 0 bytes .../78/678dcc067fa15c9f867de93e0d0410f470ed96 | Bin 81 -> 0 bytes .../7c/aa5b63e5fe4596543378e47b5225b6a1fa2dee | 1 - .../89/88da15d077d4829fc51d8544c097def6644dbb | Bin 81 -> 0 bytes .../ea/e8e8d42804e31e5761451d900ca510b9d36c3c | Bin 105 -> 0 bytes .../f2/4c74a2e500f5ee1332c86b94199f52b1d1d962 | Bin 30 -> 0 bytes 187 files changed, 10318 deletions(-) delete mode 100644 .gitignore delete mode 100644 CREDITS delete mode 100644 EXPERIMENTAL delete mode 100644 LIBGIT2_VERSION delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 build.xml delete mode 100644 docs/Makefile delete mode 100644 docs/_build/.gitignore delete mode 100644 docs/_static/.gitignore delete mode 100644 docs/_templates/.gitignore delete mode 100644 docs/classes/backend/__construct.rst delete mode 100644 docs/classes/backend/exists.rst delete mode 100644 docs/classes/backend/free.rst delete mode 100644 docs/classes/backend/index.rst delete mode 100644 docs/classes/backend/read.rst delete mode 100644 docs/classes/backend/read_header.rst delete mode 100644 docs/classes/backend/write.rst delete mode 100644 docs/classes/blob/__construct.rst delete mode 100644 docs/classes/blob/get_id.rst delete mode 100644 docs/classes/blob/get_type.rst delete mode 100644 docs/classes/blob/index.rst delete mode 100644 docs/classes/blob/is_blob.rst delete mode 100644 docs/classes/blob/is_tree.rst delete mode 100644 docs/classes/blob/set_content.rst delete mode 100644 docs/classes/blob/write.rst delete mode 100644 docs/classes/commit/__construct.rst delete mode 100644 docs/classes/commit/get_author.rst delete mode 100644 docs/classes/commit/get_committer.rst delete mode 100644 docs/classes/commit/get_id.rst delete mode 100644 docs/classes/commit/get_message.rst delete mode 100644 docs/classes/commit/get_parent.rst delete mode 100644 docs/classes/commit/get_short_message.rst delete mode 100644 docs/classes/commit/get_tree.rst delete mode 100644 docs/classes/commit/index.rst delete mode 100644 docs/classes/commit/set_author.rst delete mode 100644 docs/classes/commit/set_committer.rst delete mode 100644 docs/classes/commit/set_message.rst delete mode 100644 docs/classes/commit/set_parent.rst delete mode 100644 docs/classes/commit/set_tree.rst delete mode 100644 docs/classes/commit/write.rst delete mode 100644 docs/classes/entry/__construct.rst delete mode 100644 docs/classes/entry/index.rst delete mode 100644 docs/classes/entry/to_object.rst delete mode 100644 docs/classes/git/index.rst delete mode 100644 docs/classes/index/add.rst delete mode 100644 docs/classes/index/count.rst delete mode 100644 docs/classes/index/find.rst delete mode 100644 docs/classes/index/get_entry.rst delete mode 100644 docs/classes/index/get_iterator.rst delete mode 100644 docs/classes/index/index.rst delete mode 100644 docs/classes/index/refresh.rst delete mode 100644 docs/classes/index/write.rst delete mode 100644 docs/classes/manager/__construct.rst delete mode 100644 docs/classes/manager/create.rst delete mode 100644 docs/classes/manager/get_list.rst delete mode 100644 docs/classes/manager/index.rst delete mode 100644 docs/classes/manager/lookup.rst delete mode 100644 docs/classes/manager/pack.rst delete mode 100644 docs/classes/object/get_id.rst delete mode 100644 docs/classes/object/get_type.rst delete mode 100644 docs/classes/object/index.rst delete mode 100644 docs/classes/object/is_blob.rst delete mode 100644 docs/classes/object/is_tree.rst delete mode 100644 docs/classes/object/write.rst delete mode 100644 docs/classes/odb/__construct.rst delete mode 100644 docs/classes/odb/add_alternate.rst delete mode 100644 docs/classes/odb/add_backend.rst delete mode 100644 docs/classes/odb/index.rst delete mode 100644 docs/classes/rawobject/__construct.rst delete mode 100644 docs/classes/rawobject/get_id.rst delete mode 100644 docs/classes/rawobject/index.rst delete mode 100644 docs/classes/reference/__construct.rst delete mode 100644 docs/classes/reference/get_id.rst delete mode 100644 docs/classes/reference/get_name.rst delete mode 100644 docs/classes/reference/get_target.rst delete mode 100644 docs/classes/reference/get_type.rst delete mode 100644 docs/classes/reference/index.rst delete mode 100644 docs/classes/reference/is_blob.rst delete mode 100644 docs/classes/reference/is_tree.rst delete mode 100644 docs/classes/reference/write.rst delete mode 100644 docs/classes/repository/__construct.rst delete mode 100644 docs/classes/repository/add_alternate.rst delete mode 100644 docs/classes/repository/add_backend.rst delete mode 100644 docs/classes/repository/get_commit.rst delete mode 100644 docs/classes/repository/get_index.rst delete mode 100644 docs/classes/repository/get_object.rst delete mode 100644 docs/classes/repository/get_references.rst delete mode 100644 docs/classes/repository/get_tree.rst delete mode 100644 docs/classes/repository/get_walker.rst delete mode 100644 docs/classes/repository/index.rst delete mode 100644 docs/classes/repository/init.rst delete mode 100644 docs/classes/repository/lookup_ref.rst delete mode 100644 docs/classes/repository/open2.rst delete mode 100644 docs/classes/repository/open3.rst delete mode 100644 docs/classes/revwalk/__construct.rst delete mode 100644 docs/classes/revwalk/hide.rst delete mode 100644 docs/classes/revwalk/index.rst delete mode 100644 docs/classes/revwalk/next.rst delete mode 100644 docs/classes/revwalk/push.rst delete mode 100644 docs/classes/revwalk/reset.rst delete mode 100644 docs/classes/revwalk/sort.rst delete mode 100644 docs/classes/signature/__construct.rst delete mode 100644 docs/classes/signature/index.rst delete mode 100644 docs/classes/tag/__construct.rst delete mode 100644 docs/classes/tag/get_id.rst delete mode 100644 docs/classes/tag/get_message.rst delete mode 100644 docs/classes/tag/get_name.rst delete mode 100644 docs/classes/tag/get_target.rst delete mode 100644 docs/classes/tag/get_type.rst delete mode 100644 docs/classes/tag/index.rst delete mode 100644 docs/classes/tag/is_blob.rst delete mode 100644 docs/classes/tag/is_tree.rst delete mode 100644 docs/classes/tag/set_message.rst delete mode 100644 docs/classes/tag/set_name.rst delete mode 100644 docs/classes/tag/set_target.rst delete mode 100644 docs/classes/tag/write.rst delete mode 100644 docs/classes/tree/__construct.rst delete mode 100644 docs/classes/tree/add.rst delete mode 100644 docs/classes/tree/count.rst delete mode 100644 docs/classes/tree/get_entries.rst delete mode 100644 docs/classes/tree/get_entry.rst delete mode 100644 docs/classes/tree/get_id.rst delete mode 100644 docs/classes/tree/get_iterator.rst delete mode 100644 docs/classes/tree/get_type.rst delete mode 100644 docs/classes/tree/index.rst delete mode 100644 docs/classes/tree/path.rst delete mode 100644 docs/classes/tree/remove.rst delete mode 100644 docs/classes/tree/write.rst delete mode 100644 docs/conf.py delete mode 100644 docs/constants.rst delete mode 100644 docs/docgen.php delete mode 100644 docs/examples.rst delete mode 100644 docs/index.rst delete mode 100644 docs/ini.rst delete mode 100644 docs/installation.rst delete mode 100644 docs/intro.rst delete mode 100644 docs/requirements.rst delete mode 100644 docs/resources.rst delete mode 100644 docs/setup.rst delete mode 100644 src/backend.c delete mode 100644 src/blob.c delete mode 100644 src/commit.c delete mode 100644 src/config.c delete mode 100644 src/config.m4 delete mode 100644 src/index.c delete mode 100644 src/index_entry.c delete mode 100644 src/index_iterator.c delete mode 100644 src/object.c delete mode 100644 src/odb.c delete mode 100644 src/php_git.c delete mode 100644 src/php_git.h delete mode 100644 src/rawobject.c delete mode 100644 src/reference.c delete mode 100644 src/reference_manager.c delete mode 100644 src/repository.c delete mode 100644 src/signature.c delete mode 100644 src/tag.c delete mode 100644 src/tests/001.phpt delete mode 100644 src/tests/002_functions_git_string_to_type.phpt delete mode 100644 src/tests/002_functions_hex_to_raw.phpt delete mode 100644 src/tests/002_functions_raw_to_hex.phpt delete mode 100644 src/tests/002_functions_type_to_string.phpt delete mode 100644 src/tests/003_signature_behavior.phpt delete mode 100644 src/tests/007_index.phpt delete mode 100644 src/tests/git_repository_new.phpt delete mode 100644 src/tests/lib/MemoryBackend.php delete mode 100644 src/tree.c delete mode 100644 src/tree_builder.c delete mode 100644 src/tree_entry.c delete mode 100644 src/tree_iterator.c delete mode 100644 src/walker.c delete mode 100644 tests/GitReferenceTest.php delete mode 100644 tests/GitRevwalkTest.php delete mode 100644 tests/GitTreeTest.php delete mode 100644 tests/fixtures/fixture.git/HEAD delete mode 100644 tests/fixtures/fixture.git/index delete mode 100644 tests/fixtures/fixture.git/objects/08/dcc094241a93be371a6bf79a535231bd49df97 delete mode 100644 tests/fixtures/fixture.git/objects/26/3414f423d0e4d70dae8fe53fa34614ff3e2860 delete mode 100644 tests/fixtures/fixture.git/objects/2f/8c78fd5867e71b20d29df99a0fec29e2d2f43b delete mode 100644 tests/fixtures/fixture.git/objects/48/167ccfeeacdd14caa7d13fbc58bce17c1e13e6 delete mode 100644 tests/fixtures/fixture.git/objects/55/7db03de997c86a4a028e1ebd3a1ceb225be238 delete mode 100644 tests/fixtures/fixture.git/objects/78/678dcc067fa15c9f867de93e0d0410f470ed96 delete mode 100644 tests/fixtures/fixture.git/objects/7c/aa5b63e5fe4596543378e47b5225b6a1fa2dee delete mode 100644 tests/fixtures/fixture.git/objects/89/88da15d077d4829fc51d8544c097def6644dbb delete mode 100644 tests/fixtures/fixture.git/objects/ea/e8e8d42804e31e5761451d900ca510b9d36c3c delete mode 100644 tests/fixtures/fixture.git/objects/f2/4c74a2e500f5ee1332c86b94199f52b1d1d962 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 81a91b2d6c..0000000000 --- a/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -*.o - -# ignore build documents. - -docs/_build/* -docs/_static/* -docs/_templates/* - -# ignore temporary files -tmp/* - -# ignore your phpunit xml file. -phpunit.xml - -# ignore phpized files -src/Makefile.global -src/acinclude.m4 -src/aclocal.m4 -src/autom4te.cache -src/build -src/config.* -src/configure -src/configure* -src/install-sh -src/iltmain.sh -src/missing -src/mkinstalldirs -src/run-tests.php -src/*.lo -src/.deps -src/.libs -src/libtool -src/Makefile* -src/modules -src/ltmain.sh -src/*.la -src/tmp-php.ini -src/php_test_results* diff --git a/CREDITS b/CREDITS deleted file mode 100644 index 5b4a19f66f..0000000000 --- a/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -PHP libgit2 bindings -Shuhei Tanuma diff --git a/EXPERIMENTAL b/EXPERIMENTAL deleted file mode 100644 index 80afdcd19e..0000000000 --- a/EXPERIMENTAL +++ /dev/null @@ -1,5 +0,0 @@ -this extension is experimental, -its functions may change their names -or move to extension all together -so do not rely to much on them -you have been warned! diff --git a/LIBGIT2_VERSION b/LIBGIT2_VERSION deleted file mode 100644 index d026b09c32..0000000000 --- a/LIBGIT2_VERSION +++ /dev/null @@ -1 +0,0 @@ -c24ceffe61f15e0cb499de80b052a906ea5dc7cc \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 6c4a067761..0000000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright (c) 2010 - 2011 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. diff --git a/README.md b/README.md deleted file mode 100644 index 94e64c07ca..0000000000 --- a/README.md +++ /dev/null @@ -1,70 +0,0 @@ -php-git -======================================================= - -php-git is a set of PHP 5.3+ bindings to the libgit2 linkable C Git library. - -How Can I Contribute? -======================================================= - -* fork our repository. - - - -Current Development Status -======================================================= - -* EXPERIMENTAL - -DEPENDENCIES -======================================================= - -* libgit2 -* php5 -* pcre - -INSTALL -======================================================= - -== Quick Instructions - -* Install libgit2, pcre, and a build chain (Ubuntu: build-essential; Mac: xcode) -* `git clone git://github.com/libgit2/php-git.git && cd php-git/src` -* `phpize` -* `./configure` -* `make` -* `sudo make install` -* Add the extension to your /etc/php.ini -```` -extension=git.so -```` - -Documents -======================================================= - -see php-git Documents: - -you can build with sphinx. - -```` -# if you haven't installed php-domain yet, please install sphinxcontrib-phpdomain first. -# sudo easy_install -U sphinxcontrib-phpdomain - -cd docs -make html -```` -AUTHORS -======================================================= - -* Shuhei Tanuma - -LICENSE -======================================================= - -MIT Licence. - - -Links -======================================================= - -* libgit2: -* php-git documents: diff --git a/build.xml b/build.xml deleted file mode 100644 index 4926d8d18b..0000000000 --- a/build.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index 617dc47247..0000000000 --- a/docs/Makefile +++ /dev/null @@ -1,130 +0,0 @@ -# Makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = _build - -# Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . - -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest - -help: - @echo "Please use \`make ' where is one of" - @echo " html to make standalone HTML files" - @echo " dirhtml to make HTML files named index.html in directories" - @echo " singlehtml to make a single large HTML file" - @echo " pickle to make pickle files" - @echo " json to make JSON files" - @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" - @echo " devhelp to make HTML files and a Devhelp project" - @echo " epub to make an epub" - @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" - @echo " latexpdf to make LaTeX files and run them through pdflatex" - @echo " text to make text files" - @echo " man to make manual pages" - @echo " changes to make an overview of all changed/added/deprecated items" - @echo " linkcheck to check all external links for integrity" - @echo " doctest to run all doctests embedded in the documentation (if enabled)" - -clean: - -rm -rf $(BUILDDIR)/* - -html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." - -dirhtml: - $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." - -singlehtml: - $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml - @echo - @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." - -pickle: - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle - @echo - @echo "Build finished; now you can process the pickle files." - -json: - $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json - @echo - @echo "Build finished; now you can process the JSON files." - -htmlhelp: - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp - @echo - @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in $(BUILDDIR)/htmlhelp." - -qthelp: - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/php-git.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/php-git.qhc" - -devhelp: - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/php-git" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/php-git" - @echo "# devhelp" - -epub: - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub - @echo - @echo "Build finished. The epub file is in $(BUILDDIR)/epub." - -latex: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo - @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." - @echo "Run \`make' in that directory to run these through (pdf)latex" \ - "(use \`make latexpdf' here to do that automatically)." - -latexpdf: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through pdflatex..." - make -C $(BUILDDIR)/latex all-pdf - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -text: - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text - @echo - @echo "Build finished. The text files are in $(BUILDDIR)/text." - -man: - $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man - @echo - @echo "Build finished. The manual pages are in $(BUILDDIR)/man." - -changes: - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes - @echo - @echo "The overview file is in $(BUILDDIR)/changes." - -linkcheck: - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck - @echo - @echo "Link check complete; look for any errors in the above output " \ - "or in $(BUILDDIR)/linkcheck/output.txt." - -doctest: - $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest - @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/_build/.gitignore b/docs/_build/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/_static/.gitignore b/docs/_static/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/_templates/.gitignore b/docs/_templates/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/classes/backend/__construct.rst b/docs/classes/backend/__construct.rst deleted file mode 100644 index c76a8cc284..0000000000 --- a/docs/classes/backend/__construct.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: __construct (Git\Backend method) - - -Git\\Backend::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Backend::__construct** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/backend/exists.rst b/docs/classes/backend/exists.rst deleted file mode 100644 index db706b6c83..0000000000 --- a/docs/classes/backend/exists.rst +++ /dev/null @@ -1,30 +0,0 @@ -.. index:: - single: exists (Git\Backend method) - - -Git\\Backend::exists -=========================================================== - -Description -*********************************************************** - -abstract public **Git\\Backend::exists** (string *$key*) - - -Parameters -*********************************************************** - -*key* - target hash id. - - -Return Values -*********************************************************** - -this method must return true or false. - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/backend/free.rst b/docs/classes/backend/free.rst deleted file mode 100644 index f174a6a3f8..0000000000 --- a/docs/classes/backend/free.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: free (Git\Backend method) - - -Git\\Backend::free -=========================================================== - -Description -*********************************************************** - -public **Git\\Backend::free** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/backend/index.rst b/docs/classes/backend/index.rst deleted file mode 100644 index 8e4f3de694..0000000000 --- a/docs/classes/backend/index.rst +++ /dev/null @@ -1,12 +0,0 @@ -Git\\Backend -=========================== - -abstract class Git\\Backend - -this class use for custom backend. - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/backend/read.rst b/docs/classes/backend/read.rst deleted file mode 100644 index a750786eb5..0000000000 --- a/docs/classes/backend/read.rst +++ /dev/null @@ -1,30 +0,0 @@ -.. index:: - single: read (Git\Backend method) - - -Git\\Backend::read -=========================================================== - -Description -*********************************************************** - -abstract public **Git\\Backend::read** (string *$key*) - - -Parameters -*********************************************************** - -*key* - target hash id - - -Return Values -*********************************************************** - -Git\\RawObject / false - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/backend/read_header.rst b/docs/classes/backend/read_header.rst deleted file mode 100644 index cad3725d36..0000000000 --- a/docs/classes/backend/read_header.rst +++ /dev/null @@ -1,30 +0,0 @@ -.. index:: - single: read_header (Git\Backend method) - - -Git\\Backend::read_header -=========================================================== - -Description -*********************************************************** - -abstract public **Git\\Backend::read_header** (*$key*) - - -Parameters -*********************************************************** - -*key* - target hash id. - - -Return Values -*********************************************************** - -Git\RawObject / false - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/backend/write.rst b/docs/classes/backend/write.rst deleted file mode 100644 index 1ed215b7af..0000000000 --- a/docs/classes/backend/write.rst +++ /dev/null @@ -1,30 +0,0 @@ -.. index:: - single: write (Git\Backend method) - - -Git\\Backend::write -=========================================================== - -Description -*********************************************************** - -abstract public **Git\\Backend::write** (Git\RawObject *$object*) - - -Parameters -*********************************************************** - -*object* - Git\RawObject - - -Return Values -*********************************************************** - -true / false - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/blob/__construct.rst b/docs/classes/blob/__construct.rst deleted file mode 100644 index cfe98cee8a..0000000000 --- a/docs/classes/blob/__construct.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: __construct (Git\Blob method) - - -Git\\Blob::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Blob::__construct** (Git\Repository *$repository*) - - -Parameters -*********************************************************** - -*repository* - Git\Repository object. - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/blob/get_id.rst b/docs/classes/blob/get_id.rst deleted file mode 100644 index aac683f435..0000000000 --- a/docs/classes/blob/get_id.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getId (Git\Blob method) - - -Git\\Blob::getId -=========================================================== - -Description -*********************************************************** - -public **Git\\Blob::getId** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/blob/get_type.rst b/docs/classes/blob/get_type.rst deleted file mode 100644 index 8f22a16ed6..0000000000 --- a/docs/classes/blob/get_type.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getType (Git\Blob method) - - -Git\\Blob::getType -=========================================================== - -Description -*********************************************************** - -public **Git\\Blob::getType** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/blob/index.rst b/docs/classes/blob/index.rst deleted file mode 100644 index 4d699a3f1c..0000000000 --- a/docs/classes/blob/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\Blob -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/blob/is_blob.rst b/docs/classes/blob/is_blob.rst deleted file mode 100644 index b5bc583a20..0000000000 --- a/docs/classes/blob/is_blob.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: isBlob (Git\Blob method) - - -Git\\Blob::isBlob -=========================================================== - -Description -*********************************************************** - -public **Git\\Blob::isBlob** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/blob/is_tree.rst b/docs/classes/blob/is_tree.rst deleted file mode 100644 index 1482c2de4a..0000000000 --- a/docs/classes/blob/is_tree.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: isTree (Git\Blob method) - - -Git\\Blob::isTree -=========================================================== - -Description -*********************************************************** - -public **Git\\Blob::isTree** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/blob/set_content.rst b/docs/classes/blob/set_content.rst deleted file mode 100644 index 00baeea373..0000000000 --- a/docs/classes/blob/set_content.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: setContent (Git\Blob method) - - -Git\\Blob::setContent -=========================================================== - -Description -*********************************************************** - -public **Git\\Blob::setContent** (*$string*) - - -Parameters -*********************************************************** - -*string* - contents - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/blob/write.rst b/docs/classes/blob/write.rst deleted file mode 100644 index 88bdad8bc4..0000000000 --- a/docs/classes/blob/write.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: write (Git\Blob method) - - -Git\\Blob::write -=========================================================== - -Description -*********************************************************** - -public **Git\\Blob::write** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/commit/__construct.rst b/docs/classes/commit/__construct.rst deleted file mode 100644 index 7af4c398f4..0000000000 --- a/docs/classes/commit/__construct.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. index:: - single: __construct (Git\Commit method) - -create new commit. - - -Git\\Commit::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::__construct** (Git\\Repository *$repository*) - - -Parameters -*********************************************************** - -Git\\Repository *repository* - Repository class - - -Return Values -*********************************************************** - -:doc:`Git\\Commit ` - -Examples -*********************************************************** - - -.. code-block:: php - - ` \ No newline at end of file diff --git a/docs/classes/commit/get_author.rst b/docs/classes/commit/get_author.rst deleted file mode 100644 index 28970890f3..0000000000 --- a/docs/classes/commit/get_author.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. index:: - single: getAuthor (Git\Commit method) - - -Git\\Commit::getAuthor -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::getAuthor** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -Git\\Signature - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $commit = $repo->getCommit($ref->getId()); - $author = $commit->getAuthor(); - -See Also -*********************************************************** - -:doc:`Git\\Commit ` -:doc:`Git\\Commit::getCommitter() ` -:doc:`Git\\Signature ` - diff --git a/docs/classes/commit/get_committer.rst b/docs/classes/commit/get_committer.rst deleted file mode 100644 index dcc25357a1..0000000000 --- a/docs/classes/commit/get_committer.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. index:: - single: getCommitter (Git\Commit method) - - -Git\\Commit::getCommitter -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::getCommitter** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $commit = $repo->getCommit($ref->getId()); - $committer = $commit->getCommitter(); - - -See Also -*********************************************************** - -:doc:`Git\\Commit ` -:doc:`Git\\Commit::getAuthor() ` -:doc:`Git\\Signature ` - diff --git a/docs/classes/commit/get_id.rst b/docs/classes/commit/get_id.rst deleted file mode 100644 index b74db7fa43..0000000000 --- a/docs/classes/commit/get_id.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getId (Git\Commit method) - - -Git\\Commit::getId -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::getId** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/commit/get_message.rst b/docs/classes/commit/get_message.rst deleted file mode 100644 index 1428b49c99..0000000000 --- a/docs/classes/commit/get_message.rst +++ /dev/null @@ -1,38 +0,0 @@ -.. index:: - single: getMessage (Git\Commit method) - - -Git\\Commit::getMessage -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::getMessage** () - - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -string - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $commit = $repo->getCommit($ref->getId()); - $message = $commit->getMessage(); - - -See Also -*********************************************************** - -:doc:`Git\\Commit ` -:doc:`Git\\Commit::getShortMessage() ` \ No newline at end of file diff --git a/docs/classes/commit/get_parent.rst b/docs/classes/commit/get_parent.rst deleted file mode 100644 index 3b42b33d43..0000000000 --- a/docs/classes/commit/get_parent.rst +++ /dev/null @@ -1,31 +0,0 @@ -.. index:: - single: getParent (Git\Commit method) - - -Git\\Commit::getParent -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::getParent** (int *$offset* = 0) - - -Parameters -*********************************************************** - -int *offset* - specified parent offset. - -Return Values -*********************************************************** - -Git\\Commit - -Examples -*********************************************************** - -See Also -*********************************************************** - -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/commit/get_short_message.rst b/docs/classes/commit/get_short_message.rst deleted file mode 100644 index 108acb8991..0000000000 --- a/docs/classes/commit/get_short_message.rst +++ /dev/null @@ -1,32 +0,0 @@ -.. index:: - single: getShortMessage (Git\Commit method) - - -Git\\Commit::getShortMessage -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::getShortMessage** () - - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $commit = $repo->getCommit($ref->getId()); - $message = $commit->getShortMessage(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/commit/get_tree.rst b/docs/classes/commit/get_tree.rst deleted file mode 100644 index 1adb8c8b9c..0000000000 --- a/docs/classes/commit/get_tree.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. index:: - single: getTree (Git\Commit method) - - -Git\\Commit::getTree -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::getTree** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Git\\Tree - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $commit = $repo->getCommit($ref->getId()); - $tree = $commit->getTree(); - -See Also -*********************************************************** - -:doc:`Git\\Tree ` -:doc:`Git\\Commit ` diff --git a/docs/classes/commit/index.rst b/docs/classes/commit/index.rst deleted file mode 100644 index 4d8f162531..0000000000 --- a/docs/classes/commit/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\Commit -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/commit/set_author.rst b/docs/classes/commit/set_author.rst deleted file mode 100644 index b8a6952ecb..0000000000 --- a/docs/classes/commit/set_author.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. index:: - single: setAuthor (Git\Commit method) - - -Git\\Commit::setAuthor -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::setAuthor** (Git\\Signature *$author*) - - -Parameters -*********************************************************** - -*author* - author signature. - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - setAuthor(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - - -See Also -*********************************************************** - -:doc:`Git\\Signature ` -:doc:`Git\\Commit::setCommitter ` -`DateTime(PHP Documents) `_ -`DateTimeZone(PHP Documents) `_ \ No newline at end of file diff --git a/docs/classes/commit/set_committer.rst b/docs/classes/commit/set_committer.rst deleted file mode 100644 index a141d624f0..0000000000 --- a/docs/classes/commit/set_committer.rst +++ /dev/null @@ -1,41 +0,0 @@ -.. index:: - single: setCommitter (Git\Commit method) - - -Git\\Commit::setCommitter -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::setCommitter** (Git\\Signature *$committer*) - - -Parameters -*********************************************************** - -*committer* - committer signature - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - setCommitter(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - -See Also -*********************************************************** - -:doc:`Git\\Signature ` -:doc:`Git\\Commit::setAuthor ` -`DateTime(PHP Documents) `_ -`DateTimeZone(PHP Documents) `_ \ No newline at end of file diff --git a/docs/classes/commit/set_message.rst b/docs/classes/commit/set_message.rst deleted file mode 100644 index e024e29b85..0000000000 --- a/docs/classes/commit/set_message.rst +++ /dev/null @@ -1,46 +0,0 @@ -.. index:: - single: setMessage (Git\Commit method) - - -Git\\Commit::setMessage -=========================================================== - -.. note:: - have to set commit message when writing commit. - -Description -*********************************************************** - -public **Git\\Commit::setMessage** (string *$message*) - - -Parameters -*********************************************************** - -*message* - commit message. - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - setMessage( - "initial import\n" // short message - ."\n" - ."import from https://github.com/...\n" - ); - - -See Also -*********************************************************** - -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/commit/set_parent.rst b/docs/classes/commit/set_parent.rst deleted file mode 100644 index d34f62fe3d..0000000000 --- a/docs/classes/commit/set_parent.rst +++ /dev/null @@ -1,61 +0,0 @@ -.. index:: - single: setParent (Git\Commit method) - - -Git\\Commit::setParent -=========================================================== - -.. note:: - php-git can't add multiple parents now. - this limit will fix later. - -.. note:: - do not call this method when first commit. - -Description -*********************************************************** - -public **Git\\Commit::setParent** (string *$hash*) - - -Parameters -*********************************************************** - -*hash* - commit hash id - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -- First Commit - -.. code-block:: php - - setContent("First Object1"); - $hash = $blob->write(); - $tree = new Git\Tree($repository); - $tree->add($hash,"README",100644); - $tree_hash = $tree->write(); - $commit = new Git\Commit($repository); - $commit->setAuthor(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - $commit->setCommitter(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - $commit->setTree($tree->getId()); - // when first commit. do not call setParent. - //$commit->setParent(""); - $commit->setMessage("initial import"); - $master_hash = $commit->write(); - - -See Also -*********************************************************** - -:doc:`Git\\Signature ` -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/commit/set_tree.rst b/docs/classes/commit/set_tree.rst deleted file mode 100644 index c7b6f7ca69..0000000000 --- a/docs/classes/commit/set_tree.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. index:: - single: setTree (Git\Commit method) - - -Git\\Commit::setTree -=========================================================== - -Description -*********************************************************** - -public **Git\\Commit::setTree** (string *$tree*) - - -Parameters -*********************************************************** - -*tree* - tree hash id - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** - -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/commit/write.rst b/docs/classes/commit/write.rst deleted file mode 100644 index 11a6f30a6f..0000000000 --- a/docs/classes/commit/write.rst +++ /dev/null @@ -1,32 +0,0 @@ -.. index:: - single: write (Git\Commit method) - - -Git\\Commit::write -=========================================================== - -write current commit. - -Description -*********************************************************** - -public **Git\\Commit::write** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -boolean - -Examples -*********************************************************** - -See Also -*********************************************************** - -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/entry/__construct.rst b/docs/classes/entry/__construct.rst deleted file mode 100644 index 70b585aa10..0000000000 --- a/docs/classes/entry/__construct.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: __construct (Git\Tree\Entry method) - - -Git\\Tree\\Entry::__construct -=========================================================== - -Description -*********************************************************** - -**Git\\Tree\\Entry::__construct** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/entry/index.rst b/docs/classes/entry/index.rst deleted file mode 100644 index 0279c084fc..0000000000 --- a/docs/classes/entry/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\Tree\\Entry -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/entry/to_object.rst b/docs/classes/entry/to_object.rst deleted file mode 100644 index 2a8d48ca0a..0000000000 --- a/docs/classes/entry/to_object.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: toObject (Git\Tree\Entry method) - - -Git\\Tree\\Entry::toObject -=========================================================== - -Description -*********************************************************** - -public **Git\\Tree\\Entry::toObject** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/git/index.rst b/docs/classes/git/index.rst deleted file mode 100644 index 00d6fad742..0000000000 --- a/docs/classes/git/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\Git -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/index/add.rst b/docs/classes/index/add.rst deleted file mode 100644 index 6fdd1d8457..0000000000 --- a/docs/classes/index/add.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. index:: - single: add (Git\Index method) - - -Git\\Index::add -=========================================================== - -add specified file to your index. you have to call Git::Index::write after this method. - - -Description -*********************************************************** - -public **Git\\Index::add** (string *$path*,int *$staging* = 0) - - -Parameters -*********************************************************** - -*path* - file path. - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block:: php - - getIndex(); - $index->add("newcontents.txt"); - $index->write(); - $index->refresh(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/index/count.rst b/docs/classes/index/count.rst deleted file mode 100644 index c82b6e6f1a..0000000000 --- a/docs/classes/index/count.rst +++ /dev/null @@ -1,36 +0,0 @@ -.. index:: - single: count (Git\Index method) - - -Git\\Index::count -=========================================================== - -Countable Interface. you can count(Git::Index) this method. - -Description -*********************************************************** - -public **Git\\Index::count** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block:: php - - getIndex(); - echo count($index); - // same as echo $index->count(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/index/find.rst b/docs/classes/index/find.rst deleted file mode 100644 index ec52795717..0000000000 --- a/docs/classes/index/find.rst +++ /dev/null @@ -1,41 +0,0 @@ -.. index:: - single: find (Git\Index method) - - -Git\\Index::find -=========================================================== - -returns specified file offset in git_index. - -.. note:: - this method may change next development. - -Description -*********************************************************** - -public **Git\\Index::find** (string *$path*) - - -Parameters -*********************************************************** - -*path* - file name - -Return Values -*********************************************************** - -int offset - -Examples -*********************************************************** - -.. code-block::php - - getIndex(); - $offset = $index->find("README.md"); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/index/get_entry.rst b/docs/classes/index/get_entry.rst deleted file mode 100644 index 1281b2b7cd..0000000000 --- a/docs/classes/index/get_entry.rst +++ /dev/null @@ -1,70 +0,0 @@ -.. index:: - single: getEntry (Git\Index method) - - -Git\\Index::getEntry -=========================================================== - -returns specified index entry. - -Description -*********************************************************** - -public **Git\\Index::getEntry** (int *$offset* = 0) - - -Parameters -*********************************************************** - -*offset* - index offset - - -Return Values -*********************************************************** - -Stdclass - -Examples -*********************************************************** - -.. code-block::php - - getIndex(); - $result = $index->getEntry(0); - /* - object(stdClass)#4 (12) { - ["path"]=> - string(10) ".gitignore" - ["oid"]=> - string(40) "5b1a5b7ad3dd7141ccacd25e50e3078de4288a22" - ["dev"]=> - int(2050) - ["ino"]=> - int(1205498) - ["mode"]=> - int(33188) - ["uid"]=> - int(1000) - ["gid"]=> - int(1000) - ["file_size"]=> - int(364) - ["flags"]=> - int(10) - ["flags_extended"]=> - int(0) - ["ctime"]=> - int(1294640280) - ["mtime"]=> - int(1294640280) - } - */ - -.. note:: - return object may change next development - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/index/get_iterator.rst b/docs/classes/index/get_iterator.rst deleted file mode 100644 index 9e059f1eee..0000000000 --- a/docs/classes/index/get_iterator.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. index:: - single: getIterator (Git\Index method) - - -Git\\Index::getIterator -=========================================================== - -IteratorAggregate interface. - -Description -*********************************************************** - -public **Git\\Index::getIterator** () - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block::php - - getIndex(); - foreach($index->getIterator() as $entry){ - // something... - } - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/index/index.rst b/docs/classes/index/index.rst deleted file mode 100644 index 86c808d1ad..0000000000 --- a/docs/classes/index/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -Git\\Index -=========================== - -representation of git index. - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/index/refresh.rst b/docs/classes/index/refresh.rst deleted file mode 100644 index 56e8e19c6d..0000000000 --- a/docs/classes/index/refresh.rst +++ /dev/null @@ -1,38 +0,0 @@ -.. index:: - single: refresh (Git\Index method) - - -Git\\Index::refresh -=========================================================== - -reloading current repository index. - -Description -*********************************************************** - -public **Git\\Index::refresh** () - - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - getIndex(); - /** - * some change wrote. - * you have to refresh index. - */ - $index->refresh(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/index/write.rst b/docs/classes/index/write.rst deleted file mode 100644 index 63bafa4bd8..0000000000 --- a/docs/classes/index/write.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. index:: - single: write (Git\Index method) - - -Git\\Index::write -=========================================================== - -write current index to filesystem. - -Description -*********************************************************** - -public **Git\\Index::write** () - - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block::php - - getIndex(); - $index->add("newcontents.txt"); - $index->write(); - $index->refresh(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/manager/__construct.rst b/docs/classes/manager/__construct.rst deleted file mode 100644 index ddc684e9ed..0000000000 --- a/docs/classes/manager/__construct.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. index:: - single: __construct (Git\Reference\Manager method) - - -Git\\Reference\\Manager::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference\\Manager::__construct** (Git\\Repository *$repository*) - - -Parameters -*********************************************************** - -*repository* - Git\\Repository - - -Return Values -*********************************************************** - -:doc:`Git\\Reference\\Manager ` - -Examples -*********************************************************** - -.. code-block:: php - - ` -:doc:`Git\\Repository ` diff --git a/docs/classes/manager/create.rst b/docs/classes/manager/create.rst deleted file mode 100644 index d2757e4068..0000000000 --- a/docs/classes/manager/create.rst +++ /dev/null @@ -1,48 +0,0 @@ -.. index:: - single: create (Git\Reference\Manager method) - - -Git\\Reference\\Manager::create -=========================================================== - -.. note:: - Currentry can create non symbolic reference only. - (this is php-git limits. this issue fix soon) - -Description -*********************************************************** - -public **Git\\Reference\\Manager::create** (string *$name*,string *$oid*) - - -Parameters -*********************************************************** - -*name* - reference name (e.g. refs/heads/reference-name) - -*oid* - target commit id - -Return Values -*********************************************************** - -boolean - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - //create new branch `new-branch` what targets `master` commit. - $manager->create("refs/heads/new-branch",$master->getId()); - -See Also -*********************************************************** - -:doc:`Git\\Commit ` -:doc:`Git\\Reference ` diff --git a/docs/classes/manager/get_list.rst b/docs/classes/manager/get_list.rst deleted file mode 100644 index d439b22efb..0000000000 --- a/docs/classes/manager/get_list.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. index:: - single: getList (Git\Reference\Manager method) - - -Git\\Reference\\Manager::getList -=========================================================== - -get available reference list. - -Description -*********************************************************** - -public **Git\\Reference\\Manager::getList** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -array Git\\Reference - -Examples -*********************************************************** - -.. code-block:: php - - getList(); - -See Also -*********************************************************** - -:doc:`Git\\Reference ` \ No newline at end of file diff --git a/docs/classes/manager/index.rst b/docs/classes/manager/index.rst deleted file mode 100644 index 75951c8f50..0000000000 --- a/docs/classes/manager/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\Reference\\Manager -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/manager/lookup.rst b/docs/classes/manager/lookup.rst deleted file mode 100644 index d485206f35..0000000000 --- a/docs/classes/manager/lookup.rst +++ /dev/null @@ -1,48 +0,0 @@ -.. index:: - single: lookup (Git\Reference\Manager method) - - -Git\\Reference\\Manager::lookup -=========================================================== - -this method same as Git\Repository::lookup(); - -Description -*********************************************************** - -public **Git\\Reference\\Manager::lookup** (string *$name*) - - -Parameters -*********************************************************** - -*name* - reference name (e.g. refs/heads/master) - - -Return Values -*********************************************************** - -Git\\Reference - -ChangeLog -*********************************************************** - -- method name changed from lookupRef to lookup. - (can't define lookup method because php-compat defines `lookup` preprocessor.) - -Examples -*********************************************************** - -.. code-block:: php - - lookup("refs/heads/master"); - - -See Also -*********************************************************** - -:doc:`Git\\Repository::lookupRef ` \ No newline at end of file diff --git a/docs/classes/manager/pack.rst b/docs/classes/manager/pack.rst deleted file mode 100644 index 149be41ecf..0000000000 --- a/docs/classes/manager/pack.rst +++ /dev/null @@ -1,37 +0,0 @@ -.. index:: - single: pack (Git\Reference\Manager method) - - -Git\\Reference\\Manager::pack -=========================================================== - -.. note:: - WARNING: calling this method may invalidate any existing references previously loaded on the cache. - -Description -*********************************************************** - -public **Git\\Reference\\Manager::pack** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -boolean - -Examples -*********************************************************** - -.. code-block:: php - - pack(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/object/get_id.rst b/docs/classes/object/get_id.rst deleted file mode 100644 index c85c2821ee..0000000000 --- a/docs/classes/object/get_id.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getId (Git\Object method) - - -Git\\Object::getId -=========================================================== - -Description -*********************************************************** - -public **Git\\Object::getId** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/object/get_type.rst b/docs/classes/object/get_type.rst deleted file mode 100644 index dd17aea314..0000000000 --- a/docs/classes/object/get_type.rst +++ /dev/null @@ -1,46 +0,0 @@ -.. index:: - single: getType (Git\Object method) - - -Git\\Object::getType -=========================================================== - -returns current object type - -Description -*********************************************************** - -public **Git\\Object::getType** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -int object_type - -- Git\\Object\\Tree -- Git\\Object\\Blob - -Examples -*********************************************************** - -.. code-block:: php - - entries as $entry){ - $object = $entry->toObject(); - if($object->getType() == Git\Object\Tree){ - // - } - } - -See Also -*********************************************************** - -:doc:`Git\\Object::isTree ` -:doc:`Git\\Object::isBlob ` \ No newline at end of file diff --git a/docs/classes/object/index.rst b/docs/classes/object/index.rst deleted file mode 100644 index 3b26bab176..0000000000 --- a/docs/classes/object/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -Git\\Object -=========================== - -Base class for Git\\Commit, Git\\Blob, Git\\Tree, Git\\Commit - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/object/is_blob.rst b/docs/classes/object/is_blob.rst deleted file mode 100644 index 4e7fb9ba41..0000000000 --- a/docs/classes/object/is_blob.rst +++ /dev/null @@ -1,43 +0,0 @@ -.. index:: - single: isBlob (Git\Object method) - - -Git\\Object::isBlob -=========================================================== - -return true when object is blob. - -Description -*********************************************************** - -public **Git\\Object::isBlob** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block:: php - - entries as $entry){ - $object = $entry->toObject(); - if($object->isTree()){ - // - } else if($object->isBlob()){ - // - } - } - -See Also -*********************************************************** - -:doc:`Git\\Object::isTree ` -:doc:`Git\\Object::getType ` \ No newline at end of file diff --git a/docs/classes/object/is_tree.rst b/docs/classes/object/is_tree.rst deleted file mode 100644 index 142e5860a1..0000000000 --- a/docs/classes/object/is_tree.rst +++ /dev/null @@ -1,48 +0,0 @@ -.. index:: - single: isTree (Git\Object method) - - -Git\\Object::isTree -=========================================================== - -return true when object is tree. - - -Description -*********************************************************** - -public **Git\\Object::isTree** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -boolean - -Examples -*********************************************************** - -.. code-block:: php - - entries as $entry){ - $object = $entry->toObject(); - if($object->isTree()){ - // - } else if($object->isBlob()){ - // - } - } - -See Also -*********************************************************** - - -:doc:`Git\\Object::isBlob ` -:doc:`Git\\Object::getType ` \ No newline at end of file diff --git a/docs/classes/object/write.rst b/docs/classes/object/write.rst deleted file mode 100644 index e89ec80b17..0000000000 --- a/docs/classes/object/write.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: write (Git\Object method) - - -Git\\Object::write -=========================================================== - -Description -*********************************************************** - -public **Git\\Object::write** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/odb/__construct.rst b/docs/classes/odb/__construct.rst deleted file mode 100644 index 136515fb50..0000000000 --- a/docs/classes/odb/__construct.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: __construct (Git\ODB method) - - -Git\\ODB::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\ODB::__construct** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/odb/add_alternate.rst b/docs/classes/odb/add_alternate.rst deleted file mode 100644 index 839c2e3cb0..0000000000 --- a/docs/classes/odb/add_alternate.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: addAlternate (Git\ODB method) - - -Git\\ODB::addAlternate -=========================================================== - -Description -*********************************************************** - -public **Git\\ODB::addAlternate** (Git\Backend *$backend*) - - -Parameters -*********************************************************** - -Git\Backend *backend* - custom backend object - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/odb/add_backend.rst b/docs/classes/odb/add_backend.rst deleted file mode 100644 index d56494058f..0000000000 --- a/docs/classes/odb/add_backend.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: addBackend (Git\ODB method) - - -Git\\ODB::addBackend -=========================================================== - -Description -*********************************************************** - -public **Git\\ODB::addBackend** (Git\Backend *$backend*) - - -Parameters -*********************************************************** - -Git\Backend *backend* - custom backend object - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/odb/index.rst b/docs/classes/odb/index.rst deleted file mode 100644 index 64c8e18558..0000000000 --- a/docs/classes/odb/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\ODB -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/rawobject/__construct.rst b/docs/classes/rawobject/__construct.rst deleted file mode 100644 index e4b05fc8b4..0000000000 --- a/docs/classes/rawobject/__construct.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. index:: - single: __construct (Git\RawObject method) - - -Git\\RawObject::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\RawObject::__construct** (int *$type*, string *$data*, [int *$len*]) - - -Parameters -*********************************************************** - -*type* - object type. - -*data* - object data - -*len* - object data length - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/rawobject/get_id.rst b/docs/classes/rawobject/get_id.rst deleted file mode 100644 index e32014893a..0000000000 --- a/docs/classes/rawobject/get_id.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getId (Git\RawObject method) - - -Git\\RawObject::getId -=========================================================== - -Description -*********************************************************** - -public **Git\\RawObject::getId** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/rawobject/index.rst b/docs/classes/rawobject/index.rst deleted file mode 100644 index c6e44f0b90..0000000000 --- a/docs/classes/rawobject/index.rst +++ /dev/null @@ -1,11 +0,0 @@ -Git\\RawObject -=========================== - -this class uses php-git internal. -see also :doc:`Git\\Backend ` - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/reference/__construct.rst b/docs/classes/reference/__construct.rst deleted file mode 100644 index ff85c29e9d..0000000000 --- a/docs/classes/reference/__construct.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: __construct (Git\Reference method) - - -Git\\Reference::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::__construct** (Git\Repository *$repository*) - - -Parameters -*********************************************************** - -Git\Repository *repository* - Git\Repository object. - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/reference/get_id.rst b/docs/classes/reference/get_id.rst deleted file mode 100644 index 751936ee8a..0000000000 --- a/docs/classes/reference/get_id.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getId (Git\Reference method) - - -Git\\Reference::getId -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::getId** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/reference/get_name.rst b/docs/classes/reference/get_name.rst deleted file mode 100644 index 49ea57db3b..0000000000 --- a/docs/classes/reference/get_name.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getName (Git\Reference method) - - -Git\\Reference::getName -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::getName** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/reference/get_target.rst b/docs/classes/reference/get_target.rst deleted file mode 100644 index 8d0a1e7e1a..0000000000 --- a/docs/classes/reference/get_target.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getTarget (Git\Reference method) - - -Git\\Reference::getTarget -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::getTarget** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/reference/get_type.rst b/docs/classes/reference/get_type.rst deleted file mode 100644 index fd0236a8b7..0000000000 --- a/docs/classes/reference/get_type.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getType (Git\Reference method) - - -Git\\Reference::getType -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::getType** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/reference/index.rst b/docs/classes/reference/index.rst deleted file mode 100644 index fb1796a78f..0000000000 --- a/docs/classes/reference/index.rst +++ /dev/null @@ -1,11 +0,0 @@ -Git\\Reference -=========================== - -.. note:: - this class is experimental. - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/reference/is_blob.rst b/docs/classes/reference/is_blob.rst deleted file mode 100644 index 6d1cff9d75..0000000000 --- a/docs/classes/reference/is_blob.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: isBlob (Git\Reference method) - - -Git\\Reference::isBlob -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::isBlob** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/reference/is_tree.rst b/docs/classes/reference/is_tree.rst deleted file mode 100644 index 20538ee5ea..0000000000 --- a/docs/classes/reference/is_tree.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: isTree (Git\Reference method) - - -Git\\Reference::isTree -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::isTree** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/reference/write.rst b/docs/classes/reference/write.rst deleted file mode 100644 index 61b2fc2dca..0000000000 --- a/docs/classes/reference/write.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: write (Git\Reference method) - - -Git\\Reference::write -=========================================================== - -Description -*********************************************************** - -public **Git\\Reference::write** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/repository/__construct.rst b/docs/classes/repository/__construct.rst deleted file mode 100644 index 30017b900e..0000000000 --- a/docs/classes/repository/__construct.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. index:: - single: __construct (Git\Repository method) - - -Git\\Repository::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Repository::__construct** ( [*$repository_path*]) - - -Parameters -*********************************************************** - -*repository_path* - git repository path. - - -Return Values -*********************************************************** - -:doc:`Git\Repository ` - -Examples -*********************************************************** - -.. code-block:: php - - ` - -*priority* - [low] 1 ... 5[high] - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -See Also -*********************************************************** - -:doc:`Git\\Backend ` \ No newline at end of file diff --git a/docs/classes/repository/add_backend.rst b/docs/classes/repository/add_backend.rst deleted file mode 100644 index ee61466a70..0000000000 --- a/docs/classes/repository/add_backend.rst +++ /dev/null @@ -1,119 +0,0 @@ -.. index:: - single: addBackend (Git\Repository method) - - -Git\\Repository::addBackend -=========================================================== - -Description -*********************************************************** - -public **Git\\Repository::addBackend** (*$backend*, *$priority*) - - -Parameters -*********************************************************** - -*backend* - Specifies a class that inherits from :doc:`Git\\Backend ` - -*priority* - [low] 1 ... 5[high] - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - exists($key)){ - $object = $this->get($key); - return $object; - } - } - - /** - * Read Header - * - * @param string $key sha1 hash. - * @return Git\RawObject - */ - public function read_header($key){ - if(isset($this->memory[$key])){ - return new \Git\RawObject($obj->type,"",$obj->len); - } - } - - /** - * check specified contents. - * - * @param string $key sha1 hash. - * @return boolean - */ - public function exists($key){ - if(isset($this->memory[$key])){ - return true; - }else{ - return false; - } - } - - /** - * write contents - * - * you have to write key,data,type your storage engine. - * - * @param string $key sha1 hash. - * @param Git\RawObject $object. - * @return hash - */ - public function write($object){ - $key = $object->getId(); - $std = new \Stdclass(); - $std->data = $object->data; - $std->type = $object->type; - $std->len = $object->len; - $this->memory[$key] = $std; - return $key; - } - - public function free() - { - unset($this->memory); - } - } - - - $repository = new Git\Repository("/tmp/example/.git"); - $repository->addBackend(new MemoryBackend(), 5);// higher priority. - -See Also -*********************************************************** - -:doc:`Git\\Backend ` \ No newline at end of file diff --git a/docs/classes/repository/get_commit.rst b/docs/classes/repository/get_commit.rst deleted file mode 100644 index 57beb1dbb6..0000000000 --- a/docs/classes/repository/get_commit.rst +++ /dev/null @@ -1,41 +0,0 @@ -.. index:: - single: getCommit (Git\Repository method) - - -Git\\Repository::getCommit -=========================================================== - -returns specified Git\\Commit. - -Description -*********************************************************** - -public **Git\\Repository::getCommit** (string *$hash*) - - -Parameters -*********************************************************** - -*hash* - commit hash id. - - -Return Values -*********************************************************** - -:doc:`Git\\Commit ` - -Examples -*********************************************************** - -.. code-block:: php - - getCommit("cd584aba22827a6a59cad3ab1b4e026418558bfb"); - - -See Also -*********************************************************** - -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/repository/get_index.rst b/docs/classes/repository/get_index.rst deleted file mode 100644 index 9eb8289742..0000000000 --- a/docs/classes/repository/get_index.rst +++ /dev/null @@ -1,36 +0,0 @@ -.. index:: - single: getIndex (Git\Repository method) - - -Git\\Repository::getIndex -=========================================================== - -returns current Git\Index object. this method will fail when bare repository. - -Description -*********************************************************** - -public **Git\\Repository::getIndex** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -:doc:`Git\\Index ` - -Examples -*********************************************************** - -.. code-block:: php - - getIndex(); - - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/repository/get_object.rst b/docs/classes/repository/get_object.rst deleted file mode 100644 index d9572f5f7d..0000000000 --- a/docs/classes/repository/get_object.rst +++ /dev/null @@ -1,44 +0,0 @@ -.. index:: - single: getObject (Git\Repository method) - - -Git\\Repository::getObject -=========================================================== - -returns specified Git\\Blob. - -.. note:: - this method will rename to Git\\Repository::getBlob - -Description -*********************************************************** - -public **Git\\Repository::getObject** (*$hash*) - - -Parameters -*********************************************************** - -*hash* - blob hash id. - - -Return Values -*********************************************************** - -:doc:`Git\\Blob ` - -Examples -*********************************************************** - -.. code-block:: php - - getObject("cd584aba22827a6a59cad3ab1b4e026418558bfb"); - - -See Also -*********************************************************** - -:doc:`Git\\Blob ` diff --git a/docs/classes/repository/get_references.rst b/docs/classes/repository/get_references.rst deleted file mode 100644 index 073e066275..0000000000 --- a/docs/classes/repository/get_references.rst +++ /dev/null @@ -1,43 +0,0 @@ -.. index:: - single: getReferences (Git\Repository method) - - -Git\\Repository::getReferences -=========================================================== - -returns a list with all the references that can be found in a repository. - -.. note:: - this method may changed next development. - -Description -*********************************************************** - -public **Git\\Repository::getReferences** (int *$flag*) - - -Parameters -*********************************************************** - -*flag* - fill them out lator - - -Return Values -*********************************************************** - -:doc:`array Git\\References ` - -Examples -*********************************************************** - -.. code-block:: php - - getReferences(); - -See Also -*********************************************************** - -:doc:`Git\\Reference ` \ No newline at end of file diff --git a/docs/classes/repository/get_tree.rst b/docs/classes/repository/get_tree.rst deleted file mode 100644 index 181317e395..0000000000 --- a/docs/classes/repository/get_tree.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. index:: - single: getTree (Git\Repository method) - - -Git\\Repository::getTree -=========================================================== - -returns specified Git\\Tree. - -Description -*********************************************************** - -public **Git\\Repository::getTree** (*$hash*) - - -Parameters -*********************************************************** - -*hash* - tree hash id. - - -Return Values -*********************************************************** - -:doc:`Git\\Tree ` - -Examples -*********************************************************** - -.. code-block:: php - - getTree("cd584aba22827a6a59cad3ab1b4e026418558bfb"); - -See Also -*********************************************************** - -:doc:`Git\\Tree ` \ No newline at end of file diff --git a/docs/classes/repository/get_walker.rst b/docs/classes/repository/get_walker.rst deleted file mode 100644 index df9acbb732..0000000000 --- a/docs/classes/repository/get_walker.rst +++ /dev/null @@ -1,44 +0,0 @@ -.. index:: - single: getWalker (Git\Repository method) - - -Git\\Repository::getWalker -=========================================================== - -returns Git\Revwalk. - -Description -*********************************************************** - -public **Git\\Repository::getWalker** () - - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -:doc:`Git\\Revwalk ` - -Examples -*********************************************************** - - -.. code-block:: php - - lookupRef("refs/heads/master"); - $walker = $repo->getWalker(); - $walker->push($reference->getId()); - - while($commit = $walker->next()){ - var_dump($commit); - } - -See Also -*********************************************************** - -:doc:`Git\\Revwalk ` -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/repository/index.rst b/docs/classes/repository/index.rst deleted file mode 100644 index 1e7e1fd91e..0000000000 --- a/docs/classes/repository/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -Git\\Repository -=========================== - -representation of git_repository. - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/repository/init.rst b/docs/classes/repository/init.rst deleted file mode 100644 index 3a90e70106..0000000000 --- a/docs/classes/repository/init.rst +++ /dev/null @@ -1,45 +0,0 @@ -.. index:: - single: init (Git\Repository method) - - -Git\\Repository::init -=========================================================== - -create a new git repository on your filesystem. - -Description -*********************************************************** - -public static **Git\\Repository::init** (*$path*, *$is_bare*) - - -Parameters -*********************************************************** - -*path* - blank directory - -*is_bare* - create bare repository when is_bare is true. - - -.. note:: - do not call this method when specified repository exists. - -Return Values -*********************************************************** - -:doc:`Git\\Repository ` - -Examples -*********************************************************** - -.. code-block:: php - - ` \ No newline at end of file diff --git a/docs/classes/repository/lookup_ref.rst b/docs/classes/repository/lookup_ref.rst deleted file mode 100644 index f98348ffc7..0000000000 --- a/docs/classes/repository/lookup_ref.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. index:: - single: lookupRef (Git\Repository method) - - -Git\\Repository::lookupRef -=========================================================== - -return specified reference object. - -Description -*********************************************************** - -public **Git\\Repository::lookupRef** (*$name*) - - -Parameters -*********************************************************** - -*name* - reference name. - - -Return Values -*********************************************************** - -:doc:`Git\\Reference ` - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - -See Also -*********************************************************** - -:doc:`Git\\Reference ` \ No newline at end of file diff --git a/docs/classes/repository/open2.rst b/docs/classes/repository/open2.rst deleted file mode 100644 index 75fb4193c2..0000000000 --- a/docs/classes/repository/open2.rst +++ /dev/null @@ -1,53 +0,0 @@ -.. index:: - single: open2 (Git\Repository method) - - -Git\\Repository::open2 -=========================================================== - -Description -*********************************************************** - -public **Git\\Repository::open2** (string *$git_dir*, string *$git_object_dir*, string *$git_index_file*, string *$git_working_tree*) - - -Parameters -*********************************************************** - -*git_dir* - git repository directory - -*git_object_dir* - object directory - -*git_index_file* - index file - -*git_working_tree* - working tree directory - -Return Values -*********************************************************** - -boolean - -Examples -*********************************************************** - -.. code-block:: php - - open2( - "/home/chobie/src/libgit2/.git", // git directory - "/home/chobie/src/libgit2/.git/objects",// git object directory - "/home/chobie/src/libgit2/.git/index", // git index file - "/home/chobie/src/libgit2/" // git working tree - ); - - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/repository/open3.rst b/docs/classes/repository/open3.rst deleted file mode 100644 index ced0b9ffd6..0000000000 --- a/docs/classes/repository/open3.rst +++ /dev/null @@ -1,37 +0,0 @@ -.. index:: - single: open3 (Git\Repository method) - - -Git\\Repository::open3 -=========================================================== - -Description -*********************************************************** - -public **Git\\Repository::open3** (string *$git_dir*, [Git\Odb *$odb*], [string *$index*], [string *$tree*]) - - -Parameters -*********************************************************** - -*git_dir* - specified git repository directory - -*odb* - Git\Odb object which added custom backends. - -*index* - specified git index path. - -*tree* - specified git working tree path. - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/revwalk/__construct.rst b/docs/classes/revwalk/__construct.rst deleted file mode 100644 index 977eef6222..0000000000 --- a/docs/classes/revwalk/__construct.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. index:: - single: __construct (Git\Revwalk method) - - -Git\\Revwalk::__construct -=========================================================== - -.. note:: - you should use Git\\Repository::getWalker() instead. - -Description -*********************************************************** - -public **Git\\Revwalk::__construct** () - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** - -:doc:`Git\\Repository ` -:doc:`Git\\Repository::getWalker() ` \ No newline at end of file diff --git a/docs/classes/revwalk/hide.rst b/docs/classes/revwalk/hide.rst deleted file mode 100644 index e21390fd38..0000000000 --- a/docs/classes/revwalk/hide.rst +++ /dev/null @@ -1,52 +0,0 @@ -.. index:: - single: hide (Git\Revwalk method) - - -Git\\Revwalk::hide -=========================================================== - -hide uninterested commits. - -:: - - o---o---o---o---o---o---o---o - `--o---o--/ - ^hide - -:: - - o---o---o---o---o---o---o---o - - -Description -*********************************************************** - -public **Git\\Revwalk::hide** (*$hash*) - - -Parameters -*********************************************************** - -*hash* - uninterested commit id - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $revwalk = $repo->getWalker(); - $uninterested = "";// specified uninterested commit id - $revwalk->hide($uninterested); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/revwalk/index.rst b/docs/classes/revwalk/index.rst deleted file mode 100644 index 076b50f1bf..0000000000 --- a/docs/classes/revwalk/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\Revwalk -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/revwalk/next.rst b/docs/classes/revwalk/next.rst deleted file mode 100644 index 363129a702..0000000000 --- a/docs/classes/revwalk/next.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. index:: - single: next (Git\Revwalk method) - - -Git\\Revwalk::next -=========================================================== - -get next travasable commit. - -Description -*********************************************************** - -public **Git\\Revwalk::next** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -:doc:`Git\\Commit ` - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $revwalk = $repo->getWalker(); - $revwalk->push($master->getId()); - $commit = $revwalk->next(); - -See Also -*********************************************************** - -:doc:`Git\\Commit ` \ No newline at end of file diff --git a/docs/classes/revwalk/push.rst b/docs/classes/revwalk/push.rst deleted file mode 100644 index 248c5ed3f1..0000000000 --- a/docs/classes/revwalk/push.rst +++ /dev/null @@ -1,46 +0,0 @@ -.. index:: - single: push (Git\Revwalk method) - - -Git\\Revwalk::push -=========================================================== - -push commit to revwalk object. - -Description -*********************************************************** - -public **Git\\Revwalk::push** (string *$hash*) - - -Parameters -*********************************************************** - -*hash* - commit id - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $revwalk = $repo->getWalker(); - $revwalk->push($master->getId()); - while($commit = $revwalk->next()){ - // - } - -See Also -*********************************************************** - -:doc:`Git\\Reference ` -:doc:`Git\\Revwalk::next() ` \ No newline at end of file diff --git a/docs/classes/revwalk/reset.rst b/docs/classes/revwalk/reset.rst deleted file mode 100644 index 5d08195cd5..0000000000 --- a/docs/classes/revwalk/reset.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. index:: - single: reset (Git\Revwalk method) - - -Git\\Revwalk::reset -=========================================================== - -reset internal pointer. - -Description -*********************************************************** - -public **Git\\Revwalk::reset** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $revwalk = $repo->getWalker(); - $revwalk->push($master->getId()); - $commit = $revwalk->next(); - $revwalk->reset(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/revwalk/sort.rst b/docs/classes/revwalk/sort.rst deleted file mode 100644 index 94c15b06f9..0000000000 --- a/docs/classes/revwalk/sort.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. index:: - single: sort (Git\Revwalk method) - - -Git\\Revwalk::sort -=========================================================== - -Description -*********************************************************** - -public **Git\\Revwalk::sort** (int *$sort_type*) - -Parameters -*********************************************************** - -*sort_type* - specified sort type - -- Git\\Revwalk\\SORT_NONE -- Git\\Revwalk\\SORT_TOPO -- Git\\Revwalk\\SORT_DATE -- Git\\Revwalk\\SORT_REVERSE - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $revwalk = $repo->getWalker(); - $revwalk->sort(Git\Revwalk\SORT_REVERSE); - $revwalk->push($master->getId()); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/signature/__construct.rst b/docs/classes/signature/__construct.rst deleted file mode 100644 index 139be090fd..0000000000 --- a/docs/classes/signature/__construct.rst +++ /dev/null @@ -1,49 +0,0 @@ -.. index:: - single: __construct (Git\Signature method) - - -Git\\Signature::__construct -=========================================================== - -create signature. - -Description -*********************************************************** - -public **Git\\Signature::__construct** (string *$name*,string *$email*, \\DateTime *$when*) - - -Parameters -*********************************************************** - -*name* - full name. e.g) John Smith - -*email* - email. e.g) john.smith@example.com - -*when* - commit time - - -Return Values -*********************************************************** - -:doc:`Git\\Signature ` - -Examples -*********************************************************** - -.. code-block:: php - - ` \ No newline at end of file diff --git a/docs/classes/signature/index.rst b/docs/classes/signature/index.rst deleted file mode 100644 index 760a7aface..0000000000 --- a/docs/classes/signature/index.rst +++ /dev/null @@ -1,9 +0,0 @@ -Git\\Signature -=========================== - - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/tag/__construct.rst b/docs/classes/tag/__construct.rst deleted file mode 100644 index a7dfea078f..0000000000 --- a/docs/classes/tag/__construct.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: __construct (Git\Tag method) - - -Git\\Tag::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::__construct** (*$repository*) - - -Parameters -*********************************************************** - -*repository* - fill them out later - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/get_id.rst b/docs/classes/tag/get_id.rst deleted file mode 100644 index b3db254693..0000000000 --- a/docs/classes/tag/get_id.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getId (Git\Tag method) - - -Git\\Tag::getId -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::getId** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/get_message.rst b/docs/classes/tag/get_message.rst deleted file mode 100644 index c9ee07bade..0000000000 --- a/docs/classes/tag/get_message.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getMessage (Git\Tag method) - - -Git\\Tag::getMessage -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::getMessage** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/get_name.rst b/docs/classes/tag/get_name.rst deleted file mode 100644 index e5e61459b0..0000000000 --- a/docs/classes/tag/get_name.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getName (Git\Tag method) - - -Git\\Tag::getName -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::getName** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/get_target.rst b/docs/classes/tag/get_target.rst deleted file mode 100644 index 4ec63969fa..0000000000 --- a/docs/classes/tag/get_target.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getTarget (Git\Tag method) - - -Git\\Tag::getTarget -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::getTarget** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/get_type.rst b/docs/classes/tag/get_type.rst deleted file mode 100644 index 1304ee9035..0000000000 --- a/docs/classes/tag/get_type.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: getType (Git\Tag method) - - -Git\\Tag::getType -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::getType** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/index.rst b/docs/classes/tag/index.rst deleted file mode 100644 index d6ca7a118a..0000000000 --- a/docs/classes/tag/index.rst +++ /dev/null @@ -1,12 +0,0 @@ -Git\\Tag -=========================== - - -.. note:: - this class experimental. use :doc:`Git\\Reference ` instead. - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/tag/is_blob.rst b/docs/classes/tag/is_blob.rst deleted file mode 100644 index b1980c842e..0000000000 --- a/docs/classes/tag/is_blob.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: isBlob (Git\Tag method) - - -Git\\Tag::isBlob -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::isBlob** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/is_tree.rst b/docs/classes/tag/is_tree.rst deleted file mode 100644 index de3d61c565..0000000000 --- a/docs/classes/tag/is_tree.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: isTree (Git\Tag method) - - -Git\\Tag::isTree -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::isTree** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/set_message.rst b/docs/classes/tag/set_message.rst deleted file mode 100644 index a825c083da..0000000000 --- a/docs/classes/tag/set_message.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: setMessage (Git\Tag method) - - -Git\\Tag::setMessage -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::setMessage** (*$message*) - - -Parameters -*********************************************************** - -*message* - fill them out later - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/set_name.rst b/docs/classes/tag/set_name.rst deleted file mode 100644 index bd498fcfd7..0000000000 --- a/docs/classes/tag/set_name.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: setName (Git\Tag method) - - -Git\\Tag::setName -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::setName** (*$name*) - - -Parameters -*********************************************************** - -*name* - fill them out later - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/set_target.rst b/docs/classes/tag/set_target.rst deleted file mode 100644 index 74a702ab3c..0000000000 --- a/docs/classes/tag/set_target.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: setTarget (Git\Tag method) - - -Git\\Tag::setTarget -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::setTarget** (*$target*) - - -Parameters -*********************************************************** - -*target* - fill them out later - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tag/write.rst b/docs/classes/tag/write.rst deleted file mode 100644 index 4b0a339d20..0000000000 --- a/docs/classes/tag/write.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. index:: - single: write (Git\Tag method) - - -Git\\Tag::write -=========================================================== - -Description -*********************************************************** - -public **Git\\Tag::write** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tree/__construct.rst b/docs/classes/tree/__construct.rst deleted file mode 100644 index b58bd347b1..0000000000 --- a/docs/classes/tree/__construct.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. index:: - single: __construct (Git\Tree method) - - -Git\\Tree::__construct -=========================================================== - -Description -*********************************************************** - -public **Git\\Tree::__construct** (Git\Repository *$repository*) - - -Parameters -*********************************************************** - -*repository* - Git\Repository Object - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tree/add.rst b/docs/classes/tree/add.rst deleted file mode 100644 index b5f3f62d83..0000000000 --- a/docs/classes/tree/add.rst +++ /dev/null @@ -1,56 +0,0 @@ -.. index:: - single: add (Git\Tree method) - - -Git\\Tree::add -=========================================================== - -Description -*********************************************************** - -public **Git\\Tree::add** (string *$hash*, string *$name*, int *$mode*) - - -Parameters -*********************************************************** - -*hash* - specified object id. - -*name* - file name. - -*mode* - file attribute. - - - ======== ========================== - 100644 Regular file - 100755 Regular file & executable - 120000 Symbolic link - 40000 Directory - 160000 submodule - ======== ========================== - - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - add($hash,"README",100644); - $tree_hash = $tree->write(); - -See Also -*********************************************************** - -:doc:`Git\\Tree ` \ No newline at end of file diff --git a/docs/classes/tree/count.rst b/docs/classes/tree/count.rst deleted file mode 100644 index d74ecc074f..0000000000 --- a/docs/classes/tree/count.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. index:: - single: count (Git\Tree method) - - -Git\\Tree::count -=========================================================== - -Countable interface. - -Description -*********************************************************** - -public **Git\\Tree::count** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -int count. - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $tree = $repository->getTree($refs->getId()); - echo count($tree); // or echo $tree->count(); - -See Also -*********************************************************** - -`Countable Interface `_ (PHP Documents) \ No newline at end of file diff --git a/docs/classes/tree/get_entries.rst b/docs/classes/tree/get_entries.rst deleted file mode 100644 index a21b37f1fb..0000000000 --- a/docs/classes/tree/get_entries.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. index:: - single: getEntries (Git\Tree method) - - -Git\\Tree::getEntries -=========================================================== - -returns tree entry array. - -Description -*********************************************************** - -public **Git\\Tree::getEntries** () - - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -array Git\Tree\Entry - -Examples -*********************************************************** - -.. code-block::php - - getTree($repo->getCommit($repo->lookupRef("refs/heads/master"))); - $result = $tree->getEntries(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tree/get_entry.rst b/docs/classes/tree/get_entry.rst deleted file mode 100644 index cc88680512..0000000000 --- a/docs/classes/tree/get_entry.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. index:: - single: getEntry (Git\Tree method) - - -Git\\Tree::getEntry -=========================================================== - -returns specified tree entry. - -Description -*********************************************************** - -public **Git\\Tree::getEntry** (int *$offset* = 0) - - -Parameters -*********************************************************** - -*offset* - tree entry offset - - -Return Values -*********************************************************** - -Git\Tree\Entry - -Examples -*********************************************************** - -.. code-block::php - - getTree($repo->getCommit($repo->lookupRef("refs/heads/master"))); - $result = $tree->getEntry(0); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tree/get_id.rst b/docs/classes/tree/get_id.rst deleted file mode 100644 index df86c57564..0000000000 --- a/docs/classes/tree/get_id.rst +++ /dev/null @@ -1,37 +0,0 @@ -.. index:: - single: getId (Git\Tree method) - - -Git\\Tree::getId -=========================================================== - -returns tree hash id. - -Description -*********************************************************** - -public **Git\\Tree::getId** () - - -Parameters -*********************************************************** - - -Return Values -*********************************************************** - -string hash id - -Examples -*********************************************************** - -.. code-block:: php - - lookupRef("refs/heads/master"); - $tree = $repository->getTree($refs->getId()); - echo $tree->getId(); - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tree/get_iterator.rst b/docs/classes/tree/get_iterator.rst deleted file mode 100644 index e09526cfa6..0000000000 --- a/docs/classes/tree/get_iterator.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. index:: - single: getIterator (Git\Tree method) - - -Git\\Tree::getIterator -=========================================================== - -IteratorAggregate interface. - -Description -*********************************************************** - -public **Git\\Tree::getIterator** () - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block::php - - getCommit($repo->lookupRef("refs/heads/master")->getId()); - $tree = $commit->getTree(); - foreach($tree->getIterator() as $entry){ - // something... - } - -See Also -*********************************************************** \ No newline at end of file diff --git a/docs/classes/tree/get_type.rst b/docs/classes/tree/get_type.rst deleted file mode 100644 index c824fc429b..0000000000 --- a/docs/classes/tree/get_type.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. index:: - single: getType (Git\Tree method) - - -Git\\Tree::getType -=========================================================== - -inherits Git\\Object. - -Description -*********************************************************** - -public **Git\\Tree::getType** () - - -Parameters -*********************************************************** - -Return Values -*********************************************************** - -Examples -*********************************************************** - -See Also -*********************************************************** - - -:doc:`Git\\Object::getType ` \ No newline at end of file diff --git a/docs/classes/tree/index.rst b/docs/classes/tree/index.rst deleted file mode 100644 index eeaae305aa..0000000000 --- a/docs/classes/tree/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -Git\\Tree -=========================== - -Git\\Tree extends Git\\Object - -.. toctree:: - :maxdepth: 1 - :glob: - - * diff --git a/docs/classes/tree/path.rst b/docs/classes/tree/path.rst deleted file mode 100644 index 33514f1fed..0000000000 --- a/docs/classes/tree/path.rst +++ /dev/null @@ -1,46 +0,0 @@ -.. index:: - single: path (Git\Tree method) - - -Git\\Tree::path -=========================================================== - -returns specified Git\Tree\Entry. - -Description -*********************************************************** - -public **Git\\Tree::path** (*$path*) - - -Parameters -*********************************************************** - -*path* - file name - - -Return Values -*********************************************************** - -:doc:`Git\\Tree\Entry ` - -Examples -*********************************************************** - -.. code-block:: php - - getTree("cd584aba22827a6a59cad3ab1b4e026418558bfb"); - $entry = $tree->path("README.md"); - - -.. note:: - - this method can't resolve recursive yet. - -See Also -*********************************************************** - -:doc:`Git\\Tree\\Entry ` \ No newline at end of file diff --git a/docs/classes/tree/remove.rst b/docs/classes/tree/remove.rst deleted file mode 100644 index a0ad0e3ec7..0000000000 --- a/docs/classes/tree/remove.rst +++ /dev/null @@ -1,40 +0,0 @@ -.. index:: - single: remove (Git\Tree method) - - -Git\\Tree::remove -=========================================================== - -Description -*********************************************************** - -public **Git\\Tree::remove** (string *$name*) - - -Parameters -*********************************************************** - -*name* - specified file name - -Return Values -*********************************************************** - -void - -Examples -*********************************************************** - -.. code-block:: php - - remove("README"); - $tree_hash = $tree->write(); - -See Also -*********************************************************** - -:doc:`Git\\Tree ` \ No newline at end of file diff --git a/docs/classes/tree/write.rst b/docs/classes/tree/write.rst deleted file mode 100644 index 581e1626e2..0000000000 --- a/docs/classes/tree/write.rst +++ /dev/null @@ -1,37 +0,0 @@ -.. index:: - single: write (Git\Tree method) - - -Git\\Tree::write -=========================================================== - -Description -*********************************************************** - -public **Git\\Tree::write** () - - -Parameters -*********************************************************** - - - -Return Values -*********************************************************** - -Examples -*********************************************************** - -.. code-block:: php - - add($hash,"README",100644); - $tree_hash = $tree->write(); - -See Also -*********************************************************** - -:doc:`Git\\Object::write ` \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py deleted file mode 100644 index a6e201f08c..0000000000 --- a/docs/conf.py +++ /dev/null @@ -1,219 +0,0 @@ -# -*- coding: utf-8 -*- -# -# php-git documentation build configuration file, created by -# sphinx-quickstart on Mon Jan 10 16:13:07 2011. -# -# This file is execfile()d with the current directory set to its containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys, os - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) - -# -- General configuration ----------------------------------------------------- - -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be extensions -# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinxcontrib.phpdomain','sphinxtogithub'] - -sphinx_to_github = True -sphinx_to_github_verbose = True - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix of source filenames. -source_suffix = '.rst' - -# The encoding of source files. -#source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'php-git' -copyright = u'2011, Shuhei Tanuma' - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. -version = '0.2' -# The full version, including alpha/beta/rc tags. -release = '0.2' - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -#language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ['_build'] - -# The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - - -# -- Options for HTML output --------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = 'sphinxdoc' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -#html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -#html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -#html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -#html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -#html_additional_pages = {} - -# If false, no module index is generated. -#html_domain_indices = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None - -# Output file base name for HTML help builder. -htmlhelp_basename = 'php-gitdoc' - - -# -- Options for LaTeX output -------------------------------------------------- - -# The paper size ('letter' or 'a4'). -#latex_paper_size = 'letter' - -# The font size ('10pt', '11pt' or '12pt'). -#latex_font_size = '10pt' - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). -latex_documents = [ - ('index', 'php-git.tex', u'php-git Documentation', - u'Shuhei Tanuma', 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -#latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False - -# If true, show page references after internal links. -#latex_show_pagerefs = False - -# If true, show URL addresses after external links. -#latex_show_urls = False - -# Additional stuff for the LaTeX preamble. -#latex_preamble = '' - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -#latex_domain_indices = True - - -# -- Options for manual page output -------------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'php-git', u'php-git Documentation', - [u'Shuhei Tanuma'], 1) -] diff --git a/docs/constants.rst b/docs/constants.rst deleted file mode 100644 index b113650743..0000000000 --- a/docs/constants.rst +++ /dev/null @@ -1,18 +0,0 @@ -Predefined Constants -================================================== - - -=========================== =============== -Key Value -=========================== =============== -Git\\Revwalk\\SORT_NONE 0 -Git\\Revwalk\\SORT_TOPO 1 -Git\\Revwalk\\SORT_DATE 2 -Git\\Revwalk\\SORT_REVERSE 4 -Git\\Object\\Any GIT_OBJ_ANY -Git\\Object\\Bad GIT_OBJ_BAD -Git\\Object\\Commit GIT_OBJ_COMMIT -Git\\Object\\Tree Git_OBJ_TREE -Git\\Object\\Blob Git_OBJ_BLOB -Git\\Object\\TAG Git_OBJ_TAG -=========================== =============== diff --git a/docs/docgen.php b/docs/docgen.php deleted file mode 100644 index 9d53f95592..0000000000 --- a/docs/docgen.php +++ /dev/null @@ -1,138 +0,0 @@ -getClassNames(); - -foreach($classes as $class){ - $ref = new ReflectionClass($class); - - $methods = $ref->getMethods(); - $namespace = array(); - - if(strpos($ref->getName(),"\\") !== false) { - $tmp = explode("\\",$ref->getName()); - $className = array_pop($tmp); - $name = strtolower($className); - $namespace = $tmp; - $nameSpace = join("\\\\",$namespace) . "\\\\"; - $nameSpace2 = join("\\",$namespace) . "\\"; - } else { - $className = $ref->getName(); - $name = strtolower($className); - } - - //if(!is_dir("class/" . $name)){ - @mkdir("class/" . $name,0766); - file_put_contents("class/" . $name . "/" . "index.rst",(<<getName(); - $method_name = strtolower(preg_replace('/([a-z])([A-Z])/', "$1_$2", $methodName)); - - $filename = "class/" .$name . "/" . $method_name . ".rst"; - //if(!is_file($filename)){ - $definition = genMethodDefinition($className, $method, $nameSpace); - $parameters = genParameterDocs($method); - file_put_contents($filename,(<<isPublic()){ - $result .= "public "; - }else if($ref->isProtected()){ - $result .= "protected "; - } - if($ref->isStatic()){ - $result .= "static "; - } - $result .= "**" . $namespace . $className; - $result .= "::"; - $result .= $ref->getName() . "**"; - $result .= " ("; - - $params = $ref->getParameters(); - $p = array(); - foreach($params as $param){ - $tmp = ""; - if($param->isOptional()){ - $tmp .= " ["; - } - - if($param->isArray()) { - $tmp .= " array "; - } - - $tmp .= "*\$" . $param->getName() . "*"; - - if($param->isOptional()){ - $tmp .= "]"; - } - $p[] = $tmp; - } - $result .= join(", ", $p); - $result .= ")"; - - return $result . PHP_EOL; -} - -function genParameterDocs($ref) -{ - $params = $ref->getParameters(); - $result = array(); - foreach($params as $param){ - $name = $param->getName(); - - $result[] = sprintf("*%s*\n fill them out later\n",$name); - } - - return join("\n",$result); - -} \ No newline at end of file diff --git a/docs/examples.rst b/docs/examples.rst deleted file mode 100644 index ab5e9b3060..0000000000 --- a/docs/examples.rst +++ /dev/null @@ -1,131 +0,0 @@ -Examples -================================================== - -php-git examples.these example uses experimental API. - -Create new blob -++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. code-block:: php - - setContent("First Object1"); - $blobHash = $blob->write(); - -:doc:`Git\Blob::setContent ` - -.. note:: - maybe this API will change next release. - -Create new Tree -++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. code-block:: php - - add($hash,"README",100644); - $tree_hash = $tree->write(); - -:doc:`Git\Tree::add ` - -.. note:: - maybe this API will change next release. - - -Create new Commit -++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. code-block:: php - - add($hash,"README",100644); - $tree_hash = $tree->write(); - $commit = new Git\Commit($repository); - $commit->setAuthor(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - $commit->setCommitter(new Git\Signature("Someone","someone@example.com", new DateTime("2011-01-01 00:00:00",new DateTimezone("Asia/Tokyo")))); - $commit->setTree($tree->getId()); - // when first commit. you dont call setParent. - //$commit->setParent($last_commit->getParent()->getId()); - $commit->setMessage("initial import"); - - $master_hash = $commit->write(); - -:doc:`Git\Tree::add ` -:doc:`Git\Commit::setAuthor ` -:doc:`Git\Commit::setCommitter ` -:doc:`Git\Commit::setTree ` -:doc:`Git\Commit::setParent ` -:doc:`Git\Commit::setMessage ` - -.. note:: - php-git can't manage multiple parents now. this will fix next release. - -get master tree -++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. code-block:: php - - getCommit($repository->lookupRef("refs/heads/master")); - $tree = $master_commit->getTree(); - // or $tree->getEntries() - foreach($tree->getIterator() as $entry){ - var_dump($entry); - } - -revision walking -++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. code-block:: php - - getCommit($repository->lookupRef("refs/heads/master")); - $walker = $master_commit->getWalker(); - $walker->push($master_commit->getId()); - while($commit = $walker->next()){ - var_dump($commit); - } - -custom backends -++++++++++++++++++++++++++++++++++++++++++++++++++ - -see also :doc:`Git\\Repository\\addBackend ` - - -get available references -++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. note:: - maybe this API will change next release. - -.. code-block:: php - - getList(); - -:doc:`Git\\Reference\\Manager ` - - -this method gets available all references.if you want gets available branches.you have to check manualy now. - -.. code-block:: php - - getList() as $ref){ - if(strpos($ref->name,"refs/heads")){ - $brandhes[] $ref; - } - } diff --git a/docs/index.rst b/docs/index.rst deleted file mode 100644 index 5f38db3856..0000000000 --- a/docs/index.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. php-git documentation master file, created by - sphinx-quickstart on Mon Jan 10 14:18:21 2011. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Welcome to php-git's documentation! -=================================== - -php-git is a set of PHP 5.3+ bindings to the libgit2 linkable C Git library. -*Important Notice* this module is EXPERIMENTAL. - -Contents: - -.. toctree:: - :maxdepth: 2 - :glob: - - intro - setup - constants - examples - classes/*/index - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`search` - diff --git a/docs/ini.rst b/docs/ini.rst deleted file mode 100644 index bd9c7ae300..0000000000 --- a/docs/ini.rst +++ /dev/null @@ -1,4 +0,0 @@ -Runtime Configuration -================================================== - -nothing. diff --git a/docs/installation.rst b/docs/installation.rst deleted file mode 100644 index cff0d07414..0000000000 --- a/docs/installation.rst +++ /dev/null @@ -1,24 +0,0 @@ -Installation -================================================== - -.. code-block:: bash - - cd /tmp - git clone https://github.com/libgit2/libgit2 libgit2 - git clone https://github.com/libgit2/php-git php-git - cd libgit2 - git checkout `cat ../php-git/LIBGIT2_VERSION` - ./waf configure - ./waf build-shared - sudo ./waf install-shared - - cd ../php-git/src - phpize - ./configure && make - sudo make install - # add your php.ini - # extension=git.so - -.. note:: - php-git still under development status. - should not use production environment. \ No newline at end of file diff --git a/docs/intro.rst b/docs/intro.rst deleted file mode 100644 index 38266b261f..0000000000 --- a/docs/intro.rst +++ /dev/null @@ -1,6 +0,0 @@ -Introduction -================================================== - -Git module provides handy procedural and object oriented interface to libgit2. - -More information about libgit2 can be found at https://github.com/libgit2/libgit2 diff --git a/docs/requirements.rst b/docs/requirements.rst deleted file mode 100644 index 2800ddd9da..0000000000 --- a/docs/requirements.rst +++ /dev/null @@ -1,7 +0,0 @@ -Requirements -================================================== - -- `libgit2 `_ -- php5.3 higher -- php-devel -- pcre-devel diff --git a/docs/resources.rst b/docs/resources.rst deleted file mode 100644 index 58b707d4de..0000000000 --- a/docs/resources.rst +++ /dev/null @@ -1,4 +0,0 @@ -Resources -================================================== - -nothing diff --git a/docs/setup.rst b/docs/setup.rst deleted file mode 100644 index b92277ba65..0000000000 --- a/docs/setup.rst +++ /dev/null @@ -1,12 +0,0 @@ -Installing/Configuring -================================================== - -Table of Contents: - -.. toctree:: - :maxdepth: 2 - - requirements - installation - ini - resources diff --git a/src/backend.c b/src/backend.c deleted file mode 100644 index 92083a9f1b..0000000000 --- a/src/backend.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_backend_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read, 0, 0, 1) - ZEND_ARG_INFO(0, id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_read_header, 0, 0, 1) - ZEND_ARG_INFO(0, id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_exists, 0, 0, 1) - ZEND_ARG_INFO(0, id) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_backend_write, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - - -int php_git_backend__exists(git_odb_backend *backend, const git_oid *oid); -int php_git_backend__write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type); -int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id); -int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id); -void php_git_backend__free(git_odb_backend *backend); - - -static void php_git_backend_free_storage(php_git_backend_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - if(obj->backend) { - php_git_backend_internal *backend = obj->backend; - efree(obj->backend); - obj->backend = NULL; - } - efree(obj); -} - - -zend_object_value php_git_backend_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_backend_t *backend; - zval *tmp; - - backend = ecalloc(1, sizeof(php_git_backend_t)); - zend_object_std_init( &backend->zo, ce TSRMLS_CC ); - - zend_hash_copy(backend->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(backend, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_backend_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - - return retval; -} - -int php_git_backend__exists(git_odb_backend *_backend, const git_oid *oid) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - zval *retval, *params[1], func; - int result; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - ZVAL_STRING(&func,"exists", 1); - MAKE_STD_ZVAL(params[0]); - ZVAL_STRING(params[0],out, 1); - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call exists method"); - return 0; - } - result = Z_BVAL_P(retval); - zval_ptr_dtor(&retval); - zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - - if(result){ - return 1; - }else{ - return 0; - } -} -int php_git_backend__write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - int ret = 0; - char out[GIT_OID_HEXSZ+1] = {0}; - zval *retval; - zval *params[1]; - zval func; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - ZVAL_STRING(&func,"write", 1); - - MAKE_STD_ZVAL(params[0]); - object_init_ex(params[0],git_rawobject_class_entry); - - git_oid_to_string(out,GIT_OID_HEXSZ,id); - - add_property_stringl_ex(params[0],"data",sizeof("data"),(char *)buffer,size,1 TSRMLS_CC); - add_property_stringl_ex(params[0],"id", sizeof("id"), (char *)out, GIT_OID_HEXSZ,1 TSRMLS_CC); - add_property_long(params[0],"type",type); - add_property_long(params[0],"len",size); - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call write method"); - return GIT_ERROR; - } - if (Z_BVAL_P(retval)) { - ret = GIT_SUCCESS; - } else { - ret = GIT_ERROR; - } - - zval_ptr_dtor(&retval); - - // do not free Git\RawObject here. - //zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - - return ret; -} -int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *oid) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - int result = GIT_ERROR; - zval *str, *len, *tp, *retval, *params[1], func; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - - ZVAL_STRING(&func,"read", 1); - - MAKE_STD_ZVAL(params[0]); - ZVAL_STRING(params[0],out, 1); - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call read method"); - result = GIT_ERROR; - goto cleanup; - } - - if(Z_BVAL_P(retval) == 0) { - result = GIT_ERROR; - goto cleanup; - } - - if(!instanceof_function(Z_OBJCE_P(retval), git_rawobject_class_entry TSRMLS_CC)){ - fprintf(stderr,"read interface must return Git\\RawObject"); - result = GIT_ERROR; - goto cleanup; - } - - str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC); - len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); - tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); - - buffer = calloc(1,Z_LVAL_P(len)); - memcpy(buffer,Z_STRVAL_P(str),Z_LVAL_P(len)); - type = Z_LVAL_P(tp); - size = Z_LVAL_P(len); - - result = GIT_SUCCESS; - - -cleanup: - zval_ptr_dtor(&retval); - zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - return result; -} - -int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *oid) -{ - TSRMLS_FETCH(); - php_git_backend_internal *object = (php_git_backend_internal *)_backend; - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - zval *len, *tp, *retval, *params[1], func; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - - ZVAL_STRING(&func,"read", 1); - - MAKE_STD_ZVAL(params[0]); - ZVAL_STRING(params[0],out, 1); - - if(call_user_function(NULL,&object->self,&func,retval,1,params TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call read method"); - return GIT_ERROR; - } - - if(!instanceof_function(Z_OBJCE_P(retval), git_rawobject_class_entry TSRMLS_CC)){ - fprintf(stderr,"read interface must return Git\\RawObject"); - return GIT_ENOTFOUND; - } - - len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC); - tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC); - - type = Z_LVAL_P(tp); - size = Z_LVAL_P(len); - - zval_ptr_dtor(&retval); - zval_ptr_dtor(¶ms[0]); - zval_dtor(&func); - - return GIT_SUCCESS; -} - -void php_git_backend__free(git_odb_backend *backend) -{ - TSRMLS_FETCH(); - zval func, *retval; - php_git_backend_internal *object = (php_git_backend_internal *)backend; - - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - - ZVAL_STRING(&func,"free", 1); - - if(call_user_function(NULL,&object->self,&func,retval,0,NULL TSRMLS_CC) == FAILURE){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't call free method"); - - return; - } - - zval_ptr_dtor(&retval); - zval_dtor(&func); -} - - -PHP_METHOD(git_backend, __construct) -{ - php_git_backend_t *this = (php_git_backend_t *)zend_object_store_get_object(getThis() TSRMLS_CC); - php_git_backend_internal *internal; - - internal = ecalloc(1,sizeof(php_git_backend_internal)); - internal->parent.read = &php_git_backend__read; - internal->parent.read_header = &php_git_backend__read_header; - internal->parent.write = &php_git_backend__write; - internal->parent.exists = &php_git_backend__exists; - internal->parent.free = &php_git_backend__free; - internal->self = getThis(); - - this->backend = internal; -} - -static zend_function_entry php_git_backend_methods[] = { - PHP_ME(git_backend, __construct, NULL, ZEND_ACC_PUBLIC) - PHP_ABSTRACT_ME(git_backend, read, arginfo_git_backend_read) - PHP_ABSTRACT_ME(git_backend, read_header, arginfo_git_backend_read_header) - PHP_ABSTRACT_ME(git_backend, exists, arginfo_git_backend_exists) - PHP_ABSTRACT_ME(git_backend, write, arginfo_git_backend_write) - PHP_ABSTRACT_ME(git_backend, free, NULL) - {NULL, NULL, NULL} -}; - -void git_init_backend(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Backend", php_git_backend_methods); - git_backend_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git_backend_class_entry->create_object = php_git_backend_new; -} diff --git a/src/blob.c b/src/blob.c deleted file mode 100644 index eeb11de4d7..0000000000 --- a/src/blob.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_blob_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob__construct, 0, 0, 1) - ZEND_ARG_INFO(0, repository) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_load_string, 0, 0, 1) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_blob_load_file, 0, 0, 1) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - - -static void php_git_blob_free_storage(php_git_blob_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - if (obj->object != NULL) { - git_object_free(obj->object); - obj->object = NULL; - } - if(obj->contents != NULL) { - efree(obj->contents); - obj->contents = NULL; - } - - efree(obj); -} - -zend_object_value php_git_blob_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_blob_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_blob_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - - return retval; -} - - - -PHP_METHOD(git_blob, __construct) -{ - zval *z_repository; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &z_repository) == FAILURE){ - return; - } - - php_git_repository_t *git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC); - php_git_blob_t *obj = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - obj->repository = git->repository; -} - -static int php_git_blob_common_load(enum php_git_blob_write_type type,INTERNAL_FUNCTION_PARAMETERS) -{ - php_git_blob_t *this = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *contents; - int contents_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &contents, &contents_len) == FAILURE) { - return -1; - } - - if(contents_len <= 0) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't set null string."); - return -1; - } - - this->type = type; - this->contents = estrndup(contents,contents_len); - this->contents_len = contents_len; - - return 0; -} - -PHP_METHOD(git_blob, loadFile) -{ - php_git_blob_common_load(PHP_GIT_LOAD_FROM_FILE,INTERNAL_FUNCTION_PARAM_PASSTHRU); - RETURN_TRUE; -} - -PHP_METHOD(git_blob, loadString) -{ - php_git_blob_common_load(PHP_GIT_LOAD_FROM_STRING,INTERNAL_FUNCTION_PARAM_PASSTHRU); - RETURN_TRUE; -} - -PHP_METHOD(git_blob, write) -{ - php_git_blob_t *this = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char oid_str[GIT_OID_HEXSZ+1] = {0}; - git_oid out; - int ret = 0; - - if (this->type == PHP_GIT_LOAD_FROM_STRING) { - ret = git_blob_create_frombuffer(&out,this->repository,this->contents,this->contents_len); - if(ret != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't write blob."); - RETURN_FALSE; - } - } else if(this->type == PHP_GIT_LOAD_FROM_FILE) { - ret = git_blob_create_fromfile(&out,this->repository,this->contents); - if(ret != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"can't write blob."); - RETURN_FALSE; - } - } - - git_oid_to_string(oid_str,GIT_OID_HEXSZ+1,&out); - RETVAL_STRING(oid_str,1); -} - -static zend_function_entry php_git_blob_methods[] = { - PHP_ME(git_blob, __construct, arginfo_git_blob__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_blob, loadString, arginfo_git_blob_load_string, ZEND_ACC_PUBLIC) - PHP_ME(git_blob, loadFile, arginfo_git_blob_load_file, ZEND_ACC_PUBLIC) - PHP_ME(git_blob, write, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_blob(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Blob", php_git_blob_methods); - - git_blob_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry, NULL TSRMLS_CC); - git_blob_class_entry->create_object = php_git_blob_new; -} diff --git a/src/commit.c b/src/commit.c deleted file mode 100644 index 4f534deeff..0000000000 --- a/src/commit.c +++ /dev/null @@ -1,409 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repository *repository); -extern zend_object_value php_git_repository_new(zend_class_entry *ce TSRMLS_DC); - -PHPAPI zend_class_entry *git_commit_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit__construct, 0, 0, 1) - ZEND_ARG_INFO(0, repository) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_get_parent, 0, 0, 1) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_author, 0, 0, 1) - ZEND_ARG_INFO(0, author) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_committer, 0, 0, 1) - ZEND_ARG_INFO(0, committer) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_parents, 0, 0, 1) - ZEND_ARG_INFO(0, parents) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_message, 0, 0, 1) - ZEND_ARG_INFO(0, message) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_set_tree, 0, 0, 1) - ZEND_ARG_INFO(0, tree) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_commit_write, 0, 0, 1) - ZEND_ARG_INFO(0, update_ref) -ZEND_END_ARG_INFO() - -static void php_git_commit_free_storage(php_git_commit_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - obj->object = NULL; - obj->repository = NULL; - efree(obj); -} - -zend_object_value php_git_commit_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_commit_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_commit_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -PHP_METHOD(git_commit, __construct) -{ - zval *object = getThis(); - zval *z_repository; - git_commit *commit; - git_repository *repository; - int ret; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &z_repository) == FAILURE){ - return; - } - object_init_ex(object, git_commit_class_entry); - php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(object TSRMLS_CC); - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC); - - - cobj->repository = myobj->repository; -} - -PHP_METHOD(git_commit, getCommitter) -{ - zval *object = getThis(); - zval *signature = zend_read_property(git_commit_class_entry, object,"committer",9, 0 TSRMLS_CC); - - zval_copy_ctor(signature); - RETURN_ZVAL(signature,0, 0); -} - -PHP_METHOD(git_commit, getMessage) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - const char *message; - - message = git_commit_message(this->object); - RETURN_STRING(message,1); -} - -PHP_METHOD(git_commit, getShortMessage) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - const char *message; - - message = git_commit_message_short(this->object); - RETURN_STRING(message,1); -} - -PHP_METHOD(git_commit, getTree) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_tree *ref_tree, *tree; - git_oid *tree_oid; - zval *git_tree, *entry; - const git_oid *oid; - - git_commit_tree(&ref_tree, this->object); - oid = git_object_id((git_object*)ref_tree); - - int ret = git_object_lookup((git_object **)&tree, git_object_owner((git_object*)this->object),oid, GIT_OBJ_TREE); - if(ret != GIT_SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "specified tree not found."); - return; - } - - - MAKE_STD_ZVAL(git_tree); - object_init_ex(git_tree, git_tree_class_entry); - php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); - tobj->object = tree; - tobj->repository = this->repository; - - RETURN_ZVAL(git_tree,0,1); -} - -PHP_METHOD(git_commit, setAuthor) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *author; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &author) == FAILURE){ - return; - } - - if(!instanceof_function(Z_OBJCE_P(author), git_signature_class_entry TSRMLS_CC)){ - fprintf(stderr,"Git\\Commit::setAuthor() requires Git\\Signature"); - return; - } - - add_property_zval(getThis(),"author", author); -} - -PHP_METHOD(git_commit, setCommitter) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *committer; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &committer) == FAILURE){ - return; - } - - if(!instanceof_function(Z_OBJCE_P(committer), git_signature_class_entry TSRMLS_CC)){ - fprintf(stderr,"Git\\Commit::setCommitter() requires Git\\Signature"); - return; - } - - add_property_zval(getThis(),"committer", committer); -} - -PHP_METHOD(git_commit, setTree) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *tree; - int tree_len; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &tree,&tree_len) == FAILURE){ - return; - } - - add_property_string(getThis(),"tree", tree,1); -} - - -PHP_METHOD(git_commit, setParents) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *parents; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &parents) == FAILURE){ - return; - } - - add_property_zval(getThis(),"parents", parents); -} - -PHP_METHOD(git_commit, write) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_oid oid, tree_oid, **parents, **p, *tmp; - php_git_signature_t *author, *committer; - zval *z_author, *z_committer, *z_parents, **data; - char *update_ref, *message, *tree_oid_str = NULL; - char out[GIT_OID_HEXSZ+1]; - int count, i, update_ref_len = 0; - git_reference *ref; - - HashTable *array_hash; - HashPosition pointer; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|s", &update_ref,&update_ref_len) == FAILURE){ - return; - } - - if(ZEND_NUM_ARGS() == 0) { - if(git_reference_lookup(&ref,this->repository,"HEAD")==GIT_SUCCESS){ - if (git_reference_type(ref) == GIT_REF_SYMBOLIC) { - git_reference *ref2; - git_reference_resolve(&ref2,ref); - update_ref = (char *)git_reference_name(ref2); - } else { - update_ref = (char *)git_reference_name(ref); - } - } - } - - - tree_oid_str = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"tree",sizeof("tree")-1, 0 TSRMLS_CC)); - git_oid_fromstr(&tree_oid, tree_oid_str); - - z_author = zend_read_property(git_commit_class_entry, getThis(),"author",sizeof("author")-1, 0 TSRMLS_CC); - author = (php_git_signature_t *) zend_object_store_get_object(z_author TSRMLS_CC); - - z_committer = zend_read_property(git_commit_class_entry, getThis(),"committer",sizeof("committer")-1, 0 TSRMLS_CC); - committer = (php_git_signature_t *) zend_object_store_get_object(z_committer TSRMLS_CC); - - z_parents = zend_read_property(git_commit_class_entry, getThis(),"parents",sizeof("parents")-1, 0 TSRMLS_CC); - - count = zend_hash_num_elements(Z_ARRVAL_P(z_parents)); - - - array_hash = Z_ARRVAL_P(z_parents); - parents = (git_oid**)calloc(count,sizeof(git_oid)); - p = parents; - - for (zend_hash_internal_pointer_reset_ex(array_hash, &pointer); - zend_hash_has_more_elements_ex(array_hash,&pointer) == SUCCESS; - zend_hash_move_forward_ex(array_hash,&pointer) - ) { - tmp = (git_oid *)malloc(sizeof(git_oid)); - zend_hash_get_current_data_ex(array_hash, (void **)&data, &pointer); - git_oid_fromstr(tmp,Z_STRVAL_PP(data)); - - *p = tmp; - p++; - } - - message = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"message",sizeof("message")-1, 0 TSRMLS_CC)); - git_commit_create(&oid, - this->repository, - update_ref, - author->signature, - committer->signature, - NULL, // Message encoding (Should probably fix this at some point) - message, - &tree_oid, - count, - parents - ); - - git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); - - for(i = 0; i < count;i++){ - free(parents[i]); - } - free(parents); - - RETVAL_STRING(out,1); -} - -PHP_METHOD(git_commit, setMessage) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *message; - int message_len; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &message,&message_len) == FAILURE){ - return; - } - - add_property_string(getThis(),"message", message, 1); -} - - -PHP_METHOD(git_commit, getAuthor) -{ - zval *object = getThis(); - zval *signature = zend_read_property(git_commit_class_entry, object,"author",6, 0 TSRMLS_CC); - - zval_copy_ctor(signature); - RETURN_ZVAL(signature,0, 0); -} - -PHP_METHOD(git_commit, getParent) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - php_git_commit_t *obj; - git_commit *commit; - zval *zcommit; - int offset = 0; - int ret = 0; - zval *author; - zval *committer; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|l", &offset) == FAILURE){ - return; - } - - ret = git_commit_parent(&commit, this->object,offset); - if(ret != GIT_SUCCESS){ - //zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "specified offset not found"); - RETURN_FALSE; - } - - php_git_commit_init(&zcommit, commit, this->repository TSRMLS_CC); - - RETURN_ZVAL(zcommit,0,1); -} - -PHP_METHOD(git_commit, getId) -{ - php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_oid *oid = git_commit_id(this->object); - char id[GIT_OID_HEXSZ+1] = {0}; - - git_oid_to_string(id,GIT_OID_HEXSZ+1,oid); - - RETURN_STRING(id,1); -} - -static zend_function_entry php_git_commit_methods[] = { - PHP_ME(git_commit, __construct, arginfo_git_commit__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, getId, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setAuthor, arginfo_git_commit_set_author, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setCommitter, arginfo_git_commit_set_committer,ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setParents, arginfo_git_commit_set_parents, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setMessage, arginfo_git_commit_set_message, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, setTree, arginfo_git_commit_set_tree, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, write, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, getTree, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, getAuthor, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, getCommitter, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, getMessage, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, getShortMessage, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_commit, getParent, arginfo_git_commit_get_parent, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_commit(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Commit", php_git_commit_methods); - git_commit_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git_commit_class_entry->create_object = php_git_commit_new; - - zend_declare_property_null(git_commit_class_entry, "author", sizeof("author")-1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "committer",sizeof("committer")-1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "parents", sizeof("parents")-1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "message", sizeof("message")-1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(git_commit_class_entry, "tree", sizeof("tree")-1, ZEND_ACC_PROTECTED TSRMLS_CC); -} diff --git a/src/config.c b/src/config.c deleted file mode 100644 index eb8ead2d40..0000000000 --- a/src/config.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_config_class_entry; - -static void php_git_config_free_storage(php_git_config_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - efree(obj); -} - -zend_object_value php_git_config_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_config_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_config_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_config_parse_file, 0, 0, 1) - ZEND_ARG_INFO(0, file) -ZEND_END_ARG_INFO() - -typedef struct{ - zval *array; - git_config *config; -} git_config_foreach_t; - - -static int php_git_config_foreach(const char *key, void *data) -{ - HashTable *hash; - zval *config, *moe_key, *moe, **target_key; - char *savedptr, *current_key, *uu, *value, *tmp; - - config = ((git_config_foreach_t*)data)->array; - hash = Z_ARRVAL_P(config); - tmp = estrdup(key); - git_config_get_string(((git_config_foreach_t *)data)->config,key,&value); - - current_key = php_strtok_r(tmp, ".",&savedptr); - while (current_key != NULL) { - uu = current_key; - current_key = php_strtok_r(NULL, ".",&savedptr); - if(current_key != NULL) { - if(zend_hash_exists(hash,uu,strlen(uu)+1)) { - if (zend_hash_find(hash,uu,strlen(uu)+1,(void **)&target_key) == SUCCESS) { - hash = Z_ARRVAL_P(*target_key); - } - } else { - MAKE_STD_ZVAL(moe_key); - array_init(moe_key); - zend_hash_add(hash,uu,strlen(uu)+1,(void **)&moe_key,sizeof(moe_key),NULL); - hash = Z_ARRVAL_P(moe_key); - } - } - } - - if(uu != NULL) { - MAKE_STD_ZVAL(moe); - ZVAL_STRING(moe,value,1); - zval_copy_ctor(&moe); - zend_hash_add(hash,uu,strlen(uu)+1,(void **)&moe,sizeof(moe),NULL); - } - - efree(tmp); - return GIT_SUCCESS; -} - -PHP_METHOD(git_config, parseFile) -{ - git_config_foreach_t t; - git_config *config; - zval *zconf; - char *path; - int path_len = 0; - int ret = GIT_ERROR; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path,&path_len) == FAILURE){ - return; - } - - ret = git_config_open_file(&config, path); - if(ret != GIT_SUCCESS) { - php_git_throw_exception(NULL,ret,NULL TSRMLS_CC); - return; - } - - MAKE_STD_ZVAL(zconf); - array_init(zconf); - - t.array = zconf; - t.config = config; - - git_config_foreach(config,php_git_config_foreach,&t); - - t.array = NULL; - t.config = NULL; - git_config_free(config); - - RETURN_ZVAL(zconf,0,1); -} - -static zend_function_entry php_git_config_methods[] = { - PHP_ME(git_config, parseFile, arginfo_git_config_parse_file, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - {NULL,NULL,NULL} -}; - -void git_config_init(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Config", php_git_config_methods); - git_config_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git_config_class_entry->create_object = php_git_config_new; -} diff --git a/src/config.m4 b/src/config.m4 deleted file mode 100644 index f09a5ca823..0000000000 --- a/src/config.m4 +++ /dev/null @@ -1,39 +0,0 @@ -PHP_ARG_ENABLE(git,Whether to enable the "git" extension, - [ --enable-git Enable "phpgit" extension support]) - -PHP_ARG_WITH(libgit2-dir, for libgit2, -[ --with-libgit2-dir[=DIR] Set the path to libgit2 install prefix.], yes) - -if test $PHP_GIT != "no"; then - if test "$PHP_LIBGIT2_DIR" != "no" && test "$PHP_LIBGIT2_DIR" != "yes"; then - LIBGIT2_SEARCH_DIRS=$PHP_LIBGIT2_DIR - else - LIBGIT2_SEARCH_DIRS="/usr/local /usr" - fi - - for i in $LIBGIT2_SEARCH_DIRS; do - if test -f $i/include/libgit2/git2.h; then - LIBGIT2_DIR=$i - LIBGIT2_INCDIR=$i/include/libgit2 - elif test -f $i/include/git2.h; then - LIBGIT2_DIR=$i - LIBGIT2_INCDIR=$i/include - fi - done - - if test -z "$LIBGIT2_DIR"; then - AC_MSG_ERROR(Cannot find libgit2) - fi - - LIBGIT2_LIBDIR=$LIBGIT2_DIR/$PHP_LIBDIR - PHP_ADD_LIBRARY_WITH_PATH(git2, $LIBGIT2_LIBDIR, GIT_SHARED_LIBADD) - - PHP_SUBST(GIT_SHARED_LIBADD) - PHP_NEW_EXTENSION(git,php_git.c rawobject.c backend.c reference.c reference_manager.c repository.c signature.c commit.c index_entry.c index_iterator.c index.c tree_builder.c tree_iterator.c tree.c blob.c tree_entry.c walker.c object.c tag.c odb.c config.c, $ext_shared) - - ifdef([PHP_ADD_EXTENSION_DEP], - [ - PHP_ADD_EXTENSION_DEP(git, spl, true) - ]) - -fi diff --git a/src/index.c b/src/index.c deleted file mode 100644 index 75a24df076..0000000000 --- a/src/index.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_index_class_entry; - -static void php_git_index_free_storage(php_git_index_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - if(obj->index){ - git_index_free(obj->index); - } - efree(obj); -} - -zend_object_value php_git_index_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_index_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_index_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_add, 0, 0, 1) - ZEND_ARG_INFO(0, path) - ZEND_ARG_INFO(0, stage) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_find, 0, 0, 1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_get_entry, 0, 0, 1) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_construct, 0, 0, 1) - ZEND_ARG_INFO(0, repository_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_remove, 0, 0, 1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_insert, 0, 0, 1) - ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO() - -/* -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index__construct, 0, 0, 1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() -*/ - -void php_git_index_entry_create(zval **index, git_index_entry *entry) -{ - TSRMLS_FETCH(); - char oid[GIT_OID_HEXSZ+1] = {0}; - - MAKE_STD_ZVAL(*index); - object_init_ex(*index,git_index_entry_class_entry); - git_oid_to_string(oid,GIT_OID_HEXSZ+1,&entry->oid); - - add_property_string_ex(*index,"path", sizeof("path"), entry->path, 1 TSRMLS_CC); - add_property_string_ex(*index,"oid",sizeof("oid"),oid, 1 TSRMLS_CC); - add_property_long(*index,"dev",entry->dev); - add_property_long(*index,"ino",entry->ino); - add_property_long(*index,"mode",entry->mode); - add_property_long(*index,"uid",entry->uid); - add_property_long(*index,"gid",entry->gid); - add_property_long(*index,"file_size",entry->file_size); - add_property_long(*index,"flags",entry->flags); - add_property_long(*index,"flags_extended",entry->flags_extended); - add_property_long(*index,"ctime",time(&entry->ctime.seconds)); - add_property_long(*index,"mtime",time(&entry->mtime.seconds)); -} - -PHP_METHOD(git_index, count) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int entry_count = git_index_entrycount(this->index); - - RETVAL_LONG(entry_count); -} - -PHP_METHOD(git_index, find) -{ - int offset, path_len = 0; - char *path; - git_index *index = NULL; - git_index_entry *entry; - zval *z_git_index_entry; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE){ - return; - } - - php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - index = myobj->index; - - offset = git_index_find(index,path); - if(offset < 0){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified path does not exist."); - RETURN_FALSE; - } - - entry = git_index_get(myobj->index,offset); - if(entry == NULL){ - return; - } - php_git_index_entry_create(&z_git_index_entry, entry); - RETURN_ZVAL(z_git_index_entry,0,1); -} - -PHP_METHOD(git_index, getEntry) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_index_entry *entry; - zval *git_index_entry; - int offset = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &offset) == FAILURE){ - return; - } - - entry = git_index_get(this->index,offset); - php_git_index_entry_create(&git_index_entry, entry); - RETURN_ZVAL(git_index_entry,0, 1); -} - -PHP_METHOD(git_index, add) -{ - int path_len, success, offset = 0; - long stage = 0; - char *path; - git_index *index = NULL; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s|l", &path, &path_len, &stage) == FAILURE){ - return; - } - - php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - index = myobj->index; - - // Todo: check stage status. - success = git_index_add(index,path,stage); - if(success != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't add specified index."); - RETURN_FALSE; - } - - RETURN_TRUE; -} - -PHP_METHOD(git_index, remove) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int path_len, offset, result = 0; - char *path; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE){ - return; - } - - offset = git_index_find(this->index,path); - if(offset < 0){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified path does not exist."); - RETURN_FALSE; - } - - result = git_index_remove(this->index, offset); - if(result != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified offset does not exist."); - RETURN_FALSE - } - RETURN_TRUE; -} - - -PHP_METHOD(git_index, update) -{ - php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int success = git_index_write(myobj->index); - - if(success != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't write index"); - RETURN_FALSE; - } - - git_index_read(myobj->index); - RETURN_TRUE; -} - -PHP_METHOD(git_index, refresh) -{ - git_index *index = NULL; - php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - - index = myobj->index; - git_index_read(index); -} - -PHP_METHOD(git_index, getIterator) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *iterator; - - MAKE_STD_ZVAL(iterator); - object_init_ex(iterator,git_index_iterator_class_entry); - php_git_index_iterator_t *obj = (php_git_index_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC); - obj->index = this->index; - obj->offset = 0; - RETURN_ZVAL(iterator,0,1); -} - -PHP_METHOD(git_index, writeTree) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_oid oid; - char out[GIT_OID_HEXSZ+1]; - int ret; - - ret = git_tree_create_fromindex(&oid, this->index); - if(ret != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't write tree from index."); - RETURN_FALSE - } - - git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); - RETVAL_STRING(out,1); -} - -PHP_METHOD(git_index, write) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int ret = GIT_ERROR; - - if (this->index != NULL) { - ret = git_index_write(this->index); - if(ret == GIT_SUCCESS) { - RETURN_TRUE - } - } - - RETURN_FALSE; -} - -/* -PHP_METHOD(git_index, __construct) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_index *index; - char *path; - int path_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE){ - return; - } - int ret = git_index_open_bare(&index,path); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't read specified index"); - RETURN_FALSE; - } - this->index = index; - this->offset = 0; - add_property_long(getThis(), "entry_count",git_index_entrycount(index)); - -} -*/ -/* -PHP_METHOD(git_index, insert) -{ - php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *z_entry; - git_index_entry entry; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &z_entry) == FAILURE){ - return; - } - entry.ctime = zend_read_property(git_index_entry_class_entry, z_entry,"ctime",sizeof("ctime"), 0 TSRMLS_CC); - entry.mtime = zend_read_property(git_index_entry_class_entry, z_entry,"mtime",sizeof("mtime"), 0 TSRMLS_CC); - entry.dev = zend_read_property(git_index_entry_class_entry, z_entry,"dev",sizeof("dev"), 0 TSRMLS_CC); - entry.ino = zend_read_property(git_index_entry_class_entry, z_entry,"ino",sizeof("ino"), 0 TSRMLS_CC); - entry.mode = zend_read_property(git_index_entry_class_entry, z_entry,"mode",sizeof("mode"), 0 TSRMLS_CC); - entry.uid = zend_read_property(git_index_entry_class_entry, z_entry,"uid",sizeof("uid"), 0 TSRMLS_CC); - entry.gid = zend_read_property(git_index_entry_class_entry, z_entry,"gid",sizeof("gid"), 0 TSRMLS_CC); - entry.file_size = zend_read_property(git_index_entry_class_entry, z_entry,"file_size",sizeof("file_size"), 0 TSRMLS_CC); - entry.oid = zend_read_property(git_index_entry_class_entry, z_entry,"oid",sizeof("oid"), 0 TSRMLS_CC); - entry.flags = zend_read_property(git_index_entry_class_entry, z_entry,"flags",sizeof("flags"), 0 TSRMLS_CC); - entry.flags_extended = zend_read_property(git_index_entry_class_entry, z_entry,"flags_extended",sizeof("flags_extended"), 0 TSRMLS_CC); - entry.path = zend_read_property(git_index_entry_class_entry, z_entry,"path",sizeof("path"), 0 TSRMLS_CC); - - int ret = git_index_insert(this->index, &entry); - if(ret != GIT_SUCCESS){ - - } -} -*/ - -static zend_function_entry php_git_index_methods[] = { - //PHP_ME(git_index, __construct, arginfo_git_index__construct,ZEND_ACC_PUBLIC) - PHP_ME(git_index, getEntry, arginfo_git_index_get_entry, ZEND_ACC_PUBLIC) - PHP_ME(git_index, find, arginfo_git_index_find, ZEND_ACC_PUBLIC) - PHP_ME(git_index, add, arginfo_git_index_add, ZEND_ACC_PUBLIC) - PHP_ME(git_index, remove, arginfo_git_index_remove, ZEND_ACC_PUBLIC) - PHP_ME(git_index, refresh, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index, update, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index, writeTree, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index, write, NULL, ZEND_ACC_PUBLIC) - //PHP_ME(git_index, insert, arginfo_git_index_insert, ZEND_ACC_PUBLIC) - // Countable - PHP_ME(git_index, count, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index, getIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_index_init(TSRMLS_D) -{ - zend_class_entry git_index_ce; - INIT_NS_CLASS_ENTRY(git_index_ce, PHP_GIT_NS,"Index", php_git_index_methods); - - git_index_class_entry = zend_register_internal_class(&git_index_ce TSRMLS_CC); - git_index_class_entry->create_object = php_git_index_new; - zend_class_implements(git_index_class_entry TSRMLS_CC, 2, spl_ce_Countable, zend_ce_aggregate); -} diff --git a/src/index_entry.c b/src/index_entry.c deleted file mode 100644 index 319199619c..0000000000 --- a/src/index_entry.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_index_entry_class_entry; - -static void php_git_index_entry_free_storage(php_git_index_entry_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - obj->object = NULL; - efree(obj); -} - -zend_object_value php_git_index_entry_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_index_entry_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_index_entry_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -static zend_function_entry php_git_index_entry_methods[] = { - {NULL, NULL, NULL} -}; - -void git_index_entry_init(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, ZEND_NS_NAME(PHP_GIT_NS,"Index"),"Entry", php_git_index_entry_methods); - - git_index_entry_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git_index_entry_class_entry->create_object = php_git_index_entry_new; - zend_declare_property_null(git_index_entry_class_entry , "path",sizeof("path")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "oid",sizeof("oid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "dev",sizeof("dev")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "ino",sizeof("ino")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "mode",sizeof("mode")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "uid",sizeof("uid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "gid",sizeof("gid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "file_size",sizeof("file_size")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "flags",sizeof("flags")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "flags_extended",sizeof("flags_extended")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "ctime",sizeof("ctime")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_index_entry_class_entry , "mtime",sizeof("mtime")-1, ZEND_ACC_PUBLIC TSRMLS_CC); -} diff --git a/src/index_iterator.c b/src/index_iterator.c deleted file mode 100644 index 312ce23b39..0000000000 --- a/src/index_iterator.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - - -PHPAPI zend_class_entry *git_index_iterator_class_entry; -extern void php_git_index_entry_create(zval **index, git_index_entry *entry); - -static void php_git_index_iterator_free_storage(php_git_index_iterator_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - obj->index = NULL; - efree(obj); -} - -zend_object_value php_git_index_iterator_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_index_iterator_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_index_iterator_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_index_iterator__construct, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -PHP_METHOD(git_index_iterator, current) -{ - php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_index_entry *entry; - zval *git_index_entry; - - entry = git_index_get(this->index,this->offset); - if(entry == NULL){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified offset does not exist. %d"); - RETURN_FALSE; - } - php_git_index_entry_create(&git_index_entry, entry); - RETURN_ZVAL(git_index_entry,0,0); -} - -PHP_METHOD(git_index_iterator, key) -{ - php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_LONG(this->offset); -} - -PHP_METHOD(git_index_iterator, next) -{ - php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - this->offset++; - - RETURN_TRUE; -} - -PHP_METHOD(git_index_iterator, rewind) -{ - php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - this->offset = 0; -} - -PHP_METHOD(git_index_iterator, valid) -{ - php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int entry_count = git_index_entrycount(this->index); - if(this->offset < entry_count && this->offset >= 0){ - RETURN_TRUE; - }else{ - RETURN_FALSE; - } -} - -PHP_METHOD(git_index_iterator, __construct) -{ - php_git_index_iterator_t *this = (php_git_index_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *php_git_index; - php_git_index_t *idx; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &php_git_index) == FAILURE){ - return; - } - idx = (php_git_index_t *) zend_object_store_get_object(php_git_index TSRMLS_CC); - - this->index = idx->index; - this->offset = 0; -} - -static zend_function_entry php_git_index_iterator_methods[] = { - PHP_ME(git_index_iterator, __construct, arginfo_git_index_iterator__construct,ZEND_ACC_PUBLIC) - PHP_ME(git_index_iterator, current, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index_iterator, key, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index_iterator, next, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index_iterator, rewind, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_index_iterator, valid, NULL, ZEND_ACC_PUBLIC) -}; - -void git_index_iterator_init(TSRMLS_D) -{ - zend_class_entry git_index_iterator_ce; - INIT_NS_CLASS_ENTRY(git_index_iterator_ce, PHP_GIT_NS,"IndexIterator", php_git_index_iterator_methods); - git_index_iterator_class_entry = zend_register_internal_class(&git_index_iterator_ce TSRMLS_CC); - git_index_iterator_class_entry->create_object = php_git_index_iterator_new; - zend_class_implements(git_index_iterator_class_entry TSRMLS_CC, 1, spl_ce_Iterator); -} diff --git a/src/object.c b/src/object.c deleted file mode 100644 index 9712752d75..0000000000 --- a/src/object.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_object_class_entry; - -static void php_git_object_free_storage(php_git_object_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - if(obj->object){ - git_object_free(obj->object); - obj->object = NULL; - } - - efree(obj); -} - -zend_object_value php_git_object_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_object_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_object_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - - -PHP_METHOD(git_object, getId) -{ - php_git_object_t *this = (php_git_object_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char out[GIT_OID_HEXSZ+1] = {0}; - const git_oid *oid; - - oid = git_object_id((git_object *)this->object); - git_oid_to_string(out,GIT_OID_HEXSZ+1,oid); - - RETVAL_STRING(out,1); -} - -PHP_METHOD(git_object, getType) -{ - php_git_object_t *this = (php_git_object_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_otype type; - - type = git_object_type((git_object *)this->object); - - RETVAL_LONG(type); -} - -static zend_function_entry php_git_object_methods[] = { - PHP_ME(git_object, getId, NULL,ZEND_ACC_PUBLIC) - PHP_ME(git_object, getType, NULL,ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_object(TSRMLS_D) -{ - zend_class_entry git_object_ce; - INIT_NS_CLASS_ENTRY(git_object_ce, PHP_GIT_NS,"Object", php_git_object_methods); - git_object_class_entry = zend_register_internal_class(&git_object_ce TSRMLS_CC); - git_object_class_entry->create_object = php_git_object_new; -} diff --git a/src/odb.c b/src/odb.c deleted file mode 100644 index 461991eeb9..0000000000 --- a/src/odb.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_odb_class_entry; - -int php_git_odb_add_backend(git_odb **odb, zval *backend, int priority); -int php_git_odb_add_alternate(git_odb **odb, zval *backend, int priority); - - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_odb_add_backend,0, 0, 1) - ZEND_ARG_INFO(0, backend) -ZEND_END_ARG_INFO() - -static void php_git_odb_free_storage(php_git_odb_t *obj TSRMLS_DC) -{ - if(obj->odb != NULL){ - obj->odb = NULL; - } - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - efree(obj); -} - -zend_object_value php_git_odb_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_odb_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_odb_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -PHP_METHOD(git_odb, __construct) -{ - php_git_odb_t *this = (php_git_odb_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_odb *odb; - zval *backends; - int ret = 0; - - ret = git_odb_new(&this->odb); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create Git\\ODB"); - } - - MAKE_STD_ZVAL(backends); - array_init(backends); - add_property_zval_ex(getThis(),"backends",sizeof("backends"),backends TSRMLS_CC); -} - - -int php_git_odb_add_alternate(git_odb **odb, zval *backend, int priority) -{ - TSRMLS_FETCH(); - int ret = GIT_SUCCESS; - php_git_backend_t *b; - if(!instanceof_function(Z_OBJCE_P(backend), git_backend_class_entry TSRMLS_CC)){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"alternate must extends Git\\Backend"); - return GIT_ERROR; - } - - b = (php_git_backend_t *) zend_object_store_get_object(backend TSRMLS_CC); - ret = git_odb_add_alternate(*odb,(git_odb_backend *)b->backend, priority); - - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't add alternate"); - return GIT_ERROR; - } - - return ret; -} - - -int php_git_odb_add_backend(git_odb **odb, zval *backend, int priority) -{ - TSRMLS_FETCH(); - int ret = GIT_SUCCESS; - php_git_backend_t *b; - if(!instanceof_function(Z_OBJCE_P(backend), git_backend_class_entry TSRMLS_CC)){ - php_error_docref(NULL TSRMLS_CC, E_WARNING,"backend must extends Git\\Backend"); - return GIT_ERROR; - } - - b = (php_git_backend_t *) zend_object_store_get_object(backend TSRMLS_CC); - ret = git_odb_add_backend(*odb,(git_odb_backend *)b->backend, priority); - - if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_WARNING,"can't add backend"); - return GIT_ERROR; - } - - Z_ADDREF_P(backend); - return ret; -} - -PHP_METHOD(git_odb, addBackend) -{ - php_git_odb_t *this = (php_git_odb_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *backend; - int priority = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){ - return; - } - - php_git_odb_add_backend(&this->odb,backend, priority); -} - -PHP_METHOD(git_odb, addAlternate) -{ - php_git_odb_t *this = (php_git_odb_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *backend; - int priority = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){ - return; - } - - php_git_odb_add_alternate(&this->odb,backend, priority); -} - - -static zend_function_entry php_git_odb_methods[] = { - PHP_ME(git_odb, __construct, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_odb, addBackend, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) - PHP_ME(git_odb, addAlternate, arginfo_git_odb_add_backend, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_odb(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"ODB", php_git_odb_methods); - git_odb_class_entry = zend_register_internal_class_ex(&ce, git_odb_class_entry,NULL TSRMLS_CC); - git_odb_class_entry->create_object = php_git_odb_new; - - zend_declare_property_null(git_odb_class_entry, "backends",sizeof("backends")-1,ZEND_ACC_PROTECTED TSRMLS_CC); -} diff --git a/src/php_git.c b/src/php_git.c deleted file mode 100644 index 5064f646cf..0000000000 --- a/src/php_git.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC) -{ - zval **data; - char *key; - long *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 (zval *)*data; -} - -int php_git_add_protected_property_string_ex(zval *object, char *name, int name_length, char *data, zend_bool duplicate TSRMLS_DC) -{ - zval *tmp; - char *key; - long *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_git_add_protected_property_zval_ex(zval *object, char *name, int name_length, zval *data TSRMLS_DC) -{ - char *key; - long *length; - zend_mangle_property_name(&key,&length,"*",1,name,name_length,0); - zend_hash_update(Z_OBJPROP_P(object),key,length,&data,sizeof(zval *),NULL); - efree(key); - - return SUCCESS; -} - -void php_git_throw_exception(zend_class_entry *exception,int error_code, char *message TSRMLS_DC) -{ - if(exception == NULL) { - //will be fix soon. - exception = spl_ce_RuntimeException; - } - - if(message != NULL) { - zend_throw_exception_ex(exception, 0 TSRMLS_CC, message); - } else { - zend_throw_exception_ex(exception, 0 TSRMLS_CC, git_strerror(error_code)); - } -} - -int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC) -{ - zval *backends; - - MAKE_STD_ZVAL(*object); - object_init_ex(*object,git_odb_class_entry); - php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(*object TSRMLS_CC); - odb_t->odb = database; - - MAKE_STD_ZVAL(backends); - array_init(backends); - - php_git_add_protected_property_zval_ex(*object,"backends",sizeof("backends"),backends TSRMLS_CC); - - return SUCCESS; -} - -void php_git_commit_init(zval **object, git_commit *commit, git_repository *repository TSRMLS_DC) -{ - zval *author, *committer; - int i, parent_count; - zval *parents; - - MAKE_STD_ZVAL(*object); - object_init_ex(*object,git_commit_class_entry); - - create_signature_from_commit(&author, git_commit_author(commit)); - create_signature_from_commit(&committer, git_commit_committer(commit)); - - php_git_commit_t *cobj = (php_git_commit_t *) zend_object_store_get_object(*object TSRMLS_CC); - cobj->object = commit; - cobj->repository = repository; - - parent_count = git_commit_parentcount(commit); - MAKE_STD_ZVAL(parents); - array_init(parents); - for (i = 0; i < parent_count; i++) { - add_next_index_string(parents,git_oid_allocfmt(git_commit_parent_oid(commit,i)),1); - } - - php_git_add_protected_property_zval_ex(*object,"author",sizeof("author"),author TSRMLS_CC); - php_git_add_protected_property_zval_ex(*object,"committer",sizeof("committer"),committer TSRMLS_CC); - php_git_add_protected_property_string_ex(*object,"tree",sizeof("tree"),git_oid_allocfmt(git_commit_tree_oid(commit)),1 TSRMLS_CC); - php_git_add_protected_property_string_ex(*object,"message",sizeof("message"),git_commit_message(commit), 1 TSRMLS_CC); - php_git_add_protected_property_zval_ex(*object,"parents",sizeof("parents"),parents TSRMLS_CC); -} - -// probably this method will be deplicated. -int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_repository *repository, const char *path) -{ - const git_tree_entry *entry; - git_tree *tmp = tree; - int c, i, attribute, length, offset, position, len = 0; - char buffer[256]; - char *p; - int ret = GIT_ERROR; - length = strlen(path); - p = path; - - memset(buffer,'\0',256); - while (position < length) { - if(path[position] == '/') { - memcpy(buffer,p, position-offset); - buffer[position-offset] = '\0'; - - offset = position+1; - p+=offset; - - entry = git_tree_entry_byname(tmp,buffer); - if(entry == NULL) { - return GIT_ERROR; - } - - attribute = git_tree_entry_attributes(entry); - tmp = NULL; - ret = git_tree_entry_2object(&tmp,repository,entry); - if(ret != GIT_SUCCESS) { - return GIT_ERROR; - } - } else if (position == length-1) { - memset(buffer,'\0',256); - memcpy(buffer,p, position+1-offset); - - c = git_tree_entrycount(tmp); - i = 0; - for(i =0; i < c; i++){ - git_tree_entry *e = git_tree_entry_byindex(tmp,i); - } - //entry_sort_cmp - entry = git_tree_entry_byname(tmp,"git2.h"); - if(entry == NULL) { - return GIT_ERROR; - } - } - position++; - } - - *object = entry; - if(entry == NULL) { - return GIT_ERROR; - } else { - return GIT_SUCCESS; - } -} - - -PHPAPI zend_class_entry *git_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_string_to_type, 0, 0, 1) - ZEND_ARG_INFO(0, string_type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_type_to_string, 0, 0, 1) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_hex_to_raw, 0, 0, 1) - ZEND_ARG_INFO(0, hex) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_raw_to_hex, 0, 0, 1) - ZEND_ARG_INFO(0, raw) -ZEND_END_ARG_INFO() - -PHP_FUNCTION(git_string_to_type) -{ - const char *string_type = NULL; - int string_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &string_type, &string_len) == FAILURE){ - return; - } - - RETVAL_LONG(git_object_string2type(string_type)) -} - -PHP_FUNCTION(git_type_to_string) -{ - git_otype t; - int type; - const char *str; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &type) == FAILURE){ - return; - } - t = (git_otype)type; - str = git_object_type2string(t); - - RETVAL_STRING(str,1); -} - -PHP_FUNCTION(git_hex_to_raw) -{ - git_oid oid; - const char *hex = NULL; - int hex_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hex, &hex_len) == FAILURE){ - return; - } - - git_oid_fromstr(&oid, hex); - RETVAL_STRINGL((&oid)->id,GIT_OID_RAWSZ,1); -} - -PHP_FUNCTION(git_raw_to_hex) -{ - git_oid oid; - const char *raw = NULL; - char out[GIT_OID_HEXSZ+1]; - int raw_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s", - &raw, &raw_len) == FAILURE){ - return; - } - - git_oid_fromraw(&oid, raw); - git_oid_fmt(out, &oid); - - RETVAL_STRINGL(out,GIT_OID_HEXSZ,1); -} - -static zend_function_entry php_git_methods[] = { - {NULL, NULL, NULL} -}; - -// Git Global Functions -static zend_function_entry php_git_functions[] = { - PHP_FE(git_hex_to_raw, arginfo_git_hex_to_raw) - PHP_FE(git_raw_to_hex, arginfo_git_raw_to_hex) - PHP_FE(git_type_to_string, arginfo_git_type_to_string) - PHP_FE(git_string_to_type, arginfo_git_string_to_type) - {NULL, NULL, NULL} -}; - -void git_init(TSRMLS_D) -{ - zend_class_entry git_ce; - INIT_NS_CLASS_ENTRY(git_ce, PHP_GIT_NS,"Git", php_git_methods); - git_class_entry = zend_register_internal_class(&git_ce TSRMLS_CC); -} - -PHP_MINIT_FUNCTION(git) { - git_init(TSRMLS_C); - git_init_object(TSRMLS_C); - git_init_reference(TSRMLS_C); - php_git_repository_init(TSRMLS_C); - git_index_iterator_init(TSRMLS_C); - git_index_entry_init(TSRMLS_C); - git_index_init(TSRMLS_C); - git_init_signature(TSRMLS_C); - git_init_walker(TSRMLS_C); - git_config_init(TSRMLS_C); - git_tree_builder_init(TSRMLS_C); - git_tree_iterator_init(TSRMLS_C); - git_init_tree(TSRMLS_C); - git_init_commit(TSRMLS_C); - git_init_tree_entry(TSRMLS_C); - git_init_tag(TSRMLS_C); - git_init_blob(TSRMLS_C); - git_init_odb(TSRMLS_C); - git_init_rawobject(TSRMLS_C); - git_init_backend(TSRMLS_C); - git_init_reference_manager(TSRMLS_C); - - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_NONE", 0, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_TOPO", 1, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_DATE", 2, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Revwalk"), "SORT_REVERSE", 4, CONST_CS | CONST_PERSISTENT); - - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Any", GIT_OBJ_ANY, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Bad", GIT_OBJ_BAD, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Commit", GIT_OBJ_COMMIT, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Tree", GIT_OBJ_TREE, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Blob", GIT_OBJ_BLOB, CONST_CS | CONST_PERSISTENT); - REGISTER_NS_LONG_CONSTANT(ZEND_NS_NAME(PHP_GIT_NS,"Object"), "Tag", GIT_OBJ_TAG, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; -} - - -PHP_MINFO_FUNCTION(git) -{ - php_printf("PHP libgit2 Extension\n"); - php_info_print_table_start(); - php_info_print_table_row(2,"Version", PHP_GIT_EXTVER "-dev"); - php_info_print_table_row(2,"libgit2 version", LIBGIT2_VERSION); - php_info_print_table_end(); -} - -zend_module_entry git_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 - STANDARD_MODULE_HEADER, -#endif - PHP_GIT_EXTNAME, - php_git_functions, /* Functions */ - PHP_MINIT(git), /* MINIT */ - NULL, /* MSHUTDOWN */ - NULL, /* RINIT */ - NULL, /* RSHUTDOWN */ - PHP_MINFO(git), /* MINFO */ -#if ZEND_MODULE_API_NO >= 20010901 - PHP_GIT_EXTVER, -#endif - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_GIT -ZEND_GET_MODULE(git) -#endif diff --git a/src/php_git.h b/src/php_git.h deleted file mode 100644 index 48dd5421e0..0000000000 --- a/src/php_git.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_GIT_H - -#define PHP_GIT_H - -#define PHP_GIT_EXTNAME "git" -#define PHP_GIT_EXTVER "0.2.1" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "ext/spl/spl_exceptions.h" -#include -#include - -/* Define the entry point symbol - * Zend will use when loading this module - */ -extern zend_module_entry git_module_entry; -#define phpext_git_ptr &git_module_entry; -#define PHP_GIT_NS "Git" - -void php_git_throw_exception(zend_class_entry *exception,int error_code, char *message TSRMLS_DC); -int php_git_add_protected_property_zval_ex(zval *object, char *name, int name_length, zval *data TSRMLS_DC); -int php_git_add_protected_property_string_ex(zval *object, char *name, int name_length, char *data, zend_bool duplicate TSRMLS_DC); -int php_git_odb_init(zval **object, git_odb *database TSRMLS_DC); -zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); -void php_git_commit_init(zval **object, git_commit *commit, git_repository *repository TSRMLS_DC); -int git_tree_entry_resolve_byname(git_tree_entry **object, git_tree *tree, git_repository* repository, const char *path); - -extern PHPAPI zend_class_entry *git_class_entry; -extern PHPAPI zend_class_entry *git_reference_class_entry; -extern PHPAPI zend_class_entry *git_reference_manager_class_entry; -extern PHPAPI zend_class_entry *git_repository_class_entry; -extern PHPAPI zend_class_entry *git_object_class_entry; -extern PHPAPI zend_class_entry *git_index_class_entry; -extern PHPAPI zend_class_entry *git_index_iterator_class_entry; -extern PHPAPI zend_class_entry *git_index_entry_class_entry; -extern PHPAPI zend_class_entry *git_walker_class_entry; -extern PHPAPI zend_class_entry *git_tree_class_entry; -extern PHPAPI zend_class_entry *git_tree_builder_class_entry; -extern PHPAPI zend_class_entry *git_tree_iterator_class_entry; -extern PHPAPI zend_class_entry *git_tree_entry_class_entry; -extern PHPAPI zend_class_entry *git_commit_class_entry; -extern PHPAPI zend_class_entry *git_signature_class_entry; -extern PHPAPI zend_class_entry *git_tag_class_entry; -extern PHPAPI zend_class_entry *git_blob_class_entry; -extern PHPAPI zend_class_entry *git_odb_class_entry; -extern PHPAPI zend_class_entry *git_backend_class_entry; -extern PHPAPI zend_class_entry *git_rawobject_class_entry; -extern PHPAPI zend_class_entry *git_config_class_entry; - -typedef struct{ - zend_object zo; - git_index *index; -} php_git_index_t; - -typedef struct{ - zend_object zo; - git_index *index; - long offset; -} php_git_index_iterator_t; - -typedef struct{ - zend_object zo; - git_repository *repository; -} php_git_repository_t; - -typedef struct{ - zend_object zo; - git_treebuilder *builder; - git_repository *repository; -} php_git_tree_builder_t; - -typedef struct{ - zend_object zo; - git_repository *repository; - git_tree_entry *entry; -} php_git_tree_entry_t; - -typedef struct{ - zend_object zo; - git_tree *tree; - long offset; - git_repository *repository; -} php_git_tree_iterator_t; - -typedef struct{ - zend_object zo; - git_revwalk *walker; -} php_git_walker_t; - -typedef struct{ - git_odb_backend parent; - zval *self; -} php_git_backend_internal; - -typedef struct{ - zend_object zo; - php_git_backend_internal *backend; -} php_git_backend_t; - -typedef struct{ - zend_object zo; - git_signature *signature; -} php_git_signature_t; - -typedef struct{ - zend_object zo; - git_odb *odb; -} php_git_odb_t; - -typedef struct{ - zend_object zo; - git_index_entry *object; -} php_git_index_entry_t; - -typedef struct{ - zend_object zo; - git_object *object; -} php_git_object_t; - -// extends git_object -typedef struct{ - zend_object zo; - git_commit *object; - git_repository *repository; -} php_git_commit_t; - -typedef struct{ - zend_object zo; - git_tree *object; - git_repository *repository; -} php_git_tree_t; - -typedef struct{ - zend_object zo; - git_tag *object; -} php_git_tag_t; - -enum php_git_blob_write_type{ - PHP_GIT_LOAD_FROM_FILE, - PHP_GIT_LOAD_FROM_STRING -}; - -typedef struct{ - zend_object zo; - git_blob *object; - git_repository *repository; - enum php_git_blob_write_type type; - char *contents; - int contents_len; -} php_git_blob_t; - -typedef struct{ - zend_object zo; - git_reference *object; -} php_git_reference_t; - -typedef struct{ - zend_object zo; - git_repository *repository; -} php_git_reference_manager_t; - -typedef struct{ - zend_object zo; - git_config *config; -} php_git_config_t; - - -#endif /* PHP_GIT_H */ diff --git a/src/rawobject.c b/src/rawobject.c deleted file mode 100644 index a5004d4b88..0000000000 --- a/src/rawobject.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -PHPAPI zend_class_entry *git_rawobject_class_entry; - -static zend_function_entry php_git_rawobject_methods[] = { - {NULL, NULL, NULL} -}; - -void git_init_rawobject(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"RawObject", php_git_rawobject_methods); - git_rawobject_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - - zend_declare_property_null(git_rawobject_class_entry, "id", sizeof("id"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_rawobject_class_entry, "data", sizeof("data"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_rawobject_class_entry, "type", sizeof("type"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_rawobject_class_entry, "len", sizeof("len"), ZEND_ACC_PUBLIC TSRMLS_CC); -} diff --git a/src/reference.c b/src/reference.c deleted file mode 100644 index 11807eb0bb..0000000000 --- a/src/reference.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_reference_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_set_name, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_set_target, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_set_oid, 0, 0, 1) - ZEND_ARG_INFO(0, oid) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference__construct, 0, 0, 1) - ZEND_ARG_INFO(0, repository) -ZEND_END_ARG_INFO() - -static void php_git_reference_free_storage(php_git_reference_t *obj TSRMLS_DC) -{ - if(obj->object){ - obj->object = NULL; - } - zend_object_std_dtor(&obj->zo TSRMLS_CC); - efree(obj); -} - -zend_object_value php_git_reference_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_tag_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_reference_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - - -PHP_METHOD(git_reference, getTarget) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_rtype type; - const char *target; - - type = git_reference_type(this->object); - if(type == GIT_REF_SYMBOLIC) { - target = git_reference_target(this->object); - // FIXME: this method only available if the reference is symbolic. - if(target != NULL) { - add_property_string_ex(getThis() ,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); - RETVAL_STRING(Z_STRVAL_P(zend_read_property(git_reference_class_entry,getThis(),"target",sizeof("target")-1,1 TSRMLS_CC)),0); - } - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING,"Git\\Reference::getTarget method only available if the reference is symbolic."); - return; - } -} - -PHP_METHOD(git_reference, getType) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_rtype rtype = git_reference_type(this->object); - - RETVAL_LONG((long)rtype); -} - - -PHP_METHOD(git_reference, getName) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - const char *name = git_reference_name(this->object); - - add_property_string_ex(getThis() ,"name",sizeof("name"),(char *)name, 1 TSRMLS_CC); - RETVAL_STRING(name, 1); -} - -PHP_METHOD(git_reference, setName) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *name; - int name_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &name, &name_len) == FAILURE){ - return; - } - - git_reference_set_name(this->object, name); - add_property_string_ex(getThis() ,"name",sizeof("name"),name, 1 TSRMLS_CC); -} - -PHP_METHOD(git_reference, write) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - - int ret = git_reference_write(this->object); - if(ret != GIT_SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_ERROR,"can't write reference. something wrong"); - RETURN_FALSE; - } - RETURN_TRUE; -} - - -PHP_METHOD(git_reference, setTarget) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *target; - int target_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &target, &target_len) == FAILURE){ - return; - } - - git_reference_set_target(this->object, target); - add_property_string_ex(getThis() ,"target",sizeof("target"),target, 1 TSRMLS_CC); -} - -PHP_METHOD(git_reference, setOID) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *oid; - git_oid out; - int oid_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &oid, &oid_len) == FAILURE){ - return; - } - - git_oid_fromstr(&out, oid); - - git_reference_set_oid(this->object, &out); - add_property_string_ex(getThis() ,"oid",sizeof("oid"),oid, 1 TSRMLS_CC); -} - -PHP_METHOD(git_reference, __construct) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - php_git_repository_t *repository; - zval *z_repo; - git_rtype type; - git_reference *refs; - int res = 0; - const char *target; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &z_repo) == FAILURE){ - return; - } - - if(instanceof_function(Z_OBJCE_P(z_repo), git_repository_class_entry TSRMLS_CC)){ - repository = (php_git_repository_t *) zend_object_store_get_object(z_repo TSRMLS_CC); - }else{ - php_error_docref(NULL TSRMLS_CC, E_ERROR,"specified parameter doesn't Git\\Repository"); - RETURN_FALSE; - } - - res = git_reference_new(&refs,repository->repository); - if(res != GIT_SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_ERROR,"can't create Git\\Reference. something wrong."); - } - - type = git_reference_type(refs); - if(type == GIT_REF_SYMBOLIC) { - target = git_reference_target(refs); - if(target != NULL) { - add_property_string_ex(getThis() ,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); - RETVAL_STRING(Z_STRVAL_P(zend_read_property(git_reference_class_entry,getThis(),"target",sizeof("target")-1,1 TSRMLS_CC)),0); - } - git_reference_resolve(&this->object,refs); - } else { - this->object = refs; - } -} - -PHP_METHOD(git_reference, getId) -{ - php_git_reference_t *this = (php_git_reference_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid *oid; - - oid = git_reference_oid(this->object); - git_oid_to_string(&out, GIT_OID_HEXSZ+1, oid); - RETURN_STRINGL(&out,GIT_OID_HEXSZ, 1); -} - -static zend_function_entry php_git_reference_methods[] = { - PHP_ME(git_reference, __construct, arginfo_git_reference__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, getTarget, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, getType, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, getName, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, getId, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, write, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, setName, arginfo_git_reference_set_name, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, setTarget, arginfo_git_reference_set_target, ZEND_ACC_PUBLIC) - PHP_ME(git_reference, setOID, arginfo_git_reference_set_oid, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_reference(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Reference", php_git_reference_methods); - git_reference_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry,NULL TSRMLS_CC); - git_reference_class_entry->create_object = php_git_reference_new; - - zend_declare_property_null(git_reference_class_entry, "oid", sizeof("oid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_reference_class_entry, "name", sizeof("name")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_reference_class_entry, "target", sizeof("target")-1, ZEND_ACC_PUBLIC TSRMLS_CC); -} diff --git a/src/reference_manager.c b/src/reference_manager.c deleted file mode 100644 index 3a74a77498..0000000000 --- a/src/reference_manager.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include -#undef lookup - -PHPAPI zend_class_entry *git_reference_manager_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager__construct, 0, 0, 1) - ZEND_ARG_INFO(0, repository) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager_lookup, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager_create, 0, 0, 2) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, oid) - ZEND_ARG_INFO(0, force) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reference_manager_get_list, 0, 0, 1) - ZEND_ARG_INFO(0, flag) -ZEND_END_ARG_INFO() - -static void php_git_reference_manager_free_storage(php_git_reference_manager_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - obj->repository = NULL; - efree(obj); -} - -zend_object_value php_git_reference_manager_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_tree_entry_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_reference_manager_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -PHP_METHOD(git_reference_manager, __construct) -{ - php_git_reference_manager_t *this= (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *repository; - php_git_repository_t *repo; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &repository) == FAILURE){ - return; - } - if(!instanceof_function(Z_OBJCE_P(repository), git_repository_class_entry TSRMLS_CC)){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "argument does not Git\\Repository"); - RETURN_FALSE; - } - - repo = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC); - if(repo->repository == NULL){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "repository didn't ready"); - RETURN_FALSE; - } - this->repository = repo->repository; -} - -PHP_METHOD(git_reference_manager, getList) -{ - php_git_reference_manager_t *this= (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_strarray *list = malloc(sizeof(git_strarray)); - int rr, result, i = 0; - int flags = GIT_REF_LISTALL; - git_reference *reference; - zval *references; - git_rtype type; - const char *target; - char out[GIT_OID_HEXSZ+1] = {0}; - zval *ref; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|l", &flags) == FAILURE){ - return; - } - - git_reference_listall(list,this->repository,flags); - - MAKE_STD_ZVAL(references); - array_init(references); - for(i = 0; i < list->count; i++){ - // FIXME - result = git_reference_lookup(&reference, this->repository, list->strings[i]); - if(result != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "Can't find specified reference."); - RETURN_FALSE; - } - - MAKE_STD_ZVAL(ref); - object_init_ex(ref, git_reference_class_entry); - php_git_reference_t *refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC); - refobj->object = reference; - - add_property_string_ex(ref,"name", sizeof("name"), (char *)git_reference_name(reference), 1 TSRMLS_CC); - - type = git_reference_type(reference); - if(type == GIT_REF_SYMBOLIC) { - target = git_reference_target(reference); - if(target != NULL) { - add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); - } - rr = git_reference_resolve(&refobj->object,reference); - if(rr != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "something wrong"); - RETURN_FALSE; - } - } - - git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); - add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); - memset(out,'\0',GIT_OID_HEXSZ+1); - - add_next_index_zval(references, ref); - } - - git_strarray_free(list); - RETURN_ZVAL(references,0,0); -} - -PHP_METHOD(git_reference_manager, pack) -{ - php_git_reference_manager_t *this= (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int ret = git_reference_packall(this->repository); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "an error occured while packing references. error_code: %d\n",ret); - RETURN_FALSE; - } - RETURN_TRUE; -} - -PHP_METHOD(git_reference_manager, lookup) -{ - php_git_reference_manager_t *this = (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *name; - int rr, result, name_len = 0; - zval *ref; - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid *oid; - git_rtype type; - git_reference *reference; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &name, &name_len) == FAILURE){ - return; - } - - result = git_reference_lookup(&reference, this->repository, name); - if(result != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "Can't find specified reference."); - RETURN_FALSE; - } - - MAKE_STD_ZVAL(ref); - object_init_ex(ref, git_reference_class_entry); - php_git_reference_t *refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC); - refobj->object = reference; - - add_property_string_ex(ref,"name", sizeof("name"), (char *)git_reference_name(reference), 1 TSRMLS_CC); - - type = git_reference_type(reference); - if(type == GIT_REF_SYMBOLIC) { - const char *target = git_reference_target(reference); - if(target != NULL) { - add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); - } - rr = git_reference_resolve(&refobj->object,reference); - if(rr != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "something wrong"); - RETURN_FALSE; - } - } - - git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); - add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); - - RETURN_ZVAL(ref,0,0); -} - -PHP_METHOD(git_reference_manager, create) -{ - php_git_reference_manager_t *this = (php_git_reference_manager_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *name; - int name_len = 0; - char *oid; - int ret,rr, oid_len = 0; - git_oid id; - zend_bool force = 0; - git_odb *odb; - git_reference *reference; - char out[GIT_OID_HEXSZ+1] = {0}; - git_rtype type; - zval *ref; - const char *target; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ss|b", &name, &name_len, &oid, &oid_len, &force) == FAILURE){ - return; - } - if(oid_len != GIT_OID_HEXSZ){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "oid length seems illegal"); - RETURN_FALSE; - } - - git_oid_fromstr(&id, oid); - odb = git_repository_database(this->repository); - - if(!git_odb_exists(odb,&id)){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "specified oid not found"); - RETURN_FALSE; - } - - ret = git_reference_create_oid(&reference, this->repository, name, &id, force); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "can't add reference, maybe try setting force to boolean true"); - RETURN_FALSE; - } - - MAKE_STD_ZVAL(ref); - object_init_ex(ref, git_reference_class_entry); - php_git_reference_t *refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC); - refobj->object = reference; - - add_property_string_ex(ref,"name", sizeof("name"), name, 1 TSRMLS_CC); - type = git_reference_type(reference); - if(type == GIT_REF_SYMBOLIC) { - target = git_reference_target(reference); - if(target != NULL) { - add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); - } - rr = git_reference_resolve(&refobj->object,reference); - if(rr != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "something wrong"); - RETURN_FALSE; - } - } - git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); - add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); - RETURN_ZVAL(ref,0,0); -} - -static zend_function_entry php_git_reference_manager_methods[] = { - PHP_ME(git_reference_manager, __construct, arginfo_git_reference_manager__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_reference_manager, getList, arginfo_git_reference_manager_get_list, ZEND_ACC_PUBLIC) - PHP_ME(git_reference_manager, lookup, arginfo_git_reference_manager_lookup, ZEND_ACC_PUBLIC) - PHP_ME(git_reference_manager, pack, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_reference_manager, create, arginfo_git_reference_manager_create, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_reference_manager(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, ZEND_NS_NAME(PHP_GIT_NS,"Reference"),"Manager", php_git_reference_manager_methods); - git_reference_manager_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git_reference_manager_class_entry->create_object = php_git_reference_manager_new; - -} diff --git a/src/repository.c b/src/repository.c deleted file mode 100644 index 9abadd7d2f..0000000000 --- a/src/repository.c +++ /dev/null @@ -1,652 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_repository_class_entry; - -extern void create_signature_from_commit(zval **signature, const git_signature *sig); -extern int php_git_odb_add_backend(git_odb **odb, zval *backend, int priority); -extern int php_git_odb_add_alternate(git_odb **odb, zval *backend, int priority); - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_init, 0, 0, 2) - ZEND_ARG_INFO(0, path) - ZEND_ARG_INFO(0, is_bare) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_get_object, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_get_commit, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_construct, 0, 0, 0) - ZEND_ARG_INFO(0, repository_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_get_tree, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_walker, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_lookup_ref, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_open3, 0, 0, 1) - ZEND_ARG_INFO(0, git_dir) - ZEND_ARG_INFO(0, odb) - ZEND_ARG_INFO(0, index) - ZEND_ARG_INFO(0, tree) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_add_backend, 0, 0, 2) - ZEND_ARG_INFO(0, backend) - ZEND_ARG_INFO(0, priority) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_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_git_get_references, 0, 0, 1) - ZEND_ARG_INFO(0, flag) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_open2, 0, 0, 4) - ZEND_ARG_INFO(0, git_dir) - ZEND_ARG_INFO(0, git_object_directory) - ZEND_ARG_INFO(0, git_index_file) - ZEND_ARG_INFO(0, git_work_tree) -ZEND_END_ARG_INFO() - -static void php_git_repository_free_storage(php_git_repository_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - if(obj->repository != NULL){ - git_repository_free(obj->repository); - obj->repository = NULL; - } - - efree(obj); -} - -zend_object_value php_git_repository_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_repository_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_repository_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - - return retval; -} - -PHP_METHOD(git_repository, init) -{ - git_repository *repository; - zval *obj,*backends,*odb; - char *path = NULL; - int ret, is_bare, path_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"sl", - &path, &path_len, &is_bare) == FAILURE){ - return; - } - - int error = git_repository_init(&repository,path,is_bare); - if(error != GIT_SUCCESS){ - php_git_throw_exception(NULL,error,NULL TSRMLS_CC); - return; - } - - MAKE_STD_ZVAL(obj); - object_init_ex(obj, git_repository_class_entry); - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(obj TSRMLS_CC); - myobj->repository = repository; - - php_git_odb_init(&odb, git_repository_database(repository) TSRMLS_CC); - php_git_add_protected_property_zval_ex(obj,"odb",sizeof("odb"),odb TSRMLS_CC); - php_git_add_protected_property_string_ex(obj,"path",sizeof("path"),path,1 TSRMLS_CC); - - RETVAL_ZVAL(obj, 0, 1); -} - -PHP_METHOD(git_repository, getIndex) -{ - zval *object = getThis(); - php_git_repository_t *myobj; - git_repository *repository; - git_index *index; - zval *index_object; - int error = 0; - - myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); - error = git_repository_index(&index,myobj->repository); - - if (error != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,git_strerror(error)); - RETURN_FALSE; - } - - - MAKE_STD_ZVAL(index_object); - object_init_ex(index_object, git_index_class_entry); - php_git_index_t *iobj = (php_git_index_t *) zend_object_store_get_object(index_object TSRMLS_CC); - - iobj->index = index; - git_index_read(index); - - //Todo: Read from Git object. - //add_property_string_ex(index_object, "path",5,index->index_file_path, 1 TSRMLS_CC); - //add_property_long(index_object, "entry_count",git_index_entrycount(index)); - //zval_ptr_dtor(&index_object); - - RETURN_ZVAL(index_object,0,1); -} - - -PHP_METHOD(git_repository, getObject) -{ - zval *object = getThis(); - zval *git_object; - int git_rawsz = 0; - git_repository *repository; - git_odb *odb; - git_blob *blob; - git_oid oid; - - char *hash; - int ret, hash_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - - git_oid_fromstr(&oid, hash); - - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); - repository = myobj->repository; - - odb = git_repository_database(repository); - - if(!git_odb_exists(odb,&oid)){ - RETURN_FALSE; - }else{ - ret = git_blob_lookup(&blob, repository,&oid); - - if(ret == GIT_SUCCESS){ - MAKE_STD_ZVAL(git_object); - object_init_ex(git_object, git_blob_class_entry); - php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC); - blobobj->object = blob; - - git_rawsz = git_blob_rawsize(blob); - add_property_stringl_ex(git_object,"data", sizeof("data"), (char *)git_blob_rawcontent(blob),git_rawsz, 1 TSRMLS_CC); - RETURN_ZVAL(git_object,1,1); - }else{ - RETURN_FALSE; - } - } -} - - -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; - - MAKE_STD_ZVAL(*object); - object_init_ex(*object, git_tree_entry_class_entry); - php_git_tree_entry_t *entry_obj = (php_git_tree_entry_t *) zend_object_store_get_object(*object TSRMLS_CC); - - entry_obj->entry = entry; - entry_obj->repository = repository; - oid = git_tree_entry_id(entry); - git_oid_to_string(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, "mode", git_tree_entry_attributes(entry)); -} - -PHP_METHOD(git_repository, getCommit) -{ - php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *git_commit_object; - git_repository *repository; - git_odb *odb; - git_object *blob; - git_oid oid; - char out[GIT_OID_HEXSZ+1] = {0}; - char *hash; - int ret, hash_len = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - - git_oid_fromstr(&oid, hash); - ret = git_object_lookup((git_object **)&blob, this->repository,&oid , GIT_OBJ_COMMIT); - if(ret == GIT_SUCCESS){ - php_git_commit_init(&git_commit_object, (git_commit*)blob, this->repository TSRMLS_CC); - RETVAL_ZVAL(git_commit_object,0,1); - }else{ - RETURN_FALSE; - } -} - -PHP_METHOD(git_repository, __construct) -{ - const char *repository_path = NULL; - int arg_len, ret = 0; - git_repository *repository; - zval *odb, *backends, *object; - object = getThis(); - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "|s", &repository_path, &arg_len) == FAILURE){ - return; - } - - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); - - if(arg_len > 0){ - ret = git_repository_open(&repository,repository_path); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,git_strerror(ret)); - RETURN_FALSE; - } - myobj->repository = repository; - - php_git_add_protected_property_string_ex(object,"path",sizeof("path"),git_repository_path(repository),1 TSRMLS_CC); - }else{ - myobj->repository = NULL; - } -} - - -PHP_METHOD(git_repository, getTree) -{ - zval *object = getThis(); - git_tree *tree; - zval *git_tree; - php_git_tree_t *tobj; - git_oid oid; - char *hash; - int i, ret, hash_len = 0; - git_tree_entry *entry; - php_git_tree_entry_t *te; - char buf[GIT_OID_HEXSZ+1] = {0}; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - - git_oid_fromstr(&oid, hash); - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(object TSRMLS_CC); - - ret = git_tree_lookup(&tree, myobj->repository, &oid); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, - "target tree does not exist."); - RETURN_FALSE; - } - - MAKE_STD_ZVAL(git_tree); - object_init_ex(git_tree, git_tree_class_entry); - - tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); - tobj->object = tree; - tobj->repository = myobj->repository; - - RETURN_ZVAL(git_tree,0,0); -} - - -PHP_METHOD(git_repository, getWalker) -{ - zval *walker_object; - git_revwalk *walk; - int ret = 0; - - php_git_repository_t *myobj = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - ret = git_revwalk_new(&walk,myobj->repository); - - MAKE_STD_ZVAL(walker_object); - object_init_ex(walker_object, git_walker_class_entry); - php_git_walker_t *wobj = (php_git_walker_t *) zend_object_store_get_object(walker_object TSRMLS_CC); - wobj->walker = walk; - - RETURN_ZVAL(walker_object,0,1); -} - - -PHP_METHOD(git_repository, addAlternate) -{ - php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *backend; - git_odb *odb; - git_odb_backend *odb_backend; - int ret, priority = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){ - return; - } - - if(!instanceof_function(Z_OBJCE_P(backend), git_backend_class_entry TSRMLS_CC)){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "parameter does not extends Git\\Backend"); - return; - } - - odb = git_repository_database(this->repository); - ret = php_git_odb_add_alternate(&odb, backend, priority); -} - - -PHP_METHOD(git_repository, addBackend) -{ - php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval **data, *backend; - git_odb *odb; - git_odb_backend *odb_backend; - int priority = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &backend, &priority) == FAILURE){ - return; - } - if(!instanceof_function(Z_OBJCE_P(backend), git_backend_class_entry TSRMLS_CC)){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "parameter does not extends Git\\Backend"); - return; - } - - if(zend_hash_exists(Z_OBJPROP_P(getThis()),"odb",sizeof("odb"))) { - if (zend_hash_find(Z_OBJPROP_P(getThis()),"odb",sizeof("odb"),(void **)&data) == SUCCESS) { - php_git_odb_t *odb_t = (php_git_odb_t *) zend_object_store_get_object(*data TSRMLS_CC); - php_git_odb_add_backend(&odb_t->odb,backend, priority); - - zval **hash; - if (zend_hash_find(Z_OBJPROP_P(*data),"backends",sizeof("backends"),(void **)&hash) == SUCCESS) { - add_next_index_zval(*hash,backend); - } - } else { - RETURN_FALSE; - } - } -} - - -PHP_METHOD(git_repository, lookupRef) -{ - php_git_repository_t *this = (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *name; - int rr, result, name_len = 0; - zval *ref; - char out[GIT_OID_HEXSZ+1] = {0}; - git_oid *oid; - git_rtype type; - git_reference *reference; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &name, &name_len) == FAILURE){ - return; - } - - result = git_reference_lookup(&reference, this->repository, name); - if(result != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "Can't find specified reference."); - RETURN_FALSE; - } - - MAKE_STD_ZVAL(ref); - object_init_ex(ref, git_reference_class_entry); - php_git_reference_t *refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC); - refobj->object = reference; - - add_property_string_ex(ref,"name", sizeof("name"), (char *)git_reference_name(reference), 1 TSRMLS_CC); - - type = git_reference_type(reference); - if(type == GIT_REF_SYMBOLIC) { - const char *target = git_reference_target(reference); - if(target != NULL) { - add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); - } - rr = git_reference_resolve(&refobj->object,reference); - if(rr != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "something wrong"); - RETURN_FALSE; - } - } - - git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); - add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); - - RETURN_ZVAL(ref,0,1); -} - -PHP_METHOD(git_repository, getReferences) -{ - php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_strarray *list = malloc(sizeof(git_strarray)); - int rr, i, result = 0; - git_reference *reference; - zval *references; - git_rtype type; - char out[GIT_OID_HEXSZ+1] = {0}; - const char *target; - zval *ref; - - git_reference_listall(list,this->repository,GIT_REF_LISTALL); - - MAKE_STD_ZVAL(references); - array_init(references); - for(i = 0; i < list->count; i++){ - result = git_reference_lookup(&reference, this->repository, list->strings[i]); - if(result != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "Can't find specified reference."); - RETURN_FALSE; - } - - MAKE_STD_ZVAL(ref); - object_init_ex(ref, git_reference_class_entry); - php_git_reference_t *refobj = (php_git_reference_t *) zend_object_store_get_object(ref TSRMLS_CC); - refobj->object = reference; - - add_property_string_ex(ref,"name", sizeof("name"), (char *)git_reference_name(reference), 1 TSRMLS_CC); - - type = git_reference_type(reference); - if(type == GIT_REF_SYMBOLIC) { - target = git_reference_target(reference); - if(target != NULL) { - add_property_string_ex(ref,"target",sizeof("target"),(char *)target, 1 TSRMLS_CC); - } - rr = git_reference_resolve(&refobj->object,reference); - if(rr != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, - "something wrong"); - RETURN_FALSE; - } - } - - git_oid_to_string(out,GIT_OID_HEXSZ+1,git_reference_oid(refobj->object)); - add_property_string_ex(ref,"oid",sizeof("oid"),out, 1 TSRMLS_CC); - memset(out,'\0',GIT_OID_HEXSZ+1); - - add_next_index_zval(references, ref); - } - - git_strarray_free(list); - RETURN_ZVAL(references,0,0); -} - -PHP_METHOD(git_repository, open3) -{ - php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *git_dir, *tree, *index = NULL; - int git_dir_len, index_len, ret, tree_len = 0; - zval *z_odb; - php_git_odb_t *odbt = NULL; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s|zss", &git_dir, &git_dir_len, &z_odb, &index, &index_len, &tree, &tree_len) == FAILURE){ - return; - } - - if(this->repository != NULL){ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"repository busy."); - return; - } - if(z_odb){ - if(instanceof_function(Z_OBJCE_P(z_odb), git_odb_class_entry TSRMLS_CC)){ - odbt = (php_git_odb_t *) zend_object_store_get_object(z_odb TSRMLS_CC); - }else{ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,"specified parameter doesn't Git\\Odb"); - } - } - - ret = git_repository_open3(&this->repository,git_dir,odbt->odb,index,tree); - - if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_WARNING,"can't open specified repository & odb"); - } -} - -PHP_METHOD(git_repository, open2) -{ - php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *git_dir,*git_object_directory,*git_index_file,*git_work_tree; - int ret, git_work_tree_len, git_index_file_len, git_object_directory_len, git_dir_len = 0; - git_repository *repository; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ssss", &git_dir, &git_dir_len, &git_object_directory, &git_object_directory_len, &git_index_file, &git_index_file_len, &git_work_tree, &git_work_tree_len) == FAILURE){ - return; - } - - if(this->repository != NULL){ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "repository busy"); - return; - } - - ret = git_repository_open2(&repository,git_dir, git_object_directory, git_index_file, git_work_tree); - if(ret != GIT_SUCCESS){ - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,git_strerror(ret)); - RETURN_FALSE; - } - - - php_git_add_protected_property_string_ex(getThis(),"path",sizeof("path"),git_dir,1 TSRMLS_CC); - this->repository = repository; - RETURN_TRUE; -} - -PHP_METHOD(git_repository, getWorkdir) -{ - char *git_workdir; - php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - - if(this->repository != NULL) { - git_workdir = git_repository_workdir(this->repository); - RETVAL_STRING(git_workdir,1); - } -} - -PHP_METHOD(git_repository, empty) -{ - php_git_repository_t *this= (php_git_repository_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - if (this->repository != NULL) { - if (git_repository_is_empty(this->repository)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } - } else { - RETURN_TRUE; - } -} - -PHP_METHOD(git_repository, getOdb) -{ - zval *odb = php_git_read_protected_property(git_repository_class_entry,getThis(),"odb",sizeof("odb") TSRMLS_CC); - RETVAL_ZVAL(odb,0,0); -} - - -static zend_function_entry php_git_repository_methods[] = { - PHP_ME(git_repository, __construct, arginfo_git_construct, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getCommit, arginfo_git_get_commit, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getObject, arginfo_git_get_object, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getIndex, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getOdb, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, lookupRef, arginfo_git_lookup_ref, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getWalker, arginfo_git_walker, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getTree, arginfo_git_get_tree, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, init, arginfo_git_init, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(git_repository, addBackend, arginfo_git_add_backend, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, addAlternate, arginfo_git_add_alternate, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, open3, arginfo_git_open3, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, open2, arginfo_git_open2, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getReferences, arginfo_git_get_references, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, getWorkdir, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_repository, empty, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void php_git_repository_init(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Repository", php_git_repository_methods); - git_repository_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git_repository_class_entry->create_object = php_git_repository_new; - - zend_declare_property_null(git_repository_class_entry, "odb",sizeof("odb")-1,ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(git_repository_class_entry, "path",sizeof("path")-1,ZEND_ACC_PROTECTED TSRMLS_CC); -} diff --git a/src/signature.c b/src/signature.c deleted file mode 100644 index 712d030b47..0000000000 --- a/src/signature.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_signature_class_entry; - -void create_signature_from_commit(zval **signature, git_signature *sig); -static void php_git_signature_free_storage(php_git_signature_t *obj TSRMLS_DC); -zend_object_value php_git_signature_new(zend_class_entry *ce TSRMLS_DC); -int php_git_signature_create(zval *object, char *name, int name_len, char *email, int email_len, zval *time); -void git_init_signature(TSRMLS_D); - -/** - * Git\Signature PHP Extension register code block - */ - -PHP_METHOD(git_signature, __construct); - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature__construct, 0, 0, 3) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, email) - ZEND_ARG_INFO(0, when) -ZEND_END_ARG_INFO() - -static zend_function_entry php_git_signature_methods[] = { - PHP_ME(git_signature, __construct, arginfo_git_signature__construct, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -PHP_METHOD(git_signature, __construct) -{ - char *email, *name; - int email_len, name_len = 0; - zval *time; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ssz", &name, &name_len, &email, &email_len, &time) == FAILURE){ - return; - } - - if(!instanceof_function(Z_OBJCE_P(time), php_date_get_date_ce() TSRMLS_CC)){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Git\\Signature third parameter must be DateTime instance."); - return; - } - - int ret = php_git_signature_create(getThis(), name, name_len, email, email_len, time); - if (ret != GIT_SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Git\\Signature internal error"); - } -} - -/** - * Git\Signature PHP Extension implementation. - */ - -void git_init_signature(TSRMLS_D) -{ - zend_class_entry git_signature_ce; - INIT_NS_CLASS_ENTRY(git_signature_ce, PHP_GIT_NS,"Signature", php_git_signature_methods); - - git_signature_class_entry = zend_register_internal_class(&git_signature_ce TSRMLS_CC); - git_signature_class_entry->create_object = php_git_signature_new; -} - -void create_signature_from_commit(zval **signature, git_signature *sig) -{ - TSRMLS_FETCH(); - zval *params[1], *datetime, constructor, method, result; - php_git_signature_t *object; - - MAKE_STD_ZVAL(*signature); - - object_init_ex(*signature,git_signature_class_entry); - object = (php_git_signature_t *) zend_object_store_get_object(*signature TSRMLS_CC); - object->signature = sig; - - add_property_string_ex(*signature,"name",sizeof("name"), sig->name,1 TSRMLS_CC); - add_property_string_ex(*signature,"email",sizeof("email"),sig->email,1 TSRMLS_CC); - - MAKE_STD_ZVAL(datetime); - - ZVAL_STRING(&constructor,"__construct",0); - ZVAL_STRING(&method,"setTimestamp", 0); - - object_init_ex(datetime,php_date_get_date_ce()); - call_user_function(NULL,&datetime,&constructor,&result,0,NULL TSRMLS_CC); - - MAKE_STD_ZVAL(params[0]); - ZVAL_LONG(params[0],sig->when.time); - call_user_function(NULL,&datetime,&method,&result,1,params TSRMLS_CC); - add_property_zval(*signature, "time", datetime); - - zval_ptr_dtor(&datetime); - zval_ptr_dtor(¶ms[0]); -} - -static void php_git_signature_free_storage(php_git_signature_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - if(obj->signature){ - // do not call git_signature_free. - // i'll fix this issue on next release. - - //git_signature_free(obj->signature); - //obj->signature = NULL; - } - - efree(obj); -} - -zend_object_value php_git_signature_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_signature_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_signature_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -int php_git_signature_create(zval *object, char *name, int name_len, char *email, int email_len, zval *time) -{ - TSRMLS_FETCH(); - php_git_signature_t *this = (php_git_signature_t *) zend_object_store_get_object(object TSRMLS_CC); - zval *retval, *offset, func, func2; - int ret = 0; - - // Todo: should use `zend_fcall*` instead of `call_user-function` for performance improvement. - ZVAL_STRING(&func,"getTimestamp", 1); - MAKE_STD_ZVAL(retval); - ZVAL_NULL(retval); - call_user_function(NULL,&time,&func,retval,0,NULL TSRMLS_CC); - - MAKE_STD_ZVAL(offset); - ZVAL_NULL(offset); - ZVAL_STRING(&func2,"getOffset", 1); - call_user_function(NULL,&time,&func2,offset,0,NULL TSRMLS_CC); - git_signature_new(&this->signature, name,email,Z_LVAL_P(retval),Z_LVAL_P(offset)/60); - - add_property_string_ex(object,"name", sizeof("name"), name, 1 TSRMLS_CC); - add_property_string_ex(object,"email",sizeof("email"), email, 1 TSRMLS_CC); - add_property_zval_ex(object,"time",sizeof("time"),time TSRMLS_CC); - - zval_ptr_dtor(&retval); - zval_dtor(&func); - zval_ptr_dtor(&offset); - zval_dtor(&func2); - - return ret; -} - diff --git a/src/tag.c b/src/tag.c deleted file mode 100644 index 4384ed2c96..0000000000 --- a/src/tag.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_tag_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag__construct, 0, 0, 1) - ZEND_ARG_INFO(0, repository) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_set_message, 0, 0, 1) - ZEND_ARG_INFO(0, message) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_set_name, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tag_set_target, 0, 0, 1) - ZEND_ARG_INFO(0, target) -ZEND_END_ARG_INFO() - - -static void php_git_tag_free_storage(php_git_tag_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - if(obj->object){ - obj->object = NULL; - } - - efree(obj); -} - -zend_object_value php_git_tag_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_tag_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_tag_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -PHP_METHOD(git_tag, getMessage) -{ - zval *message = zend_read_property(git_tag_class_entry, getThis(),"message",sizeof("message")-1, 0 TSRMLS_CC); - RETURN_ZVAL(message,1,0); -} - -PHP_METHOD(git_tag, getName) -{ - zval *name = zend_read_property(git_tag_class_entry, getThis(),"name",sizeof("name")-1, 0 TSRMLS_CC); - RETVAL_ZVAL(name,1,0); -} - -PHP_METHOD(git_tag, getTarget) -{ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "this method didn't implement yet"); -/* - php_git_tag_t *tag = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - const git_object *object; - git_otype type; - - object = git_tag_target(tag->object); - type = git_object_type(object); -*/ -} - -PHP_METHOD(git_tag, __construct) -{ - php_git_tag_t *this = (php_git_tag_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - php_git_repository_t *r_obj; - zval *repository; - int ret; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &repository) == FAILURE){ - return; - } - - - if(!instanceof_function(Z_OBJCE_P(repository), git_repository_class_entry TSRMLS_CC)){ - // FIXME - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Git\\Tag parameter only allow Git\\Repository."); - return; - } - r_obj = (php_git_repository_t *) zend_object_store_get_object(repository TSRMLS_CC); - ret = git_tag_new(&this->object,r_obj->repository); - - if(ret != GIT_SUCCESS){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't create Git\\Tag."); - } -} - - -static zend_function_entry php_git_tag_methods[] = { - PHP_ME(git_tag, __construct, arginfo_git_tag__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_tag, getMessage, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tag, getName, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tag, getTarget, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_tag(TSRMLS_D) -{ - zend_class_entry git_tag_ce; - INIT_NS_CLASS_ENTRY(git_tag_ce, PHP_GIT_NS,"Tag", php_git_tag_methods); - git_tag_class_entry = zend_register_internal_class_ex(&git_tag_ce, git_object_class_entry,NULL TSRMLS_CC); - git_tag_class_entry->create_object = php_git_tag_new; - - zend_declare_property_null(git_tag_class_entry, "target", sizeof("target"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_tag_class_entry, "name", sizeof("name"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_tag_class_entry, "tagger", sizeof("tagger"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_tag_class_entry, "message",sizeof("message"), ZEND_ACC_PUBLIC TSRMLS_CC); -} diff --git a/src/tests/001.phpt b/src/tests/001.phpt deleted file mode 100644 index 2487533dbc..0000000000 --- a/src/tests/001.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Check for php-git presence ---SKIPIF-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- - ---FILE-- -name . PHP_EOL; -echo $signature->email . PHP_EOL; -echo $signature->time->getTimestamp() . PHP_EOL; - ---EXPECT-- -Name -sample@example.com -1294147094 \ No newline at end of file diff --git a/src/tests/007_index.phpt b/src/tests/007_index.phpt deleted file mode 100644 index 4c9e957071..0000000000 --- a/src/tests/007_index.phpt +++ /dev/null @@ -1,92 +0,0 @@ ---TEST-- -Check Git\Index behavior ---SKIPIF-- - ---FILE-- -getIndex(); -echo ($index instanceof Git\Index) ? "true" : "false"; -echo PHP_EOL; - -file_put_contents(__DIR__ . REPOSITORY_NAME . "/example","Hello World"); -$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); -$index = $repository->getIndex(); -$index->add("example"); -$entry = $index->find("example"); -echo ($entry->path == "example") ? "ok": "couldn't add index"; -echo PHP_EOL; -$index->refresh(); - - -$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); -$index = $repository->getIndex(); -$index->add("example"); -$index->write(); -$data = file_get_contents(__DIR__ . REPOSITORY_NAME . "/.git/index"); -echo (strpos($data,"example") !== false) ? "ok" : "couldn't write index"; -echo PHP_EOL; - - - -$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); -$index = $repository->getIndex(); -$index->add("example"); -$index->remove("example"); -$index->write(); -$data = file_get_contents(__DIR__ . REPOSITORY_NAME . "/.git/index"); -echo (strpos($data,"example") === false) ? "ok" : "couldn't remove index"; -echo PHP_EOL; - - -$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); -$index = $repository->getIndex(); -$index->add("example"); -$index->write(); -$entry = $index->getEntry(0); -echo ($entry->path == "example") ? "ok" : "couldn't get specified index"; -echo PHP_EOL; - - -$repository = new Repository(__DIR__ . REPOSITORY_NAME . "/.git"); -$index = $repository->getIndex(); -$index->add("example"); -$index->write(); -$it = $index->getIterator(); -echo ($it instanceof Iterator) ? "ok" : "couldn't get iterator instance"; - - -tmp_rmdir(__DIR__ . REPOSITORY_NAME); - ---EXPECT-- -true -ok -ok -ok -ok -ok \ No newline at end of file diff --git a/src/tests/git_repository_new.phpt b/src/tests/git_repository_new.phpt deleted file mode 100644 index 2487533dbc..0000000000 --- a/src/tests/git_repository_new.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Check for php-git presence ---SKIPIF-- - ---FILE-- -memory[$key])){ - $obj = $this->memory[$key]; - - return $obj; - }else{ - return false; - } - } - - /** - * Read Data - * - * @param string $key sha1 hash. - * @return Git\RawObject - * - * Note: libgit2 usualy use internal cache. - * so this method does not call anytime. - */ - public function read($key){ - if($this->exists($key)){ - $object = $this->get($key); - - return $object; - } - } - - /** - * Read Header - * - * @param string $key sha1 hash. - * @return Git\RawObject - * - */ - public function read_header($key){ - if(isset($this->memory[$key])){ - return $this->memory[$key]; - } - } - - /** - * check specified contents. - * - * @param string $key sha1 hash. - * @return boolean - * - */ - public function exists($key){ - if(isset($this->memory[$key])){ - return true; - }else{ - return false; - } - } - - /** - * write contents - * - * you have to write key,data,type your storage engine. - * - * @param string $key sha1 hash. - * @param Git\RawObject $object. - * @return bool - */ - public function write(Git\RawObject $object){ - $this->memory[$object->getId()] = $object; - return true; - } - - public function free() - { - unset($this->memory); - } -} diff --git a/src/tree.c b/src/tree.c deleted file mode 100644 index 7264713529..0000000000 --- a/src/tree.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_tree_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree__construct, 0, 0, 1) - ZEND_ARG_INFO(0, repository) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_add, 0, 0, 3) - ZEND_ARG_INFO(0, hash) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_path, 0, 0, 1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_get_entry, 0, 0, 1) - ZEND_ARG_INFO(0, position) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_remove, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_resolve, 0, 0, 1) - ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - - -static void php_git_tree_free_storage(php_git_tree_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - //Todo: which engine shoud free (php / libgit2) - obj->object = NULL; - efree(obj); -} - -zend_object_value php_git_tree_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_tree_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_tree_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -PHP_METHOD(git_tree, count) -{ - php_git_tree_t *this= (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - RETVAL_LONG(git_tree_entrycount(this->object)); -} - - -PHP_METHOD(git_tree, path) -{ - php_git_tree_t *this= (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *path; - git_tree *tree; - int ret, path_len= 0; - git_tree_entry *entry; - git_object *object; - php_git_blob_t *blobobj; - zval *git_tree, *entries, *git_object; - git_oid *tree_oid; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE){ - return; - } - entry = git_tree_entry_byname(this->object,path); - - if(entry == NULL){ - return; - }else{ - ret = git_tree_entry_2object(&object,git_object_owner(this->object), entry); - - if (ret != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"something uncaught error happend."); - RETURN_FALSE; - } - git_otype type = git_object_type(object); - - if(type == GIT_OBJ_TREE) { - // Todo: refactoring below block - tree = object; - - MAKE_STD_ZVAL(git_tree); - MAKE_STD_ZVAL(entries); - array_init(entries); - object_init_ex(git_tree, git_tree_class_entry); - php_git_tree_t *tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); - tobj->object = tree; - int r = git_tree_entrycount(tree); - int i = 0; - for(i; i < r; i++){ - create_tree_entry_from_entry(&entry,git_tree_entry_byindex(tree,i),this->repository); - add_next_index_zval(entries, entry); - } - add_property_zval(git_tree,"entries", entries); - RETURN_ZVAL(git_tree,0,0); - - }else if(type == GIT_OBJ_BLOB){ - // Todo: refactoring below block - MAKE_STD_ZVAL(git_object); - object_init_ex(git_object, git_blob_class_entry); - blobobj = (php_git_blob_t *) zend_object_store_get_object(git_object TSRMLS_CC); - blobobj->object = (git_blob *)object; - - add_property_stringl_ex(git_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); - RETURN_ZVAL(git_object,0,0); - } else { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, - "Git\\Tree::path can resolve GIT_OBJ_TREE or GIT_OBJ_BLOB. unhandled object type %d found.", git_object_type(object)); - RETURN_FALSE; - } - } -} - -PHP_METHOD(git_tree, __construct) -{ - zval *z_repository; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &z_repository) == FAILURE){ - return; - } - - php_git_repository_t *git = (php_git_repository_t *) zend_object_store_get_object(z_repository TSRMLS_CC); - php_git_tree_t *obj = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); -} - -PHP_METHOD(git_tree, getIterator) -{ - php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *iterator; - - MAKE_STD_ZVAL(iterator); - object_init_ex(iterator,git_tree_iterator_class_entry); - php_git_tree_iterator_t *obj = (php_git_tree_iterator_t *) zend_object_store_get_object(iterator TSRMLS_CC); - obj->tree = this->object; - obj->repository = this->repository; - obj->offset = 0; - RETURN_ZVAL(iterator,0,1); -} - -PHP_METHOD(git_tree, getEntry) -{ - php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_tree_entry *entry; - zval *git_tree_entry; - int offset = 0; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &offset) == FAILURE){ - return; - } - - entry = git_tree_entry_byindex(this->object,offset); - create_tree_entry_from_entry(&git_tree_entry, entry,this->repository); - RETURN_ZVAL(git_tree_entry,0, 1); -} - -PHP_METHOD(git_tree, getEntries) -{ - php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_tree_entry *entry; - zval *array_ptr,*entries; - int i, r; - - r = git_tree_entrycount(this->object); - - MAKE_STD_ZVAL(entries); - array_init(entries); - for(i = 0; i < r; i++){ - create_tree_entry_from_entry(&array_ptr, git_tree_entry_byindex(this->object,i),this->repository); - add_next_index_zval(entries, array_ptr); - } - - RETURN_ZVAL(entries,0,1); -} - -// probably this method will be deplicated. -PHP_METHOD(git_tree, resolve) -{ - php_git_tree_t *this = (php_git_tree_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_tree_entry *entry; - git_object *object; - git_otype type; - git_tree *tree; - php_git_tree_t *tobj; - int path_len, ret; - char *path; - zval *git_raw_object, *git_tree; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path, &path_len) == FAILURE){ - return; - } - - ret = git_tree_entry_resolve_byname(&entry, this->object, this->repository, path); - if(ret != GIT_SUCCESS) { - RETURN_FALSE; - } - - ret = git_tree_entry_2object(&object, this->repository, entry); - if(ret != GIT_SUCCESS) { - RETURN_FALSE; - } - - type = git_object_type(object); - if (type == GIT_OBJ_BLOB) { - - MAKE_STD_ZVAL(git_raw_object); - object_init_ex(git_raw_object, git_blob_class_entry); - php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_raw_object TSRMLS_CC); - blobobj->object = (git_blob *)object; - - add_property_stringl_ex(git_raw_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); - RETURN_ZVAL(git_raw_object,0,1); - } else if(type == GIT_OBJ_TREE) { - tree = object; - - MAKE_STD_ZVAL(git_tree); - object_init_ex(git_tree, git_tree_class_entry); - - tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); - tobj->object = tree; - tobj->repository = this->repository; - - RETURN_ZVAL(git_tree,0,1); - - } else{ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, - "Git\\Tree\\Entry::toObject can convert GIT_OBJ_TREE or GIT_OBJ_BLOB. unhandled object type %d found.", git_object_type(object)); - RETURN_FALSE; - } - -} - -static zend_function_entry php_git_tree_methods[] = { - PHP_ME(git_tree, resolve, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, __construct, arginfo_git_tree__construct, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, getEntry, arginfo_git_tree_get_entry, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, getEntries, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, getIterator, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, count, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree, path, arginfo_git_tree_path, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_tree(TSRMLS_D) -{ - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT_NS,"Tree", php_git_tree_methods); - git_tree_class_entry = zend_register_internal_class_ex(&ce, git_object_class_entry, NULL TSRMLS_CC); - git_tree_class_entry->create_object = php_git_tree_new; - - zend_class_implements(git_tree_class_entry TSRMLS_CC, 2, spl_ce_Countable,zend_ce_aggregate); -} diff --git a/src/tree_builder.c b/src/tree_builder.c deleted file mode 100644 index 023386fde2..0000000000 --- a/src/tree_builder.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_tree_builder_class_entry; - -static void php_git_tree_builder_free_storage(php_git_tree_builder_t *obj TSRMLS_DC) -{ - if(obj->builder){ - git_treebuilder_free(obj->builder); - } - if(obj->repository){ - obj->repository = NULL; - } - zend_object_std_dtor(&obj->zo TSRMLS_CC); - efree(obj); -} - -zend_object_value php_git_tree_builder_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_tree_builder_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_tree_builder_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder__construct, 0, 0, 1) - ZEND_ARG_INFO(0, tree) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder_add, 0, 0, 2) - ZEND_ARG_INFO(0, hash) - ZEND_ARG_INFO(0, path) - ZEND_ARG_INFO(0, attribute) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_builder_remove, 0, 0, 1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -PHP_METHOD(git_tree_builder, __construct) -{ - php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *ztree; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &ztree) == FAILURE){ - return; - } - - if(!instanceof_function(Z_OBJCE_P(ztree), git_tree_class_entry TSRMLS_CC)){ - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"argment does not Git\\Tree instance."); - RETURN_LONG(GIT_ERROR); - } - - php_git_tree_t *tree = (php_git_tree_t *) zend_object_store_get_object(ztree TSRMLS_CC); - - git_treebuilder *builder; - if(git_treebuilder_create(&builder,tree->object) != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create tree builder instance"); - RETURN_LONG(GIT_ERROR); - } - - this->builder = builder; - this->repository = tree->repository; -} - - -PHP_METHOD(git_tree_builder,add) -{ - php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int error = GIT_ERROR; - char *hash, *path; - int hash_len, path_len = 0; - unsigned int attributes; - git_oid id; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "ssl", &hash,&hash_len,&path,&path_len,&attributes) == FAILURE){ - return; - } - - error = git_oid_fromstr(&id, hash); - if (error != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't create object id."); - RETURN_FALSE; - } - - error = git_treebuilder_insert(NULL,this->builder,path,&id,attributes); - if (error != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't add entry"); - RETURN_FALSE; - } - RETURN_TRUE; -} - -PHP_METHOD(git_tree_builder,remove) -{ - php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char *path; - int path_len = 0; - int error = GIT_ERROR; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &path,&path_len) == FAILURE){ - return; - } - - if (path_len < 1) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"must specify target."); - RETURN_FALSE; - } - - error = git_treebuilder_remove(this->builder,path); - - if (error == GIT_SUCCESS) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} - -PHP_METHOD(git_tree_builder,write) -{ - php_git_tree_builder_t *this = (php_git_tree_builder_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - char out[GIT_OID_HEXSZ+1]; - git_oid oid; - int error = GIT_ERROR; - - error = git_treebuilder_write(&oid,this->repository,this->builder); - if(error != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"can't write tree"); - RETURN_FALSE; - } - - git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid); - RETVAL_STRING(out, 1); -} - -static zend_function_entry php_git_tree_builder_methods[] = { - PHP_ME(git_tree_builder, __construct, arginfo_git_tree_builder__construct,ZEND_ACC_PUBLIC) - PHP_ME(git_tree_builder, add, arginfo_git_tree_builder_add, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_builder, remove, arginfo_git_tree_builder_remove, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_builder, write, NULL, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void git_tree_builder_init(TSRMLS_D) -{ - zend_class_entry git_tree_builder_ce; - INIT_NS_CLASS_ENTRY(git_tree_builder_ce, PHP_GIT_NS,"TreeBuilder", php_git_tree_builder_methods); - git_tree_builder_class_entry = zend_register_internal_class(&git_tree_builder_ce TSRMLS_CC); - git_tree_builder_class_entry->create_object = php_git_tree_builder_new; -} diff --git a/src/tree_entry.c b/src/tree_entry.c deleted file mode 100644 index 9ff680f2a9..0000000000 --- a/src/tree_entry.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_tree_entry_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_entry_set_id, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -static void php_git_tree_entry_free_storage(php_git_tree_entry_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - - obj->entry = NULL; - efree(obj); -} - -zend_object_value php_git_tree_entry_new(zend_class_entry *ce TSRMLS_DC) - { - zend_object_value retval; - php_git_tree_entry_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_tree_entry_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - - -PHP_METHOD(git_tree_entry, toObject) -{ - php_git_tree_entry_t *this; - git_object *object; - git_otype type; - zval *git_raw_object, *git_tree; - php_git_tree_t *tobj; - int ret; - - this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - - ret = git_tree_entry_2object(&object, this->repository, this->entry); - - if(ret == GIT_SUCCESS){ - type = git_object_type(object); - if (type == GIT_OBJ_BLOB) { - MAKE_STD_ZVAL(git_raw_object); - object_init_ex(git_raw_object, git_blob_class_entry); - php_git_blob_t *blobobj = (php_git_blob_t *) zend_object_store_get_object(git_raw_object TSRMLS_CC); - blobobj->object = (git_blob *)object; - - add_property_stringl_ex(git_raw_object,"data", sizeof("data"), (char *)git_blob_rawcontent((git_blob *)object),git_blob_rawsize((git_blob *)object), 1 TSRMLS_CC); - RETURN_ZVAL(git_raw_object,0,1); - } else if(type == GIT_OBJ_TREE) { - - MAKE_STD_ZVAL(git_tree); - object_init_ex(git_tree, git_tree_class_entry); - - tobj = (php_git_tree_t *) zend_object_store_get_object(git_tree TSRMLS_CC); - tobj->object = object; - tobj->repository = this->repository; - - RETURN_ZVAL(git_tree,0,1); - - } else { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, - "Git\\Tree\\Entry::toObject can convert GIT_OBJ_TREE or GIT_OBJ_BLOB. unhandled object type %d found.", git_object_type(object)); - RETURN_FALSE; - } - } - -} - -PHP_METHOD(git_tree_entry, __construct) -{ -} - -PHP_METHOD(git_tree_entry, isTree) -{ - php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int attribute = git_tree_entry_attributes(this->entry); - - if(attribute & 040000){ - RETURN_TRUE; - }else{ - RETURN_FALSE; - } -} - -PHP_METHOD(git_tree_entry, isBlob) -{ - php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int attribute = git_tree_entry_attributes(this->entry); - if(!(attribute & 040000)){ - RETURN_TRUE; - }else{ - RETURN_FALSE; - } -} - -PHP_METHOD(git_tree_entry, toHeader) -{ - php_git_tree_entry_t *this = (php_git_tree_entry_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_odb *odb; - git_oid oid; - git_otype type; - zval *git_raw_object; - int length; - char *id; - - id = Z_STRVAL_P(zend_read_property(git_tree_entry_class_entry, getThis(),"oid",sizeof("oid")-1, 0 TSRMLS_CC)); - - git_oid_fromstr(&oid, id); - git_odb_read_header(&length,&type,git_repository_database(this->repository),&oid); - - if (type == GIT_OBJ_BLOB) { - MAKE_STD_ZVAL(git_raw_object); - object_init_ex(git_raw_object, git_blob_class_entry); - - add_property_string_ex(git_raw_object,"data", sizeof("data"), "", 1 TSRMLS_CC); - add_property_long_ex(git_raw_object,"size", sizeof("size"), length TSRMLS_CC); - RETURN_ZVAL(git_raw_object,0,1); - } else { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,"Git\\Tree\\Entry::toHeader can convert GIT_OBJ_BLOB only for now. unhandled object type %d found.", type); - } -} - -static zend_function_entry php_git_tree_entry_methods[] = { - PHP_ME(git_tree_entry, __construct, NULL, ZEND_ACC_PRIVATE) - PHP_ME(git_tree_entry, toHeader, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_entry, toObject, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_entry, isTree, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_entry, isBlob, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_tree_entry(TSRMLS_D) -{ - zend_class_entry git_tree_entry_ce; - INIT_NS_CLASS_ENTRY(git_tree_entry_ce, ZEND_NS_NAME(PHP_GIT_NS,"Tree"),"Entry", php_git_tree_entry_methods); - git_tree_entry_class_entry = zend_register_internal_class(&git_tree_entry_ce TSRMLS_CC); - git_tree_entry_class_entry->create_object = php_git_tree_entry_new; - - zend_declare_property_null(git_tree_entry_class_entry, "name",sizeof("name")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_tree_entry_class_entry, "oid",sizeof("oid")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(git_tree_entry_class_entry, "mode",sizeof("mode")-1, ZEND_ACC_PUBLIC TSRMLS_CC); - -} diff --git a/src/tree_iterator.c b/src/tree_iterator.c deleted file mode 100644 index 7bc50fe00c..0000000000 --- a/src/tree_iterator.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -extern void create_tree_entry_from_entry(zval **object, git_tree_entry *entry,git_repository *repository); - -PHPAPI zend_class_entry *git_tree_iterator_class_entry; -extern void php_tree_index_entry_create(zval **index, git_tree_entry *entry); - -static void php_git_tree_iterator_free_storage(php_git_tree_iterator_t *obj TSRMLS_DC) -{ - zend_object_std_dtor(&obj->zo TSRMLS_CC); - obj->tree = NULL; - efree(obj); -} - -zend_object_value php_git_tree_iterator_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_tree_iterator_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_tree_iterator_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_tree_iterator__construct, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -PHP_METHOD(git_tree_iterator, current) -{ - php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_tree_entry *entry; - zval *git_tree_entry; - - entry = git_tree_entry_byindex(this->tree,this->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(&git_tree_entry,entry,this->repository); - RETURN_ZVAL(git_tree_entry,0,1); -} - -PHP_METHOD(git_tree_iterator, key) -{ - php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_LONG(this->offset); -} - -PHP_METHOD(git_tree_iterator, next) -{ - php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - this->offset++; - - RETURN_TRUE; -} - -PHP_METHOD(git_tree_iterator, rewind) -{ - php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - this->offset = 0; -} - -PHP_METHOD(git_tree_iterator, valid) -{ - php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - int entry_count = git_tree_entrycount(this->tree); - - if(this->offset < entry_count && this->offset >= 0){ - RETURN_TRUE; - }else{ - RETURN_FALSE; - } -} - -PHP_METHOD(git_tree_iterator, __construct) -{ - php_git_tree_iterator_t *this = (php_git_tree_iterator_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - zval *php_tree_index; - php_git_tree_t *tree; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "z", &php_tree_index) == FAILURE){ - return; - } - tree = (php_git_tree_t *) zend_object_store_get_object(php_tree_index TSRMLS_CC); - - this->tree = tree->object; - this->offset = 0; -} - - -static zend_function_entry php_git_tree_iterator_methods[] = { - PHP_ME(git_tree_iterator, __construct, arginfo_git_tree_iterator__construct,ZEND_ACC_PUBLIC) - PHP_ME(git_tree_iterator, current, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_iterator, key, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_iterator, next, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_iterator, rewind, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_tree_iterator, valid, NULL, ZEND_ACC_PUBLIC) - {NULL,NULL,NULL} -}; - -void git_tree_iterator_init(TSRMLS_D) -{ - zend_class_entry git_tree_iterator_ce; - INIT_NS_CLASS_ENTRY(git_tree_iterator_ce, PHP_GIT_NS,"TreeIterator", php_git_tree_iterator_methods); - git_tree_iterator_class_entry = zend_register_internal_class(&git_tree_iterator_ce TSRMLS_CC); - git_tree_iterator_class_entry->create_object = php_git_tree_iterator_new; - zend_class_implements(git_tree_iterator_class_entry TSRMLS_CC, 1, spl_ce_Iterator); -} diff --git a/src/walker.c b/src/walker.c deleted file mode 100644 index b217b2e77b..0000000000 --- a/src/walker.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010 - 2011 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_git.h" -#include -#include -#include -#include - -PHPAPI zend_class_entry *git_walker_class_entry; - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_walker_hide, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_walker_push, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_git_walker_sort, 0, 0, 1) - ZEND_ARG_INFO(0, hash) -ZEND_END_ARG_INFO() - -static void php_git_walker_free_storage(php_git_walker_t *obj TSRMLS_DC) -{ - if(obj->walker != NULL){ - git_revwalk_free(obj->walker); - obj->walker = NULL; - } - zend_object_std_dtor(&obj->zo TSRMLS_CC); - efree(obj); -} - -zend_object_value php_git_walker_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_git_walker_t *obj; - zval *tmp; - - obj = ecalloc(1, sizeof(*obj)); - zend_object_std_init( &obj->zo, ce TSRMLS_CC ); - zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(obj, - (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_git_walker_free_storage, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - return retval; -} - -PHP_METHOD(git_walker, __construct) -{ -} - -PHP_METHOD(git_walker, hide) -{ - char *hash; - int hash_len = 0; - git_revwalk *walker; - git_commit *commit; - git_repository *repository; - git_oid oid; - php_git_walker_t *myobj; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - - myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - walker = myobj->walker; - - repository = git_revwalk_repository(walker); - - git_oid_fromstr(&oid,hash); - - git_revwalk_hide(walker,&oid); -} - -PHP_METHOD(git_walker, push) -{ - char *hash; - int hash_len = 0; - git_oid oid; - git_commit *head; - git_revwalk *walker; - git_repository *repository; - php_git_walker_t *myobj; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "s", &hash, &hash_len) == FAILURE){ - return; - } - - myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - walker = myobj->walker; - repository = git_revwalk_repository(walker); - - git_oid_fromstr(&oid,hash); - - git_revwalk_push(walker,&oid); -} - - -PHP_METHOD(git_walker, next) -{ - zval *git_commit_object; - char *hash; - int ret, hash_len = 0; - git_oid oid; - git_commit *commit; - git_revwalk *walker; - git_signature *signature; - zval *parents; - php_git_walker_t *myobj; - - myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - walker = myobj->walker; - - ret = git_revwalk_next(&oid,walker); - if(ret != GIT_SUCCESS){ - RETURN_FALSE; - } - git_object_lookup((git_object **)&commit, git_revwalk_repository(walker), &oid, GIT_OBJ_COMMIT); - php_git_commit_init(&git_commit_object, (git_commit*)commit, git_revwalk_repository(walker) TSRMLS_CC); - - RETURN_ZVAL(git_commit_object,0,1); -} - - -PHP_METHOD(git_walker, reset) -{ - php_git_walker_t *myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_revwalk_reset(myobj->walker); - RETURN_TRUE; -} - -PHP_METHOD(git_walker, sort) -{ - int mode = 0; - php_git_walker_t *myobj; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &mode) == FAILURE){ - return; - } - - myobj = (php_git_walker_t *) zend_object_store_get_object(getThis() TSRMLS_CC); - git_revwalk_sorting(myobj->walker, mode); - RETURN_TRUE; -} - -static zend_function_entry php_git_walker_methods[] = { - PHP_ME(git_walker, __construct, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_walker, push, arginfo_git_walker_push, ZEND_ACC_PUBLIC) - PHP_ME(git_walker, next, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_walker, hide, arginfo_git_walker_hide, ZEND_ACC_PUBLIC) - PHP_ME(git_walker, reset, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git_walker, sort, arginfo_git_walker_sort, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -void git_init_walker(TSRMLS_D) -{ - zend_class_entry git_walker_ce; - INIT_NS_CLASS_ENTRY(git_walker_ce, PHP_GIT_NS,"Revwalk", php_git_walker_methods); - git_walker_class_entry = zend_register_internal_class(&git_walker_ce TSRMLS_CC); - git_walker_class_entry->create_object = php_git_walker_new; -} diff --git a/tests/GitReferenceTest.php b/tests/GitReferenceTest.php deleted file mode 100644 index 6128e797ee..0000000000 --- a/tests/GitReferenceTest.php +++ /dev/null @@ -1,91 +0,0 @@ -markTestSkipped(); - } - - protected function tearDown() - { - // currentry nothing to do. - } - - /** - * Repository can lookup Git Reference. - */ - public function testGitRefrenceCanResolve() - { - $rep = new Git\Repository(dirname(__DIR__) . "/.git/"); - $reference = $rep->lookupRef(self::$reference_name); - $this->assertInstanceof("Git\\Reference",$reference,"returned object does not Git\\Reference"); - } - - - /** - * Reference can call getType() - */ - public function testGitReferenceCanUseGetType() - { - $rep = new Git\Repository(dirname(__DIR__) . "/.git/"); - $ref = $rep->lookupRef(self::$reference_name); - $type = $ref->getType(); - $this->assertEquals(1,$type,"illegal reference type returned.(this is legacy test. check test file)"); - } - - /** - * Reference can call getName(); - */ - public function testGitReferenceGetName() - { - $rep = new Git\Repository(dirname(__DIR__) . "/.git/"); - $ref = $rep->lookupRef(self::$reference_name); - $name = $ref->getName(); - - $this->assertEquals(self::$reference_name,$name,"reference name missmatched."); - } - - /** - * Reference can call getId(); - */ - public function testGitReferenceGetId() - { - $rep = new Git\Repository(dirname(__DIR__) . "/.git/"); - $ref = $rep->lookupRef(self::$reference_name); - $id = $ref->getId(); - - $this->assertEquals(40,strlen($id),"illegal oid size returned"); - } - - - /** - * Reference failed when call getTarget(); - */ - public function testGitReferenceGetTarget() - { - $rep = new Git\Repository(dirname(__DIR__) . "/.git/"); - $ref = $rep->lookupRef(self::$reference_name); - try{ - $target = $ref->getTarget(); - $this->fail("something wrong. this method allowed symbolic reference only."); - }catch(Exception $e){ - $this->assertTrue(true,"can't call getTarget method when lookup doesn't symbolic reference"); - } - } -} \ No newline at end of file diff --git a/tests/GitRevwalkTest.php b/tests/GitRevwalkTest.php deleted file mode 100644 index b845cd094e..0000000000 --- a/tests/GitRevwalkTest.php +++ /dev/null @@ -1,74 +0,0 @@ -getWalker(); - $this->assertInstanceOf("Git\\Revwalk",$walker); - unset($git); - } - - public function testPush() - { - $git = new Git\Repository(".git"); - $walker = $git->getWalker(); - $walker->push("1def80657903dcf8d9d87a5e4edfaca92ddcff38"); - $commit = $walker->next(); - $this->assertInstanceof("Git\\Commit",$commit); - unset($git); - } - - public function testRest() - { - $git = new Git\Repository(".git"); - $walker = $git->getWalker(); - $walker->push("1def80657903dcf8d9d87a5e4edfaca92ddcff38"); - $walker->reset(); - } - - public function testSort() - { - /* - Git::SORT_NONE - Git::SORT_TOPO - Git::SORT_DATE - Git::SORT_REVERSE - 先にPHPのarrayにしてuserspaceでの対応にするか悩む - */ - $git = new Git\Repository(".git"); - $walker = $git->getWalker(); - $walker->sort(Git\Revwalk\SORT_NONE); - $walker->push("1def80657903dcf8d9d87a5e4edfaca92ddcff38"); - $this->assertInstanceof("Git\\Commit",$walker->next()); - } -} \ No newline at end of file diff --git a/tests/GitTreeTest.php b/tests/GitTreeTest.php deleted file mode 100644 index 6d697a2546..0000000000 --- a/tests/GitTreeTest.php +++ /dev/null @@ -1,86 +0,0 @@ -getCommit("7caa5b63e5fe4596543378e47b5225b6a1fa2dee"); - }catch(\Exception $e){ - $this->fail(); - } - unset($git); - } - - public function testCount() - { - try{ - $repository = new Repository("./.git"); - $tree = $repository->getTree("8b230bc64e9384f6cedc9c8128270c30635571a7"); - $this->assertEquals(2,count($tree)); - }catch(\Exception $e){ - $this->fail(); - } - unset($git); - } - - public function testPath() - { - try{ - $repository = new Repository("./.git"); - $tree = $repository->getTree("f031269837fabfa2c63e7a37b000a91171855f3f"); - $object = $tree->path("EXPERIMENTAL"); - $this->assertInstanceof("Git\\Blob",$object,"couldn't get specified blob object"); - $this->assertEquals("80afdcd19e73e8e39757ebcdebedbf8fee2ebfc1",$object->getId()); - $object = $tree->path("docs"); - $this->assertInstanceof("Git\\Tree",$object,"couldn't get specified tree object"); - }catch(\Exception $e){ - $this->fail(); - } - unset($git); - } - - public function testGetIterator() - { - $repository = new Repository("./.git"); - $tree = $repository->getTree("f031269837fabfa2c63e7a37b000a91171855f3f"); - $itr = $tree->getIterator(); - - $this->assertInstanceOf("Iterator",$itr,"can't get iterator object"); - } - - public function testGetEntries() - { - $repository = new Repository("./.git"); - $tree = $repository->getTree("f031269837fabfa2c63e7a37b000a91171855f3f"); - $this->assertEquals(10, count($tree->getEntries()),"can't get specified entries"); - } - - public function testGetEntry() - { - $repository = new Repository("./.git"); - $tree = $repository->getTree("f031269837fabfa2c63e7a37b000a91171855f3f"); - $this->assertEquals("tests", $tree->getEntry(9)->name,"can't get specified entry"); - } - - } \ No newline at end of file diff --git a/tests/fixtures/fixture.git/HEAD b/tests/fixtures/fixture.git/HEAD deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/fixtures/fixture.git/index b/tests/fixtures/fixture.git/index deleted file mode 100644 index 37dc6a068f51a7efef259be8bdefc3862992e252..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 248 zcmZ?q402{*U|<4bW?y-e+ft?t7hp640|yg>kp5)`hQ=j8=@$^p!1u|gWYJTGukVD7 zPGnD!oFBCD;>{!m_SA~R+=84`ph3R!reAf$m4W6!Xs9`t(9BU*GZFcseBsG;-gW&? z?H9X={I}CcU|`Ki&B@6JngTNCpA|9<78G)yhh`3ohgi+|cWds7oLYX-eow@nhc$A- i&ls3<^FeL_0Y~=S6{#FyuWQcv3+ui8Ji-3zZC(KJ-%DKp diff --git a/tests/fixtures/fixture.git/objects/08/dcc094241a93be371a6bf79a535231bd49df97 b/tests/fixtures/fixture.git/objects/08/dcc094241a93be371a6bf79a535231bd49df97 deleted file mode 100644 index 818287dc185d984ad912b139b8bbe7341b2abc95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 133 zcmV;00DAv;0i}&W4#FT106p`Hy_+;ppzJ1%@#uf@rn0$ n@p8W$;MN$;np;&o9bJ;qoj|FIGrY$V)9(NJ*?zNXsu$NY5`;CCs&4eto1mfd&2W+5XadQEDS}V9FqVNzYiq< diff --git a/tests/fixtures/fixture.git/objects/48/167ccfeeacdd14caa7d13fbc58bce17c1e13e6 b/tests/fixtures/fixture.git/objects/48/167ccfeeacdd14caa7d13fbc58bce17c1e13e6 deleted file mode 100644 index 3cd096b03093fe03f82ddc145d2453b2bc15d04e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 19 acmb4V4FlPAMD&g-A@e8|M$c#+K$0JRnj3IG5A diff --git a/tests/fixtures/fixture.git/objects/78/678dcc067fa15c9f867de93e0d0410f470ed96 b/tests/fixtures/fixture.git/objects/78/678dcc067fa15c9f867de93e0d0410f470ed96 deleted file mode 100644 index 05c45edd291bd0351892cbb778ec8f4ba1d013c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 81 zcmV-X0IvUd0V^p=O;s?nU@$Z=Ff%bxNUccBEyzh__~cWv=qbb3cfv*|vZqMS588O~ nW)f6MMruw@K7*Qx$QR`cPp>wjv$*iGcWokjuxJM|t6dlV#L diff --git a/tests/fixtures/fixture.git/objects/7c/aa5b63e5fe4596543378e47b5225b6a1fa2dee b/tests/fixtures/fixture.git/objects/7c/aa5b63e5fe4596543378e47b5225b6a1fa2dee deleted file mode 100644 index 7734564048..0000000000 --- a/tests/fixtures/fixture.git/objects/7c/aa5b63e5fe4596543378e47b5225b6a1fa2dee +++ /dev/null @@ -1 +0,0 @@ -xMj0 F)/ OJ (qIz\x|պv) hiҜq"~\NP1y,ДG-=;5E2΅X8gMїr,§<*s_xn;qbOѝ< 'mkMoN \ No newline at end of file diff --git a/tests/fixtures/fixture.git/objects/89/88da15d077d4829fc51d8544c097def6644dbb b/tests/fixtures/fixture.git/objects/89/88da15d077d4829fc51d8544c097def6644dbb deleted file mode 100644 index bae81901916026f4c2750f662633a5ef63030456..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 81 zcmV-X0IvUd0V^p=O;s?nU@$Z=Ff%bxNUccBEyzh__~cWv=qbb3cfv*|vZqMS588O~ nW)f6MMruw@K0|2j2HTg@Ph@#9^~vqEl6kEZ{m23UJi8srbao`g diff --git a/tests/fixtures/fixture.git/objects/ea/e8e8d42804e31e5761451d900ca510b9d36c3c b/tests/fixtures/fixture.git/objects/ea/e8e8d42804e31e5761451d900ca510b9d36c3c deleted file mode 100644 index 92fa492654de175c3104fbf0741304bc973deb63..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 105 zcmV-v0G9uF0V^p=O;s>7FlI0`FfcPQQAn*w%q_@CW%%S%vgj$p*LT83C$gtV&JWsn z@n#a55{90NzY*!rr4=sC{W**Ojpn0EU#y`@GE#GL@)^`jM7}6rcygV0UH?=2#cm@1 L?KBbqfTJx~f?Y7? diff --git a/tests/fixtures/fixture.git/objects/f2/4c74a2e500f5ee1332c86b94199f52b1d1d962 b/tests/fixtures/fixture.git/objects/f2/4c74a2e500f5ee1332c86b94199f52b1d1d962 deleted file mode 100644 index ef863535c6026af8929eaa1f546ada9ab668aa14..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30 mcmblK%lPg0!)_R=LJ>mJ3i6Kar-2(u})eIs4 From f53cd6074fbc0a8d82ce219bd765958d495c2d6d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 24 Jan 2012 13:06:49 +0900 Subject: [PATCH 068/300] added Git2\Config --- config.c | 179 ++++++++++++++++++++++++ config.m4 | 1 + git2.c | 2 + php_git2.h | 6 + tests/mock/001-02/objects/info/.gitkeep | 0 tests/mock/001-02/objects/pack/.gitkeep | 0 6 files changed, 188 insertions(+) create mode 100644 config.c create mode 100644 tests/mock/001-02/objects/info/.gitkeep create mode 100644 tests/mock/001-02/objects/pack/.gitkeep diff --git a/config.c b/config.c new file mode 100644 index 0000000000..d67ef505de --- /dev/null +++ b/config.c @@ -0,0 +1,179 @@ +/* + * 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 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); +} + +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); + 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() + +typedef struct{ + zval *result; + git_config *config; +} php_git2_config_foreach_t; + +static int php_git2_config_foreach(const char *var_name, const char *value, void *payload) +{ + HashTable *hash; + zval *entry, **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(opaque->config, var_name, &config_value); + + 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) { + 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(entry); + array_init(entry); + zend_hash_add(hash, k, strlen(k)+1, (void **)&entry, sizeof(entry), NULL); + hash = Z_ARRVAL_P(entry); + } + } + } + + 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); + } + efree(tmp_value); + + return GIT_SUCCESS; +} + +/* +{{{ 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; + zval *config_array; + php_git2_config_foreach_t payload; + + /* @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; + + /* @todo: think solution */ + MAKE_STD_ZVAL(config_array); + array_init(config_array); + + payload.config = config; + payload.result = config_array; + error = git_config_foreach(config,&php_git2_config_foreach,&payload); + add_property_zval(getThis(), "configs", config_array); + zval_ptr_dtor(&config_array); +} +/* }}} */ + +/* +{{{ proto: Git2\Config::get(string $key) +*/ +PHP_METHOD(git2_config, get) +{ + char *key; + git_config *config; + int error, key_len = 0; + const char *value; + php_git2_config *m_config; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "s", &key, &key_len) == FAILURE) { + return; + } + + m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); + error = git_config_get_string(m_config->config, key, &value); + RETVAL_STRING(value, 1); +} +/* }}} */ + + +static zend_function_entry php_git2_config_methods[] = { + PHP_ME(git2_config, __construct, arginfo_git2_config___construct, ZEND_ACC_PUBLIC) + PHP_ME(git2_config, get, arginfo_git2_config_get, 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; +} \ No newline at end of file diff --git a/config.m4 b/config.m4 index 34aab37435..935dd968cc 100644 --- a/config.m4 +++ b/config.m4 @@ -41,6 +41,7 @@ if test $PHP_GIT2 != "no"; then reference.c \ index.c \ index_entry.c \ + config.c \ , $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], diff --git a/git2.c b/git2.c index bc8f5dec91..e91356d5c7 100644 --- a/git2.c +++ b/git2.c @@ -32,6 +32,7 @@ extern void php_git2_tree_builder_init(TSRMLS_D); extern void php_git2_signature_init(TSRMLS_D); extern void php_git2_walker_init(TSRMLS_D); extern void php_git2_reference_init(TSRMLS_D); +extern void php_git2_config_init(TSRMLS_D); int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...) @@ -176,6 +177,7 @@ PHP_MINIT_FUNCTION(git2) 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); return SUCCESS; } diff --git a/php_git2.h b/php_git2.h index d8e19e5bc7..75f5bc0703 100644 --- a/php_git2.h +++ b/php_git2.h @@ -54,6 +54,7 @@ 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; typedef struct{ zend_object zo; @@ -115,6 +116,11 @@ typedef struct{ git_index_entry *entry; } php_git2_index_entry; +typedef struct{ + zend_object zo; + git_config *config; +} php_git2_config; + # define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); diff --git a/tests/mock/001-02/objects/info/.gitkeep b/tests/mock/001-02/objects/info/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/mock/001-02/objects/pack/.gitkeep b/tests/mock/001-02/objects/pack/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From ce963231ea55c7fa81ca84bb01730c90f984fa90 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 24 Jan 2012 21:53:53 +0900 Subject: [PATCH 069/300] added gitkeep --- tests/mock/001-07/detached/refs/heads/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/mock/001-07/detached/refs/heads/.gitkeep diff --git a/tests/mock/001-07/detached/refs/heads/.gitkeep b/tests/mock/001-07/detached/refs/heads/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From 4fe6eff787238d32566422af69dfdb486de6f5a7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 24 Jan 2012 23:11:10 +0900 Subject: [PATCH 070/300] modified Git2\Config::get --- config.c | 56 ++++++++++++++++++- tests/00a-01-config___construct.phpt | 26 +++++++++ tests/00a-02-config_get.phpt | 23 ++++++++ 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 ++ .../fixtures/testrepo.git/refs/heads/.gitkeep | 0 8 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 tests/00a-01-config___construct.phpt create mode 100644 tests/00a-02-config_get.phpt create mode 100644 tests/fixtures/testrepo.git/HEAD create mode 100644 tests/fixtures/testrepo.git/config create mode 100644 tests/fixtures/testrepo.git/description create mode 100644 tests/fixtures/testrepo.git/info/exclude create mode 100644 tests/fixtures/testrepo.git/refs/heads/.gitkeep diff --git a/config.c b/config.c index d67ef505de..c3abf9d781 100644 --- a/config.c +++ b/config.c @@ -60,6 +60,52 @@ typedef struct{ 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(); + HashTable *hash; + 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 char *var_name, const char *value, void *payload) { HashTable *hash; @@ -150,15 +196,19 @@ PHP_METHOD(git2_config, get) int error, key_len = 0; const char *value; php_git2_config *m_config; + zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } - m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); - error = git_config_get_string(m_config->config, key, &value); - RETVAL_STRING(value, 1); + if (key_len < 1) { + RETURN_FALSE; + } + + php_git2_config_resolve(&result, (const char *)key, getThis()); + RETVAL_ZVAL(result,0,1); } /* }}} */ diff --git a/tests/00a-01-config___construct.phpt b/tests/00a-01-config___construct.phpt new file mode 100644 index 0000000000..191b7d56f8 --- /dev/null +++ b/tests/00a-01-config___construct.phpt @@ -0,0 +1,26 @@ +--TEST-- +Check for Git2\Config::__construct +--SKIPIF-- + +--FILE-- + + array(1) { + ["core"]=> + array(4) { + ["repositoryformatversion"]=> + string(1) "0" + ["filemode"]=> + string(4) "true" + ["bare"]=> + string(4) "true" + ["ignorecase"]=> + string(4) "true" + } + } +} \ No newline at end of file diff --git a/tests/00a-02-config_get.phpt b/tests/00a-02-config_get.phpt new file mode 100644 index 0000000000..d8adef2346 --- /dev/null +++ b/tests/00a-02-config_get.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check for Git2\Config::get +--SKIPIF-- + +--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/fixtures/testrepo.git/HEAD b/tests/fixtures/testrepo.git/HEAD new file mode 100644 index 0000000000..cb089cd89a --- /dev/null +++ b/tests/fixtures/testrepo.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests/fixtures/testrepo.git/config b/tests/fixtures/testrepo.git/config new file mode 100644 index 0000000000..c53d818dd9 --- /dev/null +++ b/tests/fixtures/testrepo.git/config @@ -0,0 +1,5 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true + ignorecase = true diff --git a/tests/fixtures/testrepo.git/description b/tests/fixtures/testrepo.git/description new file mode 100644 index 0000000000..498b267a8c --- /dev/null +++ b/tests/fixtures/testrepo.git/description @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..a5196d1be8 --- /dev/null +++ b/tests/fixtures/testrepo.git/info/exclude @@ -0,0 +1,6 @@ +# 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/refs/heads/.gitkeep b/tests/fixtures/testrepo.git/refs/heads/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From 36c0b2101a78efe1e9b01cbc3c03e8c7b48e35e8 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 25 Jan 2012 01:43:53 +0900 Subject: [PATCH 071/300] added test cases for Git2\Config::store and delete. --- config.c | 120 +++++++++++++++++++++++++++++--- tests/00a-03-config_store.phpt | 44 ++++++++++++ tests/00a-04-config_delete.phpt | 22 ++++++ 3 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 tests/00a-03-config_store.phpt create mode 100644 tests/00a-04-config_delete.phpt diff --git a/config.c b/config.c index c3abf9d781..042e7d267d 100644 --- a/config.c +++ b/config.c @@ -55,6 +55,15 @@ 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; @@ -151,6 +160,32 @@ static int php_git2_config_foreach(const char *var_name, const char *value, void return GIT_SUCCESS; } +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); + } +} + /* {{{ proto: Git2\Config::__construct(string $path) */ @@ -174,15 +209,11 @@ PHP_METHOD(git2_config, __construct) m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); m_config->config = config; - /* @todo: think solution */ - MAKE_STD_ZVAL(config_array); - array_init(config_array); - - payload.config = config; - payload.result = config_array; - error = git_config_foreach(config,&php_git2_config_foreach,&payload); - add_property_zval(getThis(), "configs", config_array); - zval_ptr_dtor(&config_array); + php_git2_config_reload(getThis(), 1 TSRMLS_CC); + /** + * @todo: support global config + * php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC); + */ } /* }}} */ @@ -213,9 +244,80 @@ PHP_METHOD(git2_config, get) /* }}} */ +/* +{{{ proto: Git2\Config::store(string $key, mixed $value) +*/ +PHP_METHOD(git2_config, store) +{ + char *key; + int error, key_len = 0; + zval *result, *value, *entry; + php_git2_config *m_config; + php_git2_config_foreach_t payload; + + 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 error, key_len = 0; + zval *result, *entry; + php_git2_config *m_config; + php_git2_config_foreach_t payload; + + 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(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) 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} }; diff --git a/tests/00a-03-config_store.phpt b/tests/00a-03-config_store.phpt new file mode 100644 index 0000000000..15791f2963 --- /dev/null +++ b/tests/00a-03-config_store.phpt @@ -0,0 +1,44 @@ +--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 new file mode 100644 index 0000000000..627d15058e --- /dev/null +++ b/tests/00a-04-config_delete.phpt @@ -0,0 +1,22 @@ +--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 From 6a957b7b02e01b5ee6a24fb554d2315ebda40637 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 25 Jan 2012 08:55:10 +0900 Subject: [PATCH 072/300] added Git2\Remoete class.but acutually it can instanciate only. --- config.m4 | 1 + git2.c | 2 + php_git2.h | 6 +++ remote.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 remote.c diff --git a/config.m4 b/config.m4 index 935dd968cc..84a306ddfb 100644 --- a/config.m4 +++ b/config.m4 @@ -42,6 +42,7 @@ if test $PHP_GIT2 != "no"; then index.c \ index_entry.c \ config.c \ + remote.c \ , $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], diff --git a/git2.c b/git2.c index e91356d5c7..78834d8e1a 100644 --- a/git2.c +++ b/git2.c @@ -33,6 +33,7 @@ extern void php_git2_signature_init(TSRMLS_D); extern void php_git2_walker_init(TSRMLS_D); extern void php_git2_reference_init(TSRMLS_D); extern void php_git2_config_init(TSRMLS_D); +extern void php_git2_remote_init(TSRMLS_D); int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...) @@ -178,6 +179,7 @@ PHP_MINIT_FUNCTION(git2) 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); return SUCCESS; } diff --git a/php_git2.h b/php_git2.h index 75f5bc0703..2d3a1b1047 100644 --- a/php_git2.h +++ b/php_git2.h @@ -55,6 +55,7 @@ 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; typedef struct{ zend_object zo; @@ -121,6 +122,11 @@ typedef struct{ git_config *config; } php_git2_config; +typedef struct{ + zend_object zo; + git_remote *remote; +} php_git2_remote; + # define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); diff --git a/remote.c b/remote.c new file mode 100644 index 0000000000..706fb651f3 --- /dev/null +++ b/remote.c @@ -0,0 +1,127 @@ +/* + * 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_connect, 0,0,1) + ZEND_ARG_INFO(0, direction) +ZEND_END_ARG_INFO() + +/* +{{{ proto: Git2\Remote::__construct(Git2\Repository $repository, string $url) +*/ +PHP_METHOD(git2_remote, __construct) +{ + char *path; + git_config *config; + 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)) { + error = git_remote_new( + &remote, + m_repository->repository, + path, + NULL + ); + } else { + error = git_remote_load(&remote,m_repository->repository, path); + } + m_remote->remote = remote; +} +/* }}} */ + +/* +{{{ proto: Git2\Remote::connect(int type) +*/ +PHP_METHOD(git2_remote, connect) +{ + php_git2_remote *m_remote; + int error = 0; + long direction = 0; + + m_remote = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "l", &direction) == FAILURE) { + return; + } + + if (direction == 0) { + direction = GIT_DIR_FETCH; + } + + error = git_remote_connect(m_remote->remote, direction); +} +/* }}} */ + +static zend_function_entry php_git2_remote_methods[] = { + PHP_ME(git2_remote, __construct, arginfo_git2_remote___construct, ZEND_ACC_PUBLIC) + PHP_ME(git2_remote, connect, arginfo_git2_remote_connect, 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 From 93fe1a6985462ac131f97529460fc7afeeb7a0c0 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 25 Jan 2012 12:47:35 +0900 Subject: [PATCH 073/300] added Git2\TreeEntry isSubmodule, isBlob, isTree methods --- tests/006-02-tree_entry_is_blob.phpt | 19 ++++++ tests/fixtures/init.php | 56 +++++++++++++++++ .../19/9e7c128125a430899fc5c1c0bd08699c9a5692 | Bin 0 -> 51 bytes .../2c/83838315fd649b17e968e96e9d4543c9efd1e9 | Bin 0 -> 46 bytes .../5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 | Bin 0 -> 27 bytes .../74/edf90112fadb1c0ea2dc48352e0ed4ead2e1cf | Bin 0 -> 2399 bytes .../87/cef34f1a5c8d386418e9fa3e8948ef7322a007 | Bin 0 -> 28 bytes .../a0/8e8505259a0ab4474ca79ba92bd7912b5a32c3 | Bin 0 -> 28 bytes .../ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 | Bin 0 -> 36 bytes tree_entry.c | 59 ++++++++++++++++++ 10 files changed, 134 insertions(+) create mode 100644 tests/006-02-tree_entry_is_blob.phpt create mode 100644 tests/fixtures/init.php create mode 100644 tests/fixtures/testrepo.git/objects/19/9e7c128125a430899fc5c1c0bd08699c9a5692 create mode 100644 tests/fixtures/testrepo.git/objects/2c/83838315fd649b17e968e96e9d4543c9efd1e9 create mode 100644 tests/fixtures/testrepo.git/objects/5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 create mode 100644 tests/fixtures/testrepo.git/objects/74/edf90112fadb1c0ea2dc48352e0ed4ead2e1cf create mode 100644 tests/fixtures/testrepo.git/objects/87/cef34f1a5c8d386418e9fa3e8948ef7322a007 create mode 100644 tests/fixtures/testrepo.git/objects/a0/8e8505259a0ab4474ca79ba92bd7912b5a32c3 create mode 100644 tests/fixtures/testrepo.git/objects/ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 diff --git a/tests/006-02-tree_entry_is_blob.phpt b/tests/006-02-tree_entry_is_blob.phpt new file mode 100644 index 0000000000..324d3c1111 --- /dev/null +++ b/tests/006-02-tree_entry_is_blob.phpt @@ -0,0 +1,19 @@ +--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/fixtures/init.php b/tests/fixtures/init.php new file mode 100644 index 0000000000..7874972c94 --- /dev/null +++ b/tests/fixtures/init.php @@ -0,0 +1,56 @@ +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/objects/19/9e7c128125a430899fc5c1c0bd08699c9a5692 b/tests/fixtures/testrepo.git/objects/19/9e7c128125a430899fc5c1c0bd08699c9a5692 new file mode 100644 index 0000000000000000000000000000000000000000..366d5f7413c945c32dac8ccaa51c97f425b5fc60 GIT binary patch literal 51 zcmbK&-#Ubrb&N~mbJ4kUmTZvjD)5VqjumU~Cv@kWf)E))wX-f?9G82Hh2i}+zIOnJ Ci4xKP literal 0 HcmV?d00001 diff --git a/tests/fixtures/testrepo.git/objects/5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 b/tests/fixtures/testrepo.git/objects/5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689 new file mode 100644 index 0000000000000000000000000000000000000000..8a119c8c0c3e2c12d2e55eaa5b45b9bcd5faca14 GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/tests/fixtures/testrepo.git/objects/ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 b/tests/fixtures/testrepo.git/objects/ca/06beddccb5d9eb9bf4787ef42407a438b3abf1 new file mode 100644 index 0000000000000000000000000000000000000000..89f87a6d666ebe4a8f9e21fb6bd65d84b4aadb3d GIT binary patch literal 36 scmb Date: Wed, 25 Jan 2012 13:01:03 +0900 Subject: [PATCH 074/300] added static method --- blob.c | 42 ++++++++++++++++++++++++++++++++++- tests/004-03-blob_create.phpt | 17 ++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/004-03-blob_create.phpt diff --git a/blob.c b/blob.c index ced9b81b6d..d5279469db 100644 --- a/blob.c +++ b/blob.c @@ -44,6 +44,12 @@ zend_object_value php_git2_blob_new(zend_class_entry *ce TSRMLS_DC) 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::__toString() @@ -67,9 +73,43 @@ PHP_METHOD(git2_blob, __toString) } /* }}} */ +/* +{{{ 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, __toString, 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} }; diff --git a/tests/004-03-blob_create.phpt b/tests/004-03-blob_create.phpt new file mode 100644 index 0000000000..64ccc61a5c --- /dev/null +++ b/tests/004-03-blob_create.phpt @@ -0,0 +1,17 @@ +--TEST-- +Check for Git2\Blob::__toString +--SKIPIF-- + +--FILE-- + Date: Wed, 25 Jan 2012 13:09:09 +0900 Subject: [PATCH 075/300] update README --- README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a818dbefe0..baa5726cf7 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,28 @@ please check tests cases. # Installing And Running +you need to install libgit2 before make php-git. + +```` +git clone https://github.com/libgit2/libgit2.git +cd libgit2 +mkdir build +cd build +cmake .. +cmake --build +sudo cmake --build . --target install +```` + ```` git clone https://github.com/libgit2/php-git.git cd php-git phpize ./configure make -sudo make Install +make test +sudo make install ```` +new php-git features almost tested. # API @@ -43,13 +57,23 @@ $repo = new Git2\Repository($path); ## Object Access +### create new blob + +```` +$oid = Git2\Blob::create($repo, "Hello World"); +```` + ## 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); } ```` @@ -109,4 +133,31 @@ $walker->push("6e20138dc38f9f626107f1cd3ef0f9838c43defe"); foreach ($walker as $oid => $commit) { printf("oid: %s\n", $oid); printf("message: %s\n", $commit->getMessage()); -} \ No newline at end of file +} + +## Config access + +```` +$config = new Git2\Config("path/to/git/config"); +$config->get("core.bare"); +$config->store("core.bare","1"); +```` + +## Reflog +will be add. + +## Remote access + +will be add. + +## Author +* Shuhei Tanuma + +## Contributors + +* Anthony Van de Gejuchte +* Cameron Eagans +* Graham Weldon +* James Titcumb +* Ryusuke SEKIYAMA +* Shuhei Tanuma \ No newline at end of file From e2920a89eda935924490e0be004d3b0f25cafb05 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 25 Jan 2012 13:12:14 +0900 Subject: [PATCH 076/300] why i forgot to commit LICENSE file ? --- LICENSE | 21 +++++++++++++++++++++ README.md | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..a68c9c890c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +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. diff --git a/README.md b/README.md index baa5726cf7..4ea6850904 100644 --- a/README.md +++ b/README.md @@ -160,4 +160,9 @@ will be add. * Graham Weldon * James Titcumb * Ryusuke SEKIYAMA -* Shuhei Tanuma \ No newline at end of file +* Shuhei Tanuma + + +## LICENSE + +MIT License From 69450d861006c7d0aa3a435d3d5c272fc3a68326 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 25 Jan 2012 13:13:44 +0900 Subject: [PATCH 077/300] fixed typo --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4ea6850904..031cc5e109 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ foreach ($walker as $oid => $commit) { printf("oid: %s\n", $oid); printf("message: %s\n", $commit->getMessage()); } +```` ## Config access From 61680105e634305583854bc51d07a9cd90941d86 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 26 Jan 2012 03:48:50 +0900 Subject: [PATCH 078/300] added getContent and getSize methods for Git2\Blob --- blob.c | 46 +++++++++++++++++++++++++++++++++ tests/004-04-blob_get_size.phpt | 12 +++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/004-04-blob_get_size.phpt diff --git a/blob.c b/blob.c index d5279469db..e9c0c33cf4 100644 --- a/blob.c +++ b/blob.c @@ -50,6 +50,50 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_blob_create, 0,0,2) ZEND_END_ARG_INFO() +/* +{{{ proto: Git2\Blob::getContent() +*/ +PHP_METHOD(git2_blob, getContent) +{ + char *data; + 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) +{ + char *data; + 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() @@ -108,6 +152,8 @@ PHP_METHOD(git2_blob, create) 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} diff --git a/tests/004-04-blob_get_size.phpt b/tests/004-04-blob_get_size.phpt new file mode 100644 index 0000000000..1828723027 --- /dev/null +++ b/tests/004-04-blob_get_size.phpt @@ -0,0 +1,12 @@ +--TEST-- +Check for Git2\Blob::__toString +--SKIPIF-- + +--FILE-- +lookup("557db03de997c86a4a028e1ebd3a1ceb225be238"); + +echo $blob->getSize(); +--EXPECT-- +12 \ No newline at end of file From bfb3e2cf2172e1d3f2c31871075f8272791a7ab1 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 26 Jan 2012 04:34:13 +0900 Subject: [PATCH 079/300] for now, added Git2\Tree::diff method. i don't have a good idea right now. --- tree.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tree.c b/tree.c index 74f4dc0b55..1abc857601 100644 --- a/tree.c +++ b/tree.c @@ -47,6 +47,54 @@ zend_object_value php_git2_tree_new(zend_class_entry *ce TSRMLS_DC) return retval; } +ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_diff, 0,0,2) + ZEND_ARG_INFO(0, old) + ZEND_ARG_INFO(0, new) +ZEND_END_ARG_INFO() + + +static int php_git2_tree_diff_cb(const git_tree_diff_data *ptr, void *data) +{ +/* +typedef struct { + unsigned int old_attr; + unsigned int new_attr; + git_oid old_oid; + git_oid new_oid; + git_status_t status; + const char *path; +} git_tree_diff_data; +*/ + fprintf(stderr,"path:%s\n",ptr->path); +} + +typedef struct{ + zval *old; + zval *new; + zval *result; +} php_git2_tree_diff_cb_t; +/* +{{{ proto: Git2\Tree::diff($old, $new) + @todo: think this behavior +*/ +PHP_METHOD(git2_tree, diff) +{ + zval *old, *new; + php_git2_tree *m_old, *m_new; + php_git2_tree_diff_cb_t payload; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "OO", &old, git2_tree_class_entry, &new, git2_tree_class_entry) == FAILURE) { + return; + } + + m_old = PHP_GIT2_GET_OBJECT(php_git2_tree, old); + m_new = PHP_GIT2_GET_OBJECT(php_git2_tree, new); + + git_tree_diff(git_tree_id(m_old->tree),git_tree_id(m_new->tree), &php_git2_tree_diff_cb, &payload); +} +/* }}} */ + /* Iterator Implementation */ @@ -69,6 +117,7 @@ PHP_METHOD(git2_tree, current) create_tree_entry_from_entry(&z_entry, entry ,m_tree->repository); RETURN_ZVAL(z_entry, 0, 1); } +/* }}} */ /* {{{ proto: Git2\Tree::key() @@ -123,6 +172,7 @@ PHP_METHOD(git2_tree, valid) static zend_function_entry php_git2_tree_methods[] = { + PHP_ME(git2_tree, diff, arginfo_git2_tree_diff, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) /* Iterator Implementation */ PHP_ME(git2_tree, current, NULL, ZEND_ACC_PUBLIC) PHP_ME(git2_tree, key, NULL, ZEND_ACC_PUBLIC) From 91d1fd9e389a339439fd5d26ed41276971032187 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 28 Jan 2012 02:00:10 +0900 Subject: [PATCH 080/300] added Git2\Commit::getOid --- commit.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/commit.c b/commit.c index 6b639caae3..bf0d657eef 100644 --- a/commit.c +++ b/commit.c @@ -168,6 +168,31 @@ PHP_METHOD(git2_commit, getCommitter) } /* }}} */ +/* +{{{ proto: Git2\Commit::getOid() +*/ +PHP_METHOD(git2_commit, getOid) +{ + unsigned int parent_count = 0; + php_git2_commit *m_commit; + char oid_out[GIT_OID_HEXSZ] = {0}; + git_oid oid; + + 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) */ @@ -304,6 +329,7 @@ static zend_function_entry php_git2_commit_methods[] = { 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, create, arginfo_git2_commit_create, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC) {NULL,NULL,NULL} }; @@ -315,4 +341,4 @@ void php_git2_commit_init(TSRMLS_D) 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; -} \ No newline at end of file +} From e86c5d7e8473f96bb6f37784ad329e2f5205f1c9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 28 Jan 2012 02:11:40 +0900 Subject: [PATCH 081/300] added Git2\Commit::getTree --- commit.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/commit.c b/commit.c index bf0d657eef..11b708333f 100644 --- a/commit.c +++ b/commit.c @@ -323,6 +323,37 @@ PHP_METHOD(git2_commit, create) } /* }}} */ + +/* +{{{ proto: Git2\Commit::getTree() +*/ +PHP_METHOD(git2_commit, getTree) +{ + php_git2_commit *m_commit; + git_oid *oid, *id; + 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; + } +} +/* }}} */ + + 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) @@ -330,6 +361,7 @@ static zend_function_entry php_git2_commit_methods[] = { 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, create, arginfo_git2_commit_create, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC) {NULL,NULL,NULL} }; From d2133ac0b419af5ded48c59d6a32d8bd9139916c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 01:57:17 +0900 Subject: [PATCH 082/300] for now, added php_git2_exception_check --- php_git2.h | 7 +++++++ repository.c | 8 ++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/php_git2.h b/php_git2.h index 2d3a1b1047..d6851c7196 100644 --- a/php_git2.h +++ b/php_git2.h @@ -242,4 +242,11 @@ static inline void php_git2_create_index_entry(zval **object, git_index_entry *e *object = tmp; } +static inline void php_git2_exception_check(int errorcode TSRMLS_DC) +{ + if (errorcode < 0) + zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%s\n(error code %d)", git_lasterror(), errorcode); + git_clearerror(); +} + #endif /* PHP_GIT2_H */ \ No newline at end of file diff --git a/repository.c b/repository.c index b4f46ddafa..493e678bcb 100644 --- a/repository.c +++ b/repository.c @@ -96,11 +96,7 @@ PHP_METHOD(git2_repository, __construct) m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); if (repository_path_len > 0) { ret = git_repository_open(&repository, repository_path); - - if (ret != GIT_SUCCESS) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, git_strerror(ret)); - RETURN_FALSE; - } + php_git2_exception_check(ret TSRMLS_CC); m_repository->repository = repository; php_git2_add_protected_property_string_ex(getThis(), @@ -231,7 +227,7 @@ PHP_METHOD(git2_repository, init) RETVAL_ZVAL(object,0,1); } else { - /* @todo: throws an runtime exception */ + php_git2_exception_check(ret TSRMLS_CC); RETURN_FALSE; } } From 4dd28ccfe0ccd88f2564b12d368d85471788491b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 18:46:33 +0900 Subject: [PATCH 083/300] for now, added Git2\Tag --- config.m4 | 1 + git2.c | 7 +++++++ php_git2.h | 20 ++++++++++++++++-- repository.c | 2 +- tag.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tag.c diff --git a/config.m4 b/config.m4 index 84a306ddfb..33cd277e08 100644 --- a/config.m4 +++ b/config.m4 @@ -43,6 +43,7 @@ if test $PHP_GIT2 != "no"; then index_entry.c \ config.c \ remote.c \ + tag.c \ , $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], diff --git a/git2.c b/git2.c index 78834d8e1a..096fac917a 100644 --- a/git2.c +++ b/git2.c @@ -34,6 +34,7 @@ extern void php_git2_walker_init(TSRMLS_D); extern void php_git2_reference_init(TSRMLS_D); extern void php_git2_config_init(TSRMLS_D); extern void php_git2_remote_init(TSRMLS_D); +extern void php_git2_tag_init(TSRMLS_D); int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...) @@ -140,6 +141,11 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ break; } 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; } default: @@ -180,6 +186,7 @@ PHP_MINIT_FUNCTION(git2) php_git2_index_init(TSRMLS_C); php_git2_config_init(TSRMLS_C); php_git2_remote_init(TSRMLS_C); + php_git2_tag_init(TSRMLS_C); return SUCCESS; } diff --git a/php_git2.h b/php_git2.h index d6851c7196..440cceca7e 100644 --- a/php_git2.h +++ b/php_git2.h @@ -56,6 +56,7 @@ 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; typedef struct{ zend_object zo; @@ -127,6 +128,11 @@ typedef struct{ git_remote *remote; } php_git2_remote; +typedef struct{ + zend_object zo; + git_tag *tag; +} php_git2_tag; + # define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); @@ -242,11 +248,21 @@ static inline void php_git2_create_index_entry(zval **object, git_index_entry *e *object = tmp; } +#define PHP_GIT2_EXCEPTION_CHECK(errorcode) \ + if (errorcode < 0) { \ + zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%s\n(error code %d)", git_lasterror(), errorcode); \ + git_clearerror(); \ + return; \ + } \ + static inline void php_git2_exception_check(int errorcode TSRMLS_DC) { - if (errorcode < 0) + if (errorcode < 0) { zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%s\n(error code %d)", git_lasterror(), errorcode); - git_clearerror(); + fprintf(stderr,"moe"); + git_clearerror(); + return; + } } #endif /* PHP_GIT2_H */ \ No newline at end of file diff --git a/repository.c b/repository.c index 493e678bcb..b94d5923c9 100644 --- a/repository.c +++ b/repository.c @@ -96,7 +96,7 @@ PHP_METHOD(git2_repository, __construct) m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); if (repository_path_len > 0) { ret = git_repository_open(&repository, repository_path); - php_git2_exception_check(ret TSRMLS_CC); + PHP_GIT2_EXCEPTION_CHECK(ret); m_repository->repository = repository; php_git2_add_protected_property_string_ex(getThis(), diff --git a/tag.c b/tag.c new file mode 100644 index 0000000000..8bbf15f35a --- /dev/null +++ b/tag.c @@ -0,0 +1,58 @@ +/* + * 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; +} + +static zend_function_entry php_git2_tag_methods[] = { + {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 From 0f44e70f4c20c7d0d5a7508bcb355bbfd8bdd6a3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 19:02:00 +0900 Subject: [PATCH 084/300] move tag block to above. --- git2.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/git2.c b/git2.c index 096fac917a..e6fdd1d50d 100644 --- a/git2.c +++ b/git2.c @@ -85,6 +85,14 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ 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; @@ -140,14 +148,6 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ break; } - 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; - } default: break; } From 978f43f29f6822dfe2bc1a562c9549f5bd79152d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 19:21:38 +0900 Subject: [PATCH 085/300] more error check --- repository.c | 64 +++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/repository.c b/repository.c index b94d5923c9..0466a7fede 100644 --- a/repository.c +++ b/repository.c @@ -308,7 +308,7 @@ PHP_METHOD(git2_repository, discover) PHP_METHOD(git2_repository, exists) { char *hash; - int hash_len = 0; + int error, hash_len = 0; git_odb *odb; git_oid id; php_git2_repository *m_repository; @@ -319,18 +319,16 @@ PHP_METHOD(git2_repository, exists) } m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (git_repository_odb(&odb, m_repository->repository) == GIT_SUCCESS) { - if (git_oid_fromstr(&id, hash) != GIT_SUCCESS) { - RETURN_FALSE; - } - - if (git_odb_exists(odb, &id) == 1) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } + error = git_repository_odb(&odb, m_repository->repository); + PHP_GIT2_EXCEPTION_CHECK(error); + + if (git_oid_fromstr(&id, hash) != GIT_SUCCESS) { + RETURN_FALSE; + } + + if (git_odb_exists(odb, &id) == 1) { + RETURN_TRUE; } else { - /* @todo: throws an exception */ RETURN_FALSE; } } @@ -349,6 +347,7 @@ PHP_METHOD(git2_repository, lookup) 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) { @@ -356,25 +355,21 @@ PHP_METHOD(git2_repository, lookup) } m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); - if (git_repository_odb(&odb, m_repository->repository) == GIT_SUCCESS) { - zval *result = NULL; - - if (git_oid_fromstrn(&id, hash, hash_len) != GIT_SUCCESS) { - 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); - } else { - /* @todo: throws an exception */ + error = git_repository_odb(&odb, m_repository->repository); + PHP_GIT2_EXCEPTION_CHECK(error); + + if (git_oid_fromstrn(&id, hash, hash_len) != GIT_SUCCESS) { 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); } /* }}} */ @@ -400,16 +395,16 @@ PHP_METHOD(git2_repository, write) m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); error = git_repository_odb(&odb, m_repository->repository); - /* @todo: error check */ + PHP_GIT2_EXCEPTION_CHECK(error); error = git_odb_open_wstream(&stream, odb, contents_len, (git_otype)type); - /* @todo: error check */ + PHP_GIT2_EXCEPTION_CHECK(error); error = stream->write(stream, contents, contents_len); - /* @todo: error check */ + PHP_GIT2_EXCEPTION_CHECK(error); error = stream->finalize_write(&oid, stream); - /* @todo: error check */ + PHP_GIT2_EXCEPTION_CHECK(error); git_oid_fmt(oid_out, &oid); RETURN_STRINGL(oid_out,GIT_OID_HEXSZ,1); @@ -437,7 +432,10 @@ PHP_METHOD(git2_repository, hash) 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); From 0878e22873e8309dfd2e0f5894f8b3ec05d9a89c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 19:24:44 +0900 Subject: [PATCH 086/300] added Git\Blob introduction to README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 031cc5e109..61527a0cf0 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ $repo = new Git2\Repository($path); ```` $oid = Git2\Blob::create($repo, "Hello World"); +/* + $blob = $repo->lookup($oid); + int $blob->getSize(); + string $blob->getContent(); +*/ ```` ## Tree Access From c9d9fb408e994c19087d8b6e871637d95c5c421e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 19:29:43 +0900 Subject: [PATCH 087/300] added exception when calling Git2\Commit::create --- commit.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commit.c b/commit.c index 11b708333f..edb525ff5e 100644 --- a/commit.c +++ b/commit.c @@ -223,6 +223,9 @@ PHP_METHOD(git2_commit, create) 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) { @@ -243,6 +246,9 @@ PHP_METHOD(git2_commit, create) 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) { @@ -259,6 +265,9 @@ PHP_METHOD(git2_commit, create) 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) { From a2571fa02a35d7ab24d187a8416576443d816b4b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 19:35:16 +0900 Subject: [PATCH 088/300] added ZEND_ACC_CTOR --- config.c | 2 +- index.c | 2 +- remote.c | 2 +- repository.c | 3 ++- signature.c | 2 +- tree_builder.c | 2 +- tree_entry.c | 2 +- walker.c | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index 042e7d267d..9fa34c0331 100644 --- a/config.c +++ b/config.c @@ -314,7 +314,7 @@ PHP_METHOD(git2_config, delete) /* }}} */ static zend_function_entry php_git2_config_methods[] = { - PHP_ME(git2_config, __construct, arginfo_git2_config___construct, ZEND_ACC_PUBLIC) + 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) diff --git a/index.c b/index.c index ea2833ffe0..e56b906d1c 100644 --- a/index.c +++ b/index.c @@ -179,7 +179,7 @@ PHP_METHOD(git2_index, valid) static zend_function_entry php_git2_index_methods[] = { - PHP_ME(git2_index, __construct, arginfo_git2_index___construct, ZEND_ACC_PUBLIC) + 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) diff --git a/remote.c b/remote.c index 706fb651f3..21ba2d20f8 100644 --- a/remote.c +++ b/remote.c @@ -112,7 +112,7 @@ PHP_METHOD(git2_remote, connect) /* }}} */ static zend_function_entry php_git2_remote_methods[] = { - PHP_ME(git2_remote, __construct, arginfo_git2_remote___construct, ZEND_ACC_PUBLIC) + PHP_ME(git2_remote, __construct, arginfo_git2_remote___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_ME(git2_remote, connect, arginfo_git2_remote_connect, ZEND_ACC_PUBLIC) {NULL,NULL,NULL} }; diff --git a/repository.c b/repository.c index 0466a7fede..8e3669051b 100644 --- a/repository.c +++ b/repository.c @@ -27,6 +27,7 @@ PHPAPI zend_class_entry *git2_repository_class_entry; void php_git2_repository_init(TSRMLS_D); + static void php_git2_repository_free_storage(php_git2_repository *object TSRMLS_DC) { if (object->repository != NULL) { @@ -444,7 +445,7 @@ PHP_METHOD(git2_repository, hash) static zend_function_entry php_git2_repository_methods[] = { - PHP_ME(git2_repository, __construct, arginfo_git2_repository___construct, ZEND_ACC_PUBLIC) + 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) diff --git a/signature.c b/signature.c index a2ba49b778..8427486c5d 100644 --- a/signature.c +++ b/signature.c @@ -112,7 +112,7 @@ PHP_METHOD(git2_signature, __construct) static zend_function_entry php_git2_signature_methods[] = { - PHP_ME(git2_signature, __construct, arginfo_git2_signature___construct, ZEND_ACC_PUBLIC) + PHP_ME(git2_signature, __construct, arginfo_git2_signature___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) {NULL,NULL,NULL} }; diff --git a/tree_builder.c b/tree_builder.c index 893e7d2d39..c513cef425 100644 --- a/tree_builder.c +++ b/tree_builder.c @@ -175,7 +175,7 @@ PHP_METHOD(git2_tree_builder, clear) /* }}} */ static zend_function_entry php_git2_tree_builder_methods[] = { - PHP_ME(git2_tree_builder, __construct, arginfo_git2_tree_builder___construct, ZEND_ACC_PUBLIC) + 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) diff --git a/tree_entry.c b/tree_entry.c index 1ffeb49a19..4e7dd1eb4c 100644 --- a/tree_entry.c +++ b/tree_entry.c @@ -144,7 +144,7 @@ PHP_METHOD(git2_tree_entry, isSubmodule) static zend_function_entry php_git2_tree_entry_methods[] = { - PHP_ME(git2_tree_entry, __construct, arginfo_git2_tree_entry___construct, ZEND_ACC_PUBLIC) + 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) diff --git a/walker.c b/walker.c index 8acc3b83f0..66b9602fad 100644 --- a/walker.c +++ b/walker.c @@ -263,7 +263,7 @@ PHP_METHOD(git2_walker, valid) /* }}} */ static zend_function_entry php_git2_walker_methods[] = { - PHP_ME(git2_walker, __construct, arginfo_git2_walker___construct, ZEND_ACC_PUBLIC) + 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) From 3292f7cebd7b0a3995e4ea3ec39beeaa43f8c717 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 19:46:55 +0900 Subject: [PATCH 089/300] Git2\Repository is not clonable --- repository.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/repository.c b/repository.c index 8e3669051b..c34784a55b 100644 --- a/repository.c +++ b/repository.c @@ -26,7 +26,7 @@ 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) { @@ -43,6 +43,7 @@ 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; } @@ -474,4 +475,8 @@ void php_git2_repository_init(TSRMLS_D) 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; + } From bf4e6889ea698d0728515ce74a113d428cbdea64 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 29 Jan 2012 23:57:10 +0900 Subject: [PATCH 090/300] read dimension and has dimension support for Git2\Config. now Git2\Config is able to use read dimension as a syntax sugar for Git2\Config::get() echo $config['core.bare'] // same as $config->get('core.bare') echo isset($config['core.bare']) --- config.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/config.c b/config.c index 9fa34c0331..8487de4087 100644 --- a/config.c +++ b/config.c @@ -27,6 +27,7 @@ #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) { @@ -38,11 +39,102 @@ static void php_git2_config_free_storage(php_git2_config *object TSRMLS_DC) efree(object); } +/* @todo refactoring */ +static int php_git2_config_has_dimension(zval *object, zval *member, int check_empty TSRMLS_DC) +{ + zend_object_handlers *standard; + HashTable *hash; + zval *entry, *tmp_result, **target_offset; + char *current_key, *tmp_value, *savedptr, *k; + int error = 0; + + entry = zend_read_property(git2_config_class_entry, object,"configs",sizeof("configs")-1, 0 TSRMLS_CC); + + 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) +{ + zend_object_handlers *standard; + HashTable *hash; + zval *entry, *tmp_result, **target_offset; + char *current_key, *tmp_value, *savedptr, *k; + int error = 0; + + entry = zend_read_property(git2_config_class_entry, object,"configs",sizeof("configs")-1, 0 TSRMLS_CC); + + 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 { + MAKE_STD_ZVAL(tmp_result); + ZVAL_NULL(tmp_result); + } + 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; } @@ -328,4 +420,8 @@ void php_git2_config_init(TSRMLS_D) 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; } \ No newline at end of file From 6783d1c89b753dea23b2364efe264a5421c114ce Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 00:09:10 +0900 Subject: [PATCH 091/300] write dimension support for Git2\Config. $config['core.bare'] = true; // same as $config->store("core.bare",true); --- config.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/config.c b/config.c index 8487de4087..8494f68ea2 100644 --- a/config.c +++ b/config.c @@ -39,6 +39,7 @@ static void php_git2_config_free_storage(php_git2_config *object TSRMLS_DC) efree(object); } + /* @todo refactoring */ static int php_git2_config_has_dimension(zval *object, zval *member, int check_empty TSRMLS_DC) { @@ -278,6 +279,36 @@ static int php_git2_config_reload(zval *object, unsigned short dtor TSRMLS_DC) } } +static void php_git2_config_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) +{ + char *key; + int error, key_len = 0; + zval *result, *entry; + 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) */ @@ -424,4 +455,5 @@ void php_git2_config_init(TSRMLS_D) 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 From 85f31d2dc4f386451d9d64d47107158de1b38a8c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 00:11:12 +0900 Subject: [PATCH 092/300] add read / write dimension support to README. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 61527a0cf0..c604659272 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,10 @@ foreach ($walker as $oid => $commit) { $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; ```` ## Reflog From 16fe634d87fe3d0817a21661c108d85a047805b7 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 02:18:14 +0900 Subject: [PATCH 093/300] added read / write dimension test for Git2\Config --- config.c | 11 +++++-- tests/00a-05-config_dimension_get.phpt | 23 ++++++++++++++ tests/00a-06-config_dimension_set.phpt | 44 ++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/00a-05-config_dimension_get.phpt create mode 100644 tests/00a-06-config_dimension_set.phpt diff --git a/config.c b/config.c index 8494f68ea2..d6b97c441b 100644 --- a/config.c +++ b/config.c @@ -51,6 +51,10 @@ static int php_git2_config_has_dimension(zval *object, zval *member, int check_e 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) { @@ -95,6 +99,10 @@ static zval* php_git2_config_read_dimension(zval *object, zval *offset, int type int error = 0; 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); @@ -123,8 +131,7 @@ static zval* php_git2_config_read_dimension(zval *object, zval *offset, int type if (target_offset != NULL) { tmp_result = *target_offset; } else { - MAKE_STD_ZVAL(tmp_result); - ZVAL_NULL(tmp_result); + tmp_result = 0; } return tmp_result; } diff --git a/tests/00a-05-config_dimension_get.phpt b/tests/00a-05-config_dimension_get.phpt new file mode 100644 index 0000000000..35e3c8c425 --- /dev/null +++ b/tests/00a-05-config_dimension_get.phpt @@ -0,0 +1,23 @@ +--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 new file mode 100644 index 0000000000..f8c1b04f04 --- /dev/null +++ b/tests/00a-06-config_dimension_set.phpt @@ -0,0 +1,44 @@ +--TEST-- +Check for Git2\Config dimension set +--SKIPIF-- + +--FILE-- + Date: Mon, 30 Jan 2012 03:54:50 +0900 Subject: [PATCH 094/300] improve exception message --- php_git2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_git2.h b/php_git2.h index 440cceca7e..cfdce8c63b 100644 --- a/php_git2.h +++ b/php_git2.h @@ -250,7 +250,7 @@ static inline void php_git2_create_index_entry(zval **object, git_index_entry *e #define PHP_GIT2_EXCEPTION_CHECK(errorcode) \ if (errorcode < 0) { \ - zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%s\n(error code %d)", git_lasterror(), errorcode); \ + zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%s\n(error code %d) at %s:%d", git_lasterror(), errorcode, __FILE__, __LINE__); \ git_clearerror(); \ return; \ } \ From 72c72884cc59c122dfcaf860628453943b00d76b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 03:55:28 +0900 Subject: [PATCH 095/300] for now, implement Git2\Remote::fetch(). Remote method stil under development. --- remote.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/remote.c b/remote.c index 21ba2d20f8..60ea27eb94 100644 --- a/remote.c +++ b/remote.c @@ -49,8 +49,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_remote___construct, 0,0,2) ZEND_ARG_INFO(0, url) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_remote_connect, 0,0,1) - ZEND_ARG_INFO(0, direction) +ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_remote_fetch, 0,0,1) ZEND_END_ARG_INFO() /* @@ -87,33 +86,89 @@ PHP_METHOD(git2_remote, __construct) } /* }}} */ + +static int php_git2_rename_packfile(char *packname, git_indexer *idx) +{ + char path[GIT_PATH_MAX], oid[GIT_OID_HEXSZ + 1], *slash; + int ret; + + strcpy(path,packname); + slash = strrchr(path, '/'); + + if (!slash) { + return GIT_EINVALIDARGS; + } + + memset(oid, 0x0, sizeof(oid)); + git_oid_fmt(oid, git_indexer_hash(idx)); + ret = sprintf(slash + 1, "pack-%s.pack", oid); + if(ret < 0) { + return GIT_EOSERR; + } + + 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_SUCCESS; +} + /* -{{{ proto: Git2\Remote::connect(int type) +{{{ proto: Git2\Remote::fetch() */ -PHP_METHOD(git2_remote, connect) +PHP_METHOD(git2_remote, fetch) { php_git2_remote *m_remote; + git_indexer *idx = NULL; + git_indexer_stats stats; + char *packname = NULL; int error = 0; long direction = 0; m_remote = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); +/* if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &direction) == FAILURE) { return; } - - if (direction == 0) { - direction = GIT_DIR_FETCH; - } +*/ + direction = GIT_DIR_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_new(&idx, packname); + PHP_GIT2_EXCEPTION_CHECK(error); + + error = git_indexer_run(idx, &stats); + PHP_GIT2_EXCEPTION_CHECK(error); + + error = git_indexer_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, connect, arginfo_git2_remote_connect, ZEND_ACC_PUBLIC) + PHP_ME(git2_remote, fetch, arginfo_git2_remote_fetch, ZEND_ACC_PUBLIC) {NULL,NULL,NULL} }; From fa822a36d3561d60ec8eae87a5ed6c3481cf759a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 06:16:37 +0900 Subject: [PATCH 096/300] for now, added Git2\ODB --- config.m4 | 1 + git2.c | 33 ++++++++++++++++++++++++++ odb.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ php_git2.h | 9 ++++++++ repository.c | 14 ++++++++++- 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 odb.c diff --git a/config.m4 b/config.m4 index 33cd277e08..ad414a7bb5 100644 --- a/config.m4 +++ b/config.m4 @@ -44,6 +44,7 @@ if test $PHP_GIT2 != "no"; then config.c \ remote.c \ tag.c \ + odb.c \ , $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], diff --git a/git2.c b/git2.c index e6fdd1d50d..4456827b9d 100644 --- a/git2.c +++ b/git2.c @@ -35,6 +35,7 @@ extern void php_git2_reference_init(TSRMLS_D); extern void php_git2_config_init(TSRMLS_D); extern void php_git2_remote_init(TSRMLS_D); extern void php_git2_tag_init(TSRMLS_D); +extern void php_git2_odb_init(TSRMLS_D); int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...) @@ -155,6 +156,21 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ 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; + long *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; @@ -170,6 +186,22 @@ int php_git2_add_protected_property_string_ex(zval *object, char *name, int name 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) { @@ -187,6 +219,7 @@ PHP_MINIT_FUNCTION(git2) php_git2_config_init(TSRMLS_C); php_git2_remote_init(TSRMLS_C); php_git2_tag_init(TSRMLS_C); + php_git2_odb_init(TSRMLS_C); return SUCCESS; } diff --git a/odb.c b/odb.c new file mode 100644 index 0000000000..0fcbd753a7 --- /dev/null +++ b/odb.c @@ -0,0 +1,65 @@ +/* + * 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 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); + return retval; +} + +static zend_function_entry php_git2_odb_methods[] = { + //PHP_ME(git2_odb, __construct, NULL, ZEND_ACC_PUBLIC); + //PHP_ME(git2_odb, hash, NULL, ZEND_ACC_PUBLIC); + //PHP_ME(git2_odb, write, NULL, ZEND_ACC_PUBLIC); + //PHP_ME(git2_odb, exists, NULL, ZEND_ACC_PUBLIC); + //PHP_ME(git2_odb, read, NULL, ZEND_ACC_PUBLIC); + //PHP_ME(git2_odb, addAlternate, NULL, ZEND_ACC_PUBLIC); + //PHP_ME(git2_odb, addBackend, NULL, 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; +} \ No newline at end of file diff --git a/php_git2.h b/php_git2.h index cfdce8c63b..b45c4f6b4d 100644 --- a/php_git2.h +++ b/php_git2.h @@ -57,6 +57,7 @@ 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; typedef struct{ zend_object zo; @@ -133,6 +134,11 @@ typedef struct{ git_tag *tag; } php_git2_tag; +typedef struct{ + zend_object zo; + git_odb *odb; +} php_git2_odb; + # define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); @@ -165,7 +171,10 @@ typedef struct{ 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, ...); diff --git a/repository.c b/repository.c index c34784a55b..88cc2bfd6c 100644 --- a/repository.c +++ b/repository.c @@ -34,6 +34,7 @@ static void php_git2_repository_free_storage(php_git2_repository *object TSRMLS_ git_repository_free(object->repository); object->repository = NULL; } + zend_object_std_dtor(&object->zo TSRMLS_CC); efree(object); } @@ -89,6 +90,7 @@ PHP_METHOD(git2_repository, __construct) int repository_path_len, ret = 0; git_repository *repository; php_git2_repository *m_repository; + zval *odb; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &repository_path, &repository_path_len) == FAILURE) { @@ -101,10 +103,19 @@ PHP_METHOD(git2_repository, __construct) PHP_GIT2_EXCEPTION_CHECK(ret); m_repository->repository = repository; + MAKE_STD_ZVAL(odb); + object_init_ex(odb,git2_odb_class_entry); + php_git2_add_protected_property_string_ex(getThis(), - "path",sizeof("path"), + "path",sizeof("path")-1, git_repository_path(repository), 1 TSRMLS_CC); + + php_git2_add_protected_property_zval_ex(getThis(), + "odb",sizeof("odb")-1, + odb, + 1 TSRMLS_CC); + zval_ptr_dtor(&odb); } else { m_repository->repository = NULL; } @@ -478,5 +489,6 @@ void php_git2_repository_init(TSRMLS_D) memcpy(&git2_repository_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); git2_repository_object_handlers.clone_obj = NULL; + //git2_repository_object_handlers.read_property = php_git2_repository_read_property; } From 85e650d0a04b91194ad2f8574c9436ffcccd98ad Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 13:46:42 +0900 Subject: [PATCH 097/300] for now, added read property handler. this will change soon --- repository.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/repository.c b/repository.c index 88cc2bfd6c..f58079292a 100644 --- a/repository.c +++ b/repository.c @@ -28,6 +28,30 @@ PHPAPI zend_class_entry *git2_repository_class_entry; void php_git2_repository_init(TSRMLS_D); static zend_object_handlers git2_repository_object_handlers; + +static zval *php_git2_repository_read_property(zval *object, zval *member, int type TSRMLS_DC) +{ + zval *retval; + zval **data = NULL; + char *key, *prop_key = NULL; + int key_len, prop_key_len = 0; + + prop_key = Z_STRVAL_P(member); + prop_key_len = Z_STRLEN_P(member); + + zend_mangle_property_name(&key, &key_len, "*", 1, prop_key, prop_key_len, 0); + if (zend_hash_find(Z_OBJPROP_P(object),key,key_len,(void **)&data) != SUCCESS) { + retval = &EG(uninitialized_zval); + } else { + ALLOC_INIT_ZVAL(retval); + Z_SET_REFCOUNT_P(retval, 0); + ZVAL_ZVAL(retval,*data,1,0); + } + efree(key); + + return retval; +} + static void php_git2_repository_free_storage(php_git2_repository *object TSRMLS_DC) { if (object->repository != NULL) { @@ -489,6 +513,6 @@ void php_git2_repository_init(TSRMLS_D) memcpy(&git2_repository_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); git2_repository_object_handlers.clone_obj = NULL; - //git2_repository_object_handlers.read_property = php_git2_repository_read_property; + git2_repository_object_handlers.read_property = php_git2_repository_read_property; } From 13b5906b40b16fa4f783f32d2be4da78856bc044 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 22:59:12 +0900 Subject: [PATCH 098/300] improved repository initialize --- repository.c | 68 +++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/repository.c b/repository.c index f58079292a..3ddbea6eec 100644 --- a/repository.c +++ b/repository.c @@ -28,30 +28,6 @@ PHPAPI zend_class_entry *git2_repository_class_entry; void php_git2_repository_init(TSRMLS_D); static zend_object_handlers git2_repository_object_handlers; - -static zval *php_git2_repository_read_property(zval *object, zval *member, int type TSRMLS_DC) -{ - zval *retval; - zval **data = NULL; - char *key, *prop_key = NULL; - int key_len, prop_key_len = 0; - - prop_key = Z_STRVAL_P(member); - prop_key_len = Z_STRLEN_P(member); - - zend_mangle_property_name(&key, &key_len, "*", 1, prop_key, prop_key_len, 0); - if (zend_hash_find(Z_OBJPROP_P(object),key,key_len,(void **)&data) != SUCCESS) { - retval = &EG(uninitialized_zval); - } else { - ALLOC_INIT_ZVAL(retval); - Z_SET_REFCOUNT_P(retval, 0); - ZVAL_ZVAL(retval,*data,1,0); - } - efree(key); - - return retval; -} - static void php_git2_repository_free_storage(php_git2_repository *object TSRMLS_DC) { if (object->repository != NULL) { @@ -105,6 +81,28 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_lookup, 0,0,1) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() +static int php_git2_repository_initialize(zval *object, git_repository *repository TSRMLS_DC) +{ + zval *odb; + php_git2_repository *m_repository; + + 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); + php_git2_add_protected_property_string_ex(object, + "path",sizeof("path")-1, + git_repository_path(repository), + 1 TSRMLS_CC); + + php_git2_add_protected_property_zval_ex(object, + "odb",sizeof("odb")-1, + odb, + 1 TSRMLS_CC); + zval_ptr_dtor(&odb); +} + /* {{{ proto: Git2\Repsotiroy::__construct(string $path) */ @@ -121,25 +119,11 @@ PHP_METHOD(git2_repository, __construct) return; } - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); if (repository_path_len > 0) { ret = git_repository_open(&repository, repository_path); PHP_GIT2_EXCEPTION_CHECK(ret); - m_repository->repository = repository; - MAKE_STD_ZVAL(odb); - object_init_ex(odb,git2_odb_class_entry); - - php_git2_add_protected_property_string_ex(getThis(), - "path",sizeof("path")-1, - git_repository_path(repository), - 1 TSRMLS_CC); - - php_git2_add_protected_property_zval_ex(getThis(), - "odb",sizeof("odb")-1, - odb, - 1 TSRMLS_CC); - zval_ptr_dtor(&odb); + php_git2_repository_initialize(getThis(), repository TSRMLS_CC); } else { m_repository->repository = NULL; } @@ -255,12 +239,10 @@ PHP_METHOD(git2_repository, init) ret = git_repository_init(&repository, path, is_bare); if (ret == GIT_SUCCESS) { zval *object; - php_git2_repository *m_repository; MAKE_STD_ZVAL(object); object_init_ex(object, git2_repository_class_entry); - m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, object); - m_repository->repository = repository; + php_git2_repository_initialize(object, repository TSRMLS_CC); RETVAL_ZVAL(object,0,1); } else { @@ -513,6 +495,4 @@ void php_git2_repository_init(TSRMLS_D) memcpy(&git2_repository_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); git2_repository_object_handlers.clone_obj = NULL; - git2_repository_object_handlers.read_property = php_git2_repository_read_property; - } From 4e54d99d2e0d0e2e6db7dcd75f82b56203fb0fd3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 23:02:15 +0900 Subject: [PATCH 099/300] changed visibility for Git2\Repository->path and odb. these prop will be readonly --- repository.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/repository.c b/repository.c index 3ddbea6eec..d3eda35c51 100644 --- a/repository.c +++ b/repository.c @@ -91,15 +91,8 @@ static int php_git2_repository_initialize(zval *object, git_repository *reposito MAKE_STD_ZVAL(odb); object_init_ex(odb,git2_odb_class_entry); - php_git2_add_protected_property_string_ex(object, - "path",sizeof("path")-1, - git_repository_path(repository), - 1 TSRMLS_CC); - - php_git2_add_protected_property_zval_ex(object, - "odb",sizeof("odb")-1, - odb, - 1 TSRMLS_CC); + add_property_string(object, "path", git_repository_path(repository),1); + add_property_zval(object, "odb", odb); zval_ptr_dtor(&odb); } From cab692e1bc28ddd79389edddfefabf054be021e1 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 23:16:36 +0900 Subject: [PATCH 100/300] added Git2\Odb method templates --- odb.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++---- repository.c | 4 +++ 2 files changed, 94 insertions(+), 7 deletions(-) diff --git a/odb.c b/odb.c index 0fcbd753a7..46f53349a9 100644 --- a/odb.c +++ b/odb.c @@ -25,6 +25,7 @@ #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) { @@ -41,17 +42,96 @@ 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) +{ +} +/* }}} */ + +/* +{{{ proto: Git2\ODB::write(string $contents, int $type) +*/ +PHP_METHOD(git2_odb, write) +{ +} +/* }}} */ + +/* +{{{ proto: Git2\ODB::exists($oid) +*/ +PHP_METHOD(git2_odb, exists) +{ +} +/* }}} */ + +/* +{{{ proto: Git2\ODB::read($oid) +*/ +PHP_METHOD(git2_odb, read) +{ +} +/* }}} */ + + +/* +{{{ proto: Git2\ODB::addAlternate(Git2\Backend $backend, $priority) +*/ +PHP_METHOD(git2_odb, addAlternate) +{ +} +/* }}} */ + +/* +{{{ proto: Git2\ODB::addBackend(Git2\Backend $backend, $priority) +*/ +PHP_METHOD(git2_odb, addBackend) +{ +} +/* }}} */ + + static zend_function_entry php_git2_odb_methods[] = { - //PHP_ME(git2_odb, __construct, NULL, ZEND_ACC_PUBLIC); - //PHP_ME(git2_odb, hash, NULL, ZEND_ACC_PUBLIC); - //PHP_ME(git2_odb, write, NULL, ZEND_ACC_PUBLIC); - //PHP_ME(git2_odb, exists, NULL, ZEND_ACC_PUBLIC); - //PHP_ME(git2_odb, read, NULL, ZEND_ACC_PUBLIC); - //PHP_ME(git2_odb, addAlternate, NULL, ZEND_ACC_PUBLIC); - //PHP_ME(git2_odb, addBackend, NULL, ZEND_ACC_PUBLIC); + 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) + PHP_ME(git2_odb, addAlternate, arginfo_git2_odb_add_alternate, ZEND_ACC_PUBLIC) + PHP_ME(git2_odb, addBackend, arginfo_git2_odb_add_backend, ZEND_ACC_PUBLIC) {NULL,NULL,NULL} }; @@ -62,4 +142,7 @@ void php_git2_odb_init(TSRMLS_D) 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/repository.c b/repository.c index d3eda35c51..194daf1204 100644 --- a/repository.c +++ b/repository.c @@ -85,12 +85,16 @@ static int php_git2_repository_initialize(zval *object, git_repository *reposito { 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); From ca1776d9f60c4e33b9401b583eb188149742587e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 30 Jan 2012 23:52:54 +0900 Subject: [PATCH 101/300] for now, testing Git2\ODB::read() method. this method will return Git2\Raw object. --- odb.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/odb.c b/odb.c index 46f53349a9..4588775338 100644 --- a/odb.c +++ b/odb.c @@ -104,6 +104,28 @@ PHP_METHOD(git2_odb, exists) */ PHP_METHOD(git2_odb, read) { + char *hash; + int error, hash_len = 0; + git_odb *odb; + git_oid id; + git_odb_object *object; + 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_SUCCESS) { + RETURN_FALSE; + } + + error = git_odb_read(&object,m_odb->odb, &id); + PHP_GIT2_EXCEPTION_CHECK(error); + + fprintf(stderr,"%s",git_odb_object_data(object)); + } /* }}} */ From 0848dde6d784ad1c3f727f0afc0cebfeaf932349 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 31 Jan 2012 23:45:06 +0900 Subject: [PATCH 102/300] added Git2\Raw --- config.m4 | 1 + git2.c | 1 + odb.c | 10 +++- php_git2.h | 6 +++ raw.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 raw.c diff --git a/config.m4 b/config.m4 index ad414a7bb5..528090efd1 100644 --- a/config.m4 +++ b/config.m4 @@ -45,6 +45,7 @@ if test $PHP_GIT2 != "no"; then remote.c \ tag.c \ odb.c \ + raw.c \ , $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], diff --git a/git2.c b/git2.c index 4456827b9d..06c3efe93e 100644 --- a/git2.c +++ b/git2.c @@ -220,6 +220,7 @@ PHP_MINIT_FUNCTION(git2) php_git2_remote_init(TSRMLS_C); php_git2_tag_init(TSRMLS_C); php_git2_odb_init(TSRMLS_C); + php_git2_raw_init(TSRMLS_C); return SUCCESS; } diff --git a/odb.c b/odb.c index 4588775338..cc0cb30fb6 100644 --- a/odb.c +++ b/odb.c @@ -109,7 +109,9 @@ PHP_METHOD(git2_odb, read) git_odb *odb; git_oid id; git_odb_object *object; + zval *raw; php_git2_odb *m_odb; + php_git2_raw *m_raw; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE) { @@ -123,9 +125,13 @@ PHP_METHOD(git2_odb, read) error = git_odb_read(&object,m_odb->odb, &id); PHP_GIT2_EXCEPTION_CHECK(error); - - fprintf(stderr,"%s",git_odb_object_data(object)); + MAKE_STD_ZVAL(raw); + object_init_ex(raw, git2_raw_class_entry); + m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw, raw); + m_raw->object = object; + + RETVAL_ZVAL(raw, 0, 1); } /* }}} */ diff --git a/php_git2.h b/php_git2.h index b45c4f6b4d..c7cce90049 100644 --- a/php_git2.h +++ b/php_git2.h @@ -58,6 +58,7 @@ 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_raw_class_entry; typedef struct{ zend_object zo; @@ -139,6 +140,11 @@ typedef struct{ git_odb *odb; } php_git2_odb; +typedef struct{ + zend_object zo; + git_odb_object *object; +} php_git2_raw; + # define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); diff --git a/raw.c b/raw.c new file mode 100644 index 0000000000..1bca02df03 --- /dev/null +++ b/raw.c @@ -0,0 +1,139 @@ +/* + * 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_raw_class_entry; +static zend_object_handlers git2_raw_object_handlers; + +static void php_git2_raw_free_storage(php_git2_raw *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_raw_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + + PHP_GIT2_STD_CREATE_OBJECT(php_git2_raw); + retval.handlers = &git2_raw_object_handlers; + return retval; +} + +static int php_git2_raw_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) +{ + zval *retval; + zend_class_entry *ce; + php_git2_raw *m_raw; + + switch (type) { + case IS_STRING: + m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw, 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_raw, getContent) +{ + php_git2_raw *m_raw; + git_otype type; + + m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw,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_raw, getType) +{ + php_git2_raw *m_raw; + git_otype type; + + m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw,getThis()); + + type = git_odb_object_type(m_raw->object); + RETURN_LONG(type); +} +/* }}} */ + + +static zend_function_entry php_git2_raw_methods[] = { + PHP_ME(git2_raw, getContent, NULL, ZEND_ACC_PUBLIC) + PHP_ME(git2_raw, getType, NULL, ZEND_ACC_PUBLIC) + {NULL,NULL,NULL} +}; + +void php_git2_raw_init(TSRMLS_D) +{ + zend_class_entry ce; + + INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Raw", php_git2_raw_methods); + git2_raw_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + git2_raw_class_entry->create_object = php_git2_raw_new; + + memcpy(&git2_raw_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + git2_raw_object_handlers.clone_obj = NULL; + git2_raw_object_handlers.cast_object = php_git2_raw_cast_object_tostring; +} \ No newline at end of file From 356a4658af0361f3cf49f17cb9bcd521f95eeec6 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 00:05:06 +0900 Subject: [PATCH 103/300] added Git2\Backend --- backend.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.m4 | 1 + git2.c | 1 + php_git2.h | 6 +++++ 4 files changed, 82 insertions(+) create mode 100644 backend.c diff --git a/backend.c b/backend.c new file mode 100644 index 0000000000..de6c938af9 --- /dev/null +++ b/backend.c @@ -0,0 +1,74 @@ +/* + * 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_backend_class_entry; +static zend_object_handlers git2_backend_object_handlers; + +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_STD_CREATE_OBJECT(php_git2_backend); + retval.handlers = &git2_backend_object_handlers; + return retval; +} + +static zend_function_entry php_git2_backend_methods[] = { + //int (* read)(void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *); + //PHP_ME(git2_backend, read, arginfo_git2_backend_read, ZEND_ACC_PUBLIC) + //int (* read_prefix)(git_oid *,void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *,unsigned int); + //PHP_ME(git2_backend, readPrefix, arginfo_git2_backend_read_prefix, ZEND_ACC_PUBLIC) + //int (* read_header)(size_t *, git_otype *,struct git_odb_backend *,const git_oid *); + //PHP_ME(git2_backend, readHeader, arginfo_git2_backend_read_header, ZEND_ACC_PUBLIC) + //int (* write)(git_oid *,struct git_odb_backend *,const void *,size_t,git_otype); + //PHP_ME(git2_backend, write, arginfo_git2_backend_write, ZEND_ACC_PUBLIC) + //int (* exists)(struct git_odb_backend *,const git_oid *); + //PHP_ME(git2_backend, exists, arginfo_git2_backend_exists, ZEND_ACC_PUBLIC) + //void (* free)(struct git_odb_backend *); + //PHP_ME(git2_backend, free, arginfo_git2_backend_free, ZEND_ACC_PUBLIC) + {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/config.m4 b/config.m4 index 528090efd1..c27ad783e4 100644 --- a/config.m4 +++ b/config.m4 @@ -46,6 +46,7 @@ if test $PHP_GIT2 != "no"; then tag.c \ odb.c \ raw.c \ + backend.c \ , $ext_shared) ifdef([PHP_ADD_EXTENSION_DEP], diff --git a/git2.c b/git2.c index 06c3efe93e..685539ec2d 100644 --- a/git2.c +++ b/git2.c @@ -221,6 +221,7 @@ PHP_MINIT_FUNCTION(git2) php_git2_tag_init(TSRMLS_C); php_git2_odb_init(TSRMLS_C); php_git2_raw_init(TSRMLS_C); + php_git2_backend_init(TSRMLS_C); return SUCCESS; } diff --git a/php_git2.h b/php_git2.h index c7cce90049..09ef4c37f9 100644 --- a/php_git2.h +++ b/php_git2.h @@ -59,6 +59,7 @@ 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_raw_class_entry; +extern PHPAPI zend_class_entry *git2_backend_class_entry; typedef struct{ zend_object zo; @@ -145,6 +146,11 @@ typedef struct{ git_odb_object *object; } php_git2_raw; +typedef struct{ + zend_object zo; + git_odb_backend *backend; +} php_git2_backend; + # define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); From 0d1b66f3d6e261de33b0a9c85003011b24fa3a6d Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 00:42:24 +0900 Subject: [PATCH 104/300] rename Git2\ODBObject from Git2\Raw --- config.m4 | 2 +- git2.c | 3 ++- odb.c | 8 +++---- raw.c => odb_object.c | 50 +++++++++++++++++++++---------------------- php_git2.h | 4 ++-- 5 files changed, 34 insertions(+), 33 deletions(-) rename raw.c => odb_object.c (63%) diff --git a/config.m4 b/config.m4 index c27ad783e4..0e8e06b953 100644 --- a/config.m4 +++ b/config.m4 @@ -45,7 +45,7 @@ if test $PHP_GIT2 != "no"; then remote.c \ tag.c \ odb.c \ - raw.c \ + odb_object.c \ backend.c \ , $ext_shared) diff --git a/git2.c b/git2.c index 685539ec2d..db310606f8 100644 --- a/git2.c +++ b/git2.c @@ -36,6 +36,7 @@ extern void php_git2_config_init(TSRMLS_D); extern void php_git2_remote_init(TSRMLS_D); extern void php_git2_tag_init(TSRMLS_D); extern void php_git2_odb_init(TSRMLS_D); +extern void php_git2_odb_object_init(TSRMLS_D); int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, unsigned int method_len, unsigned int param_count, ...) @@ -220,7 +221,7 @@ PHP_MINIT_FUNCTION(git2) php_git2_remote_init(TSRMLS_C); php_git2_tag_init(TSRMLS_C); php_git2_odb_init(TSRMLS_C); - php_git2_raw_init(TSRMLS_C); + php_git2_odb_object_init(TSRMLS_C); php_git2_backend_init(TSRMLS_C); return SUCCESS; diff --git a/odb.c b/odb.c index cc0cb30fb6..8bc3dd3b25 100644 --- a/odb.c +++ b/odb.c @@ -111,7 +111,7 @@ PHP_METHOD(git2_odb, read) git_odb_object *object; zval *raw; php_git2_odb *m_odb; - php_git2_raw *m_raw; + php_git2_odb_object *m_odb_object; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE) { @@ -127,9 +127,9 @@ PHP_METHOD(git2_odb, read) PHP_GIT2_EXCEPTION_CHECK(error); MAKE_STD_ZVAL(raw); - object_init_ex(raw, git2_raw_class_entry); - m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw, raw); - m_raw->object = object; + 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); } diff --git a/raw.c b/odb_object.c similarity index 63% rename from raw.c rename to odb_object.c index 1bca02df03..079c906b5c 100644 --- a/raw.c +++ b/odb_object.c @@ -24,10 +24,10 @@ #include "php_git2.h" -PHPAPI zend_class_entry *git2_raw_class_entry; -static zend_object_handlers git2_raw_object_handlers; +PHPAPI zend_class_entry *git2_odb_object_class_entry; +static zend_object_handlers git2_odb_object_object_handlers; -static void php_git2_raw_free_storage(php_git2_raw *object TSRMLS_DC) +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); @@ -37,24 +37,24 @@ static void php_git2_raw_free_storage(php_git2_raw *object TSRMLS_DC) efree(object); } -zend_object_value php_git2_raw_new(zend_class_entry *ce TSRMLS_DC) +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_raw); - retval.handlers = &git2_raw_object_handlers; + PHP_GIT2_STD_CREATE_OBJECT(php_git2_odb_object); + retval.handlers = &git2_odb_object_object_handlers; return retval; } -static int php_git2_raw_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) +static int php_git2_odb_object_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) { zval *retval; zend_class_entry *ce; - php_git2_raw *m_raw; + php_git2_odb_object *m_raw; switch (type) { case IS_STRING: - m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw, readobj); + 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; @@ -92,12 +92,12 @@ static int php_git2_raw_cast_object_tostring(zval *readobj, zval *writeobj, int /* {{{ proto: Git2\raw::getContent() */ -PHP_METHOD(git2_raw, getContent) +PHP_METHOD(git2_odb_object, getContent) { - php_git2_raw *m_raw; + php_git2_odb_object *m_raw; git_otype type; - m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw,getThis()); + 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); } /* }}} */ @@ -106,12 +106,12 @@ PHP_METHOD(git2_raw, getContent) /* {{{ proto: Git2\raw::getType() */ -PHP_METHOD(git2_raw, getType) +PHP_METHOD(git2_odb_object, getType) { - php_git2_raw *m_raw; + php_git2_odb_object *m_raw; git_otype type; - m_raw = PHP_GIT2_GET_OBJECT(php_git2_raw,getThis()); + m_raw = PHP_GIT2_GET_OBJECT(php_git2_odb_object,getThis()); type = git_odb_object_type(m_raw->object); RETURN_LONG(type); @@ -119,21 +119,21 @@ PHP_METHOD(git2_raw, getType) /* }}} */ -static zend_function_entry php_git2_raw_methods[] = { - PHP_ME(git2_raw, getContent, NULL, ZEND_ACC_PUBLIC) - PHP_ME(git2_raw, getType, NULL, ZEND_ACC_PUBLIC) +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_raw_init(TSRMLS_D) +void php_git2_odb_object_init(TSRMLS_D) { zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_GIT2_NS, "Raw", php_git2_raw_methods); - git2_raw_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - git2_raw_class_entry->create_object = php_git2_raw_new; + 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_raw_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - git2_raw_object_handlers.clone_obj = NULL; - git2_raw_object_handlers.cast_object = php_git2_raw_cast_object_tostring; + 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 index 09ef4c37f9..ea3ec290e5 100644 --- a/php_git2.h +++ b/php_git2.h @@ -58,7 +58,7 @@ 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_raw_class_entry; +extern PHPAPI zend_class_entry *git2_odb_object_class_entry; extern PHPAPI zend_class_entry *git2_backend_class_entry; typedef struct{ @@ -144,7 +144,7 @@ typedef struct{ typedef struct{ zend_object zo; git_odb_object *object; -} php_git2_raw; +} php_git2_odb_object; typedef struct{ zend_object zo; From 658a9dc785f3065fd1b8819c29ed406e67fa3892 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 07:39:21 +0900 Subject: [PATCH 105/300] set backend callback --- backend.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++-------- php_git2.h | 4 +++ 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/backend.c b/backend.c index de6c938af9..e5debce4fd 100644 --- a/backend.c +++ b/backend.c @@ -27,6 +27,25 @@ 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) +{ +} +static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type) +{ +} +static int php_git2_backend_read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id) +{ +} +static int php_git2_backend_read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id) +{ +} +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,unsigned int length) +{ +} +static void php_git2_backend_free(git_odb_backend *backend) +{ +} + static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) { if (object->backend != NULL) { @@ -39,25 +58,65 @@ static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC) { zend_object_value retval; + php_git2_backend *m_backend; + php_git2_backend_internal *internal; PHP_GIT2_STD_CREATE_OBJECT(php_git2_backend); + + internal = ecalloc(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; + + m_backend->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,2) + 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() + static zend_function_entry php_git2_backend_methods[] = { - //int (* read)(void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *); - //PHP_ME(git2_backend, read, arginfo_git2_backend_read, ZEND_ACC_PUBLIC) - //int (* read_prefix)(git_oid *,void **, size_t *, git_otype *,struct git_odb_backend *,const git_oid *,unsigned int); - //PHP_ME(git2_backend, readPrefix, arginfo_git2_backend_read_prefix, ZEND_ACC_PUBLIC) - //int (* read_header)(size_t *, git_otype *,struct git_odb_backend *,const git_oid *); - //PHP_ME(git2_backend, readHeader, arginfo_git2_backend_read_header, ZEND_ACC_PUBLIC) - //int (* write)(git_oid *,struct git_odb_backend *,const void *,size_t,git_otype); - //PHP_ME(git2_backend, write, arginfo_git2_backend_write, ZEND_ACC_PUBLIC) - //int (* exists)(struct git_odb_backend *,const git_oid *); - //PHP_ME(git2_backend, exists, arginfo_git2_backend_exists, ZEND_ACC_PUBLIC) - //void (* free)(struct git_odb_backend *); - //PHP_ME(git2_backend, free, arginfo_git2_backend_free, 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} }; diff --git a/php_git2.h b/php_git2.h index ea3ec290e5..da6828c712 100644 --- a/php_git2.h +++ b/php_git2.h @@ -151,6 +151,10 @@ typedef struct{ git_odb_backend *backend; } php_git2_backend; +typedef struct{ + git_odb_backend parent; +} php_git2_backend_internal; + # define PHP_GIT2_GET_OBJECT(STRUCT_NAME, OBJECT) (STRUCT_NAME *) zend_object_store_get_object(OBJECT TSRMLS_CC); From 11f641df0b1097e2267d104e85d7370eb7bec607 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 08:19:54 +0900 Subject: [PATCH 106/300] declare variables for backend callback --- backend.c | 40 ++++++++++++++++++++++++++++++++++++++-- php_git2.h | 1 + 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index e5debce4fd..78d1f32e3f 100644 --- a/backend.c +++ b/backend.c @@ -27,23 +27,59 @@ 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) +static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid) { + TSRMLS_FETCH(); + zval *retval, *param; + php_git2_backend_internal *backend; + + MAKE_STD_ZVAL(param); + MAKE_STD_ZVAL(retval); + backend = (php_git2_backend_internal *)_backend; + + zend_call_method_with_1_params(&backend->self, git2_backend_class_entry, NULL, "exists", &retval, param); + + zval_ptr_dotr(¶m); + zval_ptr_dotr(&retval); + + return GIT_SUCCESS; } + static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type) { + TSRMLS_FETCH(); + php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; + + return GIT_SUCCESS; } + static int php_git2_backend_read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id) { + TSRMLS_FETCH(); + php_git2_backend_internal *backend; + return GIT_SUCCESS; } + static int php_git2_backend_read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id) { + TSRMLS_FETCH(); + php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; + + return GIT_SUCCESS; } + 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,unsigned int length) { + TSRMLS_FETCH(); + php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; + + return GIT_SUCCESS; } -static void php_git2_backend_free(git_odb_backend *backend) + +static void php_git2_backend_free(git_odb_backend *_backend) { + TSRMLS_FETCH(); + php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; } static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) diff --git a/php_git2.h b/php_git2.h index da6828c712..49e3f9e4ee 100644 --- a/php_git2.h +++ b/php_git2.h @@ -153,6 +153,7 @@ typedef struct{ typedef struct{ git_odb_backend parent; + zval *self; } php_git2_backend_internal; From dbbef1a5b6278709a17ba001b9a4268e5fd2e550 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 12:43:34 +0900 Subject: [PATCH 107/300] added Git2\ODB::exists and hash --- odb.c | 42 ++++++++++++++++++++++++++++++++++++ tests/00b-01-odb_hash.phpt | 23 ++++++++++++++++++++ tests/00b-02-odb_exists.phpt | 23 ++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 tests/00b-01-odb_hash.phpt create mode 100644 tests/00b-02-odb_exists.phpt diff --git a/odb.c b/odb.c index 8bc3dd3b25..c14647c829 100644 --- a/odb.c +++ b/odb.c @@ -80,6 +80,26 @@ ZEND_END_ARG_INFO() */ PHP_METHOD(git2_odb, 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_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); } /* }}} */ @@ -96,6 +116,28 @@ PHP_METHOD(git2_odb, write) */ PHP_METHOD(git2_odb, exists) { + char *hash; + int error, hash_len = 0; + git_odb *odb; + 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_SUCCESS) { + RETURN_FALSE; + } + + if (git_odb_exists(m_odb->odb, &id) == 1) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } } /* }}} */ diff --git a/tests/00b-01-odb_hash.phpt b/tests/00b-01-odb_hash.phpt new file mode 100644 index 0000000000..72e34b110e --- /dev/null +++ b/tests/00b-01-odb_hash.phpt @@ -0,0 +1,23 @@ +--TEST-- +Check for Git2\ODB::hash +--SKIPIF-- + +--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 new file mode 100644 index 0000000000..6819adfd43 --- /dev/null +++ b/tests/00b-02-odb_exists.phpt @@ -0,0 +1,23 @@ +--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 From 70d2db57e9017a0fc41f1e9dac4162746fcf20e4 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 12:46:28 +0900 Subject: [PATCH 108/300] added Git2\ODB::write method --- odb.c | 27 +++++++++++++++++++++++++++ tests/00b-03-odb_write.phpt | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/00b-03-odb_write.phpt diff --git a/odb.c b/odb.c index c14647c829..da28147c76 100644 --- a/odb.c +++ b/odb.c @@ -108,6 +108,33 @@ PHP_METHOD(git2_odb, hash) */ PHP_METHOD(git2_odb, 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_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); } /* }}} */ diff --git a/tests/00b-03-odb_write.phpt b/tests/00b-03-odb_write.phpt new file mode 100644 index 0000000000..7f28b9573b --- /dev/null +++ b/tests/00b-03-odb_write.phpt @@ -0,0 +1,22 @@ +--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 From ec1a7c135a11e5d883dd9bb57a23fd154989ca21 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 12:53:26 +0900 Subject: [PATCH 109/300] improve readme --- README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c604659272..e77641b358 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,6 @@ $parent = Git2\Commit::create($repo, array( "tree" => $tree, "parents" => $parents, )); -$parents = array($parent); ```` ## Revision Walking @@ -153,12 +152,30 @@ $config['core.bare'] $config['core.bare'] = 1; ```` +## ODB operation + +```` +$repo = Git2\Repository::init("/path/to/repo",true); +$odb = $repo->odb // read only property +string $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 +## Remote access (Experimental) -will be add. +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 From 3dc224b2019bceb9c7db69f9707680b46ed3b0f9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 13:07:56 +0900 Subject: [PATCH 110/300] added Git2\ODB::addBackend --- backend.c | 7 ++++++- odb.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/backend.c b/backend.c index 78d1f32e3f..73723cfd35 100644 --- a/backend.c +++ b/backend.c @@ -32,6 +32,7 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid TSRMLS_FETCH(); zval *retval, *param; php_git2_backend_internal *backend; + int result = GIT_ERROR; MAKE_STD_ZVAL(param); MAKE_STD_ZVAL(retval); @@ -39,10 +40,14 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid zend_call_method_with_1_params(&backend->self, git2_backend_class_entry, NULL, "exists", &retval, param); + if (Z_BVAL_P(retval)) { + result = GIT_SUCCESS; + } + zval_ptr_dotr(¶m); zval_ptr_dotr(&retval); - return GIT_SUCCESS; + return result; } static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type) diff --git a/odb.c b/odb.c index da28147c76..b4802689ea 100644 --- a/odb.c +++ b/odb.c @@ -218,6 +218,24 @@ PHP_METHOD(git2_odb, addAlternate) */ PHP_METHOD(git2_odb, addBackend) { + zval *backend = NULL; + php_git2_backend *m_backend; + php_git2_odb *m_odb; + long priority = 5; + int error = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "Ol", &backend, git2_backend_class_entry, &priority) == FAILURE) { + return; + } + + m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); + m_backend = PHP_GIT2_GET_OBJECT(php_git2_backend, backend); + + error = git_odb_add_backend(m_odb->odb, m_backend->backend, priority); + PHP_GIT2_EXCEPTION_CHECK(error); + + RETURN_TRUE; } /* }}} */ From 327c51f7ab4e018b8bf1818a97d392736ca7ef9b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 13:08:05 +0900 Subject: [PATCH 111/300] remove unnessesary fprintf --- php_git2.h | 1 - 1 file changed, 1 deletion(-) diff --git a/php_git2.h b/php_git2.h index 49e3f9e4ee..1241bb29dc 100644 --- a/php_git2.h +++ b/php_git2.h @@ -285,7 +285,6 @@ static inline void php_git2_exception_check(int errorcode TSRMLS_DC) { if (errorcode < 0) { zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%s\n(error code %d)", git_lasterror(), errorcode); - fprintf(stderr,"moe"); git_clearerror(); return; } From 6c856ae55c0a0ceab3942ed17a062515ed62a9dc Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 13:19:05 +0900 Subject: [PATCH 112/300] fixed leak --- backend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend.c b/backend.c index 73723cfd35..d70ba74e78 100644 --- a/backend.c +++ b/backend.c @@ -90,6 +90,7 @@ static void php_git2_backend_free(git_odb_backend *_backend) static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) { if (object->backend != NULL) { + efree(object->backend); object->backend = NULL; } zend_object_std_dtor(&object->zo TSRMLS_CC); @@ -99,7 +100,6 @@ static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC) { zend_object_value retval; - php_git2_backend *m_backend; php_git2_backend_internal *internal; PHP_GIT2_STD_CREATE_OBJECT(php_git2_backend); @@ -112,7 +112,7 @@ zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC) internal->parent.exists = &php_git2_backend_exists; internal->parent.free = &php_git2_backend_free; - m_backend->backend = internal; + object->backend = internal; retval.handlers = &git2_backend_object_handlers; @@ -134,7 +134,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_read_header, 0,0,2) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_backend_write, 0,0,2) +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) From 66081ebb3fb8bbd2138c85e218ce100f51262510 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 13:24:44 +0900 Subject: [PATCH 113/300] added missing header file --- backend.c | 1 + 1 file changed, 1 insertion(+) diff --git a/backend.c b/backend.c index d70ba74e78..52b09a105a 100644 --- a/backend.c +++ b/backend.c @@ -23,6 +23,7 @@ */ #include "php_git2.h" +#include PHPAPI zend_class_entry *git2_backend_class_entry; static zend_object_handlers git2_backend_object_handlers; From 1f986812809d4a805ed7edae7e176f7c8a643b46 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 14:22:11 +0900 Subject: [PATCH 114/300] implemented callback for Git2\Backend::exists --- backend.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/backend.c b/backend.c index 52b09a105a..fe57a507fa 100644 --- a/backend.c +++ b/backend.c @@ -32,21 +32,21 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid { TSRMLS_FETCH(); zval *retval, *param; - php_git2_backend_internal *backend; + php_git2_backend_internal *m_backend; int result = GIT_ERROR; MAKE_STD_ZVAL(param); - MAKE_STD_ZVAL(retval); - backend = (php_git2_backend_internal *)_backend; + m_backend = (php_git2_backend_internal*)_backend; + - zend_call_method_with_1_params(&backend->self, git2_backend_class_entry, NULL, "exists", &retval, param); + 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_SUCCESS; } - zval_ptr_dotr(¶m); - zval_ptr_dotr(&retval); + zval_ptr_dtor(¶m); + zval_ptr_dtor(&retval); return result; } @@ -112,7 +112,8 @@ zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC) internal->parent.write = &php_git2_backend_write; internal->parent.exists = &php_git2_backend_exists; internal->parent.free = &php_git2_backend_free; - + internal->self = &retval; + object->backend = internal; retval.handlers = &git2_backend_object_handlers; @@ -146,7 +147,23 @@ 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; + m_internal->self = getThis(); +} +/* }}} */ + 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); */ From 919186b0d6c7b0b4c53c0ada48a4101e86a8955b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 17:41:39 +0900 Subject: [PATCH 115/300] fixed compiler warnings --- backend.c | 10 +++++----- commit.c | 7 ++++--- git2.c | 12 ++++++------ index.c | 2 +- odb.c | 4 ++-- php_git2.h | 2 +- reference.c | 2 +- remote.c | 2 +- repository.c | 4 ++-- tree.c | 4 ++-- 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/backend.c b/backend.c index fe57a507fa..f68174695c 100644 --- a/backend.c +++ b/backend.c @@ -59,14 +59,15 @@ static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const return GIT_SUCCESS; } -static int php_git2_backend_read(void **buffer,size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id) +static int php_git2_backend_read(void **buffer,size_t *size, git_otype *type, git_odb_backend *_backend, const git_oid *id) { TSRMLS_FETCH(); php_git2_backend_internal *backend; return GIT_SUCCESS; } -static int php_git2_backend_read_header(size_t size, git_otype *type, git_odb_backend *_backend, const git_oid *id) + +static int php_git2_backend_read_header(size_t *size, git_otype *type, git_odb_backend *_backend, const git_oid *id) { TSRMLS_FETCH(); php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; @@ -82,7 +83,7 @@ static int php_git2_backend_read_prefix(git_oid *id,void ** buffer, size_t * siz return GIT_SUCCESS; } -static void php_git2_backend_free(git_odb_backend *_backend) +static void php_git2_backend_free(struct git_odb_backend *_backend) { TSRMLS_FETCH(); php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; @@ -112,9 +113,8 @@ zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC) internal->parent.write = &php_git2_backend_write; internal->parent.exists = &php_git2_backend_exists; internal->parent.free = &php_git2_backend_free; - internal->self = &retval; - object->backend = internal; + object->backend = (struct git_odb_backend*)internal; retval.handlers = &git2_backend_object_handlers; diff --git a/commit.c b/commit.c index edb525ff5e..e4ae9f0690 100644 --- a/commit.c +++ b/commit.c @@ -257,7 +257,7 @@ PHP_METHOD(git2_commit, create) if (zend_hash_find(hash,"ref",sizeof("ref"),(void **)&value_pp) != FAILURE) { ref = emalloc(sizeof(char)*Z_STRLEN_PP(value_pp)+1); - sprintf(ref, Z_STRVAL_PP(value_pp)); + sprintf(ref, "%s", Z_STRVAL_PP(value_pp)); } else { ref = emalloc(sizeof(char)*5); sprintf(ref,"HEAD"); @@ -272,7 +272,7 @@ PHP_METHOD(git2_commit, create) if (zend_hash_find(hash,"encoding",sizeof("encoding"),(void **)&value_pp) != FAILURE) { encoding = emalloc(sizeof(char)*Z_STRLEN_PP(value_pp)+1); - sprintf(encoding, Z_STRVAL_PP(value_pp)); + sprintf(encoding, "%s",Z_STRVAL_PP(value_pp)); } else { encoding = emalloc(sizeof(char)*6); sprintf(encoding,"UTF-8"); @@ -339,7 +339,8 @@ PHP_METHOD(git2_commit, create) PHP_METHOD(git2_commit, getTree) { php_git2_commit *m_commit; - git_oid *oid, *id; + const git_oid *oid; + git_oid *id; git_otype type = GIT_OBJ_TREE; git_object *object; zval *result; diff --git a/git2.c b/git2.c index db310606f8..3d9eff22e0 100644 --- a/git2.c +++ b/git2.c @@ -113,7 +113,7 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ } case GIT_OBJ_TREE: { php_git2_tree *m_obj = NULL; - unsigned int *numbers = 0; + unsigned int numbers = 0; int i = 0; zval *m_array; @@ -127,7 +127,7 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ for (i = 0;i < numbers; i++) { const char *entry_name = {0}; - const char entry_oid[GIT_OID_HEXSZ+1] = {0}; + char entry_oid[GIT_OID_HEXSZ+1] = {0}; const git_tree_entry *entry; const git_oid *oid = NULL; zval *m_entry = NULL; @@ -139,9 +139,9 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ MAKE_STD_ZVAL(m_entry); object_init_ex(m_entry, git2_tree_entry_class_entry); - add_property_stringl_ex(m_entry, "name", sizeof("name"), entry_name, strlen(entry_name), 1 TSRMLS_CC); - add_property_stringl_ex(m_entry, "oid", sizeof("oid"), 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_stringl_ex(m_entry, "name", sizeof("name")-1, (const char *)entry_name, strlen(entry_name), 1 TSRMLS_CC); + add_property_stringl_ex(m_entry, "oid", sizeof("oid")-1, (const char *)entry_oid, strlen(entry_oid), 1 TSRMLS_CC); + add_property_long_ex(m_entry, "attributes", sizeof("attributes")-1, git_tree_entry_attributes(entry) TSRMLS_CC); add_next_index_zval(m_array, m_entry); } @@ -161,7 +161,7 @@ zval* php_git_read_protected_property(zend_class_entry *scope, zval *object, cha { zval **data; char *key; - long *length; + 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) { diff --git a/index.c b/index.c index e56b906d1c..a0cef31489 100644 --- a/index.c +++ b/index.c @@ -122,7 +122,7 @@ PHP_METHOD(git2_index, current) RETURN_FALSE; } - php_git2_create_index_entry(&z_entry, entry TSRMLS_CC); + php_git2_create_index_entry(&z_entry, (git_index_entry *)entry TSRMLS_CC); RETURN_ZVAL(z_entry, 0, 1); } diff --git a/odb.c b/odb.c index b4802689ea..800f6cec49 100644 --- a/odb.c +++ b/odb.c @@ -85,7 +85,7 @@ PHP_METHOD(git2_odb, hash) long type = 0; git_odb *odb; git_oid oid; - char *oid_out[GIT_OID_HEXSZ+1]; + char oid_out[GIT_OID_HEXSZ+1]; int error = 0; php_git2_odb *m_odb; @@ -114,7 +114,7 @@ PHP_METHOD(git2_odb, write) git_odb_stream *stream; git_odb *odb; git_oid oid; - char *oid_out[GIT_OID_HEXSZ+1]; + char oid_out[GIT_OID_HEXSZ+1]; int error = 0; php_git2_odb *m_odb; diff --git a/php_git2.h b/php_git2.h index 1241bb29dc..087853e304 100644 --- a/php_git2.h +++ b/php_git2.h @@ -148,7 +148,7 @@ typedef struct{ typedef struct{ zend_object zo; - git_odb_backend *backend; + struct git_odb_backend *backend; } php_git2_backend; typedef struct{ diff --git a/reference.c b/reference.c index d90101f515..c1aaa22fe0 100644 --- a/reference.c +++ b/reference.c @@ -99,7 +99,7 @@ PHP_METHOD(git2_reference, getTarget) m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); if (git_reference_type(m_reference->reference) == GIT_REF_OID) { - git_oid *oid; + const git_oid *oid; char oid_out[GIT_OID_HEXSZ] = {0}; oid = git_reference_oid(m_reference->reference); diff --git a/remote.c b/remote.c index 60ea27eb94..924ccc5770 100644 --- a/remote.c +++ b/remote.c @@ -129,7 +129,7 @@ PHP_METHOD(git2_remote, fetch) int error = 0; long direction = 0; - m_remote = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); + m_remote = PHP_GIT2_GET_OBJECT(php_git2_remote, getThis()); /* if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/repository.c b/repository.c index 194daf1204..cf01a9a3a2 100644 --- a/repository.c +++ b/repository.c @@ -400,7 +400,7 @@ PHP_METHOD(git2_repository, write) git_odb_stream *stream; git_odb *odb; git_oid oid; - char *oid_out[GIT_OID_HEXSZ+1]; + char oid_out[GIT_OID_HEXSZ+1]; int error = 0; php_git2_repository *m_repository; @@ -437,7 +437,7 @@ PHP_METHOD(git2_repository, hash) long type = 0; git_odb *odb; git_oid oid; - char *oid_out[GIT_OID_HEXSZ+1]; + char oid_out[GIT_OID_HEXSZ+1]; int error = 0; php_git2_repository *m_repository; diff --git a/tree.c b/tree.c index 1abc857601..53d1fb99c6 100644 --- a/tree.c +++ b/tree.c @@ -91,7 +91,7 @@ PHP_METHOD(git2_tree, diff) m_old = PHP_GIT2_GET_OBJECT(php_git2_tree, old); m_new = PHP_GIT2_GET_OBJECT(php_git2_tree, new); - git_tree_diff(git_tree_id(m_old->tree),git_tree_id(m_new->tree), &php_git2_tree_diff_cb, &payload); + git_tree_diff(m_old->tree,m_new->tree, &php_git2_tree_diff_cb, &payload); } /* }}} */ @@ -114,7 +114,7 @@ PHP_METHOD(git2_tree, current) "specified offset does not exist. %d"); RETURN_FALSE; } - create_tree_entry_from_entry(&z_entry, entry ,m_tree->repository); + create_tree_entry_from_entry(&z_entry, (git_tree_entry *)entry ,m_tree->repository); RETURN_ZVAL(z_entry, 0, 1); } /* }}} */ From 64bd001e8e7c9500fb1577963f236343dec2653c Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 18:04:00 +0900 Subject: [PATCH 116/300] implement Git2\Backend::free callback --- backend.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index f68174695c..85bf8fb02f 100644 --- a/backend.c +++ b/backend.c @@ -38,7 +38,6 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid MAKE_STD_ZVAL(param); 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)) { @@ -86,7 +85,12 @@ static int php_git2_backend_read_prefix(git_oid *id,void ** buffer, size_t * siz static void php_git2_backend_free(struct git_odb_backend *_backend) { TSRMLS_FETCH(); - php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; + 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); } static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) @@ -158,6 +162,8 @@ PHP_METHOD(git2_backend, __construct) 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(); } /* }}} */ From d58bdc17d67d903d726d38ca8ed2ab5f90bf4c20 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 1 Feb 2012 18:27:21 +0900 Subject: [PATCH 117/300] for now, i've tried to implement backend callbacks. i'll be modify next time --- backend.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 6 deletions(-) diff --git a/backend.c b/backend.c index 85bf8fb02f..09c54c4319 100644 --- a/backend.c +++ b/backend.c @@ -61,25 +61,116 @@ static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const static int php_git2_backend_read(void **buffer,size_t *size, git_otype *type, git_odb_backend *_backend, const git_oid *id) { TSRMLS_FETCH(); - php_git2_backend_internal *backend; - return GIT_SUCCESS; + zval *retval, *z_oid, *z_type; + php_git2_backend_internal *m_backend; + int result = GIT_ERROR; + + MAKE_STD_ZVAL(z_oid); + MAKE_STD_ZVAL(z_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) { + 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(); - php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; + zval *retval, *z_oid, *z_type; + php_git2_backend_internal *m_backend; + int result = GIT_ERROR; + + MAKE_STD_ZVAL(z_oid); + MAKE_STD_ZVAL(z_type); + 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; - return GIT_SUCCESS; + 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,unsigned int length) { TSRMLS_FETCH(); - php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; + zval *retval, *z_oid, *z_type; + php_git2_backend_internal *m_backend; + int result = GIT_ERROR; + + MAKE_STD_ZVAL(z_oid); + MAKE_STD_ZVAL(z_type); + 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; - return GIT_SUCCESS; + 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) { + size = *value_pp; + } + + //if (zend_hash_find(hash,"oid",sizeof("oid"),(void **)&value_pp) != FAILURE) { + //oid = *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 void php_git2_backend_free(struct git_odb_backend *_backend) From 6f8122061493dfeb5c9a3914214c7cdfda126197 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 2 Feb 2012 01:18:46 +0900 Subject: [PATCH 118/300] improve Git2\Backend implementation --- backend.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/backend.c b/backend.c index 09c54c4319..b224dbf0b6 100644 --- a/backend.c +++ b/backend.c @@ -33,9 +33,12 @@ 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; - int result = GIT_ERROR; + const 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); @@ -47,7 +50,7 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid zval_ptr_dtor(¶m); zval_ptr_dtor(&retval); - return result; + return (result == GIT_SUCCESS); } static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const void *buffer, size_t size, git_otype type) @@ -61,12 +64,17 @@ static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const 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; + zval *retval, *z_oid, *z_type = NULL; php_git2_backend_internal *m_backend; + const 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, 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); @@ -101,10 +109,13 @@ static int php_git2_backend_read_header(size_t *size, git_otype *type, git_odb_b TSRMLS_FETCH(); zval *retval, *z_oid, *z_type; php_git2_backend_internal *m_backend; + const 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); @@ -137,10 +148,13 @@ static int php_git2_backend_read_prefix(git_oid *id,void ** buffer, size_t * siz TSRMLS_FETCH(); zval *retval, *z_oid, *z_type; php_git2_backend_internal *m_backend; + const 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); @@ -158,13 +172,13 @@ static int php_git2_backend_read_prefix(git_oid *id,void ** buffer, size_t * siz size = *value_pp; } - //if (zend_hash_find(hash,"oid",sizeof("oid"),(void **)&value_pp) != FAILURE) { - //oid = *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); @@ -180,14 +194,13 @@ static void php_git2_backend_free(struct git_odb_backend *_backend) 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); + //zend_call_method_with_0_params(&m_backend->self, Z_OBJCE_P(m_backend->self), NULL, "free", &retval); + //zval_ptr_dtor(&retval); } static void php_git2_backend_free_storage(php_git2_backend *object TSRMLS_DC) { if (object->backend != NULL) { - efree(object->backend); object->backend = NULL; } zend_object_std_dtor(&object->zo TSRMLS_CC); @@ -201,7 +214,8 @@ zend_object_value php_git2_backend_new(zend_class_entry *ce TSRMLS_DC) PHP_GIT2_STD_CREATE_OBJECT(php_git2_backend); - internal = ecalloc(1,sizeof(php_git2_backend_internal)); + /* 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; From d620033dc95b3daacc259dc09bc202bfb3981d28 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 4 Feb 2012 14:51:20 +0900 Subject: [PATCH 119/300] implement Git2\Backend::free callback --- backend.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index b224dbf0b6..9c1d1ce270 100644 --- a/backend.c +++ b/backend.c @@ -194,8 +194,10 @@ static void php_git2_backend_free(struct git_odb_backend *_backend) 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); + 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) @@ -270,6 +272,7 @@ PHP_METHOD(git2_backend, __construct) /* 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); } /* }}} */ From df20d34a875b7f494d01ba5f46da69808e8caeaf Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 4 Feb 2012 15:21:43 +0900 Subject: [PATCH 120/300] implemented Git2\Backend::write callback --- backend.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index 9c1d1ce270..75be8bbde8 100644 --- a/backend.c +++ b/backend.c @@ -55,10 +55,37 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid 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, **value; + int error = GIT_ERROR; + char t_id[GIT_OID_HEXSZ] = {0}; TSRMLS_FETCH(); - php_git2_backend_internal *backend = (php_git2_backend_internal *)_backend; + 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_SUCCESS; + } + zval_ptr_dtor(&retval); - return GIT_SUCCESS; + return error; } static int php_git2_backend_read(void **buffer,size_t *size, git_otype *type, git_odb_backend *_backend, const git_oid *id) From cd2e6584c953e89c699b81bd0b18e2cd7e43546f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 4 Feb 2012 15:50:31 +0900 Subject: [PATCH 121/300] fixed README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e77641b358..11fa7699f7 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ $config['core.bare'] = 1; ```` $repo = Git2\Repository::init("/path/to/repo",true); $odb = $repo->odb // read only property -string $odb->read(sha1) // returns uncompressed git raw data. +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 From bc06227b19c2011839eb4f66659249e46acae7fa Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 4 Feb 2012 16:18:42 +0900 Subject: [PATCH 122/300] added test case for Git2\ODB::read() --- tests/00b-04-odb_read.phpt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/00b-04-odb_read.phpt diff --git a/tests/00b-04-odb_read.phpt b/tests/00b-04-odb_read.phpt new file mode 100644 index 0000000000..1beb5a559e --- /dev/null +++ b/tests/00b-04-odb_read.phpt @@ -0,0 +1,28 @@ +--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 From d499ed4a79e70f2ebacec4b266f0ed2be343f05f Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 14 Feb 2012 09:35:01 +0900 Subject: [PATCH 123/300] remove Git2\ODB::addBackend and Git2\ODB::addAlternate methods. these methods does not expect hotswap backends. will be add `Git2\ODB Git2\ODB::withBackends(array $backends[, array $alternate_backends])` instead of these. --- odb.c | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/odb.c b/odb.c index 800f6cec49..52e8c6d62f 100644 --- a/odb.c +++ b/odb.c @@ -204,49 +204,11 @@ PHP_METHOD(git2_odb, read) } /* }}} */ - -/* -{{{ proto: Git2\ODB::addAlternate(Git2\Backend $backend, $priority) -*/ -PHP_METHOD(git2_odb, addAlternate) -{ -} -/* }}} */ - -/* -{{{ proto: Git2\ODB::addBackend(Git2\Backend $backend, $priority) -*/ -PHP_METHOD(git2_odb, addBackend) -{ - zval *backend = NULL; - php_git2_backend *m_backend; - php_git2_odb *m_odb; - long priority = 5; - int error = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "Ol", &backend, git2_backend_class_entry, &priority) == FAILURE) { - return; - } - - m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); - m_backend = PHP_GIT2_GET_OBJECT(php_git2_backend, backend); - - error = git_odb_add_backend(m_odb->odb, m_backend->backend, priority); - PHP_GIT2_EXCEPTION_CHECK(error); - - RETURN_TRUE; -} -/* }}} */ - - 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) - PHP_ME(git2_odb, addAlternate, arginfo_git2_odb_add_alternate, ZEND_ACC_PUBLIC) - PHP_ME(git2_odb, addBackend, arginfo_git2_odb_add_backend, ZEND_ACC_PUBLIC) {NULL,NULL,NULL} }; From a058b5dc2bc2c9296470711d48373e15b1ff611e Mon Sep 17 00:00:00 2001 From: tsteiner Date: Fri, 17 Feb 2012 11:38:52 -0600 Subject: [PATCH 124/300] Fix a compile error when building for php 5.4. --- php_git2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_git2.h b/php_git2.h index 087853e304..dfb8e6f4a0 100644 --- a/php_git2.h +++ b/php_git2.h @@ -165,7 +165,7 @@ typedef struct{ \ object = ecalloc(1, sizeof(*object));\ zend_object_std_init(&object->zo, ce TSRMLS_CC);\ - object_properties_init(&object->zo, ce); + object_properties_init(&object->zo, ce);\ \ retval.handle = zend_objects_store_put(object,\ (zend_objects_store_dtor_t)zend_objects_destroy_object,\ From f0b3e2dbe9bca4191dbe0f51790e969f60d2ef80 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 23 Feb 2012 14:56:50 +0900 Subject: [PATCH 125/300] adjust test case for Git2\Config --- tests/00a-01-config___construct.phpt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/00a-01-config___construct.phpt b/tests/00a-01-config___construct.phpt index 191b7d56f8..b781da9c5e 100644 --- a/tests/00a-01-config___construct.phpt +++ b/tests/00a-01-config___construct.phpt @@ -13,14 +13,14 @@ object(Git2\Config)#1 (1) { array(1) { ["core"]=> array(4) { - ["repositoryformatversion"]=> - string(1) "0" - ["filemode"]=> - string(4) "true" ["bare"]=> string(4) "true" + ["filemode"]=> + string(4) "true" ["ignorecase"]=> string(4) "true" + ["repositoryformatversion"]=> + string(1) "0" } } } \ No newline at end of file From 35df2cb88b1a5245b914f152d50df8285ba92967 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 27 Feb 2012 21:31:53 +0900 Subject: [PATCH 126/300] fix property name bug for tree entry --- git2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git2.c b/git2.c index 3d9eff22e0..d4dbf8e243 100644 --- a/git2.c +++ b/git2.c @@ -139,9 +139,9 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ MAKE_STD_ZVAL(m_entry); object_init_ex(m_entry, git2_tree_entry_class_entry); - add_property_stringl_ex(m_entry, "name", sizeof("name")-1, (const char *)entry_name, strlen(entry_name), 1 TSRMLS_CC); - add_property_stringl_ex(m_entry, "oid", sizeof("oid")-1, (const char *)entry_oid, strlen(entry_oid), 1 TSRMLS_CC); - add_property_long_ex(m_entry, "attributes", sizeof("attributes")-1, git_tree_entry_attributes(entry) TSRMLS_CC); + 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_next_index_zval(m_array, m_entry); } From 4a599ab75f7450a22229dae179cc0ba9e5f05bdc Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 27 Feb 2012 21:32:25 +0900 Subject: [PATCH 127/300] add Git2\Tree Git2\Tree::getSubtree(string $path) method this method will return specified subtree. Internally, this method does not use git_tree_getsubtree function as that little bit too much. --- tests/003-03-tree_get_subtree.phpt | 45 +++++ 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 0 -> 120 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 0 -> 43 bytes .../83/32251b41aef6ef2f6ef3624e7879affc4fdc70 | Bin 0 -> 44 bytes .../97/eb5a985ce4329e30ce5893339dc2aeba72c3ef | Bin 0 -> 43 bytes .../a2/c260d5a5c3a4b9f4247433b89dd0069fce423f | Bin 0 -> 43 bytes .../aa/657721abe75c346c59e483c40bed53224c8988 | Bin 0 -> 44 bytes .../bc/2b542422510d8b23eae97ede32dc2d5fa13c90 | Bin 0 -> 43 bytes .../cb/50e7dc3b7b52daf18d8bd62e158467236f47bb | Bin 0 -> 140 bytes .../d5/64d0bc3dd917926892c55e3706cc116d5b165e | Bin 0 -> 53 bytes .../e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | Bin 0 -> 15 bytes tests/mock/003-03/refs/heads/master | 1 + tree.c | 127 +++++++++++++ 30 files changed, 653 insertions(+) create mode 100644 tests/003-03-tree_get_subtree.phpt create mode 100644 tests/mock/003-03/COMMIT_EDITMSG create mode 100644 tests/mock/003-03/HEAD create mode 100644 tests/mock/003-03/config create mode 100644 tests/mock/003-03/description create mode 100755 tests/mock/003-03/hooks/applypatch-msg.sample create mode 100755 tests/mock/003-03/hooks/commit-msg.sample create mode 100755 tests/mock/003-03/hooks/post-commit.sample create mode 100755 tests/mock/003-03/hooks/post-receive.sample create mode 100755 tests/mock/003-03/hooks/post-update.sample create mode 100755 tests/mock/003-03/hooks/pre-applypatch.sample create mode 100755 tests/mock/003-03/hooks/pre-commit.sample create mode 100755 tests/mock/003-03/hooks/pre-rebase.sample create mode 100755 tests/mock/003-03/hooks/prepare-commit-msg.sample create mode 100755 tests/mock/003-03/hooks/update.sample create mode 100644 tests/mock/003-03/index create mode 100644 tests/mock/003-03/info/exclude create mode 100644 tests/mock/003-03/logs/HEAD create mode 100644 tests/mock/003-03/logs/refs/heads/master create mode 100644 tests/mock/003-03/objects/45/1cad1f3affaf6e3159c7c85d9ce9a21e21993d create mode 100644 tests/mock/003-03/objects/83/32251b41aef6ef2f6ef3624e7879affc4fdc70 create mode 100644 tests/mock/003-03/objects/97/eb5a985ce4329e30ce5893339dc2aeba72c3ef create mode 100644 tests/mock/003-03/objects/a2/c260d5a5c3a4b9f4247433b89dd0069fce423f create mode 100644 tests/mock/003-03/objects/aa/657721abe75c346c59e483c40bed53224c8988 create mode 100644 tests/mock/003-03/objects/bc/2b542422510d8b23eae97ede32dc2d5fa13c90 create mode 100644 tests/mock/003-03/objects/cb/50e7dc3b7b52daf18d8bd62e158467236f47bb create mode 100644 tests/mock/003-03/objects/d5/64d0bc3dd917926892c55e3706cc116d5b165e create mode 100644 tests/mock/003-03/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 create mode 100644 tests/mock/003-03/refs/heads/master diff --git a/tests/003-03-tree_get_subtree.phpt b/tests/003-03-tree_get_subtree.phpt new file mode 100644 index 0000000000..2877be0f5f --- /dev/null +++ b/tests/003-03-tree_get_subtree.phpt @@ -0,0 +1,45 @@ +--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/mock/003-03/COMMIT_EDITMSG b/tests/mock/003-03/COMMIT_EDITMSG new file mode 100644 index 0000000000..bcceaee9ea --- /dev/null +++ b/tests/mock/003-03/COMMIT_EDITMSG @@ -0,0 +1 @@ +add deep directory entry diff --git a/tests/mock/003-03/HEAD b/tests/mock/003-03/HEAD new file mode 100644 index 0000000000..cb089cd89a --- /dev/null +++ b/tests/mock/003-03/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests/mock/003-03/config b/tests/mock/003-03/config new file mode 100644 index 0000000000..0be3105329 --- /dev/null +++ b/tests/mock/003-03/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true + logallrefupdates = true + ignorecase = true diff --git a/tests/mock/003-03/description b/tests/mock/003-03/description new file mode 100644 index 0000000000..498b267a8c --- /dev/null +++ b/tests/mock/003-03/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/mock/003-03/hooks/applypatch-msg.sample b/tests/mock/003-03/hooks/applypatch-msg.sample new file mode 100755 index 0000000000..8b2a2fe84f --- /dev/null +++ b/tests/mock/003-03/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/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/003-03/hooks/commit-msg.sample b/tests/mock/003-03/hooks/commit-msg.sample new file mode 100755 index 0000000000..b58d1184a9 --- /dev/null +++ b/tests/mock/003-03/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/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/003-03/hooks/post-commit.sample b/tests/mock/003-03/hooks/post-commit.sample new file mode 100755 index 0000000000..22668216a3 --- /dev/null +++ b/tests/mock/003-03/hooks/post-commit.sample @@ -0,0 +1,8 @@ +#!/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 new file mode 100755 index 0000000000..7a83e17ab5 --- /dev/null +++ b/tests/mock/003-03/hooks/post-receive.sample @@ -0,0 +1,15 @@ +#!/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 new file mode 100755 index 0000000000..ec17ec1939 --- /dev/null +++ b/tests/mock/003-03/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/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 new file mode 100755 index 0000000000..b1f187c2e9 --- /dev/null +++ b/tests/mock/003-03/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/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 new file mode 100755 index 0000000000..b187c4bb1f --- /dev/null +++ b/tests/mock/003-03/hooks/pre-commit.sample @@ -0,0 +1,46 @@ +#!/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 new file mode 100755 index 0000000000..9773ed4cb2 --- /dev/null +++ b/tests/mock/003-03/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/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 new file mode 100755 index 0000000000..f093a02ec4 --- /dev/null +++ b/tests/mock/003-03/hooks/prepare-commit-msg.sample @@ -0,0 +1,36 @@ +#!/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 new file mode 100755 index 0000000000..71ab04edc0 --- /dev/null +++ b/tests/mock/003-03/hooks/update.sample @@ -0,0 +1,128 @@ +#!/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 new file mode 100644 index 0000000000000000000000000000000000000000..f2229422a64a79fa33363c1722cec23373962bfe GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/info/exclude b/tests/mock/003-03/info/exclude new file mode 100644 index 0000000000..a5196d1be8 --- /dev/null +++ b/tests/mock/003-03/info/exclude @@ -0,0 +1,6 @@ +# 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 new file mode 100644 index 0000000000..3599cf1f61 --- /dev/null +++ b/tests/mock/003-03/logs/HEAD @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..3599cf1f61 --- /dev/null +++ b/tests/mock/003-03/logs/refs/heads/master @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..b6fa0869db068e152accf45a5451b4ddb3239c1f GIT binary patch literal 43 zcmb)5U|`6=)aud}y7Fn)>iNfKJaMthv^(_IEaK$y&CCo}<9Lk$X4Mh5 literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/objects/83/32251b41aef6ef2f6ef3624e7879affc4fdc70 b/tests/mock/003-03/objects/83/32251b41aef6ef2f6ef3624e7879affc4fdc70 new file mode 100644 index 0000000000000000000000000000000000000000..60e0ca6a272c3ee13e2359c4a090d981e381d131 GIT binary patch literal 44 zcmb)5U|`6=)Ed(Ea{c18BQ}P!(hKyGHhsL~{JKn3wvM0Su_eDf0BThb A-2eap literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/objects/97/eb5a985ce4329e30ce5893339dc2aeba72c3ef b/tests/mock/003-03/objects/97/eb5a985ce4329e30ce5893339dc2aeba72c3ef new file mode 100644 index 0000000000000000000000000000000000000000..21a674f693876a4a25c6202ceeb0161c84c96034 GIT binary patch literal 43 zcmV+`0M!3@0V^p=O;s?mU@$QN0);e&t0@=u*xnSMlriaOoH^SW!Q5!EH~`#U46Ih| B5vKqE literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/objects/a2/c260d5a5c3a4b9f4247433b89dd0069fce423f b/tests/mock/003-03/objects/a2/c260d5a5c3a4b9f4247433b89dd0069fce423f new file mode 100644 index 0000000000000000000000000000000000000000..352f7c4ad9ba197b102f0d040ac9bab023429195 GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/objects/bc/2b542422510d8b23eae97ede32dc2d5fa13c90 b/tests/mock/003-03/objects/bc/2b542422510d8b23eae97ede32dc2d5fa13c90 new file mode 100644 index 0000000000000000000000000000000000000000..9d3c57746030107f006af1126f73f0fc8b31a327 GIT binary patch literal 43 zcmb)5U|`6=)GE@JrW~4iy!8IP*UxMHKCNC6^Z)pNKSqWN*}R_tX8{vS literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/objects/cb/50e7dc3b7b52daf18d8bd62e158467236f47bb b/tests/mock/003-03/objects/cb/50e7dc3b7b52daf18d8bd62e158467236f47bb new file mode 100644 index 0000000000000000000000000000000000000000..a58a918a3d419be2034dd3cc463a9fcc16096c9a GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/objects/d5/64d0bc3dd917926892c55e3706cc116d5b165e b/tests/mock/003-03/objects/d5/64d0bc3dd917926892c55e3706cc116d5b165e new file mode 100644 index 0000000000000000000000000000000000000000..24279dca4468ca5ca61e5498dbfd93f0f9f09795 GIT binary patch literal 53 zcmbx literal 0 HcmV?d00001 diff --git a/tests/mock/003-03/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests/mock/003-03/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 new file mode 100644 index 0000000000000000000000000000000000000000..711223894375fe1186ac5bfffdc48fb1fa1e65cc GIT binary patch literal 15 Wcmbtree, path); + if (error == GIT_SUCCESS) { + 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; + } +} +/* }}} */ + + + static zend_function_entry php_git2_tree_methods[] = { PHP_ME(git2_tree, diff, arginfo_git2_tree_diff, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) /* Iterator Implementation */ @@ -179,6 +305,7 @@ static zend_function_entry php_git2_tree_methods[] = { 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) {NULL,NULL,NULL} }; From 4a95e5f04f71a2729c351c98adb930cae406c604 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 28 Feb 2012 17:11:01 +0900 Subject: [PATCH 128/300] add Git2\Tree::getEntryByName(string $path) --- tests/003-04-tree_get_entry_by_name.phpt | 20 ++++++++++++++ tree.c | 34 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/003-04-tree_get_entry_by_name.phpt diff --git a/tests/003-04-tree_get_entry_by_name.phpt b/tests/003-04-tree_get_entry_by_name.phpt new file mode 100644 index 0000000000..5ee2dc1c8b --- /dev/null +++ b/tests/003-04-tree_get_entry_by_name.phpt @@ -0,0 +1,20 @@ +--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(39) "557db03de997c86a4a028e1ebd3a1ceb225be23" + ["attributes"]=> + int(33188) +} diff --git a/tree.c b/tree.c index ef5efa3ef3..a9d89db0a9 100644 --- a/tree.c +++ b/tree.c @@ -56,6 +56,10 @@ 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() + static int php_git2_tree_diff_cb(const git_tree_diff_data *ptr, void *data) { @@ -296,6 +300,35 @@ PHP_METHOD(git2_tree, getSubtree) /* }}} */ +/* +{{{ 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[] = { PHP_ME(git2_tree, diff, arginfo_git2_tree_diff, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) @@ -306,6 +339,7 @@ static zend_function_entry php_git2_tree_methods[] = { 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} }; From 7dc59163e2105a8eed1c7a3f7cebbde8d7f35160 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 28 Feb 2012 22:04:06 +0900 Subject: [PATCH 129/300] add missing methods for Git2\Commit int Git2\Commit::getParentCount() Git2\Commit Git2\Commit::getParent([int index]) Git2\Commit Git2\Commit::getParents() --- commit.c | 114 ++++++++++++++++++++++ tests/002-08-commit_get_parent_count.phpt | 24 +++++ tests/002-09-commit_get_parent.phpt | 19 ++++ 3 files changed, 157 insertions(+) create mode 100644 tests/002-08-commit_get_parent_count.phpt create mode 100644 tests/002-09-commit_get_parent.phpt diff --git a/commit.c b/commit.c index e4ae9f0690..ee7a0769b5 100644 --- a/commit.c +++ b/commit.c @@ -49,6 +49,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_commit_create, 0,0,2) 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() */ @@ -363,6 +367,113 @@ PHP_METHOD(git2_commit, getTree) } /* }}} */ +/* +{{{ 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_SUCCESS) { + tmp = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), 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, i = 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_SUCCESS) { + result = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), 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; + int error, i = 0; + zval *result; + git_commit *parent = NULL; + + 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) @@ -372,6 +483,9 @@ static zend_function_entry php_git2_commit_methods[] = { 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} }; diff --git a/tests/002-08-commit_get_parent_count.phpt b/tests/002-08-commit_get_parent_count.phpt new file mode 100644 index 0000000000..77f145b5f4 --- /dev/null +++ b/tests/002-08-commit_get_parent_count.phpt @@ -0,0 +1,24 @@ +--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 new file mode 100644 index 0000000000..baf34adb9e --- /dev/null +++ b/tests/002-09-commit_get_parent.phpt @@ -0,0 +1,19 @@ +--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 From 6fcfa9647b87ce6f7cb812d990117080035641ee Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 28 Feb 2012 23:36:31 +0900 Subject: [PATCH 130/300] now Git2\Reference::each supports callback. callback method accepts string $name parameter and returns boolean --- reference.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/reference.c b/reference.c index c1aaa22fe0..56312a0550 100644 --- a/reference.c +++ b/reference.c @@ -153,6 +153,8 @@ 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) @@ -174,7 +176,31 @@ static int php_git2_ref_foreach_cb(const char *name, void *opaque) if (payload->type == 0) { add_next_index_zval(payload->result, ref); } else { - /* for lambda callback */ + 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_SUCCESS; @@ -192,19 +218,25 @@ PHP_METHOD(git2_reference, each) php_git2_ref_foreach_cb_t opaque; int error, filter_len = 0; unsigned int list_flags = GIT_REF_LISTALL; + zend_fcall_info fci; + zend_fcall_info_cache fci_cache; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "O|sz", &repository, git2_repository_class_entry, &filter, &filter_len, &callback) == FAILURE) { + "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 != NULL) { + 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); - /* @todo: closure support */ git_reference_foreach(m_repository->repository, list_flags, &php_git2_ref_foreach_cb, (void *)&opaque); RETVAL_ZVAL(opaque.result,0,1); From 1e65a91a585a716f3744081fe5d3b1c6f08a88b9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 28 Feb 2012 23:51:34 +0900 Subject: [PATCH 131/300] fix segv for Git2\Reference::each --- reference.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reference.c b/reference.c index 56312a0550..e736c3ead9 100644 --- a/reference.c +++ b/reference.c @@ -218,7 +218,9 @@ PHP_METHOD(git2_reference, each) php_git2_ref_foreach_cb_t opaque; int error, filter_len = 0; unsigned int list_flags = GIT_REF_LISTALL; - zend_fcall_info fci; + 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, @@ -228,7 +230,7 @@ PHP_METHOD(git2_reference, each) m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); opaque.type = 0; - if (&fci != NULL) { + if (fci.size != 0) { opaque.type = 1; opaque.fci = &fci; opaque.fci_cache = &fci_cache; From fedb2c51d69181f6afe8440e1c1f727b15ff2eec Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Wed, 29 Feb 2012 00:22:41 +0900 Subject: [PATCH 132/300] add Git2\Reference::getBaseName() --- reference.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/reference.c b/reference.c index e736c3ead9..c4ede32b1e 100644 --- a/reference.c +++ b/reference.c @@ -125,6 +125,26 @@ PHP_METHOD(git2_reference, getName) } /* }}} */ +/* +{{{ proto: Git2\Reference::getBaseName() +*/ +PHP_METHOD(git2_reference, getBaseName) +{ + git_reference *ref; + zval *result; + const char *name = NULL; + const *basename = 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() */ @@ -249,6 +269,7 @@ PHP_METHOD(git2_reference, each) 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, each, arginfo_git2_reference_each, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) #ifdef lookup From d1e7968e0a09f7d6cc9750b22fec186fb46cb542 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 3 Mar 2012 12:36:26 +0900 Subject: [PATCH 133/300] add Git2\Tag::getTarget --- tag.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tag.c b/tag.c index 8bbf15f35a..73afadd4d3 100644 --- a/tag.c +++ b/tag.c @@ -44,7 +44,24 @@ zend_object_value php_git2_tag_new(zend_class_entry *ce TSRMLS_DC) return retval; } +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_SUCCESS) { + result = php_git2_object_new((git_repository*)git_object_owner((git_object*)m_tag->tag), object TSRMLS_CC); + RETVAL_ZVAL(result,0,1); + } +} + static zend_function_entry php_git2_tag_methods[] = { + PHP_ME(git2_tag, getTarget, NULL, ZEND_ACC_PUBLIC) {NULL,NULL,NULL} }; From 122be1df9bdb4a71397305d210c480789f581051 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 3 Mar 2012 12:43:08 +0900 Subject: [PATCH 134/300] add Git2\Tag::getMessage --- tag.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tag.c b/tag.c index 73afadd4d3..ca15ae0345 100644 --- a/tag.c +++ b/tag.c @@ -60,8 +60,21 @@ PHP_METHOD(git2_tag, getTarget) } } +PHP_METHOD(git2_tag, getMessage) +{ + php_git2_tag *m_tag; + const char *message; + zval *result; + int error = 0; + + m_tag = PHP_GIT2_GET_OBJECT(php_git2_tag, getThis()); + message = git_tag_message(m_tag->tag); + RETURN_STRING(message,1); +} + 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) {NULL,NULL,NULL} }; From d60d562543ec651a0e908b56a8774da7568864e2 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 3 Mar 2012 12:44:13 +0900 Subject: [PATCH 135/300] add folding markers --- tag.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tag.c b/tag.c index ca15ae0345..c06627ec9c 100644 --- a/tag.c +++ b/tag.c @@ -44,6 +44,9 @@ zend_object_value php_git2_tag_new(zend_class_entry *ce TSRMLS_DC) return retval; } +/* +{{{ proto: Git2\Tag::getTarget() +*/ PHP_METHOD(git2_tag, getTarget) { php_git2_tag *m_tag; @@ -59,7 +62,11 @@ PHP_METHOD(git2_tag, getTarget) RETVAL_ZVAL(result,0,1); } } +/* }}} */ +/* +{{{ proto: Git2\Tag::getMessage() +*/ PHP_METHOD(git2_tag, getMessage) { php_git2_tag *m_tag; @@ -71,6 +78,7 @@ PHP_METHOD(git2_tag, getMessage) message = git_tag_message(m_tag->tag); RETURN_STRING(message,1); } +/* }}} */ static zend_function_entry php_git2_tag_methods[] = { PHP_ME(git2_tag, getTarget, NULL, ZEND_ACC_PUBLIC) From b99e6f1a3509b263d9afa4d3db7ccf6b8f169a33 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 3 Mar 2012 12:48:14 +0900 Subject: [PATCH 136/300] add Git2\Tag::getBaseName --- tag.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tag.c b/tag.c index c06627ec9c..7cf1cf5c85 100644 --- a/tag.c +++ b/tag.c @@ -80,9 +80,30 @@ PHP_METHOD(git2_tag, getMessage) } /* }}} */ + +/* +{{{ proto: Git2\Tag::getBaseName() +*/ +PHP_METHOD(git2_tag, getBaseName) +{ + zval *result; + const char *name = NULL; + const *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} }; From c656c7e91af0fb6a6825d3643d3633f3d02ceea8 Mon Sep 17 00:00:00 2001 From: Vasileios Georgitzikis Date: Sat, 10 Mar 2012 18:08:20 +0200 Subject: [PATCH 137/300] fixed minor typo in the libgit2 make instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11fa7699f7..3c93c5f9b0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ cd libgit2 mkdir build cd build cmake .. -cmake --build +cmake --build . sudo cmake --build . --target install ```` From fb3b2aee6aa976277c0a1df919b89a6e1efb7aed Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 11 Mar 2012 09:44:52 +0900 Subject: [PATCH 138/300] add note for installation --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c93c5f9b0..4fefb7a9d5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ phpize ./configure make make test +# please create a ticket on the Github if test failed sudo make install +# add `extension=git2.so` to your php.ini ```` new php-git features almost tested. @@ -188,7 +190,8 @@ $remote->fetch(); * James Titcumb * Ryusuke SEKIYAMA * Shuhei Tanuma - +* Vasileios Georgitzikis +* tsteiner ## LICENSE From 4bf67ea5ff09805b42db7a4df3f1a8b148738049 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 12 Mar 2012 06:17:04 +0900 Subject: [PATCH 139/300] following latest libgit2 API: use git_oid_tostr instead ofr git_oid_to_string. --- php_git2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_git2.h b/php_git2.h index dfb8e6f4a0..c59c8961a7 100644 --- a/php_git2.h +++ b/php_git2.h @@ -242,7 +242,7 @@ static inline void create_tree_entry_from_entry(zval **object, git_tree_entry *e m_entry->entry = entry; oid = git_tree_entry_id(entry); - git_oid_to_string(buf,GIT_OID_HEXSZ,oid); + git_oid_tostr(buf,GIT_OID_HEXSZ,oid); add_property_string(*object, "name", (char *)git_tree_entry_name(entry), 1); add_property_string(*object, "oid", buf, 1); From 7299941b61eb0f5fb2008c2f84ca7f7187d2cd0e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 12 Mar 2012 22:14:21 +0900 Subject: [PATCH 140/300] adjust Git2\Config::__construct test case. --- tests/00a-01-config___construct.phpt | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/00a-01-config___construct.phpt b/tests/00a-01-config___construct.phpt index b781da9c5e..d30b4b0c1f 100644 --- a/tests/00a-01-config___construct.phpt +++ b/tests/00a-01-config___construct.phpt @@ -6,21 +6,6 @@ Check for Git2\Config::__construct - array(1) { - ["core"]=> - array(4) { - ["bare"]=> - string(4) "true" - ["filemode"]=> - string(4) "true" - ["ignorecase"]=> - string(4) "true" - ["repositoryformatversion"]=> - string(1) "0" - } - } -} \ No newline at end of file +bool(true) \ No newline at end of file From c83a1e0775c1a3bbfe0115bcac4aa7d6615e98d9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 21 Apr 2012 11:07:17 +0900 Subject: [PATCH 141/300] use ported function instead of php_date_instantiate --- php_git2.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/php_git2.h b/php_git2.h index c59c8961a7..2469cb6f64 100644 --- a/php_git2.h +++ b/php_git2.h @@ -198,6 +198,15 @@ extern int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, 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) +{ + Z_TYPE_P(object) = IS_OBJECT; + object_init_ex(object, pce); + Z_SET_REFCOUNT_P(object, 1); + Z_UNSET_ISREF_P(object); + return object; +} + static inline php_git2_create_signature_from_commit(zval **object, git_commit *commit, int type TSRMLS_DC) { zval *ret; @@ -220,7 +229,7 @@ static inline php_git2_create_signature_from_commit(zval **object, git_commit *c 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_date_instantiate(php_date_get_date_ce(), date TSRMLS_CC); + php_git2_date_instantiate(php_date_get_date_ce(), date TSRMLS_CC); snprintf(time_str,12,"%c%ld",'@',author->when.time); php_date_initialize(zend_object_store_get_object(date TSRMLS_CC), time_str, strlen(time_str), NULL, NULL, 0 TSRMLS_CC); From c8e3cdebad4600a19f3c596aafc782cf04b20c26 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 21 Apr 2012 11:37:20 +0900 Subject: [PATCH 142/300] use preprocessor macro --- php_git2.h | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/php_git2.h b/php_git2.h index 2469cb6f64..2aba310525 100644 --- a/php_git2.h +++ b/php_git2.h @@ -34,6 +34,7 @@ # include "php.h" # include "ext/spl/spl_exceptions.h" +# include # include # include # include @@ -197,14 +198,106 @@ extern int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, extern inline void php_git2_create_signature(zval *object, char *name, int name_len, char *email, int email_len, zval *date TSRMLS_DC); +static timelib_tzdb *php_date_global_timezone_db; +#define GIT2_DATE_TIMEZONEDB php_date_global_timezone_db ? php_date_global_timezone_db : timelib_builtin_db() + +static int php_git2_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC) +{ +#if PHP_VERSION_ID <= 50304 + timelib_time *now; + timelib_tzinfo *tzi; + timelib_error_container *err = NULL; + int type = TIMELIB_ZONETYPE_ID, new_dst; + char *new_abbr; + timelib_sll new_offset; + + if (dateobj->time) { + timelib_time_dtor(dateobj->time); + } + if (format) { + dateobj->time = timelib_parse_from_format(format, time_str_len ? time_str : "", time_str_len ? time_str_len : 0, &err, GIT2_DATE_TIMEZONEDB); + } else { + dateobj->time = timelib_strtotime(time_str_len ? time_str : "now", time_str_len ? time_str_len : sizeof("now") -1, &err, GIT2_DATE_TIMEZONEDB); + } + + /* update last errors and warnings */ + update_errors_warnings(err TSRMLS_CC); + + + if (ctor && err && err->error_count) { + /* spit out the first library error message, at least */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str, + err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message); + } + if (err && err->error_count) { + return 0; + } + + if (timezone_object) { + php_timezone_obj *tzobj; + + tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone_object TSRMLS_CC); + switch (tzobj->type) { + case TIMELIB_ZONETYPE_ID: + tzi = tzobj->tzi.tz; + break; + case TIMELIB_ZONETYPE_OFFSET: + new_offset = tzobj->tzi.utc_offset; + break; + case TIMELIB_ZONETYPE_ABBR: + new_offset = tzobj->tzi.z.utc_offset; + new_dst = tzobj->tzi.z.dst; + new_abbr = strdup(tzobj->tzi.z.abbr); + break; + } + type = tzobj->type; + } else if (dateobj->time->tz_info) { + tzi = dateobj->time->tz_info; + } else { + tzi = get_timezone_info(TSRMLS_C); + } + + now = timelib_time_ctor(); + now->zone_type = type; + switch (type) { + case TIMELIB_ZONETYPE_ID: + now->tz_info = tzi; + break; + case TIMELIB_ZONETYPE_OFFSET: + now->z = new_offset; + break; + case TIMELIB_ZONETYPE_ABBR: + now->z = new_offset; + now->dst = new_dst; + now->tz_abbr = new_abbr; + break; + } + timelib_unixtime2local(now, (timelib_sll) time(NULL)); + + timelib_fill_holes(dateobj->time, now, TIMELIB_NO_CLONE); + timelib_update_ts(dateobj->time, tzi); + + dateobj->time->have_relative = 0; + + timelib_time_dtor(now); + + return 1; +#else + return php_date_initialize(dateobj, time_str, time_str_len, format, timezone_object, ctor TSRMLS_CC); +#endif +} 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 inline php_git2_create_signature_from_commit(zval **object, git_commit *commit, int type TSRMLS_DC) @@ -231,7 +324,7 @@ static inline php_git2_create_signature_from_commit(zval **object, git_commit *c php_git2_date_instantiate(php_date_get_date_ce(), date TSRMLS_CC); snprintf(time_str,12,"%c%ld",'@',author->when.time); - php_date_initialize(zend_object_store_get_object(date TSRMLS_CC), time_str, strlen(time_str), NULL, NULL, 0 TSRMLS_CC); + php_git2_date_initialize(zend_object_store_get_object(date TSRMLS_CC), time_str, strlen(time_str), NULL, NULL, 0 TSRMLS_CC); add_property_zval(ret,"time",date); zval_ptr_dtor(&date); From c45f098775c5747ab5d4a763f6e6ab06569f9668 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 21 Apr 2012 13:29:17 +0900 Subject: [PATCH 143/300] call DateTime::__construct method when PHP_VERSION_ID less than equal 50304. --- php_git2.h | 105 +++++++---------------------------------------------- 1 file changed, 14 insertions(+), 91 deletions(-) diff --git a/php_git2.h b/php_git2.h index 2aba310525..4afc47c6f8 100644 --- a/php_git2.h +++ b/php_git2.h @@ -33,8 +33,8 @@ # endif # include "php.h" +# include "Zend/zend_interfaces.h" # include "ext/spl/spl_exceptions.h" -# include # include # include # include @@ -198,95 +198,6 @@ extern int php_git2_call_user_function_v(zval **retval, zval *obj, char *method, extern inline void php_git2_create_signature(zval *object, char *name, int name_len, char *email, int email_len, zval *date TSRMLS_DC); -static timelib_tzdb *php_date_global_timezone_db; -#define GIT2_DATE_TIMEZONEDB php_date_global_timezone_db ? php_date_global_timezone_db : timelib_builtin_db() - -static int php_git2_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC) -{ -#if PHP_VERSION_ID <= 50304 - timelib_time *now; - timelib_tzinfo *tzi; - timelib_error_container *err = NULL; - int type = TIMELIB_ZONETYPE_ID, new_dst; - char *new_abbr; - timelib_sll new_offset; - - if (dateobj->time) { - timelib_time_dtor(dateobj->time); - } - if (format) { - dateobj->time = timelib_parse_from_format(format, time_str_len ? time_str : "", time_str_len ? time_str_len : 0, &err, GIT2_DATE_TIMEZONEDB); - } else { - dateobj->time = timelib_strtotime(time_str_len ? time_str : "now", time_str_len ? time_str_len : sizeof("now") -1, &err, GIT2_DATE_TIMEZONEDB); - } - - /* update last errors and warnings */ - update_errors_warnings(err TSRMLS_CC); - - - if (ctor && err && err->error_count) { - /* spit out the first library error message, at least */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str, - err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message); - } - if (err && err->error_count) { - return 0; - } - - if (timezone_object) { - php_timezone_obj *tzobj; - - tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone_object TSRMLS_CC); - switch (tzobj->type) { - case TIMELIB_ZONETYPE_ID: - tzi = tzobj->tzi.tz; - break; - case TIMELIB_ZONETYPE_OFFSET: - new_offset = tzobj->tzi.utc_offset; - break; - case TIMELIB_ZONETYPE_ABBR: - new_offset = tzobj->tzi.z.utc_offset; - new_dst = tzobj->tzi.z.dst; - new_abbr = strdup(tzobj->tzi.z.abbr); - break; - } - type = tzobj->type; - } else if (dateobj->time->tz_info) { - tzi = dateobj->time->tz_info; - } else { - tzi = get_timezone_info(TSRMLS_C); - } - - now = timelib_time_ctor(); - now->zone_type = type; - switch (type) { - case TIMELIB_ZONETYPE_ID: - now->tz_info = tzi; - break; - case TIMELIB_ZONETYPE_OFFSET: - now->z = new_offset; - break; - case TIMELIB_ZONETYPE_ABBR: - now->z = new_offset; - now->dst = new_dst; - now->tz_abbr = new_abbr; - break; - } - timelib_unixtime2local(now, (timelib_sll) time(NULL)); - - timelib_fill_holes(dateobj->time, now, TIMELIB_NO_CLONE); - timelib_update_ts(dateobj->time, tzi); - - dateobj->time->have_relative = 0; - - timelib_time_dtor(now); - - return 1; -#else - return php_date_initialize(dateobj, time_str, time_str_len, format, timezone_object, ctor TSRMLS_CC); -#endif -} - static zval* php_git2_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) { #if PHP_VERSION_ID <= 50304 @@ -324,7 +235,19 @@ static inline php_git2_create_signature_from_commit(zval **object, git_commit *c 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_git2_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); @@ -392,4 +315,4 @@ static inline void php_git2_exception_check(int errorcode TSRMLS_DC) } } -#endif /* PHP_GIT2_H */ \ No newline at end of file +#endif /* PHP_GIT2_H */ From 464115afb68233e00a8b3f5d47cabbfc8a310f59 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sat, 21 Apr 2012 13:42:28 +0900 Subject: [PATCH 144/300] fix compile error regarding date_instantiate --- php_git2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_git2.h b/php_git2.h index 4afc47c6f8..5fcf828964 100644 --- a/php_git2.h +++ b/php_git2.h @@ -246,7 +246,7 @@ static inline php_git2_create_signature_from_commit(zval **object, git_commit *c zval_ptr_dtor(&tmp); } #else - php_git2_date_initialize(zend_object_store_get_object(date TSRMLS_CC), time_str, strlen(time_str), NULL, NULL, 0 TSRMLS_CC); + 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); From d2228fe2a7c8ad66a0bf044fba2ad8ab39d56793 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 26 Apr 2012 06:48:59 +0900 Subject: [PATCH 145/300] fix #25 Git\Tree::getEntryByName should return correct size of oid. --- php_git2.h | 4 ++-- tests/003-02-tree_iterate.phpt | 2 +- tests/003-04-tree_get_entry_by_name.phpt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/php_git2.h b/php_git2.h index 5fcf828964..9fee9a1164 100644 --- a/php_git2.h +++ b/php_git2.h @@ -257,7 +257,7 @@ static inline php_git2_create_signature_from_commit(zval **object, git_commit *c static inline void create_tree_entry_from_entry(zval **object, git_tree_entry *entry, git_repository *repository) { TSRMLS_FETCH(); - char buf[GIT_OID_HEXSZ] = {0}; + char buf[GIT_OID_HEXSZ+1] = {0}; const git_oid *oid; php_git2_tree_entry *m_entry; @@ -267,7 +267,7 @@ static inline void create_tree_entry_from_entry(zval **object, git_tree_entry *e m_entry->entry = entry; oid = git_tree_entry_id(entry); - git_oid_tostr(buf,GIT_OID_HEXSZ,oid); + 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); diff --git a/tests/003-02-tree_iterate.phpt b/tests/003-02-tree_iterate.phpt index 08ff05e966..dc2eeb19d5 100644 --- a/tests/003-02-tree_iterate.phpt +++ b/tests/003-02-tree_iterate.phpt @@ -14,5 +14,5 @@ foreach ($tree as $entry) { } --EXPECT-- README -557db03de997c86a4a028e1ebd3a1ceb225be23 +557db03de997c86a4a028e1ebd3a1ceb225be238 33188 \ 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 index 5ee2dc1c8b..59cd3a203e 100644 --- a/tests/003-04-tree_get_entry_by_name.phpt +++ b/tests/003-04-tree_get_entry_by_name.phpt @@ -14,7 +14,7 @@ object(Git2\TreeEntry)#5 (3) { ["name"]=> string(6) "README" ["oid"]=> - string(39) "557db03de997c86a4a028e1ebd3a1ceb225be23" + string(40) "557db03de997c86a4a028e1ebd3a1ceb225be238" ["attributes"]=> int(33188) } From 43480aa02c50d90e51dff3a911691a4b3b9f562b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 21 May 2012 00:46:55 +0900 Subject: [PATCH 146/300] focusing Lord of Diffstruction. --- backend.c | 6 +++--- commit.c | 4 ++-- config.c | 2 +- odb.c | 4 ++-- php_git2.h | 1 + reference.c | 2 +- remote.c | 14 +++++++------ repository.c | 8 ++++---- tag.c | 2 +- tree.c | 54 +++----------------------------------------------- tree_builder.c | 2 +- walker.c | 4 ++-- 12 files changed, 29 insertions(+), 74 deletions(-) diff --git a/backend.c b/backend.c index 75be8bbde8..6d4bb2b84e 100644 --- a/backend.c +++ b/backend.c @@ -44,13 +44,13 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid 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_SUCCESS; + result = GIT_OK; } zval_ptr_dtor(¶m); zval_ptr_dtor(&retval); - return (result == GIT_SUCCESS); + 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) @@ -81,7 +81,7 @@ static int php_git2_backend_write(git_oid *id, git_odb_backend *_backend, const zval_ptr_dtor(&z_type); if (Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)) { - error = GIT_SUCCESS; + error = GIT_OK; } zval_ptr_dtor(&retval); diff --git a/commit.c b/commit.c index ee7a0769b5..296beb7714 100644 --- a/commit.c +++ b/commit.c @@ -392,7 +392,7 @@ PHP_METHOD(git2_commit, getParents) zval *tmp = NULL; error = git_commit_parent(&parent, m_commit->commit, i); - if (error == GIT_SUCCESS) { + if (error == GIT_OK) { tmp = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), parent TSRMLS_CC); add_next_index_zval(result, tmp); } @@ -438,7 +438,7 @@ PHP_METHOD(git2_commit, getParent) } error = git_commit_parent(&parent, m_commit->commit, (unsigned int)index); - if (error == GIT_SUCCESS) { + if (error == GIT_OK) { result = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), parent TSRMLS_CC); RETVAL_ZVAL(result,0,1); } diff --git a/config.c b/config.c index d6b97c441b..e72eb92994 100644 --- a/config.c +++ b/config.c @@ -257,7 +257,7 @@ static int php_git2_config_foreach(const char *var_name, const char *value, void } efree(tmp_value); - return GIT_SUCCESS; + return GIT_OK; } static int php_git2_config_reload(zval *object, unsigned short dtor TSRMLS_DC) diff --git a/odb.c b/odb.c index 52e8c6d62f..3db393d732 100644 --- a/odb.c +++ b/odb.c @@ -156,7 +156,7 @@ PHP_METHOD(git2_odb, exists) m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); - if (git_oid_fromstr(&id, hash) != GIT_SUCCESS) { + if (git_oid_fromstr(&id, hash) != GIT_OK) { RETURN_FALSE; } @@ -188,7 +188,7 @@ PHP_METHOD(git2_odb, read) } m_odb = PHP_GIT2_GET_OBJECT(php_git2_odb, getThis()); - if (git_oid_fromstr(&id, hash) != GIT_SUCCESS) { + if (git_oid_fromstr(&id, hash) != GIT_OK) { RETURN_FALSE; } diff --git a/php_git2.h b/php_git2.h index 9fee9a1164..cb6f2a24de 100644 --- a/php_git2.h +++ b/php_git2.h @@ -37,6 +37,7 @@ # include "ext/spl/spl_exceptions.h" # include # include +# include # include extern zend_module_entry git2_module_entry; diff --git a/reference.c b/reference.c index c4ede32b1e..af91784a8a 100644 --- a/reference.c +++ b/reference.c @@ -223,7 +223,7 @@ static int php_git2_ref_foreach_cb(const char *name, void *opaque) } - return GIT_SUCCESS; + return GIT_OK; } /* diff --git a/remote.c b/remote.c index 924ccc5770..9e7179a57b 100644 --- a/remote.c +++ b/remote.c @@ -73,12 +73,14 @@ PHP_METHOD(git2_remote, __construct) 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)) { - error = git_remote_new( +/* TODO + error = git_remote_new( &remote, m_repository->repository, path, NULL ); + */ } else { error = git_remote_load(&remote,m_repository->repository, path); } @@ -96,14 +98,14 @@ static int php_git2_rename_packfile(char *packname, git_indexer *idx) slash = strrchr(path, '/'); if (!slash) { - return GIT_EINVALIDARGS; + return -1; } memset(oid, 0x0, sizeof(oid)); git_oid_fmt(oid, git_indexer_hash(idx)); ret = sprintf(slash + 1, "pack-%s.pack", oid); if(ret < 0) { - return GIT_EOSERR; + return -2; } return rename(packname, path); @@ -114,7 +116,7 @@ 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_SUCCESS; + return GIT_OK; } /* @@ -141,7 +143,7 @@ PHP_METHOD(git2_remote, 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); + //error = git_remote_download(&packname, m_remote->remote); if (packname != NULL) { // Create a new instance indexer @@ -158,7 +160,7 @@ PHP_METHOD(git2_remote, fetch) PHP_GIT2_EXCEPTION_CHECK(error); } - error = git_remote_update_tips(m_remote->remote); + //error = git_remote_update_tips(m_remote->remote); PHP_GIT2_EXCEPTION_CHECK(error); free(packname); diff --git a/repository.c b/repository.c index cf01a9a3a2..2a5dbe5e56 100644 --- a/repository.c +++ b/repository.c @@ -234,7 +234,7 @@ PHP_METHOD(git2_repository, init) } ret = git_repository_init(&repository, path, is_bare); - if (ret == GIT_SUCCESS) { + if (ret == GIT_OK) { zval *object; MAKE_STD_ZVAL(object); @@ -310,7 +310,7 @@ PHP_METHOD(git2_repository, discover) return; } - if (git_repository_discover(path_buffer,path_size,(const char *)start_path,(int)across_fs, (const char *)ceiling_dirs) == GIT_SUCCESS) { + 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; @@ -338,7 +338,7 @@ PHP_METHOD(git2_repository, exists) error = git_repository_odb(&odb, m_repository->repository); PHP_GIT2_EXCEPTION_CHECK(error); - if (git_oid_fromstr(&id, hash) != GIT_SUCCESS) { + if (git_oid_fromstr(&id, hash) != GIT_OK) { RETURN_FALSE; } @@ -374,7 +374,7 @@ PHP_METHOD(git2_repository, lookup) error = git_repository_odb(&odb, m_repository->repository); PHP_GIT2_EXCEPTION_CHECK(error); - if (git_oid_fromstrn(&id, hash, hash_len) != GIT_SUCCESS) { + if (git_oid_fromstrn(&id, hash, hash_len) != GIT_OK) { RETURN_FALSE; } diff --git a/tag.c b/tag.c index 7cf1cf5c85..21de02c3a5 100644 --- a/tag.c +++ b/tag.c @@ -57,7 +57,7 @@ PHP_METHOD(git2_tag, getTarget) m_tag = PHP_GIT2_GET_OBJECT(php_git2_tag, getThis()); error = git_tag_target(&object, m_tag->tag); - if (error == GIT_SUCCESS) { + 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); } diff --git a/tree.c b/tree.c index a9d89db0a9..629ed97aaf 100644 --- a/tree.c +++ b/tree.c @@ -47,11 +47,6 @@ zend_object_value php_git2_tree_new(zend_class_entry *ce TSRMLS_DC) return retval; } -ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_diff, 0,0,2) - ZEND_ARG_INFO(0, old) - ZEND_ARG_INFO(0, new) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_get_subtree, 0,0,1) ZEND_ARG_INFO(0, path) ZEND_END_ARG_INFO() @@ -60,49 +55,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_tree_get_entry_by_name, 0,0,1) ZEND_ARG_INFO(0, path) ZEND_END_ARG_INFO() - -static int php_git2_tree_diff_cb(const git_tree_diff_data *ptr, void *data) -{ -/* -typedef struct { - unsigned int old_attr; - unsigned int new_attr; - git_oid old_oid; - git_oid new_oid; - git_status_t status; - const char *path; -} git_tree_diff_data; -*/ - fprintf(stderr,"path:%s\n",ptr->path); -} -typedef struct{ - zval *old; - zval *new; - zval *result; -} php_git2_tree_diff_cb_t; -/* -{{{ proto: Git2\Tree::diff($old, $new) - @todo: think this behavior -*/ -PHP_METHOD(git2_tree, diff) -{ - zval *old, *new; - php_git2_tree *m_old, *m_new; - php_git2_tree_diff_cb_t payload; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "OO", &old, git2_tree_class_entry, &new, git2_tree_class_entry) == FAILURE) { - return; - } - - m_old = PHP_GIT2_GET_OBJECT(php_git2_tree, old); - m_new = PHP_GIT2_GET_OBJECT(php_git2_tree, new); - - git_tree_diff(m_old->tree,m_new->tree, &php_git2_tree_diff_cb, &payload); -} -/* }}} */ - /* Iterator Implementation */ @@ -224,7 +177,7 @@ static int get_subtree(git_tree **result, git_tree *root, char *path) git_tree_entry_id(entry) ); - if (error == GIT_SUCCESS) { + if (error == GIT_OK) { target = tmp_result; } else { return -1; @@ -243,7 +196,7 @@ static int get_subtree(git_tree **result, git_tree *root, char *path) git_object_id((const git_object *)entry) ); - if (error == GIT_SUCCESS) { + if (error == GIT_OK) { target = tmp_result; } else { return -1; @@ -288,7 +241,7 @@ PHP_METHOD(git2_tree, getSubtree) * this method returns specified subtree or false. */ error = get_subtree(&subtree, object->tree, path); - if (error == GIT_SUCCESS) { + if (error == GIT_OK) { zval *result; result = php_git2_object_new(git_object_owner((git_object *)object->tree), (git_object *)subtree TSRMLS_CC); @@ -331,7 +284,6 @@ PHP_METHOD(git2_tree, getEntryByName) static zend_function_entry php_git2_tree_methods[] = { - PHP_ME(git2_tree, diff, arginfo_git2_tree_diff, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) /* Iterator Implementation */ PHP_ME(git2_tree, current, NULL, ZEND_ACC_PUBLIC) PHP_ME(git2_tree, key, NULL, ZEND_ACC_PUBLIC) diff --git a/tree_builder.c b/tree_builder.c index c513cef425..4d765ba8f0 100644 --- a/tree_builder.c +++ b/tree_builder.c @@ -153,7 +153,7 @@ PHP_METHOD(git2_tree_builder, write) m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, repository); error = git_treebuilder_write(&oid, m_repository->repository, m_builder->builder); - if (error != GIT_SUCCESS) { + if (error != GIT_OK) { RETURN_FALSE; } diff --git a/walker.c b/walker.c index 66b9602fad..7fdbc8f8d7 100644 --- a/walker.c +++ b/walker.c @@ -92,7 +92,7 @@ PHP_METHOD(git2_walker, __construct) error = git_revwalk_new(&m_walker->walker, m_repository->repository); - if (error != GIT_SUCCESS) { + if (error != GIT_OK) { /* @todo error handling */ } m_walker->repository = m_repository->repository; @@ -222,7 +222,7 @@ PHP_METHOD(git2_walker, next) m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); error = git_revwalk_next(m_walker->current, m_walker->walker); - if (error != GIT_SUCCESS) { + if (error != GIT_OK) { efree(m_walker->current); m_walker->current = NULL; } From cb095001b8c68ea899034d20d16e714698b043a3 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 21 May 2012 00:52:56 +0900 Subject: [PATCH 147/300] for now, adjust error handling --- php_git2.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/php_git2.h b/php_git2.h index cb6f2a24de..bdbf13a52e 100644 --- a/php_git2.h +++ b/php_git2.h @@ -302,16 +302,16 @@ static inline void php_git2_create_index_entry(zval **object, git_index_entry *e #define PHP_GIT2_EXCEPTION_CHECK(errorcode) \ if (errorcode < 0) { \ - zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%s\n(error code %d) at %s:%d", git_lasterror(), errorcode, __FILE__, __LINE__); \ - git_clearerror(); \ + 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,"%s\n(error code %d)", git_lasterror(), errorcode); - git_clearerror(); + zend_throw_exception_ex(NULL, 0 TSRMLS_CC,"%d\n(error code %d)", giterr_last(), errorcode); + giterr_clear(); return; } } From f178c321f998d8d09613fa3f644a99da3a76deb6 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 21 May 2012 01:01:01 +0900 Subject: [PATCH 148/300] fix Git2::Config --- config.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index e72eb92994..7cfeb4ef21 100644 --- a/config.c +++ b/config.c @@ -226,7 +226,7 @@ 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(opaque->config, var_name, &config_value); + error = git_config_get_string(&config_value, opaque->config, var_name); tmp_value = estrdup(var_name); current_key = php_strtok_r(tmp_value, ".", &savedptr); @@ -335,7 +335,8 @@ PHP_METHOD(git2_config, __construct) } error = git_config_open_ondisk(&config, path); - /* @todo: automatic convert types */ + + /* @todo: automatic convert types */ m_config = PHP_GIT2_GET_OBJECT(php_git2_config, getThis()); m_config->config = config; From b08b92890ad116995ac01dc3feaad959dde676d9 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 21 May 2012 01:15:21 +0900 Subject: [PATCH 149/300] adjust commit create test case. 0.17.0 has changed whitespace rules. --- tests/002-07-commit_create.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/002-07-commit_create.phpt b/tests/002-07-commit_create.phpt index 48e0cc0448..e90f006970 100644 --- a/tests/002-07-commit_create.phpt +++ b/tests/002-07-commit_create.phpt @@ -42,7 +42,7 @@ echo PHP_EOL; printf("%s\n", $commit->getMessage()); `rm -rf {$path}`; --EXPECT-- -commit_id: 239442d8e6cdbd904e150e25778cc45024b60d51 +commit_id: 850e8fd947badfe89add66c0d8bf033231ae9b9d author: Shuhei Tanuma email: chobieee@gmail.com time: 1327164747 From ebea5e5fe8d140d83edf2ee48f9035422b6b03dd Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 7 Aug 2012 21:24:56 +0900 Subject: [PATCH 150/300] use static lib --- .gitmodules | 3 +++ config.m4 | 26 +++----------------------- libgit2 | 1 + 3 files changed, 7 insertions(+), 23 deletions(-) create mode 100644 .gitmodules create mode 160000 libgit2 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..3a95da8561 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libgit2"] + path = libgit2 + url = git@github.com:libgit2/libgit2.git diff --git a/config.m4 b/config.m4 index 0e8e06b953..373b69d815 100644 --- a/config.m4 +++ b/config.m4 @@ -5,29 +5,6 @@ PHP_ARG_WITH(libgit2-dir, for libgit2, [ --with-libgit2-dir[=DIR] Set the path to libgit2 install prefix.], yes) if test $PHP_GIT2 != "no"; then - if test "$PHP_LIBGIT2_DIR" != "no" && test "$PHP_LIBGIT2_DIR" != "yes"; then - LIBGIT2_SEARCH_DIRS=$PHP_LIBGIT2_DIR - else - LIBGIT2_SEARCH_DIRS="/usr/local /usr" - fi - - for i in $LIBGIT2_SEARCH_DIRS; do - if test -f $i/include/libgit2/git2.h; then - LIBGIT2_DIR=$i - LIBGIT2_INCDIR=$i/include/libgit2 - elif test -f $i/include/git2.h; then - LIBGIT2_DIR=$i - LIBGIT2_INCDIR=$i/include - fi - done - - if test -z "$LIBGIT2_DIR"; then - AC_MSG_ERROR(Cannot find libgit2) - fi - - LIBGIT2_LIBDIR=$LIBGIT2_DIR/$PHP_LIBDIR - PHP_ADD_LIBRARY_WITH_PATH(git2, $LIBGIT2_LIBDIR, GIT2_SHARED_LIBADD) - PHP_SUBST(GIT2_SHARED_LIBADD) PHP_NEW_EXTENSION(git2, git2.c \ repository.c \ @@ -49,6 +26,9 @@ if test $PHP_GIT2 != "no"; then backend.c \ , $ext_shared) + 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" + PHP_SUBST([CFLAGS]) + ifdef([PHP_ADD_EXTENSION_DEP], [ PHP_ADD_EXTENSION_DEP(git, spl, true) diff --git a/libgit2 b/libgit2 new file mode 160000 index 0000000000..e4607392b5 --- /dev/null +++ b/libgit2 @@ -0,0 +1 @@ +Subproject commit e4607392b5cbdcaf6a5dc810ca77b5dd1afcb147 From 4a3f7d7e74dadfd4c83e5e94200b1caaacd6af3e Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 7 Aug 2012 21:30:15 +0900 Subject: [PATCH 151/300] update readme --- README.md | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4fefb7a9d5..cc02f48c89 100644 --- a/README.md +++ b/README.md @@ -13,26 +13,21 @@ please check tests cases. you need to install libgit2 before make php-git. ```` -git clone https://github.com/libgit2/libgit2.git +git clone https://github.com/libgit2/php-git.git --recursive cd libgit2 -mkdir build -cd build +mkdir build && cd build cmake .. -cmake --build . -sudo cmake --build . --target install -```` - -```` -git clone https://github.com/libgit2/php-git.git -cd php-git +cmake -DBUILD_SHARED_LIBS=OFF -build . +make +cd ../../ phpize ./configure make -make test -# please create a ticket on the Github if test failed +make install sudo make install # add `extension=git2.so` to your php.ini ```` + new php-git features almost tested. # API From a18e5114114cf26949c89d30d1766559344a1b5b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 7 Aug 2012 22:09:14 +0900 Subject: [PATCH 152/300] fix several compile warnings --- backend.c | 4 ++-- blob.c | 3 --- commit.c | 16 +++----------- config.c | 24 +++++---------------- git2.c | 38 +++++++++++++++++++++------------ index.c | 2 +- odb.c | 6 +----- odb_object.c | 2 -- php_git2.h | 6 +++--- reference.c | 13 +++-------- remote.c | 1 - repository.c | 9 ++------ signature.c | 2 +- tag.c | 5 +---- tests/002-07-commit_create.phpt | 2 +- tree.c | 2 +- tree_builder.c | 1 - walker.c | 3 --- 18 files changed, 48 insertions(+), 91 deletions(-) diff --git a/backend.c b/backend.c index 6d4bb2b84e..897228362c 100644 --- a/backend.c +++ b/backend.c @@ -33,7 +33,7 @@ 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; - const char out[GIT_OID_HEXSZ+1] = {0}; + char out[GIT_OID_HEXSZ+1] = {0}; int result = -1; MAKE_STD_ZVAL(param); @@ -93,7 +93,7 @@ static int php_git2_backend_read(void **buffer,size_t *size, git_otype *type, gi TSRMLS_FETCH(); zval *retval, *z_oid, *z_type = NULL; php_git2_backend_internal *m_backend; - const char out[GIT_OID_HEXSZ+1] = {0}; + char out[GIT_OID_HEXSZ+1] = {0}; int result = GIT_ERROR; MAKE_STD_ZVAL(z_oid); diff --git a/blob.c b/blob.c index e9c0c33cf4..bf0b98d6e6 100644 --- a/blob.c +++ b/blob.c @@ -55,7 +55,6 @@ ZEND_END_ARG_INFO() */ PHP_METHOD(git2_blob, getContent) { - char *data; php_git2_blob *m_blob; m_blob = PHP_GIT2_GET_OBJECT(php_git2_blob, getThis()); @@ -78,7 +77,6 @@ PHP_METHOD(git2_blob, getContent) */ PHP_METHOD(git2_blob, getSize) { - char *data; php_git2_blob *m_blob; m_blob = PHP_GIT2_GET_OBJECT(php_git2_blob, getThis()); @@ -100,7 +98,6 @@ PHP_METHOD(git2_blob, getSize) */ PHP_METHOD(git2_blob, __toString) { - char *data; php_git2_blob *m_blob; m_blob = PHP_GIT2_GET_OBJECT(php_git2_blob, getThis()); diff --git a/commit.c b/commit.c index 296beb7714..bad3e24181 100644 --- a/commit.c +++ b/commit.c @@ -58,7 +58,6 @@ ZEND_END_ARG_INFO() */ PHP_METHOD(git2_commit, getMessage) { - char *data; php_git2_commit *m_commit; m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); @@ -129,9 +128,8 @@ PHP_METHOD(git2_commit, parentCount) */ PHP_METHOD(git2_commit, getAuthor) { - unsigned int parent_count = 0; php_git2_commit *m_commit; - zval *z_signature, *date; + zval *z_signature; m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); @@ -153,9 +151,8 @@ PHP_METHOD(git2_commit, getAuthor) */ PHP_METHOD(git2_commit, getCommitter) { - unsigned int parent_count = 0; php_git2_commit *m_commit; - zval *z_signature, *date; + zval *z_signature; m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); @@ -177,10 +174,8 @@ PHP_METHOD(git2_commit, getCommitter) */ PHP_METHOD(git2_commit, getOid) { - unsigned int parent_count = 0; php_git2_commit *m_commit; char oid_out[GIT_OID_HEXSZ] = {0}; - git_oid oid; m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); @@ -210,7 +205,6 @@ PHP_METHOD(git2_commit, create) const git_commit **parents = NULL; git_commit **free_list = NULL; git_tree *tree; - git_signature *author, *committer; git_oid commit_oid; char *message, *encoding, *ref, oid_out[GIT_OID_HEXSZ]; int parent_count, i, error = 0; @@ -344,7 +338,6 @@ PHP_METHOD(git2_commit, getTree) { php_git2_commit *m_commit; const git_oid *oid; - git_oid *id; git_otype type = GIT_OBJ_TREE; git_object *object; zval *result; @@ -412,7 +405,7 @@ PHP_METHOD(git2_commit, getParent) { php_git2_commit *m_commit; unsigned int parent_count = 0; - int error, i = 0; + int error = 0; long index = 0; zval *result; git_commit *parent = NULL; @@ -455,9 +448,6 @@ PHP_METHOD(git2_commit, getParentCount) { php_git2_commit *m_commit; unsigned int parent_count = 0; - int error, i = 0; - zval *result; - git_commit *parent = NULL; m_commit = PHP_GIT2_GET_OBJECT(php_git2_commit, getThis()); diff --git a/config.c b/config.c index 7cfeb4ef21..ee55cc3de9 100644 --- a/config.c +++ b/config.c @@ -44,10 +44,8 @@ static void php_git2_config_free_storage(php_git2_config *object TSRMLS_DC) static int php_git2_config_has_dimension(zval *object, zval *member, int check_empty TSRMLS_DC) { zend_object_handlers *standard; - HashTable *hash; - zval *entry, *tmp_result, **target_offset; + zval *entry, **target_offset; char *current_key, *tmp_value, *savedptr, *k; - int error = 0; entry = zend_read_property(git2_config_class_entry, object,"configs",sizeof("configs")-1, 0 TSRMLS_CC); @@ -92,8 +90,6 @@ static int php_git2_config_has_dimension(zval *object, zval *member, int check_e /* @todo refactoring */ static zval* php_git2_config_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) { - zend_object_handlers *standard; - HashTable *hash; zval *entry, *tmp_result, **target_offset; char *current_key, *tmp_value, *savedptr, *k; int error = 0; @@ -172,7 +168,6 @@ typedef struct{ static int php_git2_config_resolve(zval **result, const char *var_name, zval *m_config) { TSRMLS_FETCH(); - HashTable *hash; zval *entry, *tmp_result, **target_offset; char *current_key, *tmp_value, *savedptr, *k; int error = 0; @@ -289,8 +284,7 @@ static int php_git2_config_reload(zval *object, unsigned short dtor TSRMLS_DC) static void php_git2_config_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) { char *key; - int error, key_len = 0; - zval *result, *entry; + int error = 0; php_git2_config *m_config; m_config = PHP_GIT2_GET_OBJECT(php_git2_config, object); @@ -325,8 +319,6 @@ PHP_METHOD(git2_config, __construct) git_config *config; int error, path_len = 0; php_git2_config *m_config; - zval *config_array; - php_git2_config_foreach_t payload; /* @todo: supports array for reading multiple configs */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -354,10 +346,7 @@ PHP_METHOD(git2_config, __construct) PHP_METHOD(git2_config, get) { char *key; - git_config *config; - int error, key_len = 0; - const char *value; - php_git2_config *m_config; + int key_len = 0; zval *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -382,9 +371,8 @@ PHP_METHOD(git2_config, store) { char *key; int error, key_len = 0; - zval *result, *value, *entry; + zval *value; php_git2_config *m_config; - php_git2_config_foreach_t payload; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, &value) == FAILURE) { @@ -424,10 +412,8 @@ PHP_METHOD(git2_config, store) PHP_METHOD(git2_config, delete) { char *key; - int error, key_len = 0; - zval *result, *entry; + int key_len = 0; php_git2_config *m_config; - php_git2_config_foreach_t payload; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { diff --git a/git2.c b/git2.c index d4dbf8e243..b9a32cdd80 100644 --- a/git2.c +++ b/git2.c @@ -23,21 +23,25 @@ */ #include "php_git2.h" +#include "ext/standard/info.h" -extern void php_git2_repository_init(TSRMLS_D); -extern void php_git2_commit_init(TSRMLS_D); -extern void php_git2_blob_init(TSRMLS_D); -extern void php_git2_tree_init(TSRMLS_D); -extern void php_git2_tree_builder_init(TSRMLS_D); -extern void php_git2_signature_init(TSRMLS_D); -extern void php_git2_walker_init(TSRMLS_D); -extern void php_git2_reference_init(TSRMLS_D); -extern void php_git2_config_init(TSRMLS_D); -extern void php_git2_remote_init(TSRMLS_D); -extern void php_git2_tag_init(TSRMLS_D); -extern void php_git2_odb_init(TSRMLS_D); -extern void php_git2_odb_object_init(TSRMLS_D); - +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, ...) { @@ -150,6 +154,12 @@ zval* php_git2_object_new(git_repository *repository, git_object *object TSRMLS_ 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; } diff --git a/index.c b/index.c index a0cef31489..1835c0e8e3 100644 --- a/index.c +++ b/index.c @@ -169,7 +169,7 @@ PHP_METHOD(git2_index, valid) m_index = PHP_GIT2_GET_OBJECT(php_git2_index, getThis()); entry_count = git_index_entrycount(m_index->index); - if (m_index->offset < entry_count && m_index->offset >= 0) { + if (m_index->offset < entry_count) { RETURN_TRUE; } else { RETURN_FALSE; diff --git a/odb.c b/odb.c index 3db393d732..b91475026b 100644 --- a/odb.c +++ b/odb.c @@ -83,7 +83,6 @@ PHP_METHOD(git2_odb, 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; @@ -112,7 +111,6 @@ PHP_METHOD(git2_odb, write) 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; @@ -144,8 +142,7 @@ PHP_METHOD(git2_odb, write) PHP_METHOD(git2_odb, exists) { char *hash; - int error, hash_len = 0; - git_odb *odb; + int hash_len = 0; git_oid id; php_git2_odb *m_odb; @@ -175,7 +172,6 @@ PHP_METHOD(git2_odb, read) { char *hash; int error, hash_len = 0; - git_odb *odb; git_oid id; git_odb_object *object; zval *raw; diff --git a/odb_object.c b/odb_object.c index 079c906b5c..2760630872 100644 --- a/odb_object.c +++ b/odb_object.c @@ -48,7 +48,6 @@ zend_object_value php_git2_odb_object_new(zend_class_entry *ce TSRMLS_DC) static int php_git2_odb_object_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) { - zval *retval; zend_class_entry *ce; php_git2_odb_object *m_raw; @@ -95,7 +94,6 @@ static int php_git2_odb_object_cast_object_tostring(zval *readobj, zval *writeob PHP_METHOD(git2_odb_object, getContent) { php_git2_odb_object *m_raw; - git_otype type; 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); diff --git a/php_git2.h b/php_git2.h index bdbf13a52e..e2e0758cec 100644 --- a/php_git2.h +++ b/php_git2.h @@ -34,6 +34,7 @@ # include "php.h" # include "Zend/zend_interfaces.h" +# include "Zend/zend_exceptions.h" # include "ext/spl/spl_exceptions.h" # include # include @@ -212,10 +213,9 @@ static zval* php_git2_date_instantiate(zend_class_entry *pce, zval *object TSRML #endif } -static inline php_git2_create_signature_from_commit(zval **object, git_commit *commit, int type TSRMLS_DC) +static void inline php_git2_create_signature_from_commit(zval **object, git_commit *commit, int type TSRMLS_DC) { - zval *ret; - zval *z_signature, *date; + zval *ret, *date; char time_str[12] = {0}; const git_signature *author; php_git2_signature *m_signature; diff --git a/reference.c b/reference.c index af91784a8a..462ced95b5 100644 --- a/reference.c +++ b/reference.c @@ -59,11 +59,9 @@ ZEND_END_ARG_INFO() PHP_METHOD(git2_reference, lookup) { char *path; - char oid_out[GIT_OID_HEXSZ] = {0}; int error, path_len = 0; git_reference *ref; zval *repository, *object; - git_oid *oid; php_git2_repository *m_repository; php_git2_reference *m_reference; @@ -93,7 +91,6 @@ PHP_METHOD(git2_reference, lookup) */ PHP_METHOD(git2_reference, getTarget) { - git_reference *ref; php_git2_reference *m_reference; m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); @@ -116,7 +113,6 @@ PHP_METHOD(git2_reference, getTarget) */ PHP_METHOD(git2_reference, getName) { - git_reference *ref; php_git2_reference *m_reference; m_reference = PHP_GIT2_GET_OBJECT(php_git2_reference, getThis()); @@ -130,10 +126,8 @@ PHP_METHOD(git2_reference, getName) */ PHP_METHOD(git2_reference, getBaseName) { - git_reference *ref; - zval *result; + char *basename = NULL; const char *name = NULL; - const *basename = NULL; php_git2_reference *m_reference; size_t len; @@ -231,12 +225,11 @@ static int php_git2_ref_foreach_cb(const char *name, void *opaque) */ PHP_METHOD(git2_reference, each) { - git_reference *ref; - zval *repository,*callback = NULL; + zval *repository = NULL; php_git2_repository *m_repository; char *filter; php_git2_ref_foreach_cb_t opaque; - int error, filter_len = 0; + int filter_len = 0; unsigned int list_flags = GIT_REF_LISTALL; zend_fcall_info fci = { 0,NULL,NULL,NULL,NULL,0,NULL,NULL diff --git a/remote.c b/remote.c index 9e7179a57b..35416ec8fc 100644 --- a/remote.c +++ b/remote.c @@ -58,7 +58,6 @@ ZEND_END_ARG_INFO() PHP_METHOD(git2_remote, __construct) { char *path; - git_config *config; int error, path_len = 0; zval *repository; php_git2_repository *m_repository; diff --git a/repository.c b/repository.c index 2a5dbe5e56..4394677ad8 100644 --- a/repository.c +++ b/repository.c @@ -98,6 +98,8 @@ static int php_git2_repository_initialize(zval *object, git_repository *reposito add_property_string(object, "path", git_repository_path(repository),1); add_property_zval(object, "odb", odb); zval_ptr_dtor(&odb); + + return 0; } /* @@ -109,7 +111,6 @@ PHP_METHOD(git2_repository, __construct) int repository_path_len, ret = 0; git_repository *repository; php_git2_repository *m_repository; - zval *odb; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &repository_path, &repository_path_len) == FAILURE) { @@ -132,7 +133,6 @@ PHP_METHOD(git2_repository, __construct) */ PHP_METHOD(git2_repository, isEmpty) { - git_repository *repository; php_git2_repository *m_repository; m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); @@ -153,7 +153,6 @@ PHP_METHOD(git2_repository, isEmpty) */ PHP_METHOD(git2_repository, isBare) { - git_repository *repository; php_git2_repository *m_repository; m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); @@ -174,7 +173,6 @@ PHP_METHOD(git2_repository, isBare) */ PHP_METHOD(git2_repository, getPath) { - git_repository *repository; php_git2_repository *m_repository; const char *path = NULL; zval *m_path = NULL; @@ -198,7 +196,6 @@ PHP_METHOD(git2_repository, getPath) */ PHP_METHOD(git2_repository, getWorkdir) { - git_repository *repository; php_git2_repository *m_repository; const char *path = NULL; zval *m_path = NULL; @@ -255,7 +252,6 @@ PHP_METHOD(git2_repository, init) */ PHP_METHOD(git2_repository, headDetached) { - git_repository *repository; php_git2_repository *m_repository; m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); @@ -278,7 +274,6 @@ PHP_METHOD(git2_repository, headDetached) */ PHP_METHOD(git2_repository, headOrphan) { - git_repository *repository; php_git2_repository *m_repository; m_repository = PHP_GIT2_GET_OBJECT(php_git2_repository, getThis()); diff --git a/signature.c b/signature.c index 8427486c5d..6c8598cb2e 100644 --- a/signature.c +++ b/signature.c @@ -90,7 +90,7 @@ ZEND_END_ARG_INFO() PHP_METHOD(git2_signature, __construct) { char *name, *email; - int error, name_len, email_len = 0; + int name_len, email_len = 0; zval *date = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, diff --git a/tag.c b/tag.c index 21de02c3a5..358d935616 100644 --- a/tag.c +++ b/tag.c @@ -71,8 +71,6 @@ PHP_METHOD(git2_tag, getMessage) { php_git2_tag *m_tag; const char *message; - zval *result; - int error = 0; m_tag = PHP_GIT2_GET_OBJECT(php_git2_tag, getThis()); message = git_tag_message(m_tag->tag); @@ -86,9 +84,8 @@ PHP_METHOD(git2_tag, getMessage) */ PHP_METHOD(git2_tag, getBaseName) { - zval *result; const char *name = NULL; - const *basename = NULL; + char *basename = NULL; php_git2_tag *m_tag; size_t len; diff --git a/tests/002-07-commit_create.phpt b/tests/002-07-commit_create.phpt index e90f006970..48e0cc0448 100644 --- a/tests/002-07-commit_create.phpt +++ b/tests/002-07-commit_create.phpt @@ -42,7 +42,7 @@ echo PHP_EOL; printf("%s\n", $commit->getMessage()); `rm -rf {$path}`; --EXPECT-- -commit_id: 850e8fd947badfe89add66c0d8bf033231ae9b9d +commit_id: 239442d8e6cdbd904e150e25778cc45024b60d51 author: Shuhei Tanuma email: chobieee@gmail.com time: 1327164747 diff --git a/tree.c b/tree.c index 629ed97aaf..78fde4df42 100644 --- a/tree.c +++ b/tree.c @@ -123,7 +123,7 @@ PHP_METHOD(git2_tree, valid) m_tree = PHP_GIT2_GET_OBJECT(php_git2_tree, getThis()); entry_count = git_tree_entrycount(m_tree->tree); - if (m_tree->offset < entry_count && m_tree->offset >= 0) { + if (m_tree->offset < entry_count) { RETURN_TRUE; } else { RETURN_FALSE; diff --git a/tree_builder.c b/tree_builder.c index 4d765ba8f0..5d395758e2 100644 --- a/tree_builder.c +++ b/tree_builder.c @@ -120,7 +120,6 @@ PHP_METHOD(git2_tree_builder, remove) char *name; int name_len = 0; php_git2_tree_builder *m_builder; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { diff --git a/walker.c b/walker.c index 7fdbc8f8d7..5c8dcfc603 100644 --- a/walker.c +++ b/walker.c @@ -106,7 +106,6 @@ PHP_METHOD(git2_walker, sorting) { php_git2_walker *m_walker; long mode = GIT_SORT_NONE; - int error = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode) == FAILURE) { @@ -126,7 +125,6 @@ PHP_METHOD(git2_walker, push) php_git2_walker *m_walker; char *sha; int sha_len = 0; - int error = 0; git_oid oid; /* @todo: also supports Git2\Commit object */ @@ -152,7 +150,6 @@ PHP_METHOD(git2_walker, hide) php_git2_walker *m_walker; char *sha; int sha_len = 0; - int error = 0; git_oid oid; /* @todo: also supports Git2\Commit object */ From f804fa7514e2268939e1d24bb7494741e889c109 Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Tue, 7 Aug 2012 20:12:26 +0300 Subject: [PATCH 153/300] Updated libgit2 gitmodule scheme Updated libgit2 gitmodule scheme from git to https, because it doesn't work if you don't have send your public key to Github. --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 3a95da8561..30eb68a28c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "libgit2"] path = libgit2 - url = git@github.com:libgit2/libgit2.git + url = https://github.com/libgit2/libgit2.git From 003c2845aa4509e1cb8becc5d96427aea8a40254 Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Wed, 8 Aug 2012 11:33:09 +0200 Subject: [PATCH 154/300] Fixed methods name in README The methods Git2\Repository::isExist() and Git2\Repository::read() are no longer avalaible. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc02f48c89..ef2b4bd9ae 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ new php-git features almost tested. ````php $repo = new Git2\Repository($path); /* - bool = $repo->isExist(string sha1) - Git2\Object = $repo->read(string sha1) + 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() From 994eedcb0a72aea080554b8640bc60bf010d938b Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Wed, 8 Aug 2012 11:35:46 +0200 Subject: [PATCH 155/300] Fixed typo in comments --- repository.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/repository.c b/repository.c index 4394677ad8..41c3ff710c 100644 --- a/repository.c +++ b/repository.c @@ -103,7 +103,7 @@ static int php_git2_repository_initialize(zval *object, git_repository *reposito } /* -{{{ proto: Git2\Repsotiroy::__construct(string $path) +{{{ proto: Git2\Repository::__construct(string $path) */ PHP_METHOD(git2_repository, __construct) { @@ -129,7 +129,7 @@ PHP_METHOD(git2_repository, __construct) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::isEmpty() +{{{ proto: Git2\Repository::isEmpty() */ PHP_METHOD(git2_repository, isEmpty) { @@ -149,7 +149,7 @@ PHP_METHOD(git2_repository, isEmpty) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::isBare() +{{{ proto: Git2\Repository::isBare() */ PHP_METHOD(git2_repository, isBare) { @@ -169,7 +169,7 @@ PHP_METHOD(git2_repository, isBare) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::getPath() +{{{ proto: Git2\Repository::getPath() */ PHP_METHOD(git2_repository, getPath) { @@ -192,7 +192,7 @@ PHP_METHOD(git2_repository, getPath) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::getWorkdir() +{{{ proto: Git2\Repository::getWorkdir() */ PHP_METHOD(git2_repository, getWorkdir) { @@ -216,7 +216,7 @@ PHP_METHOD(git2_repository, getWorkdir) /* -{{{ proto: Git2\Repsotiroy::init(string $path [, bool isBare]) +{{{ proto: Git2\Repository::init(string $path [, bool isBare]) */ PHP_METHOD(git2_repository, init) { @@ -247,7 +247,7 @@ PHP_METHOD(git2_repository, init) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::headDetached() +{{{ 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) @@ -268,7 +268,7 @@ PHP_METHOD(git2_repository, headDetached) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::headOrphan() +{{{ 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. */ @@ -290,7 +290,7 @@ PHP_METHOD(git2_repository, headOrphan) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::discover(string $path[, bool across_fs, string ceiling_dirs]) +{{{ proto: Git2\Repository::discover(string $path[, bool across_fs, string ceiling_dirs]) */ PHP_METHOD(git2_repository, discover) { @@ -314,7 +314,7 @@ PHP_METHOD(git2_repository, discover) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::exists(string $sha1) +{{{ proto: Git2\Repository::exists(string $sha1) */ PHP_METHOD(git2_repository, exists) { @@ -347,7 +347,7 @@ PHP_METHOD(git2_repository, exists) /* -{{{ proto: Git2\Repsotiroy::lookup(string $sha1[, int type = GIT_OBJ_ANY]) +{{{ proto: Git2\Repository::lookup(string $sha1[, int type = GIT_OBJ_ANY]) */ PHP_METHOD(git2_repository, lookup) { @@ -385,7 +385,7 @@ PHP_METHOD(git2_repository, lookup) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::write(string $contents, int $type) +{{{ proto: Git2\Repository::write(string $contents, int $type) */ PHP_METHOD(git2_repository, write) { @@ -423,7 +423,7 @@ PHP_METHOD(git2_repository, write) /* }}} */ /* -{{{ proto: Git2\Repsotiroy::hash(string $contents, int $type) +{{{ proto: Git2\Repository::hash(string $contents, int $type) */ PHP_METHOD(git2_repository, hash) { From 1b11198fbff5e1e10728056ed5b0baded0582f9a Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 9 Aug 2012 00:13:45 +0900 Subject: [PATCH 156/300] fixed #32. add missing PHP_ADD_INCLUDE macro --- config.m4 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.m4 b/config.m4 index 373b69d815..bfad160cbe 100644 --- a/config.m4 +++ b/config.m4 @@ -26,6 +26,8 @@ if test $PHP_GIT2 != "no"; then backend.c \ , $ext_shared) + PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) + 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" PHP_SUBST([CFLAGS]) From f9fcdc98928e78b9f09dbfe2f09600420a07fe75 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 9 Aug 2012 00:35:50 +0900 Subject: [PATCH 157/300] phipze: remove unused args. --- config.m4 | 3 --- 1 file changed, 3 deletions(-) diff --git a/config.m4 b/config.m4 index bfad160cbe..008cc22965 100644 --- a/config.m4 +++ b/config.m4 @@ -1,9 +1,6 @@ PHP_ARG_ENABLE(git2, Whether to enable the "git2" extension, [ --enable-git2 Enable "php-git2" extension support]) -PHP_ARG_WITH(libgit2-dir, for libgit2, - [ --with-libgit2-dir[=DIR] Set the path to libgit2 install prefix.], yes) - if test $PHP_GIT2 != "no"; then PHP_SUBST(GIT2_SHARED_LIBADD) PHP_NEW_EXTENSION(git2, git2.c \ From a6e35a2a3674cac5a9d84dfb46d5800d64b4af7b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 9 Aug 2012 00:36:28 +0900 Subject: [PATCH 158/300] phpize: fix tabs --- config.m4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.m4 b/config.m4 index 008cc22965..47874bddb5 100644 --- a/config.m4 +++ b/config.m4 @@ -25,8 +25,8 @@ if test $PHP_GIT2 != "no"; then PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) - 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" - PHP_SUBST([CFLAGS]) + 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" + PHP_SUBST([CFLAGS]) ifdef([PHP_ADD_EXTENSION_DEP], [ From 9d254e0b59fa5c48a12753c074a6b7bffd298a5b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 9 Aug 2012 00:38:22 +0900 Subject: [PATCH 159/300] update contributors. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ef2b4bd9ae..b970b5e071 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ $remote->fetch(); * Cameron Eagans * Graham Weldon * James Titcumb +* Matthieu Moquet * Ryusuke SEKIYAMA * Shuhei Tanuma * Vasileios Georgitzikis From 3d6d07f3fd1115c613c16dca610c28e919b60e1b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 9 Aug 2012 00:45:21 +0900 Subject: [PATCH 160/300] threads: call threads_init and threads_shutdown on each RINIT and RSHUTDOWN --- git2.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/git2.c b/git2.c index b9a32cdd80..2c5c9600f6 100644 --- a/git2.c +++ b/git2.c @@ -246,6 +246,19 @@ PHP_MINFO_FUNCTION(git2) 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, @@ -254,8 +267,8 @@ zend_module_entry git2_module_entry = { NULL, /* Functions */ PHP_MINIT(git2), /* MINIT */ NULL, /* MSHUTDOWN */ - NULL, /* RINIT */ - NULL, /* RSHUTDOWN */ + PHP_RINIT(git2), /* RINIT */ + PHP_RSHUTDOWN(git2),/* RSHUTDOWN */ PHP_MINFO(git2), /* MFINFO */ #if ZEND_MODULE_API_NO >= 20010901 PHP_GIT2_EXTVER, From 5f495c2e4dfcd336375d2356cca95b2a12adea53 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 9 Aug 2012 01:19:15 +0900 Subject: [PATCH 161/300] fix several compile warnings --- backend.c | 15 +++++++-------- commit.c | 4 ++-- config.c | 3 ++- php_git2.h | 1 + tree.c | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend.c b/backend.c index 897228362c..593a93f2e4 100644 --- a/backend.c +++ b/backend.c @@ -55,10 +55,9 @@ static int php_git2_backend_exists(git_odb_backend *_backend, const git_oid *oid 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, **value; + zval *z_id, *z_buffer, *z_size, *z_type, *retval; int error = GIT_ERROR; char t_id[GIT_OID_HEXSZ] = {0}; - TSRMLS_FETCH(); php_git2_backend_internal *backend; MAKE_STD_ZVAL(z_id); @@ -101,7 +100,7 @@ static int php_git2_backend_read(void **buffer,size_t *size, git_otype *type, gi git_oid_fmt(out, id); ZVAL_STRING(z_oid, out, 1); - ZVAL_LONG(z_type, type); + 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); @@ -116,7 +115,7 @@ static int php_git2_backend_read(void **buffer,size_t *size, git_otype *type, gi } if (zend_hash_find(hash,"size",sizeof("size"),(void **)&value_pp) != FAILURE) { - size = *value_pp; + z_size = *value_pp; } *buffer = estrndup(Z_STRVAL_P(data),Z_STRLEN_P(data)); @@ -136,7 +135,7 @@ static int php_git2_backend_read_header(size_t *size, git_otype *type, git_odb_b TSRMLS_FETCH(); zval *retval, *z_oid, *z_type; php_git2_backend_internal *m_backend; - const char out[GIT_OID_HEXSZ] = {0}; + char out[GIT_OID_HEXSZ] = {0}; int result = GIT_ERROR; MAKE_STD_ZVAL(z_oid); @@ -170,12 +169,12 @@ static int php_git2_backend_read_header(size_t *size, git_otype *type, git_odb_b 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,unsigned int length) +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; - const char out[GIT_OID_HEXSZ+1] = {0}; + char out[GIT_OID_HEXSZ+1] = {0}; int result = GIT_ERROR; MAKE_STD_ZVAL(z_oid); @@ -196,7 +195,7 @@ static int php_git2_backend_read_prefix(git_oid *id,void ** buffer, size_t * siz } if (zend_hash_find(hash,"size",sizeof("size"),(void **)&value_pp) != FAILURE) { - size = *value_pp; + z_size = *value_pp; } if (zend_hash_find(hash,"oid",sizeof("oid"),(void **)&value_pp) != FAILURE) { diff --git a/commit.c b/commit.c index bad3e24181..23b7656895 100644 --- a/commit.c +++ b/commit.c @@ -386,7 +386,7 @@ PHP_METHOD(git2_commit, getParents) 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), parent TSRMLS_CC); + tmp = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), (git_object*)parent TSRMLS_CC); add_next_index_zval(result, tmp); } } @@ -432,7 +432,7 @@ PHP_METHOD(git2_commit, getParent) 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), parent TSRMLS_CC); + result = php_git2_object_new(git_object_owner((git_object *)m_commit->commit), (git_object*)parent TSRMLS_CC); RETVAL_ZVAL(result,0,1); } } else { diff --git a/config.c b/config.c index ee55cc3de9..715851b350 100644 --- a/config.c +++ b/config.c @@ -92,7 +92,6 @@ static zval* php_git2_config_read_dimension(zval *object, zval *offset, int type { zval *entry, *tmp_result, **target_offset; char *current_key, *tmp_value, *savedptr, *k; - int error = 0; entry = zend_read_property(git2_config_class_entry, object,"configs",sizeof("configs")-1, 0 TSRMLS_CC); @@ -279,6 +278,8 @@ static int php_git2_config_reload(zval *object, unsigned short dtor TSRMLS_DC) if (dtor == 1) { zval_ptr_dtor(&entry); } + + return 0; } static void php_git2_config_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) diff --git a/php_git2.h b/php_git2.h index e2e0758cec..53fc14f1df 100644 --- a/php_git2.h +++ b/php_git2.h @@ -36,6 +36,7 @@ # 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 diff --git a/tree.c b/tree.c index 78fde4df42..270b31ef35 100644 --- a/tree.c +++ b/tree.c @@ -135,7 +135,7 @@ PHP_METHOD(git2_tree, valid) static int get_subtree(git_tree **result, git_tree *root, char *path) { char *p, *k, *current_key, *tmp_value, *savedptr = NULL; - git_tree_entry *entry; + const git_tree_entry *entry; git_tree *target,*tmp_result; int error = 0; From fe4cb28947a9e2cafafb98db6c97c87187d69a7b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Thu, 9 Aug 2012 01:26:26 +0900 Subject: [PATCH 162/300] phpize: don't add static lib directoly. use PHP_ADD_LIBLARY --- config.m4 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config.m4 b/config.m4 index 47874bddb5..827e609975 100644 --- a/config.m4 +++ b/config.m4 @@ -25,7 +25,9 @@ if test $PHP_GIT2 != "no"; then PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include]) - 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" + CFLAGS=" $CFLAGS -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Winline -Wunused-macros -Wredundant-decls -Wstrict-aliasing=2 -Wswitch-enum -Wdeclaration-after-statement" + 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], From 8aa140f17932c730daa5afb44c440e4ba527a800 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 27 Aug 2012 21:20:59 +0900 Subject: [PATCH 163/300] add Git2\Repository::getMergeBase method --- repository.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/repository.c b/repository.c index 41c3ff710c..cb77cd19a3 100644 --- a/repository.c +++ b/repository.c @@ -76,6 +76,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_repository_hash, 0,0,2) 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) @@ -346,6 +351,44 @@ PHP_METHOD(git2_repository, exists) /* }}} */ +/* +{{{ 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]) */ @@ -465,8 +508,9 @@ static zend_function_entry php_git2_repository_methods[] = { 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, 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) #ifdef lookup #undef lookup #endif From 5531c47e2e88b4f4abfe7a7ae0d077274e1f25cc Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 27 Aug 2012 23:46:44 +0900 Subject: [PATCH 164/300] revwalk: fix #34 problem. * Git2\Revwalk::rewind completely broken (ignores any hided commits, didn't push, hide correctly) --- php_git2.h | 8 ++ tests/008-02-walker_itrate.phpt | 22 ++++ walker.c | 185 +++++++++++++++++++++++++++----- 3 files changed, 187 insertions(+), 28 deletions(-) diff --git a/php_git2.h b/php_git2.h index 53fc14f1df..19b304220d 100644 --- a/php_git2.h +++ b/php_git2.h @@ -107,11 +107,19 @@ typedef struct{ 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{ diff --git a/tests/008-02-walker_itrate.phpt b/tests/008-02-walker_itrate.phpt index 79b713a36d..6e3c9a825e 100644 --- a/tests/008-02-walker_itrate.phpt +++ b/tests/008-02-walker_itrate.phpt @@ -13,6 +13,14 @@ 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 @@ -23,5 +31,19 @@ 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/walker.c b/walker.c index 5c8dcfc603..22b68dcd8c 100644 --- a/walker.c +++ b/walker.c @@ -25,11 +25,76 @@ #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; @@ -39,6 +104,11 @@ static void php_git2_walker_free_storage(php_git2_walker *object TSRMLS_DC) 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; @@ -51,8 +121,11 @@ 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; } @@ -93,8 +166,9 @@ PHP_METHOD(git2_walker, __construct) error = git_revwalk_new(&m_walker->walker, m_repository->repository); if (error != GIT_OK) { - /* @todo error handling */ + zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "can't create a Git2\\Walker instance."); } + m_walker->repository = m_repository->repository; } /* }}} */ @@ -124,8 +198,8 @@ PHP_METHOD(git2_walker, push) { php_git2_walker *m_walker; char *sha; - int sha_len = 0; - git_oid oid; + 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, @@ -134,11 +208,17 @@ PHP_METHOD(git2_walker, push) } m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); + elm = emalloc(sizeof(php_git2_revwalk_element)); + elm->interested = 1; - git_oid_fromstrn(&oid, sha, sha_len); - git_revwalk_reset(m_walker->walker); - git_revwalk_push(m_walker->walker, &oid); - memcpy(m_walker->current, &oid, sizeof(git_oid)); + 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); } /* }}} */ @@ -149,8 +229,9 @@ PHP_METHOD(git2_walker, hide) { php_git2_walker *m_walker; char *sha; - int sha_len = 0; + 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, @@ -159,8 +240,16 @@ PHP_METHOD(git2_walker, hide) } m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - git_oid_fromstrn(&oid, sha, sha_len); - git_revwalk_hide(m_walker->walker, &oid); + 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); } /* }}} */ @@ -171,9 +260,18 @@ PHP_METHOD(git2_walker, hide) PHP_METHOD(git2_walker, reset) { php_git2_walker *m_walker; + int i = 0; - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); + 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); } /* }}} */ @@ -191,9 +289,10 @@ PHP_METHOD(git2_walker, current) 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); + + 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); + RETVAL_ZVAL(result, 0, 1); } /* @@ -203,22 +302,26 @@ 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()); + m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); git_oid_fmt(out, m_walker->current); - RETURN_STRINGL(out,GIT_OID_HEXSZ,1); + + RETURN_STRINGL(out, GIT_OID_HEXSZ, 1); } /* -{{{ proto: Git2\Walker::valid() +{{{ 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()); + 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; @@ -231,16 +334,42 @@ PHP_METHOD(git2_walker, next) PHP_METHOD(git2_walker, rewind) { php_git2_walker *m_walker; - - m_walker = PHP_GIT2_GET_OBJECT(php_git2_walker, getThis()); - git_revwalk_reset(m_walker->walker); - if (m_walker->current == NULL) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, - "does not specify interested hash before calling Git2\\Walker::rewind."); - RETURN_FALSE; + 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."); + } } - git_revwalk_push(m_walker->walker, m_walker->current); - git_revwalk_next(m_walker->current, m_walker->walker); + } /* @@ -249,8 +378,8 @@ PHP_METHOD(git2_walker, rewind) 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 { From 1cf68604eeceb639be67872ac19945c94103b4a1 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 24 Sep 2012 22:03:06 +0900 Subject: [PATCH 165/300] 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 166/300] 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 167/300] 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 168/300] 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 169/300] - 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 170/300] 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 171/300] 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 172/300] 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 @@ -xAN0 Y#}%q'B..DԦW`9o1z#m@8@HR#a0),56/H9t|>Ԛ%(8RSUr,c kZm/ޯv>1xyHo0R /޻{±)&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 @@ -xM -0F]$.ݨHg0=>MMS}$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 173/300] 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 174/300] 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 175/300] 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 176/300] 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 177/300] [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 178/300] 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 179/300] 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 180/300] [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 181/300] [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 182/300] [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 183/300] 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 184/300] [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 185/300] [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 186/300] [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 187/300] 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 188/300] [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 189/300] 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 190/300] 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 191/300] [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 192/300] [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 193/300] [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 194/300] [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 195/300] [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 196/300] [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 197/300] [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 198/300] [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 199/300] 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 200/300] [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 201/300] [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 202/300] 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 203/300] 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 204/300] [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 205/300] [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 206/300] [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 207/300] [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 208/300] [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 209/300] [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 210/300] [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 211/300] [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 212/300] [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 213/300] 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 214/300] 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 215/300] 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 216/300] 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 217/300] 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 218/300] 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 219/300] 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 220/300] 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 221/300] 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 222/300] 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 223/300] 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 224/300] [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 225/300] 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 226/300] 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 227/300] 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 228/300] 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 229/300] 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 230/300] 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 231/300] [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 232/300] [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 233/300] 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 234/300] [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 235/300] 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 236/300] [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 237/300] 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 238/300] 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 239/300] [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 240/300] 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 241/300] 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 242/300] 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 243/300] 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 244/300] [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 245/300] 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 246/300] 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 247/300] [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 248/300] [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 249/300] [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 250/300] 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 251/300] 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 252/300] [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 253/300] 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 254/300] [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 255/300] [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 256/300] [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 257/300] [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 258/300] [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 259/300] [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 260/300] [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 261/300] 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 262/300] 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 263/300] 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 264/300] [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 265/300] [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 266/300] [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 267/300] [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 268/300] [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 269/300] [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 270/300] [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 271/300] 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 272/300] [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 273/300] [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 274/300] [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 275/300] [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 276/300] [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 277/300] [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 278/300] [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 279/300] [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 280/300] [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 281/300] 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 282/300] [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 283/300] [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 284/300] [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 285/300] 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 286/300] [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 287/300] 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 288/300] [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 289/300] 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 290/300] 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 291/300] 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 292/300] 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 293/300] 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 294/300] 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 295/300] 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 296/300] 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 297/300] 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 298/300] 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 299/300] 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 300/300] 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