Commit ab01cbd4 by Russell Belfer

Add configs to repo config cache

This adds a bunch of additional config values to the repository
config value cache and makes it easier to add a simple boolean
config without creating enum values for each possible setting.

Also, this fixes a bug in git_config_refresh where the config
cache was not being cleared which could lead to potential
incorrect values.

The work to start using the new cached configs will come in the
next couple of commits...
parent 608d0466
...@@ -293,6 +293,9 @@ int git_config_refresh(git_config *cfg) ...@@ -293,6 +293,9 @@ int git_config_refresh(git_config *cfg)
error = file->refresh(file); error = file->refresh(file);
} }
if (!error && GIT_REFCOUNT_OWNER(cfg) != NULL)
git_repository__cvar_cache_clear(GIT_REFCOUNT_OWNER(cfg));
return error; return error;
} }
......
...@@ -26,7 +26,7 @@ struct map_data { ...@@ -26,7 +26,7 @@ struct map_data {
* files that have the text property set. Alternatives are lf, crlf * files that have the text property set. Alternatives are lf, crlf
* and native, which uses the platform's native line ending. The default * and native, which uses the platform's native line ending. The default
* value is native. See gitattributes(5) for more information on * value is native. See gitattributes(5) for more information on
* end-of-line conversion. * end-of-line conversion.
*/ */
static git_cvar_map _cvar_map_eol[] = { static git_cvar_map _cvar_map_eol[] = {
{GIT_CVAR_FALSE, NULL, GIT_EOL_UNSET}, {GIT_CVAR_FALSE, NULL, GIT_EOL_UNSET},
...@@ -37,7 +37,7 @@ static git_cvar_map _cvar_map_eol[] = { ...@@ -37,7 +37,7 @@ static git_cvar_map _cvar_map_eol[] = {
/* /*
* core.autocrlf * core.autocrlf
* Setting this variable to "true" is almost the same as setting * Setting this variable to "true" is almost the same as setting
* the text attribute to "auto" on all files except that text files are * the text attribute to "auto" on all files except that text files are
* not guaranteed to be normalized: files that contain CRLF in the * not guaranteed to be normalized: files that contain CRLF in the
* repository will not be touched. Use this setting if you want to have * repository will not be touched. Use this setting if you want to have
...@@ -51,9 +51,22 @@ static git_cvar_map _cvar_map_autocrlf[] = { ...@@ -51,9 +51,22 @@ static git_cvar_map _cvar_map_autocrlf[] = {
{GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT} {GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT}
}; };
/*
* Generic map for integer values
*/
static git_cvar_map _cvar_map_int[] = {
{GIT_CVAR_INT32, NULL, 0},
};
static struct map_data _cvar_maps[] = { static struct map_data _cvar_maps[] = {
{"core.autocrlf", _cvar_map_autocrlf, ARRAY_SIZE(_cvar_map_autocrlf), GIT_AUTO_CRLF_DEFAULT}, {"core.autocrlf", _cvar_map_autocrlf, ARRAY_SIZE(_cvar_map_autocrlf), GIT_AUTO_CRLF_DEFAULT},
{"core.eol", _cvar_map_eol, ARRAY_SIZE(_cvar_map_eol), GIT_EOL_DEFAULT} {"core.eol", _cvar_map_eol, ARRAY_SIZE(_cvar_map_eol), GIT_EOL_DEFAULT},
{"core.symlinks", NULL, 0, GIT_SYMLINKS_DEFAULT },
{"core.ignorecase", NULL, 0, GIT_IGNORECASE_DEFAULT },
{"core.filemode", NULL, 0, GIT_FILEMODE_DEFAULT },
{"core.ignorestat", NULL, 0, GIT_IGNORESTAT_DEFAULT },
{"core.trustctime", NULL, 0, GIT_TRUSTCTIME_DEFAULT },
{"core.abbrev", _cvar_map_int, 1, GIT_ABBREV_DEFAULT },
}; };
int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar) int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar)
...@@ -69,12 +82,16 @@ int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar) ...@@ -69,12 +82,16 @@ int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar)
if (error < 0) if (error < 0)
return error; return error;
error = git_config_get_mapped(out, if (data->maps)
config, data->cvar_name, data->maps, data->map_count); error = git_config_get_mapped(
out, config, data->cvar_name, data->maps, data->map_count);
else
error = git_config_get_bool(out, config, data->cvar_name);
if (error == GIT_ENOTFOUND) if (error == GIT_ENOTFOUND) {
giterr_clear();
*out = data->default_value; *out = data->default_value;
}
else if (error < 0) else if (error < 0)
return error; return error;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "git2/odb.h" #include "git2/odb.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/object.h" #include "git2/object.h"
#include "git2/config.h"
#include "index.h" #include "index.h"
#include "cache.h" #include "cache.h"
...@@ -31,7 +32,13 @@ ...@@ -31,7 +32,13 @@
/** Cvar cache identifiers */ /** Cvar cache identifiers */
typedef enum { typedef enum {
GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */ GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
GIT_CVAR_EOL, /* core.eol */ GIT_CVAR_EOL, /* core.eol */
GIT_CVAR_SYMLINKS, /* core.symlinks */
GIT_CVAR_IGNORECASE, /* core.ignorecase */
GIT_CVAR_FILEMODE, /* core.filemode */
GIT_CVAR_IGNORESTAT, /* core.ignorestat */
GIT_CVAR_TRUSTCTIME, /* core.trustctime */
GIT_CVAR_ABBREV, /* core.abbrev */
GIT_CVAR_CACHE_MAX GIT_CVAR_CACHE_MAX
} git_cvar_cached; } git_cvar_cached;
...@@ -67,7 +74,21 @@ typedef enum { ...@@ -67,7 +74,21 @@ typedef enum {
#else #else
GIT_EOL_NATIVE = GIT_EOL_LF, GIT_EOL_NATIVE = GIT_EOL_LF,
#endif #endif
GIT_EOL_DEFAULT = GIT_EOL_NATIVE GIT_EOL_DEFAULT = GIT_EOL_NATIVE,
/* core.symlinks: bool */
GIT_SYMLINKS_DEFAULT = GIT_CVAR_TRUE,
/* core.ignorecase */
GIT_IGNORECASE_DEFAULT = GIT_CVAR_FALSE,
/* core.filemode */
GIT_FILEMODE_DEFAULT = GIT_CVAR_TRUE,
/* core.ignorestat */
GIT_IGNORESTAT_DEFAULT = GIT_CVAR_FALSE,
/* core.trustctime */
GIT_TRUSTCTIME_DEFAULT = GIT_CVAR_TRUE,
/* core.abbrev */
GIT_ABBREV_DEFAULT = 7,
} git_cvar_value; } git_cvar_value;
/* internal repository init flags */ /* internal repository init flags */
......
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