summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-01-14 15:05:43 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2015-01-14 19:36:50 +0100
commiteac773d92bccc7d3fc7ce1b18578d374873e0d7a (patch)
treeeb165d11a1a30274ed7ff40d27bd461640067bc3 /src/config.c
parent4d6f55acce14eeec55729e55335635375e9026df (diff)
downloadlibgit2-cmn/config-get-path.tar.gz
config: add parsing and getter for pathscmn/config-get-path
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
index 0f8c24465..f80770138 100644
--- a/src/config.c
+++ b/src/config.c
@@ -785,6 +785,17 @@ int git_config_get_bool(int *out, const git_config *cfg, const char *name)
return git_config_parse_bool(out, entry->value);
}
+int git_config_get_path(git_buf *out, const git_config *cfg, const char *name)
+{
+ const git_config_entry *entry;
+ int error;
+
+ if ((error = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS)) < 0)
+ return error;
+
+ return git_config_parse_path(out, entry->value);
+}
+
int git_config_get_string(
const char **out, const git_config *cfg, const char *name)
{
@@ -1184,6 +1195,36 @@ fail_parse:
return -1;
}
+int git_config_parse_path(git_buf *out, const char *value)
+{
+ int error = 0;
+ const git_buf *home;
+
+ assert(out && value);
+
+ git_buf_sanitize(out);
+
+ if (value[0] == '~') {
+ if (value[1] != '\0' && value[1] != '/') {
+ giterr_set(GITERR_CONFIG, "retrieving a homedir by name is not supported");
+ return -1;
+ }
+
+ if ((error = git_sysdir_get(&home, GIT_SYSDIR_GLOBAL)) < 0)
+ return error;
+
+ git_buf_sets(out, home->ptr);
+ git_buf_puts(out, value + 1);
+
+ if (git_buf_oom(out))
+ return -1;
+
+ return 0;
+ }
+
+ return git_buf_sets(out, value);
+}
+
/* Take something the user gave us and make it nice for our hash function */
int git_config__normalize_name(const char *in, char **out)
{