Skip to content

Commit 0d3856f

Browse files
committed
wip
1 parent 75e9093 commit 0d3856f

File tree

1 file changed

+55
-24
lines changed

1 file changed

+55
-24
lines changed

g_config.c

+55-24
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,21 @@ PHP_FUNCTION(git_config_add_file_ondisk)
258258
php_git2_t *_cfg;
259259
char *path = {0};
260260
int path_len;
261-
zval *level;
262-
php_git2_t *_level;
263-
long force;
264-
265-
/* TODO(chobie): implement this */
266-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_add_file_ondisk not implemented yet");
267-
return;
261+
long level;
262+
long force = 0;
263+
int error = 0;
268264

269265
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
270266
"rsrl", &cfg, &path, &path_len, &level, &force) == FAILURE) {
271267
return;
272268
}
269+
273270
ZEND_FETCH_RESOURCE(_cfg, php_git2_t*, &cfg, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
271+
error = git_config_add_file_ondisk(PHP_GIT2_V(_cfg, config), path, level, force);
272+
if (php_git2_check_error(error, "git_config_add_file_ondisk" TSRMLS_CC)) {
273+
RETURN_FALSE
274+
}
275+
RETURN_TRUE;
274276
}
275277

276278
/* {{{ proto resource git_config_open_ondisk(path)
@@ -279,53 +281,82 @@ PHP_FUNCTION(git_config_open_ondisk)
279281
{
280282
char *path = {0};
281283
int path_len;
282-
283-
/* TODO(chobie): implement this */
284-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_ondisk not implemented yet");
285-
return;
284+
git_config *config;
285+
php_git2_t *result;
286+
int error = 0;
286287

287288
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
288289
"s", &path, &path_len) == FAILURE) {
289290
return;
290291
}
292+
error = git_config_open_ondisk(&config, path);
293+
if (php_git2_check_error(error, "git_config_open_ondisk" TSRMLS_CC)) {
294+
RETURN_FALSE
295+
}
296+
PHP_GIT2_MAKE_RESOURCE(result);
297+
PHP_GIT2_V(result, config) = config;
298+
result->type = PHP_GIT2_TYPE_CONFIG;
299+
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
300+
result->should_free_v = 1;
301+
302+
ZVAL_RESOURCE(return_value, result->resource_id);
291303
}
292304

293305
/* {{{ proto resource git_config_open_level(parent, level)
294306
*/
295307
PHP_FUNCTION(git_config_open_level)
296308
{
297309
zval *parent;
298-
php_git2_t *_parent;
299-
zval *level;
300-
php_git2_t *_level;
301-
302-
/* TODO(chobie): implement this */
303-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_level not implemented yet");
304-
return;
310+
php_git2_t *_parent, *result;
311+
long level;
312+
int error = 0;
313+
git_config *out;
305314

306315
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
307-
"rr", &parent, &level) == FAILURE) {
316+
"rl", &parent, &level) == FAILURE) {
308317
return;
309318
}
310319
ZEND_FETCH_RESOURCE(_parent, php_git2_t*, &parent, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
320+
321+
error = git_config_open_level(&out, PHP_GIT2_V(_parent, config), level);
322+
if (php_git2_check_error(error, "git_config_open_level" TSRMLS_CC)) {
323+
RETURN_FALSE
324+
}
325+
PHP_GIT2_MAKE_RESOURCE(result);
326+
PHP_GIT2_V(result, config) = out;
327+
result->type = PHP_GIT2_TYPE_CONFIG;
328+
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
329+
result->should_free_v = 1;
330+
331+
ZVAL_RESOURCE(return_value, result->resource_id);
311332
}
312333

313334
/* {{{ proto resource git_config_open_global(config)
314335
*/
315336
PHP_FUNCTION(git_config_open_global)
316337
{
317338
zval *config;
318-
php_git2_t *_config;
319-
320-
/* TODO(chobie): implement this */
321-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "git_config_open_global not implemented yet");
322-
return;
339+
php_git2_t *_config, *result;
340+
git_config *out;
341+
int error = 0;
323342

324343
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
325344
"r", &config) == FAILURE) {
326345
return;
327346
}
347+
328348
ZEND_FETCH_RESOURCE(_config, php_git2_t*, &config, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
349+
error = git_config_open_global(&out, PHP_GIT2_V(_config, config));
350+
if (php_git2_check_error(error, "git_config_open_global" TSRMLS_CC)) {
351+
RETURN_FALSE
352+
}
353+
PHP_GIT2_MAKE_RESOURCE(result);
354+
PHP_GIT2_V(result, config) = out;
355+
result->type = PHP_GIT2_TYPE_CONFIG;
356+
result->resource_id = PHP_GIT2_LIST_INSERT(result, git2_resource_handle);
357+
result->should_free_v = 1;
358+
359+
ZVAL_RESOURCE(return_value, result->resource_id);
329360
}
330361

331362
/* {{{ proto long git_config_refresh(cfg)

0 commit comments

Comments
 (0)