1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Fix the computation of commit order for circular dependencies

When finding a circular dependencies, we must ensure that all dependencies
of a node have been visited before adding it to the sorted list.
This commit is contained in:
Christophe Coevoet 2018-09-20 12:13:25 +02:00
parent 11a7f359d1
commit 568c2d308c

View File

@ -164,6 +164,17 @@ class CommitOrderCalculator
case self::IN_PROGRESS:
if (isset($adjacentVertex->dependencyList[$vertex->hash]) &&
$adjacentVertex->dependencyList[$vertex->hash]->weight < $edge->weight) {
// If we have some non-visited dependencies in the in-progress dependency, we
// need to visit them before adding the node.
foreach ($adjacentVertex->dependencyList as $adjacentEdge) {
$adjacentEdgeVertex = $this->nodeList[$adjacentEdge->to];
if ($adjacentEdgeVertex->state === self::NOT_VISITED) {
$this->visit($adjacentEdgeVertex);
}
}
$adjacentVertex->state = self::VISITED;
$this->sortedNodeList[] = $adjacentVertex->value;