cli: reimplement "debug resolverev" as command to debug print revset

Also removed -r/--revision and the default "@" as it is a debug command.
This commit is contained in:
Yuya Nishihara 2023-04-02 18:22:00 +09:00
parent 429562ca2f
commit 6c5947181d
2 changed files with 52 additions and 10 deletions

View file

@ -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,

View file

@ -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();