Skip to content

Commit 605af01

Browse files
committed
add signature
1 parent a1e3477 commit 605af01

File tree

4 files changed

+189
-1
lines changed

4 files changed

+189
-1
lines changed

config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PHP_ARG_ENABLE(git2-debug, for git2 debug support,
77
if test $PHP_GIT2 != "no"; then
88
PHP_SUBST(GIT2_SHARED_LIBADD)
99

10-
PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c, $ext_shared)
10+
PHP_NEW_EXTENSION(git2, php_git2.c repository.c commit.c tree.c clone.c blob.c helper.c revwalk.c treebuilder.c reference.c g_config.c object.c index.c revparse.c branch.c tag.c status.c cred.c remote.c transport.c diff.c checkout.c filter.c ignore.c indexer.c pathspec.c patch.c merge.c note.c odb.c reflog.c blame.c packbuilder.c stash.c signature.c, $ext_shared)
1111
PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include])
1212

1313
# for now

php_git2.c

+8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "blame.h"
5858
#include "packbuilder.h"
5959
#include "stash.h"
60+
#include "signature.h"
6061

6162
int git2_resource_handle;
6263

@@ -796,6 +797,13 @@ static zend_function_entry php_git2_functions[] = {
796797
PHP_FE(git_stash_foreach, arginfo_git_stash_foreach)
797798
PHP_FE(git_stash_drop, arginfo_git_stash_drop)
798799

800+
/* signature */
801+
PHP_FE(git_signature_new, arginfo_git_signature_new)
802+
PHP_FE(git_signature_now, arginfo_git_signature_now)
803+
PHP_FE(git_signature_default, arginfo_git_signature_default)
804+
PHP_FE(git_signature_dup, arginfo_git_signature_dup)
805+
PHP_FE(git_signature_free, arginfo_git_signature_free)
806+
799807
/* misc */
800808
PHP_FE(git_resource_type, arginfo_git_resource_type)
801809
PHP_FE_END

signature.c

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include "php_git2.h"
2+
#include "php_git2_priv.h"
3+
#include "signature.h"
4+
5+
/* {{{ proto resource git_signature_new(string $name, string $email, $time, long $offset)
6+
*/
7+
PHP_FUNCTION(git_signature_new)
8+
{
9+
php_git2_t *result = NULL;
10+
git_signature *out = NULL;
11+
char *name = NULL, *email = NULL;
12+
int name_len = 0, email_len = 0, error = 0;
13+
zval *time = NULL;
14+
long offset = 0;
15+
16+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
17+
"ssal", &name, &name_len, &email, &email_len, &time, &offset) == FAILURE) {
18+
return;
19+
}
20+
21+
error = git_signature_new(&out, name, email, time, offset);
22+
if (php_git2_check_error(error, "git_signature_new" TSRMLS_CC)) {
23+
RETURN_FALSE;
24+
}
25+
}
26+
/* }}} */
27+
28+
/* {{{ proto resource git_signature_now(string $name, string $email)
29+
*/
30+
PHP_FUNCTION(git_signature_now)
31+
{
32+
php_git2_t *result = NULL;
33+
git_signature *out = NULL;
34+
char *name = NULL, *email = NULL;
35+
int name_len = 0, email_len = 0, error = 0;
36+
37+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
38+
"ss", &name, &name_len, &email, &email_len) == FAILURE) {
39+
return;
40+
}
41+
42+
error = git_signature_now(&out, name, email);
43+
if (php_git2_check_error(error, "git_signature_now" TSRMLS_CC)) {
44+
RETURN_FALSE;
45+
}
46+
}
47+
/* }}} */
48+
49+
/* {{{ proto resource git_signature_default(resource $repo)
50+
*/
51+
PHP_FUNCTION(git_signature_default)
52+
{
53+
php_git2_t *result = NULL, *_repo = NULL;
54+
git_signature *out = NULL;
55+
zval *repo = NULL;
56+
int error = 0;
57+
58+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
59+
"r", &repo) == FAILURE) {
60+
return;
61+
}
62+
63+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
64+
error = git_signature_default(&out, PHP_GIT2_V(_repo, repository));
65+
if (php_git2_check_error(error, "git_signature_default" TSRMLS_CC)) {
66+
RETURN_FALSE;
67+
}
68+
}
69+
/* }}} */
70+
71+
/* {{{ proto array git_signature_dup(array $sig)
72+
*/
73+
PHP_FUNCTION(git_signature_dup)
74+
{
75+
git_signature *result = NULL;
76+
zval *__result = NULL, *sig = NULL;
77+
78+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
79+
"a", &sig) == FAILURE) {
80+
return;
81+
}
82+
83+
result = git_signature_dup(sig);
84+
php_git2_signature_to_array(result, &__result TSRMLS_CC);
85+
RETURN_ZVAL(__result, 0, 1);
86+
}
87+
/* }}} */
88+
89+
/* {{{ proto void git_signature_free(array $sig)
90+
*/
91+
PHP_FUNCTION(git_signature_free)
92+
{
93+
// zval *sig = NULL;
94+
//
95+
// if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
96+
// "a", &sig) == FAILURE) {
97+
// return;
98+
// }
99+
//
100+
// if (GIT2_SHOULD_FREE(_sig)) {
101+
// git_signature_free(sig);
102+
// GIT2_SHOULD_FREE(_sig) = 0;
103+
// };
104+
// zval_ptr_dtor(&sig);
105+
}
106+
/* }}} */
107+

signature.h

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* PHP Libgit2 Extension
3+
*
4+
* https://github.com/libgit2/php-git
5+
*
6+
* Copyright 2014 Shuhei Tanuma. All rights reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#ifndef PHP_GIT2_SIGNATURE_H
27+
#define PHP_GIT2_SIGNATURE_H
28+
29+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_new, 0, 0, 4)
30+
ZEND_ARG_INFO(0, name)
31+
ZEND_ARG_INFO(0, email)
32+
ZEND_ARG_INFO(0, time)
33+
ZEND_ARG_INFO(0, offset)
34+
ZEND_END_ARG_INFO()
35+
36+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_now, 0, 0, 2)
37+
ZEND_ARG_INFO(0, name)
38+
ZEND_ARG_INFO(0, email)
39+
ZEND_END_ARG_INFO()
40+
41+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_default, 0, 0, 1)
42+
ZEND_ARG_INFO(0, repo)
43+
ZEND_END_ARG_INFO()
44+
45+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_dup, 0, 0, 1)
46+
ZEND_ARG_INFO(0, sig)
47+
ZEND_END_ARG_INFO()
48+
49+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_signature_free, 0, 0, 1)
50+
ZEND_ARG_INFO(0, sig)
51+
ZEND_END_ARG_INFO()
52+
53+
/* {{{ proto resource git_signature_new(name, email, time, offset)
54+
*/
55+
PHP_FUNCTION(git_signature_new);
56+
57+
/* {{{ proto resource git_signature_now(name, email)
58+
*/
59+
PHP_FUNCTION(git_signature_now);
60+
61+
/* {{{ proto resource git_signature_default(repo)
62+
*/
63+
PHP_FUNCTION(git_signature_default);
64+
65+
/* {{{ proto resource git_signature_dup(sig)
66+
*/
67+
PHP_FUNCTION(git_signature_dup);
68+
69+
/* {{{ proto void git_signature_free(sig)
70+
*/
71+
PHP_FUNCTION(git_signature_free);
72+
73+
#endif

0 commit comments

Comments
 (0)