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

Don't eagerly merge configs. #20459

Merged
merged 1 commit into from
Jan 25, 2024
Merged

Conversation

benjyw
Copy link
Contributor

@benjyw benjyw commented Jan 24, 2024

Merging the config values is incorrect for list- and
dict-valued options, where we want to concatenate
edits, not stomp them.

For example, if for some list-valued option the default
value is [0,1], config1 has -[0] and config2 has +[2,3]
then the resulting value should be [1,2,3], but before
this change it would have been [0,1,2,3].

Instead, we preserve each config file as a separate
source, and do the appropriate stomping/merging
at option value get time.

Merging the config values is incorrect for
list- and dict-valued options, where we want
to concatenate edits, not stomp them.

For example, if for some list-valued option the
default value is [0,1], config1 has -[0] and
config2 has +[2,3] then the resulting value should
be [1,2,3], but before this change it would have been
[0,1,2,3].
@benjyw benjyw added the category:bugfix Bug fixes for released features label Jan 24, 2024
@benjyw benjyw requested a review from tgolsson January 24, 2024 22:52
config: Value,
}

impl ConfigSource {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff looks scarier than it is. The meat of this change is the introduction of a ConfigSource, representing a single Config, and moving the generic get_value/get_list/get_dict logic to it unchanged. Then Config has a vec of these ConfigSources, and does the right thing.

The rest is just test and plumbing changes.

@@ -56,24 +56,46 @@ fn test_display() {
}

#[test]
fn test_section_overlap() {
// Two files with the same section should result in merged content for that section.
fn test_multiple_sources() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test has been enhanced to test more multiple source scenarios.

Copy link
Contributor

@tgolsson tgolsson left a comment

Choose a reason for hiding this comment

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

Two nits that I think would really help readability, and one question. Looks good overall, but would be nice with a small cleanup.

@benjyw
Copy link
Contributor Author

benjyw commented Jan 25, 2024

Thanks for the review!

@benjyw benjyw merged commit b47af8a into pantsbuild:main Jan 25, 2024
24 checks passed
@benjyw benjyw deleted the config_merge_fix branch January 25, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:bugfix Bug fixes for released features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants