Skip to content

Conversation

LucasOe
Copy link

@LucasOe LucasOe commented Jun 26, 2022

Fix for #64:
This fix replaces the duplicate merge_tables function with the already existing recursive_extend_map function. I wasn't able to add unit tests because I don't know any Rust. From my testing this solution works, but please take a look at it before merging and let me know if there are any issues.

runiq and others added 2 commits June 25, 2022 21:20
src/config.rs Outdated
@@ -331,7 +331,19 @@ fn merge_configuration_files(

for (variable_name, variable_value) in package.variables {
if first_package.variables.contains_key(&variable_name) {
anyhow::bail!("variable {:?} already encountered", variable_name);
// Panic safety: Already checked via `contains_key` above
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be rewritten like so:

-                if first_package.variables.contains_key(&variable_name) {
-                    // Panic safety: Already checked via `contains_key` above
-                    let mut first_value = first_package.variables.get_mut(&variable_name).unwrap();
-                    match (&mut first_value, &variable_value) {
+                if let Some(first_value) = first_package.variables.get_mut(&variable_name).as_mut() {
+                    match (&first_value, &variable_value) {

src/config.rs Outdated
let mut first_value = first_package.variables.get_mut(&variable_name).unwrap();
match (&mut first_value, &variable_value) {
(toml::Value::Table(_a), toml::Value::Table(_b)) => {
info!("Merging {:?} tables", variable_name);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be trace!, not info! since it shouldn't appear with just a single -v, it fits more into -vvv category.

@SuperCuber
Copy link
Owner

See above comments and make sure to run cargo fmt to keep the CI happy, and this is looking good :D

@LucasOe
Copy link
Author

LucasOe commented Jun 26, 2022

I fixed the issues mentioned above.

@SuperCuber
Copy link
Owner

The code could be simplified even more, I pushed a commit that implements it with the simplification.

Thanks for opening the PR, I wouldn't have gotten around to it otherwise :)

@LucasOe LucasOe deleted the merge-tables branch June 26, 2022 16:02
@runiq
Copy link

runiq commented Jun 27, 2022

Yeah, me neither. (I was the OP of the other PR.)

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants