From ac31c83e13b03de33744a4c64198cf7bf9078ac0 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 10 May 2023 23:26:23 -0700 Subject: [PATCH] cli: rename `ui.default-revset` to `revsets.log` I plan to add `revsets.short-prefixes` and `revsets.immutable` soon, and I think `[revsets]` seems like reasonable place to put them. It seems consistent with our `[templates]` section. However, it also suffers from the same problem as that section, which is that the difference between `[templates]` and `[template-aliases]` is not clear. We can decide about about templates and revsets later. --- CHANGELOG.md | 2 ++ docs/config.md | 9 +++++++++ lib/src/settings.rs | 14 +++++++++----- src/commands/mod.rs | 2 +- src/config-schema.json | 19 ++++++++++++++----- tests/test_log_command.rs | 4 ++-- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d210bbbc2..3c932fca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 without arguments is now called `visible_heads()`. `heads()` with one argument is unchanged. +* The `ui.default-revset` config was renamed to `revsets.log`. + ### New features * `jj git push --deleted` will remove all locally deleted branches from the remote. diff --git a/docs/config.md b/docs/config.md index 182cbfa4a..e4cfdd7f0 100644 --- a/docs/config.md +++ b/docs/config.md @@ -141,6 +141,15 @@ ui.default-command = "log" ui.diff.format = "git" ``` +### Default revisions to log + +You can configure the revisions `jj log` without `-r` should show. + +```toml +# Show commits that are not in `main` +revsets.log = "main.." +``` + ### Graph style ```toml diff --git a/lib/src/settings.rs b/lib/src/settings.rs index 783c576d4..92f72187c 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -136,11 +136,15 @@ impl UserSettings { } pub fn default_revset(&self) -> String { - self.config - .get_string("ui.default-revset") - .unwrap_or_else(|_| { - "@ | (remote_branches() | tags()).. | ((remote_branches() | tags())..)-".to_string() - }) + self.config.get_string("revsets.log").unwrap_or_else(|_| { + // For compatibility with old config files (<0.8.0) + self.config + .get_string("ui.default-revset") + .unwrap_or_else(|_| { + "@ | (remote_branches() | tags()).. | ((remote_branches() | tags())..)-" + .to_string() + }) + }) } pub fn signature(&self) -> Signature { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 97e604aa9..0b2289425 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -328,7 +328,7 @@ struct StatusArgs {} /// Show commit history #[derive(clap::Args, Clone, Debug)] struct LogArgs { - /// Which revisions to show. Defaults to the `ui.default-revset` setting, + /// Which revisions to show. Defaults to the `revsets.log` setting, /// or `@ | (remote_branches() | tags()).. | ((remote_branches() | /// tags())..)-` if it is not set. #[arg(long, short)] diff --git a/src/config-schema.json b/src/config-schema.json index 6638a972e..6bcfbdf8b 100644 --- a/src/config-schema.json +++ b/src/config-schema.json @@ -56,11 +56,6 @@ "description": "Default command to run when no explicit command is given", "default": "log" }, - "default-revset": { - "type": "string", - "description": "Default set of revisions to show when no explicit revset is given for jj log and similar commands", - "default": "@ | (remote_branches() | tags()).. | ((remote_branches() | tags())..)-" - }, "color": { "description": "Whether to colorize command output", "enum": [ @@ -267,6 +262,20 @@ } } }, + "revsets": { + "type": "object", + "description": "Revset expressions used by various commands", + "properties": { + "log": { + "type": "string", + "description": "Default set of revisions to show when no explicit revset is given for jj log and similar commands", + "default": "@ | (remote_branches() | tags()).. | ((remote_branches() | tags())..)-" + } + }, + "additionalProperties": { + "type": "string" + } + }, "revset-aliases": { "type": "object", "description": "Custom symbols/function aliases that can used in revset expressions", diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index c8b2ca7e5..d1c286e2b 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -788,7 +788,7 @@ fn test_default_revset() { test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]); // Set configuration to only show the root commit. - test_env.add_config(r#"ui.default-revset = "root""#); + test_env.add_config(r#"revsets.log = "root""#); // Log should only contain one line (for the root commit), and not show the // commit created above. @@ -813,7 +813,7 @@ fn test_default_revset_per_repo() { // Set configuration to only show the root commit. std::fs::write( repo_path.join(".jj/repo/config.toml"), - r#"ui.default-revset = "root""#, + r#"revsets.log = "root""#, ) .unwrap();