diff --git a/lib/src/graph.rs b/lib/src/graph.rs index 18362a6259..4e2282a8c7 100644 --- a/lib/src/graph.rs +++ b/lib/src/graph.rs @@ -75,7 +75,7 @@ fn reachable_targets(edges: &[GraphEdge]) -> impl DoubleEndedIterator { - items: Vec>, + items: std::vec::IntoIter>, } impl ReverseGraphIterator @@ -85,7 +85,7 @@ where pub fn new( input: impl Iterator, RevsetEvaluationError>>, ) -> Result { - let items = reverse_graph(input)?; + let items = reverse_graph(input)?.into_iter(); Ok(Self { items }) } } @@ -94,11 +94,11 @@ impl Iterator for ReverseGraphIterator { type Item = Result, RevsetEvaluationError>; fn next(&mut self) -> Option { - self.items.pop().map(Ok) + self.items.next().map(Ok) } } -/// Creates new graph in which edges are reversed. +/// Creates new graph in which nodes and edges are reversed. fn reverse_graph( input: impl Iterator, E>>, ) -> Result>, E> { @@ -116,7 +116,7 @@ fn reverse_graph( } let mut items = vec![]; - for node in entries.into_iter() { + for node in entries.into_iter().rev() { let edges = reverse_edges.get(&node).cloned().unwrap_or_default(); items.push((node, edges)); }