Skip to content

Commit ed3b37f

Browse files
committed
do not throw exception on abort
1 parent 2c91385 commit ed3b37f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

git2_tree.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct git2_treewalk_payload {
8585
zval *callback_data;
8686
zend_fcall_info callback_i;
8787
zend_fcall_info_cache callback_ic;
88+
zend_bool aborted;
8889
};
8990

9091
static int git2_treewalk_cb(const char *root, const git_tree_entry *entry, void *payload) {
@@ -108,11 +109,14 @@ static int git2_treewalk_cb(const char *root, const git_tree_entry *entry, void
108109

109110
error = zend_call_function(&p->callback_i, &p->callback_ic);
110111
if (error == FAILURE) {
112+
p->aborted = 1; // failure of zend_call_function will already throw something (TODO confirm if this is indeed the case)
111113
return -1; // causes end of walk
112114
} else if (!Z_ISUNDEF(retval)) {
113115
convert_to_long(&retval);
114116
error = Z_LVAL(retval);
115117
zval_ptr_dtor(&retval);
118+
if (error < 0)
119+
p->aborted = 1;
116120
} else {
117121
error = 0;
118122
}
@@ -134,6 +138,7 @@ static PHP_METHOD(Tree, walk) {
134138
struct git2_treewalk_payload p;
135139
p.this = getThis();
136140
p.callback_data = NULL;
141+
p.aborted = 0;
137142

138143
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lf|z", &mode, &p.callback_i, &p.callback_ic, &p.callback_data) != SUCCESS) {
139144
return;
@@ -152,6 +157,10 @@ static PHP_METHOD(Tree, walk) {
152157

153158
int res = git_tree_walk(intern->tree, mode, git2_treewalk_cb, &p);
154159

160+
if (p.aborted) {
161+
RETURN_FALSE; // no point throwing an exception if aborted
162+
}
163+
155164
if (res != 0) {
156165
git2_throw_last_error();
157166
return;

0 commit comments

Comments
 (0)