From 2bc1d942c372090e6873e32b5b82d405fdb2eb2e 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 --- cli/src/commands/log.rs | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index 93ca0f43e45..ce68288510e 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -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)?;