Introduce get_installed_ports()
MODIFY
include/vcpkglib.h
include/vcpkglib.h
@@ -18,6 +18,7 @@ namespace vcpkg
ImmutableSortedVector<std::string> files;
};
+ std::vector<StatusParagraph*> get_installed_ports(const StatusParagraphs& status_db);
std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db);

MODIFY
src/commands_list.cpp
src/commands_list.cpp
@@ -22,13 +22,7 @@ namespace vcpkg::Commands::List
args.check_and_get_optional_command_arguments({});
const StatusParagraphs status_paragraphs = database_load_check(paths);
- std::vector<StatusParagraph> installed_packages;
- for (auto&& pgh : status_paragraphs)
- {
- if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge)
- continue;
- installed_packages.push_back(*pgh);
- }
+ std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_paragraphs);
if (installed_packages.empty())
{
@@ -37,30 +31,30 @@ namespace vcpkg::Commands::List
}
std::sort(installed_packages.begin(), installed_packages.end(),
- [ ]( const StatusParagraph& lhs, const StatusParagraph& rhs ) -> bool
+ [ ]( const StatusParagraph* lhs, const StatusParagraph* rhs ) -> bool
{
- return lhs.package.displayname() < rhs.package.displayname();
+ return lhs->package.displayname() < rhs->package.displayname();
});
if (args.command_arguments.size() == 0)
{
- for (const StatusParagraph& status_paragraph : installed_packages)
+ for (const StatusParagraph* status_paragraph : installed_packages)
{
- do_print(status_paragraph);
+ do_print(*status_paragraph);
}
}
else
{
// At this point there is 1 argument
- for (const StatusParagraph& status_paragraph : installed_packages)
+ for (const StatusParagraph* status_paragraph : installed_packages)
{
- const std::string displayname = status_paragraph.package.displayname();
+ const std::string displayname = status_paragraph->package.displayname();
if (Strings::case_insensitive_ascii_find(displayname, args.command_arguments[0]) == displayname.end())
{
continue;
}
- do_print(status_paragraph);
+ do_print(*status_paragraph);
}
}

MODIFY
src/commands_update.cpp
src/commands_update.cpp
@@ -18,13 +18,11 @@ namespace vcpkg::Commands::Update
const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.ports);
const std::map<std::string, std::string> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
- std::string packages_list;
+ std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
std::vector<std::string> packages_output;
- for (auto&& pgh : status_db)
+ for (const StatusParagraph* pgh : installed_packages)
{
- if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge)
- continue;
auto it = src_names_to_versions.find(pgh->package.spec.name());
if (it == src_names_to_versions.end())
{
@@ -37,7 +35,6 @@ namespace vcpkg::Commands::Update
pgh->package.displayname(),
pgh->package.version,
it->second));
- packages_list.append(" " + pgh->package.displayname());
}
}
std::sort(packages_output.begin(), packages_output.end());

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
@@ -171,6 +171,19 @@ namespace vcpkg
fs::rename(updated_listfile_path, listfile_path);
}
+ std::vector<StatusParagraph*> get_installed_ports(const StatusParagraphs& status_db)
+ {
+ std::vector<StatusParagraph*> installed_packages;
+ for (auto&& pgh : status_db)
+ {
+ if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge)
+ continue;
+ installed_packages.push_back(pgh.get());
+ }
+
+ return installed_packages;
+ }
+
std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db)
{
std::vector<StatusParagraph_and_associated_files> installed_files;

Introduce get_installed_ports()