From 6c5947181d4b4ad1cd5b76e24295e71469706248 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 2 Apr 2023 18:22:00 +0900 Subject: [PATCH] cli: reimplement "debug resolverev" as command to debug print revset Also removed -r/--revision and the default "@" as it is a debug command. --- src/commands/mod.rs | 35 +++++++++++++++++++++++++---------- tests/test_debug_command.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index b0135b689..f4aa3dbc3 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -932,8 +932,7 @@ struct SupportConfigSchemaArgs {} #[derive(Subcommand, Clone, Debug)] #[command(hide = true)] enum DebugCommands { - #[command(name = "resolverev")] - ResolveRev(DebugResolveRevArgs), + Revset(DebugRevsetArgs), #[command(name = "workingcopy")] WorkingCopy(DebugWorkingCopyArgs), Template(DebugTemplateArgs), @@ -943,10 +942,9 @@ enum DebugCommands { Operation(DebugOperationArgs), } -/// Resolve a revision identifier to its full ID +/// Evaluate revset to full commit IDs #[derive(clap::Args, Clone, Debug)] -struct DebugResolveRevArgs { - #[arg(long, short, default_value = "@")] +struct DebugRevsetArgs { revision: String, } @@ -3092,11 +3090,7 @@ fn cmd_debug( subcommand: &DebugCommands, ) -> Result<(), CommandError> { match subcommand { - DebugCommands::ResolveRev(resolve_matches) => { - let workspace_command = command.workspace_helper(ui)?; - let commit = workspace_command.resolve_single_rev(&resolve_matches.revision)?; - writeln!(ui, "{}", commit.id().hex())?; - } + DebugCommands::Revset(args) => cmd_debug_revset(ui, command, args)?, DebugCommands::WorkingCopy(_wc_matches) => { let workspace_command = command.workspace_helper(ui)?; let wc = workspace_command.working_copy(); @@ -3174,6 +3168,27 @@ fn cmd_debug( Ok(()) } +fn cmd_debug_revset( + ui: &mut Ui, + command: &CommandHelper, + args: &DebugRevsetArgs, +) -> Result<(), CommandError> { + let workspace_command = command.workspace_helper(ui)?; + let expression = workspace_command.parse_revset(&args.revision)?; + writeln!(ui, "-- Expression:")?; + writeln!(ui, "{expression:#?}")?; + writeln!(ui)?; + let revset = workspace_command.evaluate_revset(expression)?; + writeln!(ui, "-- Evaluated:")?; + writeln!(ui, "{revset:#?}")?; + writeln!(ui)?; + writeln!(ui, "-- Commit IDs:")?; + for commit_id in revset.iter() { + writeln!(ui, "{}", commit_id.hex())?; + } + Ok(()) +} + fn cmd_workspace( ui: &mut Ui, command: &CommandHelper, diff --git a/tests/test_debug_command.rs b/tests/test_debug_command.rs index 80269add5..1814f5bb0 100644 --- a/tests/test_debug_command.rs +++ b/tests/test_debug_command.rs @@ -19,6 +19,33 @@ use crate::common::TestEnvironment; pub mod common; +#[test] +fn test_debug_revset() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); + let workspace_path = test_env.env_root().join("repo"); + + let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "revset", "root"]); + insta::with_settings!({filters => vec![ + (r"(?m)(^ .*\n)+", " ..\n"), + ]}, { + assert_snapshot!(stdout, @r###" + -- Expression: + Symbol( + .. + ) + + -- Evaluated: + RevsetImpl { + .. + } + + -- Commit IDs: + 0000000000000000000000000000000000000000 + "###); + }); +} + #[test] fn test_debug_index() { let test_env = TestEnvironment::default();