From 3e9c3d2679d8f336ed5cbdd89647761403222bfe Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 27 Apr 2023 14:44:47 +0200 Subject: [PATCH] cob: Don't overwrite nodes during traversal By not checking if the node exists, if a node is traversed twice, the second instance of it gets overwritten, and all the edges get lost. --- radicle-cob/src/change_graph.rs | 5 +++-- radicle-dag/src/lib.rs | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/radicle-cob/src/change_graph.rs b/radicle-cob/src/change_graph.rs index c98a90b4..f7fbc8a3 100644 --- a/radicle-cob/src/change_graph.rs +++ b/radicle-cob/src/change_graph.rs @@ -130,8 +130,9 @@ impl GraphBuilder { let resource_commit = *change.resource(); let commit_id = commit.id; - self.graph.node(commit_id, change); - + if !self.graph.contains(&commit_id) { + self.graph.node(commit_id, change); + } commit.parents.into_iter().filter_map(move |parent| { if parent.id != resource_commit && !self.graph.has_dependency(&commit_id, &parent.id) { Some((parent, commit_id)) diff --git a/radicle-dag/src/lib.rs b/radicle-dag/src/lib.rs index ce40811d..6bd95f0d 100644 --- a/radicle-dag/src/lib.rs +++ b/radicle-dag/src/lib.rs @@ -103,6 +103,11 @@ impl Dag { } } + /// Check if the graph contains a node. + pub fn contains(&self, key: &K) -> bool { + self.graph.contains_key(key) + } + /// Get a node. pub fn get(&self, key: &K) -> Option<&Node> { self.graph.get(key)