diff options
author | 2010-12-08 16:16:32 +0000 | |
---|---|---|
committer | 2010-12-08 16:16:32 +0000 | |
commit | 26cdad7e7cd655655e06fc07eef74ab01d63250b (patch) | |
tree | f9934e7e7227fa3a430358a3ab1eb23c49d2cd17 | |
parent | f1902e624313bd9f34b0e22eb567034242f3c25d (diff) | |
download | paludis-26cdad7e7cd655655e06fc07eef74ab01d63250b.tar.gz paludis-26cdad7e7cd655655e06fc07eef74ab01d63250b.tar.xz |
Refactor replacing logic into a helper
-rw-r--r-- | paludis/resolver/Makefile.am | 4 | ||||
-rw-r--r-- | paludis/resolver/decider.cc | 47 | ||||
-rw-r--r-- | paludis/resolver/decider.hh | 3 | ||||
-rw-r--r-- | paludis/resolver/find_replacing_helper-fwd.hh | 14 | ||||
-rw-r--r-- | paludis/resolver/find_replacing_helper.cc | 104 | ||||
-rw-r--r-- | paludis/resolver/find_replacing_helper.hh | 52 | ||||
-rw-r--r-- | paludis/resolver/resolver_functions.hh | 7 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.cc | 2 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.hh | 2 | ||||
-rw-r--r-- | paludis/resolver/same_slot-fwd.hh | 37 | ||||
-rw-r--r-- | paludis/resolver/same_slot.cc | 40 | ||||
-rw-r--r-- | paludis/resolver/same_slot.hh | 25 | ||||
-rw-r--r-- | src/clients/cave/resolve_common.cc | 4 |
13 files changed, 294 insertions, 47 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am index 2116c8df4..4e1d6ef41 100644 --- a/paludis/resolver/Makefile.am +++ b/paludis/resolver/Makefile.am @@ -50,6 +50,7 @@ noinst_HEADERS = \ destination.hh destination-fwd.hh \ destination_types.hh destination_types-fwd.hh destination_types-se.hh \ destination_utils.hh destination_utils-fwd.hh \ + find_replacing_helper.hh find_replacing_helper-fwd.hh \ find_repository_for_helper.hh find_repository_for_helper-fwd.hh \ get_constraints_for_dependent_helper.hh get_constraints_for_dependent_helper-fwd.hh \ get_constraints_for_purge_helper.hh get_constraints_for_purge_helper-fwd.hh \ @@ -86,6 +87,7 @@ noinst_HEADERS = \ resolvent.hh resolvent-fwd.hh \ resolver.hh resolver-fwd.hh \ resolver_functions.hh resolver_functions-fwd.hh \ + same_slot.hh same_slot-fwd.hh \ sanitised_dependencies.hh sanitised_dependencies-fwd.hh \ slot_name_or_null.hh slot_name_or_null-fwd.hh \ spec_rewriter.hh spec_rewriter-fwd.hh \ @@ -118,6 +120,7 @@ libpaludisresolver_a_SOURCES = \ destination.cc \ destination_types.cc \ destination_utils.cc \ + find_replacing_helper.cc \ find_repository_for_helper.cc \ get_constraints_for_dependent_helper.cc \ get_constraints_for_purge_helper.cc \ @@ -154,6 +157,7 @@ libpaludisresolver_a_SOURCES = \ resolvent.cc \ resolver.cc \ resolver_functions.cc \ + same_slot.cc \ sanitised_dependencies.cc \ slot_name_or_null.cc \ spec_rewriter.cc \ diff --git a/paludis/resolver/decider.cc b/paludis/resolver/decider.cc index 9b323f5aa..e937a2dfd 100644 --- a/paludis/resolver/decider.cc +++ b/paludis/resolver/decider.cc @@ -37,6 +37,7 @@ #include <paludis/resolver/collect_purges.hh> #include <paludis/resolver/accumulate_deps_and_provides.hh> #include <paludis/resolver/why_changed_choices.hh> +#include <paludis/resolver/same_slot.hh> #include <paludis/util/exception.hh> #include <paludis/util/stringify.hh> #include <paludis/util/make_named_values.hh> @@ -463,7 +464,7 @@ Decider::_make_change_type_for( { for (auto o(others->begin()), o_end(others->end()) ; o != o_end ; ++o) - if (_same_slot(*o, decision.origin_id())) + if (same_slot(*o, decision.origin_id())) return ct_add_to_slot; return ct_slot_new; @@ -528,49 +529,7 @@ Decider::_find_replacing( const std::shared_ptr<const PackageID> & id, const std::shared_ptr<const Repository> & repo) const { - Context context("When working out what is replaced by '" + stringify(*id) + - "' when it is installed to '" + stringify(repo->name()) + "':"); - - std::set<RepositoryName> repos; - - if (repo->installed_root_key()) - { - for (PackageDatabase::RepositoryConstIterator r(_imp->env->package_database()->begin_repositories()), - r_end(_imp->env->package_database()->end_repositories()) ; - r != r_end ; ++r) - if ((*r)->installed_root_key() && - (*r)->installed_root_key()->value() == repo->installed_root_key()->value()) - repos.insert((*r)->name()); - } - else - repos.insert(repo->name()); - - std::shared_ptr<PackageIDSequence> result(std::make_shared<PackageIDSequence>()); - for (std::set<RepositoryName>::const_iterator r(repos.begin()), - r_end(repos.end()) ; - r != r_end ; ++r) - { - std::shared_ptr<const PackageIDSequence> ids((*_imp->env)[selection::AllVersionsUnsorted( - generator::Package(id->name()) & generator::InRepository(*r))]); - for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ; - i != i_end ; ++i) - { - if ((*i)->version() == id->version() || (_same_slot(*i, id) && repo->installed_root_key())) - result->push_back(*i); - } - } - - return result; -} - -bool -Decider::_same_slot(const std::shared_ptr<const PackageID> & a, - const std::shared_ptr<const PackageID> & b) const -{ - if (a->slot_key()) - return b->slot_key() && a->slot_key()->value() == b->slot_key()->value(); - else - return ! b->slot_key(); + return _imp->fns.find_replacing_fn()(id, repo); } const std::shared_ptr<Resolution> diff --git a/paludis/resolver/decider.hh b/paludis/resolver/decider.hh index ff0a27c7b..139865325 100644 --- a/paludis/resolver/decider.hh +++ b/paludis/resolver/decider.hh @@ -212,9 +212,6 @@ namespace paludis const std::shared_ptr<Constraints> _initial_constraints_for(const Resolvent &) const; - bool _same_slot(const std::shared_ptr<const PackageID> & a, - const std::shared_ptr<const PackageID> & b) const; - const std::shared_ptr<const PackageID> _find_existing_id_for( const std::shared_ptr<const Resolution> &) const; const std::shared_ptr<const PackageIDSequence> _find_installable_id_candidates_for( diff --git a/paludis/resolver/find_replacing_helper-fwd.hh b/paludis/resolver/find_replacing_helper-fwd.hh new file mode 100644 index 000000000..25cbbbdaf --- /dev/null +++ b/paludis/resolver/find_replacing_helper-fwd.hh @@ -0,0 +1,14 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_FIND_REPLACING_HELPER_FWD_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_FIND_REPLACING_HELPER_FWD_HH 1 + +namespace paludis +{ + namespace resolver + { + struct FindReplacingHelper; + } +} + +#endif diff --git a/paludis/resolver/find_replacing_helper.cc b/paludis/resolver/find_replacing_helper.cc new file mode 100644 index 000000000..70ae44d91 --- /dev/null +++ b/paludis/resolver/find_replacing_helper.cc @@ -0,0 +1,104 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/resolver/find_replacing_helper.hh> +#include <paludis/resolver/same_slot.hh> +#include <paludis/util/pimp-impl.hh> +#include <paludis/util/make_shared_copy.hh> +#include <paludis/util/make_named_values.hh> +#include <paludis/util/stringify.hh> +#include <paludis/package_id.hh> +#include <paludis/partially_made_package_dep_spec.hh> +#include <paludis/elike_slot_requirement.hh> +#include <paludis/metadata_key.hh> +#include <paludis/repository.hh> +#include <paludis/package_database.hh> +#include <paludis/environment.hh> +#include <paludis/generator.hh> +#include <paludis/filtered_generator.hh> +#include <paludis/filter.hh> +#include <paludis/selection.hh> +#include <set> + +using namespace paludis; +using namespace paludis::resolver; + +namespace paludis +{ + template <> + struct Imp<FindReplacingHelper> + { + const Environment * const env; + + Imp(const Environment * const e) : + env(e) + { + } + }; +} + +FindReplacingHelper::FindReplacingHelper(const Environment * const e) : + Pimp<FindReplacingHelper>(e) +{ +} + +FindReplacingHelper::~FindReplacingHelper() = default; + +const std::shared_ptr<const PackageIDSequence> +FindReplacingHelper::operator() ( + const std::shared_ptr<const PackageID> & id, + const std::shared_ptr<const Repository> & repo) const +{ + Context context("When working out what is replaced by '" + stringify(*id) + + "' when it is installed to '" + stringify(repo->name()) + "':"); + + std::set<RepositoryName> repos; + + if (repo->installed_root_key()) + { + for (PackageDatabase::RepositoryConstIterator r(_imp->env->package_database()->begin_repositories()), + r_end(_imp->env->package_database()->end_repositories()) ; + r != r_end ; ++r) + if ((*r)->installed_root_key() && + (*r)->installed_root_key()->value() == repo->installed_root_key()->value()) + repos.insert((*r)->name()); + } + else + repos.insert(repo->name()); + + std::shared_ptr<PackageIDSequence> result(std::make_shared<PackageIDSequence>()); + for (std::set<RepositoryName>::const_iterator r(repos.begin()), + r_end(repos.end()) ; + r != r_end ; ++r) + { + std::shared_ptr<const PackageIDSequence> ids((*_imp->env)[selection::AllVersionsUnsorted( + generator::Package(id->name()) & generator::InRepository(*r))]); + for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ; + i != i_end ; ++i) + { + if ((*i)->version() == id->version() || (same_slot(*i, id) && repo->installed_root_key())) + result->push_back(*i); + } + } + + return result; +} + +template class Pimp<FindReplacingHelper>; + diff --git a/paludis/resolver/find_replacing_helper.hh b/paludis/resolver/find_replacing_helper.hh new file mode 100644 index 000000000..46cae8797 --- /dev/null +++ b/paludis/resolver/find_replacing_helper.hh @@ -0,0 +1,52 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_FIND_REPLACING_HELPER_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_FIND_REPLACING_HELPER_HH 1 + +#include <paludis/resolver/find_replacing_helper-fwd.hh> +#include <paludis/util/pimp.hh> +#include <paludis/util/attributes.hh> +#include <paludis/dep_spec-fwd.hh> +#include <paludis/environment-fwd.hh> +#include <paludis/package_id-fwd.hh> +#include <paludis/repository-fwd.hh> +#include <memory> + +namespace paludis +{ + namespace resolver + { + class PALUDIS_VISIBLE FindReplacingHelper : + private Pimp<FindReplacingHelper> + { + public: + explicit FindReplacingHelper(const Environment * const); + ~FindReplacingHelper(); + + const std::shared_ptr<const PackageIDSequence> operator() ( + const std::shared_ptr<const PackageID> &, + const std::shared_ptr<const Repository> &) const; + }; + } + + extern template class Pimp<resolver::FindReplacingHelper>; +} + +#endif diff --git a/paludis/resolver/resolver_functions.hh b/paludis/resolver/resolver_functions.hh index a378c3b8a..ae65454dd 100644 --- a/paludis/resolver/resolver_functions.hh +++ b/paludis/resolver/resolver_functions.hh @@ -51,6 +51,7 @@ namespace paludis typedef Name<struct always_via_binary_fn_name> always_via_binary_fn; typedef Name<struct can_use_fn_name> can_use_fn; typedef Name<struct confirm_fn_name> confirm_fn; + typedef Name<struct find_replacing_fn_name> find_replacing_fn; typedef Name<struct find_repository_for_fn_name> find_repository_for_fn; typedef Name<struct get_constraints_for_dependent_fn_name> get_constraints_for_dependent_fn; typedef Name<struct get_constraints_for_purge_fn_name> get_constraints_for_purge_fn; @@ -93,6 +94,11 @@ namespace paludis const std::shared_ptr<const RequiredConfirmation> & )> ConfirmFunction; + typedef std::function<std::shared_ptr<const PackageIDSequence> ( + const std::shared_ptr<const PackageID> &, + const std::shared_ptr<const Repository> & + )> FindReplacingFunction; + typedef std::function<const std::shared_ptr<const Repository> ( const std::shared_ptr<const Resolution> &, const ChangesToMakeDecision & @@ -178,6 +184,7 @@ namespace paludis NamedValue<n::always_via_binary_fn, AlwaysViaBinaryFunction> always_via_binary_fn; NamedValue<n::can_use_fn, CanUseFunction> can_use_fn; NamedValue<n::confirm_fn, ConfirmFunction> confirm_fn; + NamedValue<n::find_replacing_fn, FindReplacingFunction> find_replacing_fn; NamedValue<n::find_repository_for_fn, FindRepositoryForFunction> find_repository_for_fn; NamedValue<n::get_constraints_for_dependent_fn, GetConstraintsForDependentFunction> get_constraints_for_dependent_fn; NamedValue<n::get_constraints_for_purge_fn, GetConstraintsForPurgeFunction> get_constraints_for_purge_fn; diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc index 4fb08c195..73cee7774 100644 --- a/paludis/resolver/resolver_test.cc +++ b/paludis/resolver/resolver_test.cc @@ -106,6 +106,7 @@ ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s, always_via_binary_helper(&env), can_use_helper(&env), confirm_helper(&env), + find_replacing_helper(&env), find_repository_for_helper(&env), get_constraints_for_dependent_helper(&env), get_constraints_for_purge_helper(&env), @@ -177,6 +178,7 @@ ResolverTestCase::get_resolver_functions() n::always_via_binary_fn() = std::cref(always_via_binary_helper), n::can_use_fn() = std::cref(can_use_helper), n::confirm_fn() = std::cref(confirm_helper), + n::find_replacing_fn() = std::cref(find_replacing_helper), n::find_repository_for_fn() = std::cref(find_repository_for_helper), n::get_constraints_for_dependent_fn() = std::cref(get_constraints_for_dependent_helper), n::get_constraints_for_purge_fn() = std::cref(get_constraints_for_purge_helper), diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh index b1e959a6f..4f18be2ed 100644 --- a/paludis/resolver/resolver_test.hh +++ b/paludis/resolver/resolver_test.hh @@ -40,6 +40,7 @@ #include <paludis/resolver/always_via_binary_helper.hh> #include <paludis/resolver/can_use_helper.hh> #include <paludis/resolver/confirm_helper.hh> +#include <paludis/resolver/find_replacing_helper.hh> #include <paludis/resolver/find_repository_for_helper.hh> #include <paludis/resolver/get_constraints_for_dependent_helper.hh> #include <paludis/resolver/get_constraints_for_purge_helper.hh> @@ -95,6 +96,7 @@ namespace paludis AlwaysViaBinaryHelper always_via_binary_helper; CanUseHelper can_use_helper; ConfirmHelper confirm_helper; + FindReplacingHelper find_replacing_helper; FindRepositoryForHelper find_repository_for_helper; GetConstraintsForDependentHelper get_constraints_for_dependent_helper; GetConstraintsForPurgeHelper get_constraints_for_purge_helper; diff --git a/paludis/resolver/same_slot-fwd.hh b/paludis/resolver/same_slot-fwd.hh new file mode 100644 index 000000000..6c3b64cb1 --- /dev/null +++ b/paludis/resolver/same_slot-fwd.hh @@ -0,0 +1,37 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_SAME_SLOT_FWD_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_SAME_SLOT_FWD_HH 1 + +#include <paludis/util/attributes.hh> +#include <paludis/package_id-fwd.hh> +#include <memory> + +namespace paludis +{ + namespace resolver + { + bool same_slot( + const std::shared_ptr<const PackageID> & a, + const std::shared_ptr<const PackageID> & b) PALUDIS_ATTRIBUTE((warn_unused_result)); + } +} + +#endif diff --git a/paludis/resolver/same_slot.cc b/paludis/resolver/same_slot.cc new file mode 100644 index 000000000..7cd9bcfd5 --- /dev/null +++ b/paludis/resolver/same_slot.cc @@ -0,0 +1,40 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/resolver/same_slot.hh> +#include <paludis/util/wrapped_value.hh> +#include <paludis/package_id.hh> +#include <paludis/metadata_key.hh> +#include <paludis/name.hh> + +using namespace paludis; +using namespace paludis::resolver; + +bool +paludis::resolver::same_slot( + const std::shared_ptr<const PackageID> & a, + const std::shared_ptr<const PackageID> & b) +{ + if (a->slot_key()) + return b->slot_key() && a->slot_key()->value() == b->slot_key()->value(); + else + return ! b->slot_key(); +} + + diff --git a/paludis/resolver/same_slot.hh b/paludis/resolver/same_slot.hh new file mode 100644 index 000000000..07d8165cb --- /dev/null +++ b/paludis/resolver/same_slot.hh @@ -0,0 +1,25 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_SAME_SLOT_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_SAME_SLOT_HH 1 + +#include <paludis/resolver/same_slot-fwd.hh> + +#endif diff --git a/src/clients/cave/resolve_common.cc b/src/clients/cave/resolve_common.cc index 2eb7c6431..1992599b2 100644 --- a/src/clients/cave/resolve_common.cc +++ b/src/clients/cave/resolve_common.cc @@ -71,6 +71,7 @@ #include <paludis/resolver/always_via_binary_helper.hh> #include <paludis/resolver/can_use_helper.hh> #include <paludis/resolver/confirm_helper.hh> +#include <paludis/resolver/find_replacing_helper.hh> #include <paludis/resolver/find_repository_for_helper.hh> #include <paludis/resolver/get_constraints_for_dependent_helper.hh> #include <paludis/resolver/get_constraints_for_purge_helper.hh> @@ -710,6 +711,8 @@ paludis::cave::resolve_common( else confirm_helper.add_allowed_to_break_spec(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); + FindReplacingHelper find_replacing_helper(env.get()); + FindRepositoryForHelper find_repository_for_helper(env.get()); GetConstraintsForDependentHelper get_constraints_for_dependent_helper(env.get()); @@ -940,6 +943,7 @@ paludis::cave::resolve_common( n::always_via_binary_fn() = std::cref(always_via_binary_helper), n::can_use_fn() = std::cref(can_use_helper), n::confirm_fn() = std::cref(confirm_helper), + n::find_replacing_fn() = std::cref(find_replacing_helper), n::find_repository_for_fn() = std::cref(find_repository_for_helper), n::get_constraints_for_dependent_fn() = std::cref(get_constraints_for_dependent_helper), n::get_constraints_for_purge_fn() = std::cref(get_constraints_for_purge_helper), |