Skip to content

Commit 473077a

Browse files
committed
fix pieces of code, copy git_tree_entry by default
1 parent ed3b37f commit 473077a

File tree

10 files changed

+24
-29
lines changed

10 files changed

+24
-29
lines changed

git2_commit.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ static PHP_METHOD(Commit, lookup_oid) {
4747
int res = git_commit_lookup(&intern->commit, git_repo, &id);
4848

4949
if (res != 0) {
50-
// TODO Throw exception
51-
RETURN_NULL();
50+
git2_throw_last_error(TSRMLS_C);
5251
}
5352
}
5453

@@ -145,7 +144,7 @@ static PHP_METHOD(Commit, tree) {
145144
int res = git_commit_tree(&out, intern->commit);
146145

147146
if (res != 0) {
148-
git2_throw_last_error(TSRMLS_CC);
147+
git2_throw_last_error(TSRMLS_C);
149148
return;
150149
}
151150

@@ -205,7 +204,7 @@ static zend_function_entry git2_commit_methods[] = {
205204
{ NULL, NULL, NULL }
206205
};
207206

208-
void git2_commit_init(TSRMLS_DC) {
207+
void git2_commit_init(TSRMLS_D) {
209208
zend_class_entry ce;
210209

211210
INIT_NS_CLASS_ENTRY(ce, "Git2", "Commit", git2_commit_methods);

git2_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static zend_function_entry git2_config_methods[] = {
131131
{ NULL, NULL, NULL }
132132
};
133133

134-
void git2_config_init(TSRMLS_DC) {
134+
void git2_config_init(TSRMLS_D) {
135135
zend_class_entry ce;
136136

137137
INIT_NS_CLASS_ENTRY(ce, "Git2", "Config", git2_config_methods);

git2_config_entry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static zend_function_entry git2_config_entry_methods[] = {
7171
{ NULL, NULL, NULL }
7272
};
7373

74-
void git2_config_entry_init(TSRMLS_DC) {
74+
void git2_config_entry_init(TSRMLS_D) {
7575
zend_class_entry ce;
7676

7777
INIT_NS_CLASS_ENTRY(ce, "Git2\\Config", "Entry", git2_config_entry_methods);

git2_exception.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
zend_class_entry *php_git2_exception_ce;
66

7-
zend_bool git2_throw_last_error(TSRMLS_DC) {
7+
zend_bool git2_throw_last_error(TSRMLS_D) {
88
// throw an exception for last git error
99
const git_error *e = giterr_last();
1010
if (e == NULL) return FAILURE;
@@ -29,7 +29,7 @@ static zend_function_entry php_git2_exception_me[] = {
2929
PHP_FE_END
3030
};
3131

32-
void git2_exception_init(TSRMLS_DC) {
32+
void git2_exception_init(TSRMLS_D) {
3333
zend_class_entry ce;
3434

3535
INIT_NS_CLASS_ENTRY(ce, "Git2", "Exception", php_git2_exception_me);

git2_exception.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef GIT2_EXCEPTION_H
22
#define GIT2_EXCEPTION_H
33

4-
void git2_exception_init(TSRMLS_DC);
4+
void git2_exception_init(TSRMLS_D);
55
void git2_throw_exception(zend_long code TSRMLS_DC, const char *format, ...);
6-
zend_bool git2_throw_last_error(TSRMLS_DC);
6+
zend_bool git2_throw_last_error(TSRMLS_D);
77

88
extern zend_class_entry *php_git2_exception_ce;
99

git2_reference.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static PHP_METHOD(Reference, peel) {
9595
int res = git_reference_peel(&out, intern->ref, type);
9696

9797
if (res != 0) {
98-
git2_throw_last_error(TSRMLS_CC);
98+
git2_throw_last_error(TSRMLS_C);
9999
return;
100100
}
101101

@@ -161,7 +161,7 @@ static zend_function_entry git2_reference_methods[] = {
161161
{ NULL, NULL, NULL }
162162
};
163163

164-
void git2_reference_init(TSRMLS_DC) {
164+
void git2_reference_init(TSRMLS_D) {
165165
zend_class_entry ce;
166166

167167
INIT_NS_CLASS_ENTRY(ce, "Git2", "Reference", git2_reference_methods);

git2_remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static PHP_METHOD(Remote, fetch) {
246246
php_git2_strarray_free(&git_refspecs);
247247

248248
if (res != 0) {
249-
git2_throw_last_error(TSRMLS_CC);
249+
git2_throw_last_error(TSRMLS_C);
250250
return;
251251
}
252252

@@ -342,7 +342,7 @@ static zend_function_entry git2_remote_methods[] = {
342342
{ NULL, NULL, NULL }
343343
};
344344

345-
void git2_remote_init(TSRMLS_DC) {
345+
void git2_remote_init(TSRMLS_D) {
346346
zend_class_entry ce;
347347

348348
INIT_NS_CLASS_ENTRY(ce, "Git2", "Remote", git2_remote_methods);

git2_repository.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static PHP_METHOD(Repository, open) {
3737
int res = git_repository_open_ext(&intern->repo, path, flags, NULL);
3838

3939
if (res != 0) {
40-
git2_throw_last_error(TSRMLS_CC);
40+
git2_throw_last_error(TSRMLS_C);
4141
return;
4242
}
4343
}
@@ -62,7 +62,7 @@ static PHP_METHOD(Repository, open_bare) {
6262
int res = git_repository_open_bare(&intern->repo, path);
6363

6464
if (res != 0) {
65-
git2_throw_last_error(TSRMLS_CC);
65+
git2_throw_last_error(TSRMLS_C);
6666
return;
6767
}
6868
}
@@ -89,7 +89,7 @@ static PHP_METHOD(Repository, init) {
8989
int res = git_repository_init(&intern->repo, path, is_bare ? 1 : 0);
9090

9191
if (res != 0) {
92-
git2_throw_last_error(TSRMLS_CC);
92+
git2_throw_last_error(TSRMLS_C);
9393
return;
9494
}
9595
}
@@ -129,7 +129,7 @@ static PHP_METHOD(Repository, init_ext) {
129129
int res = git_repository_init_ext(&intern->repo, path, &opts_libgit2);
130130

131131
if (res != 0) {
132-
git2_throw_last_error(TSRMLS_CC);
132+
git2_throw_last_error(TSRMLS_C);
133133
return;
134134
}
135135
}
@@ -186,7 +186,7 @@ static PHP_METHOD(Repository, config) {
186186
git_config *out;
187187
int res = git_repository_config(&out, intern->repo);
188188
if (res != 0) {
189-
git2_throw_last_error(TSRMLS_CC);
189+
git2_throw_last_error(TSRMLS_C);
190190
return;
191191
}
192192

@@ -318,7 +318,7 @@ static zend_function_entry git2_repository_methods[] = {
318318
{ NULL, NULL, NULL }
319319
};
320320

321-
void git2_repository_init(TSRMLS_DC) {
321+
void git2_repository_init(TSRMLS_D) {
322322
zend_class_entry ce;
323323

324324
INIT_NS_CLASS_ENTRY(ce, "Git2", "Repository", git2_repository_methods);

git2_tree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ static PHP_METHOD(Tree, lookup_oid) {
4747
int res = git_tree_lookup(&intern->tree, git_repo, &id);
4848

4949
if (res != 0) {
50-
// TODO Throw exception
51-
RETURN_NULL();
50+
git2_throw_last_error(TSRMLS_C);
5251
}
5352
}
5453

@@ -213,7 +212,7 @@ static zend_function_entry git2_tree_methods[] = {
213212
{ NULL, NULL, NULL }
214213
};
215214

216-
void git2_tree_init(TSRMLS_DC) {
215+
void git2_tree_init(TSRMLS_D) {
217216
zend_class_entry ce;
218217

219218
INIT_NS_CLASS_ENTRY(ce, "Git2", "Tree", git2_tree_methods);

git2_tree_entry.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ static zend_object_handlers php_git2_tree_entry_handler;
77
typedef struct _git2_tree_entry_object {
88
zend_object std;
99
git_tree_entry *e;
10-
zend_bool readonly;
1110
} git2_tree_entry_object_t;
1211

1312
#define GIT2_TREE_ENTRY_FETCH() git2_tree_entry_object_t *intern = (git2_tree_entry_object_t*)Z_OBJ_P(getThis()); \
@@ -58,16 +57,14 @@ void git2_tree_entry_spawn(zval *return_value, git_tree_entry *e TSRMLS_DC) {
5857
object_init_ex(return_value, php_git2_tree_entry_ce);
5958
intern = (git2_tree_entry_object_t*)Z_OBJ_P(return_value);
6059
intern->e = e;
61-
intern->readonly = 0;
6260
}
6361

6462
void git2_tree_entry_spawn_ephemeral(zval *return_value, const git_tree_entry *e TSRMLS_DC) {
6563
git2_tree_entry_object_t *intern;
6664

6765
object_init_ex(return_value, php_git2_tree_entry_ce);
6866
intern = (git2_tree_entry_object_t*)Z_OBJ_P(return_value);
69-
intern->e = e;
70-
intern->readonly = 1;
67+
git_tree_entry_dup(&intern->e, e); // dup it so the object can be kept longer (we do not know if the php code needs it, but it may)
7168
}
7269

7370
zend_object *php_git2_tree_entry_create_object(zend_class_entry *class_type TSRMLS_DC) {
@@ -89,7 +86,7 @@ static void php_git2_tree_entry_free_object(zend_object *object TSRMLS_DC) {
8986

9087
zend_object_std_dtor(&intern->std TSRMLS_CC);
9188

92-
if ((intern->e) && (!intern->readonly)) {
89+
if (intern->e) {
9390
git_tree_entry_free(intern->e);
9491
intern->e = NULL;
9592
}
@@ -108,7 +105,7 @@ static zend_function_entry git2_tree_entry_methods[] = {
108105
{ NULL, NULL, NULL }
109106
};
110107

111-
void git2_tree_entry_init(TSRMLS_DC) {
108+
void git2_tree_entry_init(TSRMLS_D) {
112109
zend_class_entry ce;
113110

114111
INIT_NS_CLASS_ENTRY(ce, "Git2\\Tree", "Entry", git2_tree_entry_methods);

0 commit comments

Comments
 (0)