diff --git a/lib/src/index.rs b/lib/src/index.rs index 4609e1ece..5ec307383 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -141,10 +141,7 @@ impl<'a> IndexRef<'a> { } } - pub fn heads<'candidates>( - &self, - candidates: impl IntoIterator, - ) -> Vec { + pub fn heads(&self, candidates: &mut dyn Iterator) -> Vec { 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, - ) -> Vec { + pub fn heads(&self, candidates: &mut dyn Iterator) -> Vec { CompositeIndex(self).heads(candidates) } - pub fn topo_order<'candidates>( - &self, - input: impl IntoIterator, - ) -> Vec { + pub fn topo_order(&self, input: &mut dyn Iterator) -> Vec { CompositeIndex(self).topo_order(input) } } @@ -961,12 +952,8 @@ impl<'a> CompositeIndex<'a> { rev_walk } - pub fn heads<'candidates>( - &self, - candidate_ids: impl IntoIterator, - ) -> Vec { + pub fn heads(&self, candidate_ids: &mut dyn Iterator) -> Vec { 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, - ) -> Vec> { + pub fn topo_order(&self, input: &mut dyn Iterator) -> Vec> { 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, - ) -> Vec { + pub fn heads(&self, candidates: &mut dyn Iterator) -> Vec { CompositeIndex(self).heads(candidates) } - pub fn topo_order<'candidates>( - &self, - input: impl IntoIterator, - ) -> Vec { + pub fn topo_order(&self, input: &mut dyn Iterator) -> Vec { 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] diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 4db653688..ff534edf1 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -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(); diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 6c4ea0cf1..bfcc41be3 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -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) => { diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index b30809f97..90a484eb3 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -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(); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 87cea3ecb..e602c9c8b 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -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()) {