libgit2 / php-git

PHP bindings for libgit2
http://libgit2.github.com
MIT License
565 stars 118 forks source link

git_reference_create_oid method signature changed #11

Closed asgrim closed 13 years ago

asgrim commented 13 years ago

I tried to compile php-git with latest git clone of libgit2, and it worked except for:

/home/james/workspace/php-git/src/reference_manager.c:246: error: too few arguments to function ‘git_reference_create_oid’

I had a quick dig around and it turns out in libgit2 a parameter has been added.

diff --git a/src/reference_manager.c b/src/reference_manager.c
index 2786998..beec6ce 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");

This seemed to work and I got the php-git-sample app working - however I'm not experienced enough to know whether this "force" value should be 1 or 0...

asgrim commented 13 years ago

I have made a fix for this but not made a pull request yet as I'm not sure whether force should be 1 or 0 yet. on a branch: https://github.com/Asgrim/php-git/tree/fix-git_reference_create_oid-signature-bug

Commit: Asgrim/php-git@9528478a1130b537f51f30b1ae482cecf5a39f78

chobie commented 13 years ago

Hi James, thank you for suggesting me.

when it specified 0, git_reference_create_oid will return some sort of error when specified reference has already registered. otherwise, force create a reference.

so, we should change that signature like following sample.

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()
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 oid_len = 0;
    git_oid id;
    int force = 0;

    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
        "ssl", &name, &name_len, &oid, &oid_len, &force) == FAILURE){
        return;
    }
    //...

anyway, i'll look for your commit and libgit2 changes when i came back home (AM8 in Japan, right now). please send pull request me.

thanks, Shuhei

asgrim commented 13 years ago

Pull request made in #12 !