Skip to content

Commit 8a59286

Browse files
committed
improve codes
1 parent 1359d14 commit 8a59286

File tree

6 files changed

+52
-52
lines changed

6 files changed

+52
-52
lines changed

pathspec.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ PHP_FUNCTION(git_pathspec_new)
1212
git_strarray _pathspec = {0};
1313
int error = 0;
1414

15-
/* TODO(chobie): generate converter */
1615
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
1716
"a", &pathspec) == FAILURE) {
1817
return;
1918
}
2019

2120
php_git2_array_to_strarray(&_pathspec, pathspec TSRMLS_CC);
22-
error = git_pathspec_new(&out, pathspec);
21+
error = git_pathspec_new(&out, &pathspec);
2322
if (php_git2_check_error(error, "git_pathspec_new" TSRMLS_CC)) {
2423
RETURN_FALSE;
2524
}

php_git2.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,17 @@ PHP_FUNCTION(git_libgit2_capabilities)
318318
}
319319

320320

321+
PHP_FUNCTION(git_libgit2_version)
322+
{
323+
char buf[32] = {0};
324+
int major, minor, rev;
325+
326+
git_libgit2_version(&major, &minor, &rev);
327+
snprintf(buf, 32, "%d.%d.%d", major, minor, rev);
328+
329+
RETURN_STRING(buf, 1);
330+
}
331+
321332
static zend_function_entry php_git2_functions[] = {
322333
/* repository */
323334
PHP_FE(git_repository_new, arginfo_git_repository_new)
@@ -936,6 +947,7 @@ static zend_function_entry php_git2_functions[] = {
936947
/* misc */
937948
PHP_FE(git_resource_type, arginfo_git_resource_type)
938949
PHP_FE(git_libgit2_capabilities, NULL)
950+
PHP_FE(git_libgit2_version, NULL)
939951
PHP_FE_END
940952
};
941953

reflog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ PHP_FUNCTION(git_reflog_entry_id_old)
219219
}
220220
/* }}} */
221221

222-
/* {{{ proto resource git_reflog_entry_id_new(resource $entry)
222+
/* {{{ proto string git_reflog_entry_id_new(resource $entry)
223223
*/
224224
PHP_FUNCTION(git_reflog_entry_id_new)
225225
{

remote.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ PHP_FUNCTION(git_remote_create_with_fetchspec)
7676
}
7777
/* }}} */
7878

79-
80-
8179
/* {{{ proto resource git_remote_create_inmemory(resource $repo, string $fetch, string $url)
8280
*/
8381
PHP_FUNCTION(git_remote_create_inmemory)

repository.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -720,33 +720,31 @@ PHP_FUNCTION(git_repository_mergehead_foreach)
720720
/* }}} */
721721

722722

723-
/* {{{ proto resource git_repository_hashfile(repo, path, type, as_path)
724-
*/
723+
/* {{{ proto string git_repository_hashfile(resource $repo, string $path, long $type, string $as_path)
724+
*/
725725
PHP_FUNCTION(git_repository_hashfile)
726726
{
727-
zval *repo;
728-
php_git2_t *_repo;
729-
char *path = {0};
730-
int path_len;
731-
zval *type;
732-
php_git2_t *_type;
733-
char *as_path = {0};
734-
int as_path_len;
735-
git_oid oid;
736-
int error = 0;
737-
char out[GIT2_OID_HEXSIZE] = {0};
727+
php_git2_t *result = NULL, *_repo = NULL;
728+
git_oid out = {0};
729+
zval *repo = NULL;
730+
char *path = NULL, *as_path = NULL, buf[41] = {0};
731+
int path_len = 0, as_path_len = 0, error = 0;
732+
long type = 0;
738733

739734
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
740-
"rsrs", &repo, &path, &path_len, &type, &as_path, &as_path_len) == FAILURE) {
735+
"rsls", &repo, &path, &path_len, &type, &as_path, &as_path_len) == FAILURE) {
741736
return;
742737
}
738+
743739
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
744740
error = git_repository_hashfile(&out, PHP_GIT2_V(_repo, repository), path, type, as_path);
745741
if (php_git2_check_error(error, "git_repository_hashfile" TSRMLS_CC)) {
746-
RETURN_FALSE
742+
RETURN_FALSE;
747743
}
748-
git_oid_fmt(out, &oid);
744+
git_oid_fmt(buf, &out);
745+
RETURN_STRING(buf, 1);
749746
}
747+
/* }}} */
750748

751749
/* {{{ proto long git_repository_set_head(repo, refname)
752750
*/
@@ -769,6 +767,7 @@ PHP_FUNCTION(git_repository_set_head)
769767
}
770768
RETURN_TRUE;
771769
}
770+
/* }}} */
772771

773772
/* {{{ proto long git_repository_set_head_detached(repo, commitish)
774773
*/
@@ -796,6 +795,7 @@ PHP_FUNCTION(git_repository_set_head_detached)
796795
}
797796
RETURN_TRUE;
798797
}
798+
/* }}} */
799799

800800
/* {{{ proto long git_repository_detach_head(repo)
801801
*/
@@ -816,6 +816,7 @@ PHP_FUNCTION(git_repository_detach_head)
816816
}
817817
RETURN_TRUE;
818818
}
819+
/* }}} */
819820

820821
/* {{{ proto long git_repository_state(repo)
821822
*/
@@ -834,6 +835,7 @@ PHP_FUNCTION(git_repository_state)
834835

835836
RETURN_LONG(state);
836837
}
838+
/* }}} */
837839

838840
/* {{{ proto long git_repository_set_namespace(repo, nmspace)
839841
*/
@@ -856,6 +858,7 @@ PHP_FUNCTION(git_repository_set_namespace)
856858
}
857859
RETURN_TRUE;
858860
}
861+
/* }}} */
859862

860863
/* {{{ proto long git_repository_is_shallow(repo)
861864
*/
@@ -872,4 +875,5 @@ PHP_FUNCTION(git_repository_is_shallow)
872875
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
873876
is_shallow = git_repository_is_shallow(PHP_GIT2_V(_repo, repository));
874877
RETURN_LONG(is_shallow);
875-
}
878+
}
879+
/* }}} */

tag.c

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,16 @@ static int php_git2_tag_foreach_cb(const char *name, git_oid *oid, void *payload
3333
return retval;
3434
}
3535

36-
3736
/* {{{ proto resource git_tag_lookup(resource $repo, string $id)
3837
*/
3938
PHP_FUNCTION(git_tag_lookup)
4039
{
41-
php_git2_t *result = NULL;
40+
php_git2_t *result = NULL, *_repo = NULL;
4241
git_tag *out = NULL;
4342
zval *repo = NULL;
44-
php_git2_t *_repo = NULL;
4543
char *id = NULL;
46-
int id_len = 0;
47-
git_oid __id;
48-
int error = 0;
44+
int id_len = 0, error = 0;
45+
git_oid __id = {0};
4946

5047
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
5148
"rs", &repo, &id, &id_len) == FAILURE) {
@@ -60,16 +57,13 @@ PHP_FUNCTION(git_tag_lookup)
6057
if (php_git2_check_error(error, "git_tag_lookup" TSRMLS_CC)) {
6158
RETURN_FALSE;
6259
}
63-
PHP_GIT2_MAKE_RESOURCE(result);
64-
PHP_GIT2_V(result, tag) = out;
65-
result->type = PHP_GIT2_TYPE_TAG;
66-
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
67-
result->should_free_v = 0;
68-
ZVAL_RESOURCE(return_value, result->resource_id);
60+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TAG, out, 1 TSRMLS_CC)) {
61+
RETURN_FALSE;
62+
}
63+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
6964
}
7065
/* }}} */
7166

72-
7367
/* {{{ proto resource git_tag_lookup_prefix(resource $repo, string $id)
7468
*/
7569
PHP_FUNCTION(git_tag_lookup_prefix)
@@ -152,8 +146,7 @@ PHP_FUNCTION(git_tag_owner)
152146
{
153147
git_repository *result = NULL;
154148
zval *tag = NULL;
155-
php_git2_t *_tag = NULL;
156-
php_git2_t *__result = NULL;
149+
php_git2_t *_tag = NULL, *__result = NULL;
157150

158151
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
159152
"r", &tag) == FAILURE) {
@@ -162,12 +155,10 @@ PHP_FUNCTION(git_tag_owner)
162155

163156
ZEND_FETCH_RESOURCE(_tag, php_git2_t*, &tag, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
164157
result = git_tag_owner(PHP_GIT2_V(_tag, tag));
165-
PHP_GIT2_MAKE_RESOURCE(__result);
166-
PHP_GIT2_V(__result, tag) = tag;
167-
__result->type = PHP_GIT2_TYPE_TAG;
168-
__result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
169-
__result->should_free_v = 0;
170-
ZVAL_RESOURCE(return_value, __result->resource_id);
158+
if (php_git2_make_resource(&__result, PHP_GIT2_TYPE_TAG, result, 1 TSRMLS_CC)) {
159+
RETURN_FALSE;
160+
}
161+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(__result));
171162
}
172163
/* }}} */
173164

@@ -433,7 +424,6 @@ PHP_FUNCTION(git_tag_create_lightweight)
433424
}
434425
/* }}} */
435426

436-
437427
/* {{{ proto long git_tag_delete(resource $repo, string $tag_name)
438428
*/
439429
PHP_FUNCTION(git_tag_delete)
@@ -546,10 +536,9 @@ PHP_FUNCTION(git_tag_foreach)
546536
*/
547537
PHP_FUNCTION(git_tag_peel)
548538
{
549-
php_git2_t *result = NULL;
539+
php_git2_t *result = NULL, *_tag = NULL;
550540
git_object *tag_target_out = NULL;
551541
zval *tag = NULL;
552-
php_git2_t *_tag = NULL;
553542
int error = 0;
554543

555544
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
@@ -562,11 +551,9 @@ PHP_FUNCTION(git_tag_peel)
562551
if (php_git2_check_error(error, "git_tag_peel" TSRMLS_CC)) {
563552
RETURN_FALSE;
564553
}
565-
PHP_GIT2_MAKE_RESOURCE(result);
566-
PHP_GIT2_V(result, object) = tag_target_out;
567-
result->type = PHP_GIT2_TYPE_OBJECT;
568-
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
569-
result->should_free_v = 0;
570-
ZVAL_RESOURCE(return_value, result->resource_id);
554+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_OBJECT, tag_target_out, 1 TSRMLS_CC)) {
555+
RETURN_FALSE;
556+
}
557+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
571558
}
572559
/* }}} */

0 commit comments

Comments
 (0)