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

config: add conditional tables #5135

Merged
merged 6 commits into from
Dec 19, 2024
Merged

config: add conditional tables #5135

merged 6 commits into from
Dec 19, 2024

Conversation

yuja
Copy link
Contributor

@yuja yuja commented Dec 18, 2024

#616

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

Copy link
Contributor

@PhilipMetzger PhilipMetzger left a 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.

lib/src/config.rs Outdated Show resolved Hide resolved
lib/src/config_resolver.rs Outdated Show resolved Hide resolved
yuja added 6 commits December 19, 2024 10:53
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 yuja force-pushed the push-klomkoxqlvvq branch from 216f54c to 225a1e6 Compare December 19, 2024 01:57
@yuja yuja enabled auto-merge (rebase) December 19, 2024 02:07
@yuja yuja merged commit f5d450d into jj-vcs:main Dec 19, 2024
18 checks passed
@yuja yuja deleted the push-klomkoxqlvvq branch December 19, 2024 02:09
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