Skip to content

Commit 7e31ddb

Browse files
committed
[index] implment several functions
1 parent faf4e4a commit 7e31ddb

File tree

4 files changed

+310
-143
lines changed

4 files changed

+310
-143
lines changed

commit.c

-11
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,6 @@ PHP_FUNCTION(git_commit_nth_gen_ancestor)
469469

470470
}
471471

472-
static zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC)
473-
{
474-
zval *result = NULL, **element;
475-
476-
if (zend_hash_find(Z_ARRVAL_P(array), name, name_len, (void**)&element) == SUCCESS) {
477-
result = *element;
478-
}
479-
480-
return result;
481-
}
482-
483472
static void php_git2_array_to_signature(git_signature *signature, zval *author TSRMLS_DC)
484473
{
485474
zval *name = NULL, *email = NULL, *time = NULL;

helper.c

+38
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,41 @@ int php_git2_check_error(int error_code, const char *action TSRMLS_DC)
1616
result = 1;
1717
return result;
1818
}
19+
20+
21+
zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC)
22+
{
23+
zval *result = NULL, **element;
24+
25+
if (zend_hash_find(Z_ARRVAL_P(array), name, name_len, (void**)&element) == SUCCESS) {
26+
result = *element;
27+
}
28+
29+
return result;
30+
}
31+
32+
long php_git2_read_arrval_long(zval *array, char *name, size_t name_len TSRMLS_DC)
33+
{
34+
zval *tmp;
35+
long result = 0;
36+
37+
tmp = php_git2_read_arrval(array, name, name_len TSRMLS_CC);
38+
if (tmp) {
39+
result = Z_LVAL_P(tmp);
40+
}
41+
42+
return result;
43+
}
44+
45+
const char* php_git2_read_arrval_string(zval *array, char *name, size_t name_len TSRMLS_DC)
46+
{
47+
zval *tmp;
48+
const char *result = NULL;
49+
50+
tmp = php_git2_read_arrval(array, name, name_len TSRMLS_CC);
51+
if (tmp) {
52+
result = Z_STRVAL_P(tmp);
53+
}
54+
55+
return result;
56+
}

helper.h

+6
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@
3030

3131
int php_git2_check_error(int error_code, const char *action TSRMLS_DC);
3232

33+
zval* php_git2_read_arrval(zval *array, char *name, size_t name_len TSRMLS_DC);
34+
35+
long php_git2_read_arrval_long(zval *array, char *name, size_t name_len TSRMLS_DC);
36+
37+
const char* php_git2_read_arrval_string(zval *array, char *name, size_t name_len TSRMLS_DC);
38+
3339
#endif

0 commit comments

Comments
 (0)