From 2fc0237f7ecda61abebd46bb7dc9f173bbed8868 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 5 May 2011 10:21:43 -0700 Subject: [PATCH] depgraph: simplify break_refs --- pym/_emerge/RootConfig.py | 10 +++++++++- pym/_emerge/depgraph.py | 34 ++++++++++++++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/pym/_emerge/RootConfig.py b/pym/_emerge/RootConfig.py index 110f11694..d84f10889 100644 --- a/pym/_emerge/RootConfig.py +++ b/pym/_emerge/RootConfig.py @@ -1,9 +1,10 @@ -# Copyright 1999-2010 Gentoo Foundation +# Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 class RootConfig(object): """This is used internally by depgraph to track information about a particular $ROOT.""" + __slots__ = ("root", "setconfig", "sets", "settings", "trees") pkg_tree_map = { "ebuild" : "porttree", @@ -24,3 +25,10 @@ class RootConfig(object): self.sets = {} else: self.sets = self.setconfig.getSets() + + def update(self, other): + """ + Shallow copy all attributes from another instance. + """ + for k in self.__slots__: + setattr(self, k, getattr(other, k)) diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 47c0232cd..1f80d0cd5 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -4573,8 +4573,6 @@ class depgraph(object): mergelist = self.altlist() self._implicit_libc_deps(mergelist, self._dynamic_config._scheduler_graph) - self.break_refs(mergelist) - self.break_refs(self._dynamic_config._scheduler_graph.order) # Break DepPriority.satisfied attributes which reference # installed Package instances. @@ -4596,31 +4594,27 @@ class depgraph(object): for root in trees: trees[root]['vartree']._pkg_cache = pruned_pkg_cache - self.break_refs(trees[root]['vartree'].dbapi) - self.break_refs(pruned_pkg_cache.values()) + self.break_refs() sched_config = \ _scheduler_graph_config(trees, pruned_pkg_cache, graph, mergelist) return sched_config - def break_refs(self, nodes): + def break_refs(self): """ - Take a mergelist like that returned from self.altlist() and - break any references that lead back to the depgraph. This is - useful if you want to hold references to packages without - also holding the depgraph on the heap. + Break any references in Package instances that lead back to the depgraph. + This is useful if you want to hold references to packages without also + holding the depgraph on the heap. It should only be called after the + depgraph will not be used for any more calculations. """ - for node in nodes: - if hasattr(node, "root_config"): - # The FakeVartree references the _package_cache which - # references the depgraph. So that Package instances don't - # hold the depgraph and FakeVartree on the heap, replace - # the RootConfig that references the FakeVartree with the - # original RootConfig instance which references the actual - # vartree. - node.root_config = \ - self._frozen_config._trees_orig[node.root_config.root]["root_config"] + for root_config in self._frozen_config.roots.values(): + root_config.update(self._frozen_config._trees_orig[ + root_config.root]["root_config"]) + # Both instances are now identical, so discard the + # original which should have no other references. + self._frozen_config._trees_orig[ + root_config.root]["root_config"] = root_config def _resolve_conflicts(self): if not self._complete_graph(): @@ -6427,7 +6421,7 @@ def _resume_depgraph(settings, trees, mtimedb, myopts, myparams, spinner): # package has already been installed. dropped_tasks.update(pkg for pkg in \ unsatisfied_parents if pkg.operation != "nomerge") - mydepgraph.break_refs(unsatisfied_parents) + mydepgraph.break_refs() del e, graph, traversed_nodes, \ unsatisfied_parents, unsatisfied_stack -- 2.26.2