Commit 0700ca1a by Russell Belfer

More config code checks and cleanups

parent 3b32b6d3
...@@ -339,17 +339,6 @@ int git_config_foreach_match( ...@@ -339,17 +339,6 @@ int git_config_foreach_match(
return ret; return ret;
} }
int git_config_delete_entry(git_config *cfg, const char *name)
{
git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
file = internal->file;
return file->del(file, name);
}
/************** /**************
* Setters * Setters
**************/ **************/
...@@ -361,6 +350,19 @@ static int config_error_nofiles(const char *name) ...@@ -361,6 +350,19 @@ static int config_error_nofiles(const char *name)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
int git_config_delete_entry(git_config *cfg, const char *name)
{
git_config_backend *file;
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
if (!internal || !internal->file)
return config_error_nofiles(name);
file = internal->file;
return file->del(file, name);
}
int git_config_set_int64(git_config *cfg, const char *name, int64_t value) int git_config_set_int64(git_config *cfg, const char *name, int64_t value)
{ {
char str_value[32]; /* All numbers should fit in here */ char str_value[32]; /* All numbers should fit in here */
...@@ -390,7 +392,7 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value) ...@@ -390,7 +392,7 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
} }
internal = git_vector_get(&cfg->files, 0); internal = git_vector_get(&cfg->files, 0);
if (!internal) if (!internal || !internal->file)
return config_error_nofiles(name); return config_error_nofiles(name);
file = internal->file; file = internal->file;
...@@ -468,7 +470,7 @@ static int get_string(const char **out, const git_config *cfg, const char *name) ...@@ -468,7 +470,7 @@ static int get_string(const char **out, const git_config *cfg, const char *name)
int res; int res;
git_vector_foreach(&cfg->files, i, internal) { git_vector_foreach(&cfg->files, i, internal) {
if (!internal || !internal->file || !internal->file->get) if (!internal || !internal->file)
continue; continue;
res = get_string_at_file(out, internal->file, name); res = get_string_at_file(out, internal->file, name);
...@@ -506,12 +508,17 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co ...@@ -506,12 +508,17 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co
{ {
file_internal *internal; file_internal *internal;
unsigned int i; unsigned int i;
git_config_backend *file;
int ret;
*out = NULL; *out = NULL;
git_vector_foreach(&cfg->files, i, internal) { git_vector_foreach(&cfg->files, i, internal) {
git_config_backend *file = internal->file; if (!internal || !internal->file)
int ret = file->get(file, name, out); continue;
file = internal->file;
ret = file->get(file, name, out);
if (ret != GIT_ENOTFOUND) if (ret != GIT_ENOTFOUND)
return ret; return ret;
} }
...@@ -519,8 +526,9 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co ...@@ -519,8 +526,9 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co
return config_error_notfound(name); return config_error_notfound(name);
} }
int git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp, int git_config_get_multivar(
git_config_foreach_cb cb, void *payload) const git_config *cfg, const char *name, const char *regexp,
git_config_foreach_cb cb, void *payload)
{ {
file_internal *internal; file_internal *internal;
git_config_backend *file; git_config_backend *file;
...@@ -533,7 +541,10 @@ int git_config_get_multivar(const git_config *cfg, const char *name, const char ...@@ -533,7 +541,10 @@ int git_config_get_multivar(const git_config *cfg, const char *name, const char
*/ */
for (i = cfg->files.length; i > 0; --i) { for (i = cfg->files.length; i > 0; --i) {
internal = git_vector_get(&cfg->files, i - 1); internal = git_vector_get(&cfg->files, i - 1);
if (!internal || !internal->file)
continue;
file = internal->file; file = internal->file;
ret = file->get_multivar(file, name, regexp, cb, payload); ret = file->get_multivar(file, name, regexp, cb, payload);
if (ret < 0 && ret != GIT_ENOTFOUND) if (ret < 0 && ret != GIT_ENOTFOUND)
return ret; return ret;
...@@ -548,7 +559,7 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex ...@@ -548,7 +559,7 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
file_internal *internal; file_internal *internal;
internal = git_vector_get(&cfg->files, 0); internal = git_vector_get(&cfg->files, 0);
if (!internal) if (!internal || !internal->file)
return config_error_nofiles(name); return config_error_nofiles(name);
file = internal->file; file = internal->file;
...@@ -643,13 +654,12 @@ int git_config_open_default(git_config **out) ...@@ -643,13 +654,12 @@ int git_config_open_default(git_config **out)
git_config *cfg = NULL; git_config *cfg = NULL;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
error = git_config_new(&cfg); if ((error = git_config_new(&cfg)) < 0)
return error;
if (!error && (!git_config_find_global_r(&buf) || if (!git_config_find_global_r(&buf) || !git_config__global_location(&buf)) {
!git_config__global_location(&buf))) {
error = git_config_add_file_ondisk(cfg, buf.ptr, error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_GLOBAL, 0); GIT_CONFIG_LEVEL_GLOBAL, 0);
} else {
} }
if (!error && !git_config_find_xdg_r(&buf)) if (!error && !git_config_find_xdg_r(&buf))
...@@ -662,7 +672,7 @@ int git_config_open_default(git_config **out) ...@@ -662,7 +672,7 @@ int git_config_open_default(git_config **out)
git_buf_free(&buf); git_buf_free(&buf);
if (error && cfg) { if (error) {
git_config_free(cfg); git_config_free(cfg);
cfg = NULL; cfg = NULL;
} }
...@@ -675,6 +685,7 @@ int git_config_open_default(git_config **out) ...@@ -675,6 +685,7 @@ int git_config_open_default(git_config **out)
/*********** /***********
* Parsers * Parsers
***********/ ***********/
int git_config_lookup_map_value( int git_config_lookup_map_value(
int *out, int *out,
const git_cvar_map *maps, const git_cvar_map *maps,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment