summaryrefslogtreecommitdiff
path: root/src/config_file.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-11-25 14:21:34 -0800
committerRussell Belfer <rb@github.com>2013-12-11 10:57:49 -0800
commit9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b (patch)
tree1c5405663a7bcc505f098b375c7ff5dc872af3ea /src/config_file.c
parent0eedacb06ae07fd0d784066ad41383276e05d92e (diff)
downloadlibgit2-9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b.tar.gz
Add config read fns with controlled error behavior
This adds `git_config__lookup_entry` which will look up a key in a config and return either the entry or NULL if the key was not present. Optionally, it can either suppress all errors or can return them (although not finding the key is not an error for this function). Unlike other accessors, this does not normalize the config key string, so it must only be used when the key is known to be in normalized form (i.e. all lower-case before the first dot and after the last dot, with no invalid characters). This also adds three high-level helper functions to look up config values with no errors and a fallback value. The three functions are for string, bool, and int values, and will resort to the fallback value for any error that arises. They are: * `git_config__get_string_force` * `git_config__get_bool_force` * `git_config__get_int_force` None of them normalize the config `key` either, so they can only be used for internal cases where the key is known to be in normal format.
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 15c8de49c..0971aa7b0 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -404,20 +404,12 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
/*
* Internal function that actually gets the value in string form
*/
-static int config_get(const git_config_backend *cfg, const char *name, const git_config_entry **out)
+static int config_get(const git_config_backend *cfg, const char *key, const git_config_entry **out)
{
diskfile_backend *b = (diskfile_backend *)cfg;
- char *key;
- khiter_t pos;
- int error;
+ khiter_t pos = git_strmap_lookup_index(b->values, key);
cvar_t *var;
- if ((error = git_config__normalize_name(name, &key)) < 0)
- return error;
-
- pos = git_strmap_lookup_index(b->values, key);
- git__free(key);
-
/* no error message; the config system will write one */
if (!git_strmap_valid_index(b->values, pos))
return GIT_ENOTFOUND;
@@ -427,7 +419,6 @@ static int config_get(const git_config_backend *cfg, const char *name, const git
var = var->next;
*out = var->entry;
-
return 0;
}