♻️ Refactor Config.versioned_defaults to reduce merge conflicts (backport to 0.5)#584
Merged
nevans merged 7 commits intov0.5-stablefrom Dec 17, 2025
Merged
Conversation
This will be used to simplify the code in lib/net/imap/config.rb. In this first step, only a couple pieces are extracted: * `AttrVersionDefaults` stores the `Config.version_defaults` hash. The hash's `#default_proc` is defined there, too. * `AttrVersionDefaults.compile` only freezes that hash.
This refactoring decouples the assignment of versioned default values and the creation of `version_defaults` config objects. At first, `version_defaults` stores hashes for each version's updated defaults. At the end, the hashes are transformed into config objects by `Config::AttrVersionDefaults.compile!`.
This also causes Config[0.7r] through Config[1.0r] to be aliases (rather than clones) of each other.
This avoids usage of the private `Config#defaults_hash` method, relying instead on the public `#load_defaults` API.
At the cost of one big conflict now, this should significantly reduce future merge conflicts in the config file. It's also easier to match documentation with default values when they're right next to each other. This also assigns all of the original (`Config[0]`) defaults explicitly, and not only where they differ from Config.default.
Similar to the versioned defaults, this could be a source of conflicts when merging, rebasing, or cherry-picking feature and backport branches. Now that all of the attributes specify their defaults, the current version's default config can be compiled from that. The sanity-check at the end of `config.rb` has been removed. It was there to protect against bad merges. Now that `Config.default` is also compiled from the version defaults added to each attr_accessor, the tests in `test/net/imap/test_config.rb` are good enough.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports #544 to the
v0.5-stablebranch. From that PR:This handles that "one final merge conflict" for this branch.