aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 15:12:33 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 15:12:33 +0000
commitd3cbb77445129d11d71756c35ea16545f8b2e5c6 (patch)
treec78edb11b218271cebcce459e2b1c9061fb7f7f8
parent41ab83381f30ecfbb48abadb1b89b465b0392e3b (diff)
downloadpaludis-d3cbb77445129d11d71756c35ea16545f8b2e5c6.tar.gz
paludis-d3cbb77445129d11d71756c35ea16545f8b2e5c6.tar.xz
Unify package matching algorithm
-rw-r--r--paludis/default_environment.cc24
-rw-r--r--paludis/dep_list.cc37
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/match_package.cc50
-rw-r--r--paludis/match_package.hh95
-rw-r--r--paludis/package_database.cc12
-rw-r--r--paludis/portage_repository.cc2
7 files changed, 173 insertions, 48 deletions
diff --git a/paludis/default_environment.cc b/paludis/default_environment.cc
index 193c4c1..62d2e28 100644
--- a/paludis/default_environment.cc
+++ b/paludis/default_environment.cc
@@ -22,6 +22,7 @@
#include "portage_repository.hh"
#include "default_config.hh"
#include "stringify.hh"
+#include "match_package.hh"
#include <list>
#include <vector>
@@ -36,7 +37,7 @@ DefaultEnvironment::DefaultEnvironment() :
for (DefaultConfig::RepositoryIterator r(DefaultConfig::get_instance()->begin_repositories()),
r_end(DefaultConfig::get_instance()->end_repositories()) ; r != r_end ; ++r)
{
- /// \todo abstract factory
+ /// \todo class factory
if (r->get<rce_format>() != "portage")
throw DefaultConfigError("Unknown repository format '" + r->get<rce_format>() + "'");
Repository::Pointer repo(new PortageRepository(r->get<rce_location>(),
@@ -133,13 +134,8 @@ DefaultEnvironment::accept_keyword(const KeywordName & keyword, const PackageDat
k_end(DefaultConfig::get_instance()->end_package_keywords(d->get<pde_package>())) ;
k != k_end ; ++k)
{
- if (k->first->package() != d->get<pde_package>())
+ if (! match_package(package_db(), k->first, d))
continue;
- if (k->first->version_spec_ptr() && ! (((d->get<pde_version>()).*
- (k->first->version_operator().as_version_spec_operator()))
- (*k->first->version_spec_ptr())))
- continue;
- /// \bug slot
result |= k->second == keyword;
}
@@ -160,13 +156,8 @@ DefaultEnvironment::query_user_masks(const PackageDatabaseEntry & d) const
k_end(DefaultConfig::get_instance()->end_user_masks(d.get<pde_package>())) ;
k != k_end ; ++k)
{
- if (k->package() != d.get<pde_package>())
- continue;
- if (k->version_spec_ptr() && ! (((d.get<pde_version>()).*
- (k->version_operator().as_version_spec_operator()))
- (*k->version_spec_ptr())))
+ if (! match_package(package_db(), *k, d))
continue;
- /// \bug slot
return true;
}
@@ -182,13 +173,8 @@ DefaultEnvironment::query_user_unmasks(const PackageDatabaseEntry & d) const
k_end(DefaultConfig::get_instance()->end_user_unmasks(d.get<pde_package>())) ;
k != k_end ; ++k)
{
- if (k->package() != d.get<pde_package>())
- continue;
- if (k->version_spec_ptr() && ! (((d.get<pde_version>()).*
- (k->version_operator().as_version_spec_operator()))
- (*k->version_spec_ptr())))
+ if (! match_package(package_db(), *k, d))
continue;
- /// \bug slot
return true;
}
diff --git a/paludis/dep_list.cc b/paludis/dep_list.cc
index cc0f4b4..351a706 100644
--- a/paludis/dep_list.cc
+++ b/paludis/dep_list.cc
@@ -17,19 +17,20 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "dep_list.hh"
-#include "dep_parser.hh"
#include "all_dep_atom.hh"
#include "any_dep_atom.hh"
#include "block_dep_atom.hh"
-#include "use_dep_atom.hh"
-#include "package_dep_atom.hh"
-#include "stringify.hh"
#include "container_entry.hh"
-#include "save.hh"
+#include "dep_list.hh"
+#include "dep_parser.hh"
+#include "filter_insert_iterator.hh"
#include "indirect_iterator.hh"
#include "join.hh"
-#include "filter_insert_iterator.hh"
+#include "match_package.hh"
+#include "package_dep_atom.hh"
+#include "save.hh"
+#include "stringify.hh"
+#include "use_dep_atom.hh"
#include <algorithm>
#include <functional>
@@ -179,25 +180,18 @@ DepList::visit(const AllDepAtom * const v)
struct DepListEntryMatcher :
public std::unary_function<bool, const DepListEntry &>
{
+ const PackageDatabase * const db;
const PackageDepAtom & atom;
- DepListEntryMatcher(const PackageDepAtom & p) :
+ DepListEntryMatcher(const PackageDatabase * const d, const PackageDepAtom & p) :
+ db(d),
atom(p)
{
}
bool operator() (const DepListEntry & e) const
{
- if (e.get<dle_name>() != atom.package())
- return false;
- if (atom.slot_ptr())
- if (e.get<dle_slot>() != *atom.slot_ptr())
- return false;
- if (atom.version_spec_ptr())
- if (! (((e.get<dle_version>()).*(atom.version_operator().as_version_spec_operator()))(
- *atom.version_spec_ptr())))
- return false;
- return true;
+ return match_package(db, atom, e);
}
};
#endif
@@ -218,7 +212,7 @@ DepList::visit(const PackageDepAtom * const p)
/* will we be installed by this point? */
if ((! already_there) && (_implementation->merge_list.end() != std::find_if(
_implementation->merge_list.begin(), _implementation->merge_list.end(),
- DepListEntryMatcher(*p))))
+ DepListEntryMatcher(_implementation->environment->package_db().raw_pointer(), *p))))
return;
if (already_there && ((! _implementation->recursive_deps) || (_implementation->check_existing_only)))
@@ -236,7 +230,7 @@ DepList::visit(const PackageDepAtom * const p)
std::list<DepListEntry>::iterator i;
if (_implementation->pending_list.end() != ((i = std::find_if(
_implementation->pending_list.begin(), _implementation->pending_list.end(),
- DepListEntryMatcher(*p)))))
+ DepListEntryMatcher(_implementation->environment->package_db().raw_pointer(), *p)))))
{
std::list<std::string> entries;
entries.push_front(stringify(*p));
@@ -458,7 +452,8 @@ DepList::visit(const BlockDepAtom * const d)
/* will we be installed by this point? */
if (_implementation->merge_list.end() != ((m = std::find_if(
_implementation->merge_list.begin(), _implementation->merge_list.end(),
- DepListEntryMatcher(*(d->blocked_atom()))))))
+ DepListEntryMatcher(_implementation->environment->package_db().raw_pointer(),
+ *(d->blocked_atom()))))))
{
if (! _implementation->current_package)
throw BlockError("'" + stringify(*(d->blocked_atom())) + "' blocked by pending package '"
diff --git a/paludis/files.m4 b/paludis/files.m4
index 547f422..fd72f8a 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -52,6 +52,7 @@ add(`key_value_config_file', `hh', `cc', `test')
add(`keyword_name', `hh', `cc')
add(`line_config_file', `hh', `cc', `test')
add(`mask_reasons', `hh', `cc')
+add(`match_package', `hh', `cc')
add(`name_error', `hh', `cc')
add(`package_database', `hh', `cc', `test')
add(`package_dep_atom', `hh', `cc')
diff --git a/paludis/match_package.cc b/paludis/match_package.cc
new file mode 100644
index 0000000..a913d9c
--- /dev/null
+++ b/paludis/match_package.cc
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+#include "match_package.hh"
+
+using namespace paludis;
+
+bool
+match_package_internals::do_match(
+ const PackageDatabase * const db,
+ const PackageDepAtom * const atom,
+ const PackageDatabaseEntry * const entry)
+{
+ if (atom->package() != entry->get<pde_package>())
+ return false;
+
+ if (atom->version_spec_ptr() && ! (((entry->get<pde_version>()).*
+ (atom->version_operator().as_version_spec_operator()))
+ (*atom->version_spec_ptr())))
+ return false;
+
+ if (atom->slot_ptr())
+ {
+ VersionMetadata::ConstPointer metadata(db->fetch_metadata(*entry));
+ if (*atom->slot_ptr() != SlotName(metadata->get(vmk_slot)))
+ return false;
+ }
+
+ return true;
+}
+
+bool
+match_package_internals::do_match(
+ const PackageDatabase * const db,
+ const PackageDepAtom * const atom,
+ const DepListEntry * const entry)
+{
+ if (atom->package() != entry->get<dle_name>())
+ return false;
+
+ if (atom->version_spec_ptr() && ! (((entry->get<dle_version>()).*
+ (atom->version_operator().as_version_spec_operator()))
+ (*atom->version_spec_ptr())))
+ return false;
+
+ if (atom->slot_ptr() && (*atom->slot_ptr() != entry->get<dle_slot>()))
+ return false;
+
+ return true;
+
+}
diff --git a/paludis/match_package.hh b/paludis/match_package.hh
new file mode 100644
index 0000000..c2752b0
--- /dev/null
+++ b/paludis/match_package.hh
@@ -0,0 +1,95 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+#ifndef PALUDIS_GUARD_PALUDIS_MATCH_PACKAGE_HH
+#define PALUDIS_GUARD_PALUDIS_MATCH_PACKAGE_HH 1
+
+/** \file
+ * Declare the match_package function.
+ *
+ * Do not merge this file into dep_atom. It will cause all sorts of horrible
+ * circular dependency issues. Avoid including this file in headers if at all
+ * possible.
+ */
+
+#include <paludis/package_database.hh>
+#include <paludis/package_dep_atom.hh>
+#include <paludis/dep_list.hh>
+
+namespace paludis
+{
+ namespace match_package_internals
+ {
+ bool do_match(
+ const PackageDatabase * const db,
+ const PackageDepAtom * const atom,
+ const PackageDatabaseEntry * const entry);
+
+ bool do_match(
+ const PackageDatabase * const db,
+ const PackageDepAtom * const atom,
+ const DepListEntry * const entry);
+
+ inline const PackageDatabase * sanitise_db(const PackageDatabase * db)
+ {
+ return db;
+ }
+
+ inline const PackageDatabase * sanitise_db(const PackageDatabase & db)
+ {
+ return &db;
+ }
+
+ template <typename P1_, typename P2_>
+ inline const PackageDatabase * sanitise_db(const CountedPtr<const PackageDatabase, P1_, P2_> db)
+ {
+ return db.raw_pointer();
+ }
+
+ inline const PackageDatabase * sanitise_db(const PackageDatabase::ConstPointer db)
+ {
+ return db.raw_pointer();
+ }
+
+ inline const PackageDepAtom * sanitise_atom(const PackageDepAtom * atom)
+ {
+ return atom;
+ }
+
+ inline const PackageDepAtom * sanitise_atom(const PackageDepAtom & atom)
+ {
+ return &atom;
+ }
+
+ template <typename P1_, typename P2_>
+ inline const PackageDepAtom * sanitise_atom(const CountedPtr<const PackageDepAtom, P1_, P2_> atom)
+ {
+ return atom.raw_pointer();
+ }
+
+ template <typename T_>
+ inline const T_ * sanitise_target(const T_ * e)
+ {
+ return e;
+ }
+
+ template <typename T_>
+ inline const T_ * sanitise_target(const T_ & e)
+ {
+ return &e;
+ }
+ }
+
+ template <typename DB_, typename Atom_, typename Target_>
+ bool match_package(
+ const DB_ & db,
+ const Atom_ & atom,
+ const Target_ & target)
+ {
+ return match_package_internals::do_match(
+ match_package_internals::sanitise_db(db),
+ match_package_internals::sanitise_atom(atom),
+ match_package_internals::sanitise_target(target));
+ }
+}
+
+#endif
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index 39887b4..45fff63 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -21,6 +21,7 @@
#include "package_dep_atom.hh"
#include "indirect_iterator.hh"
#include "stringify.hh"
+#include "match_package.hh"
#include <list>
#include <map>
@@ -178,14 +179,11 @@ PackageDatabase::query(const PackageDepAtom * const a) const
VersionSpecCollection::Iterator v(versions->begin()), v_end(versions->end());
for ( ; v != v_end ; ++v)
{
- if (a->version_spec_ptr())
- if (! ((*v).*(a->version_operator().as_version_spec_operator()))(*a->version_spec_ptr()))
- continue;
+ PackageDatabaseEntry e(a->package(), *v, r->name());
+ if (! match_package(this, *a, e))
+ continue;
- /// \bug SLOT etc
-
- if (! result->insert(PackageDatabaseEntry(a->package(), *v, r->name())))
- ; /// \bug exception
+ result->insert(e);
}
}
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index d5909af..bdbf989 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -404,7 +404,7 @@ PortageRepository::do_version_metadata(
result->set(vmk_keywords, "*");
}
else
- throw InternalError(PALUDIS_HERE, "not implemented"); /// \todo
+ throw InternalError(PALUDIS_HERE, "no cache handling not implemented"); /// \todo
_implementation->metadata.insert(std::make_pair(std::make_pair(QualifiedPackageName(c, p), v), result));
return result;