aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-03 12:22:24 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-03 12:22:24 +0100
commit37d9cd6f1689f0f004302cceb198fd9b18373264 (patch)
treee13cf7cfb6715490cc807871732b4f9b25080fd2
parent72e656ca1a79aaf34a56fb91b849ffd99c11b65f (diff)
downloadpaludis-37d9cd6f1689f0f004302cceb198fd9b18373264.tar.gz
paludis-37d9cd6f1689f0f004302cceb198fd9b18373264.tar.xz
cave search --matching
Fixes: ticket:905
-rw-r--r--src/clients/cave/cmd_find_candidates.cc136
-rw-r--r--src/clients/cave/cmd_search_cmdline.cc3
-rw-r--r--src/clients/cave/cmd_search_cmdline.hh1
3 files changed, 90 insertions, 50 deletions
diff --git a/src/clients/cave/cmd_find_candidates.cc b/src/clients/cave/cmd_find_candidates.cc
index 9d4825f..ee798ef 100644
--- a/src/clients/cave/cmd_find_candidates.cc
+++ b/src/clients/cave/cmd_find_candidates.cc
@@ -28,6 +28,7 @@
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/wrapped_output_iterator.hh>
#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/make_shared_copy.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/simple_visitor_cast.hh>
#include <paludis/generator.hh>
@@ -90,6 +91,19 @@ namespace
void no_step(const std::string &)
{
}
+
+ void check_candidates(
+ const std::tr1::function<void (const PackageDepSpec &)> & yield,
+ const std::tr1::function<void (const std::string &)> & step,
+ const std::tr1::shared_ptr<const PackageIDSequence> & ids)
+ {
+ for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
+ i != i_end ; ++i)
+ {
+ step("Checking candidates");
+ yield((*i)->uniquely_identifying_spec());
+ }
+ }
}
int
@@ -131,71 +145,95 @@ FindCandidatesCommand::run_hosted(
const std::tr1::function<void (const PackageDepSpec &)> & yield,
const std::tr1::function<void (const std::string &)> & step)
{
- step("Searching repositories");
+ if (! search_options.a_matching.specified())
+ {
+ step("Searching repositories");
- RepositoryNames repository_names;
- for (PackageDatabase::RepositoryConstIterator r(env->package_database()->begin_repositories()),
- r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
- repository_names.insert((*r)->name());
+ RepositoryNames repository_names;
+ for (PackageDatabase::RepositoryConstIterator r(env->package_database()->begin_repositories()),
+ r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
+ repository_names.insert((*r)->name());
- step("Searching categories");
+ step("Searching categories");
- CategoryNames category_names;
- for (RepositoryNames::const_iterator r(repository_names.begin()), r_end(repository_names.end()) ;
- r != r_end ; ++r)
- {
- const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
- const std::tr1::shared_ptr<const CategoryNamePartSet> cats(repo->category_names());
- std::copy(cats->begin(), cats->end(), std::inserter(category_names, category_names.end()));
- }
+ CategoryNames category_names;
+ for (RepositoryNames::const_iterator r(repository_names.begin()), r_end(repository_names.end()) ;
+ r != r_end ; ++r)
+ {
+ const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
+ const std::tr1::shared_ptr<const CategoryNamePartSet> cats(repo->category_names());
+ std::copy(cats->begin(), cats->end(), std::inserter(category_names, category_names.end()));
+ }
- step("Searching packages");
+ step("Searching packages");
- QualifiedPackageNames package_names;
- for (RepositoryNames::const_iterator r(repository_names.begin()), r_end(repository_names.end()) ;
- r != r_end ; ++r)
- {
- const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
- for (CategoryNames::const_iterator c(category_names.begin()), c_end(category_names.end()) ;
- c != c_end ; ++c)
+ QualifiedPackageNames package_names;
+ for (RepositoryNames::const_iterator r(repository_names.begin()), r_end(repository_names.end()) ;
+ r != r_end ; ++r)
{
- const std::tr1::shared_ptr<const QualifiedPackageNameSet> qpns(repo->package_names(*c));
- std::copy(qpns->begin(), qpns->end(), std::inserter(package_names, package_names.end()));
+ const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
+ for (CategoryNames::const_iterator c(category_names.begin()), c_end(category_names.end()) ;
+ c != c_end ; ++c)
+ {
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> qpns(repo->package_names(*c));
+ std::copy(qpns->begin(), qpns->end(), std::inserter(package_names, package_names.end()));
+ }
}
- }
- step("Searching versions");
+ step("Searching versions");
- for (QualifiedPackageNames::const_iterator q(package_names.begin()), q_end(package_names.end()) ;
- q != q_end ; ++q)
- {
- if (search_options.a_all_versions.specified())
+ for (QualifiedPackageNames::const_iterator q(package_names.begin()), q_end(package_names.end()) ;
+ q != q_end ; ++q)
{
- const std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsUnsorted(
- generator::Package(*q))]);
- for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
- i != i_end ; ++i)
+ if (search_options.a_all_versions.specified())
{
- step("Checking candidates");
- yield((*i)->uniquely_identifying_spec());
+ const std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsUnsorted(
+ generator::Package(*q))]);
+ check_candidates(yield, step, ids);
+ }
+ else
+ {
+ std::tr1::shared_ptr<const PackageIDSequence> ids;
+
+ ids = ((*env)[selection::BestVersionOnly(generator::Package(*q) | filter::SupportsAction<InstallAction>() | filter::NotMasked())]);
+ if (ids->empty())
+ ids = ((*env)[selection::BestVersionOnly(generator::Package(*q) | filter::SupportsAction<InstallAction>())]);
+ if (ids->empty())
+ ids = ((*env)[selection::BestVersionOnly(generator::Package(*q))]);
+
+ check_candidates(yield, step, ids);
}
}
- else
+ }
+ else
+ {
+ step("Searching matches");
+
+ std::tr1::shared_ptr<Generator> match_generator;
+
+ for (args::StringSetArg::ConstIterator k(search_options.a_matching.begin_args()),
+ k_end(search_options.a_matching.end_args()) ;
+ k != k_end ; ++k)
{
- std::tr1::shared_ptr<const PackageIDSequence> ids;
+ generator::Matches m(parse_user_package_dep_spec(*k, env.get(), UserPackageDepSpecOptions() + updso_allow_wildcards), MatchPackageOptions());
- ids = ((*env)[selection::BestVersionOnly(generator::Package(*q) | filter::SupportsAction<InstallAction>() | filter::NotMasked())]);
- if (ids->empty())
- ids = ((*env)[selection::BestVersionOnly(generator::Package(*q) | filter::SupportsAction<InstallAction>())]);
- if (ids->empty())
- ids = ((*env)[selection::BestVersionOnly(generator::Package(*q))]);
+ if (match_generator)
+ match_generator = make_shared_ptr(new generator::Union(*match_generator, m));
+ else
+ match_generator = make_shared_copy(m);
+ }
- for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
- i != i_end ; ++i)
- {
- step("Checking candidates");
- yield((*i)->uniquely_identifying_spec());
- }
+ if (search_options.a_all_versions.specified())
+ {
+ const std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsUnsorted(
+ *match_generator)]);
+ check_candidates(yield, step, ids);
+ }
+ else
+ {
+ const std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::BestVersionOnly(
+ *match_generator)]);
+ check_candidates(yield, step, ids);
}
}
}
diff --git a/src/clients/cave/cmd_search_cmdline.cc b/src/clients/cave/cmd_search_cmdline.cc
index 89f58b4..cdc08c5 100644
--- a/src/clients/cave/cmd_search_cmdline.cc
+++ b/src/clients/cave/cmd_search_cmdline.cc
@@ -26,7 +26,8 @@ SearchCommandLineCandidateOptions::SearchCommandLineCandidateOptions(args::ArgsH
ArgsSection(h, "Search Candidate Options"),
g_candidate_options(this, "Candidate Options", "Control which packages and versions are selected as "
"candidates for matching."),
- a_all_versions(&g_candidate_options, "all-versions", 'a', "Search in every version of packages", true)
+ a_all_versions(&g_candidate_options, "all-versions", 'a', "Search in every version of packages", true),
+ a_matching(&g_candidate_options, "matching", 'm', "Search only in packages matching the supplied specification")
{
}
diff --git a/src/clients/cave/cmd_search_cmdline.hh b/src/clients/cave/cmd_search_cmdline.hh
index dda27a1..cbb99e9 100644
--- a/src/clients/cave/cmd_search_cmdline.hh
+++ b/src/clients/cave/cmd_search_cmdline.hh
@@ -35,6 +35,7 @@ namespace paludis
args::ArgsGroup g_candidate_options;
args::SwitchArg a_all_versions;
+ args::StringSetArg a_matching;
};
struct SearchCommandLineMatchOptions :