Skip to content

Commit

Permalink
cli: only use default log revset when neither path nor revset is prov…
Browse files Browse the repository at this point in the history
…ided
  • Loading branch information
noahmayr committed Apr 2, 2024
1 parent 320f50e commit 6a89baa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ impl WorkspaceCommandHelper {
self.attach_revset_evaluator(expression)
}

fn attach_revset_evaluator(
pub fn attach_revset_evaluator(
&self,
expression: Rc<RevsetExpression>,
) -> Result<RevsetExpressionEvaluator<'_>, CommandError> {
Expand Down
14 changes: 10 additions & 4 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RevisionArg>,
/// Show revisions modifying the given paths
Expand Down Expand Up @@ -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
Expand All @@ -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()?;
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ Spans of revisions that are not included in the graph per `--revisions` are rend
###### **Options:**
* `-r`, `--revisions <REVISIONS>` — Which revisions to show. Defaults to the `revsets.log` setting, or `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set
* `-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
* `--reversed` — Show revisions in the opposite order (older revisions first)
Possible values: `true`, `false`
Expand Down
9 changes: 9 additions & 0 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` would show when neither `-r` paths are specified.

```toml
# Show commits that are not in `main@origin`
Expand Down

0 comments on commit 6a89baa

Please sign in to comment.