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
+
5
78
static int php_git2_git_diff_file_cb (
6
79
const git_diff_delta * delta ,
7
80
float progress ,
@@ -110,8 +183,8 @@ PHP_FUNCTION(git_diff_tree_to_tree)
110
183
php_git2_t * _new_tree = NULL ;
111
184
zval * opts = NULL ;
112
185
int error = 0 ;
186
+ git_diff_options options = {0 };
113
187
114
- /* TODO(chobie): generate converter */
115
188
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
116
189
"rrra" , & repo , & old_tree , & new_tree , & opts ) == FAILURE ) {
117
190
return ;
@@ -120,7 +193,9 @@ PHP_FUNCTION(git_diff_tree_to_tree)
120
193
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
121
194
ZEND_FETCH_RESOURCE (_old_tree , php_git2_t * , & old_tree , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
122
195
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 );
123
197
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 );
124
199
RETURN_LONG (result );
125
200
}
126
201
/* }}} */
@@ -134,8 +209,8 @@ PHP_FUNCTION(git_diff_tree_to_index)
134
209
git_diff * diff = NULL ;
135
210
zval * repo = NULL , * old_tree = NULL , * index = NULL , * opts = NULL ;
136
211
php_git2_t * _repo = NULL , * _old_tree = NULL , * _index = NULL , * _diff = NULL ;
212
+ git_diff_options options = {0 };
137
213
138
- /* TODO(chobie): convert options */
139
214
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
140
215
"rrra" , & repo , & old_tree , & index , & opts ) == FAILURE ) {
141
216
return ;
@@ -144,7 +219,9 @@ PHP_FUNCTION(git_diff_tree_to_index)
144
219
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
145
220
ZEND_FETCH_RESOURCE (_old_tree , php_git2_t * , & old_tree , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
146
221
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 );
147
223
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 );
148
225
if (php_git2_make_resource (& _diff , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
149
226
RETURN_FALSE ;
150
227
}
@@ -161,6 +238,7 @@ PHP_FUNCTION(git_diff_index_to_workdir)
161
238
git_diff * diff = NULL ;
162
239
zval * repo = NULL , * index = NULL , * opts = NULL ;
163
240
php_git2_t * _repo = NULL , * _index = NULL , * _diff = NULL ;
241
+ git_diff_options options = {0 };
164
242
165
243
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
166
244
"rra" , & repo , & index , & opts ) == FAILURE ) {
@@ -169,7 +247,9 @@ PHP_FUNCTION(git_diff_index_to_workdir)
169
247
170
248
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
171
249
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 );
172
251
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 );
173
253
if (php_git2_make_resource (& _diff , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
174
254
RETURN_FALSE ;
175
255
}
@@ -185,6 +265,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir)
185
265
git_diff * diff = NULL ;
186
266
zval * repo = NULL , * old_tree = NULL , * opts = NULL ;
187
267
php_git2_t * _repo = NULL , * _old_tree = NULL , * _result ;
268
+ git_diff_options options = {0 };
188
269
189
270
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
190
271
"rra" , & repo , & old_tree , & opts ) == FAILURE ) {
@@ -193,7 +274,9 @@ PHP_FUNCTION(git_diff_tree_to_workdir)
193
274
194
275
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
195
276
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 );
197
280
198
281
if (php_git2_make_resource (& _result , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
199
282
RETURN_FALSE ;
@@ -210,6 +293,7 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index)
210
293
git_diff * diff = NULL ;
211
294
zval * repo = NULL , * old_tree = NULL , * opts = NULL ;
212
295
php_git2_t * _repo = NULL , * _old_tree = NULL , * _diff = NULL ;
296
+ git_diff_options options = {0 };
213
297
214
298
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
215
299
"rra" , & repo , & old_tree , & opts ) == FAILURE ) {
@@ -218,7 +302,9 @@ PHP_FUNCTION(git_diff_tree_to_workdir_with_index)
218
302
219
303
ZEND_FETCH_RESOURCE (_repo , php_git2_t * , & repo , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
220
304
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 );
221
306
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 );
222
308
if (php_git2_make_resource (& _diff , PHP_GIT2_TYPE_DIFF , diff , 0 TSRMLS_CC )) {
223
309
RETURN_FALSE ;
224
310
}
@@ -255,6 +341,7 @@ PHP_FUNCTION(git_diff_find_similar)
255
341
php_git2_t * _diff = NULL ;
256
342
zval * options = NULL ;
257
343
int error = 0 ;
344
+ git_diff_options _options = {0 };
258
345
259
346
/* TODO(chobie): generate converter */
260
347
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
@@ -263,28 +350,31 @@ PHP_FUNCTION(git_diff_find_similar)
263
350
}
264
351
265
352
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 );
267
356
RETURN_LONG (result );
268
357
}
269
358
/* }}} */
270
359
271
- /* {{{ proto long git_diff_options_init( $options, long $version)
360
+ /* {{{ proto long git_diff_options_init(long $version)
272
361
*/
273
362
PHP_FUNCTION (git_diff_options_init )
274
363
{
275
364
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 ;
278
368
int error = 0 ;
279
369
280
- /* TODO(chobie): generate converter */
281
370
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
282
- "al" , & options , & version ) == FAILURE ) {
371
+ "|l" , & version ) == FAILURE ) {
283
372
return ;
284
373
}
285
374
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 );
288
378
}
289
379
/* }}} */
290
380
0 commit comments