22#include "php_git2_priv.h"
33#include "diff.h"
44
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+
578static int php_git2_git_diff_file_cb (
679 const git_diff_delta * delta ,
780 float progress ,
@@ -110,8 +183,8 @@ PHP_FUNCTION(git_diff_tree_to_tree)
110183 php_git2_t * _new_tree = NULL ;
111184 zval * opts = NULL ;
112185 int error = 0 ;
186+ git_diff_options options = {0 };
113187
114- /* TODO(chobie): generate converter */
115188 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
116189 "rrra" , & repo , & old_tree , & new_tree , & opts ) == FAILURE ) {
117190 return ;
@@ -120,7 +193,9 @@ PHP_FUNCTION(git_diff_tree_to_tree)
120193 ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
121194 ZEND_FETCH_RESOURCE (_old_tree , php_git2_t * , & old_tree , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
122195 ZEND_FETCH_RESOURCE (_new_tree , php_git2_t * , & new_tree , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
196+ php_git2_array_to_git_diff_options (& options , opts TSRMLS_CC );
123197 result = git_diff_tree_to_tree (& diff , PHP_GIT2_V (_repo , repository ), PHP_GIT2_V (_old_tree , tree ), PHP_GIT2_V (_new_tree , tree ), opts );
198+ php_git2_git_diff_options_free (& options );
124199 RETURN_LONG (result );
125200}
126201/* }}} */
@@ -134,8 +209,8 @@ PHP_FUNCTION(git_diff_tree_to_index)
134209 git_diff * diff = NULL ;
135210 zval * repo = NULL , * old_tree = NULL , * index = NULL , * opts = NULL ;
136211 php_git2_t * _repo = NULL , * _old_tree = NULL , * _index = NULL , * _diff = NULL ;
212+ git_diff_options options = {0 };
137213
138- /* TODO(chobie): convert options */
139214 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
140215 "rrra" , & repo , & old_tree , & index , & opts ) == FAILURE ) {
141216 return ;
@@ -144,7 +219,9 @@ PHP_FUNCTION(git_diff_tree_to_index)
144219 ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
145220 ZEND_FETCH_RESOURCE (_old_tree , php_git2_t * , & old_tree , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
146221 ZEND_FETCH_RESOURCE (_index , php_git2_t * , & index , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
222+ php_git2_array_to_git_diff_options (& options , opts TSRMLS_CC );
147223 result = git_diff_tree_to_index (& diff , PHP_GIT2_V (_repo , repository ), PHP_GIT2_V (_old_tree , tree ), PHP_GIT2_V (_index , index ), opts );
224+ php_git2_git_diff_options_free (& options );
148225 if (php_git2_make_resource (& _diff , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
149226 RETURN_FALSE ;
150227 }
@@ -161,6 +238,7 @@ PHP_FUNCTION(git_diff_index_to_workdir)
161238 git_diff * diff = NULL ;
162239 zval * repo = NULL , * index = NULL , * opts = NULL ;
163240 php_git2_t * _repo = NULL , * _index = NULL , * _diff = NULL ;
241+ git_diff_options options = {0 };
164242
165243 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
166244 "rra" , & repo , & index , & opts ) == FAILURE ) {
@@ -169,7 +247,9 @@ PHP_FUNCTION(git_diff_index_to_workdir)
169247
170248 ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
171249 ZEND_FETCH_RESOURCE (_index , php_git2_t * , & index , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
250+ php_git2_array_to_git_diff_options (& options , opts TSRMLS_CC );
172251 result = git_diff_index_to_workdir (& diff , PHP_GIT2_V (_repo , repository ), PHP_GIT2_V (_index , index ), opts );
252+ php_git2_git_diff_options_free (& options );
173253 if (php_git2_make_resource (& _diff , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
174254 RETURN_FALSE ;
175255 }
@@ -185,6 +265,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir)
185265 git_diff * diff = NULL ;
186266 zval * repo = NULL , * old_tree = NULL , * opts = NULL ;
187267 php_git2_t * _repo = NULL , * _old_tree = NULL , * _result ;
268+ git_diff_options options = {0 };
188269
189270 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
190271 "rra" , & repo , & old_tree , & opts ) == FAILURE ) {
@@ -193,7 +274,9 @@ PHP_FUNCTION(git_diff_tree_to_workdir)
193274
194275 ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
195276 ZEND_FETCH_RESOURCE (_old_tree , php_git2_t * , & old_tree , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
196- result = git_diff_tree_to_workdir (& diff , PHP_GIT2_V (_repo , repository ), PHP_GIT2_V (_old_tree , tree ), NULL );
277+ php_git2_array_to_git_diff_options (& options , opts TSRMLS_CC );
278+ result = git_diff_tree_to_workdir (& diff , PHP_GIT2_V (_repo , repository ), PHP_GIT2_V (_old_tree , tree ), & options );
279+ php_git2_git_diff_options_free (& options );
197280
198281 if (php_git2_make_resource (& _result , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
199282 RETURN_FALSE ;
@@ -210,6 +293,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index)
210293 git_diff * diff = NULL ;
211294 zval * repo = NULL , * old_tree = NULL , * opts = NULL ;
212295 php_git2_t * _repo = NULL , * _old_tree = NULL , * _diff = NULL ;
296+ git_diff_options options = {0 };
213297
214298 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
215299 "rra" , & repo , & old_tree , & opts ) == FAILURE ) {
@@ -218,7 +302,9 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index)
218302
219303 ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
220304 ZEND_FETCH_RESOURCE (_old_tree , php_git2_t * , & old_tree , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
305+ php_git2_array_to_git_diff_options (& options , opts TSRMLS_CC );
221306 result = git_diff_tree_to_workdir_with_index (& diff , PHP_GIT2_V (_repo , repository ), PHP_GIT2_V (_old_tree , tree ), opts );
307+ php_git2_git_diff_options_free (& options );
222308 if (php_git2_make_resource (& _diff , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
223309 RETURN_FALSE ;
224310 }
@@ -255,6 +341,7 @@ PHP_FUNCTION(git_diff_find_similar)
255341 php_git2_t * _diff = NULL ;
256342 zval * options = NULL ;
257343 int error = 0 ;
344+ git_diff_options _options = {0 };
258345
259346 /* TODO(chobie): generate converter */
260347 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
@@ -263,28 +350,31 @@ PHP_FUNCTION(git_diff_find_similar)
263350 }
264351
265352 ZEND_FETCH_RESOURCE (_diff , php_git2_t * , & diff , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
266- result = git_diff_find_similar (PHP_GIT2_V (_diff , diff ), options );
353+ php_git2_array_to_git_diff_options (& _options , options TSRMLS_CC );
354+ result = git_diff_find_similar (PHP_GIT2_V (_diff , diff ), & _options );
355+ php_git2_git_diff_options_free (& _options );
267356 RETURN_LONG (result );
268357}
269358/* }}} */
270359
271- /* {{{ proto long git_diff_options_init( $options, long $version)
360+ /* {{{ proto long git_diff_options_init(long $version)
272361 */
273362PHP_FUNCTION (git_diff_options_init )
274363{
275364 int result = 0 ;
276- zval * options = NULL ;
277- long version = 0 ;
365+ git_diff_options options = {0 };
366+ long version = GIT_DIFF_OPTIONS_VERSION ;
367+ zval * out ;
278368 int error = 0 ;
279369
280- /* TODO(chobie): generate converter */
281370 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
282- "al" , & options , & version ) == FAILURE ) {
371+ "|l" , & version ) == FAILURE ) {
283372 return ;
284373 }
285374
286- result = git_diff_options_init (options , version );
287- RETURN_LONG (result );
375+ result = git_diff_options_init (& options , version );
376+ php_git2_git_diff_options_to_array (& options , & out TSRMLS_CC );
377+ RETURN_ZVAL (out , 0 , 1 );
288378}
289379/* }}} */
290380
0 commit comments