Skip to content

Commit a1e3477

Browse files
committed
add stash stub code
1 parent d9969f5 commit a1e3477

File tree

4 files changed

+157
-1
lines changed

4 files changed

+157
-1
lines changed

Diff for: 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, $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, $ext_shared)
1111
PHP_ADD_INCLUDE([$ext_srcdir/libgit2/include])
1212

1313
# for now

Diff for: php_git2.c

+20
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "reflog.h"
5757
#include "blame.h"
5858
#include "packbuilder.h"
59+
#include "stash.h"
5960

6061
int git2_resource_handle;
6162

@@ -776,6 +777,25 @@ static zend_function_entry php_git2_functions[] = {
776777
PHP_FE(git_reflog_entry_message, arginfo_git_reflog_entry_message)
777778
PHP_FE(git_reflog_free, arginfo_git_reflog_free)
778779

780+
/* packbuilder */
781+
PHP_FE(git_packbuilder_new, arginfo_git_packbuilder_new)
782+
PHP_FE(git_packbuilder_set_threads, arginfo_git_packbuilder_set_threads)
783+
PHP_FE(git_packbuilder_insert, arginfo_git_packbuilder_insert)
784+
PHP_FE(git_packbuilder_insert_tree, arginfo_git_packbuilder_insert_tree)
785+
PHP_FE(git_packbuilder_insert_commit, arginfo_git_packbuilder_insert_commit)
786+
PHP_FE(git_packbuilder_write, arginfo_git_packbuilder_write)
787+
PHP_FE(git_packbuilder_hash, arginfo_git_packbuilder_hash)
788+
PHP_FE(git_packbuilder_foreach, arginfo_git_packbuilder_foreach)
789+
PHP_FE(git_packbuilder_object_count, arginfo_git_packbuilder_object_count)
790+
PHP_FE(git_packbuilder_written, arginfo_git_packbuilder_written)
791+
PHP_FE(git_packbuilder_set_callbacks, arginfo_git_packbuilder_set_callbacks)
792+
PHP_FE(git_packbuilder_free, arginfo_git_packbuilder_free)
793+
794+
/* stash */
795+
PHP_FE(git_stash_save, arginfo_git_stash_save)
796+
PHP_FE(git_stash_foreach, arginfo_git_stash_foreach)
797+
PHP_FE(git_stash_drop, arginfo_git_stash_drop)
798+
779799
/* misc */
780800
PHP_FE(git_resource_type, arginfo_git_resource_type)
781801
PHP_FE_END

Diff for: stash.c

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "php_git2.h"
2+
#include "php_git2_priv.h"
3+
#include "stash.h"
4+
5+
/* {{{ proto resource git_stash_save(resource $repo, array $stasher, string $message, long $flags)
6+
*/
7+
PHP_FUNCTION(git_stash_save)
8+
{
9+
php_git2_t *result = NULL, *_repo = NULL;
10+
git_oid out = {0};
11+
zval *repo = NULL, *stasher = NULL;
12+
char *message = NULL;
13+
int message_len = 0, error = 0;
14+
long flags = 0;
15+
char buf[41] = {0};
16+
17+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
18+
"rasl", &repo, &stasher, &message, &message_len, &flags) == FAILURE) {
19+
return;
20+
}
21+
22+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
23+
error = git_stash_save(&out, PHP_GIT2_V(_repo, repository), stasher, message, flags);
24+
if (php_git2_check_error(error, "git_stash_save" TSRMLS_CC)) {
25+
RETURN_FALSE;
26+
}
27+
git_oid_fmt(buf, &out);
28+
RETURN_STRING(buf, 1);
29+
}
30+
/* }}} */
31+
32+
/* {{{ proto long git_stash_foreach(resource $repo, Callable $callback, $payload)
33+
*/
34+
PHP_FUNCTION(git_stash_foreach)
35+
{
36+
int result = 0, error = 0;
37+
zval *repo = NULL, *callback = NULL, *payload = NULL;
38+
php_git2_t *_repo = NULL;
39+
zend_fcall_info fci = empty_fcall_info;
40+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
41+
php_git2_cb_t *cb = NULL;
42+
43+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
44+
"rfz", &repo, &fci, &fcc, &payload) == FAILURE) {
45+
return;
46+
}
47+
48+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
49+
if (php_git2_cb_init(&cb, &fci, &fcc, payload TSRMLS_CC)) {
50+
RETURN_FALSE;
51+
}
52+
//result = git_stash_foreach(PHP_GIT2_V(_repo, repository), <CHANGEME>, cb);
53+
php_git2_cb_free(cb);
54+
RETURN_LONG(result);
55+
}
56+
/* }}} */
57+
58+
/* {{{ proto long git_stash_drop(resource $repo, long $index)
59+
*/
60+
PHP_FUNCTION(git_stash_drop)
61+
{
62+
int result = 0, error = 0;
63+
zval *repo = NULL;
64+
php_git2_t *_repo = NULL;
65+
long index = 0;
66+
67+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
68+
"rl", &repo, &index) == FAILURE) {
69+
return;
70+
}
71+
72+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
73+
result = git_stash_drop(PHP_GIT2_V(_repo, repository), index);
74+
RETURN_LONG(result);
75+
}
76+
/* }}} */
77+

Diff for: stash.h

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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_STASH_H
27+
#define PHP_GIT2_STASH_H
28+
29+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_save, 0, 0, 4)
30+
ZEND_ARG_INFO(0, repo)
31+
ZEND_ARG_INFO(0, stasher)
32+
ZEND_ARG_INFO(0, message)
33+
ZEND_ARG_INFO(0, flags)
34+
ZEND_END_ARG_INFO()
35+
36+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_foreach, 0, 0, 3)
37+
ZEND_ARG_INFO(0, repo)
38+
ZEND_ARG_INFO(0, callback)
39+
ZEND_ARG_INFO(0, payload)
40+
ZEND_END_ARG_INFO()
41+
42+
ZEND_BEGIN_ARG_INFO_EX(arginfo_git_stash_drop, 0, 0, 2)
43+
ZEND_ARG_INFO(0, repo)
44+
ZEND_ARG_INFO(0, index)
45+
ZEND_END_ARG_INFO()
46+
47+
/* {{{ proto resource git_stash_save(repo, stasher, message, flags)
48+
*/
49+
PHP_FUNCTION(git_stash_save);
50+
51+
/* {{{ proto long git_stash_foreach(repo, callback, payload)
52+
*/
53+
PHP_FUNCTION(git_stash_foreach);
54+
55+
/* {{{ proto long git_stash_drop(repo, index)
56+
*/
57+
PHP_FUNCTION(git_stash_drop);
58+
59+
#endif

0 commit comments

Comments
 (0)