forked from mirrors/jj
index: specialize evaluate_revset_static() to change_id_index_static()
I'd like to move `change_id_index()` from `Revset` to `Index` (and make it take the set of visible heads as argument). We currently use `evaluate_revset_static()` only to get a `ChangeIdIndex`, so a good place to start is to convert that into `change_id_index_static()`.
This commit is contained in:
parent
b549090acc
commit
f9dc00704d
4 changed files with 30 additions and 21 deletions
|
@ -396,6 +396,23 @@ pub(super) struct ChangeIdIndexImpl<I> {
|
|||
pub pos_by_change: IdIndex<ChangeId, IndexPosition, 4>,
|
||||
}
|
||||
|
||||
impl<I: AsCompositeIndex> ChangeIdIndexImpl<I> {
|
||||
pub fn new(index: I, heads: &mut dyn Iterator<Item = &CommitId>) -> ChangeIdIndexImpl<I> {
|
||||
let mut pos_by_change = IdIndex::builder();
|
||||
let composite = index.as_composite();
|
||||
let head_positions = heads
|
||||
.map(|id| composite.commit_id_to_pos(id).unwrap())
|
||||
.collect_vec();
|
||||
for entry in composite.walk_revs(&head_positions, &[]) {
|
||||
pos_by_change.insert(&entry.change_id(), entry.position());
|
||||
}
|
||||
Self {
|
||||
index,
|
||||
pos_by_change: pos_by_change.build(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: AsCompositeIndex + Send + Sync> ChangeIdIndex for ChangeIdIndexImpl<I> {
|
||||
fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<Vec<CommitId>> {
|
||||
self.pos_by_change
|
||||
|
|
|
@ -26,12 +26,11 @@ use std::sync::Arc;
|
|||
use smallvec::SmallVec;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::composite::{AsCompositeIndex, CompositeIndex, IndexSegment};
|
||||
use super::composite::{AsCompositeIndex, ChangeIdIndexImpl, CompositeIndex, IndexSegment};
|
||||
use super::entry::{IndexPosition, LocalPosition, SmallIndexPositionsVec};
|
||||
use super::mutable::DefaultMutableIndex;
|
||||
use super::revset_engine;
|
||||
use crate::backend::{ChangeId, CommitId};
|
||||
use crate::index::{Index, MutableIndex, ReadonlyIndex};
|
||||
use crate::index::{ChangeIdIndex, Index, MutableIndex, ReadonlyIndex};
|
||||
use crate::object_id::{HexPrefix, ObjectId, PrefixResolution};
|
||||
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
||||
use crate::store::Store;
|
||||
|
@ -528,13 +527,11 @@ impl ReadonlyIndex for DefaultReadonlyIndex {
|
|||
self
|
||||
}
|
||||
|
||||
fn evaluate_revset_static(
|
||||
fn change_id_index_static(
|
||||
&self,
|
||||
expression: &ResolvedExpression,
|
||||
store: &Arc<Store>,
|
||||
) -> Result<Box<dyn Revset<'static>>, RevsetEvaluationError> {
|
||||
let revset_impl = revset_engine::evaluate(expression, store, self.clone())?;
|
||||
Ok(Box::new(revset_impl))
|
||||
heads: &mut dyn Iterator<Item = &CommitId>,
|
||||
) -> Box<dyn ChangeIdIndex> {
|
||||
Box::new(ChangeIdIndexImpl::new(self.clone(), heads))
|
||||
}
|
||||
|
||||
fn start_modification(&self) -> Box<dyn MutableIndex> {
|
||||
|
|
|
@ -84,13 +84,12 @@ 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(
|
||||
// TODO: might be better to split Index::change_id_index() to
|
||||
// Readonly/MutableIndex::change_id_index_static().
|
||||
fn change_id_index_static(
|
||||
&self,
|
||||
expression: &ResolvedExpression,
|
||||
store: &Arc<Store>,
|
||||
) -> Result<Box<dyn Revset<'static>>, RevsetEvaluationError>;
|
||||
heads: &mut dyn Iterator<Item = &CommitId>,
|
||||
) -> Box<dyn ChangeIdIndex>;
|
||||
|
||||
fn start_modification(&self) -> Box<dyn MutableIndex>;
|
||||
}
|
||||
|
|
|
@ -268,12 +268,8 @@ impl ReadonlyRepo {
|
|||
.get_or_init(|| {
|
||||
// TODO: maybe add abstraction over 'static/'index revset
|
||||
// evaluation, and use it.
|
||||
let expression = RevsetExpression::all().resolve_programmatic(self);
|
||||
let revset = self
|
||||
.readonly_index()
|
||||
.evaluate_revset_static(&expression, self.store())
|
||||
.unwrap();
|
||||
revset.change_id_index()
|
||||
self.readonly_index()
|
||||
.change_id_index_static(&mut self.view().heads().iter())
|
||||
})
|
||||
.as_ref()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue