|
2 | 2 | #include "php_git2_priv.h"
|
3 | 3 | #include "indexer.h"
|
4 | 4 |
|
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 | + */ |
7 | 7 | PHP_FUNCTION(git_indexer_new)
|
8 | 8 | {
|
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; |
16 | 18 |
|
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 | + } |
20 | 23 |
|
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)); |
26 | 36 | }
|
| 37 | +/* }}} */ |
27 | 38 |
|
28 |
| -/* {{{ proto long git_indexer_append(idx, data, size, stats) |
29 |
| -*/ |
| 39 | +/* {{{ proto long git_indexer_append(resource $idx, $data, long $size, $stats) |
| 40 | + */ |
30 | 41 | PHP_FUNCTION(git_indexer_append)
|
31 | 42 | {
|
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; |
40 | 48 |
|
41 | 49 | // 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) { |
43 | 51 | // return;
|
44 | 52 | // }
|
| 53 | +// |
45 | 54 | // 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); |
46 | 57 | }
|
| 58 | +/* }}} */ |
47 | 59 |
|
48 |
| -/* {{{ proto long git_indexer_commit(idx, stats) |
49 |
| -*/ |
| 60 | +/* {{{ proto long git_indexer_commit(resource $idx, $stats) |
| 61 | + */ |
50 | 62 | PHP_FUNCTION(git_indexer_commit)
|
51 | 63 | {
|
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; |
60 | 67 |
|
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); |
66 | 76 | }
|
| 77 | +/* }}} */ |
67 | 78 |
|
68 |
| -/* {{{ proto resource git_indexer_hash(idx) |
69 |
| -*/ |
| 79 | +/* {{{ proto resource git_indexer_hash(resource $idx) |
| 80 | + */ |
70 | 81 | PHP_FUNCTION(git_indexer_hash)
|
71 | 82 | {
|
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}; |
78 | 87 |
|
79 | 88 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
80 | 89 | "r", &idx) == FAILURE) {
|
81 | 90 | return;
|
82 | 91 | }
|
| 92 | + |
83 | 93 | 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); |
84 | 97 | }
|
| 98 | +/* }}} */ |
85 | 99 |
|
86 |
| -/* {{{ proto void git_indexer_free(idx) |
87 |
| -*/ |
| 100 | +/* {{{ proto void git_indexer_free(resource $idx) |
| 101 | + */ |
88 | 102 | PHP_FUNCTION(git_indexer_free)
|
89 | 103 | {
|
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; |
96 | 106 |
|
97 | 107 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
98 | 108 | "r", &idx) == FAILURE) {
|
99 | 109 | return;
|
100 | 110 | }
|
| 111 | + |
101 | 112 | 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); |
102 | 118 | }
|
| 119 | +/* }}} */ |
103 | 120 |
|
0 commit comments