|
2 | 2 | #include "php_git2_priv.h"
|
3 | 3 | #include "repository.h"
|
4 | 4 |
|
| 5 | +static int php_git2_repository_fetchhead_foreach_cb(const char *ref_name, |
| 6 | + const char *remote_url, |
| 7 | + const git_oid *oid, |
| 8 | + unsigned int is_merge, |
| 9 | + void *payload) |
| 10 | +{ |
| 11 | + php_git2_t *result; |
| 12 | + zval *param_ref_name, *param_remote_url, *param_oid, *param_is_merge, *retval_ptr = NULL; |
| 13 | + php_git2_cb_t *p = (php_git2_cb_t*)payload; |
| 14 | + int i = 0; |
| 15 | + long retval = 0; |
| 16 | + char _oid[41] = {0}; |
| 17 | + GIT2_TSRMLS_SET(p->tsrm_ls) |
| 18 | + |
| 19 | + git_oid_fmt(_oid, oid); |
| 20 | + |
| 21 | + Z_ADDREF_P(p->payload); |
| 22 | + MAKE_STD_ZVAL(param_ref_name); |
| 23 | + MAKE_STD_ZVAL(param_remote_url); |
| 24 | + MAKE_STD_ZVAL(param_oid); |
| 25 | + MAKE_STD_ZVAL(param_is_merge); |
| 26 | + ZVAL_STRING(param_ref_name, ref_name, 1); |
| 27 | + ZVAL_STRING(param_remote_url, remote_url, 1); |
| 28 | + ZVAL_STRING(param_oid, _oid, 1); |
| 29 | + ZVAL_BOOL(param_is_merge, is_merge); |
| 30 | + |
| 31 | + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 5, |
| 32 | + ¶m_ref_name, |
| 33 | + ¶m_remote_url, |
| 34 | + ¶m_oid, |
| 35 | + ¶m_is_merge, |
| 36 | + &p->payload)) { |
| 37 | + return GIT_EUSER; |
| 38 | + } |
| 39 | + |
| 40 | + retval = Z_LVAL_P(retval_ptr); |
| 41 | + zval_ptr_dtor(&retval_ptr); |
| 42 | + return retval; |
| 43 | +} |
| 44 | + |
| 45 | +static int php_git2_repository_mergehead_foreach_cb(const git_oid *oid, |
| 46 | + void *payload) |
| 47 | +{ |
| 48 | + php_git2_t *result; |
| 49 | + zval *param_oid, *retval_ptr = NULL; |
| 50 | + php_git2_cb_t *p = (php_git2_cb_t*)payload; |
| 51 | + int i = 0; |
| 52 | + long retval = 0; |
| 53 | + char _oid[41] = {0}; |
| 54 | + GIT2_TSRMLS_SET(p->tsrm_ls) |
| 55 | + |
| 56 | + git_oid_fmt(_oid, oid); |
| 57 | + |
| 58 | + Z_ADDREF_P(p->payload); |
| 59 | + MAKE_STD_ZVAL(param_oid); |
| 60 | + ZVAL_STRING(param_oid, _oid, 1); |
| 61 | + |
| 62 | + if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, ¶m_oid, &p->payload)) { |
| 63 | + return GIT_EUSER; |
| 64 | + } |
| 65 | + |
| 66 | + retval = Z_LVAL_P(retval_ptr); |
| 67 | + zval_ptr_dtor(&retval_ptr); |
| 68 | + return retval; |
| 69 | +} |
| 70 | + |
5 | 71 | /* {{{ proto resource git_repository_new()
|
6 | 72 | */
|
7 | 73 | PHP_FUNCTION(git_repository_new)
|
@@ -601,48 +667,58 @@ PHP_FUNCTION(git_repository_merge_cleanup)
|
601 | 667 | }
|
602 | 668 | /* }}} */
|
603 | 669 |
|
604 |
| - |
605 |
| -/* {{{ proto long git_repository_fetchhead_foreach(repo, callback, payload) |
606 |
| -*/ |
| 670 | +/* {{{ proto long git_repository_fetchhead_foreach(resource $repo, Callable $callback, $payload) |
| 671 | + */ |
607 | 672 | PHP_FUNCTION(git_repository_fetchhead_foreach)
|
608 | 673 | {
|
609 |
| - zval *repo; |
610 |
| - php_git2_t *_repo; |
611 |
| - zval *callback; |
612 |
| - php_git2_t *_callback; |
613 |
| - zval *payload; |
614 |
| - |
615 |
| - /* TODO(chobie): implement this */ |
616 |
| - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_fetchhead_foreach not implemented yet"); |
617 |
| - return; |
| 674 | + int result = 0, error = 0; |
| 675 | + zval *repo = NULL, *callback = NULL, *payload = NULL; |
| 676 | + php_git2_t *_repo = NULL; |
| 677 | + zend_fcall_info fci = empty_fcall_info; |
| 678 | + zend_fcall_info_cache fcc = empty_fcall_info_cache; |
| 679 | + php_git2_cb_t *cb = NULL; |
618 | 680 |
|
619 | 681 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
620 |
| - "rrz", &repo, &callback, &payload) == FAILURE) { |
| 682 | + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { |
621 | 683 | return;
|
622 | 684 | }
|
| 685 | + |
623 | 686 | ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
|
| 687 | + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { |
| 688 | + RETURN_FALSE; |
| 689 | + } |
| 690 | + result = git_repository_fetchhead_foreach(PHP_GIT2_V(_repo, repository), php_git2_repository_fetchhead_foreach_cb, cb); |
| 691 | + php_git2_cb_free(cb); |
| 692 | + RETURN_LONG(result); |
624 | 693 | }
|
| 694 | +/* }}} */ |
625 | 695 |
|
626 |
| -/* {{{ proto long git_repository_mergehead_foreach(repo, callback, payload) |
627 |
| -*/ |
| 696 | +/* {{{ proto long git_repository_mergehead_foreach(resource $repo, Callable $callback, $payload) |
| 697 | + */ |
628 | 698 | PHP_FUNCTION(git_repository_mergehead_foreach)
|
629 | 699 | {
|
630 |
| - zval *repo; |
631 |
| - php_git2_t *_repo; |
632 |
| - zval *callback; |
633 |
| - php_git2_t *_callback; |
634 |
| - zval *payload; |
635 |
| - |
636 |
| - /* TODO(chobie): implement this */ |
637 |
| - php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_repository_mergehead_foreach not implemented yet"); |
638 |
| - return; |
| 700 | + int result = 0, error = 0; |
| 701 | + zval *repo = NULL, *callback = NULL, *payload = NULL; |
| 702 | + php_git2_t *_repo = NULL; |
| 703 | + zend_fcall_info fci = empty_fcall_info; |
| 704 | + zend_fcall_info_cache fcc = empty_fcall_info_cache; |
| 705 | + php_git2_cb_t *cb = NULL; |
639 | 706 |
|
640 | 707 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
641 |
| - "rrz", &repo, &callback, &payload) == FAILURE) { |
| 708 | + "rfz", &repo, &fci, &fcc, &payload) == FAILURE) { |
642 | 709 | return;
|
643 | 710 | }
|
| 711 | + |
644 | 712 | ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
|
| 713 | + if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) { |
| 714 | + RETURN_FALSE; |
| 715 | + } |
| 716 | + result = git_repository_mergehead_foreach(PHP_GIT2_V(_repo, repository), php_git2_repository_mergehead_foreach_cb, cb); |
| 717 | + php_git2_cb_free(cb); |
| 718 | + RETURN_LONG(result); |
645 | 719 | }
|
| 720 | +/* }}} */ |
| 721 | + |
646 | 722 |
|
647 | 723 | /* {{{ proto resource git_repository_hashfile(repo, path, type, as_path)
|
648 | 724 | */
|
|
0 commit comments