mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +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>(
|
pub fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||||
&self,
|
|
||||||
candidates: impl IntoIterator<Item = &'candidates CommitId>,
|
|
||||||
) -> Vec<CommitId> {
|
|
||||||
match self {
|
match self {
|
||||||
IndexRef::Readonly(index) => index.heads(candidates),
|
IndexRef::Readonly(index) => index.heads(candidates),
|
||||||
IndexRef::Mutable(index) => index.heads(candidates),
|
IndexRef::Mutable(index) => index.heads(candidates),
|
||||||
|
@ -677,17 +674,11 @@ impl MutableIndex {
|
||||||
CompositeIndex(self).walk_revs(wanted, unwanted)
|
CompositeIndex(self).walk_revs(wanted, unwanted)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn heads<'candidates>(
|
pub fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||||
&self,
|
|
||||||
candidates: impl IntoIterator<Item = &'candidates CommitId>,
|
|
||||||
) -> Vec<CommitId> {
|
|
||||||
CompositeIndex(self).heads(candidates)
|
CompositeIndex(self).heads(candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn topo_order<'candidates>(
|
pub fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
|
||||||
&self,
|
|
||||||
input: impl IntoIterator<Item = &'candidates CommitId>,
|
|
||||||
) -> Vec<IndexEntry> {
|
|
||||||
CompositeIndex(self).topo_order(input)
|
CompositeIndex(self).topo_order(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -961,12 +952,8 @@ impl<'a> CompositeIndex<'a> {
|
||||||
rev_walk
|
rev_walk
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn heads<'candidates>(
|
pub fn heads(&self, candidate_ids: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||||
&self,
|
|
||||||
candidate_ids: impl IntoIterator<Item = &'candidates CommitId>,
|
|
||||||
) -> Vec<CommitId> {
|
|
||||||
let candidate_positions: BTreeSet<_> = candidate_ids
|
let candidate_positions: BTreeSet<_> = candidate_ids
|
||||||
.into_iter()
|
|
||||||
.map(|id| self.commit_id_to_pos(id).unwrap())
|
.map(|id| self.commit_id_to_pos(id).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -1012,10 +999,7 @@ impl<'a> CompositeIndex<'a> {
|
||||||
candidate_positions
|
candidate_positions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn topo_order<'input>(
|
pub fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry<'a>> {
|
||||||
&self,
|
|
||||||
input: impl IntoIterator<Item = &'input CommitId>,
|
|
||||||
) -> Vec<IndexEntry<'a>> {
|
|
||||||
let mut entries_by_generation = input
|
let mut entries_by_generation = input
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|id| IndexEntryByPosition(self.entry_by_id(id).unwrap()))
|
.map(|id| IndexEntryByPosition(self.entry_by_id(id).unwrap()))
|
||||||
|
@ -1662,17 +1646,11 @@ impl ReadonlyIndex {
|
||||||
CompositeIndex(self).walk_revs(wanted, unwanted)
|
CompositeIndex(self).walk_revs(wanted, unwanted)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn heads<'candidates>(
|
pub fn heads(&self, candidates: &mut dyn Iterator<Item = &CommitId>) -> Vec<CommitId> {
|
||||||
&self,
|
|
||||||
candidates: impl IntoIterator<Item = &'candidates CommitId>,
|
|
||||||
) -> Vec<CommitId> {
|
|
||||||
CompositeIndex(self).heads(candidates)
|
CompositeIndex(self).heads(candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn topo_order<'candidates>(
|
pub fn topo_order(&self, input: &mut dyn Iterator<Item = &CommitId>) -> Vec<IndexEntry> {
|
||||||
&self,
|
|
||||||
input: impl IntoIterator<Item = &'candidates CommitId>,
|
|
||||||
) -> Vec<IndexEntry> {
|
|
||||||
CompositeIndex(self).topo_order(input)
|
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()]);
|
index.add_commit_data(id_5.clone(), new_change_id(), &[id_4.clone(), id_2.clone()]);
|
||||||
|
|
||||||
// Empty input
|
// Empty input
|
||||||
assert!(index.heads(&[]).is_empty());
|
assert!(index.heads(&mut [].iter()).is_empty());
|
||||||
// Single head
|
// 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
|
// 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
|
// 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
|
// Multiple heads
|
||||||
assert_eq!(
|
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]
|
vec![id_3.clone(), id_4]
|
||||||
);
|
);
|
||||||
// Merge commit and ancestors
|
// 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
|
// 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]
|
#[test]
|
||||||
|
|
|
@ -829,14 +829,14 @@ impl MutableRepo {
|
||||||
let view = view.store_view_mut();
|
let view = view.store_view_mut();
|
||||||
view.public_head_ids = self
|
view.public_head_ids = self
|
||||||
.index
|
.index
|
||||||
.heads(view.public_head_ids.iter())
|
.heads(&mut view.public_head_ids.iter())
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
view.head_ids.extend(view.public_head_ids.iter().cloned());
|
view.head_ids.extend(view.public_head_ids.iter().cloned());
|
||||||
view.head_ids = self
|
view.head_ids = self
|
||||||
.index
|
.index
|
||||||
.heads(view.head_ids.iter())
|
.heads(&mut view.head_ids.iter())
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -2006,7 +2006,7 @@ pub fn evaluate_expression<'repo>(
|
||||||
let candidate_ids = candidate_set.iter().commit_ids().collect_vec();
|
let candidate_ids = candidate_set.iter().commit_ids().collect_vec();
|
||||||
Ok(revset_for_commit_ids(
|
Ok(revset_for_commit_ids(
|
||||||
repo,
|
repo,
|
||||||
&repo.index().heads(&candidate_ids),
|
&repo.index().heads(&mut candidate_ids.iter()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
RevsetExpression::Roots(candidates) => {
|
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()]);
|
new_parents.insert(old_commit, vec![new_commits.iter().next().unwrap().clone()]);
|
||||||
} else {
|
} else {
|
||||||
// The call to index.heads() is mostly to get a predictable order
|
// 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);
|
divergent.insert(old_commit, new_commits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ impl<'settings, 'repo> DescendantRebaser<'settings, 'repo> {
|
||||||
let head_set: HashSet<_> = self
|
let head_set: HashSet<_> = self
|
||||||
.mut_repo
|
.mut_repo
|
||||||
.index()
|
.index()
|
||||||
.heads(&new_parent_ids)
|
.heads(&mut new_parent_ids.iter())
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -1892,7 +1892,7 @@ fn cmd_duplicate(
|
||||||
let mut_repo = tx.mut_repo();
|
let mut_repo = tx.mut_repo();
|
||||||
|
|
||||||
for original_commit_id in index
|
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()
|
.into_iter()
|
||||||
.map(|index_entry| index_entry.commit_id())
|
.map(|index_entry| index_entry.commit_id())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue