aboutsummaryrefslogtreecommitdiffstats
path: root/lib/_emerge/depgraph.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2023-11-29 08:14:27 -0800
committerZac Medico <zmedico@gentoo.org>2023-11-29 08:33:18 -0800
commit31832c7faf5bffde25a596ce62ecf84c478fac45 (patch)
tree3a5d02aa8be255285609b9126552047d53910c3d /lib/_emerge/depgraph.py
parentPrefer installed leaves in runtime cycle topological sort (diff)
downloadgentoo-portage-31832c7faf5bffde25a596ce62ecf84c478fac45.tar.xz
gentoo-portage-31832c7faf5bffde25a596ce62ecf84c478fac45.zip
Optimize runtime cycle ignore_priority leaf selection loop for topological sort
Since increasing ignore_priority can only lead to a larger selection of leaf nodes, there is no need to increase ignore_priority to search for smaller groups of leaf nodes. It was the "only harvest one node at a time" part of commit 3487594cd8f4 that caused the test case to succeed. Fixes: 3487594cd8f4 ("Increase ignore_priority during topological sort for runtime cycle") Bug: https://bugs.gentoo.org/917259 Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib/_emerge/depgraph.py')
-rw-r--r--lib/_emerge/depgraph.py31
1 files changed, 12 insertions, 19 deletions
diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py
index 9f041f83a90e..15c3e3ca7b8e 100644
--- a/lib/_emerge/depgraph.py
+++ b/lib/_emerge/depgraph.py
@@ -9478,36 +9478,29 @@ class depgraph:
)
selected_nodes = []
while cycle_digraph:
- # Increase ignore_priority in order to find
- # smaller groups of leaf nodes. This solves
- # bug 917259 which happened because too many
- # leaves were selected at once.
- smallest_leaves = None
+ leaves = None
for ignore_priority in ignore_priorities:
leaves = cycle_digraph.leaf_nodes(
ignore_priority=ignore_priority
)
- if leaves and (
- smallest_leaves is None
- or len(leaves) < len(smallest_leaves)
- ):
- smallest_leaves = leaves
- if len(smallest_leaves) == 1:
- break
+ if leaves:
+ # Select leaves with minimum ignore_priority,
+ # in order to ingore as few deps as possible.
+ break
- if smallest_leaves is None:
- smallest_leaves = [cycle_digraph.order[-1]]
+ if leaves is None:
+ leaves = [cycle_digraph.order[-1]]
# Prefer installed leaves, in order to avoid
- # merging something too early.
- installed_leaves = [pkg for pkg in smallest_leaves if pkg.installed]
+ # merging something too early as in bug 917259.
+ installed_leaves = [pkg for pkg in leaves if pkg.installed]
if installed_leaves:
- smallest_leaves = installed_leaves
+ leaves = installed_leaves
# Only harvest one node at a time, in order to
# minimize the number of ignored dependencies.
- cycle_digraph.remove(smallest_leaves[0])
- selected_nodes.append(smallest_leaves[0])
+ cycle_digraph.remove(leaves[0])
+ selected_nodes.append(leaves[0])
if not selected_nodes and myblocker_uninstalls:
# An Uninstall task needs to be executed in order to