Skip to content

Commit 34ab9e7

Browse files
committed
[stash] add stash callback
1 parent 152812c commit 34ab9e7

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

stash.c

+33-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22
#include "php_git2_priv.h"
33
#include "stash.h"
44

5+
static int php_git2_stash_cb(size_t index,
6+
const char* message,
7+
const git_oid *stash_id,
8+
void *payload)
9+
{
10+
php_git2_t *result;
11+
zval *param_index, *param_message,*param_stash_id, *retval_ptr = NULL;
12+
php_git2_cb_t *p = (php_git2_cb_t*)payload;
13+
int i = 0;
14+
long retval = 0;
15+
char _oid[41] = {0};
16+
GIT2_TSRMLS_SET(p->tsrm_ls)
17+
18+
git_oid_fmt(_oid, stash_id);
19+
20+
Z_ADDREF_P(p->payload);
21+
MAKE_STD_ZVAL(param_index);
22+
MAKE_STD_ZVAL(param_message);
23+
MAKE_STD_ZVAL(param_stash_id);
24+
ZVAL_LONG(param_index, index);
25+
ZVAL_STRING(param_message, message, 1);
26+
ZVAL_STRING(param_stash_id, _oid, 1);
27+
28+
if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 4, &param_index, &param_message, &param_stash_id, &p->payload)) {
29+
return GIT_EUSER;
30+
}
31+
32+
retval = Z_LVAL_P(retval_ptr);
33+
zval_ptr_dtor(&retval_ptr);
34+
return retval;
35+
}
36+
537
/* {{{ proto resource git_stash_save(resource $repo, array $stasher, string $message, long $flags)
638
*/
739
PHP_FUNCTION(git_stash_save)
@@ -49,7 +81,7 @@ PHP_FUNCTION(git_stash_foreach)
4981
if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {
5082
RETURN_FALSE;
5183
}
52-
//result = git_stash_foreach(PHP_GIT2_V(_repo, repository), <CHANGEME>, cb);
84+
result = git_stash_foreach(PHP_GIT2_V(_repo, repository), php_git2_stash_cb, cb);
5385
php_git2_cb_free(cb);
5486
RETURN_LONG(result);
5587
}

stash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ZEND_END_ARG_INFO()
3636
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_foreach, 0, 0, 3)
3737
ZEND_ARG_INFO(0, repo)
3838
ZEND_ARG_INFO(0, callback)
39-
ZEND_ARG_INFO(0, payload)
39+
ZEND_ARG_INFO(1, payload)
4040
ZEND_END_ARG_INFO()
4141

4242
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_drop, 0, 0, 2)

0 commit comments

Comments
 (0)