From 1bf6ab53709e82637a2e31791387f19f9489d481 Mon Sep 17 00:00:00 2001
From: Yuya Nishihara <yuya@tcha.org>
Date: Fri, 28 Jul 2023 15:38:57 +0900
Subject: [PATCH] revset_graph: avoid construction of edges if already known

The stack can contain duplicated entries, and we only need the last one to
resolve edges.
---
 lib/src/default_revset_graph_iterator.rs | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/src/default_revset_graph_iterator.rs b/lib/src/default_revset_graph_iterator.rs
index 7c5253433..a2cb2a1e8 100644
--- a/lib/src/default_revset_graph_iterator.rs
+++ b/lib/src/default_revset_graph_iterator.rs
@@ -200,6 +200,10 @@ impl<'revset, 'index> RevsetGraphIterator<'revset, 'index> {
         let mut stack = vec![index_entry];
         while let Some(entry) = stack.last() {
             let position = entry.position();
+            if self.edges.contains_key(&position) {
+                stack.pop().unwrap();
+                continue;
+            }
             let mut edges = HashSet::new();
             let mut parents_complete = true;
             for parent in entry.parents() {