index: rename ReadonlyIndexWrapper to DefaultReadonlyIndex

This matches the store naming: impl IndexStore for DefaultIndexStore. I also
added minimal doc comment and Debug.
This commit is contained in:
Yuya Nishihara 2023-12-08 12:59:26 +09:00
parent cee69d1665
commit 6c57ba7f21
4 changed files with 21 additions and 18 deletions

View file

@ -18,7 +18,7 @@ use std::io::Write as _;
use clap::Subcommand; use clap::Subcommand;
use jj_lib::backend::ObjectId; use jj_lib::backend::ObjectId;
use jj_lib::default_index_store::{DefaultIndexStore, ReadonlyIndexWrapper}; use jj_lib::default_index_store::{DefaultIndexStore, DefaultReadonlyIndex};
use jj_lib::local_working_copy::LocalWorkingCopy; use jj_lib::local_working_copy::LocalWorkingCopy;
use jj_lib::revset; use jj_lib::revset;
use jj_lib::working_copy::WorkingCopy; use jj_lib::working_copy::WorkingCopy;
@ -199,9 +199,10 @@ fn cmd_debug_index(
) -> Result<(), CommandError> { ) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?; let workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo(); let repo = workspace_command.repo();
let index_impl: Option<&ReadonlyIndexWrapper> = repo.readonly_index().as_any().downcast_ref(); let default_index: Option<&DefaultReadonlyIndex> =
if let Some(index_impl) = index_impl { repo.readonly_index().as_any().downcast_ref();
let stats = index_impl.as_composite().stats(); if let Some(default_index) = default_index {
let stats = default_index.as_composite().stats();
writeln!(ui.stdout(), "Number of commits: {}", stats.num_commits)?; writeln!(ui.stdout(), "Number of commits: {}", stats.num_commits)?;
writeln!(ui.stdout(), "Number of merges: {}", stats.num_merges)?; writeln!(ui.stdout(), "Number of merges: {}", stats.num_merges)?;
writeln!( writeln!(
@ -238,15 +239,15 @@ fn cmd_debug_reindex(
if let Some(default_index_store) = default_index_store { if let Some(default_index_store) = default_index_store {
default_index_store.reinit(); default_index_store.reinit();
let repo = repo.reload_at(repo.operation())?; let repo = repo.reload_at(repo.operation())?;
let index_impl: &ReadonlyIndexWrapper = repo let default_index: &DefaultReadonlyIndex = repo
.readonly_index() .readonly_index()
.as_any() .as_any()
.downcast_ref() .downcast_ref()
.expect("Default index should be a ReadonlyIndexWrapper"); .expect("Default index should be a DefaultReadonlyIndex");
writeln!( writeln!(
ui.stderr(), ui.stderr(),
"Finished indexing {:?} commits.", "Finished indexing {:?} commits.",
index_impl.as_composite().stats().num_commits default_index.as_composite().stats().num_commits
)?; )?;
} else { } else {
return Err(user_error(format!( return Err(user_error(format!(

View file

@ -238,7 +238,7 @@ impl IndexStore for DefaultIndexStore {
} else { } else {
self.index_at_operation(store, op).unwrap() self.index_at_operation(store, op).unwrap()
}; };
Box::new(ReadonlyIndexWrapper(index_impl)) Box::new(DefaultReadonlyIndex(index_impl))
} }
fn write_index( fn write_index(
@ -259,7 +259,7 @@ impl IndexStore for DefaultIndexStore {
"Failed to associate commit index file with a operation {op_id:?}: {err}" "Failed to associate commit index file with a operation {op_id:?}: {err}"
)) ))
})?; })?;
Ok(Box::new(ReadonlyIndexWrapper(index))) Ok(Box::new(DefaultReadonlyIndex(index)))
} }
} }
@ -385,9 +385,11 @@ pub(crate) struct ReadonlyIndexImpl {
overflow_parent: Vec<u8>, overflow_parent: Vec<u8>,
} }
pub struct ReadonlyIndexWrapper(Arc<ReadonlyIndexImpl>); /// Commit index backend which stores data on local disk.
#[derive(Debug)]
pub struct DefaultReadonlyIndex(Arc<ReadonlyIndexImpl>);
impl ReadonlyIndex for ReadonlyIndexWrapper { impl ReadonlyIndex for DefaultReadonlyIndex {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
@ -410,7 +412,7 @@ impl Debug for ReadonlyIndexImpl {
} }
} }
impl ReadonlyIndexWrapper { impl DefaultReadonlyIndex {
pub fn as_composite(&self) -> CompositeIndex { pub fn as_composite(&self) -> CompositeIndex {
self.0.as_composite() self.0.as_composite()
} }
@ -704,8 +706,8 @@ impl MutableIndex for MutableIndexImpl {
fn merge_in(&mut self, other: &dyn ReadonlyIndex) { fn merge_in(&mut self, other: &dyn ReadonlyIndex) {
let other = other let other = other
.as_any() .as_any()
.downcast_ref::<ReadonlyIndexWrapper>() .downcast_ref::<DefaultReadonlyIndex>()
.expect("index to merge in must be a ReadonlyIndexWrapper"); .expect("index to merge in must be a DefaultReadonlyIndex");
let mut maybe_own_ancestor = self.parent_file.clone(); let mut maybe_own_ancestor = self.parent_file.clone();
let mut maybe_other_ancestor = Some(other.0.clone()); let mut maybe_other_ancestor = Some(other.0.clone());

View file

@ -14,7 +14,7 @@
use itertools::Itertools; use itertools::Itertools;
use jj_lib::commit::Commit; use jj_lib::commit::Commit;
use jj_lib::default_index_store::ReadonlyIndexWrapper; use jj_lib::default_index_store::DefaultReadonlyIndex;
use jj_lib::default_revset_engine::{evaluate, RevsetImpl}; use jj_lib::default_revset_engine::{evaluate, RevsetImpl};
use jj_lib::repo::{ReadonlyRepo, Repo as _}; use jj_lib::repo::{ReadonlyRepo, Repo as _};
use jj_lib::revset::ResolvedExpression; use jj_lib::revset::ResolvedExpression;
@ -29,7 +29,7 @@ fn revset_for_commits<'index>(
let index = repo let index = repo
.readonly_index() .readonly_index()
.as_any() .as_any()
.downcast_ref::<ReadonlyIndexWrapper>() .downcast_ref::<DefaultReadonlyIndex>()
.unwrap() .unwrap()
.as_composite(); .as_composite();
let expression = let expression =

View file

@ -18,7 +18,7 @@ use jj_lib::backend::CommitId;
use jj_lib::commit::Commit; use jj_lib::commit::Commit;
use jj_lib::commit_builder::CommitBuilder; use jj_lib::commit_builder::CommitBuilder;
use jj_lib::default_index_store::{ use jj_lib::default_index_store::{
CompositeIndex, IndexPosition, MutableIndexImpl, ReadonlyIndexWrapper, CompositeIndex, DefaultReadonlyIndex, IndexPosition, MutableIndexImpl,
}; };
use jj_lib::index::Index as _; use jj_lib::index::Index as _;
use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo}; use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo};
@ -446,7 +446,7 @@ fn create_n_commits(
fn as_readonly_composite(repo: &Arc<ReadonlyRepo>) -> CompositeIndex<'_> { fn as_readonly_composite(repo: &Arc<ReadonlyRepo>) -> CompositeIndex<'_> {
repo.readonly_index() repo.readonly_index()
.as_any() .as_any()
.downcast_ref::<ReadonlyIndexWrapper>() .downcast_ref::<DefaultReadonlyIndex>()
.unwrap() .unwrap()
.as_composite() .as_composite()
} }