Skip to content

Commit 96e716d

Browse files
committed
refactor: extract non-mergeable lists to a const
so it is easier to understand than in a function body.
1 parent da54ba3 commit 96e716d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/cargo/util/context/mod.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@ pub use schema::*;
132132

133133
use super::auth::RegistryConfig;
134134

135+
/// List of which configuration lists cannot be merged.
136+
///
137+
/// Instead of merging,
138+
/// the higher priority list should replaces the lower priority list.
139+
///
140+
/// ## What kind of config is non-mergeable
141+
///
142+
/// The rule of thumb is that if a config is a path of a program,
143+
/// it should be added to this list.
144+
const NON_MERGEABLE_LISTS: &[&str] = &[
145+
"credential-alias.*",
146+
"doc.browser",
147+
"host.runner",
148+
"registries.*.credential-provider",
149+
"registry.credential-provider",
150+
"target.*.runner",
151+
];
152+
135153
/// Helper macro for creating typed access methods.
136154
macro_rules! get_value_typed {
137155
($name:ident, $ty:ty, $variant:ident, $expected:expr) => {
@@ -2356,15 +2374,8 @@ impl ConfigValue {
23562374
}
23572375
}
23582376

2359-
/// List of which configuration lists cannot be merged.
2360-
/// Instead of merging, these the higher priority list replaces the lower priority list.
23612377
fn is_nonmergeable_list(key: &ConfigKey) -> bool {
2362-
key.matches("registry.credential-provider")
2363-
|| key.matches("registries.*.credential-provider")
2364-
|| key.matches("target.*.runner")
2365-
|| key.matches("host.runner")
2366-
|| key.matches("credential-alias.*")
2367-
|| key.matches("doc.browser")
2378+
NON_MERGEABLE_LISTS.iter().any(|l| key.matches(l))
23682379
}
23692380

23702381
pub fn homedir(cwd: &Path) -> Option<PathBuf> {

src/cargo/util/context/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl ConfigRelativePath {
9898
/// to get the actual program.
9999
///
100100
/// **Note**: Any usage of this type in config needs to be listed in
101-
/// the `util::context::is_nonmergeable_list` check to prevent list merging
101+
/// the [`super::NON_MERGEABLE_LISTS`] check to prevent list merging
102102
/// from multiple config files.
103103
#[derive(Debug, Clone, PartialEq)]
104104
pub struct PathAndArgs {

0 commit comments

Comments
 (0)