From 23d35e73477b09dd0099adfd1bdafc6c9672c4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Tue, 29 Nov 2022 10:29:32 +0100 Subject: [PATCH] Repoquery: Add --duplicates option For: https://github.com/rpm-software-management/dnf5/issues/122 --- dnf5/commands/repoquery/repoquery.cpp | 24 +++++++++++++++++++++--- dnf5/commands/repoquery/repoquery.hpp | 4 ++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/dnf5/commands/repoquery/repoquery.cpp b/dnf5/commands/repoquery/repoquery.cpp index f6f235adb..ccd03fec7 100644 --- a/dnf5/commands/repoquery/repoquery.cpp +++ b/dnf5/commands/repoquery/repoquery.cpp @@ -101,6 +101,14 @@ void RepoqueryCommand::set_argument_parser() { info->add_conflict_argument(*nevra); + duplicates = std::make_unique( + *this, + "duplicates", + '\0', + "Limit the resulting set to installed duplicate packages (i.e. more package versions for the same name and " + "architecture). Installonly packages are excluded from this set.", + false); + advisory_name = std::make_unique(*this); advisory_security = std::make_unique(*this); advisory_bugfix = std::make_unique(*this); @@ -120,7 +128,8 @@ void RepoqueryCommand::set_argument_parser() { void RepoqueryCommand::configure() { auto & context = get_context(); context.update_repo_load_flags_from_specs(pkg_specs); - context.set_load_system_repo(installed_option->get_value()); + only_system_repo_needed = installed_option->get_value() || duplicates->get_value(); + context.set_load_system_repo(only_system_repo_needed); bool updateinfo_needed = advisory_name->get_value().empty() || advisory_security->get_value() || advisory_bugfix->get_value() || advisory_enhancement->get_value() || advisory_newpackage->get_value() || advisory_severity->get_value().empty() || @@ -130,13 +139,13 @@ void RepoqueryCommand::configure() { context.get_available_repos_load_flags() | libdnf::repo::LoadFlags::UPDATEINFO); } context.set_load_available_repos( - available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !installed_option->get_value() + available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !only_system_repo_needed ? Context::LoadAvailableRepos::ENABLED : Context::LoadAvailableRepos::NONE); } void RepoqueryCommand::load_additional_packages() { - if (available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !installed_option->get_value()) { + if (available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !only_system_repo_needed) { cmdline_packages = get_context().add_cmdline_packages(pkg_file_paths); } } @@ -161,6 +170,15 @@ void RepoqueryCommand::run() { full_package_query.filter_advisories(advisories.value(), libdnf::sack::QueryCmp::GTE); } + if (duplicates->get_value()) { + auto & cfg_main = ctx.base.get_config(); + const auto & installonly_packages = cfg_main.installonlypkgs().get_value(); + auto installonly_query = full_package_query; + installonly_query.filter_provides(installonly_packages, libdnf::sack::QueryCmp::GLOB); + full_package_query -= installonly_query; + full_package_query.filter_duplicates(); + } + if (pkg_specs.empty() && pkg_file_paths.empty()) { result_pset |= full_package_query; } else { diff --git a/dnf5/commands/repoquery/repoquery.hpp b/dnf5/commands/repoquery/repoquery.hpp index 3bc356bfa..8be26829d 100644 --- a/dnf5/commands/repoquery/repoquery.hpp +++ b/dnf5/commands/repoquery/repoquery.hpp @@ -43,6 +43,8 @@ class RepoqueryCommand : public Command { void run() override; private: + bool only_system_repo_needed = false; + libdnf::OptionBool * available_option{nullptr}; libdnf::OptionBool * installed_option{nullptr}; libdnf::OptionBool * info_option{nullptr}; @@ -51,6 +53,8 @@ class RepoqueryCommand : public Command { std::vector pkg_file_paths; std::vector cmdline_packages; + std::unique_ptr duplicates{nullptr}; + std::unique_ptr advisory_name{nullptr}; std::unique_ptr advisory_security{nullptr}; std::unique_ptr advisory_bugfix{nullptr};