diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index 8fd38aa23..2b1232262 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -66,6 +66,11 @@ impl DefaultIndexStore { } } + pub fn reinit(&self, op_id: &OperationId) { + let op_id_file = self.dir.join("operations").join(op_id.hex()); + std::fs::remove_file(op_id_file).unwrap(); + } + fn load_index_at_operation( &self, commit_id_length: usize, @@ -165,6 +170,10 @@ impl DefaultIndexStore { } impl IndexStore for DefaultIndexStore { + fn as_any(&self) -> &dyn Any { + self + } + fn name(&self) -> &str { "default" } diff --git a/lib/src/index.rs b/lib/src/index.rs index 8f953257f..79b45e6ad 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -32,6 +32,8 @@ pub enum IndexWriteError { } pub trait IndexStore: Send + Sync + Debug { + fn as_any(&self) -> &dyn Any; + fn name(&self) -> &str; fn get_index_at_op(&self, op: &Operation, store: &Arc) -> Box; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d8955998e..97f8fe428 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -30,7 +30,7 @@ use itertools::Itertools; use jujutsu_lib::backend::{CommitId, ObjectId, TreeValue}; use jujutsu_lib::commit::Commit; use jujutsu_lib::dag_walk::topo_order_reverse; -use jujutsu_lib::default_index_store::IndexEntry; +use jujutsu_lib::default_index_store::{DefaultIndexStore, IndexEntry}; use jujutsu_lib::matchers::EverythingMatcher; use jujutsu_lib::op_store::{RefTarget, WorkspaceId}; use jujutsu_lib::repo::{ReadonlyRepo, Repo}; @@ -3107,12 +3107,23 @@ fn cmd_debug( DebugCommands::ReIndex(_reindex_matches) => { let workspace_command = command.workspace_helper(ui)?; let repo = workspace_command.repo(); - let repo = repo.reload_at(repo.operation()); - writeln!( - ui, - "Finished indexing {:?} commits.", - repo.index().num_commits() - )?; + let default_index_store: Option<&DefaultIndexStore> = + repo.index_store().as_any().downcast_ref(); + if let Some(default_index_store) = default_index_store { + let op = repo.operation(); + default_index_store.reinit(op.id()); + let repo = repo.reload_at(op); + writeln!( + ui, + "Finished indexing {:?} commits.", + repo.index().num_commits() + )?; + } else { + return Err(user_error(format!( + "Cannot reindex indexes of type '{}'", + repo.index_store().name() + ))); + } } DebugCommands::Operation(operation_args) => { let workspace_command = command.workspace_helper(ui)?;