Skip to content

Commit

Permalink
fix(backend)!: Use correct merge stratgy for repository options (#291)
Browse files Browse the repository at this point in the history
This fixes the merge strategy for values of `options`, `options_hot`,
and `options_cold` to ignore incoming elements if they are already
existing in the HashMap. The prior implementation was overwriting the
values.

Breaking change: The freestanding and public `extend` function has been
removed. You can use `conflate::hashmap::overwrite` as a replacement.

---------

Signed-off-by: simonsan <[email protected]>
Co-authored-by: Alexander Weiss <[email protected]>
Co-authored-by: aawsome <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent 5980401 commit afaf707
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions crates/backend/src/choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,20 @@ pub struct BackendOptions {

/// Other options for this repository (hot and cold part)
#[cfg_attr(feature = "clap", clap(skip))]
#[cfg_attr(feature = "merge", merge(strategy = extend))]
#[cfg_attr(feature = "merge", merge(strategy = conflate::hashmap::ignore))]
pub options: HashMap<String, String>,

/// Other options for the hot repository
#[cfg_attr(feature = "clap", clap(skip))]
#[cfg_attr(feature = "merge", merge(strategy = extend))]
#[cfg_attr(feature = "merge", merge(strategy = conflate::hashmap::ignore))]
pub options_hot: HashMap<String, String>,

/// Other options for the cold repository
#[cfg_attr(feature = "clap", clap(skip))]
#[cfg_attr(feature = "merge", merge(strategy = extend))]
#[cfg_attr(feature = "merge", merge(strategy = conflate::hashmap::ignore))]
pub options_cold: HashMap<String, String>,
}

/// Overwrite the left value with the right value
///
/// This is used for merging config values, e.g. [`BackendOptions`].
///
/// # Arguments
///
/// * `left` - The left value
/// * `right` - The right value
#[cfg(feature = "merge")]
pub fn extend<A, T: Extend<A> + IntoIterator<Item = A>>(left: &mut T, right: T) {
left.extend(right);
}

impl BackendOptions {
/// Convert the options to backends.
///
Expand Down

0 comments on commit afaf707

Please sign in to comment.