Skip to content

Commit 323f805

Browse files
committed
add reset
1 parent 605af01 commit 323f805

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-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 signature.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 reset.c, $ext_shared)
1111
PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include])
1212

1313
# for now

php_git2.c

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "packbuilder.h"
5959
#include "stash.h"
6060
#include "signature.h"
61+
#include "reset.h"
6162

6263
int git2_resource_handle;
6364

@@ -804,6 +805,10 @@ static zend_function_entry php_git2_functions[] = {
804805
PHP_FE(git_signature_dup, arginfo_git_signature_dup)
805806
PHP_FE(git_signature_free, arginfo_git_signature_free)
806807

808+
/* reset */
809+
PHP_FE(git_reset, arginfo_git_reset)
810+
PHP_FE(git_reset_default, arginfo_git_reset_default)
811+
807812
/* misc */
808813
PHP_FE(git_resource_type, arginfo_git_resource_type)
809814
PHP_FE_END

reset.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "php_git2.h"
2+
#include "php_git2_priv.h"
3+
#include "reset.h"
4+
5+
/* {{{ proto long git_reset(resource $repo, resource $target, $reset_type)
6+
*/
7+
PHP_FUNCTION(git_reset)
8+
{
9+
int result = 0, error = 0;
10+
zval *repo = NULL, *target = NULL, *reset_type = NULL;
11+
php_git2_t *_repo = NULL, *_target = NULL;
12+
13+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
14+
"rr<git_reset_t>", &repo, &target, &reset_type) == FAILURE) {
15+
return;
16+
}
17+
18+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
19+
ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
20+
result = git_reset(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_target, object), reset_type);
21+
RETURN_LONG(result);
22+
}
23+
/* }}} */
24+
25+
/* {{{ proto long git_reset_default(resource $repo, resource $target, array $pathspecs)
26+
*/
27+
PHP_FUNCTION(git_reset_default)
28+
{
29+
int result = 0, error = 0;
30+
zval *repo = NULL, *target = NULL, *pathspecs = NULL;
31+
php_git2_t *_repo = NULL, *_target = NULL;
32+
33+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
34+
"rra", &repo, &target, &pathspecs) == FAILURE) {
35+
return;
36+
}
37+
38+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
39+
ZEND_FETCH_RESOURCE(_target, php_git2_t*, &target, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
40+
result = git_reset_default(PHP_GIT2_V(_repo, repository), PHP_GIT2_V(_target, object), pathspecs);
41+
RETURN_LONG(result);
42+
}
43+
/* }}} */
44+

reset.h

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_RESET_H
27+
#define PHP_GIT2_RESET_H
28+
29+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reset, 0, 0, 3)
30+
ZEND_ARG_INFO(0, repo)
31+
ZEND_ARG_INFO(0, target)
32+
ZEND_ARG_INFO(0, reset_type)
33+
ZEND_END_ARG_INFO()
34+
35+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_reset_default, 0, 0, 3)
36+
ZEND_ARG_INFO(0, repo)
37+
ZEND_ARG_INFO(0, target)
38+
ZEND_ARG_INFO(0, pathspecs)
39+
ZEND_END_ARG_INFO()
40+
41+
/* {{{ proto long git_reset(repo, target, reset_type)
42+
*/
43+
PHP_FUNCTION(git_reset);
44+
45+
/* {{{ proto long git_reset_default(repo, target, pathspecs)
46+
*/
47+
PHP_FUNCTION(git_reset_default);
48+
49+
#endif

0 commit comments

Comments
 (0)