From 9d4fb6a6d3e0fb337ec9bbd5c5608aebe5157e86 Mon Sep 17 00:00:00 2001 From: Noah Mayr Date: Sun, 31 Mar 2024 11:47:31 +0200 Subject: [PATCH] cli: only use default log revset when neither path nor revset is provided --- CHANGELOG.md | 2 ++ cli/src/cli_util.rs | 2 +- cli/src/commands/log.rs | 14 ++++++++++---- cli/tests/cli-reference@.md.snap | 2 +- cli/tests/test_log_command.rs | 9 +++++++++ docs/config.md | 2 +- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d93e165f5..aca9e46634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * The `jj sparse` subcommands now parse and print patterns as workspace-relative paths. +* The `jj log` command no longer uses the default revset when a path is specified. + ### New features * Config now supports rgb hex colors (in the form `#rrggbb`) wherever existing color names are supported. diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 71af456307..4564a87713 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -880,7 +880,7 @@ impl WorkspaceCommandHelper { self.attach_revset_evaluator(expression) } - fn attach_revset_evaluator( + pub fn attach_revset_evaluator( &self, expression: Rc, ) -> Result, CommandError> { diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index 93ca0f43e4..0df4ba1bfb 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -38,8 +38,9 @@ use crate::ui::Ui; /// rendered as a synthetic node labeled "(elided revisions)". #[derive(clap::Args, Clone, Debug)] pub(crate) struct LogArgs { - /// Which revisions to show. Defaults to the `revsets.log` setting, or - /// `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set. + /// Which revisions to show. If no paths nor revisions are specified, this + /// defaults to the `revsets.log` setting, or `@ | + /// ancestors(immutable_heads().., 2) | trunk()` if it is not set. #[arg(long, short)] revisions: Vec, /// Show revisions modifying the given paths @@ -77,10 +78,14 @@ pub(crate) fn cmd_log( let workspace_command = command.workspace_helper(ui)?; let revset_expression = { - let mut expression = if args.revisions.is_empty() { + // only use default revset if neither revset nor path are specified + let mut expression = if args.revisions.is_empty() && args.paths.is_empty() { workspace_command.parse_revset(&command.settings().default_revset())? - } else { + } else if !args.revisions.is_empty() { workspace_command.parse_union_revsets(&args.revisions)? + } else { + // a path was specified so we use all() and add path filter later + workspace_command.attach_revset_evaluator(RevsetExpression::all())? }; if !args.paths.is_empty() { let repo_paths: Vec<_> = args @@ -94,6 +99,7 @@ pub(crate) fn cmd_log( } expression }; + let repo = workspace_command.repo(); let matcher = workspace_command.matcher_from_values(&args.paths)?; let revset = revset_expression.evaluate()?; diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 8ff377a2f0..0e881954a2 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -1025,7 +1025,7 @@ Spans of revisions that are not included in the graph per `--revisions` are rend ###### **Options:** -* `-r`, `--revisions ` — Which revisions to show. Defaults to the `revsets.log` setting, or `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set +* `-r`, `--revisions ` — Which revisions to show. If no paths nor revisions are specified, this 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_log_command.rs b/cli/tests/test_log_command.rs index 0782d6ba3a..0d52f0ddf9 100644 --- a/cli/tests/test_log_command.rs +++ b/cli/tests/test_log_command.rs @@ -1001,6 +1001,15 @@ fn test_default_revset() { .lines() .count() ); + + // The default revset is not used if a path is specified + insta::assert_snapshot!( + test_env.jj_cmd_success(&repo_path, &["log", "file1", "-T", "description"]), + @r###" + @ add a file + │ + ~ + "###); } #[test] diff --git a/docs/config.md b/docs/config.md index 6ff3b99add..d8d8013ad3 100644 --- a/docs/config.md +++ b/docs/config.md @@ -215,7 +215,7 @@ immutable even if the set is empty. ### Default revisions to log -You can configure the revisions `jj log` without `-r` should show. +You can configure the revisions `jj log` without `-r` or any specified paths should show. ```toml # Show commits that are not in `main@origin`