aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-06-28 00:08:57 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-06-28 00:08:57 +0000
commit0658bb4953134d28a58264a3222c410e7b64d41d (patch)
treed1d87de749aee80cf216f0d9d8ae0752b7e0732f
parent15f07ae3e9aacd865f96117d2633e54f2128f11f (diff)
downloadpaludis-0658bb4953134d28a58264a3222c410e7b64d41d.tar.gz
paludis-0658bb4953134d28a58264a3222c410e7b64d41d.tar.xz
r3626@snowflake: ciaranm | 2007-06-28 01:08:33 +0100
Fix --query output. Fixes: ticket:298
-rw-r--r--src/clients/inquisitio/do_search.cc2
-rw-r--r--src/output/console_install_task.cc15
-rw-r--r--src/output/console_query_task.cc102
-rw-r--r--src/output/console_query_task.hh20
-rw-r--r--src/output/use_flag_pretty_printer.cc36
-rw-r--r--src/output/use_flag_pretty_printer.hh6
6 files changed, 122 insertions, 59 deletions
diff --git a/src/clients/inquisitio/do_search.cc b/src/clients/inquisitio/do_search.cc
index f27d85c..8de8e25 100644
--- a/src/clients/inquisitio/do_search.cc
+++ b/src/clients/inquisitio/do_search.cc
@@ -127,7 +127,7 @@ do_search(const Environment & env)
InquisitioQueryTask query(&env);
query.show(PackageDepSpec(
tr1::shared_ptr<QualifiedPackageName>(new QualifiedPackageName(display_entry->name()))),
- display_entry.get());
+ display_entry);
}
return 0;
diff --git a/src/output/console_install_task.cc b/src/output/console_install_task.cc
index 1a961ae..da3ef7a 100644
--- a/src/output/console_install_task.cc
+++ b/src/output/console_install_task.cc
@@ -945,8 +945,19 @@ ConsoleInstallTask::display_merge_list_entry_use(const DepListEntry & d,
output_no_endl(" ");
tr1::shared_ptr<UseFlagPrettyPrinter> printer(make_use_flag_pretty_printer());
- printer->print_package_flags(*d.package_id, ! existing_slot_repo->empty() ? existing_slot_repo->last()->get() :
- ! existing_repo->empty() ? existing_repo->last()->get() : 0);
+ tr1::shared_ptr<const PackageID> old_id;
+ tr1::shared_ptr<const IUseFlagCollection> old;
+
+ if (! existing_slot_repo->empty())
+ old_id = *existing_slot_repo->last();
+ else if (! existing_repo->empty())
+ old_id = *existing_repo->last();
+
+ if (old_id && old_id->iuse_key())
+ old = old_id->iuse_key()->value();
+
+ if (d.package_id->iuse_key())
+ printer->print_package_flags(d.package_id, d.package_id->iuse_key()->value(), old_id, old);
_add_descriptions(printer->new_flags(), d.package_id, uds_new);
_add_descriptions(printer->changed_flags(), d.package_id, uds_changed);
diff --git a/src/output/console_query_task.cc b/src/output/console_query_task.cc
index 9383421..e092138 100644
--- a/src/output/console_query_task.cc
+++ b/src/output/console_query_task.cc
@@ -32,6 +32,8 @@
#include <paludis/eapi.hh>
#include <paludis/package_database.hh>
#include <paludis/dep_spec_pretty_printer.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_id.hh>
#include <list>
using namespace paludis;
@@ -61,7 +63,7 @@ ConsoleQueryTask::~ConsoleQueryTask()
}
void
-ConsoleQueryTask::show(const PackageDepSpec & a, const PackageID * display_entry) const
+ConsoleQueryTask::show(const PackageDepSpec & a, tr1::shared_ptr<const PackageID> display_entry) const
{
/* prefer the best installed version, then the best visible version, then
* the best version */
@@ -76,33 +78,33 @@ ConsoleQueryTask::show(const PackageDepSpec & a, const PackageID * display_entry
if (! display_entry)
{
- display_entry = preferred_entries->last()->get();
+ display_entry = *preferred_entries->last();
for (PackageIDSequence::Iterator i(preferred_entries->begin()),
i_end(preferred_entries->end()) ; i != i_end ; ++i)
if (! _imp->env->mask_reasons(**i).any())
- display_entry = i->get();
+ display_entry = *i;
}
- display_header(a, *display_entry);
- display_versions_by_repository(a, entries, *display_entry);
- display_metadata(a, *display_entry);
+ display_header(a, display_entry);
+ display_versions_by_repository(a, entries, display_entry);
+ display_metadata(a, display_entry);
output_endl();
}
void
-ConsoleQueryTask::display_header(const PackageDepSpec & a, const PackageID & e) const
+ConsoleQueryTask::display_header(const PackageDepSpec & a, const tr1::shared_ptr<const PackageID> & e) const
{
if (a.version_requirements_ptr() || a.slot_ptr() || a.use_requirements_ptr() ||
a.repository_ptr())
output_starred_item(render_as_package_name(stringify(a)));
else
- output_starred_item(render_as_package_name(stringify(e.name())));
+ output_starred_item(render_as_package_name(stringify(e->name())));
}
void
ConsoleQueryTask::display_versions_by_repository(const PackageDepSpec &,
tr1::shared_ptr<const PackageIDSequence> entries,
- const PackageID & display_entry) const
+ const tr1::shared_ptr<const PackageID> & display_entry) const
{
/* find all repository names. */
RepositoryNameCollection::Concrete repo_names;
@@ -182,7 +184,7 @@ ConsoleQueryTask::display_versions_by_repository(const PackageDepSpec &,
right_column.append(render_as_masked("(" + (*e)->canonical_form(idcf_version) + ")" + reasons));
}
- if (**e == display_entry)
+ if (**e == *display_entry)
right_column.append("*");
right_column.append(" ");
}
@@ -202,73 +204,112 @@ namespace
{
private:
const ConsoleQueryTask * const task;
+ const tr1::shared_ptr<const PackageID> id;
+ const MetadataKeyType type;
public:
- Displayer(const ConsoleQueryTask * const t) :
- task(t)
+ Displayer(const ConsoleQueryTask * const t, const tr1::shared_ptr<const PackageID> & i, const MetadataKeyType k) :
+ task(t),
+ id(i),
+ type(k)
{
}
- void visit(const MetadataCollectionKey<IUseFlagCollection> &)
+ void visit(const MetadataCollectionKey<IUseFlagCollection> & k)
{
+ if (k.type() == type)
+ task->display_metadata_iuse(k.human_name(), k.raw_name(), join(k.value()->begin(), k.value()->end(), " "),
+ id, k.value());
}
- void visit(const MetadataCollectionKey<InheritedCollection> &)
+ void visit(const MetadataCollectionKey<InheritedCollection> & k)
{
+ if (k.type() == type)
+ task->display_metadata_key(k.human_name(), k.raw_name(), join(k.value()->begin(), k.value()->end(), " "));
}
- void visit(const MetadataCollectionKey<UseFlagNameCollection> &)
+ void visit(const MetadataCollectionKey<UseFlagNameCollection> & k)
{
+ if (k.type() == type)
+ task->display_metadata_key(k.human_name(), k.raw_name(), join(k.value()->begin(), k.value()->end(), " "));
}
- void visit(const MetadataCollectionKey<KeywordNameCollection> &)
+ void visit(const MetadataCollectionKey<KeywordNameCollection> & k)
{
+ if (k.type() == type)
+ task->display_metadata_key(k.human_name(), k.raw_name(), join(k.value()->begin(), k.value()->end(), " "));
}
void visit(const MetadataSpecTreeKey<DependencySpecTree> & k)
{
- task->display_metadata_dependency(k.human_name(), k.raw_name(), k.value(), false);
+ if (k.type() == type)
+ task->display_metadata_dependency(k.human_name(), k.raw_name(), k.value(), false);
}
- void visit(const MetadataSpecTreeKey<URISpecTree> &)
+ void visit(const MetadataSpecTreeKey<URISpecTree> & k)
{
+ if (k.type() == type)
+ task->display_metadata_uri(k.human_name(), k.raw_name(), k.value(), true);
}
- void visit(const MetadataSpecTreeKey<LicenseSpecTree> &)
+ void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k)
{
+ if (k.type() == type)
+ task->display_metadata_license(k.human_name(), k.raw_name(), k.value(), id);
}
- void visit(const MetadataSpecTreeKey<ProvideSpecTree> &)
+ void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k)
{
+ if (k.type() == type)
+ task->display_metadata_provides(k.human_name(), k.raw_name(), k.value(), true);
}
- void visit(const MetadataSpecTreeKey<RestrictSpecTree> &)
+ void visit(const MetadataSpecTreeKey<RestrictSpecTree> & k)
{
+ if (k.type() == type)
+ task->display_metadata_restrict(k.human_name(), k.raw_name(), k.value(), true);
}
void visit(const MetadataPackageIDKey & k)
{
- task->display_metadata_pde(k.human_name(), k.raw_name(), *k.value());
+ if (k.type() == type)
+ task->display_metadata_pde(k.human_name(), k.raw_name(), *k.value());
}
void visit(const MetadataStringKey & k)
{
- task->display_metadata_key(k.human_name(), k.raw_name(), k.value());
+ if (k.type() == type)
+ task->display_metadata_key(k.human_name(), k.raw_name(), k.value());
}
};
}
void
-ConsoleQueryTask::display_metadata(const PackageDepSpec &, const PackageID & id) const
+ConsoleQueryTask::display_metadata(const PackageDepSpec &, const tr1::shared_ptr<const PackageID> & id) const
{
- if (! id.eapi()->supported)
+ if (! id->eapi()->supported)
{
- display_metadata_key("EAPI", "EAPI", id.eapi()->name);
+ display_metadata_key("EAPI", "EAPI", id->eapi()->name);
return;
}
- Displayer d(this);
- std::for_each(id.begin(), id.end(), accept_visitor(d));
+ Displayer ds(this, id, mkt_significant);
+ std::for_each(id->begin(), id->end(), accept_visitor(ds));
+
+ Displayer dn(this, id, mkt_normal);
+ std::for_each(id->begin(), id->end(), accept_visitor(dn));
+
+ if (want_deps() || want_raw())
+ {
+ Displayer dd(this, id, mkt_dependencies);
+ std::for_each(id->begin(), id->end(), accept_visitor(dd));
+ }
+
+ if (want_raw())
+ {
+ Displayer dr(this, id, mkt_internal);
+ std::for_each(id->begin(), id->end(), accept_visitor(dr));
+ }
}
namespace
@@ -448,7 +489,8 @@ ConsoleQueryTask::display_metadata_time(const std::string & k, const std::string
void
ConsoleQueryTask::display_metadata_iuse(const std::string & k, const std::string & kk,
- const std::string & v, const PackageID & e) const
+ const std::string & v, const tr1::shared_ptr<const PackageID> & id,
+ const tr1::shared_ptr<const IUseFlagCollection> & e) const
{
if (v.empty())
return;
@@ -460,7 +502,7 @@ ConsoleQueryTask::display_metadata_iuse(const std::string & k, const std::string
else
{
UseFlagPrettyPrinter printer(_imp->env);
- printer.print_package_flags(e);
+ printer.print_package_flags(id, e);
output_right_column("");
}
}
diff --git a/src/output/console_query_task.hh b/src/output/console_query_task.hh
index 81eca3d..d729e51 100644
--- a/src/output/console_query_task.hh
+++ b/src/output/console_query_task.hh
@@ -20,8 +20,13 @@
#ifndef PALUDIS_GUARD_SRC_OUTPUT_CONSOLE_QUERY_TASK_HH
#define PALUDIS_GUARD_SRC_OUTPUT_CONSOLE_QUERY_TASK_HH 1
-#include <paludis/environment.hh>
-#include <paludis/dep_spec.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/metadata_key-fwd.hh>
+#include <paludis/name-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/mask_reasons.hh>
+#include <paludis/util/private_implementation_pattern.hh>
#include <src/output/console_task.hh>
namespace paludis
@@ -36,12 +41,12 @@ namespace paludis
public:
virtual ~ConsoleQueryTask();
- virtual void show(const PackageDepSpec &, const PackageID * = 0) const;
+ virtual void show(const PackageDepSpec &, tr1::shared_ptr<const PackageID> = tr1::shared_ptr<const PackageID>()) const;
- virtual void display_header(const PackageDepSpec &, const PackageID &) const;
+ virtual void display_header(const PackageDepSpec &, const tr1::shared_ptr<const PackageID> &) const;
virtual void display_versions_by_repository(const PackageDepSpec &,
- tr1::shared_ptr<const PackageIDSequence>, const PackageID &) const;
- virtual void display_metadata(const PackageDepSpec &, const PackageID &) const;
+ tr1::shared_ptr<const PackageIDSequence>, const tr1::shared_ptr<const PackageID> &) const;
+ virtual void display_metadata(const PackageDepSpec &, const tr1::shared_ptr<const PackageID> &) const;
virtual void display_metadata_key(const std::string &, const std::string &,
const std::string &) const;
@@ -58,7 +63,8 @@ namespace paludis
virtual void display_metadata_pde(const std::string &, const std::string &, const PackageID &) const;
virtual void display_metadata_time(const std::string &, const std::string &, time_t) const;
virtual void display_metadata_iuse(const std::string &, const std::string &, const std::string &,
- const PackageID &) const;
+ const tr1::shared_ptr<const PackageID> & id,
+ const tr1::shared_ptr<const IUseFlagCollection> &) const;
virtual bool want_deps() const = 0;
virtual bool want_raw() const = 0;
diff --git a/src/output/use_flag_pretty_printer.cc b/src/output/use_flag_pretty_printer.cc
index 49aea96..79c3117 100644
--- a/src/output/use_flag_pretty_printer.cc
+++ b/src/output/use_flag_pretty_printer.cc
@@ -58,22 +58,22 @@ UseFlagPrettyPrinter::use_expand_delim_pos(const UseFlagName & u,
}
void
-UseFlagPrettyPrinter::print_package_flags(const PackageID & pkg,
- const PackageID * const old_pkg)
+UseFlagPrettyPrinter::print_package_flags(
+ const tr1::shared_ptr<const PackageID> & pkg,
+ const tr1::shared_ptr<const IUseFlagCollection> & iuse_c,
+ const tr1::shared_ptr<const PackageID> & old_pkg,
+ const tr1::shared_ptr<const IUseFlagCollection> & old_iuse_c)
{
std::set<UseFlagName> iuse, old_iuse;
- if (! pkg.iuse_key())
- return;
-
- std::copy(pkg.iuse_key()->value()->begin(), pkg.iuse_key()->value()->end(),
+ std::copy(iuse_c->begin(), iuse_c->end(),
transform_inserter(std::inserter(iuse, iuse.begin()), tr1::mem_fn(&IUseFlag::flag)));
- if (old_pkg && old_pkg->iuse_key())
- std::copy(old_pkg->iuse_key()->value()->begin(), old_pkg->iuse_key()->value()->end(),
+ if (old_pkg && old_iuse_c)
+ std::copy(old_iuse_c->begin(), old_iuse_c->end(),
transform_inserter(std::inserter(old_iuse, old_iuse.begin()), tr1::mem_fn(&IUseFlag::flag)));
- const RepositoryUseInterface * const use_interface(pkg.repository()->use_interface);
+ const RepositoryUseInterface * const use_interface(pkg->repository()->use_interface);
/* first pass: only non-expand flags */
for (std::set<UseFlagName>::const_iterator flag(iuse.begin()), flag_end(iuse.end()) ;
@@ -83,26 +83,26 @@ UseFlagPrettyPrinter::print_package_flags(const PackageID & pkg,
if (std::string::npos != use_expand_delim_pos(*flag, use_interface->use_expand_prefixes()))
continue;
- if (environment()->query_use(*flag, pkg))
+ if (environment()->query_use(*flag, *pkg))
{
- if (use_interface && use_interface->query_use_force(*flag, pkg))
+ if (use_interface && use_interface->query_use_force(*flag, *pkg))
output_flag(render_as_forced_flag(stringify(*flag)));
else
output_flag(render_as_enabled_flag(stringify(*flag)));
}
else
{
- if (use_interface && use_interface->query_use_mask(*flag, pkg))
+ if (use_interface && use_interface->query_use_mask(*flag, *pkg))
output_flag(render_as_masked_flag(stringify(*flag)));
else
output_flag(render_as_disabled_flag(stringify(*flag)));
}
- if (old_pkg)
+ if (old_iuse_c)
{
if (old_iuse.end() != old_iuse.find(*flag))
{
- if (environment()->query_use(*flag, pkg) != environment()->query_use(*flag, *old_pkg))
+ if (environment()->query_use(*flag, *pkg) != environment()->query_use(*flag, *old_pkg))
{
_changed_flags->insert(*flag);
output_flag_changed_mark();
@@ -146,16 +146,16 @@ UseFlagPrettyPrinter::print_package_flags(const PackageID & pkg,
old_expand_name = expand_name;
}
- if (environment()->query_use(*flag, pkg))
+ if (environment()->query_use(*flag, *pkg))
{
- if (use_interface && use_interface->query_use_force(*flag, pkg))
+ if (use_interface && use_interface->query_use_force(*flag, *pkg))
output_flag(render_as_forced_flag(stringify(expand_value)));
else
output_flag(render_as_enabled_flag(stringify(expand_value)));
}
else
{
- if (use_interface && use_interface->query_use_mask(*flag, pkg))
+ if (use_interface && use_interface->query_use_mask(*flag, *pkg))
output_flag(render_as_masked_flag(stringify(expand_value)));
else
output_flag(render_as_disabled_flag(stringify(expand_value)));
@@ -165,7 +165,7 @@ UseFlagPrettyPrinter::print_package_flags(const PackageID & pkg,
{
if (old_iuse.end() != old_iuse.find(*flag))
{
- if (environment()->query_use(*flag, pkg) != environment()->query_use(*flag, *old_pkg))
+ if (environment()->query_use(*flag, *pkg) != environment()->query_use(*flag, *old_pkg))
{
_changed_flags->insert(*flag);
output_flag_changed_mark();
diff --git a/src/output/use_flag_pretty_printer.hh b/src/output/use_flag_pretty_printer.hh
index ef07c19..1ec5ca8 100644
--- a/src/output/use_flag_pretty_printer.hh
+++ b/src/output/use_flag_pretty_printer.hh
@@ -48,7 +48,11 @@ namespace paludis
UseFlagPrettyPrinter(const Environment * const);
virtual ~UseFlagPrettyPrinter();
- virtual void print_package_flags(const PackageID &, const PackageID * const = 0);
+ virtual void print_package_flags(
+ const tr1::shared_ptr<const PackageID> &,
+ const tr1::shared_ptr<const IUseFlagCollection> &,
+ const tr1::shared_ptr<const PackageID> & w = tr1::shared_ptr<const PackageID>(),
+ const tr1::shared_ptr<const IUseFlagCollection> & x = tr1::shared_ptr<const IUseFlagCollection>());
virtual void output_flag(const std::string &);
virtual void output_flag_changed_mark();