-
Notifications
You must be signed in to change notification settings - Fork 78
/
diff.c
469 lines (409 loc) · 15.2 KB
/
diff.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#include "php_git2.h"
#include "php_git2_priv.h"
#include "diff.h"
/* {{{ proto void git_diff_free(resource $diff)
*/
PHP_FUNCTION(git_diff_free)
{
zval *diff = NULL;
php_git2_t *_diff = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &diff) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (GIT2_SHOULD_FREE(_diff)) {
git_diff_free(PHP_GIT2_V(_diff, diff));
GIT2_SHOULD_FREE(_diff) = 0;
};
zval_ptr_dtor(&diff);
}
/* }}} */
/* {{{ proto long git_diff_tree_to_tree(resource $repo, resource $old_tree, resource $new_tree, $opts)
*/
PHP_FUNCTION(git_diff_tree_to_tree)
{
int result = 0;
git_diff *diff = NULL;
zval *repo = NULL;
php_git2_t *_repo = NULL;
zval *old_tree = NULL;
php_git2_t *_old_tree = NULL;
zval *new_tree = NULL;
php_git2_t *_new_tree = NULL;
zval *opts = NULL;
git_diff_options options = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rrra", &repo, &old_tree, &new_tree, &opts) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_new_tree, php_git2_t*, &new_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC);
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);
php_git2_git_diff_options_free(&options);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_diff_tree_to_index(resource $repo, resource $old_tree, resource $index, $opts)
*/
PHP_FUNCTION(git_diff_tree_to_index)
{
int result = 0;
git_diff *diff = NULL;
zval *repo = NULL, *old_tree = NULL, *index = NULL, *opts = NULL;
php_git2_t *_repo = NULL, *_old_tree = NULL, *_index = NULL, *_diff = NULL;
git_diff_options options = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rrra", &repo, &old_tree, &index, &opts) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC);
result = git_diff_tree_to_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), PHP_GIT2_V(_index, index), opts);
php_git2_git_diff_options_free(&options);
if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_diff));
}
/* }}} */
/* {{{ proto long git_diff_index_to_workdir(resource $repo, resource $index, $opts)
*/
PHP_FUNCTION(git_diff_index_to_workdir)
{
int result = 0;
git_diff *diff = NULL;
zval *repo = NULL, *index = NULL, *opts = NULL;
php_git2_t *_repo = NULL, *_index = NULL, *_diff = NULL;
git_diff_options options = GIT_DIFF_OPTIONS_INIT;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rra", &repo, &index, &opts) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_index, php_git2_t*, &index, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC);
result = git_diff_index_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_index, index), opts);
php_git2_git_diff_options_free(&options);
if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_diff));
}
/* }}} */
/* {{{ proto long git_diff_tree_to_workdir(resource $repo, resource $old_tree, $opts)
*/
PHP_FUNCTION(git_diff_tree_to_workdir)
{
int result = 0;
git_diff *diff = NULL;
zval *repo = NULL, *old_tree = NULL, *opts = NULL;
php_git2_t *_repo = NULL, *_old_tree = NULL, *_result;
git_diff_options options = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rra", &repo, &old_tree, &opts) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC);
result = git_diff_tree_to_workdir(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), &options);
if (php_git2_check_error(result, "git_diff_tree_to_workdir" TSRMLS_CC)) {
php_git2_git_diff_options_free(&options);
RETURN_FALSE
}
php_git2_git_diff_options_free(&options);
if (php_git2_make_resource(&_result, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_result));
}
/* }}} */
/* {{{ proto long git_diff_tree_to_workdir_with_index(resource $repo, resource $old_tree, $opts)
*/
PHP_FUNCTION(git_diff_tree_to_workdir_with_index)
{
int result = 0;
git_diff *diff = NULL;
zval *repo = NULL, *old_tree = NULL, *opts = NULL;
php_git2_t *_repo = NULL, *_old_tree = NULL, *_diff = NULL;
git_diff_options options = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rra", &repo, &old_tree, &opts) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_old_tree, php_git2_t*, &old_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_array_to_git_diff_options(&options, opts TSRMLS_CC);
result = git_diff_tree_to_workdir_with_index(&diff, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_old_tree, tree), opts);
php_git2_git_diff_options_free(&options);
if (php_git2_make_resource(&_diff, PHP_GIT2_TYPE_DIFF, diff, 0 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(_diff));
}
/* }}} */
/* {{{ proto long git_diff_merge(resource $onto, resource $from)
*/
PHP_FUNCTION(git_diff_merge)
{
int result = 0;
zval *onto = NULL, *from = NULL;
php_git2_t *_onto = NULL, *_from = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rr", &onto, &from) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_onto, php_git2_t*, &onto, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_from, php_git2_t*, &from, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_diff_merge(PHP_GIT2_V(_onto, diff), PHP_GIT2_V(_from, diff));
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_diff_find_similar(resource $diff, $options)
*/
PHP_FUNCTION(git_diff_find_similar)
{
int result = 0;
zval *diff = NULL;
php_git2_t *_diff = NULL;
zval *options = NULL;
git_diff_options _options = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ra", &diff, &options) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_array_to_git_diff_options(&_options, options TSRMLS_CC);
result = git_diff_find_similar(PHP_GIT2_V(_diff, diff), &_options);
php_git2_git_diff_options_free(&_options);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_diff_options_init(long $version)
*/
PHP_FUNCTION(git_diff_options_init)
{
int result = 0;
git_diff_options options = {0};
long version = GIT_DIFF_OPTIONS_VERSION;
zval *out;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"|l", &version) == FAILURE) {
return;
}
result = git_diff_options_init(&options, version);
php_git2_git_diff_options_to_array(&options, &out TSRMLS_CC);
RETURN_ZVAL(out, 0, 1);
}
/* }}} */
/* {{{ proto long git_diff_num_deltas(resource $diff)
*/
PHP_FUNCTION(git_diff_num_deltas)
{
size_t result = 0;
zval *diff = NULL;
php_git2_t *_diff = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &diff) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_diff_num_deltas(PHP_GIT2_V(_diff, diff));
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_diff_num_deltas_of_type(resource $diff, $type)
*/
PHP_FUNCTION(git_diff_num_deltas_of_type)
{
size_t result = 0;
zval *diff = NULL;
php_git2_t *_diff = NULL;
long type = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rl", &diff, &type) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_diff_num_deltas_of_type(PHP_GIT2_V(_diff, diff), type);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto resource git_diff_get_delta(resource $diff, long $idx)
*/
PHP_FUNCTION(git_diff_get_delta)
{
const git_diff_delta *result = NULL;
zval *diff = NULL, *_result;
php_git2_t *_diff = NULL;
long idx = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rl", &diff, &idx) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_diff_get_delta(PHP_GIT2_V(_diff, diff), idx);
php_git2_diff_delta_to_array(result, &_result TSRMLS_CC);
RETURN_ZVAL(_result, 0, 1);
}
/* }}} */
/* {{{ proto long git_diff_is_sorted_icase(resource $diff)
*/
PHP_FUNCTION(git_diff_is_sorted_icase)
{
int result = 0;
zval *diff = NULL;
php_git2_t *_diff = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &diff) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_diff_is_sorted_icase(PHP_GIT2_V(_diff, diff));
RETURN_BOOL(result);
}
/* }}} */
/* {{{ proto long git_diff_foreach(resource $diff, Callable $file_cb, Callable $hunk_cb, Callable $line_cb, $payload)
*/
PHP_FUNCTION(git_diff_foreach)
{
int result = 0;
zval *diff = NULL, *payload = NULL;
php_git2_t *_diff = NULL;
zend_fcall_info file_fci = empty_fcall_info;
zend_fcall_info_cache file_fcc = empty_fcall_info_cache;
zend_fcall_info hunk_fci = empty_fcall_info;
zend_fcall_info_cache hunk_fcc = empty_fcall_info_cache;
zend_fcall_info line_fci = empty_fcall_info;
zend_fcall_info_cache line_fcc = empty_fcall_info_cache;
php_git2_multi_cb_t *cb = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rfffz", &diff, &file_fci, &file_fcc, &hunk_fci, &hunk_fcc, &line_fci, &line_fcc, &payload) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3,
&file_fci, &file_fcc,
&hunk_fci, &hunk_fcc,
&line_fci, &line_fcc
);
result = git_diff_foreach(PHP_GIT2_V(_diff, diff), php_git2_git_diff_file_cb, php_git2_git_diff_hunk_cb, php_git2_git_diff_line_cb, cb);
php_git2_multi_cb_free(cb);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto string git_diff_status_char( $status)
*/
PHP_FUNCTION(git_diff_status_char)
{
char result;
long status = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &status) == FAILURE) {
return;
}
result = git_diff_status_char(status);
RETURN_STRINGL(&result, 1, 1);
}
/* }}} */
/* {{{ proto long git_diff_print(resource $diff, long $format, Callable $print_cb, $payload)
*/
PHP_FUNCTION(git_diff_print)
{
int result = 0;
zval *diff = NULL, *payload = NULL;
php_git2_t *_diff = NULL;
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
php_git2_multi_cb_t *cb = NULL;
long format = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rlfz", &diff, &format, &fci, &fcc, &payload) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_diff, php_git2_t*, &diff, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3, &empty_fcall_info, &empty_fcall_info_cache, &empty_fcall_info, &empty_fcall_info_cache, &fci, &fcc)) {
RETURN_FALSE;
}
result = git_diff_print(PHP_GIT2_V(_diff, diff), format, php_git2_git_diff_line_cb, cb);
php_git2_multi_cb_free(cb);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_diff_blobs(resource $old_blob, string $old_as_path, resource $new_blob, string $new_as_path, $options, Callable $file_cb, Callable $hunk_cb, Callable $line_cb, $payload)
*/
PHP_FUNCTION(git_diff_blobs)
{
int result = 0, old_as_path_len = 0, new_as_path_len = 0;
zval *old_blob = NULL, *new_blob = NULL, *options = NULL, *payload = NULL;
php_git2_t *_old_blob = NULL, *_new_blob = NULL;
char *old_as_path = NULL, *new_as_path = NULL;
zend_fcall_info file_fci = empty_fcall_info;
zend_fcall_info_cache file_fcc = empty_fcall_info_cache;
zend_fcall_info hunk_fci = empty_fcall_info;
zend_fcall_info_cache hunk_fcc = empty_fcall_info_cache;
zend_fcall_info line_fci = empty_fcall_info;
zend_fcall_info_cache line_fcc = empty_fcall_info_cache;
php_git2_cb_t *cb = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rsrsafffz", &old_blob, &old_as_path, &old_as_path_len, &new_blob, &new_as_path, &new_as_path_len, &options,
&file_fci, &file_fcc, &hunk_fci, &hunk_fcc, &line_fci, &line_fcc, &payload) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_new_blob, php_git2_t*, &new_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3,
&file_fci, &file_fcc,
&hunk_fci, &hunk_fcc,
&line_fci, &line_fcc
);
result = git_diff_blobs(
PHP_GIT2_V(_old_blob, blob), old_as_path,
PHP_GIT2_V(_new_blob, blob), new_as_path, NULL,
php_git2_git_diff_file_cb, php_git2_git_diff_hunk_cb, php_git2_git_diff_line_cb, cb);
php_git2_multi_cb_free(cb);
RETURN_LONG(result);
}
/* }}} */
/* {{{ proto long git_diff_blob_to_buffer(resource $old_blob, string $old_as_path, string $buffer, long $buffer_len, string $buffer_as_path, $options, Callable $file_cb, Callable $hunk_cb, Callable $line_cb, $payload)
*/
PHP_FUNCTION(git_diff_blob_to_buffer)
{
int result = 0, old_as_path_len = 0, buffer_len = 0, buffer_as_path_len = 0;
zval *old_blob = NULL, *options = NULL, *payload = NULL;
php_git2_t *_old_blob = NULL;
char *old_as_path = NULL, *buffer = NULL, *buffer_as_path = NULL;
zend_fcall_info file_fci = empty_fcall_info;
zend_fcall_info_cache file_fcc = empty_fcall_info_cache;
zend_fcall_info hunk_fci = empty_fcall_info;
zend_fcall_info_cache hunk_fcc = empty_fcall_info_cache;
zend_fcall_info line_fci = empty_fcall_info;
zend_fcall_info_cache line_fcc = empty_fcall_info_cache;
php_git2_multi_cb_t *cb = NULL;
git_diff_options opts = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rsslsafffz", &old_blob, &old_as_path, &old_as_path_len,
&buffer, &buffer_len, &buffer_len, &buffer_as_path, &buffer_as_path_len, &options,
&file_fci, &file_fcc, &hunk_fci, &hunk_fcc, &line_fci, &line_fcc, &payload) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_old_blob, php_git2_t*, &old_blob, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
php_git2_multi_cb_init(&cb, payload TSRMLS_CC, 3,
&file_fci, &file_fcc,
&hunk_fci, &hunk_fcc,
&line_fci, &line_fcc
);
result = git_diff_blob_to_buffer(
PHP_GIT2_V(_old_blob, blob), old_as_path,
buffer, buffer_len, buffer_as_path,
&opts,
php_git2_git_diff_file_cb, php_git2_git_diff_hunk_cb, php_git2_git_diff_line_cb, cb);
php_git2_multi_cb_free(cb);
RETURN_LONG(result);
}
/* }}} */