aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-09 06:08:33 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-09 06:08:33 +0000
commitf3d622911b0e8619bcb5637552a30c7905cf9e5c (patch)
treee241dd0ec79b69c489788f61ebac70815c8bdd2f
parentc9a803676da3e3e0f6dc2ee498ad2418a9ae413f (diff)
downloadpaludis-f3d622911b0e8619bcb5637552a30c7905cf9e5c.tar.gz
paludis-f3d622911b0e8619bcb5637552a30c7905cf9e5c.tar.xz
Add qo_best_version_only, qo_best_version_in_slot_only. Fixes: ticket:219
-rw-r--r--paludis/environment.se2
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/package_database.cc82
-rw-r--r--paludis/package_database.hh23
-rw-r--r--paludis/package_database.se24
-rw-r--r--paludis/package_database_TEST.cc37
-rw-r--r--paludis/package_database_entry.cc4
7 files changed, 116 insertions, 58 deletions
diff --git a/paludis/environment.se b/paludis/environment.se
index c7d1798..e4bf5c6 100644
--- a/paludis/environment.se
+++ b/paludis/environment.se
@@ -3,8 +3,6 @@
make_enum_MaskReasonsOption()
{
- visible
-
prefix mro
key mro_override_unkeyworded "Ignore keyword masks for unkeyworded packages"
diff --git a/paludis/files.m4 b/paludis/files.m4
index 4bf2fdc..a3b6bf8 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -24,7 +24,7 @@ add(`host_tuple_name', `hh', `cc', `sr', `test')
add(`mask_reasons', `hh', `cc', `se')
add(`match_package', `hh', `cc')
add(`name', `hh', `cc', `test', `sr', `se')
-add(`package_database', `hh', `cc', `test')
+add(`package_database', `hh', `cc', `test', `se')
add(`package_database_entry', `hh', `cc', `sr')
add(`paludis', `hh', `cc')
add(`portage_dep_lexer', `hh', `cc', `test')
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index d7db1ed..347bd8f 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -36,7 +36,7 @@
using namespace paludis;
-#include "package_database_entry-sr.cc"
+#include "package_database-se.cc"
std::ostream &
paludis::operator<< (std::ostream & s, const PackageDatabaseEntry & v)
@@ -252,6 +252,36 @@ PackageDatabase::query(const PackageDepSpec & a, const InstallState installed_st
throw InternalError(PALUDIS_HERE, "Bad InstallState");
}
+namespace
+{
+ bool compare_name(const PackageDatabaseEntry & a, const PackageDatabaseEntry & b)
+ {
+ return a.name == b.name;
+ }
+
+ struct CompareNameSlot
+ {
+ const PackageDatabase * const db;
+
+ CompareNameSlot(const PackageDatabase * const d) :
+ db(d)
+ {
+ }
+
+ bool operator() (const PackageDatabaseEntry & a, const PackageDatabaseEntry & b) const
+ {
+ if (a.name != b.name)
+ return false;
+
+ std::tr1::shared_ptr<const VersionMetadata>
+ ma(db->fetch_repository(a.repository)->version_metadata(a.name, a.version)),
+ mb(db->fetch_repository(b.repository)->version_metadata(b.name, b.version));
+
+ return ma->slot == mb->slot;
+ }
+ };
+}
+
std::tr1::shared_ptr<PackageDatabaseEntryCollection>
PackageDatabase::query(const Query & q, const QueryOrder query_order) const
{
@@ -333,6 +363,27 @@ PackageDatabase::query(const Query & q, const QueryOrder query_order) const
_group_package_database_entry_collection(*result);
continue;
+ case qo_best_version_only:
+ {
+ _sort_package_database_entry_collection(*result);
+ std::list<PackageDatabaseEntry> l;
+ std::unique_copy(result->list.rbegin(), result->list.rend(),
+ std::front_inserter(l), &compare_name);
+ result->list.swap(l);
+ }
+ continue;
+
+ case qo_best_version_in_slot_only:
+ {
+ _sort_package_database_entry_collection(*result);
+ _group_package_database_entry_collection(*result);
+ std::list<PackageDatabaseEntry> l;
+ std::unique_copy(result->list.rbegin(), result->list.rend(),
+ std::front_inserter(l), CompareNameSlot(this));
+ result->list.swap(l);
+ }
+ continue;
+
case qo_whatever:
continue;
@@ -548,32 +599,3 @@ paludis::operator<< (std::ostream & o, const InstallState & s)
return o;
}
-std::ostream &
-paludis::operator<< (std::ostream & o, const QueryOrder & s)
-{
- do
- {
- switch (s)
- {
- case qo_order_by_version:
- o << "order_by_version";
- continue;
-
- case qo_group_by_slot:
- o << "group_by_slot";
- continue;
-
- case qo_whatever:
- o << "whatever";
- continue;
-
- case last_qo:
- ;
- }
-
- throw InternalError(PALUDIS_HERE, "Bad QueryOrder");
- } while (false);
-
- return o;
-}
-
diff --git a/paludis/package_database.hh b/paludis/package_database.hh
index a5f2b20..bc479a4 100644
--- a/paludis/package_database.hh
+++ b/paludis/package_database.hh
@@ -226,20 +226,9 @@ namespace paludis
is_installable_only, ///< Installable only
is_any, ///< Either
last_is
- };
+ } PALUDIS_ATTRIBUTE((deprecated));
- /**
- * How to order query results.
- *
- * \ingroup grppackagedatabase
- */
- enum QueryOrder
- {
- qo_order_by_version, ///< By version
- qo_group_by_slot, ///< By version, with like slots adjacent
- qo_whatever, ///< No particular order
- last_qo
- };
+#include <paludis/package_database-se.hh>
/**
* A PackageDatabase can be queried for Package instances.
@@ -357,14 +346,6 @@ namespace paludis
*/
std::ostream &
operator<< (std::ostream &, const InstallState &) PALUDIS_VISIBLE;
-
- /**
- * Write a QueryOrder to a stream.
- *
- * \ingroup grppackagedatabase
- */
- std::ostream &
- operator<< (std::ostream &, const QueryOrder &) PALUDIS_VISIBLE;
}
#endif
diff --git a/paludis/package_database.se b/paludis/package_database.se
new file mode 100644
index 0000000..84d2858
--- /dev/null
+++ b/paludis/package_database.se
@@ -0,0 +1,24 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et ft=sh :
+
+make_enum_QueryOrder()
+{
+ prefix qo
+
+ key qo_order_by_version "Order by version"
+ key qo_group_by_slot "Order by version, with like slots grouped"
+ key qo_best_version_only "Only the best version"
+ key qo_best_version_in_slot_only "Only the best version in each slot"
+ key qo_whatever "Arbitrary ordering"
+
+ doxygen_comment << "END"
+ /**
+ * How to order paludis::PackageDatabase::query() results.
+ *
+ * \see PackageDatabase
+ * \ingroup grppackagedatabase
+ */
+END
+}
+
+
diff --git a/paludis/package_database_TEST.cc b/paludis/package_database_TEST.cc
index addb2bb..fd35f34 100644
--- a/paludis/package_database_TEST.cc
+++ b/paludis/package_database_TEST.cc
@@ -175,18 +175,49 @@ namespace test_cases
std::tr1::shared_ptr<FakeRepository> r2(new FakeRepository(&e, RepositoryName("repo2")));
r2->add_version("cat", "pkg", "1")->slot = SlotName("a");
r2->add_version("cat", "pkg", "3")->slot = SlotName("b");
- p.add_repository(10, r2);
+ p.add_repository(5, r2);
TEST_CHECK(true);
PackageDepSpec d("cat/pkg", pds_pm_permissive);
const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q1(p.query(d, is_any, qo_order_by_version));
TEST_CHECK_EQUAL(join(q1->begin(), q1->end(), " "),
- "cat/pkg-1::repo1 cat/pkg-1::repo2 cat/pkg-2::repo1 cat/pkg-3::repo1 cat/pkg-3::repo2 cat/pkg-4::repo1");
+ "cat/pkg-1::repo2 cat/pkg-1::repo1 cat/pkg-2::repo1 cat/pkg-3::repo2 cat/pkg-3::repo1 cat/pkg-4::repo1");
const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q2(p.query(d, is_any, qo_group_by_slot));
TEST_CHECK_EQUAL(join(q2->begin(), q2->end(), " "),
- "cat/pkg-2::repo1 cat/pkg-3::repo1 cat/pkg-3::repo2 cat/pkg-1::repo1 cat/pkg-1::repo2 cat/pkg-4::repo1");
+ "cat/pkg-3::repo2 cat/pkg-2::repo1 cat/pkg-3::repo1 cat/pkg-1::repo2 cat/pkg-1::repo1 cat/pkg-4::repo1");
+
+ const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q3(p.query(d, is_any, qo_best_version_only));
+ TEST_CHECK_EQUAL(join(q3->begin(), q3->end(), " "),
+ "cat/pkg-4::repo1");
+
+ const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q4(p.query(d, is_any, qo_best_version_in_slot_only));
+ TEST_CHECK_EQUAL(join(q4->begin(), q4->end(), " "),
+ "cat/pkg-3::repo2 cat/pkg-3::repo1 cat/pkg-4::repo1");
+
+ std::tr1::shared_ptr<FakeRepository> r3(new FakeRepository(&e, RepositoryName("repo3")));
+ r3->add_version("cat", "other", "1")->slot = SlotName("a");
+ p.add_repository(5, r3);
+ TEST_CHECK(true);
+
+ PackageDepSpec c("cat/*", pds_pm_unspecific);
+
+ const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q5(p.query(c, is_any, qo_order_by_version));
+ TEST_CHECK_EQUAL(join(q5->begin(), q5->end(), " "),
+ "cat/other-1::repo3 cat/pkg-1::repo2 cat/pkg-1::repo1 cat/pkg-2::repo1 cat/pkg-3::repo2 cat/pkg-3::repo1 cat/pkg-4::repo1");
+
+ const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q6(p.query(c, is_any, qo_group_by_slot));
+ TEST_CHECK_EQUAL(join(q6->begin(), q6->end(), " "),
+ "cat/other-1::repo3 cat/pkg-3::repo2 cat/pkg-2::repo1 cat/pkg-3::repo1 cat/pkg-1::repo2 cat/pkg-1::repo1 cat/pkg-4::repo1");
+
+ const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q7(p.query(c, is_any, qo_best_version_only));
+ TEST_CHECK_EQUAL(join(q7->begin(), q7->end(), " "),
+ "cat/other-1::repo3 cat/pkg-4::repo1");
+
+ const std::tr1::shared_ptr<PackageDatabaseEntryCollection> q8(p.query(c, is_any, qo_best_version_in_slot_only));
+ TEST_CHECK_EQUAL(join(q8->begin(), q8->end(), " "),
+ "cat/other-1::repo3 cat/pkg-3::repo2 cat/pkg-3::repo1 cat/pkg-4::repo1");
}
} package_database_query_order_test;
diff --git a/paludis/package_database_entry.cc b/paludis/package_database_entry.cc
index 12d2a46..1aa23e6 100644
--- a/paludis/package_database_entry.cc
+++ b/paludis/package_database_entry.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ * Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
*
* 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
@@ -22,6 +22,8 @@
using namespace paludis;
+#include "package_database_entry-sr.cc"
+
bool
ArbitrarilyOrderedPackageDatabaseEntryCollectionComparator::operator () (
const PackageDatabaseEntry & lhs, const PackageDatabaseEntry & rhs) const