diff options
author | 2011-06-11 17:56:14 +0100 | |
---|---|---|
committer | 2011-06-11 19:13:23 +0100 | |
commit | e3400d6d4c843671c687c02240e24dae12dd0cf8 (patch) | |
tree | dd551f5fc39dc6557b5e20e1b0fd49e941397c4d | |
parent | 7ce202f0c9f10ea545daf9ed919d969e8ef19bdc (diff) | |
download | paludis-e3400d6d4c843671c687c02240e24dae12dd0cf8.tar.gz paludis-e3400d6d4c843671c687c02240e24dae12dd0cf8.tar.xz |
Split out
-rw-r--r-- | paludis/resolver/Makefile.am | 2 | ||||
-rw-r--r-- | paludis/resolver/decider.cc | 62 | ||||
-rw-r--r-- | paludis/resolver/get_sameness-fwd.hh | 39 | ||||
-rw-r--r-- | paludis/resolver/get_sameness.cc | 100 | ||||
-rw-r--r-- | paludis/resolver/get_sameness.hh | 33 |
5 files changed, 177 insertions, 59 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am index 94cd84faa..dddbf1bea 100644 --- a/paludis/resolver/Makefile.am +++ b/paludis/resolver/Makefile.am @@ -60,6 +60,7 @@ noinst_HEADERS = \ get_destination_types_for_error_helper.hh get_destination_types_for_error_helper-fwd.hh \ get_initial_constraints_for_helper.hh get_initial_constraints_for_helper-fwd.hh \ get_resolvents_for_helper.hh get_resolvents_for_helper-fwd.hh \ + get_sameness.hh get_sameness-fwd.hh \ get_use_existing_nothing_helper.hh get_use_existing_nothing_helper-fwd.hh \ has_behaviour.hh has_behaviour-fwd.hh \ interest_in_spec_helper.hh interest_in_spec_helper-fwd.hh \ @@ -134,6 +135,7 @@ libpaludisresolver_a_SOURCES = \ get_destination_types_for_error_helper.cc \ get_initial_constraints_for_helper.cc \ get_resolvents_for_helper.cc \ + get_sameness.cc \ get_use_existing_nothing_helper.cc \ has_behaviour.cc \ interest_in_spec_helper.cc \ diff --git a/paludis/resolver/decider.cc b/paludis/resolver/decider.cc index 79488175b..e0ffad32d 100644 --- a/paludis/resolver/decider.cc +++ b/paludis/resolver/decider.cc @@ -41,6 +41,7 @@ #include <paludis/resolver/reason_utils.hh> #include <paludis/resolver/make_uninstall_blocker.hh> #include <paludis/resolver/has_behaviour-fwd.hh> +#include <paludis/resolver/get_sameness.hh> #include <paludis/util/exception.hh> #include <paludis/util/stringify.hh> #include <paludis/util/make_named_values.hh> @@ -1559,65 +1560,8 @@ Decider::_try_to_find_decision_for( } else if (existing_id && installable_id) { - bool is_same_version(existing_id->version() == installable_id->version()); - bool is_same(false); - bool is_same_metadata(false); - - if (is_same_version) - { - is_same = true; - is_same_metadata = true; - - std::set<ChoiceNameWithPrefix> common; - std::shared_ptr<const Choices> installable_choices; - std::shared_ptr<const Choices> existing_choices; - - if (existing_id->choices_key() && installable_id->choices_key()) - { - installable_choices = installable_id->choices_key()->parse_value(); - existing_choices = existing_id->choices_key()->parse_value(); - - std::set<ChoiceNameWithPrefix> i_common, u_common; - for (Choices::ConstIterator k(installable_choices->begin()), k_end(installable_choices->end()) ; - k != k_end ; ++k) - { - if (! (*k)->consider_added_or_changed()) - continue; - - for (Choice::ConstIterator i((*k)->begin()), i_end((*k)->end()) ; - i != i_end ; ++i) - if ((*i)->explicitly_listed()) - i_common.insert((*i)->name_with_prefix()); - } - - for (Choices::ConstIterator k(existing_choices->begin()), k_end(existing_choices->end()) ; - k != k_end ; ++k) - { - if (! (*k)->consider_added_or_changed()) - continue; - - for (Choice::ConstIterator i((*k)->begin()), i_end((*k)->end()) ; - i != i_end ; ++i) - if ((*i)->explicitly_listed()) - u_common.insert((*i)->name_with_prefix()); - } - - std::set_intersection( - i_common.begin(), i_common.end(), - u_common.begin(), u_common.end(), - std::inserter(common, common.begin())); - } - - for (std::set<ChoiceNameWithPrefix>::const_iterator f(common.begin()), f_end(common.end()) ; - f != f_end ; ++f) - if (installable_choices->find_by_name_with_prefix(*f)->enabled() != - existing_choices->find_by_name_with_prefix(*f)->enabled()) - { - is_same = false; - is_same_metadata = false; - break; - } - } + bool is_same_version, is_same, is_same_metadata; + std::tie(is_same_version, is_same, is_same_metadata) = get_sameness(existing_id, installable_id); bool is_transient(has_behaviour(existing_id, "transient")); diff --git a/paludis/resolver/get_sameness-fwd.hh b/paludis/resolver/get_sameness-fwd.hh new file mode 100644 index 000000000..c5ed22f33 --- /dev/null +++ b/paludis/resolver/get_sameness-fwd.hh @@ -0,0 +1,39 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2011 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_GET_SAMENESS_FWD_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_GET_SAMENESS_FWD_HH 1 + +#include <paludis/util/attributes.hh> +#include <paludis/package_id-fwd.hh> +#include <tuple> +#include <memory> + +namespace paludis +{ + namespace resolver + { + std::tuple<bool, bool, bool> + get_sameness( + const std::shared_ptr<const PackageID> & existing_id, + const std::shared_ptr<const PackageID> & installable_id) PALUDIS_ATTRIBUTE((warn_unused_result)); + } +} + +#endif diff --git a/paludis/resolver/get_sameness.cc b/paludis/resolver/get_sameness.cc new file mode 100644 index 000000000..d395562b8 --- /dev/null +++ b/paludis/resolver/get_sameness.cc @@ -0,0 +1,100 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2011 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/get_sameness.hh> + +#include <paludis/package_id.hh> +#include <paludis/choice.hh> +#include <paludis/metadata_key.hh> +#include <paludis/version_spec.hh> + +#include <set> +#include <algorithm> + +using namespace paludis; +using namespace paludis::resolver; + +std::tuple<bool, bool, bool> +paludis::resolver::get_sameness( + const std::shared_ptr<const PackageID> & existing_id, + const std::shared_ptr<const PackageID> & installable_id) +{ + bool is_same_version(existing_id->version() == installable_id->version()); + bool is_same(false); + bool is_same_metadata(false); + + if (is_same_version) + { + is_same = true; + is_same_metadata = true; + + std::set<ChoiceNameWithPrefix> common; + std::shared_ptr<const Choices> installable_choices; + std::shared_ptr<const Choices> existing_choices; + + if (existing_id->choices_key() && installable_id->choices_key()) + { + installable_choices = installable_id->choices_key()->parse_value(); + existing_choices = existing_id->choices_key()->parse_value(); + + std::set<ChoiceNameWithPrefix> i_common, u_common; + for (Choices::ConstIterator k(installable_choices->begin()), k_end(installable_choices->end()) ; + k != k_end ; ++k) + { + if (! (*k)->consider_added_or_changed()) + continue; + + for (Choice::ConstIterator i((*k)->begin()), i_end((*k)->end()) ; + i != i_end ; ++i) + if ((*i)->explicitly_listed()) + i_common.insert((*i)->name_with_prefix()); + } + + for (Choices::ConstIterator k(existing_choices->begin()), k_end(existing_choices->end()) ; + k != k_end ; ++k) + { + if (! (*k)->consider_added_or_changed()) + continue; + + for (Choice::ConstIterator i((*k)->begin()), i_end((*k)->end()) ; + i != i_end ; ++i) + if ((*i)->explicitly_listed()) + u_common.insert((*i)->name_with_prefix()); + } + + std::set_intersection( + i_common.begin(), i_common.end(), + u_common.begin(), u_common.end(), + std::inserter(common, common.begin())); + } + + for (std::set<ChoiceNameWithPrefix>::const_iterator f(common.begin()), f_end(common.end()) ; + f != f_end ; ++f) + if (installable_choices->find_by_name_with_prefix(*f)->enabled() != + existing_choices->find_by_name_with_prefix(*f)->enabled()) + { + is_same = false; + is_same_metadata = false; + break; + } + } + + return std::make_tuple(is_same_version, is_same, is_same_metadata); +} + diff --git a/paludis/resolver/get_sameness.hh b/paludis/resolver/get_sameness.hh new file mode 100644 index 000000000..b2b3854f3 --- /dev/null +++ b/paludis/resolver/get_sameness.hh @@ -0,0 +1,33 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2011 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_GET_SAMENESS_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_GET_SAMENESS_HH 1 + +#include <paludis/resolver/get_sameness-fwd.hh> + +namespace paludis +{ + namespace resolver + { + + } +} + +#endif |