From 07578cbb51e8a1be59d39400d716b348a2fa7937 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 19 Feb 2024 23:20:13 +0900 Subject: [PATCH] cli: change default log revset to not include all tagged heads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default immutable_heads() includes tags(), which makes sense, but computing heads(tags()) can be expensive because the tags() set is usually sparse. For example, "jj bench revset 'heads(tags())'" took 157ms in my linux stable mirror. We can of course optimize the heads evaluation by using bit set or segmented index, but the query includes many historical heads if the repository has per-release branches, which are uninteresting anyway. So, this patch replaces heads(immutable_heads()) with trunk(). The reason we include heads(immutable_heads()) is to mitigate the following problem. Suppose trunk() is the branch to be based off, I think using trunk() here is pretty good. ``` A B *---*----* trunk() ⊆ immutable_heads() \ * C ``` https://github.com/martinvonz/jj/pull/2247#discussion_r1335078879 --- CHANGELOG.md | 4 ++++ cli/src/commands/log.rs | 3 +-- cli/src/config-schema.json | 2 +- cli/tests/cli-reference@.md.snap | 2 +- cli/tests/test_immutable_commits.rs | 5 +++-- lib/src/settings.rs | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac78133347f..20d5ab4f225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Dropped support for the "legacy" graph-drawing style. Use "ascii" for a very similar result. +* The default log output no longer lists all tagged heads. Set `revsets.log = + "@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())"` to restore + the old behavior. + * Dropped support for the deprecated `:` revset operator. Use `::` instead. ### New features diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index 641323a8e67..83ea7f2fec8 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -30,8 +30,7 @@ use crate::ui::Ui; #[derive(clap::Args, Clone, Debug)] pub(crate) struct LogArgs { /// Which revisions to show. Defaults to the `revsets.log` setting, or - /// `@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())` if - /// it is not set. + /// `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set. #[arg(long, short)] revisions: Vec, /// Show commits modifying the given paths diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json index 0db9dd1cc3c..5c768a01896 100644 --- a/cli/src/config-schema.json +++ b/cli/src/config-schema.json @@ -303,7 +303,7 @@ "log": { "type": "string", "description": "Default set of revisions to show when no explicit revset is given for jj log and similar commands", - "default": "@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())" + "default": "@ | ancestors(immutable_heads().., 2) | trunk()" }, "short-prefixes": { "type": "string", diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 3201a151dbb..9cf232dfa4e 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -1002,7 +1002,7 @@ Show commit history ###### **Options:** -* `-r`, `--revisions ` — Which revisions to show. Defaults to the `revsets.log` setting, or `@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())` if it is not set +* `-r`, `--revisions ` — Which revisions to show. Defaults to the `revsets.log` setting, or `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set * `--reversed` — Show revisions in the opposite order (older revisions first) Possible values: `true`, `false` diff --git a/cli/tests/test_immutable_commits.rs b/cli/tests/test_immutable_commits.rs index 66dfb0e7d84..96ca227ef14 100644 --- a/cli/tests/test_immutable_commits.rs +++ b/cli/tests/test_immutable_commits.rs @@ -64,7 +64,7 @@ fn test_rewrite_immutable_generic() { insta::assert_snapshot!(stderr, @r###" Config error: Invalid `revsets.short-prefixes`: --> 1:31 | - 1 | @ | ancestors(immutable_heads().., 2) | heads(immutable_heads()) + 1 | @ | ancestors(immutable_heads().., 2) | trunk() | ^ | = Invalid arguments to revset function "immutable_heads": Expected 1 arguments @@ -93,8 +93,9 @@ fn test_rewrite_immutable_commands() { test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]); test_env.jj_cmd_ok(&repo_path, &["new", "description(b)"]); test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#); + test_env.add_config(r#"revset-aliases."trunk()" = "main""#); - // Log shows mutable commits and immutable heads by default + // Log shows mutable commits, their parents, and trunk() by default let stdout = test_env.jj_cmd_success(&repo_path, &["log"]); insta::assert_snapshot!(stdout, @r###" @ yqosqzyt test.user@example.com 2001-02-03 04:05:13.000 +07:00 3f89addf diff --git a/lib/src/settings.rs b/lib/src/settings.rs index be51e237c8c..10bea3019a3 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -210,7 +210,7 @@ impl UserSettings { self.config .get_string("ui.default-revset") .unwrap_or_else(|_| { - "@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())".to_string() + "@ | ancestors(immutable_heads().., 2) | trunk()".to_string() }) }) }