Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge default language data with section language data #2039

Merged
merged 6 commits into from
Jan 17, 2023

Conversation

vcrn
Copy link
Contributor

@vcrn vcrn commented Nov 26, 2022

Resolves #1918

When there is a merge conflict, I went with causing a panic right away and not returning anything if everything went well, instead of bail at conflict and returning an Ok() if everything went well. If you want this changed to the latter approach, just let me know.

I don't seem to be able to directly manipulate languagesi[default_language], which is why I'm cloning it, manipulating it via .merge() and then using .insert().

The test add_default_language_skips_insert() doesn't check that insert actually hasn't been performed, it is only when running it manually that a person can check and see that a warning message hasn't been printed. I used it for my testing and left it, but we can remove it if you want to.

Also, under method add_default_language() there was some TODO comments. This PR might solve it but I'm not sure, so I've left it.

@vcrn vcrn changed the title Merge def lang data with section lang data Merge default language data with section language data Nov 26, 2022
Copy link
Collaborator

@Keats Keats left a comment

Choose a reason for hiding this comment

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

I think that's not the right way to do it. We should handle that before adding the default language struct in this line: https://github.com/getzola/zola/blob/next/components/config/src/config/mod.rs#L128

components/config/src/config/languages.rs Outdated Show resolved Hide resolved
components/config/src/config/languages.rs Outdated Show resolved Hide resolved
components/config/src/config/mod.rs Outdated Show resolved Hide resolved
@vcrn
Copy link
Contributor Author

vcrn commented Dec 4, 2022

Thanks for the feedback! It seems clear for me how to proceed.

Edit:

I think that's not the right way to do it. We should handle that before adding the default language struct in this line: https://github.com/getzola/zola/blob/next/components/config/src/config/mod.rs#L128

This one I'm a bit uncertain about though. Which part are you referring to that should be handled before adding the default language struct, @Keats?

@vcrn
Copy link
Contributor Author

vcrn commented Dec 8, 2022

Fixing my broken logic, I went with a slightly more complicated route than I first imagined, in order to not do a merge unless necessary. If you think we should go with a simpler route, I propose something like this:

        if let Some(section_default_language_options) = self.languages.get(&self.default_language) {
            if base_default_language_options != languages::LanguageOptions::default() {
                println!("Warning: config.toml contains both default language specific information at base and under section `[languages.{}]`, \
                    which may cause merge conflicts. Please use only one to specify language specific information", self.default_language);
            }
            base_default_language_options.merge(section_default_language_options)?;
        }
        self.languages.insert(self.default_language.clone(), base_default_language_options);

        Ok(()

@vcrn vcrn requested a review from Keats December 27, 2022 10:22
@vcrn
Copy link
Contributor Author

vcrn commented Jan 8, 2023

Just wanted to check whether you believe you'll have time to check out the updated PR any time soon, @Keats ?

Copy link
Collaborator

@Keats Keats left a comment

Choose a reason for hiding this comment

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

It's ok I think. I'll change some style stuff later after merging but I think we should at least correcly test the errors before merging.

components/config/src/config/mod.rs Outdated Show resolved Hide resolved
@vcrn vcrn force-pushed the merge_def_data_lang_data branch from 773d50b to 5512f7a Compare January 14, 2023 09:11
@vcrn vcrn requested a review from Keats January 14, 2023 09:46
@vcrn
Copy link
Contributor Author

vcrn commented Jan 14, 2023

@Keats, I've updated the test in question. I also took a second look at your test names and gave mine ones that are more in line with yours. I also changed some of the variable names in the new tests so they are more descriptive.

@Keats
Copy link
Collaborator

Keats commented Jan 17, 2023

Thanks!

Keats pushed a commit that referenced this pull request Feb 16, 2023
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.

2 participants