Skip to content

Commit 0543448

Browse files
committed
[reference] add foreach callback
1 parent 10249ff commit 0543448

File tree

8 files changed

+227
-79
lines changed

8 files changed

+227
-79
lines changed

helper.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v
171171
case PHP_GIT2_TYPE_REFERENCE:
172172
PHP_GIT2_V(result, reference) = (git_reference*)resource;
173173
break;
174+
case PHP_GIT2_TYPE_REFERENCE_ITERATOR:
175+
PHP_GIT2_V(result, reference_iterator) = (git_reference_iterator*)resource;
176+
break;
174177
case PHP_GIT2_TYPE_CONFIG:
175178
PHP_GIT2_V(result, config) = (git_config*)resource;
176179
break;
@@ -237,6 +240,8 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v
237240
case PHP_GIT2_TYPE_DIFF_LINE:
238241
PHP_GIT2_V(result, diff_line) = (git_diff_line*)resource;
239242
break;
243+
default:
244+
php_error_docref(NULL TSRMLS_CC, E_ERROR, "passed resource type does not support. probably bug.");
240245
}
241246

242247
result->type = type;
@@ -285,4 +290,27 @@ int php_git2_call_function_v(
285290
efree(params);
286291
}
287292
return 0;
293+
}
294+
295+
int php_git2_cb_init(php_git2_cb_t **out, zend_fcall_info *fci, zend_fcall_info_cache *fcc, void *payload TSRMLS_DC)
296+
{
297+
php_git2_cb_t *cb;
298+
299+
cb = (struct php_git2_cb_t*)emalloc(sizeof(php_git2_cb_t));
300+
if (cb == NULL) {
301+
return 1;
302+
}
303+
304+
cb->payload = payload;
305+
cb->fci = fci;
306+
cb->fcc = fcc;
307+
GIT2_TSRMLS_SET2(cb, TSRMLS_C);
308+
309+
*out = cb;
310+
return 0;
311+
}
312+
313+
void php_git2_cb_free(php_git2_cb_t *target)
314+
{
315+
efree(target);
288316
}

helper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ int php_git2_make_resource(php_git2_t **out, enum php_git2_resource_type type, v
4747
int php_git2_call_function_v(
4848
zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC, zval **retval_ptr_ptr, zend_uint param_count, ...);
4949

50+
int php_git2_cb_init(php_git2_cb_t **out, zend_fcall_info *fci, zend_fcall_info_cache *fcc, void *payload TSRMLS_DC);
51+
52+
void php_git2_cb_free(php_git2_cb_t *target);
53+
5054
#endif

ng.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public function shouldResource(Arg $arg)
359359
"git_buf",
360360
"git_filter_source",
361361
"git_diff_line",
362+
"git_reference_iterator",
362363
);
363364
}
364365

php_git2.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ void static destruct_git2(zend_rsrc_list_entry *rsrc TSRMLS_DC)
8989
case PHP_GIT2_TYPE_OBJECT:
9090
git_object_free(PHP_GIT2_V(resource, object));
9191
break;
92-
default:
93-
break;
9492
}
9593
}
9694

php_git2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ enum php_git2_resource_type {
8686
PHP_GIT2_TYPE_REVWALK,
8787
PHP_GIT2_TYPE_TREEBUILDER,
8888
PHP_GIT2_TYPE_REFERENCE,
89+
PHP_GIT2_TYPE_REFERENCE_ITERATOR,
8990
PHP_GIT2_TYPE_CONFIG,
9091
PHP_GIT2_TYPE_OBJECT,
9192
PHP_GIT2_TYPE_INDEX,
@@ -121,6 +122,7 @@ typedef struct php_git2_t {
121122
git_revwalk *revwalk;
122123
git_treebuilder *treebuilder;
123124
git_reference *reference;
125+
git_reference_iterator *reference_iterator;
124126
git_config *config;
125127
git_object *object;
126128
git_index *index;

php_git2_priv.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ do {\
7171

7272
#define GIT2_OID_HEXSIZE (GIT_OID_HEXSZ+1)
7373

74+
typedef struct php_git2_cb_t {
75+
zval *payload;
76+
zend_fcall_info *fci;
77+
zend_fcall_info_cache *fcc;
78+
GIT2_TSRMLS_DECL
79+
} php_git2_cb_t;
80+
7481
#include "helper.h"
7582

7683
#endif

0 commit comments

Comments
 (0)