From 0d991bfa4a2c59654a271b714298cb84379065cc Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 6 Apr 2023 13:40:25 +0900 Subject: [PATCH] cli: make "debug revset" print expression for each stage It helps while debugging tree substitution. --- src/cli_util.rs | 6 +++++- src/commands/mod.rs | 25 ++++++++++++++++++++++--- tests/test_debug_command.rs | 12 +++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/cli_util.rs b/src/cli_util.rs index 349f1a108..7b48ae91e 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -881,7 +881,11 @@ impl WorkspaceCommandHelper { Ok(revset_expression.evaluate(self.repo.as_ref())?) } - fn revset_context(&self) -> RevsetWorkspaceContext { + pub(crate) fn revset_aliases_map(&self) -> &RevsetAliasesMap { + &self.revset_aliases_map + } + + pub(crate) fn revset_context(&self) -> RevsetWorkspaceContext { RevsetWorkspaceContext { cwd: &self.cwd, workspace_id: self.workspace_id(), diff --git a/src/commands/mod.rs b/src/commands/mod.rs index c76aa2ad2..94bf42447 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -3181,14 +3181,33 @@ fn cmd_debug_revset( args: &DebugRevsetArgs, ) -> Result<(), CommandError> { let workspace_command = command.workspace_helper(ui)?; - let expression = workspace_command.parse_revset(&args.revision)?; - writeln!(ui, "-- Expression:")?; + let workspace_ctx = workspace_command.revset_context(); + let repo = workspace_command.repo().as_ref(); + + let expression = revset::parse( + &args.revision, + workspace_command.revset_aliases_map(), + Some(&workspace_ctx), + )?; + writeln!(ui, "-- Parsed:")?; writeln!(ui, "{expression:#?}")?; writeln!(ui)?; - let revset = workspace_command.evaluate_revset(expression)?; + + let expression = revset::optimize(expression); + writeln!(ui, "-- Optimized:")?; + writeln!(ui, "{expression:#?}")?; + writeln!(ui)?; + + let expression = revset::resolve_symbols(repo, expression, Some(&workspace_ctx))?; + writeln!(ui, "-- Resolved:")?; + writeln!(ui, "{expression:#?}")?; + writeln!(ui)?; + + let revset = expression.evaluate(repo)?; writeln!(ui, "-- Evaluated:")?; writeln!(ui, "{revset:#?}")?; writeln!(ui)?; + writeln!(ui, "-- Commit IDs:")?; for commit_id in revset.iter() { writeln!(ui, "{}", commit_id.hex())?; diff --git a/tests/test_debug_command.rs b/tests/test_debug_command.rs index 1814f5bb0..d4f856936 100644 --- a/tests/test_debug_command.rs +++ b/tests/test_debug_command.rs @@ -30,11 +30,21 @@ fn test_debug_revset() { (r"(?m)(^ .*\n)+", " ..\n"), ]}, { assert_snapshot!(stdout, @r###" - -- Expression: + -- Parsed: Symbol( .. ) + -- Optimized: + Symbol( + .. + ) + + -- Resolved: + Commits( + .. + ) + -- Evaluated: RevsetImpl { ..