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.
This commit is contained in:
Alexis Sellier 2023-04-27 14:44:47 +02:00
parent 730eaa00ca
commit 3e9c3d2679
No known key found for this signature in database
2 changed files with 8 additions and 2 deletions

View File

@ -130,8 +130,9 @@ impl GraphBuilder {
let resource_commit = *change.resource(); let resource_commit = *change.resource();
let commit_id = commit.id; 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| { commit.parents.into_iter().filter_map(move |parent| {
if parent.id != resource_commit && !self.graph.has_dependency(&commit_id, &parent.id) { if parent.id != resource_commit && !self.graph.has_dependency(&commit_id, &parent.id) {
Some((parent, commit_id)) Some((parent, commit_id))

View File

@ -103,6 +103,11 @@ impl<K: Eq + Copy + Hash, V> Dag<K, V> {
} }
} }
/// Check if the graph contains a node.
pub fn contains(&self, key: &K) -> bool {
self.graph.contains_key(key)
}
/// Get a node. /// Get a node.
pub fn get(&self, key: &K) -> Option<&Node<K, V>> { pub fn get(&self, key: &K) -> Option<&Node<K, V>> {
self.graph.get(key) self.graph.get(key)