From ba6ea6f638711480f9f9aedf0adba22afd4a2911 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 27 Jul 2023 08:00:20 -0700 Subject: [PATCH] cli: make `jj debug operation --display operation` work with broken view This is to aid debugging in cases like #1907, where the operation object has an invalid view object. --- src/cli_util.rs | 2 +- src/commands/debug.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cli_util.rs b/src/cli_util.rs index afaaf6609..e4d096988 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1615,7 +1615,7 @@ fn expand_git_path(path_str: String) -> PathBuf { PathBuf::from(path_str) } -fn resolve_op_for_load( +pub fn resolve_op_for_load( op_store: &Arc, op_heads_store: &Arc, op_str: &str, diff --git a/src/commands/debug.rs b/src/commands/debug.rs index f5b6a7e41..ecdeb8b68 100644 --- a/src/commands/debug.rs +++ b/src/commands/debug.rs @@ -19,7 +19,7 @@ use jj_lib::backend::ObjectId; use jj_lib::default_index_store::{DefaultIndexStore, ReadonlyIndexWrapper}; use jj_lib::revset; -use crate::cli_util::{user_error, CommandError, CommandHelper}; +use crate::cli_util::{resolve_op_for_load, user_error, CommandError, CommandHelper}; use crate::template_parser; use crate::ui::Ui; @@ -167,8 +167,15 @@ pub fn cmd_debug( } } DebugCommands::Operation(operation_args) => { - let workspace_command = command.workspace_helper(ui)?; - let op = workspace_command.resolve_single_op(&operation_args.operation)?; + // Resolve the operation without loading the repo, so this command can be used + // even if e.g. the view object is broken. + let workspace = command.load_workspace()?; + let repo_loader = workspace.repo_loader(); + let op = resolve_op_for_load( + repo_loader.op_store(), + repo_loader.op_heads_store(), + &operation_args.operation, + )?; if operation_args.display == DebugOperationDisplay::Id { writeln!(ui, "{}", op.id().hex())?; return Ok(());