index: obtain CompositeIndex from ReadonlyIndexWrapper

I'll remove Index::as_any() so that Index can be implemented for reference
wrapper.
This commit is contained in:
Yuya Nishihara 2023-05-26 15:38:57 +09:00
parent fb77c55268
commit 93284a153f
2 changed files with 20 additions and 11 deletions

View file

@ -14,22 +14,32 @@
use itertools::Itertools;
use jujutsu_lib::commit::Commit;
use jujutsu_lib::default_index_store::ReadonlyIndexImpl;
use jujutsu_lib::default_index_store::ReadonlyIndexWrapper;
use jujutsu_lib::default_revset_engine::{evaluate, RevsetImpl};
use jujutsu_lib::repo::Repo;
use jujutsu_lib::index::ReadonlyIndex as _;
use jujutsu_lib::repo::{ReadonlyRepo, Repo as _};
use jujutsu_lib::revset::{ResolvedExpression, RevsetGraphEdge};
use test_case::test_case;
use testutils::{CommitGraphBuilder, TestRepo};
fn revset_for_commits<'index>(repo: &'index dyn Repo, commits: &[&Commit]) -> RevsetImpl<'index> {
fn revset_for_commits<'index>(
repo: &'index ReadonlyRepo,
commits: &[&Commit],
) -> RevsetImpl<'index> {
let index = repo
.index()
.readonly_index()
.as_any()
.downcast_ref::<ReadonlyIndexImpl>()
.downcast_ref::<ReadonlyIndexWrapper>()
.unwrap();
let expression =
ResolvedExpression::Commits(commits.iter().map(|commit| commit.id().clone()).collect());
evaluate(&expression, repo.store(), index, index.as_composite()).unwrap()
evaluate(
&expression,
repo.store(),
index.as_index(),
index.as_composite(),
)
.unwrap()
}
fn direct(commit: &Commit) -> RevsetGraphEdge {

View file

@ -17,7 +17,7 @@ use std::sync::Arc;
use jujutsu_lib::backend::CommitId;
use jujutsu_lib::commit::Commit;
use jujutsu_lib::commit_builder::CommitBuilder;
use jujutsu_lib::default_index_store::{CompositeIndex, MutableIndexImpl, ReadonlyIndexImpl};
use jujutsu_lib::default_index_store::{CompositeIndex, MutableIndexImpl, ReadonlyIndexWrapper};
use jujutsu_lib::repo::{MutableRepo, ReadonlyRepo, Repo};
use jujutsu_lib::settings::UserSettings;
use test_case::test_case;
@ -445,16 +445,15 @@ fn create_n_commits(
tx.commit()
}
fn as_readonly_impl(repo: &Arc<ReadonlyRepo>) -> &ReadonlyIndexImpl {
fn as_readonly_wrapper(repo: &Arc<ReadonlyRepo>) -> &ReadonlyIndexWrapper {
repo.readonly_index()
.as_index()
.as_any()
.downcast_ref::<ReadonlyIndexImpl>()
.downcast_ref::<ReadonlyIndexWrapper>()
.unwrap()
}
fn as_readonly_composite(repo: &Arc<ReadonlyRepo>) -> CompositeIndex<'_> {
as_readonly_impl(repo).as_composite()
as_readonly_wrapper(repo).as_composite()
}
fn as_mutable_impl(repo: &MutableRepo) -> &MutableIndexImpl {