config: split ConfigSource::Env reflecting layer precedence

I'll make LayeredConfigs store a list of layers sorted by source (or
precedence), where multiple layers can exist for the same source.
This commit is contained in:
Yuya Nishihara 2024-11-22 18:07:26 +09:00
parent 8c5b39e286
commit 75b8e9b857
2 changed files with 11 additions and 6 deletions

View file

@ -87,10 +87,11 @@ pub enum ConfigEnvError {
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConfigSource {
Default,
Env,
EnvBase,
// TODO: Track explicit file paths, especially for when user config is a dir.
User,
Repo,
EnvOverrides,
CommandArg,
}
@ -183,10 +184,10 @@ impl LayeredConfigs {
pub fn sources(&self) -> Vec<(ConfigSource, &config::Config)> {
let config_sources = [
(ConfigSource::Default, Some(&self.default)),
(ConfigSource::Env, Some(&self.env_base)),
(ConfigSource::EnvBase, Some(&self.env_base)),
(ConfigSource::User, self.user.as_ref()),
(ConfigSource::Repo, self.repo.as_ref()),
(ConfigSource::Env, Some(&self.env_overrides)),
(ConfigSource::EnvOverrides, Some(&self.env_overrides)),
(ConfigSource::CommandArg, self.arg_overrides.as_ref()),
];
config_sources
@ -869,7 +870,7 @@ mod tests {
"base@user.email",
),
},
source: Env,
source: EnvBase,
is_overridden: true,
},
AnnotatedValue {
@ -907,7 +908,7 @@ mod tests {
"base-user-name",
),
},
source: Env,
source: EnvBase,
is_overridden: false,
},
AnnotatedValue {

View file

@ -141,7 +141,11 @@ fn warn_user_redefined_builtin(
) -> Result<(), CommandError> {
match source {
ConfigSource::Default => (),
ConfigSource::Env | ConfigSource::User | ConfigSource::Repo | ConfigSource::CommandArg => {
ConfigSource::EnvBase
| ConfigSource::User
| ConfigSource::Repo
| ConfigSource::EnvOverrides
| ConfigSource::CommandArg => {
let checked_mutability_builtins =
["mutable()", "immutable()", "builtin_immutable_heads()"];