Skip to content

Commit 48df873

Browse files
committed
adjusting ANSI-C syntax. (work in progress).
C99 does not accept on Windows environment. so i'm adjusting these horrible variable declarations.
1 parent c56b463 commit 48df873

20 files changed

+193
-245
lines changed

src/backend.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ int php_git_backend__exists(git_odb_backend *_backend, const git_oid *oid)
9393
php_git_backend_internal *object = (php_git_backend_internal *)_backend;
9494
char out[GIT_OID_HEXSZ+1] = {0};
9595
git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
96-
97-
zval *retval;
98-
zval *params[1];
99-
zval func;
96+
zval *retval, *params[1], func;
10097
int result;
10198

10299
MAKE_STD_ZVAL(retval);
@@ -130,11 +127,11 @@ int php_git_backend__write(git_oid *id, git_odb_backend *_backend, const void *b
130127
zval *retval;
131128
zval *params[1];
132129
zval func;
130+
133131
MAKE_STD_ZVAL(retval);
134132
ZVAL_NULL(retval);
135133
ZVAL_STRING(&func,"write", 1);
136134

137-
138135
MAKE_STD_ZVAL(params[0]);
139136
object_init_ex(params[0],git_rawobject_class_entry);
140137

@@ -171,10 +168,7 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba
171168
char out[GIT_OID_HEXSZ+1] = {0};
172169
git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
173170
int result = GIT_ERROR;
174-
175-
zval *retval;
176-
zval *params[1];
177-
zval func;
171+
zval *str, *len, *tp, *retval, *params[1], func;
178172

179173
MAKE_STD_ZVAL(retval);
180174
ZVAL_NULL(retval);
@@ -202,9 +196,9 @@ int php_git_backend__read(void **buffer,size_t size, git_otype *type, git_odb_ba
202196
goto cleanup;
203197
}
204198

205-
zval *str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC);
206-
zval *len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC);
207-
zval *tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC);
199+
str = zend_read_property(git_rawobject_class_entry, retval,"data",4, 0 TSRMLS_CC);
200+
len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC);
201+
tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC);
208202

209203
buffer = calloc(1,Z_LVAL_P(len));
210204
memcpy(buffer,Z_STRVAL_P(str),Z_LVAL_P(len));
@@ -227,10 +221,7 @@ int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *
227221
php_git_backend_internal *object = (php_git_backend_internal *)_backend;
228222
char out[GIT_OID_HEXSZ+1] = {0};
229223
git_oid_to_string(out,GIT_OID_HEXSZ+1,oid);
230-
231-
zval *retval;
232-
zval *params[1];
233-
zval func;
224+
zval *len, *tp, *retval, *params[1], func;
234225

235226
MAKE_STD_ZVAL(retval);
236227
ZVAL_NULL(retval);
@@ -251,8 +242,8 @@ int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *
251242
return GIT_ENOTFOUND;
252243
}
253244

254-
zval *len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC);
255-
zval *tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC);
245+
len = zend_read_property(git_rawobject_class_entry, retval,"len",3, 0 TSRMLS_CC);
246+
tp = zend_read_property(git_rawobject_class_entry, retval,"type",4, 0 TSRMLS_CC);
256247

257248
type = Z_LVAL_P(tp);
258249
size = Z_LVAL_P(len);
@@ -267,11 +258,9 @@ int php_git_backend__read_header(size_t size, git_otype *type, git_odb_backend *
267258
void php_git_backend__free(git_odb_backend *backend)
268259
{
269260
TSRMLS_FETCH();
261+
zval func, *retval;
270262
php_git_backend_internal *object = (php_git_backend_internal *)backend;
271263

272-
zval *retval;
273-
zval func;
274-
275264
MAKE_STD_ZVAL(retval);
276265
ZVAL_NULL(retval);
277266

src/blob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ PHP_METHOD(git_blob, loadString)
131131
PHP_METHOD(git_blob, write)
132132
{
133133
php_git_blob_t *this = (php_git_blob_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
134+
char oid_str[GIT_OID_HEXSZ+1] = {0};
134135
git_oid out;
135136
int ret = 0;
136137

@@ -148,7 +149,6 @@ PHP_METHOD(git_blob, write)
148149
}
149150
}
150151

151-
char oid_str[GIT_OID_HEXSZ+1] = {0};
152152
git_oid_to_string(oid_str,GIT_OID_HEXSZ+1,&out);
153153
RETVAL_STRING(oid_str,1);
154154
}

src/commit.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ zend_object_value php_git_commit_new(zend_class_entry *ce TSRMLS_DC)
9393

9494
PHP_METHOD(git_commit, __construct)
9595
{
96+
zval *object = getThis();
9697
zval *z_repository;
9798
git_commit *commit;
9899
git_repository *repository;
99-
zval *object = getThis();
100100
int ret;
101101

102102
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
@@ -141,20 +141,19 @@ PHP_METHOD(git_commit, getShortMessage)
141141
PHP_METHOD(git_commit, getTree)
142142
{
143143
php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
144-
git_tree *ref_tree;
144+
git_tree *ref_tree, *tree;
145+
git_oid *tree_oid;
146+
zval *git_tree, *entry;
147+
148+
const git_oid *oid = git_object_id((git_object*)ref_tree);
145149
git_commit_tree(&ref_tree, this->object);
146-
const git_oid *oid = git_object_id((git_object*)ref_tree);
147150

148-
git_tree *tree;
149151
int ret = git_object_lookup((git_object **)&tree, git_object_owner((git_object*)this->object),oid, GIT_OBJ_TREE);
150152
if(ret != GIT_SUCCESS) {
151153
php_error_docref(NULL TSRMLS_CC, E_ERROR, "specified tree not found.");
152154
return;
153155
}
154156

155-
git_oid *tree_oid;
156-
zval *git_tree;
157-
zval *entry;
158157

159158
MAKE_STD_ZVAL(git_tree);
160159
object_init_ex(git_tree, git_tree_class_entry);
@@ -232,20 +231,23 @@ PHP_METHOD(git_commit, setParents)
232231
PHP_METHOD(git_commit, write)
233232
{
234233
php_git_commit_t *this = (php_git_commit_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
235-
git_oid oid;
236-
php_git_signature_t *author;
237-
php_git_signature_t *committer;
234+
git_oid oid, tree_oid, **parents, **p, *tmp;
235+
php_git_signature_t *author, *committer;
236+
zval *z_author, *z_committer, *z_parents, **data;
237+
char *update_ref, *message, *tree_oid_str = NULL;
238+
char out[GIT_OID_HEXSZ+1];
239+
int count, i, update_ref_len = 0;
240+
git_reference *ref;
238241

239-
char *update_ref = NULL;
240-
int update_ref_len = 0;
242+
HashTable *array_hash;
243+
HashPosition pointer;
241244

242245
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
243246
"|s", &update_ref,&update_ref_len) == FAILURE){
244247
return;
245248
}
246249

247250
if(ZEND_NUM_ARGS() == 0) {
248-
git_reference *ref;
249251
if(git_reference_lookup(&ref,this->repository,"HEAD")==GIT_SUCCESS){
250252
if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
251253
git_reference *ref2;
@@ -258,27 +260,22 @@ PHP_METHOD(git_commit, write)
258260
}
259261

260262

261-
git_oid tree_oid;
262-
char *tree_oid_str = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"tree",sizeof("tree")-1, 0 TSRMLS_CC));
263+
tree_oid_str = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"tree",sizeof("tree")-1, 0 TSRMLS_CC));
263264
git_oid_fromstr(&tree_oid, tree_oid_str);
264265

265-
zval *z_author = zend_read_property(git_commit_class_entry, getThis(),"author",sizeof("author")-1, 0 TSRMLS_CC);
266+
z_author = zend_read_property(git_commit_class_entry, getThis(),"author",sizeof("author")-1, 0 TSRMLS_CC);
266267
author = (php_git_signature_t *) zend_object_store_get_object(z_author TSRMLS_CC);
267268

268-
zval *z_committer = zend_read_property(git_commit_class_entry, getThis(),"committer",sizeof("committer")-1, 0 TSRMLS_CC);
269+
z_committer = zend_read_property(git_commit_class_entry, getThis(),"committer",sizeof("committer")-1, 0 TSRMLS_CC);
269270
committer = (php_git_signature_t *) zend_object_store_get_object(z_committer TSRMLS_CC);
270271

271-
zval *z_parents = zend_read_property(git_commit_class_entry, getThis(),"parents",sizeof("parents")-1, 0 TSRMLS_CC);
272+
z_parents = zend_read_property(git_commit_class_entry, getThis(),"parents",sizeof("parents")-1, 0 TSRMLS_CC);
272273

273-
int count = zend_hash_num_elements(Z_ARRVAL_P(z_parents));
274+
count = zend_hash_num_elements(Z_ARRVAL_P(z_parents));
274275

275276

276-
HashTable *array_hash = Z_ARRVAL_P(z_parents);
277-
HashPosition pointer;
278-
git_oid *tmp;
279-
zval **data;
280-
git_oid **p;
281-
git_oid **parents = (git_oid**)calloc(count,sizeof(git_oid));
277+
array_hash = Z_ARRVAL_P(z_parents);
278+
parents = (git_oid**)calloc(count,sizeof(git_oid));
282279
p = parents;
283280

284281
for (zend_hash_internal_pointer_reset_ex(array_hash, &pointer);
@@ -293,7 +290,7 @@ PHP_METHOD(git_commit, write)
293290
p++;
294291
}
295292

296-
char *message = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"message",sizeof("message")-1, 0 TSRMLS_CC));
293+
message = Z_STRVAL_P(zend_read_property(git_commit_class_entry, getThis(),"message",sizeof("message")-1, 0 TSRMLS_CC));
297294
git_commit_create(&oid,
298295
this->repository,
299296
update_ref,
@@ -305,10 +302,8 @@ PHP_METHOD(git_commit, write)
305302
parents
306303
);
307304

308-
char out[GIT_OID_HEXSZ+1];
309305
git_oid_to_string(out,GIT_OID_HEXSZ+1,&oid);
310306

311-
int i;
312307
for(i = 0; i < count;i++){
313308
free(parents[i]);
314309
}

src/config.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,21 @@ ZEND_END_ARG_INFO()
6060

6161
typedef struct{
6262
zval *array;
63-
git_config *config
63+
git_config *config;
6464
} git_config_foreach_t;
6565

6666

6767
static int php_git_config_foreach(const char *key, void *data)
6868
{
69-
zval *config = ((git_config_foreach_t*)data)->array;
70-
HashTable *hash = Z_ARRVAL_P(config);
71-
zval **target_key;
72-
zval *moe_key;
73-
74-
char *tmp = estrdup(key);
75-
76-
char *current_key;
77-
char *uu;
78-
char *value;
69+
HashTable *hash;
70+
zval *config, *moe_key, *moe, **target_key;
71+
char *savedptr, *current_key, *uu, *value, *tmp;
7972

73+
config = ((git_config_foreach_t*)data)->array;
74+
hash = Z_ARRVAL_P(config);
75+
tmp = estrdup(key);
8076
git_config_get_string(((git_config_foreach_t *)data)->config,key,&value);
8177

82-
char *savedptr;
83-
8478
current_key = php_strtok_r(tmp, ".",&savedptr);
8579
while (current_key != NULL) {
8680
uu = current_key;
@@ -100,15 +94,13 @@ static int php_git_config_foreach(const char *key, void *data)
10094
}
10195

10296
if(uu != NULL) {
103-
zval *moe;
10497
MAKE_STD_ZVAL(moe);
10598
ZVAL_STRING(moe,value,1);
10699
zval_copy_ctor(&moe);
107100
zend_hash_add(hash,uu,strlen(uu)+1,(void **)&moe,sizeof(moe),NULL);
108101
}
109102

110103
efree(tmp);
111-
112104
return GIT_SUCCESS;
113105
}
114106

@@ -117,7 +109,6 @@ PHP_METHOD(git_config, parseFile)
117109
git_config_foreach_t t;
118110
git_config *config;
119111
zval *zconf;
120-
121112
char *path;
122113
int path_len = 0;
123114
int ret = GIT_ERROR;

src/index.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ ZEND_END_ARG_INFO()
9191
void php_git_index_entry_create(zval **index, git_index_entry *entry)
9292
{
9393
TSRMLS_FETCH();
94-
MAKE_STD_ZVAL(*index);
9594
char oid[GIT_OID_HEXSZ+1] = {0};
95+
96+
MAKE_STD_ZVAL(*index);
9697
object_init_ex(*index,git_index_entry_class_entry);
9798
git_oid_to_string(oid,GIT_OID_HEXSZ+1,&entry->oid);
9899

@@ -120,9 +121,8 @@ PHP_METHOD(git_index, count)
120121

121122
PHP_METHOD(git_index, find)
122123
{
123-
int offset = 0;
124+
int offset, path_len = 0;
124125
char *path;
125-
int path_len = 0;
126126
git_index *index = NULL;
127127
git_index_entry *entry;
128128
zval *z_git_index_entry;
@@ -169,11 +169,10 @@ PHP_METHOD(git_index, getEntry)
169169

170170
PHP_METHOD(git_index, add)
171171
{
172-
int offset = 0;
172+
int path_len, success, offset = 0;
173+
long stage = 0;
173174
char *path;
174-
int path_len = 0;
175175
git_index *index = NULL;
176-
long stage = 0;
177176

178177
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
179178
"s|l", &path, &path_len, &stage) == FAILURE){
@@ -183,11 +182,8 @@ PHP_METHOD(git_index, add)
183182
php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
184183
index = myobj->index;
185184

186-
//FIXME: examine stage value.
187-
// 0 => new file
188-
// 1 => deleted ?
189-
// 2 => ?
190-
int success = git_index_add(index,path,stage);
185+
// Todo: check stage status.
186+
success = git_index_add(index,path,stage);
191187
if(success != GIT_SUCCESS){
192188
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
193189
"can't add specified index.");
@@ -200,22 +196,22 @@ PHP_METHOD(git_index, add)
200196
PHP_METHOD(git_index, remove)
201197
{
202198
php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
199+
int path_len, offset, result = 0;
203200
char *path;
204-
int path_len = 0;
205201

206202
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
207203
"s", &path, &path_len) == FAILURE){
208204
return;
209205
}
210206

211-
int offset = git_index_find(this->index,path);
207+
offset = git_index_find(this->index,path);
212208
if(offset < 0){
213209
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
214210
"specified path does not exist.");
215211
RETURN_FALSE;
216212
}
217213

218-
int result = git_index_remove(this->index, offset);
214+
result = git_index_remove(this->index, offset);
219215
if(result != GIT_SUCCESS){
220216
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
221217
"specified offset does not exist.");
@@ -228,8 +224,8 @@ PHP_METHOD(git_index, remove)
228224
PHP_METHOD(git_index, update)
229225
{
230226
php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
231-
232227
int success = git_index_write(myobj->index);
228+
233229
if(success != GIT_SUCCESS){
234230
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
235231
"can't write index");
@@ -244,8 +240,8 @@ PHP_METHOD(git_index, refresh)
244240
{
245241
git_index *index = NULL;
246242
php_git_index_t *myobj = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
247-
index = myobj->index;
248243

244+
index = myobj->index;
249245
git_index_read(index);
250246
}
251247

@@ -267,8 +263,9 @@ PHP_METHOD(git_index, writeTree)
267263
php_git_index_t *this = (php_git_index_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
268264
git_oid oid;
269265
char out[GIT_OID_HEXSZ+1];
266+
int ret;
270267

271-
int ret = git_tree_create_fromindex(&oid, this->index);
268+
ret = git_tree_create_fromindex(&oid, this->index);
272269
if(ret != GIT_SUCCESS) {
273270
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC,
274271
"can't write tree from index.");

0 commit comments

Comments
 (0)