aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-21 02:05:40 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-21 02:05:40 +0000
commit97f0c87df64c8f820c4fb959631ef6e49cfbbc6e (patch)
tree9a467fa5c7f07fdca1b76342f55b730052f6a413
parent9f2f1c916901f4fd0467cd7078e92c6637ed00de (diff)
downloadpaludis-97f0c87df64c8f820c4fb959631ef6e49cfbbc6e.tar.gz
paludis-97f0c87df64c8f820c4fb959631ef6e49cfbbc6e.tar.xz
Switch match_package to take Environment rather than PackageDatabase as its first argument, since we're not using multiple DBs per environment any more.
-rw-r--r--paludis/default_environment.cc14
-rw-r--r--paludis/dep_list.cc20
-rw-r--r--paludis/match_package.cc6
-rw-r--r--paludis/match_package.hh48
-rw-r--r--paludis/package_database.cc8
-rw-r--r--paludis/package_database.hh3
-rw-r--r--paludis/package_database_TEST.cc28
-rw-r--r--paludis/portage_repository.cc4
-rw-r--r--paludis/test_environment.cc2
9 files changed, 50 insertions, 83 deletions
diff --git a/paludis/default_environment.cc b/paludis/default_environment.cc
index 9364153..9320f0e 100644
--- a/paludis/default_environment.cc
+++ b/paludis/default_environment.cc
@@ -30,7 +30,7 @@
using namespace paludis;
DefaultEnvironment::DefaultEnvironment() :
- Environment(PackageDatabase::Pointer(new PackageDatabase))
+ Environment(PackageDatabase::Pointer(new PackageDatabase(this)))
{
Context context("When loading default environment:");
@@ -60,7 +60,7 @@ DefaultEnvironment::query_use(const UseFlagName & f, const PackageDatabaseEntry
if (f != u->get<uce_flag_name>())
continue;
- if (! match_package(package_database(), *u->get<uce_dep_atom>(), *e))
+ if (! match_package(this, *u->get<uce_dep_atom>(), *e))
continue;
switch (u->get<uce_flag_state>())
@@ -154,7 +154,7 @@ DefaultEnvironment::accept_keyword(const KeywordName & keyword, const PackageDat
k_end(DefaultConfig::get_instance()->end_package_keywords(d->get<pde_name>())) ;
k != k_end ; ++k)
{
- if (! match_package(package_database(), k->first, d))
+ if (! match_package(this, k->first, d))
continue;
result |= k->second == keyword;
@@ -185,7 +185,7 @@ DefaultEnvironment::accept_license(const std::string & license, const PackageDat
k_end(DefaultConfig::get_instance()->end_package_licenses(d->get<pde_name>())) ;
k != k_end ; ++k)
{
- if (! match_package(package_database(), k->first, d))
+ if (! match_package(this, k->first, d))
continue;
result |= k->second == license;
@@ -213,7 +213,7 @@ DefaultEnvironment::query_user_masks(const PackageDatabaseEntry & d) const
k_end(DefaultConfig::get_instance()->end_user_masks(d.get<pde_name>())) ;
k != k_end ; ++k)
{
- if (! match_package(package_database(), *k, d))
+ if (! match_package(this, *k, d))
continue;
return true;
@@ -230,7 +230,7 @@ DefaultEnvironment::query_user_unmasks(const PackageDatabaseEntry & d) const
k_end(DefaultConfig::get_instance()->end_user_unmasks(d.get<pde_name>())) ;
k != k_end ; ++k)
{
- if (! match_package(package_database(), *k, d))
+ if (! match_package(this, *k, d))
continue;
return true;
@@ -290,7 +290,7 @@ DefaultEnvironment::query_enabled_use_matching(const std::string & prefix,
if (0 != u->get<uce_flag_name>().data().compare(0, prefix.length(), prefix))
continue;
- if (! match_package(package_database(), *u->get<uce_dep_atom>(), *e))
+ if (! match_package(this, *u->get<uce_dep_atom>(), *e))
continue;
switch (u->get<uce_flag_state>())
diff --git a/paludis/dep_list.cc b/paludis/dep_list.cc
index 01d7264..57e6541 100644
--- a/paludis/dep_list.cc
+++ b/paludis/dep_list.cc
@@ -310,18 +310,18 @@ DepList::visit(const AllDepAtom * const v)
struct DepListEntryMatcher :
public std::unary_function<bool, const DepListEntry &>
{
- const PackageDatabase * const db;
+ const Environment * const env;
const PackageDepAtom & atom;
- DepListEntryMatcher(const PackageDatabase * const d, const PackageDepAtom & p) :
- db(d),
+ DepListEntryMatcher(const Environment * const e, const PackageDepAtom & p) :
+ env(e),
atom(p)
{
}
bool operator() (const DepListEntry & e) const
{
- return match_package(db, atom, e);
+ return match_package(env, atom, e);
}
};
#endif
@@ -340,8 +340,7 @@ DepList::visit(const PackageDepAtom * const p)
if (_imp->merge_list.end() != ((i = std::find_if(
_imp->merge_list.begin(),
_imp->merge_list.end(),
- DepListEntryMatcher(
- _imp->environment->package_database().raw_pointer(), *p)))))
+ DepListEntryMatcher(_imp->environment, *p)))))
{
/* what's our status? */
if (! i->get<dle_flags>()[dlef_has_predeps])
@@ -353,8 +352,7 @@ DepList::visit(const PackageDepAtom * const p)
return;
else if (_imp->current_package && _imp->drop_self_circular &&
- match_package(_imp->environment->package_database(), p,
- _imp->current_package))
+ match_package(_imp->environment, p, _imp->current_package))
return;
else
@@ -456,8 +454,7 @@ DepList::visit(const PackageDepAtom * const p)
PackageDepAtom pp(QualifiedPackageName((*p)->text()));
if (_imp->merge_list.end() != std::find_if(
_imp->merge_list.begin(), _imp->merge_list.end(),
- DepListEntryMatcher(
- _imp->environment->package_database().raw_pointer(), pp)))
+ DepListEntryMatcher(_imp->environment, pp)))
continue;
VersionMetadata::Pointer p_metadata(new VersionMetadata);
@@ -700,8 +697,7 @@ DepList::visit(const BlockDepAtom * const d)
while (m != _imp->merge_list.end())
{
if (_imp->merge_list.end() != ((m = std::find_if(m, _imp->merge_list.end(),
- DepListEntryMatcher(_imp->environment->package_database().raw_pointer(),
- *(d->blocked_atom()))))))
+ DepListEntryMatcher(_imp->environment, *(d->blocked_atom()))))))
{
if (! _imp->current_package)
throw BlockError("'" + stringify(*(d->blocked_atom())) + "' blocked by pending package '"
diff --git a/paludis/match_package.cc b/paludis/match_package.cc
index daee034..dfa61b3 100644
--- a/paludis/match_package.cc
+++ b/paludis/match_package.cc
@@ -29,7 +29,7 @@ using namespace paludis;
bool
match_package_internals::do_match(
- const PackageDatabase * const db,
+ const Environment * const env,
const PackageDepAtom * const atom,
const PackageDatabaseEntry * const entry)
{
@@ -47,7 +47,7 @@ match_package_internals::do_match(
if (atom->slot_ptr())
{
- VersionMetadata::ConstPointer metadata(db->fetch_metadata(*entry));
+ VersionMetadata::ConstPointer metadata(env->package_database()->fetch_metadata(*entry));
if (*atom->slot_ptr() != SlotName(metadata->get(vmk_slot)))
return false;
}
@@ -57,7 +57,7 @@ match_package_internals::do_match(
bool
match_package_internals::do_match(
- const PackageDatabase * const,
+ const Environment * const,
const PackageDepAtom * const atom,
const DepListEntry * const entry)
{
diff --git a/paludis/match_package.hh b/paludis/match_package.hh
index 65bc79f..a9cc620 100644
--- a/paludis/match_package.hh
+++ b/paludis/match_package.hh
@@ -15,7 +15,7 @@
#include <paludis/dep_atom.hh>
#include <paludis/dep_list.hh>
-#include <paludis/package_database.hh>
+#include <paludis/environment.hh>
#include <paludis/util/attributes.hh>
namespace paludis
@@ -33,7 +33,7 @@ namespace paludis
* \ingroup grpmatchpackage
*/
bool do_match(
- const PackageDatabase * const db,
+ const Environment * const env,
const PackageDepAtom * const atom,
const PackageDatabaseEntry * const entry)
PALUDIS_ATTRIBUTE((nonnull(1, 2, 3)));
@@ -44,33 +44,19 @@ namespace paludis
* \ingroup grpmatchpackage
*/
bool do_match(
- const PackageDatabase * const db,
+ const Environment * const env,
const PackageDepAtom * const atom,
const DepListEntry * const entry)
PALUDIS_ATTRIBUTE((nonnull(2, 3)));
/**
- * Normalise DB type.
- *
- * \ingroup grpmatchpackage
- */
- inline const PackageDatabase * sanitise_db(const PackageDatabase * db)
- {
- return db;
- }
-
- /**
- * Normalise type.
- *
- * \deprecated Use sanitise_db(const PackageDatabase *) instead.
+ * Normalise env type.
*
* \ingroup grpmatchpackage
*/
- inline const PackageDatabase * sanitise_db(const PackageDatabase & db) PALUDIS_ATTRIBUTE((deprecated));
-
- inline const PackageDatabase * sanitise_db(const PackageDatabase & db)
+ inline const Environment * sanitise_env(const Environment * env)
{
- return &db;
+ return env;
}
/**
@@ -79,19 +65,9 @@ namespace paludis
* \ingroup grpmatchpackage
*/
template <typename P1_, typename P2_>
- inline const PackageDatabase * sanitise_db(const CountedPtr<const PackageDatabase, P1_, P2_> db)
- {
- return db.raw_pointer();
- }
-
- /**
- * Normalise DB type.
- *
- * \ingroup grpmatchpackage
- */
- inline const PackageDatabase * sanitise_db(const PackageDatabase::ConstPointer db)
+ inline const Environment * sanitise_env(const CountedPtr<const Environment, P1_, P2_> env)
{
- return db.raw_pointer();
+ return env.raw_pointer();
}
/**
@@ -151,20 +127,20 @@ namespace paludis
/**
* Return whether the specified atom matches the specified target.
*
- * \param db Some kind of package database
+ * \param env Some kind of environment
* \param atom Some kind of package dep atom
* \param target Some kind of target
*
* \ingroup grpmatchpackage
*/
- template <typename DB_, typename Atom_, typename Target_>
+ template <typename Env_, typename Atom_, typename Target_>
bool match_package(
- const DB_ & db,
+ const Env_ & env,
const Atom_ & atom,
const Target_ & target)
{
return match_package_internals::do_match(
- match_package_internals::sanitise_db(db),
+ match_package_internals::sanitise_env(env),
match_package_internals::sanitise_atom(atom),
match_package_internals::sanitise_target(target));
}
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index 5820172..99f844b 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -87,11 +87,15 @@ namespace paludis
* Our Repository instances.
*/
std::list<Repository::ConstPointer> repositories;
+
+ /// Our environment.
+ const Environment * environment;
};
}
-PackageDatabase::PackageDatabase() :
+PackageDatabase::PackageDatabase(const Environment * const e) :
PrivateImplementationPattern<PackageDatabase>(new Implementation<PackageDatabase>)
{
+ _imp->environment = e;
}
PackageDatabase::~PackageDatabase()
@@ -193,7 +197,7 @@ PackageDatabase::_do_query(const PackageDepAtom * const a, const InstallState in
for ( ; v != v_end ; ++v)
{
PackageDatabaseEntry e(a->package(), *v, r->name());
- if (! match_package(this, *a, e))
+ if (! match_package(_imp->environment, *a, e))
continue;
result->insert(e);
diff --git a/paludis/package_database.hh b/paludis/package_database.hh
index 8888cd7..a106893 100644
--- a/paludis/package_database.hh
+++ b/paludis/package_database.hh
@@ -50,6 +50,7 @@
namespace paludis
{
class PackageDepAtom;
+ class Environment;
/**
* A PackageDatabaseError is an error that occurs when performing some
@@ -265,7 +266,7 @@ namespace paludis
/**
* Constructor.
*/
- PackageDatabase();
+ explicit PackageDatabase(const Environment * const);
/**
* Destructor.
diff --git a/paludis/package_database_TEST.cc b/paludis/package_database_TEST.cc
index 695b569..a7249be 100644
--- a/paludis/package_database_TEST.cc
+++ b/paludis/package_database_TEST.cc
@@ -33,22 +33,6 @@ using namespace test;
namespace test_cases
{
/**
- * \test Basic PackageDatabase tests.
- *
- * \ingroup grptestcases
- */
- struct PackageDatabaseTest : TestCase
- {
- PackageDatabaseTest() : TestCase("package database") { }
-
- void run()
- {
- PackageDatabase p;
- TEST_CHECK(true);
- }
- } package_database_test;
-
- /**
* \test PackageDatabase repository tests.
*
* \ingroup grptestcases
@@ -59,7 +43,9 @@ namespace test_cases
void run()
{
- PackageDatabase p;
+ TestEnvironment e;
+ PackageDatabase & p(*e.package_database());
+
FakeRepository::Pointer r1(new FakeRepository(RepositoryName("repo1")));
FakeRepository::Pointer r2(new FakeRepository(RepositoryName("repo2")));
@@ -114,7 +100,9 @@ namespace test_cases
void run()
{
- PackageDatabase p;
+ TestEnvironment e;
+ PackageDatabase & p(*e.package_database());
+
FakeRepository::Pointer r1(new FakeRepository(RepositoryName("repo1")));
r1->add_version(CategoryNamePart("r1c1"), PackageNamePart("r1c1p1"), VersionSpec("1"));
r1->add_version(CategoryNamePart("r1c1"), PackageNamePart("r1c1p2"), VersionSpec("1"));
@@ -175,7 +163,9 @@ namespace test_cases
void run()
{
- PackageDatabase p;
+ TestEnvironment e;
+ PackageDatabase & p(*e.package_database());
+
FakeRepository::Pointer r1(new FakeRepository(RepositoryName("repo1")));
r1->add_package(CategoryNamePart("cat-one"), PackageNamePart("pkg-one"));
r1->add_package(CategoryNamePart("cat-one"), PackageNamePart("pkg-two"));
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 581b2ef..af2e5c8 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -641,7 +641,7 @@ PortageRepository::need_version_names(const QualifiedPackageName & n) const
vv != vv_end ; ++vv)
{
PackageDatabaseEntry e(i->second->package(), *vv, name());
- if (! match_package(_imp->db, i->second, e))
+ if (! match_package(_imp->env, i->second, e))
continue;
v->insert(*vv);
@@ -859,7 +859,7 @@ PortageRepository::do_query_repository_masks(const CategoryNamePart & c,
else
for (IndirectIterator<std::deque<PackageDepAtom::ConstPointer>::const_iterator, const PackageDepAtom>
k(r->second.begin()), k_end(r->second.end()) ; k != k_end ; ++k)
- if (match_package(_imp->db, *k, PackageDatabaseEntry(
+ if (match_package(_imp->env, *k, PackageDatabaseEntry(
QualifiedPackageName(c, p), v, name())))
return true;
diff --git a/paludis/test_environment.cc b/paludis/test_environment.cc
index 6e54d09..402af9b 100644
--- a/paludis/test_environment.cc
+++ b/paludis/test_environment.cc
@@ -28,7 +28,7 @@
using namespace paludis;
TestEnvironment::TestEnvironment() :
- Environment(PackageDatabase::Pointer(new PackageDatabase))
+ Environment(PackageDatabase::Pointer(new PackageDatabase(this)))
{
}