mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-10 05:44:29 +03:00
index: make jj debug reindex
actually reindex
I broke `jj debug reindex` in a27da7d8d5
. From that commit, we no
longer delete the pointer to the old index, so nothing happens when we
reload the index. This commit fixes that, and also makes the command
error out if run on a repo with a non-default index type.
This commit is contained in:
parent
ff1b6ce3d1
commit
63b3c0899a
@ -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"
|
||||
}
|
||||
|
@ -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<Store>) -> Box<dyn ReadonlyIndex>;
|
||||
|
@ -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)?;
|
||||
|
Loading…
Reference in New Issue
Block a user