@@ -49,6 +49,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git2_commit_create, 0,0,2)
4949 ZEND_ARG_INFO (0 , data )
5050ZEND_END_ARG_INFO ()
5151
52+ ZEND_BEGIN_ARG_INFO_EX (arginfo_git2_commit_get_parent , 0 ,0 ,1 )
53+ ZEND_ARG_INFO (0 , index )
54+ ZEND_END_ARG_INFO ()
55+
5256/*
5357{{{ proto: Git2\Commit::getMessage()
5458*/
@@ -363,6 +367,113 @@ PHP_METHOD(git2_commit, getTree)
363367}
364368/* }}} */
365369
370+ /*
371+ {{{ proto: Git2\Commit::getParents()
372+ */
373+ PHP_METHOD (git2_commit , getParents )
374+ {
375+ php_git2_commit * m_commit ;
376+ unsigned int parent_count = 0 ;
377+ int error , i = 0 ;
378+ zval * result ;
379+
380+ m_commit = PHP_GIT2_GET_OBJECT (php_git2_commit , getThis ());
381+
382+ if (m_commit != NULL ) {
383+ if (m_commit -> commit == NULL ) {
384+ RETURN_FALSE ;
385+ }
386+
387+ parent_count = git_commit_parentcount (m_commit -> commit );
388+ MAKE_STD_ZVAL (result );
389+ array_init (result );
390+ for (i = 0 ; i < parent_count ; i ++ ) {
391+ git_commit * parent = NULL ;
392+ zval * tmp = NULL ;
393+
394+ error = git_commit_parent (& parent , m_commit -> commit , i );
395+ if (error == GIT_SUCCESS ) {
396+ tmp = php_git2_object_new (git_object_owner ((git_object * )m_commit -> commit ), parent TSRMLS_CC );
397+ add_next_index_zval (result , tmp );
398+ }
399+ }
400+
401+ RETVAL_ZVAL (result ,0 ,1 );
402+ } else {
403+ RETURN_FALSE ;
404+ }
405+ }
406+ /* }}} */
407+
408+ /*
409+ {{{ proto: Git2\Commit::getParent([int index])
410+ */
411+ PHP_METHOD (git2_commit , getParent )
412+ {
413+ php_git2_commit * m_commit ;
414+ unsigned int parent_count = 0 ;
415+ int error , i = 0 ;
416+ long index = 0 ;
417+ zval * result ;
418+ git_commit * parent = NULL ;
419+
420+
421+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
422+ "|l" , & index ) == FAILURE ) {
423+ return ;
424+ }
425+
426+
427+ m_commit = PHP_GIT2_GET_OBJECT (php_git2_commit , getThis ());
428+
429+ if (m_commit != NULL ) {
430+ if (m_commit -> commit == NULL ) {
431+ RETURN_FALSE ;
432+ }
433+
434+ parent_count = git_commit_parentcount (m_commit -> commit );
435+ if (index > (parent_count - 1 ) || index < 0 ) {
436+ /* @todo: throws invalidargument exception */
437+ RETURN_FALSE ;
438+ }
439+
440+ error = git_commit_parent (& parent , m_commit -> commit , (unsigned int )index );
441+ if (error == GIT_SUCCESS ) {
442+ result = php_git2_object_new (git_object_owner ((git_object * )m_commit -> commit ), parent TSRMLS_CC );
443+ RETVAL_ZVAL (result ,0 ,1 );
444+ }
445+ } else {
446+ RETURN_FALSE ;
447+ }
448+ }
449+ /* }}} */
450+
451+ /*
452+ {{{ proto: Git2\Commit::getParentCount()
453+ */
454+ PHP_METHOD (git2_commit , getParentCount )
455+ {
456+ php_git2_commit * m_commit ;
457+ unsigned int parent_count = 0 ;
458+ int error , i = 0 ;
459+ zval * result ;
460+ git_commit * parent = NULL ;
461+
462+ m_commit = PHP_GIT2_GET_OBJECT (php_git2_commit , getThis ());
463+
464+ if (m_commit != NULL ) {
465+ if (m_commit -> commit == NULL ) {
466+ RETURN_FALSE ;
467+ }
468+
469+ parent_count = git_commit_parentcount (m_commit -> commit );
470+ RETURN_LONG (parent_count );
471+ } else {
472+ RETURN_FALSE ;
473+ }
474+ }
475+ /* }}} */
476+
366477
367478static zend_function_entry php_git2_commit_methods [] = {
368479 PHP_ME (git2_commit , getMessage , NULL , ZEND_ACC_PUBLIC )
@@ -372,6 +483,9 @@ static zend_function_entry php_git2_commit_methods[] = {
372483 PHP_ME (git2_commit , getCommitter , NULL , ZEND_ACC_PUBLIC )
373484 PHP_ME (git2_commit , getOid , NULL , ZEND_ACC_PUBLIC )
374485 PHP_ME (git2_commit , getTree , NULL , ZEND_ACC_PUBLIC )
486+ PHP_ME (git2_commit , getParentCount , NULL , ZEND_ACC_PUBLIC )
487+ PHP_ME (git2_commit , getParent , arginfo_git2_commit_get_parent , ZEND_ACC_PUBLIC )
488+ PHP_ME (git2_commit , getParents , NULL , ZEND_ACC_PUBLIC )
375489 PHP_ME (git2_commit , create , arginfo_git2_commit_create , ZEND_ACC_STATIC | ZEND_ACC_PUBLIC )
376490 {NULL ,NULL ,NULL }
377491};
0 commit comments