forked from mirrors/jj
index: add 'static version of evaluate_revset() to ReadonlyIndex
We'll probably need a better abstraction, but a separate method is good enough to remove unsafe code from ReadonlyRepo. I'm not sure if this is feasible for the other backends, but I guess there would be less lifetimed variables than DefaultReadonlyIndex.
This commit is contained in:
parent
2ba50c76c7
commit
d9e8297059
3 changed files with 23 additions and 5 deletions
|
@ -30,6 +30,7 @@ use super::entry::{IndexEntry, IndexPosition, SmallIndexPositionsVec};
|
|||
use super::mutable::DefaultMutableIndex;
|
||||
use super::store::IndexLoadError;
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::default_revset_engine;
|
||||
use crate::index::{HexPrefix, Index, MutableIndex, PrefixResolution, ReadonlyIndex};
|
||||
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
||||
use crate::store::Store;
|
||||
|
@ -373,7 +374,7 @@ impl IndexSegment for ReadonlyIndexSegment {
|
|||
}
|
||||
|
||||
/// Commit index backend which stores data on local disk.
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DefaultReadonlyIndex(Arc<ReadonlyIndexSegment>);
|
||||
|
||||
impl DefaultReadonlyIndex {
|
||||
|
@ -440,6 +441,15 @@ impl ReadonlyIndex for DefaultReadonlyIndex {
|
|||
self
|
||||
}
|
||||
|
||||
fn evaluate_revset_static(
|
||||
&self,
|
||||
expression: &ResolvedExpression,
|
||||
store: &Arc<Store>,
|
||||
) -> Result<Box<dyn Revset<'static>>, RevsetEvaluationError> {
|
||||
let revset_impl = default_revset_engine::evaluate(expression, store, self.clone())?;
|
||||
Ok(Box::new(revset_impl))
|
||||
}
|
||||
|
||||
fn start_modification(&self) -> Box<dyn MutableIndex> {
|
||||
Box::new(DefaultMutableIndex::incremental(self.0.clone()))
|
||||
}
|
||||
|
|
|
@ -75,6 +75,14 @@ pub trait ReadonlyIndex: Send + Sync {
|
|||
|
||||
fn as_index(&self) -> &dyn Index;
|
||||
|
||||
// TODO: might be better to split Index::evaluate_revset() to
|
||||
// Readonly/MutableIndex::evaluate_static().
|
||||
fn evaluate_revset_static(
|
||||
&self,
|
||||
expression: &ResolvedExpression,
|
||||
store: &Arc<Store>,
|
||||
) -> Result<Box<dyn Revset<'static>>, RevsetEvaluationError>;
|
||||
|
||||
fn start_modification(&self) -> Box<dyn MutableIndex>;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,10 @@ use jj_lib::revset_graph::RevsetGraphEdge;
|
|||
use test_case::test_case;
|
||||
use testutils::{CommitGraphBuilder, TestRepo};
|
||||
|
||||
fn revset_for_commits<'index>(
|
||||
repo: &'index ReadonlyRepo,
|
||||
fn revset_for_commits(
|
||||
repo: &ReadonlyRepo,
|
||||
commits: &[&Commit],
|
||||
) -> RevsetImpl<&'index DefaultReadonlyIndex> {
|
||||
) -> RevsetImpl<DefaultReadonlyIndex> {
|
||||
let index = repo
|
||||
.readonly_index()
|
||||
.as_any()
|
||||
|
@ -33,7 +33,7 @@ fn revset_for_commits<'index>(
|
|||
.unwrap();
|
||||
let expression =
|
||||
ResolvedExpression::Commits(commits.iter().map(|commit| commit.id().clone()).collect());
|
||||
evaluate(&expression, repo.store(), index).unwrap()
|
||||
evaluate(&expression, repo.store(), index.clone()).unwrap()
|
||||
}
|
||||
|
||||
fn direct(commit: &Commit) -> RevsetGraphEdge {
|
||||
|
|
Loading…
Reference in a new issue