mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
index: remove entry_by_id() from trait
It no longer needs to be on the `Index` trait, thereby removing the last direct use of `IndexEntry` in the trait (it's still used indirectly in `walk_revs()`).
This commit is contained in:
parent
831c45539e
commit
c60f14899a
4 changed files with 13 additions and 16 deletions
|
@ -493,6 +493,10 @@ impl MutableIndexImpl {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn as_composite(&self) -> CompositeIndex {
|
||||
CompositeIndex(self)
|
||||
}
|
||||
|
||||
pub(crate) fn add_commit_data(
|
||||
&mut self,
|
||||
commit_id: CommitId,
|
||||
|
@ -509,7 +513,7 @@ impl MutableIndexImpl {
|
|||
parent_positions: vec![],
|
||||
};
|
||||
for parent_id in parent_ids {
|
||||
let parent_entry = self
|
||||
let parent_entry = CompositeIndex(self)
|
||||
.entry_by_id(parent_id)
|
||||
.expect("parent commit is not indexed");
|
||||
entry.generation_number = max(
|
||||
|
@ -699,10 +703,6 @@ impl Index for MutableIndexImpl {
|
|||
CompositeIndex(self).resolve_prefix(prefix)
|
||||
}
|
||||
|
||||
fn entry_by_id(&self, commit_id: &CommitId) -> Option<IndexEntry> {
|
||||
CompositeIndex(self).entry_by_id(commit_id)
|
||||
}
|
||||
|
||||
fn has_id(&self, commit_id: &CommitId) -> bool {
|
||||
CompositeIndex(self).has_id(commit_id)
|
||||
}
|
||||
|
@ -953,7 +953,7 @@ impl<'a> CompositeIndex<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn entry_by_id(&self, commit_id: &CommitId) -> Option<IndexEntry<'a>> {
|
||||
pub fn entry_by_id(&self, commit_id: &CommitId) -> Option<IndexEntry<'a>> {
|
||||
self.commit_id_to_pos(commit_id)
|
||||
.map(|pos| self.entry_by_pos(pos))
|
||||
}
|
||||
|
@ -1781,10 +1781,6 @@ impl Index for ReadonlyIndexImpl {
|
|||
CompositeIndex(self).resolve_prefix(prefix)
|
||||
}
|
||||
|
||||
fn entry_by_id(&self, commit_id: &CommitId) -> Option<IndexEntry> {
|
||||
CompositeIndex(self).entry_by_id(commit_id)
|
||||
}
|
||||
|
||||
fn has_id(&self, commit_id: &CommitId) -> bool {
|
||||
CompositeIndex(self).has_id(commit_id)
|
||||
}
|
||||
|
|
|
@ -944,7 +944,6 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::backend::{ChangeId, CommitId, ObjectId};
|
||||
use crate::default_index_store::MutableIndexImpl;
|
||||
use crate::index::Index;
|
||||
|
||||
#[test]
|
||||
fn test_id_index_resolve_prefix() {
|
||||
|
@ -1073,7 +1072,7 @@ mod tests {
|
|||
index.add_commit_data(id_3.clone(), new_change_id(), &[id_2.clone()]);
|
||||
index.add_commit_data(id_4.clone(), new_change_id(), &[id_3.clone()]);
|
||||
|
||||
let get_entry = |id: &CommitId| index.entry_by_id(id).unwrap();
|
||||
let get_entry = |id: &CommitId| index.as_composite().entry_by_id(id).unwrap();
|
||||
let make_entries = |ids: &[&CommitId]| ids.iter().map(|id| get_entry(id)).collect_vec();
|
||||
let make_set = |ids: &[&CommitId]| -> Box<dyn InternalRevset> {
|
||||
let index_entries = make_entries(ids);
|
||||
|
|
|
@ -20,7 +20,7 @@ use thiserror::Error;
|
|||
|
||||
use crate::backend::{CommitId, ObjectId};
|
||||
use crate::commit::Commit;
|
||||
use crate::default_index_store::{IndexEntry, RevWalk};
|
||||
use crate::default_index_store::RevWalk;
|
||||
use crate::op_store::OperationId;
|
||||
use crate::operation::Operation;
|
||||
use crate::revset::{ResolvedExpression, Revset, RevsetEvaluationError};
|
||||
|
@ -53,8 +53,6 @@ pub trait Index: Send + Sync {
|
|||
|
||||
fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId>;
|
||||
|
||||
fn entry_by_id(&self, commit_id: &CommitId) -> Option<IndexEntry>;
|
||||
|
||||
fn has_id(&self, commit_id: &CommitId) -> bool;
|
||||
|
||||
fn is_ancestor(&self, ancestor_id: &CommitId, descendant_id: &CommitId) -> bool;
|
||||
|
|
|
@ -36,7 +36,11 @@ fn child_commit<'repo>(
|
|||
|
||||
// Helper just to reduce line wrapping
|
||||
fn generation_number(index: &ReadonlyIndexImpl, commit_id: &CommitId) -> u32 {
|
||||
index.entry_by_id(commit_id).unwrap().generation_number()
|
||||
index
|
||||
.as_composite()
|
||||
.entry_by_id(commit_id)
|
||||
.unwrap()
|
||||
.generation_number()
|
||||
}
|
||||
|
||||
#[test_case(false ; "local backend")]
|
||||
|
|
Loading…
Reference in a new issue