Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-05-24 03:11:53 +0400
committerRussell Belfer <rb@github.com>2013-05-24 03:11:53 +0400
commit0700ca1a74b58b73c4fb9ececffeaa80046c2f58 (patch)
tree3132ccbec0cf599b46cadd8c90e0907bf01a52e5
parent3b32b6d3cc649a7808151dd67d1dd3e45e202f08 (diff)
More config code checks and cleanups
-rw-r--r--src/config.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/config.c b/src/config.c
index 49b91237d..e436a31ad 100644
--- a/src/config.c
+++ b/src/config.c
@@ -339,17 +339,6 @@ int git_config_foreach_match(
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
**************/
@@ -361,6 +350,19 @@ static int config_error_nofiles(const char *name)
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)
{
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)
}
internal = git_vector_get(&cfg->files, 0);
- if (!internal)
+ if (!internal || !internal->file)
return config_error_nofiles(name);
file = internal->file;
@@ -468,7 +470,7 @@ static int get_string(const char **out, const git_config *cfg, const char *name)
int res;
git_vector_foreach(&cfg->files, i, internal) {
- if (!internal || !internal->file || !internal->file->get)
+ if (!internal || !internal->file)
continue;
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
{
file_internal *internal;
unsigned int i;
+ git_config_backend *file;
+ int ret;
*out = NULL;
git_vector_foreach(&cfg->files, i, internal) {
- git_config_backend *file = internal->file;
- int ret = file->get(file, name, out);
+ if (!internal || !internal->file)
+ continue;
+ file = internal->file;
+
+ ret = file->get(file, name, out);
if (ret != GIT_ENOTFOUND)
return ret;
}
@@ -519,8 +526,9 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co
return config_error_notfound(name);
}
-int git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp,
- git_config_foreach_cb cb, void *payload)
+int git_config_get_multivar(
+ const git_config *cfg, const char *name, const char *regexp,
+ git_config_foreach_cb cb, void *payload)
{
file_internal *internal;
git_config_backend *file;
@@ -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) {
internal = git_vector_get(&cfg->files, i - 1);
+ if (!internal || !internal->file)
+ continue;
file = internal->file;
+
ret = file->get_multivar(file, name, regexp, cb, payload);
if (ret < 0 && ret != GIT_ENOTFOUND)
return ret;
@@ -548,7 +559,7 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
file_internal *internal;
internal = git_vector_get(&cfg->files, 0);
- if (!internal)
+ if (!internal || !internal->file)
return config_error_nofiles(name);
file = internal->file;
@@ -643,13 +654,12 @@ int git_config_open_default(git_config **out)
git_config *cfg = NULL;
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) ||
- !git_config__global_location(&buf))) {
+ if (!git_config_find_global_r(&buf) || !git_config__global_location(&buf)) {
error = git_config_add_file_ondisk(cfg, buf.ptr,
GIT_CONFIG_LEVEL_GLOBAL, 0);
- } else {
}
if (!error && !git_config_find_xdg_r(&buf))
@@ -662,7 +672,7 @@ int git_config_open_default(git_config **out)
git_buf_free(&buf);
- if (error && cfg) {
+ if (error) {
git_config_free(cfg);
cfg = NULL;
}
@@ -675,6 +685,7 @@ int git_config_open_default(git_config **out)
/***********
* Parsers
***********/
+
int git_config_lookup_map_value(
int *out,
const git_cvar_map *maps,