From: Zac Medico Date: Sat, 5 Apr 2008 19:00:38 +0000 (-0000) Subject: For better performace and consistency in package selection, merge the X-Git-Tag: v2.1.5~244 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=055a588d2b4ae8135ab5bef77949b3b8c99d2019;p=portage.git For better performace and consistency in package selection, merge the CompositeDbapi code from trunk. svn path=/main/branches/2.1.2/; revision=9721 --- diff --git a/bin/emerge b/bin/emerge index 1bfe6ec88..01cbf8dbc 100755 --- a/bin/emerge +++ b/bin/emerge @@ -1463,6 +1463,39 @@ def show_invalid_depstring_notice(parent_node, depstring, error_msg): f.add_flowing_data(x) f.end_paragraph(1) +class CompositeDbapi(object): + def __init__(self, depgraph, root): + self._depgraph = depgraph + self._root = root + self._match_cache = {} + self._cpv_tree_map = {} + + def match(self, atom): + ret = self._match_cache.get(atom) + if ret is not None: + return ret[:] + pkg, existing = self._depgraph._select_package(self._root, atom) + if not pkg: + ret = [] + else: + if pkg.installed and "selective" not in self._depgraph.myparams: + try: + if self._depgraph._set_atoms.findAtomForPackage( + pkg.cpv, pkg.metadata): + ret = [] + except portage_exception.InvalidDependString: + pass + if ret is None: + self._cpv_tree_map[pkg.cpv] = \ + self._depgraph.pkg_tree_map[pkg.type_name] + ret = [pkg.cpv] + self._match_cache[atom] = ret + return ret[:] + + def aux_get(self, cpv, wants): + return self._depgraph.trees[self._root][ + self._cpv_tree_map[cpv]].dbapi.aux_get(cpv, wants) + class depgraph: pkg_tree_map = { @@ -1524,6 +1557,11 @@ class depgraph: vardb.aux_get(pkg, self._mydbapi_keys)))) del vardb, fakedb self._filtered_trees[myroot] = {} + self._filtered_trees[myroot]["vartree"] = self.trees[myroot]["vartree"] + def filtered_tree(): + pass + filtered_tree.dbapi = CompositeDbapi(self, myroot) + self._filtered_trees[myroot]["porttree"] = filtered_tree dbs = [] portdb = self.trees[myroot]["porttree"].dbapi bindb = self.trees[myroot]["bintree"].dbapi @@ -1568,6 +1606,7 @@ class depgraph: self._unsatisfied_deps_for_display = [] self._world_problems = False self._select_package = self._select_pkg_highest_available + self._highest_pkg_cache = {} def _show_slot_collision_notice(self): """Show an informational message advising the user to mask one of the @@ -2206,6 +2245,23 @@ class depgraph: print def _select_pkg_highest_available(self, root, atom, onlydeps=False): + cache_key = (root, atom, onlydeps) + ret = self._highest_pkg_cache.get(cache_key) + if ret is not None: + pkg, existing = ret + if pkg and not existing: + existing = self._slot_pkg_map[root].get(pkg.slot_atom) + if existing and existing == pkg: + # Update the cache to reflect that the + # package has been added to the graph. + ret = pkg, pkg + self._highest_pkg_cache[cache_key] = ret + return ret + ret = self._select_pkg_highest_available_imp(root, atom, onlydeps=onlydeps) + self._highest_pkg_cache[cache_key] = ret + return ret + + def _select_pkg_highest_available_imp(self, root, atom, onlydeps=False): pkgsettings = self.pkgsettings[root] dbs = self._filtered_trees[root]["dbs"] vardb = self.roots[root].trees["vartree"].dbapi @@ -2462,15 +2518,12 @@ class depgraph: mymerge = [] else: try: - self.trees[myroot]["selective"] = "selective" in self.myparams if myparent and p_status == "nomerge": portage_dep._dep_check_strict = False mycheck = portage.dep_check(depstring, None, - pkgsettings, myuse=myuse, - use_binaries=("--usepkgonly" in self.myopts), - myroot=myroot, trees=self.trees) + pkgsettings, myuse=myuse, myroot=myroot, + trees=self._filtered_trees) finally: - self.trees[myroot]["selective"] = False portage_dep._dep_check_strict = True if not mycheck[0]: diff --git a/pym/portage.py b/pym/portage.py index c14aa0353..8cf24bd7a 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -5354,7 +5354,6 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): if trees is None: global db trees = db - selective = trees[myroot].get("selective", False) writemsg("ZapDeps -- %s\n" % (use_binaries), 2) if not reduced or unreduced == ["||"] or dep_eval(reduced): return [] @@ -5415,13 +5414,6 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): avail_pkg = avail_pkg[-1] # highest (ascending order) avail_slot = "%s:%s" % (dep_getkey(atom), mydbapi.aux_get(avail_pkg, ["SLOT"])[0]) - elif not avail_pkg: - if selective: - avail_pkg = vardb.match(atom) - if avail_pkg: - avail_pkg = avail_pkg[-1] # highest (ascending order) - avail_slot = "%s:%s" % (dep_getkey(atom), - vardb.aux_get(avail_pkg, ["SLOT"])[0]) if not avail_pkg: all_available = False break