-
Notifications
You must be signed in to change notification settings - Fork 372
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
config: add conditional tables #5135
Merged
Merged
Conversation
This file contains 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
PhilipMetzger
approved these changes
Dec 18, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, thanks for implementing the feature.
martinvonz
approved these changes
Dec 18, 2024
ConfigLayers will be cloned to new StackedConfig instance at resolution stage. ConfigFile could own ConfigLayer instead of Arc<_>, but copy-on-write behavior is probably better for the current users.
This provides an inline version of Git's includeIf. The idea is that each config layer has an optional key "--when" to enable the layer, and a layer may have multiple sub-layer tables "--scope" to inline stuff. Layers can be nested, but that wouldn't be useful in practice. I choose "--" prefix to make these meta keys look special (and are placed earlier in lexicographical order), but I don't have strong opinion about that. We can use whatever names that are unlikely to conflict with the other config sections. resolve() isn't exported as a StackedConfig method because it doesn't make sense to call resolve() on "resolved" StackedConfig. I'll add a newtype in CLI layer to distinguish raw config from resolved one. Most consumers will just see the "resolved" config. jj-vcs#616
This will simplify path comparison in config resolver. <cwd>/.. shouldn't match path prefix <cwd>. Maybe we should do path canonicalization globally (or never do canonicalization), but I'm not sure where that should be made.
I'm going to add config post-processing stage in order to enable config variables conditionally, and handle/parse_early_args() doesn't have enough information to evaluate the condition. The deprecation warning could be emitted by parse_early_args(), but it's probably better to print it after --color option is applied.
The next patch will introduce the resolution stage of conditional tables. Since it wasn't easy to detect misuse of "raw" StackedConfig, I added a thin newtype.
This is an alternative way to achieve includeIf of Git without adding "include" directive. Conditional include (or include in general) is a bit trickier to implement than loading all files and filtering the contents. Closes jj-vcs#616
yuja
force-pushed
the
push-klomkoxqlvvq
branch
from
December 19, 2024 01:57
216f54c
to
225a1e6
Compare
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.
#616
Checklist
If applicable:
CHANGELOG.md