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 1, 2024
1 parent 320f50e commit 2bc1d94
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,30 @@ pub(crate) fn cmd_log(
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;

let revset_expression = {
let mut expression = if args.revisions.is_empty() {
workspace_command.parse_revset(&command.settings().default_revset())?
} else {
workspace_command.parse_union_revsets(&args.revisions)?
};
if !args.paths.is_empty() {
let repo_paths: Vec<_> = args
.paths
.iter()
.map(|path_arg| workspace_command.parse_file_path(path_arg))
.try_collect()?;
expression.intersect_with(&RevsetExpression::filter(RevsetFilterPredicate::File(
Some(repo_paths),
)));
}
expression
let path_expression = if !args.paths.is_empty() {
let repo_paths: Vec<_> = args
.paths
.iter()
.map(|path_arg| workspace_command.parse_file_path(path_arg))
.try_collect()?;
Some(RevsetExpression::filter(RevsetFilterPredicate::File(Some(
repo_paths,
))))
} else {
None
};

// if no args are passed, use default revset
// if only paths are passed, filter by paths
// if only a revset is passed, use the revset
// if paths and revset are passed, use an intersection of both
let revset_expression = match (args.revisions.is_empty(), path_expression.clone()) {
(true, None) => workspace_command.parse_revset(&command.settings().default_revset())?,
(true, Some(path_expression)) => path_expression,
(false, None) => workspace_command.parse_union_revsets(&args.revisions)?,
(false, Some(path_expression)) => workspace_command
.parse_union_revsets(&args.revisions)?
.intersect_with(&path_expression),
};
let repo = workspace_command.repo();
let matcher = workspace_command.matcher_from_values(&args.paths)?;
Expand Down

0 comments on commit 2bc1d94

Please sign in to comment.