Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revset: add 'static version of evaluate_revset(), forbid unsafe #2706

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/src/default_index/readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()))
}
Expand Down
8 changes: 8 additions & 0 deletions lib/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

yuja marked this conversation as resolved.
Show resolved Hide resolved
fn start_modification(&self) -> Box<dyn MutableIndex>;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/tests/test_default_revset_graph_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ 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()
.downcast_ref::<DefaultReadonlyIndex>()
.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 {
Expand Down