|
2 | 2 | #include "php_git2_priv.h" |
3 | 3 | #include "diff.h" |
4 | 4 |
|
5 | | - |
6 | | -static void php_git2_array_to_git_diff_options(git_diff_options *options, zval *array TSRMLS_DC) |
7 | | -{ |
8 | | - git_diff_options_init(options, GIT_DIFF_OPTIONS_VERSION); |
9 | | - |
10 | | - options->version = php_git2_read_arrval_long(array, ZEND_STRS("version") TSRMLS_CC); |
11 | | - options->flags = php_git2_read_arrval_long(array, ZEND_STRS("flags") TSRMLS_CC); |
12 | | - options->ignore_submodules = php_git2_read_arrval_long(array, ZEND_STRS("ignore_submodules") TSRMLS_CC); |
13 | | - |
14 | | - php_git2_array_to_strarray(&options->pathspec, php_git2_read_arrval(array, ZEND_STRS("pathspec") TSRMLS_CC) TSRMLS_CC); |
15 | | - // TODO(chobie): support notify cb |
16 | | - |
17 | | - |
18 | | - options->context_lines = php_git2_read_arrval_long(array, ZEND_STRS("context_lines") TSRMLS_CC); |
19 | | - options->interhunk_lines = php_git2_read_arrval_long(array, ZEND_STRS("interhunk_lines") TSRMLS_CC); |
20 | | - options->oid_abbrev = php_git2_read_arrval_long(array, ZEND_STRS("oid_abbrev") TSRMLS_CC); |
21 | | - options->max_size = php_git2_read_arrval_long(array, ZEND_STRS("max_size") TSRMLS_CC); |
22 | | - options->old_prefix = php_git2_read_arrval_string(array, ZEND_STRS("old_prefix") TSRMLS_CC); |
23 | | - options->new_prefix = php_git2_read_arrval_string(array, ZEND_STRS("new_prefix") TSRMLS_CC); |
24 | | -} |
25 | | - |
26 | | -static void php_git2_git_diff_options_free(git_diff_options *options) |
27 | | -{ |
28 | | - if (options->pathspec.count > 0) { |
29 | | - efree(options->pathspec.strings); |
30 | | - } |
31 | | -} |
32 | | - |
33 | | -static void php_git2_git_diff_options_to_array(git_diff_options *options, zval **out TSRMLS_DC) |
34 | | -{ |
35 | | - zval *result, *pathspec; |
36 | | - |
37 | | - MAKE_STD_ZVAL(result); |
38 | | - array_init(result); |
39 | | - add_assoc_long_ex(result, ZEND_STRS("version"), options->version); |
40 | | - add_assoc_long_ex(result, ZEND_STRS("flags"), options->flags); |
41 | | - add_assoc_long_ex(result, ZEND_STRS("ignore_submodules"), options->ignore_submodules); |
42 | | - |
43 | | - MAKE_STD_ZVAL(pathspec); |
44 | | - array_init(pathspec); |
45 | | - if (options->pathspec.count > 0) { |
46 | | - } else { |
47 | | - add_assoc_zval_ex(result, ZEND_STRS("pathspec"), pathspec); |
48 | | - } |
49 | | - |
50 | | - if (options->notify_cb) { |
51 | | - } else { |
52 | | - add_assoc_null_ex(result, ZEND_STRS("notify_cb")); |
53 | | - } |
54 | | - |
55 | | - add_assoc_long_ex(result, ZEND_STRS("context_lines"), options->context_lines); |
56 | | - add_assoc_long_ex(result, ZEND_STRS("interhunk_lines"), options->interhunk_lines); |
57 | | - add_assoc_long_ex(result, ZEND_STRS("oid_abbrev"), options->oid_abbrev); |
58 | | - add_assoc_long_ex(result, ZEND_STRS("max_size"), options->max_size); |
59 | | - if (options->notify_payload) { |
60 | | - } else { |
61 | | - add_assoc_null_ex(result, ZEND_STRS("notify_payload")); |
62 | | - } |
63 | | - if (options->old_prefix) { |
64 | | - add_assoc_string_ex(result, ZEND_STRS("old_prefix"), options->old_prefix, 1); |
65 | | - } else { |
66 | | - add_assoc_null_ex(result, ZEND_STRS("old_prefix")); |
67 | | - } |
68 | | - if (options->new_prefix) { |
69 | | - add_assoc_string_ex(result, ZEND_STRS("new_prefix"), options->new_prefix, 1); |
70 | | - } else { |
71 | | - add_assoc_null_ex(result, ZEND_STRS("new_prefix")); |
72 | | - } |
73 | | - |
74 | | - *out = result; |
75 | | -} |
76 | | - |
77 | | - |
78 | | -static int php_git2_git_diff_file_cb( |
79 | | - const git_diff_delta *delta, |
80 | | - float progress, |
81 | | - void *payload) |
82 | | -{ |
83 | | - php_git2_t *result; |
84 | | - zval *param_delta = NULL, *param_progress = NULL, *retval_ptr = NULL; |
85 | | - php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; |
86 | | - int i = 0, retval = 0; |
87 | | - GIT2_TSRMLS_SET(p->tsrm_ls) |
88 | | - |
89 | | - Z_ADDREF_P(p->payload); |
90 | | - MAKE_STD_ZVAL(param_progress); |
91 | | - ZVAL_DOUBLE(param_progress, progress); |
92 | | - php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); |
93 | | - if (php_git2_call_function_v(&p->callbacks[0].fci, &p->callbacks[0].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_progress, &p->payload)) { |
94 | | - return GIT_EUSER; |
95 | | - } |
96 | | - retval = Z_LVAL_P(retval_ptr); |
97 | | - zval_ptr_dtor(&retval_ptr); |
98 | | - |
99 | | - return retval; |
100 | | -} |
101 | | - |
102 | | -static int php_git2_git_diff_hunk_cb( |
103 | | - const git_diff_delta *delta, |
104 | | - const git_diff_hunk *hunk, |
105 | | - void *payload) |
106 | | -{ |
107 | | - php_git2_t *result; |
108 | | - zval *param_delta = NULL, *param_hunk = NULL, *retval_ptr = NULL; |
109 | | - php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; |
110 | | - int i = 0, retval = 0; |
111 | | - GIT2_TSRMLS_SET(p->tsrm_ls) |
112 | | - |
113 | | - Z_ADDREF_P(p->payload); |
114 | | - php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); |
115 | | - php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); |
116 | | - |
117 | | - if (php_git2_call_function_v(&p->callbacks[1].fci, &p->callbacks[1].fcc TSRMLS_CC, &retval_ptr, 3, ¶m_delta, ¶m_hunk, &p->payload)) { |
118 | | - return GIT_EUSER; |
119 | | - } |
120 | | - |
121 | | - retval = Z_LVAL_P(retval_ptr); |
122 | | - zval_ptr_dtor(&retval_ptr); |
123 | | - return retval; |
124 | | -} |
125 | | - |
126 | | -static int php_git2_git_diff_line_cb( |
127 | | - const git_diff_delta *delta, |
128 | | - const git_diff_hunk *hunk, |
129 | | - const git_diff_line *line, |
130 | | - void *payload) { |
131 | | - php_git2_t *result; |
132 | | - zval *param_delta = NULL, *param_hunk = NULL, *param_line = NULL, *retval_ptr = NULL; |
133 | | - php_git2_multi_cb_t *p = (php_git2_multi_cb_t*)payload; |
134 | | - int i = 0, retval = 0; |
135 | | - GIT2_TSRMLS_SET(p->tsrm_ls) |
136 | | - |
137 | | - Z_ADDREF_P(p->payload); |
138 | | - php_git2_diff_delta_to_array(delta, ¶m_delta TSRMLS_CC); |
139 | | - php_git2_diff_hunk_to_array(hunk, ¶m_hunk TSRMLS_CC); |
140 | | - php_git2_diff_line_to_array(line, ¶m_line TSRMLS_CC); |
141 | | - |
142 | | - if (php_git2_call_function_v(&p->callbacks[2].fci, &p->callbacks[2].fcc TSRMLS_CC, &retval_ptr, 4, ¶m_delta, ¶m_hunk, ¶m_line, &p->payload)) { |
143 | | - return GIT_EUSER; |
144 | | - } |
145 | | - |
146 | | - retval = Z_LVAL_P(retval_ptr); |
147 | | - zval_ptr_dtor(&retval_ptr); |
148 | | - return retval; |
149 | | -} |
150 | | - |
151 | 5 | /* {{{ proto void git_diff_free(resource $diff) |
152 | 6 | */ |
153 | 7 | PHP_FUNCTION(git_diff_free) |
@@ -238,7 +92,7 @@ PHP_FUNCTION(git_diff_index_to_workdir) |
238 | 92 | git_diff *diff = NULL; |
239 | 93 | zval *repo = NULL, *index = NULL, *opts = NULL; |
240 | 94 | php_git2_t *_repo = NULL, *_index = NULL, *_diff = NULL; |
241 | | - git_diff_options options = {0}; |
| 95 | + git_diff_options options = GIT_DIFF_OPTIONS_INIT; |
242 | 96 |
|
243 | 97 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
244 | 98 | "rra", &repo, &index, &opts) == FAILURE) { |
@@ -276,6 +130,11 @@ PHP_FUNCTION(git_diff_tree_to_workdir) |
276 | 130 | ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle); |
277 | 131 | php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC); |
278 | 132 | result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), &options); |
| 133 | + if (php_git2_check_error(result, "git_diff_tree_to_workdir" TSRMLS_CC)) { |
| 134 | + php_git2_git_diff_options_free(&options); |
| 135 | + RETURN_FALSE |
| 136 | + } |
| 137 | + |
279 | 138 | php_git2_git_diff_options_free(&options); |
280 | 139 |
|
281 | 140 | if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) { |
|
0 commit comments