Skip to content

Commit

Permalink
index: impl Index for DefaultReadonlyIndex instead of ReadonlyIndexSe…
Browse files Browse the repository at this point in the history
…gment

The idea is that the ReadonlyIndexSegment is a sub component of the index. The
Index trait could be implemented for any Segment type, but we don't need a
public interface to access sub segment as an index.
  • Loading branch information
yuja committed Dec 8, 2023
1 parent 5db8e14 commit 132bb24
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/src/default_index_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl DefaultIndexStore {
let parent_file_has_id = |id: &CommitId| {
maybe_parent_file
.as_ref()
.map_or(false, |index| index.has_id(id))
.map_or(false, |segment| segment.as_composite().has_id(id))
};
let commits = dag_walk::topo_order_reverse_ord(
new_heads
Expand Down Expand Up @@ -395,7 +395,7 @@ impl ReadonlyIndex for DefaultReadonlyIndex {
}

fn as_index(&self) -> &dyn Index {
self.0.as_ref()
self
}

fn start_modification(&self) -> Box<dyn MutableIndex> {
Expand Down Expand Up @@ -1935,41 +1935,42 @@ impl ReadonlyIndexSegment {
}
}

impl Index for ReadonlyIndexSegment {
impl Index for DefaultReadonlyIndex {
fn shortest_unique_commit_id_prefix_len(&self, commit_id: &CommitId) -> usize {
CompositeIndex(self).shortest_unique_commit_id_prefix_len(commit_id)
self.as_composite()
.shortest_unique_commit_id_prefix_len(commit_id)
}

fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
CompositeIndex(self).resolve_prefix(prefix)
self.as_composite().resolve_prefix(prefix)
}

fn has_id(&self, commit_id: &CommitId) -> bool {
CompositeIndex(self).has_id(commit_id)
self.as_composite().has_id(commit_id)
}

fn is_ancestor(&self, ancestor_id: &CommitId, descendant_id: &CommitId) -> bool {
CompositeIndex(self).is_ancestor(ancestor_id, descendant_id)
self.as_composite().is_ancestor(ancestor_id, descendant_id)
}

fn common_ancestors(&self, set1: &[CommitId], set2: &[CommitId]) -> Vec<CommitId> {
CompositeIndex(self).common_ancestors(set1, set2)
self.as_composite().common_ancestors(set1, set2)
}

fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
CompositeIndex(self).heads(candidates)
self.as_composite().heads(candidates)
}

fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
CompositeIndex(self).topo_order(input)
self.as_composite().topo_order(input)
}

fn evaluate_revset<'index>(
&'index self,
expression: &ResolvedExpression,
store: &Arc<Store>,
) -> Result<Box<dyn Revset<'index> + 'index>, RevsetEvaluationError> {
CompositeIndex(self).evaluate_revset(expression, store)
self.as_composite().evaluate_revset(expression, store)
}
}

Expand Down

0 comments on commit 132bb24

Please sign in to comment.