summaryrefslogtreecommitdiff
path: root/src/attr.c
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-05-24 11:39:56 -0700
committerVicent Martí <vicent@github.com>2013-05-24 11:39:56 -0700
commit85281328be6341794341a9a46b54e3a557b2b889 (patch)
treeb0bac0291ac788c6771b02e4ed59e970d2c669c7 /src/attr.c
parent5e57cfa1b34374835f03e8d0ea61c338ed5cd9f0 (diff)
parent7a5ee3dc923caf2b3b9b5e9b2408340f6ae32d7d (diff)
downloadlibgit2-85281328be6341794341a9a46b54e3a557b2b889.tar.gz
Merge pull request #1608 from arrbee/various-cleanups-and-tweaks
Various cleanups and tweaks
Diffstat (limited to 'src/attr.c')
-rw-r--r--src/attr.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/attr.c b/src/attr.c
index 9fe4471f6..6cdff29f9 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -596,26 +596,33 @@ static int collect_attr_files(
}
static int attr_cache__lookup_path(
- const char **out, git_config *cfg, const char *key, const char *fallback)
+ char **out, git_config *cfg, const char *key, const char *fallback)
{
git_buf buf = GIT_BUF_INIT;
int error;
+ const char *cfgval = NULL;
- if (!(error = git_config_get_string(out, cfg, key)))
- return 0;
+ *out = NULL;
+
+ if (!(error = git_config_get_string(&cfgval, cfg, key))) {
+
+ /* expand leading ~/ as needed */
+ if (cfgval && cfgval[0] == '~' && cfgval[1] == '/' &&
+ !git_futils_find_global_file(&buf, &cfgval[2]))
+ *out = git_buf_detach(&buf);
+ else if (cfgval)
+ *out = git__strdup(cfgval);
- if (error == GIT_ENOTFOUND) {
+ } else if (error == GIT_ENOTFOUND) {
giterr_clear();
error = 0;
if (!git_futils_find_xdg_file(&buf, fallback))
*out = git_buf_detach(&buf);
- else
- *out = NULL;
-
- git_buf_free(&buf);
}
+ git_buf_free(&buf);
+
return error;
}
@@ -696,6 +703,12 @@ void git_attr_cache_flush(
git_pool_clear(&cache->pool);
+ git__free(cache->cfg_attr_file);
+ cache->cfg_attr_file = NULL;
+
+ git__free(cache->cfg_excl_file);
+ cache->cfg_excl_file = NULL;
+
cache->initialized = 0;
}