diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index 7f12a721ac..6a17ebbf0c 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -17,10 +17,10 @@ use std::cell::RefCell; use std::cmp::{Ordering, Reverse}; use std::collections::{BTreeSet, BinaryHeap, HashSet}; -use std::fmt; use std::ops::Range; use std::rc::Rc; use std::sync::Arc; +use std::{fmt, iter}; use itertools::Itertools; @@ -119,15 +119,31 @@ impl fmt::Debug for RevsetImpl { } impl Revset for RevsetImpl { - fn iter(&self) -> Box + '_> { - Box::new(self.entries().map(|index_entry| index_entry.commit_id())) + fn iter<'a>(&self) -> Box + 'a> + where + Self: 'a, + { + let index = self.index.clone(); + let mut walk = self.inner.positions(); + Box::new(iter::from_fn(move || { + let index = index.as_composite(); + let pos = walk.next(index)?; + Some(index.entry_by_pos(pos).commit_id()) + })) } - fn commit_change_ids(&self) -> Box + '_> { - Box::new( - self.entries() - .map(|index_entry| (index_entry.commit_id(), index_entry.change_id())), - ) + fn commit_change_ids<'a>(&self) -> Box + 'a> + where + Self: 'a, + { + let index = self.index.clone(); + let mut walk = self.inner.positions(); + Box::new(iter::from_fn(move || { + let index = index.as_composite(); + let pos = walk.next(index)?; + let entry = index.entry_by_pos(pos); + Some((entry.commit_id(), entry.change_id())) + })) } fn iter_graph(&self) -> Box)> + '_> { diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 416d985fb5..f653850253 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -2401,10 +2401,14 @@ impl VisibilityResolutionContext<'_> { pub trait Revset: fmt::Debug { /// Iterate in topological order with children before parents. - fn iter(&self) -> Box + '_>; + fn iter<'a>(&self) -> Box + 'a> + where + Self: 'a; /// Iterates commit/change id pairs in topological order. - fn commit_change_ids(&self) -> Box + '_>; + fn commit_change_ids<'a>(&self) -> Box + 'a> + where + Self: 'a; fn iter_graph(&self) -> Box)> + '_>;