ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: only use default log revset when neither path nor revset is provided

This commit is contained in:
Noah Mayr 2024-03-31 11:47:31 +02:00
parent 670e6ac62b
commit b79984884d
6 changed files with 24 additions and 7 deletions

View file

@ -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.

View file

@ -836,7 +836,7 @@ impl WorkspaceCommandHelper {
self.attach_revset_evaluator(expression)
}
fn attach_revset_evaluator(
pub fn attach_revset_evaluator(
&self,
expression: Rc<RevsetExpression>,
) -> Result<RevsetExpressionEvaluator<'_>, CommandError> {

View file

@ -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
@ -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()?;

View file

@ -1029,7 +1029,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`

View file

@ -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]

View file

@ -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` nor any paths are specified.
```toml
# Show commits that are not in `main@origin`