Skip to content

Commit 384367d

Browse files
committed
[indexer] update code base
1 parent bc11496 commit 384367d

File tree

4 files changed

+92
-71
lines changed

4 files changed

+92
-71
lines changed

indexer.c

+76-59
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,119 @@
22
#include "php_git2_priv.h"
33
#include "indexer.h"
44

5-
/* {{{ proto resource git_indexer_new(path, mode, odb, progress_cb, progress_cb_payload)
6-
*/
5+
/* {{{ proto resource git_indexer_new(string $path, long $mode, resource $odb, $progress_cb, $progress_cb_payload)
6+
*/
77
PHP_FUNCTION(git_indexer_new)
88
{
9-
char *path = {0};
10-
int path_len;
11-
long mode;
12-
zval *odb;
13-
php_git2_t *_odb;
14-
zval *progress_cb;
15-
php_git2_t *_progress_cb;
9+
php_git2_t *result = NULL, *_odb = NULL;
10+
git_indexer *out = NULL;
11+
char *path = NULL;
12+
int path_len = 0, error = 0;
13+
long mode = 0;
14+
zval *odb = NULL, *progress_cb = NULL, *progress_cb_payload = NULL;
15+
zend_fcall_info fci = empty_fcall_info;
16+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
17+
php_git2_cb_t *cb = NULL;
1618

17-
/* TODO(chobie): implement this */
18-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_new not implemented yet");
19-
return;
19+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
20+
"slrfz", &path, &path_len, &mode, &odb, &fci, &fcc, &progress_cb_payload) == FAILURE) {
21+
return;
22+
}
2023

21-
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
22-
// "slrr", &path, &path_len, &mode, &odb, &progress_cb, &progress_cb_payload) == FAILURE) {
23-
// return;
24-
// }
25-
// ZEND_FETCH_RESOURCE(_path, php_git2_t*, &path, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
24+
ZEND_FETCH_RESOURCE(_odb, php_git2_t*, &odb, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
25+
if (php_git2_cb_init(&cb, &fci, &fcc, progress_cb_payload TSRMLS_CC)) {
26+
RETURN_FALSE;
27+
}
28+
//error = git_indexer_new(&out, path, mode, PHP_GIT2_V(_odb, odb), progress_cb, cb);
29+
if (php_git2_check_error(error, "git_indexer_new" TSRMLS_CC)) {
30+
RETURN_FALSE;
31+
}
32+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEXER, out, 1 TSRMLS_CC)) {
33+
RETURN_FALSE;
34+
}
35+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
2636
}
37+
/* }}} */
2738

28-
/* {{{ proto long git_indexer_append(idx, data, size, stats)
29-
*/
39+
/* {{{ proto long git_indexer_append(resource $idx, $data, long $size, $stats)
40+
*/
3041
PHP_FUNCTION(git_indexer_append)
3142
{
32-
zval *idx;
33-
php_git2_t *_idx;
34-
zval *stats;
35-
php_git2_t *_stats;
36-
37-
/* TODO(chobie): implement this */
38-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_append not implemented yet");
39-
return;
43+
int result = 0, error = 0;
44+
zval *idx = NULL, *stats = NULL;
45+
php_git2_t *_idx = NULL;
46+
zval *data = NULL;
47+
long size = 0;
4048

4149
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
42-
// "rr", &idx, &data, &size, &stats) == FAILURE) {
50+
// "r<void>l<git_transfer_progress>", &idx, &data, &size, &stats) == FAILURE) {
4351
// return;
4452
// }
53+
//
4554
// ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
55+
// result = git_indexer_append(PHP_GIT2_V(_idx, indexer), data, size, stats);
56+
// RETURN_LONG(result);
4657
}
58+
/* }}} */
4759

48-
/* {{{ proto long git_indexer_commit(idx, stats)
49-
*/
60+
/* {{{ proto long git_indexer_commit(resource $idx, $stats)
61+
*/
5062
PHP_FUNCTION(git_indexer_commit)
5163
{
52-
zval *idx;
53-
php_git2_t *_idx;
54-
zval *stats;
55-
php_git2_t *_stats;
56-
57-
/* TODO(chobie): implement this */
58-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_commit not implemented yet");
59-
return;
64+
int result = 0, error = 0;
65+
zval *idx = NULL, *stats = NULL;
66+
php_git2_t *_idx = NULL;
6067

61-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
62-
"rr", &idx, &stats) == FAILURE) {
63-
return;
64-
}
65-
ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
68+
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
69+
// "r<git_transfer_progress>", &idx, &stats) == FAILURE) {
70+
// return;
71+
// }
72+
//
73+
// ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
74+
// result = git_indexer_commit(PHP_GIT2_V(_idx, indexer), stats);
75+
// RETURN_LONG(result);
6676
}
77+
/* }}} */
6778

68-
/* {{{ proto resource git_indexer_hash(idx)
69-
*/
79+
/* {{{ proto resource git_indexer_hash(resource $idx)
80+
*/
7081
PHP_FUNCTION(git_indexer_hash)
7182
{
72-
zval *idx;
73-
php_git2_t *_idx;
74-
75-
/* TODO(chobie): implement this */
76-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_hash not implemented yet");
77-
return;
83+
const git_oid *result = NULL;
84+
zval *idx = NULL;
85+
php_git2_t *_idx = NULL;
86+
char __result[GIT2_OID_HEXSIZE] = {0};
7887

7988
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
8089
"r", &idx) == FAILURE) {
8190
return;
8291
}
92+
8393
ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
94+
result = git_indexer_hash(PHP_GIT2_V(_idx, indexer));
95+
git_oid_fmt(__result, result);
96+
RETURN_STRING(__result, 1);
8497
}
98+
/* }}} */
8599

86-
/* {{{ proto void git_indexer_free(idx)
87-
*/
100+
/* {{{ proto void git_indexer_free(resource $idx)
101+
*/
88102
PHP_FUNCTION(git_indexer_free)
89103
{
90-
zval *idx;
91-
php_git2_t *_idx;
92-
93-
/* TODO(chobie): implement this */
94-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_indexer_free not implemented yet");
95-
return;
104+
zval *idx = NULL;
105+
php_git2_t *_idx = NULL;
96106

97107
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
98108
"r", &idx) == FAILURE) {
99109
return;
100110
}
111+
101112
ZEND_FETCH_RESOURCE(_idx, php_git2_t*, &idx, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
113+
if (GIT2_SHOULD_FREE(_idx)) {
114+
git_indexer_free(PHP_GIT2_V(_idx, indexer));
115+
GIT2_SHOULD_FREE(_idx) = 0;
116+
};
117+
zval_ptr_dtor(&idx);
102118
}
119+
/* }}} */
103120

indexer.h

+13-12
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#ifndef PHP_GIT2_INDEXER_H
2727
#define PHP_GIT2_INDEXER_H
2828

29-
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_new, 0, 0, 5)
29+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_new, 0, 0, 6)
30+
ZEND_ARG_INFO(0, out)
3031
ZEND_ARG_INFO(0, path)
3132
ZEND_ARG_INFO(0, mode)
3233
ZEND_ARG_INFO(0, odb)
@@ -54,24 +55,24 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_git_indexer_free, 0, 0, 1)
5455
ZEND_ARG_INFO(0, idx)
5556
ZEND_END_ARG_INFO()
5657

57-
/* {{{ proto resource git_indexer_new(path, mode, odb, progress_cb, progress_cb_payload)
58-
*/
58+
/* {{{ proto resource git_indexer_new(string $path, long $mode, resource $odb, $progress_cb, $progress_cb_payload)
59+
*/
5960
PHP_FUNCTION(git_indexer_new);
6061

61-
/* {{{ proto long git_indexer_append(idx, data, size, stats)
62-
*/
62+
/* {{{ proto long git_indexer_append(resource $idx, $data, long $size, $stats)
63+
*/
6364
PHP_FUNCTION(git_indexer_append);
6465

65-
/* {{{ proto long git_indexer_commit(idx, stats)
66-
*/
66+
/* {{{ proto long git_indexer_commit(resource $idx, $stats)
67+
*/
6768
PHP_FUNCTION(git_indexer_commit);
6869

69-
/* {{{ proto resource git_indexer_hash(idx)
70-
*/
70+
/* {{{ proto resource git_indexer_hash(resource $idx)
71+
*/
7172
PHP_FUNCTION(git_indexer_hash);
7273

73-
/* {{{ proto void git_indexer_free(idx)
74-
*/
74+
/* {{{ proto void git_indexer_free(resource $idx)
75+
*/
7576
PHP_FUNCTION(git_indexer_free);
7677

77-
#endif
78+
#endif

ng.php

+1
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ public function shouldResource(Arg $arg)
407407
"git_push",
408408
"git_refspec",
409409
"git_filter",
410+
"git_indexer",
410411
);
411412
}
412413

php_git2.h

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ enum php_git2_resource_type {
125125
PHP_GIT2_TYPE_SUBMODULE,
126126
PHP_GIT2_TYPE_PUSH,
127127
PHP_GIT2_TYPE_REFSPEC,
128+
PHP_GIT2_TYPE_INDEXER,
128129
};
129130

130131
typedef struct php_git2_t {
@@ -177,6 +178,7 @@ typedef struct php_git2_t {
177178
git_submodule *submodule;
178179
git_push *push;
179180
git_refspec *refspec;
181+
git_indexer *indexer;
180182
} v;
181183
int should_free_v;
182184
int resource_id;

0 commit comments

Comments
 (0)