diff options
author | Vicent Martà <vicent@github.com> | 2013-05-24 11:39:56 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-05-24 11:39:56 -0700 |
commit | 85281328be6341794341a9a46b54e3a557b2b889 (patch) | |
tree | b0bac0291ac788c6771b02e4ed59e970d2c669c7 /src | |
parent | 5e57cfa1b34374835f03e8d0ea61c338ed5cd9f0 (diff) | |
parent | 7a5ee3dc923caf2b3b9b5e9b2408340f6ae32d7d (diff) | |
download | libgit2-85281328be6341794341a9a46b54e3a557b2b889.tar.gz |
Merge pull request #1608 from arrbee/various-cleanups-and-tweaks
Various cleanups and tweaks
Diffstat (limited to 'src')
-rw-r--r-- | src/attr.c | 29 | ||||
-rw-r--r-- | src/attrcache.h | 8 | ||||
-rw-r--r-- | src/cache.c | 5 | ||||
-rw-r--r-- | src/config.c | 24 | ||||
-rw-r--r-- | src/config_file.c | 8 | ||||
-rw-r--r-- | src/diff.c | 4 |
6 files changed, 50 insertions, 28 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; } diff --git a/src/attrcache.h b/src/attrcache.h index 12cec4bfb..077633b87 100644 --- a/src/attrcache.h +++ b/src/attrcache.h @@ -13,10 +13,10 @@ typedef struct { int initialized; git_pool pool; - git_strmap *files; /* hash path to git_attr_file of rules */ - git_strmap *macros; /* hash name to vector<git_attr_assignment> */ - const char *cfg_attr_file; /* cached value of core.attributesfile */ - const char *cfg_excl_file; /* cached value of core.excludesfile */ + git_strmap *files; /* hash path to git_attr_file of rules */ + git_strmap *macros; /* hash name to vector<git_attr_assignment> */ + char *cfg_attr_file; /* cached value of core.attributesfile */ + char *cfg_excl_file; /* cached value of core.excludesfile */ } git_attr_cache; extern int git_attr_cache__init(git_repository *repo); diff --git a/src/cache.c b/src/cache.c index 1360cc976..dc3af063a 100644 --- a/src/cache.c +++ b/src/cache.c @@ -174,6 +174,11 @@ static void *cache_store(git_cache *cache, git_cached_obj *entry) git_cached_obj_incref(entry); + if (!git_cache__enabled && cache->used_memory > 0) { + git_cache_clear(cache); + return entry; + } + if (!cache_should_store(entry->type, entry->size)) return entry; diff --git a/src/config.c b/src/config.c index e436a31ad..9491d267a 100644 --- a/src/config.c +++ b/src/config.c @@ -23,7 +23,7 @@ typedef struct { git_refcount rc; git_config_backend *file; - unsigned int level; + git_config_level_t level; } file_internal; static void file_internal_free(file_internal *internal) @@ -87,7 +87,7 @@ int git_config_new(git_config **out) int git_config_add_file_ondisk( git_config *cfg, const char *path, - unsigned int level, + git_config_level_t level, int force) { git_config_backend *file = NULL; @@ -138,11 +138,11 @@ int git_config_open_ondisk(git_config **out, const char *path) static int find_internal_file_by_level( file_internal **internal_out, const git_config *cfg, - int level) + git_config_level_t level) { int pos = -1; file_internal *internal; - unsigned int i; + size_t i; /* when passing GIT_CONFIG_HIGHEST_LEVEL, the idea is to get the config file * which has the highest level. As config files are stored in a vector @@ -153,14 +153,14 @@ static int find_internal_file_by_level( pos = 0; } else { git_vector_foreach(&cfg->files, i, internal) { - if (internal->level == (unsigned int)level) + if (internal->level == level) pos = i; } } if (pos == -1) { giterr_set(GITERR_CONFIG, - "No config file exists for the given level '%i'", level); + "No config file exists for the given level '%i'", (int)level); return GIT_ENOTFOUND; } @@ -175,17 +175,17 @@ static int duplicate_level(void **old_raw, void *new_raw) GIT_UNUSED(new_raw); - giterr_set(GITERR_CONFIG, "A file with the same level (%i) has already been added to the config", (*old)->level); + giterr_set(GITERR_CONFIG, "A file with the same level (%i) has already been added to the config", (int)(*old)->level); return GIT_EEXISTS; } static void try_remove_existing_file_internal( git_config *cfg, - unsigned int level) + git_config_level_t level) { int pos = -1; file_internal *internal; - unsigned int i; + size_t i; git_vector_foreach(&cfg->files, i, internal) { if (internal->level == level) @@ -206,7 +206,7 @@ static void try_remove_existing_file_internal( static int git_config__add_internal( git_config *cfg, file_internal *internal, - unsigned int level, + git_config_level_t level, int force) { int result; @@ -238,7 +238,7 @@ int git_config_open_global(git_config **cfg_out, git_config *cfg) int git_config_open_level( git_config **cfg_out, const git_config *cfg_parent, - unsigned int level) + git_config_level_t level) { git_config *cfg; file_internal *internal; @@ -263,7 +263,7 @@ int git_config_open_level( int git_config_add_backend( git_config *cfg, git_config_backend *file, - unsigned int level, + git_config_level_t level, int force) { file_internal *internal; diff --git a/src/config_file.c b/src/config_file.c index e57cd1e53..dec952115 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -81,10 +81,10 @@ typedef struct { time_t file_mtime; size_t file_size; - unsigned int level; + git_config_level_t level; } diskfile_backend; -static int config_parse(diskfile_backend *cfg_file, unsigned int level); +static int config_parse(diskfile_backend *cfg_file, git_config_level_t level); static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_value); static int config_write(diskfile_backend *cfg, const char *key, const regex_t *preg, const char *value); static char *escape_value(const char *ptr); @@ -181,7 +181,7 @@ static void free_vars(git_strmap *values) git_strmap_free(values); } -static int config_open(git_config_backend *cfg, unsigned int level) +static int config_open(git_config_backend *cfg, git_config_level_t level) { int res; diskfile_backend *b = (diskfile_backend *)cfg; @@ -965,7 +965,7 @@ static int strip_comments(char *line, int in_quotes) return quote_count; } -static int config_parse(diskfile_backend *cfg_file, unsigned int level) +static int config_parse(diskfile_backend *cfg_file, git_config_level_t level) { int c; char *current_section = NULL; diff --git a/src/diff.c b/src/diff.c index d2389f103..b96ff4705 100644 --- a/src/diff.c +++ b/src/diff.c @@ -383,6 +383,10 @@ static int diff_list_apply_options( if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_TYPECHANGE_TREES)) diff->opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE; + /* flag INCLUDE_UNTRACKED_CONTENT implies INCLUDE_UNTRACKED */ + if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_INCLUDE_UNTRACKED_CONTENT)) + diff->opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED; + /* load config values that affect diff behavior */ if (git_repository_config__weakptr(&cfg, repo) < 0) return -1; |