-
Notifications
You must be signed in to change notification settings - Fork 78
/
checkout.c
91 lines (75 loc) · 2.55 KB
/
checkout.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
#include "php_git2.h"
#include "php_git2_priv.h"
#include "checkout.h"
/* {{{ proto long git_checkout_head(resource $repo, $opts)
*/
PHP_FUNCTION(git_checkout_head)
{
zval *opts = NULL, *repo = NULL;
php_git2_t *_repo = NULL;
int result = 0, shoud_free = 0;
git_checkout_opts *options;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"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), options);
if (shoud_free) {
php_git_git_checkout_opts_free(options TSRMLS_CC);
}
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_checkout_index(resource $repo, resource $index, $opts)
*/
PHP_FUNCTION(git_checkout_index)
{
int result = 0;
zval *repo = NULL, *index = NULL, *opts = NULL;
php_git2_t *_repo = NULL, *_index = NULL;
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_checkout_index(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_index, index), opts);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_checkout_tree(resource $repo, resource $treeish, $opts)
*/
PHP_FUNCTION(git_checkout_tree)
{
int result = 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,
"rra", &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);
RETURN_LONG(result);
}
/* }}} */