Commit eac76c23 by Russell Belfer

Use config cache where possible

This converts many of the config lookups that are done around the
library to use the repository config cache.  This was everything I
could find that wasn't part of diff (which requires a larger fix).
parent ab01cbd4
...@@ -1119,7 +1119,6 @@ static int checkout_data_init( ...@@ -1119,7 +1119,6 @@ static int checkout_data_init(
git_checkout_opts *proposed) git_checkout_opts *proposed)
{ {
int error = 0; int error = 0;
git_config *cfg;
git_repository *repo = git_iterator_owner(target); git_repository *repo = git_iterator_owner(target);
memset(data, 0, sizeof(*data)); memset(data, 0, sizeof(*data));
...@@ -1132,9 +1131,6 @@ static int checkout_data_init( ...@@ -1132,9 +1131,6 @@ static int checkout_data_init(
if ((error = git_repository__ensure_not_bare(repo, "checkout")) < 0) if ((error = git_repository__ensure_not_bare(repo, "checkout")) < 0)
return error; return error;
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
data->repo = repo; data->repo = repo;
GITERR_CHECK_VERSION( GITERR_CHECK_VERSION(
...@@ -1147,7 +1143,10 @@ static int checkout_data_init( ...@@ -1147,7 +1143,10 @@ static int checkout_data_init(
/* refresh config and index content unless NO_REFRESH is given */ /* refresh config and index content unless NO_REFRESH is given */
if ((data->opts.checkout_strategy & GIT_CHECKOUT_NO_REFRESH) == 0) { if ((data->opts.checkout_strategy & GIT_CHECKOUT_NO_REFRESH) == 0) {
if ((error = git_config_refresh(cfg)) < 0) git_config *cfg;
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 ||
(error = git_config_refresh(cfg)) < 0)
goto cleanup; goto cleanup;
/* if we are checking out the index, don't reload, /* if we are checking out the index, don't reload,
...@@ -1184,19 +1183,13 @@ static int checkout_data_init( ...@@ -1184,19 +1183,13 @@ static int checkout_data_init(
data->pfx = git_pathspec_prefix(&data->opts.paths); data->pfx = git_pathspec_prefix(&data->opts.paths);
error = git_config_get_bool(&data->can_symlink, cfg, "core.symlinks"); if ((error = git_repository__cvar(
if (error < 0) { &data->can_symlink, repo, GIT_CVAR_SYMLINKS)) < 0)
if (error != GIT_ENOTFOUND)
goto cleanup; goto cleanup;
/* If "core.symlinks" is not found anywhere, default to true. */
data->can_symlink = true;
giterr_clear();
error = 0;
}
if (!data->opts.baseline) { if (!data->opts.baseline) {
data->opts_free_baseline = true; data->opts_free_baseline = true;
error = checkout_lookup_head_tree(&data->opts.baseline, repo); error = checkout_lookup_head_tree(&data->opts.baseline, repo);
if (error == GIT_EORPHANEDHEAD) { if (error == GIT_EORPHANEDHEAD) {
......
...@@ -15,25 +15,15 @@ static int parse_ignore_file( ...@@ -15,25 +15,15 @@ static int parse_ignore_file(
git_attr_fnmatch *match = NULL; git_attr_fnmatch *match = NULL;
const char *scan = NULL; const char *scan = NULL;
char *context = NULL; char *context = NULL;
bool ignore_case = false; int ignore_case = false;
git_config *cfg = NULL;
int val; /* Prefer to have the caller pass in a git_ignores as the parsedata
* object. If they did not, then look up the value of ignore_case */
/* Prefer to have the caller pass in a git_ignores as the parsedata object. if (parsedata != NULL)
* If they did not, then we can (much more slowly) find the value of
* ignore_case by using the repository object. */
if (parsedata != NULL) {
ignore_case = ((git_ignores *)parsedata)->ignore_case; ignore_case = ((git_ignores *)parsedata)->ignore_case;
} else { else if (git_repository__cvar(&ignore_case, repo, GIT_CVAR_IGNORECASE) < 0)
if ((error = git_repository_config(&cfg, repo)) < 0)
return error; return error;
if (git_config_get_bool(&val, cfg, "core.ignorecase") == 0)
ignore_case = (val != 0);
git_config_free(cfg);
}
if (ignores->key && git__suffixcmp(ignores->key, "/" GIT_IGNORE_FILE) == 0) { if (ignores->key && git__suffixcmp(ignores->key, "/" GIT_IGNORE_FILE) == 0) {
context = ignores->key + 2; context = ignores->key + 2;
context[strlen(context) - strlen(GIT_IGNORE_FILE)] = '\0'; context[strlen(context) - strlen(GIT_IGNORE_FILE)] = '\0';
...@@ -109,8 +99,6 @@ int git_ignore__for_path( ...@@ -109,8 +99,6 @@ int git_ignore__for_path(
{ {
int error = 0; int error = 0;
const char *workdir = git_repository_workdir(repo); const char *workdir = git_repository_workdir(repo);
git_config *cfg = NULL;
int val;
assert(ignores); assert(ignores);
...@@ -118,17 +106,11 @@ int git_ignore__for_path( ...@@ -118,17 +106,11 @@ int git_ignore__for_path(
git_buf_init(&ignores->dir, 0); git_buf_init(&ignores->dir, 0);
ignores->ign_internal = NULL; ignores->ign_internal = NULL;
/* Set the ignore_case flag appropriately */ /* Read the ignore_case flag */
if ((error = git_repository_config(&cfg, repo)) < 0) if ((error = git_repository__cvar(
&ignores->ignore_case, repo, GIT_CVAR_IGNORECASE)) < 0)
goto cleanup; goto cleanup;
if (git_config_get_bool(&val, cfg, "core.ignorecase") == 0)
ignores->ignore_case = (val != 0);
else
ignores->ignore_case = 0;
git_config_free(cfg);
if ((error = git_vector_init(&ignores->ign_path, 8, NULL)) < 0 || if ((error = git_vector_init(&ignores->ign_path, 8, NULL)) < 0 ||
(error = git_vector_init(&ignores->ign_global, 2, NULL)) < 0 || (error = git_vector_init(&ignores->ign_global, 2, NULL)) < 0 ||
(error = git_attr_cache__init(repo)) < 0) (error = git_attr_cache__init(repo)) < 0)
......
...@@ -28,7 +28,7 @@ typedef struct { ...@@ -28,7 +28,7 @@ typedef struct {
git_attr_file *ign_internal; git_attr_file *ign_internal;
git_vector ign_path; git_vector ign_path;
git_vector ign_global; git_vector ign_global;
unsigned int ignore_case:1; int ignore_case;
} git_ignores; } git_ignores;
extern int git_ignore__for_path(git_repository *repo, const char *path, git_ignores *ign); extern int git_ignore__for_path(git_repository *repo, const char *path, git_ignores *ign);
......
...@@ -352,19 +352,18 @@ int git_index_set_caps(git_index *index, unsigned int caps) ...@@ -352,19 +352,18 @@ int git_index_set_caps(git_index *index, unsigned int caps)
old_ignore_case = index->ignore_case; old_ignore_case = index->ignore_case;
if (caps == GIT_INDEXCAP_FROM_OWNER) { if (caps == GIT_INDEXCAP_FROM_OWNER) {
git_config *cfg; git_repository *repo = INDEX_OWNER(index);
int val; int val;
if (INDEX_OWNER(index) == NULL || if (!repo)
git_repository_config__weakptr(&cfg, INDEX_OWNER(index)) < 0) return create_index_error(
return create_index_error(-1, -1, "Cannot access repository to set index caps");
"Cannot get repository config to set index caps");
if (git_config_get_bool(&val, cfg, "core.ignorecase") == 0) if (!git_repository__cvar(&val, repo, GIT_CVAR_IGNORECASE))
index->ignore_case = (val != 0); index->ignore_case = (val != 0);
if (git_config_get_bool(&val, cfg, "core.filemode") == 0) if (!git_repository__cvar(&val, repo, GIT_CVAR_FILEMODE))
index->distrust_filemode = (val == 0); index->distrust_filemode = (val == 0);
if (git_config_get_bool(&val, cfg, "core.symlinks") == 0) if (!git_repository__cvar(&val, repo, GIT_CVAR_SYMLINKS))
index->no_symlinks = (val == 0); index->no_symlinks = (val == 0);
} }
else { else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment