summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2012-11-13 14:59:18 -0800
committerVicent Martí <vicent@github.com>2012-11-13 14:59:18 -0800
commit513e794ef47363b8900816a9b141b3eae81eb83e (patch)
tree7125079999fa0984e4395666e6637117b902a590 /src/config.c
parentf6c18dda048ae3332d60468c34c4fd7d1aa67f1e (diff)
parent0da81d2b39290fe4d444953acb6d68795ed1ef42 (diff)
downloadlibgit2-513e794ef47363b8900816a9b141b3eae81eb83e.tar.gz
Merge pull request #1068 from carlosmn/config-empty-value
Deal with empty and nonexsitent values in config
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/config.c b/src/config.c
index ed9901bd2..4fb161169 100644
--- a/src/config.c
+++ b/src/config.c
@@ -393,24 +393,11 @@ int git_config_get_int32(int32_t *out, git_config *cfg, const char *name)
return git_config_parse_int32(out, value);
}
-int git_config_get_bool(int *out, git_config *cfg, const char *name)
-{
- const char *value;
- int ret;
-
- if ((ret = git_config_get_string(&value, cfg, name)) < 0)
- return ret;
-
- return git_config_parse_bool(out, value);
-}
-
static int get_string_at_file(const char **out, git_config_file *file, const char *name)
{
const git_config_entry *entry;
int res;
- *out = NULL;
-
res = file->get(file, name, &entry);
if (!res)
*out = entry->value;
@@ -418,7 +405,7 @@ static int get_string_at_file(const char **out, git_config_file *file, const cha
return res;
}
-int git_config_get_string(const char **out, git_config *cfg, const char *name)
+static int get_string(const char **out, git_config *cfg, const char *name)
{
file_internal *internal;
unsigned int i;
@@ -435,6 +422,29 @@ int git_config_get_string(const char **out, git_config *cfg, const char *name)
return GIT_ENOTFOUND;
}
+int git_config_get_bool(int *out, git_config *cfg, const char *name)
+{
+ const char *value;
+ int ret;
+
+ if ((ret = get_string(&value, cfg, name)) < 0)
+ return ret;
+
+ return git_config_parse_bool(out, value);
+}
+
+int git_config_get_string(const char **out, git_config *cfg, const char *name)
+{
+ int ret;
+ const char *str;
+
+ if ((ret = get_string(&str, cfg, name)) < 0)
+ return ret;
+
+ *out = str == NULL ? "" : str;
+ return 0;
+}
+
int git_config_get_entry(const git_config_entry **out, git_config *cfg, const char *name)
{
file_internal *internal;