cli: make "debug revset" print expression for each stage

It helps while debugging tree substitution.
This commit is contained in:
Yuya Nishihara 2023-04-06 13:40:25 +09:00
parent f5a3d02638
commit 0d991bfa4a
3 changed files with 38 additions and 5 deletions

View file

@ -881,7 +881,11 @@ impl WorkspaceCommandHelper {
Ok(revset_expression.evaluate(self.repo.as_ref())?) 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 { RevsetWorkspaceContext {
cwd: &self.cwd, cwd: &self.cwd,
workspace_id: self.workspace_id(), workspace_id: self.workspace_id(),

View file

@ -3181,14 +3181,33 @@ fn cmd_debug_revset(
args: &DebugRevsetArgs, args: &DebugRevsetArgs,
) -> Result<(), CommandError> { ) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?; let workspace_command = command.workspace_helper(ui)?;
let expression = workspace_command.parse_revset(&args.revision)?; let workspace_ctx = workspace_command.revset_context();
writeln!(ui, "-- Expression:")?; 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, "{expression:#?}")?;
writeln!(ui)?; 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, "-- Evaluated:")?;
writeln!(ui, "{revset:#?}")?; writeln!(ui, "{revset:#?}")?;
writeln!(ui)?; writeln!(ui)?;
writeln!(ui, "-- Commit IDs:")?; writeln!(ui, "-- Commit IDs:")?;
for commit_id in revset.iter() { for commit_id in revset.iter() {
writeln!(ui, "{}", commit_id.hex())?; writeln!(ui, "{}", commit_id.hex())?;

View file

@ -30,11 +30,21 @@ fn test_debug_revset() {
(r"(?m)(^ .*\n)+", " ..\n"), (r"(?m)(^ .*\n)+", " ..\n"),
]}, { ]}, {
assert_snapshot!(stdout, @r###" assert_snapshot!(stdout, @r###"
-- Expression: -- Parsed:
Symbol( Symbol(
.. ..
) )
-- Optimized:
Symbol(
..
)
-- Resolved:
Commits(
..
)
-- Evaluated: -- Evaluated:
RevsetImpl { RevsetImpl {
.. ..