Skip to content

Commit 286a546

Browse files
committed
add reflog stubs
1 parent dded5ba commit 286a546

File tree

6 files changed

+476
-1
lines changed

6 files changed

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

1313
# for now

ng.php

+2
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ public function shouldResource(Arg $arg)
373373
"git_odb_backend",
374374
"git_odb_stream",
375375
"struct git_odb",
376+
"git_reflog",
377+
"git_reflog_entry",
376378
);
377379
}
378380

php_git2.c

+17
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "merge.h"
5454
#include "note.h"
5555
#include "odb.h"
56+
#include "reflog.h"
5657

5758
int git2_resource_handle;
5859

@@ -757,6 +758,22 @@ static zend_function_entry php_git2_functions[] = {
757758
PHP_FE(git_odb_num_backends, arginfo_git_odb_num_backends)
758759
PHP_FE(git_odb_get_backend, arginfo_git_odb_get_backend)
759760

761+
/* reflog */
762+
PHP_FE(git_reflog_read, arginfo_git_reflog_read)
763+
PHP_FE(git_reflog_write, arginfo_git_reflog_write)
764+
PHP_FE(git_reflog_append, arginfo_git_reflog_append)
765+
PHP_FE(git_reflog_append_to, arginfo_git_reflog_append_to)
766+
PHP_FE(git_reflog_rename, arginfo_git_reflog_rename)
767+
PHP_FE(git_reflog_delete, arginfo_git_reflog_delete)
768+
PHP_FE(git_reflog_entrycount, arginfo_git_reflog_entrycount)
769+
PHP_FE(git_reflog_entry_byindex, arginfo_git_reflog_entry_byindex)
770+
PHP_FE(git_reflog_drop, arginfo_git_reflog_drop)
771+
PHP_FE(git_reflog_entry_id_old, arginfo_git_reflog_entry_id_old)
772+
PHP_FE(git_reflog_entry_id_new, arginfo_git_reflog_entry_id_new)
773+
PHP_FE(git_reflog_entry_committer, arginfo_git_reflog_entry_committer)
774+
PHP_FE(git_reflog_entry_message, arginfo_git_reflog_entry_message)
775+
PHP_FE(git_reflog_free, arginfo_git_reflog_free)
776+
760777
/* misc */
761778
PHP_FE(git_resource_type, arginfo_git_resource_type)
762779
PHP_FE_END

php_git2.h

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ enum php_git2_resource_type {
118118
PHP_GIT2_TYPE_ODB_OBJECT,
119119
PHP_GIT2_TYPE_ODB_WRITEPACK,
120120
PHP_GIT2_TYPE_ODB_BACKEND,
121+
PHP_GIT2_TYPE_REFLOG,
122+
PHP_GIT2_TYPE_REFLOG_ENTRY,
121123
};
122124

123125
typedef struct php_git2_t {
@@ -163,6 +165,8 @@ typedef struct php_git2_t {
163165
git_odb_object *odb_object;
164166
git_odb_writepack *odb_writepack;
165167
git_odb_backend *odb_backend;
168+
git_reflog *reflog;
169+
git_reflog_entry *reflog_entry;
166170
} v;
167171
int should_free_v;
168172
int resource_id;

reflog.c

+299
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
#include "php_git2.h"
2+
#include "php_git2_priv.h"
3+
#include "reflog.h"
4+
5+
/* {{{ proto resource git_reflog_read(resource $repo, string $name)
6+
*/
7+
PHP_FUNCTION(git_reflog_read)
8+
{
9+
php_git2_t *result = NULL, *_repo = NULL;
10+
git_reflog *out = NULL;
11+
zval *repo = NULL;
12+
char *name = NULL;
13+
int name_len = 0, error = 0;
14+
15+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
16+
"rs", &repo, &name, &name_len) == FAILURE) {
17+
return;
18+
}
19+
20+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
21+
error = git_reflog_read(&out, PHP_GIT2_V(_repo, repository), name);
22+
if (php_git2_check_error(error, "git_reflog_read" TSRMLS_CC)) {
23+
RETURN_FALSE;
24+
}
25+
if (php_git2_make_resource(&result, PHP_GIT2_TYPE_REFLOG, out, 1 TSRMLS_CC)) {
26+
RETURN_FALSE;
27+
}
28+
ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
29+
}
30+
/* }}} */
31+
32+
/* {{{ proto long git_reflog_write(resource $reflog)
33+
*/
34+
PHP_FUNCTION(git_reflog_write)
35+
{
36+
int result = 0, error = 0;
37+
zval *reflog = NULL;
38+
php_git2_t *_reflog = NULL;
39+
40+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
41+
"r", &reflog) == FAILURE) {
42+
return;
43+
}
44+
45+
ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
46+
result = git_reflog_write(PHP_GIT2_V(_reflog, reflog));
47+
RETURN_LONG(result);
48+
}
49+
/* }}} */
50+
51+
/* {{{ proto long git_reflog_append(resource $reflog, string $id, array $committer, string $msg)
52+
*/
53+
PHP_FUNCTION(git_reflog_append)
54+
{
55+
int result = 0, id_len = 0, msg_len = 0, error = 0;
56+
zval *reflog = NULL, *committer = NULL;
57+
php_git2_t *_reflog = NULL;
58+
char *id = NULL, *msg = NULL;
59+
git_oid __id = {0};
60+
61+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
62+
"rsas", &reflog, &id, &id_len, &committer, &msg, &msg_len) == FAILURE) {
63+
return;
64+
}
65+
66+
ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
67+
if (git_oid_fromstrn(&__id, id, id_len)) {
68+
RETURN_FALSE;
69+
}
70+
result = git_reflog_append(PHP_GIT2_V(_reflog, reflog), &__id, committer, msg);
71+
RETURN_LONG(result);
72+
}
73+
/* }}} */
74+
75+
/* {{{ proto long git_reflog_append_to(resource $repo, string $name, string $id, array $committer, string $msg)
76+
*/
77+
PHP_FUNCTION(git_reflog_append_to)
78+
{
79+
int result = 0, name_len = 0, id_len = 0, msg_len = 0, error = 0;
80+
zval *repo = NULL, *committer = NULL;
81+
php_git2_t *_repo = NULL;
82+
char *name = NULL, *id = NULL, *msg = NULL;
83+
git_oid __id = {0};
84+
85+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
86+
"rssas", &repo, &name, &name_len, &id, &id_len, &committer, &msg, &msg_len) == FAILURE) {
87+
return;
88+
}
89+
90+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
91+
if (git_oid_fromstrn(&__id, id, id_len)) {
92+
RETURN_FALSE;
93+
}
94+
result = git_reflog_append_to(PHP_GIT2_V(_repo, repository), name, &__id, committer, msg);
95+
RETURN_LONG(result);
96+
}
97+
/* }}} */
98+
99+
/* {{{ proto long git_reflog_rename(resource $repo, string $old_name, string $name)
100+
*/
101+
PHP_FUNCTION(git_reflog_rename)
102+
{
103+
int result = 0, old_name_len = 0, name_len = 0, error = 0;
104+
zval *repo = NULL;
105+
php_git2_t *_repo = NULL;
106+
char *old_name = NULL, *name = NULL;
107+
108+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
109+
"rss", &repo, &old_name, &old_name_len, &name, &name_len) == FAILURE) {
110+
return;
111+
}
112+
113+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
114+
result = git_reflog_rename(PHP_GIT2_V(_repo, repository), old_name, name);
115+
RETURN_LONG(result);
116+
}
117+
/* }}} */
118+
119+
/* {{{ proto long git_reflog_delete(resource $repo, string $name)
120+
*/
121+
PHP_FUNCTION(git_reflog_delete)
122+
{
123+
int result = 0, name_len = 0, error = 0;
124+
zval *repo = NULL;
125+
php_git2_t *_repo = NULL;
126+
char *name = NULL;
127+
128+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
129+
"rs", &repo, &name, &name_len) == FAILURE) {
130+
return;
131+
}
132+
133+
ZEND_FETCH_RESOURCE(_repo, php_git2_t*, &repo, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
134+
result = git_reflog_delete(PHP_GIT2_V(_repo, repository), name);
135+
RETURN_LONG(result);
136+
}
137+
/* }}} */
138+
139+
/* {{{ proto long git_reflog_entrycount(resource $reflog)
140+
*/
141+
PHP_FUNCTION(git_reflog_entrycount)
142+
{
143+
size_t result = 0;
144+
zval *reflog = NULL;
145+
php_git2_t *_reflog = NULL;
146+
147+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
148+
"r", &reflog) == FAILURE) {
149+
return;
150+
}
151+
152+
ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
153+
result = git_reflog_entrycount(PHP_GIT2_V(_reflog, reflog));
154+
RETURN_LONG(result);
155+
}
156+
/* }}} */
157+
158+
/* {{{ proto resource git_reflog_entry_byindex(resource $reflog, long $idx)
159+
*/
160+
PHP_FUNCTION(git_reflog_entry_byindex)
161+
{
162+
const git_reflog_entry *result = NULL;
163+
zval *reflog = NULL;
164+
php_git2_t *_reflog = NULL;
165+
long idx = 0;
166+
167+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
168+
"rl", &reflog, &idx) == FAILURE) {
169+
return;
170+
}
171+
172+
ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
173+
result = git_reflog_entry_byindex(PHP_GIT2_V(_reflog, reflog), idx);
174+
/* TODO(chobie): implement this */
175+
}
176+
/* }}} */
177+
178+
/* {{{ proto long git_reflog_drop(resource $reflog, long $idx, long $rewrite_previous_entry)
179+
*/
180+
PHP_FUNCTION(git_reflog_drop)
181+
{
182+
int result = 0, error = 0;
183+
zval *reflog = NULL;
184+
php_git2_t *_reflog = NULL;
185+
long idx = 0, rewrite_previous_entry = 0;
186+
187+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
188+
"rll", &reflog, &idx, &rewrite_previous_entry) == FAILURE) {
189+
return;
190+
}
191+
192+
ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
193+
result = git_reflog_drop(PHP_GIT2_V(_reflog, reflog), idx, rewrite_previous_entry);
194+
RETURN_LONG(result);
195+
}
196+
/* }}} */
197+
198+
/* {{{ proto resource git_reflog_entry_id_old(resource $entry)
199+
*/
200+
PHP_FUNCTION(git_reflog_entry_id_old)
201+
{
202+
const git_oid *result = NULL;
203+
zval *entry = NULL;
204+
php_git2_t *_entry = NULL;
205+
char __result[GIT2_OID_HEXSIZE] = {0};
206+
207+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
208+
"r", &entry) == FAILURE) {
209+
return;
210+
}
211+
212+
ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
213+
result = git_reflog_entry_id_old(PHP_GIT2_V(_entry, reflog_entry));
214+
git_oid_fmt(__result, result);
215+
RETURN_STRING(__result, 1);
216+
}
217+
/* }}} */
218+
219+
/* {{{ proto resource git_reflog_entry_id_new(resource $entry)
220+
*/
221+
PHP_FUNCTION(git_reflog_entry_id_new)
222+
{
223+
const git_oid *result = NULL;
224+
zval *entry = NULL;
225+
php_git2_t *_entry = NULL;
226+
char __result[GIT2_OID_HEXSIZE] = {0};
227+
228+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
229+
"r", &entry) == FAILURE) {
230+
return;
231+
}
232+
233+
ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
234+
result = git_reflog_entry_id_new(PHP_GIT2_V(_entry, reflog_entry));
235+
git_oid_fmt(__result, result);
236+
RETURN_STRING(__result, 1);
237+
}
238+
/* }}} */
239+
240+
/* {{{ proto array git_reflog_entry_committer(resource $entry)
241+
*/
242+
PHP_FUNCTION(git_reflog_entry_committer)
243+
{
244+
const git_signature *result = NULL;
245+
zval *__result = NULL, *entry = NULL;
246+
php_git2_t *_entry = NULL;
247+
248+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
249+
"r", &entry) == FAILURE) {
250+
return;
251+
}
252+
253+
ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
254+
result = git_reflog_entry_committer(PHP_GIT2_V(_entry, reflog_entry));
255+
php_git2_signature_to_array(result, &__result TSRMLS_CC);
256+
RETURN_ZVAL(__result, 0, 1);
257+
}
258+
/* }}} */
259+
260+
/* {{{ proto string git_reflog_entry_message(resource $entry)
261+
*/
262+
PHP_FUNCTION(git_reflog_entry_message)
263+
{
264+
const char *result = NULL;
265+
zval *entry = NULL;
266+
php_git2_t *_entry = NULL;
267+
268+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
269+
"r", &entry) == FAILURE) {
270+
return;
271+
}
272+
273+
ZEND_FETCH_RESOURCE(_entry, php_git2_t*, &entry, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
274+
result = git_reflog_entry_message(PHP_GIT2_V(_entry, reflog_entry));
275+
RETURN_STRING(result, 1);
276+
}
277+
/* }}} */
278+
279+
/* {{{ proto void git_reflog_free(resource $reflog)
280+
*/
281+
PHP_FUNCTION(git_reflog_free)
282+
{
283+
zval *reflog = NULL;
284+
php_git2_t *_reflog = NULL;
285+
286+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
287+
"r", &reflog) == FAILURE) {
288+
return;
289+
}
290+
291+
ZEND_FETCH_RESOURCE(_reflog, php_git2_t*, &reflog, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
292+
if (GIT2_SHOULD_FREE(_reflog)) {
293+
git_reflog_free(PHP_GIT2_V(_reflog, reflog));
294+
GIT2_SHOULD_FREE(_reflog) = 0;
295+
};
296+
zval_ptr_dtor(&reflog);
297+
}
298+
/* }}} */
299+

0 commit comments

Comments
 (0)