-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrevparse.c
122 lines (97 loc) · 2.84 KB
/
revparse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "php_git2.h"
#include "php_git2_priv.h"
#include "revparse.h"
/* {{{ proto resource git_revparse_single(resource $repo, string $spec)
*/
PHP_FUNCTION(git_revparse_single)
{
php_git2_t *result = NULL, *_repo = NULL;
git_object *out = NULL;
zval *repo = NULL;
char *spec = NULL;
size_t spec_len;
int error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs", &repo, &spec, &spec_len) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_revparse_single(&out, PHP_GIT2_V(_repo, repository), spec);
if (php_git2_check_error(error, "git_revparse_single" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
RETURN_RES(GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto array git_revparse_ext(resource $repo, string $spec)
*/
PHP_FUNCTION(git_revparse_ext)
{
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;
size_t spec_len;
int error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs", &repo, &spec, &spec_len) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
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;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, object_out, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RES(a, GIT2_RVAL_P(result));
if (php_git2_make_resource(&result2, PHP_GIT2_TYPE_REFERENCE, reference_out, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RES(b, GIT2_RVAL_P(result2));
array_init(array);
add_next_index_zval(array, a);
add_next_index_zval(array, b);
RETURN_ZVAL(array, 0, 1);
}
/* }}} */
/* {{{ proto array git_revparse(resource $repo, string $spec)
*/
PHP_FUNCTION(git_revparse)
{
git_revspec *revspec = NULL;
zval *repo = NULL;
php_git2_t *_repo = NULL;
char *spec = NULL;
size_t spec_len;
int error;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs", &repo, &spec, &spec_len) == FAILURE) {
return;
}
if ((_repo = (php_git2_t *) zend_fetch_resource(Z_RES_P(repo), PHP_GIT2_RESOURCE_NAME, git2_resource_handle)) == NULL) {
RETURN_FALSE;
}
error = git_revparse(revspec, PHP_GIT2_V(_repo, repository), spec);
if (php_git2_check_error(error, "git_revparse" TSRMLS_CC)) {
RETURN_FALSE;
}
if (revspec == NULL) {
RETURN_FALSE;
}
array_init(return_value);
php_git2_git_revspec_to_array(revspec, return_value TSRMLS_CC);
RETVAL_ARR(Z_ARRVAL_P(return_value));
}
/* }}} */