From 6a20da4d5d2ddd87ce98e93da60922feb2e6948d Mon Sep 17 00:00:00 2001
From: Zac Medico <zmedico@gentoo.org>
Date: Sun, 23 Nov 2008 07:47:43 +0000
Subject: [PATCH] Fix the code from bug #245358 so that it's guaranteed to
 traverse all the way to a root node, even when circular deps are encountered.
 (trunk r12051)

svn path=/main/branches/2.1.6/; revision=12052
---
 pym/_emerge/__init__.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index c69998e67..e73455023 100644
--- a/pym/_emerge/__init__.py
+++ b/pym/_emerge/__init__.py
@@ -5395,17 +5395,19 @@ class depgraph(object):
 			traversed_nodes.add(node)
 			msg.append('(dependency required by "%s" [%s])' % \
 				(colorize('INFORM', str(node.cpv)), node.type_name))
-			parent = None
+			# When traversing to parents, prefer arguments over packages
+			# since arguments are root nodes. Never traverse the same
+			# package twice, in order to prevent an infinite loop.
+			selected_parent = None
 			for parent in self.digraph.parent_nodes(node):
-				if parent in traversed_nodes:
-					parent = None
-					continue
 				if isinstance(parent, DependencyArg):
 					msg.append('(dependency required by "%s" [argument])' % \
 						(colorize('INFORM', str(parent))))
-					parent = None
+					selected_parent = None
 					break
-			node = parent
+				if parent not in traversed_nodes:
+					selected_parent = parent
+			node = selected_parent
 		for line in msg:
 			print line
 
-- 
2.26.2