aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-11-11 16:28:56 +0000
committerAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-11-11 16:28:56 +0000
commitee5451e860fb571e4fadb7a865077d95bfaf9d24 (patch)
treebc06dec767f1cc71e580a69006508b672925a7f6
parent15e745302f54207940b8cf43e1aa1764b81e3bdb (diff)
downloadpaludis-ee5451e860fb571e4fadb7a865077d95bfaf9d24.tar.gz
paludis-ee5451e860fb571e4fadb7a865077d95bfaf9d24.tar.xz
Use Query to generate potential candidates for FuzzyCandidatesFinder
-rw-r--r--paludis/fuzzy_finder.cc40
-rw-r--r--paludis/fuzzy_finder.hh3
-rw-r--r--src/clients/adjutrix/find_reverse_deps.cc2
-rw-r--r--src/clients/adjutrix/what_needs_keywording.cc3
-rw-r--r--src/clients/paludis/do_contents.cc2
-rw-r--r--src/clients/paludis/query.cc2
-rw-r--r--src/clients/paludis/uninstall.cc3
-rw-r--r--src/output/console_install_task.cc23
8 files changed, 40 insertions, 38 deletions
diff --git a/paludis/fuzzy_finder.cc b/paludis/fuzzy_finder.cc
index 2e62a42..33cc715 100644
--- a/paludis/fuzzy_finder.cc
+++ b/paludis/fuzzy_finder.cc
@@ -24,8 +24,11 @@
#include <paludis/package_database.hh>
#include <paludis/environment.hh>
#include <paludis/repository.hh>
+#include <paludis/package_id.hh>
#include <paludis/name.hh>
+#include <paludis/query.hh>
#include <paludis/util/set.hh>
+#include <paludis/util/sequence.hh>
#include <list>
#include <algorithm>
#include <set>
@@ -63,11 +66,10 @@ namespace paludis
};
}
-FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::string & name) :
+FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::string & name, const Query & generator) :
PrivateImplementationPattern<FuzzyCandidatesFinder>(new Implementation<FuzzyCandidatesFinder>)
{
- std::string cat;
- std::string repo;
+ Query real_generator(generator);
std::string package(name);
if (std::string::npos != name.find('/'))
@@ -76,12 +78,12 @@ FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::s
if (pds.package_ptr())
{
- cat = stringify(pds.package_ptr()->category);
+ real_generator = real_generator & query::Category(pds.package_ptr()->category);
package = stringify(pds.package_ptr()->package);
}
if (pds.repository_ptr())
- repo = stringify(*pds.repository_ptr());
+ real_generator = real_generator & query::Repository(*pds.repository_ptr());
}
std::string package_0_cost(tolower_0_cost(package));
@@ -91,30 +93,14 @@ FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::s
QualifiedPackageNameSet potential_candidates;
- for (PackageDatabase::RepositoryConstIterator r(e.package_database()->begin_repositories()),
- r_end(e.package_database()->end_repositories()) ; r != r_end ; ++r)
+ tr1::shared_ptr<const PackageIDSequence> ids(e.package_database()->query(real_generator, qo_whatever));
+
+ for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end())
+ ; i != i_end ; ++i)
{
- if (! repo.empty() && repo != stringify((*r)->name()))
+ if (tolower(stringify((*i)->name().package)[0]) != tolower(package[0]))
continue;
-
- tr1::shared_ptr<const Repository> rr(e.package_database()->fetch_repository((*r)->name()));
-
- tr1::shared_ptr<const CategoryNamePartSet> cat_names(rr->category_names());
- for (CategoryNamePartSet::ConstIterator c(cat_names->begin()), c_end(cat_names->end()) ;
- c != c_end ; ++c)
- {
- if (! cat.empty() && cat != stringify(*c))
- continue;
-
- tr1::shared_ptr<const QualifiedPackageNameSet> packages(rr->package_names(*c));
- for (QualifiedPackageNameSet::ConstIterator p(packages->begin()), p_end(packages->end()) ;
- p != p_end ; ++p)
- {
- if (tolower(stringify(p->package)[0]) != tolower(package[0]))
- continue;
- potential_candidates.insert(*p);
- }
- }
+ potential_candidates.insert((*i)->name());
}
for (QualifiedPackageNameSet::ConstIterator p(potential_candidates.begin()), p_end(potential_candidates.end()) ;
diff --git a/paludis/fuzzy_finder.hh b/paludis/fuzzy_finder.hh
index 4bd97d5..c1afb4a 100644
--- a/paludis/fuzzy_finder.hh
+++ b/paludis/fuzzy_finder.hh
@@ -23,6 +23,7 @@
#include <paludis/environment-fwd.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
+#include <paludis/query-fwd.hh>
#include <paludis/name.hh>
#include <string>
@@ -46,7 +47,7 @@ namespace paludis
///\name Basic Operations
///\{
- FuzzyCandidatesFinder(const Environment & e, const std::string & name);
+ FuzzyCandidatesFinder(const Environment & e, const std::string & name, const Query & generator);
~FuzzyCandidatesFinder();
///\}
diff --git a/src/clients/adjutrix/find_reverse_deps.cc b/src/clients/adjutrix/find_reverse_deps.cc
index 8dd45d8..5a39ee9 100644
--- a/src/clients/adjutrix/find_reverse_deps.cc
+++ b/src/clients/adjutrix/find_reverse_deps.cc
@@ -286,7 +286,7 @@ int do_find_reverse_deps(NoConfigEnvironment & env)
cerr << " * " << e.backtrace("\n * ");
cerr << "Could not find '" << e.name() << "'. Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(env, e.name());
+ FuzzyCandidatesFinder f(env, e.name(), query::All());
if (f.begin() == f.end())
cerr << "No suggestions found." << endl;
diff --git a/src/clients/adjutrix/what_needs_keywording.cc b/src/clients/adjutrix/what_needs_keywording.cc
index 1a92d7d..62e4c3f 100644
--- a/src/clients/adjutrix/what_needs_keywording.cc
+++ b/src/clients/adjutrix/what_needs_keywording.cc
@@ -36,6 +36,7 @@
#include <paludis/metadata_key.hh>
#include <paludis/mask.hh>
#include <paludis/fuzzy_finder.hh>
+#include <paludis/query.hh>
#include <set>
#include <map>
@@ -101,7 +102,7 @@ int do_what_needs_keywording(NoConfigEnvironment & env)
cerr << " * " << e.backtrace("\n * ");
cerr << "Could not find '" << e.name() << "'. Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(env, e.name());
+ FuzzyCandidatesFinder f(env, e.name(), query::All());
if (f.begin() == f.end())
cerr << "No suggestions found." << endl;
diff --git a/src/clients/paludis/do_contents.cc b/src/clients/paludis/do_contents.cc
index 51a455f..b948845 100644
--- a/src/clients/paludis/do_contents.cc
+++ b/src/clients/paludis/do_contents.cc
@@ -155,7 +155,7 @@ do_contents(tr1::shared_ptr<Environment> env)
cerr << " * " << e.backtrace("\n * ");
cerr << "Could not find '" << e.name() << "'. Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(*env, e.name());
+ FuzzyCandidatesFinder f(*env, e.name(), query::InstalledAtRoot(env->root()));
if (f.begin() == f.end())
cerr << "No suggestions found." << endl;
diff --git a/src/clients/paludis/query.cc b/src/clients/paludis/query.cc
index d9087f2..a0ac5c4 100644
--- a/src/clients/paludis/query.cc
+++ b/src/clients/paludis/query.cc
@@ -191,7 +191,7 @@ int do_query(tr1::shared_ptr<Environment> env)
cerr << " * " << e.backtrace("\n * ");
cerr << "Could not find '" << e.name() << "'. Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(*env, e.name());
+ FuzzyCandidatesFinder f(*env, e.name(), query::All());
if (f.begin() == f.end())
cerr << "No suggestions found." << endl;
diff --git a/src/clients/paludis/uninstall.cc b/src/clients/paludis/uninstall.cc
index 912b535..e1d5b28 100644
--- a/src/clients/paludis/uninstall.cc
+++ b/src/clients/paludis/uninstall.cc
@@ -27,6 +27,7 @@
#include <paludis/package_database.hh>
#include <paludis/action.hh>
#include <paludis/fuzzy_finder.hh>
+#include <paludis/query.hh>
#include <iostream>
#include <limits>
@@ -295,7 +296,7 @@ namespace
cerr << " * " << e.backtrace("\n * ");
cerr << "Could not find '" << e.name() << "'. Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(*env, e.name());
+ FuzzyCandidatesFinder f(*env, e.name(), query::InstalledAtRoot(env->root()));
if (f.begin() == f.end())
cerr << "No suggestions found." << endl;
diff --git a/src/output/console_install_task.cc b/src/output/console_install_task.cc
index 1b40cbf..6d14b3d 100644
--- a/src/output/console_install_task.cc
+++ b/src/output/console_install_task.cc
@@ -181,7 +181,7 @@ ConsoleInstallTask::try_to_add_target(const std::string & s)
output_stream() << " * " << e.backtrace("\n * ");
output_stream() << "Could not find '" << e.name() << "'. Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(*environment(), e.name());
+ FuzzyCandidatesFinder f(*environment(), e.name(), query::SupportsAction<InstallAction>() & query::NotMasked());
if (f.begin() == f.end())
output_stream() << "No suggestions found." << endl;
@@ -1452,15 +1452,16 @@ ConsoleInstallTask::on_no_such_package_error(const NoSuchPackageError & e)
output_stream() << " * " << e.backtrace("\n * ");
output_stream() << "Could not find '" << e.name() << "'. Looking for suggestions:" << endl;
- FuzzyCandidatesFinder f(*environment(), e.name());
+ FuzzyCandidatesFinder f(*environment(), e.name(),
+ query::SupportsAction<InstallAction>() & query::NotMasked());
if (f.begin() == f.end())
output_stream() << "No suggestions found." << endl;
else
output_stream() << "Suggestions:" << endl;
- for (FuzzyCandidatesFinder::CandidatesConstIterator c(f.begin()),
- c_end(f.end()) ; c != c_end ; ++c)
+ for (FuzzyCandidatesFinder::CandidatesConstIterator c(f.begin()), c_end(f.end())
+ ; c != c_end ; ++c)
output_stream() << " * " << colour(cl_package_name, *c) << endl;
output_stream() << endl;
}
@@ -1478,7 +1479,19 @@ ConsoleInstallTask::on_all_masked_error(const AllMaskedError & e)
output_stream() << endl;
output_stream() << "Query error:" << endl;
output_stream() << " * " << e.backtrace("\n * ");
- output_stream() << "No versions of '" << e.query() << "' are available" << endl;
+ output_stream() << "No versions of '" << e.query() << "' are available. Looking for suggestions:" << endl;
+
+ FuzzyCandidatesFinder f(*environment(), stringify(e.query()),
+ query::SupportsAction<InstallAction>() & query::NotMasked());
+
+ if (f.begin() == f.end())
+ output_stream() << "No suggestions found." << endl;
+ else
+ output_stream() << "Suggestions:" << endl;
+
+ for (FuzzyCandidatesFinder::CandidatesConstIterator c(f.begin()), c_end(f.end())
+ ; c != c_end ; ++c)
+ output_stream() << " * " << colour(cl_package_name, *c) << endl;
}
else
{