aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Dimitry Ishenko <dimitry.ishenko@gmail.com> 2014-03-04 22:46:37 -0500
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2014-03-21 15:36:14 +0000
commit20d93f8212a5d0da626bca631b7e36cc3125cc6b (patch)
tree4583ebbca14852fcc6dff4cbc6692f199051ec18
parent4a1b5b7509d0faccb32a31f38aa21e6175fd6438 (diff)
downloadpaludis-20d93f8212a5d0da626bca631b7e36cc3125cc6b.tar.gz
paludis-20d93f8212a5d0da626bca631b7e36cc3125cc6b.tar.xz
Add selection::AllVersionsSortedWithPromotion
-rw-r--r--paludis/resolver/Makefile.am4
-rw-r--r--paludis/resolver/package_id_comparator_with_promotion-fwd.hh32
-rw-r--r--paludis/resolver/package_id_comparator_with_promotion.cc101
-rw-r--r--paludis/resolver/package_id_comparator_with_promotion.hh70
-rw-r--r--paludis/resolver/selection_with_promotion-fwd.hh32
-rw-r--r--paludis/resolver/selection_with_promotion.cc85
-rw-r--r--paludis/resolver/selection_with_promotion.hh52
-rw-r--r--paludis/selection_handler.hh2
8 files changed, 377 insertions, 1 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am
index 1208db1..84f9578 100644
--- a/paludis/resolver/Makefile.am
+++ b/paludis/resolver/Makefile.am
@@ -81,6 +81,7 @@ noinst_HEADERS = \
order_early_helper.hh order_early_helper-fwd.hh \
orderer.hh orderer-fwd.hh \
orderer_notes.hh orderer_notes-fwd.hh \
+ package_id_comparator_with_promotion.hh package_id_comparator_with_promotion-fwd.hh \
package_or_block_dep_spec.hh package_or_block_dep_spec-fwd.hh \
prefer_or_avoid_helper.hh prefer_or_avoid_helper-fwd.hh \
reason.hh reason-fwd.hh \
@@ -96,6 +97,7 @@ noinst_HEADERS = \
resolver_functions.hh resolver_functions-fwd.hh \
same_slot.hh same_slot-fwd.hh \
sanitised_dependencies.hh sanitised_dependencies-fwd.hh \
+ selection_with_promotion.hh selection_with_promotion-fwd.hh \
slot_name_or_null.hh slot_name_or_null-fwd.hh \
strongly_connected_component.hh strongly_connected_component-fwd.hh \
suggest_restart.hh suggest_restart-fwd.hh \
@@ -154,6 +156,7 @@ libpaludisresolver_a_SOURCES = \
order_early_helper.cc \
orderer.cc \
orderer_notes.cc \
+ package_id_comparator_with_promotion.cc \
package_or_block_dep_spec.cc \
prefer_or_avoid_helper.cc \
reason.cc \
@@ -169,6 +172,7 @@ libpaludisresolver_a_SOURCES = \
resolver_functions.cc \
same_slot.cc \
sanitised_dependencies.cc \
+ selection_with_promotion.cc \
slot_name_or_null.cc \
strongly_connected_component.cc \
suggest_restart.cc \
diff --git a/paludis/resolver/package_id_comparator_with_promotion-fwd.hh b/paludis/resolver/package_id_comparator_with_promotion-fwd.hh
new file mode 100644
index 0000000..cd86913
--- /dev/null
+++ b/paludis/resolver/package_id_comparator_with_promotion-fwd.hh
@@ -0,0 +1,32 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2014 Dimitry Ishenko
+ *
+ * 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_PACKAGE_ID_COMPARATOR_WITH_PROMOTION_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_PACKAGE_ID_COMPARATOR_WITH_PROMOTION_FWD_HH 1
+
+namespace paludis
+{
+ namespace resolver
+ {
+ class PackageIDComparatorWithPromotion;
+ }
+}
+
+#endif
diff --git a/paludis/resolver/package_id_comparator_with_promotion.cc b/paludis/resolver/package_id_comparator_with_promotion.cc
new file mode 100644
index 0000000..ea984b9
--- /dev/null
+++ b/paludis/resolver/package_id_comparator_with_promotion.cc
@@ -0,0 +1,101 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2014 Dimitry Ishenko
+ *
+ * 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/package_id_comparator_with_promotion.hh>
+#include <paludis/resolver/get_sameness.hh>
+#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/name.hh>
+#include <paludis/version_spec.hh>
+#include <paludis/repository.hh>
+#include <paludis/environment.hh>
+
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/hashes.hh>
+
+#include <memory>
+#include <unordered_map>
+
+using namespace paludis;
+using namespace paludis::resolver;
+
+namespace paludis
+{
+ template <>
+ struct Imp<PackageIDComparatorWithPromotion>
+ {
+ std::unordered_map<RepositoryName, unsigned, Hash<RepositoryName> > m;
+ };
+}
+
+PackageIDComparatorWithPromotion::PackageIDComparatorWithPromotion(const Environment * const e) :
+ _imp()
+{
+ unsigned c(0);
+ for (auto r(e->begin_repositories()), r_end(e->end_repositories()) ; r != r_end ; ++r)
+ _imp->m.insert(std::make_pair((*r)->name(), ++c));
+}
+
+PackageIDComparatorWithPromotion::PackageIDComparatorWithPromotion(const PackageIDComparatorWithPromotion & other) :
+ _imp()
+{
+ _imp->m = other._imp->m;
+}
+
+PackageIDComparatorWithPromotion::~PackageIDComparatorWithPromotion()
+{
+}
+
+bool
+PackageIDComparatorWithPromotion::operator() (const std::shared_ptr<const PackageID> & a,
+ const std::shared_ptr<const PackageID> & b) const
+{
+ if (a->name() < b->name())
+ return true;
+
+ if (a->name() > b->name())
+ return false;
+
+ if (a->version() < b->version())
+ return true;
+
+ if (a->version() > b->version())
+ return false;
+
+ bool a_bin(false), b_bin(false);
+ if (a->behaviours_key()) a_bin = a->behaviours_key()->parse_value()->count("binary");
+ if (b->behaviours_key()) b_bin = b->behaviours_key()->parse_value()->count("binary");
+
+ if ( (a_bin != b_bin) && get_sameness(a, b)[epia_is_same] )
+ return b_bin;
+
+ auto ma(_imp->m.find(a->repository_name())), mb(_imp->m.find(b->repository_name()));
+
+ if (ma == _imp->m.end() || mb == _imp->m.end())
+ throw InternalError(PALUDIS_HERE, "Repository not in database");
+
+ if (ma->second < mb->second)
+ return true;
+ if (ma->second > mb->second)
+ return false;
+
+ return a->arbitrary_less_than_comparison(*b);
+}
diff --git a/paludis/resolver/package_id_comparator_with_promotion.hh b/paludis/resolver/package_id_comparator_with_promotion.hh
new file mode 100644
index 0000000..e114161
--- /dev/null
+++ b/paludis/resolver/package_id_comparator_with_promotion.hh
@@ -0,0 +1,70 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2014 Dimitry Ishenko
+ *
+ * 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_PACKAGE_ID_COMPARATOR_WITH_PROMOTION_HH
+#define PALUDIS_GUARD_PALUDIS_PACKAGE_ID_COMPARATOR_WITH_PROMOTION_HH 1
+
+#include <paludis/resolver/package_id_comparator_with_promotion-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/util/pimp.hh>
+
+#include <memory>
+
+namespace paludis
+{
+ namespace resolver
+ {
+ /**
+ * A comparison functor that operates similar to the PackageIDComparator,
+ * but promotes binary packages over identical non-binary ones.
+ */
+ class PALUDIS_VISIBLE PackageIDComparatorWithPromotion
+ {
+ private:
+ Pimp<PackageIDComparatorWithPromotion> _imp;
+
+ public:
+ ///\name Standard library typedefs
+ ///\{
+
+ typedef bool result_type;
+
+ ///\}
+
+ ///\name Basic operations
+ ///\{
+
+ PackageIDComparatorWithPromotion(const Environment * const);
+ PackageIDComparatorWithPromotion(const PackageIDComparatorWithPromotion &);
+ ~PackageIDComparatorWithPromotion();
+
+ ///\}
+
+ /**
+ * Perform the less-than comparison.
+ */
+ bool operator() (const std::shared_ptr<const PackageID> &,
+ const std::shared_ptr<const PackageID> &) const;
+ };
+ }
+}
+
+#endif
diff --git a/paludis/resolver/selection_with_promotion-fwd.hh b/paludis/resolver/selection_with_promotion-fwd.hh
new file mode 100644
index 0000000..27382f1
--- /dev/null
+++ b/paludis/resolver/selection_with_promotion-fwd.hh
@@ -0,0 +1,32 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008, 2010 Ciaran McCreesh
+ * Copyright (c) 2014 Dimitry Ishenko
+ *
+ * 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_SELECTION_WITH_PROMOTION_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_SELECTION_WITH_PROMOTION_FWD_HH 1
+
+namespace paludis
+{
+ namespace selection
+ {
+ class AllVersionsSortedWithPromotion;
+ }
+}
+
+#endif
diff --git a/paludis/resolver/selection_with_promotion.cc b/paludis/resolver/selection_with_promotion.cc
new file mode 100644
index 0000000..1bcd2b0
--- /dev/null
+++ b/paludis/resolver/selection_with_promotion.cc
@@ -0,0 +1,85 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2014 Dimitry Ishenko
+ *
+ * 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/selection_with_promotion.hh>
+#include <paludis/resolver/package_id_comparator_with_promotion.hh>
+#include <paludis/selection_handler.hh>
+#include <paludis/util/sequence-impl.hh>
+#include <paludis/util/set-impl.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/name.hh>
+#include <paludis/repository.hh>
+#include <paludis/package_id.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/environment.hh>
+
+#include <memory>
+#include <algorithm>
+
+using namespace paludis;
+
+namespace
+{
+ class AllVersionsSortedWithPromotionSelectionHandler :
+ public SelectionHandler
+ {
+ public:
+ AllVersionsSortedWithPromotionSelectionHandler(const FilteredGenerator & g) :
+ SelectionHandler(g)
+ {
+ }
+
+ virtual std::shared_ptr<PackageIDSequence> perform_select(const Environment * const env) const
+ {
+ std::shared_ptr<PackageIDSequence> result(std::make_shared<PackageIDSequence>());
+ RepositoryContentMayExcludes may_excludes(_fg.filter().may_excludes());
+
+ std::shared_ptr<const RepositoryNameSet> r(_fg.filter().repositories(env, _fg.generator().repositories(env, may_excludes)));
+ if (r->empty())
+ return result;
+
+ std::shared_ptr<const CategoryNamePartSet> c(_fg.filter().categories(env, r, _fg.generator().categories(env, r, may_excludes)));
+ if (c->empty())
+ return result;
+
+ std::shared_ptr<const QualifiedPackageNameSet> p(_fg.filter().packages(env, r, _fg.generator().packages(env, r, c, may_excludes)));
+ if (p->empty())
+ return result;
+
+ std::shared_ptr<const PackageIDSet> i(_fg.filter().ids(env, _fg.generator().ids(env, r, p, may_excludes)));
+ std::copy(i->begin(), i->end(), result->back_inserter());
+ result->sort(resolver::PackageIDComparatorWithPromotion(env));
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "all versions sorted from " + stringify(_fg);
+ }
+ };
+}
+
+selection::AllVersionsSortedWithPromotion::AllVersionsSortedWithPromotion(const FilteredGenerator & f) :
+ Selection(std::make_shared<AllVersionsSortedWithPromotionSelectionHandler>(f))
+{
+}
diff --git a/paludis/resolver/selection_with_promotion.hh b/paludis/resolver/selection_with_promotion.hh
new file mode 100644
index 0000000..02e271d
--- /dev/null
+++ b/paludis/resolver/selection_with_promotion.hh
@@ -0,0 +1,52 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2014 Dimitry Ishenko
+ *
+ * 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_SELECTION_WITH_PROMOTION_HH
+#define PALUDIS_GUARD_PALUDIS_SELECTION_WITH_PROMOTION_HH 1
+
+#include <paludis/resolver/selection_with_promotion-fwd.hh>
+#include <paludis/selection.hh>
+#include <paludis/filtered_generator-fwd.hh>
+
+namespace paludis
+{
+ namespace selection
+ {
+ /**
+ * Return all versions with the specified properties, sorted from worst
+ * to best, promoting binary packages over identical non-binary ones.
+ *
+ * \ingroup g_selections
+ */
+ class PALUDIS_VISIBLE AllVersionsSortedWithPromotion :
+ public Selection
+ {
+ public:
+ ///\name Basic operations
+ ///\{
+
+ AllVersionsSortedWithPromotion(const FilteredGenerator &);
+
+ ///\}
+ };
+ }
+}
+
+#endif
diff --git a/paludis/selection_handler.hh b/paludis/selection_handler.hh
index a4f30f4..6745e2b 100644
--- a/paludis/selection_handler.hh
+++ b/paludis/selection_handler.hh
@@ -30,7 +30,7 @@
namespace paludis
{
- class SelectionHandler
+ class PALUDIS_VISIBLE SelectionHandler
{
protected:
const FilteredGenerator _fg;