-
Notifications
You must be signed in to change notification settings - Fork 78
/
merge.c
321 lines (283 loc) · 10.1 KB
/
merge.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
#include "php_git2.h"
#include "php_git2_priv.h"
#include "merge.h"
/* {{{ proto resource git_merge_base(resource $repo, string $one, string $two)
*/
PHP_FUNCTION(git_merge_base)
{
php_git2_t *_repo = NULL;
git_oid out = {0}, __one = {0}, __two = {0};
zval *repo = NULL;
char *one = NULL, *two = NULL, oid[41] = {0};
int one_len = 0, two_len = 0, error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rss", &repo, &one, &one_len, &two, &two_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (git_oid_fromstrn(&__one, one, one_len)) {
RETURN_FALSE;
}
if (git_oid_fromstrn(&__two, two, two_len)) {
RETURN_FALSE;
}
error = git_merge_base(&out, PHP_GIT2_V(_repo, repository), &__one, &__two);
if (php_git2_check_error(error, "git_merge_base" TSRMLS_CC)) {
RETURN_FALSE;
}
git_oid_fmt(oid, &out);
RETURN_STRING(oid, 1);
}
/* }}} */
/* {{{ proto resource git_merge_base_many(resource $repo, long $length, string $input_array[])
*/
PHP_FUNCTION(git_merge_base_many)
{
// php_git2_t *result = NULL, *_repo = NULL;
// git_oid out = {0}, __input_array[] = {0};
// zval *repo = NULL;
// long length = 0;
// char *input_array[] = NULL;
// int input_array[]_len = 0, error = 0;
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
// "rls", &repo, &length, &input_array[], &input_array[]_len) == FAILURE) {
// return;
// }
// ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
// if (git_oid_fromstrn(&__input_array[], input_array[], input_array[]_len)) {
// RETURN_FALSE;
// }
// error = git_merge_base_many(&__out, PHP_GIT2_V(_repo, repository), length, __input_array[]);
// if (php_git2_check_error(error, "git_merge_base_many" TSRMLS_CC)) {
// RETURN_FALSE;
// }
// if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OID, out, 1 TSRMLS_CC)) {
// RETURN_FALSE;
// }
// ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_merge_head_from_ref(resource $repo, resource $ref)
*/
PHP_FUNCTION(git_merge_head_from_ref)
{
php_git2_t *result = NULL, *_repo = NULL, *_ref = NULL;
git_merge_head *out = NULL;
zval *repo = NULL, *ref = NULL;
int error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rr", &repo, &ref) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_ref, php_git2_t*, &ref, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
error = git_merge_head_from_ref(&out, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_ref, reference));
if (php_git2_check_error(error, "git_merge_head_from_ref" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_merge_head_from_fetchhead(resource $repo, string $branch_name, string $remote_url, string $oid)
*/
PHP_FUNCTION(git_merge_head_from_fetchhead)
{
php_git2_t *result = NULL, *_repo = NULL;
git_merge_head *out = NULL;
zval *repo = NULL;
char *branch_name = NULL, *remote_url = NULL, *oid = NULL;
int branch_name_len = 0, remote_url_len = 0, oid_len = 0, error = 0;
git_oid __oid = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rsss", &repo, &branch_name, &branch_name_len, &remote_url, &remote_url_len, &oid, &oid_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (git_oid_fromstrn(&__oid, oid, oid_len)) {
RETURN_FALSE;
}
error = git_merge_head_from_fetchhead(&out, PHP_GIT2_V(_repo, repository), branch_name, remote_url, &__oid);
if (php_git2_check_error(error, "git_merge_head_from_fetchhead" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_merge_head_from_oid(resource $repo, string $oid)
*/
PHP_FUNCTION(git_merge_head_from_oid)
{
php_git2_t *result = NULL, *_repo = NULL;
git_merge_head *out = NULL;
zval *repo = NULL;
char *oid = NULL;
int oid_len = 0, error = 0;
git_oid __oid = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs", &repo, &oid, &oid_len) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (git_oid_fromstrn(&__oid, oid, oid_len)) {
RETURN_FALSE;
}
error = git_merge_head_from_oid(&out, PHP_GIT2_V(_repo, repository), &__oid);
if (php_git2_check_error(error, "git_merge_head_from_oid" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_HEAD, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto void git_merge_head_free(resource $head)
*/
PHP_FUNCTION(git_merge_head_free)
{
zval *head = NULL;
php_git2_t *_head = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &head) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_head, php_git2_t*, &head, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (GIT2_SHOULD_FREE(_head)) {
git_merge_head_free(PHP_GIT2_V(_head, merge_head));
GIT2_SHOULD_FREE(_head) = 0;
};
zval_ptr_dtor(&head);
}
/* }}} */
/* {{{ proto resource git_merge_trees(resource $repo, resource $ancestor_tree, resource $our_tree, resource $their_tree, $opts)
*/
PHP_FUNCTION(git_merge_trees)
{
php_git2_t *result = NULL, *_repo = NULL, *_ancestor_tree = NULL, *_our_tree = NULL, *_their_tree = NULL;
git_index *out = NULL;
zval *repo = NULL, *ancestor_tree = NULL, *our_tree = NULL, *their_tree = NULL, *opts = NULL;
int error = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rrrr<git_merge_tree_opts>", &repo, &ancestor_tree, &our_tree, &their_tree, &opts) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_ancestor_tree, php_git2_t*, &ancestor_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_our_tree, php_git2_t*, &our_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_their_tree, php_git2_t*, &their_tree, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
error = git_merge_trees(&out, PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_ancestor_tree, tree), PHP_GIT2_V(_our_tree, tree), PHP_GIT2_V(_their_tree, tree), opts);
if (php_git2_check_error(error, "git_merge_trees" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_INDEX, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto resource git_merge(resource $repo, array $their_heads, array $opts)
*/
PHP_FUNCTION(git_merge)
{
php_git2_t *result = NULL, *_repo = NULL, *_their_head = NULL;
git_merge_result *out = NULL;
zval *repo = NULL, *opts = NULL, *theirhead = NULL;
git_merge_head *heads[1];
int error = 0;
git_merge_opts options = GIT_MERGE_OPTS_INIT;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rza", &repo, &theirhead, &opts) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
ZEND_FETCH_RESOURCE(_their_head, php_git2_t*, &theirhead, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
heads[0] = PHP_GIT2_V(_their_head, merge_head);
options.merge_flags = GIT_MERGE_NO_FASTFORWARD;
error = git_merge(&out, PHP_GIT2_V(_repo, repository), heads, 1, &options);
if (php_git2_check_error(error, "git_merge" TSRMLS_CC)) {
RETURN_FALSE;
}
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_MERGE_RESULT, out, 1 TSRMLS_CC)) {
RETURN_FALSE;
}
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */
/* {{{ proto long git_merge_result_is_uptodate(resource $merge_result)
*/
PHP_FUNCTION(git_merge_result_is_uptodate)
{
int result = 0;
zval *merge_result = NULL;
php_git2_t *_merge_result = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &merge_result) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_merge_result_is_uptodate(PHP_GIT2_V(_merge_result, merge_result));
RETURN_BOOL(result);
}
/* }}} */
/* {{{ proto long git_merge_result_is_fastforward(resource $merge_result)
*/
PHP_FUNCTION(git_merge_result_is_fastforward)
{
int result = 0;
zval *merge_result = NULL;
php_git2_t *_merge_result = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &merge_result) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
result = git_merge_result_is_fastforward(PHP_GIT2_V(_merge_result, merge_result));
RETURN_BOOL(result);
}
/* }}} */
/* {{{ proto resource git_merge_result_fastforward_oid(resource $merge_result)
*/
PHP_FUNCTION(git_merge_result_fastforward_oid)
{
php_git2_t *_merge_result = NULL;
git_oid out = {0};
zval *merge_result = NULL;
int error = 0;
char buf[41] = {0};
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &merge_result) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
error = git_merge_result_fastforward_oid(&out, PHP_GIT2_V(_merge_result, merge_result));
if (php_git2_check_error(error, "git_merge_result_fastforward_oid" TSRMLS_CC)) {
RETURN_FALSE;
}
git_oid_fmt(buf, &out);
RETURN_STRING(buf, 1);
}
/* }}} */
/* {{{ proto void git_merge_result_free(resource $merge_result)
*/
PHP_FUNCTION(git_merge_result_free)
{
zval *merge_result = NULL;
php_git2_t *_merge_result = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"r", &merge_result) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(_merge_result, php_git2_t*, &merge_result, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
if (GIT2_SHOULD_FREE(_merge_result)) {
git_merge_result_free(PHP_GIT2_V(_merge_result, merge_result));
GIT2_SHOULD_FREE(_merge_result) = 0;
};
zval_ptr_dtor(&merge_result);
}
/* }}} */