revset: move evaluation into index

This commit adds an `evaluate_revset()` function to the `Index`
trait. It will require some further cleanup, but it already achieves
the goal of letting the index implementation decide which revset
engine to use.
This commit is contained in:
Martin von Zweigbergk 2023-03-12 23:00:02 -07:00 committed by Martin von Zweigbergk
parent eed0b23009
commit 28cbd7b1c5
3 changed files with 35 additions and 3 deletions

View File

@ -44,8 +44,10 @@ use crate::index::{
use crate::nightly_shims::BTreeSetExt;
use crate::op_store::OperationId;
use crate::operation::Operation;
use crate::repo::Repo;
use crate::revset::{Revset, RevsetError, RevsetExpression, RevsetWorkspaceContext};
use crate::store::Store;
use crate::{backend, dag_walk};
use crate::{backend, dag_walk, default_revset_engine};
#[derive(Debug)]
pub struct DefaultIndexStore {
@ -733,6 +735,15 @@ impl Index for MutableIndexImpl {
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
CompositeIndex(self).topo_order(input)
}
fn evaluate_revset<'index>(
&'index self,
repo: &'index dyn Repo,
expression: &RevsetExpression,
workspace_ctx: Option<&RevsetWorkspaceContext>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetError> {
default_revset_engine::evaluate(repo, expression, workspace_ctx)
}
}
impl MutableIndex for MutableIndexImpl {
@ -1806,6 +1817,15 @@ impl Index for ReadonlyIndexImpl {
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
CompositeIndex(self).topo_order(input)
}
fn evaluate_revset<'index>(
&'index self,
repo: &'index dyn Repo,
expression: &RevsetExpression,
workspace_ctx: Option<&RevsetWorkspaceContext>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetError> {
default_revset_engine::evaluate(repo, expression, workspace_ctx)
}
}
#[cfg(test)]

View File

@ -23,6 +23,8 @@ use crate::commit::Commit;
use crate::default_index_store::{IndexEntry, IndexPosition, RevWalk};
use crate::op_store::OperationId;
use crate::operation::Operation;
use crate::repo::Repo;
use crate::revset::{Revset, RevsetError, RevsetExpression, RevsetWorkspaceContext};
use crate::store::Store;
#[derive(Debug, Error)]
@ -70,6 +72,17 @@ pub trait Index {
/// Parents before children
fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry>;
// TODO: It's weird that we pass in the repo here since the repo is a
// higher-level concept. We should probably pass in the view and store
// instead, or maybe we should resolve symbols in the expression before we
// get here.
fn evaluate_revset<'index>(
&'index self,
repo: &'index dyn Repo,
expression: &RevsetExpression,
workspace_ctx: Option<&RevsetWorkspaceContext>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetError>;
}
pub trait ReadonlyIndex: Send + Sync {

View File

@ -30,7 +30,6 @@ use thiserror::Error;
use crate::backend::{BackendError, BackendResult, CommitId};
use crate::commit::Commit;
use crate::default_index_store::IndexEntry;
use crate::default_revset_engine;
use crate::op_store::WorkspaceId;
use crate::repo::Repo;
use crate::repo_path::{FsPathParseError, RepoPath};
@ -394,7 +393,7 @@ impl RevsetExpression {
repo: &'index dyn Repo,
workspace_ctx: Option<&RevsetWorkspaceContext>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetError> {
default_revset_engine::evaluate(repo, self, workspace_ctx)
repo.index().evaluate_revset(repo, self, workspace_ctx)
}
}