diff options
| author | Russell Belfer <rb@github.com> | 2013-11-25 14:21:34 -0800 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-12-11 10:57:49 -0800 |
| commit | 9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b (patch) | |
| tree | 1c5405663a7bcc505f098b375c7ff5dc872af3ea /src/attr.c | |
| parent | 0eedacb06ae07fd0d784066ad41383276e05d92e (diff) | |
| download | libgit2-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/attr.c')
| -rw-r--r-- | src/attr.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/attr.c b/src/attr.c index 98a328a55..51895b7ac 100644 --- a/src/attr.c +++ b/src/attr.c @@ -603,11 +603,15 @@ static int attr_cache__lookup_path( { git_buf buf = GIT_BUF_INIT; int error; - const char *cfgval = NULL; + const git_config_entry *entry = NULL; *out = NULL; - if (!(error = git_config_get_string(&cfgval, cfg, key))) { + if ((error = git_config__lookup_entry(&entry, cfg, key, false)) < 0) + return error; + + if (entry) { + const char *cfgval = entry->value; /* expand leading ~/ as needed */ if (cfgval && cfgval[0] == '~' && cfgval[1] == '/' && @@ -616,13 +620,9 @@ static int attr_cache__lookup_path( else if (cfgval) *out = git__strdup(cfgval); - } else if (error == GIT_ENOTFOUND) { - giterr_clear(); - error = 0; - - if (!git_futils_find_xdg_file(&buf, fallback)) - *out = git_buf_detach(&buf); } + else if (!git_futils_find_xdg_file(&buf, fallback)) + *out = git_buf_detach(&buf); git_buf_free(&buf); |
