mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-28 15:34:22 +00:00
index: remove lifetime parameter to IndexRef::heads()/topo_order()
I want to replace `IndexRef` by a trait, and I want that trait to be object-safe.
This commit is contained in:
parent
a474c688a8
commit
7a985ed122
5 changed files with 32 additions and 42 deletions
|
@ -141,10 +141,7 @@ impl<'a> IndexRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn heads<'candidates>(
|
||||
&self,
|
||||
candidates: impl IntoIterator<Item = &'candidates CommitId>,
|
||||
) -> Vec<CommitId> {
|
||||
pub fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||
match self {
|
||||
IndexRef::Readonly(index) => index.heads(candidates),
|
||||
IndexRef::Mutable(index) => index.heads(candidates),
|
||||
|
@ -677,17 +674,11 @@ impl MutableIndex {
|
|||
CompositeIndex(self).walk_revs(wanted, unwanted)
|
||||
}
|
||||
|
||||
pub fn heads<'candidates>(
|
||||
&self,
|
||||
candidates: impl IntoIterator<Item = &'candidates CommitId>,
|
||||
) -> Vec<CommitId> {
|
||||
pub fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||
CompositeIndex(self).heads(candidates)
|
||||
}
|
||||
|
||||
pub fn topo_order<'candidates>(
|
||||
&self,
|
||||
input: impl IntoIterator<Item = &'candidates CommitId>,
|
||||
) -> Vec<IndexEntry> {
|
||||
pub fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
|
||||
CompositeIndex(self).topo_order(input)
|
||||
}
|
||||
}
|
||||
|
@ -961,12 +952,8 @@ impl<'a> CompositeIndex<'a> {
|
|||
rev_walk
|
||||
}
|
||||
|
||||
pub fn heads<'candidates>(
|
||||
&self,
|
||||
candidate_ids: impl IntoIterator<Item = &'candidates CommitId>,
|
||||
) -> Vec<CommitId> {
|
||||
pub fn heads(&self, candidate_ids: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||
let candidate_positions: BTreeSet<_> = candidate_ids
|
||||
.into_iter()
|
||||
.map(|id| self.commit_id_to_pos(id).unwrap())
|
||||
.collect();
|
||||
|
||||
|
@ -1012,10 +999,7 @@ impl<'a> CompositeIndex<'a> {
|
|||
candidate_positions
|
||||
}
|
||||
|
||||
pub fn topo_order<'input>(
|
||||
&self,
|
||||
input: impl IntoIterator<Item = &'input CommitId>,
|
||||
) -> Vec<IndexEntry<'a>> {
|
||||
pub fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry<'a>> {
|
||||
let mut entries_by_generation = input
|
||||
.into_iter()
|
||||
.map(|id| IndexEntryByPosition(self.entry_by_id(id).unwrap()))
|
||||
|
@ -1662,17 +1646,11 @@ impl ReadonlyIndex {
|
|||
CompositeIndex(self).walk_revs(wanted, unwanted)
|
||||
}
|
||||
|
||||
pub fn heads<'candidates>(
|
||||
&self,
|
||||
candidates: impl IntoIterator<Item = &'candidates CommitId>,
|
||||
) -> Vec<CommitId> {
|
||||
pub fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||
CompositeIndex(self).heads(candidates)
|
||||
}
|
||||
|
||||
pub fn topo_order<'candidates>(
|
||||
&self,
|
||||
input: impl IntoIterator<Item = &'candidates CommitId>,
|
||||
) -> Vec<IndexEntry> {
|
||||
pub fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
|
||||
CompositeIndex(self).topo_order(input)
|
||||
}
|
||||
|
||||
|
@ -2586,22 +2564,34 @@ mod tests {
|
|||
index.add_commit_data(id_5.clone(), new_change_id(), &[id_4.clone(), id_2.clone()]);
|
||||
|
||||
// Empty input
|
||||
assert!(index.heads(&[]).is_empty());
|
||||
assert!(index.heads(&mut [].iter()).is_empty());
|
||||
// Single head
|
||||
assert_eq!(index.heads(&[id_4.clone()]), vec![id_4.clone()]);
|
||||
assert_eq!(index.heads(&mut [id_4.clone()].iter()), vec![id_4.clone()]);
|
||||
// Single head and parent
|
||||
assert_eq!(index.heads(&[id_4.clone(), id_1]), vec![id_4.clone()]);
|
||||
assert_eq!(
|
||||
index.heads(&mut [id_4.clone(), id_1].iter()),
|
||||
vec![id_4.clone()]
|
||||
);
|
||||
// Single head and grand-parent
|
||||
assert_eq!(index.heads(&[id_4.clone(), id_0]), vec![id_4.clone()]);
|
||||
assert_eq!(
|
||||
index.heads(&mut [id_4.clone(), id_0].iter()),
|
||||
vec![id_4.clone()]
|
||||
);
|
||||
// Multiple heads
|
||||
assert_eq!(
|
||||
index.heads(&[id_4.clone(), id_3.clone()]),
|
||||
index.heads(&mut [id_4.clone(), id_3.clone()].iter()),
|
||||
vec![id_3.clone(), id_4]
|
||||
);
|
||||
// Merge commit and ancestors
|
||||
assert_eq!(index.heads(&[id_5.clone(), id_2]), vec![id_5.clone()]);
|
||||
assert_eq!(
|
||||
index.heads(&mut [id_5.clone(), id_2].iter()),
|
||||
vec![id_5.clone()]
|
||||
);
|
||||
// Merge commit and other commit
|
||||
assert_eq!(index.heads(&[id_5.clone(), id_3.clone()]), vec![id_3, id_5]);
|
||||
assert_eq!(
|
||||
index.heads(&mut [id_5.clone(), id_3.clone()].iter()),
|
||||
vec![id_3, id_5]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -829,14 +829,14 @@ impl MutableRepo {
|
|||
let view = view.store_view_mut();
|
||||
view.public_head_ids = self
|
||||
.index
|
||||
.heads(view.public_head_ids.iter())
|
||||
.heads(&mut view.public_head_ids.iter())
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
view.head_ids.extend(view.public_head_ids.iter().cloned());
|
||||
view.head_ids = self
|
||||
.index
|
||||
.heads(view.head_ids.iter())
|
||||
.heads(&mut view.head_ids.iter())
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
|
|
|
@ -2006,7 +2006,7 @@ pub fn evaluate_expression<'repo>(
|
|||
let candidate_ids = candidate_set.iter().commit_ids().collect_vec();
|
||||
Ok(revset_for_commit_ids(
|
||||
repo,
|
||||
&repo.index().heads(&candidate_ids),
|
||||
&repo.index().heads(&mut candidate_ids.iter()),
|
||||
))
|
||||
}
|
||||
RevsetExpression::Roots(candidates) => {
|
||||
|
|
|
@ -209,7 +209,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
|
|||
new_parents.insert(old_commit, vec![new_commits.iter().next().unwrap().clone()]);
|
||||
} else {
|
||||
// The call to index.heads() is mostly to get a predictable order
|
||||
let new_commits = mut_repo.index().heads(&new_commits);
|
||||
let new_commits = mut_repo.index().heads(&mut new_commits.iter());
|
||||
divergent.insert(old_commit, new_commits);
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
|
|||
let head_set: HashSet<_> = self
|
||||
.mut_repo
|
||||
.index()
|
||||
.heads(&new_parent_ids)
|
||||
.heads(&mut new_parent_ids.iter())
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
|
|
|
@ -1892,7 +1892,7 @@ fn cmd_duplicate(
|
|||
let mut_repo = tx.mut_repo();
|
||||
|
||||
for original_commit_id in index
|
||||
.topo_order(to_duplicate.iter().map(|c| c.id()))
|
||||
.topo_order(&mut to_duplicate.iter().map(|c| c.id()))
|
||||
.into_iter()
|
||||
.map(|index_entry| index_entry.commit_id())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue