Skip to content

Commit b799848

Browse files
committed
cli: only use default log revset when neither path nor revset is provided
1 parent 670e6ac commit b799848

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
* The `jj sparse` subcommands now parse and print patterns as workspace-relative
2323
paths.
2424

25+
* The `jj log` command no longer uses the default revset when a path is specified.
26+
2527
### New features
2628

2729
* Config now supports rgb hex colors (in the form `#rrggbb`) wherever existing color names are supported.

cli/src/cli_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ impl WorkspaceCommandHelper {
836836
self.attach_revset_evaluator(expression)
837837
}
838838

839-
fn attach_revset_evaluator(
839+
pub fn attach_revset_evaluator(
840840
&self,
841841
expression: Rc<RevsetExpression>,
842842
) -> Result<RevsetExpressionEvaluator<'_>, CommandError> {

cli/src/commands/log.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ use crate::ui::Ui;
3838
/// rendered as a synthetic node labeled "(elided revisions)".
3939
#[derive(clap::Args, Clone, Debug)]
4040
pub(crate) struct LogArgs {
41-
/// Which revisions to show. Defaults to the `revsets.log` setting, or
42-
/// `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set.
41+
/// Which revisions to show. If no paths nor revisions are specified, this
42+
/// defaults to the `revsets.log` setting, or `@ |
43+
/// ancestors(immutable_heads().., 2) | trunk()` if it is not set.
4344
#[arg(long, short)]
4445
revisions: Vec<RevisionArg>,
4546
/// Show revisions modifying the given paths
@@ -77,10 +78,14 @@ pub(crate) fn cmd_log(
7778
let workspace_command = command.workspace_helper(ui)?;
7879

7980
let revset_expression = {
80-
let mut expression = if args.revisions.is_empty() {
81+
// only use default revset if neither revset nor path are specified
82+
let mut expression = if args.revisions.is_empty() && args.paths.is_empty() {
8183
workspace_command.parse_revset(&command.settings().default_revset())?
82-
} else {
84+
} else if !args.revisions.is_empty() {
8385
workspace_command.parse_union_revsets(&args.revisions)?
86+
} else {
87+
// a path was specified so we use all() and add path filter later
88+
workspace_command.attach_revset_evaluator(RevsetExpression::all())?
8489
};
8590
if !args.paths.is_empty() {
8691
let repo_paths: Vec<_> = args
@@ -94,6 +99,7 @@ pub(crate) fn cmd_log(
9499
}
95100
expression
96101
};
102+
97103
let repo = workspace_command.repo();
98104
let matcher = workspace_command.matcher_from_values(&args.paths)?;
99105
let revset = revset_expression.evaluate()?;

cli/tests/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ Spans of revisions that are not included in the graph per `--revisions` are rend
10291029
10301030
###### **Options:**
10311031
1032-
* `-r`, `--revisions <REVISIONS>` — Which revisions to show. Defaults to the `revsets.log` setting, or `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set
1032+
* `-r`, `--revisions <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
10331033
* `--reversed` — Show revisions in the opposite order (older revisions first)
10341034
10351035
Possible values: `true`, `false`

cli/tests/test_log_command.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,15 @@ fn test_default_revset() {
10011001
.lines()
10021002
.count()
10031003
);
1004+
1005+
// The default revset is not used if a path is specified
1006+
insta::assert_snapshot!(
1007+
test_env.jj_cmd_success(&repo_path, &["log", "file1", "-T", "description"]),
1008+
@r###"
1009+
@ add a file
1010+
1011+
~
1012+
"###);
10041013
}
10051014

10061015
#[test]

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ immutable even if the set is empty.
215215

216216
### Default revisions to log
217217

218-
You can configure the revisions `jj log` without `-r` should show.
218+
You can configure the revisions `jj log` would show when neither `-r` nor any paths are specified.
219219

220220
```toml
221221
# Show commits that are not in `main@origin`

0 commit comments

Comments
 (0)