From 54859c0f1f201dfcc78e783c77c3b477d0c86c92 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 27 Feb 2017 16:14:36 -0800 Subject: [PATCH] Introduce extract_port_names_and_versions() --- toolsrc/include/Paragraphs.h | 4 +++- toolsrc/src/Paragraphs.cpp | 11 +++++++++++ toolsrc/src/commands_portsdiff.cpp | 16 ++-------------- toolsrc/src/commands_update.cpp | 21 ++------------------- 4 files changed, 18 insertions(+), 34 deletions(-) diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h index 9564d2290..79b66a67f 100644 --- a/toolsrc/include/Paragraphs.h +++ b/toolsrc/include/Paragraphs.h @@ -1,7 +1,7 @@ #pragma once #include "filesystem_fs.h" -#include +#include #include "expected.h" #include "BinaryParagraph.h" #include "vcpkg_paths.h" @@ -16,4 +16,6 @@ namespace vcpkg::Paragraphs expected try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec); std::vector load_all_ports(const fs::path& ports_dir); + + std::map extract_port_names_and_versions(const std::vector& source_paragraphs); } diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp index fdb583bcc..1d8106750 100644 --- a/toolsrc/src/Paragraphs.cpp +++ b/toolsrc/src/Paragraphs.cpp @@ -217,4 +217,15 @@ namespace vcpkg::Paragraphs return output; } + + std::map extract_port_names_and_versions(const std::vector& source_paragraphs) + { + std::map names_and_versions; + for (const SourceParagraph& port : source_paragraphs) + { + names_and_versions.emplace(port.name, port.version); + } + + return names_and_versions; + } } diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 06a1f6c60..ff17a7086 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -40,19 +40,6 @@ namespace vcpkg::Commands::PortsDiff } } - static std::map read_port_names_and_versions(const fs::path& ports_folder_path) - { - std::map names_and_versions; - - std::vector ports = Paragraphs::load_all_ports(ports_folder_path); - for (SourceParagraph& port : ports) - { - names_and_versions.emplace(std::move(port.name), std::move(port.version)); - } - - return names_and_versions; - } - static std::map read_ports_from_commit(const vcpkg_paths& paths, const std::wstring& git_commit_id) { const fs::path dot_git_dir = paths.root / ".git"; @@ -68,7 +55,8 @@ namespace vcpkg::Commands::PortsDiff checkout_this_dir, L".vcpkg-root"); System::cmd_execute(cmd); - std::map names_and_versions = read_port_names_and_versions(temp_checkout_path / ports_dir_name_as_string); + const std::vector source_paragraphs = Paragraphs::load_all_ports(temp_checkout_path / ports_dir_name_as_string); + const std::map names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs); fs::remove_all(temp_checkout_path); return names_and_versions; } diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp index d4519ca14..8131d9a73 100644 --- a/toolsrc/src/commands_update.cpp +++ b/toolsrc/src/commands_update.cpp @@ -15,25 +15,8 @@ namespace vcpkg::Commands::Update auto status_db = database_load_check(paths); - std::unordered_map src_names_to_versions; - - auto begin_it = fs::directory_iterator(paths.ports); - auto end_it = fs::directory_iterator(); - for (; begin_it != end_it; ++begin_it) - { - const auto& path = begin_it->path(); - try - { - auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); - if (pghs.empty()) - continue; - auto srcpgh = SourceParagraph(pghs[0]); - src_names_to_versions.emplace(srcpgh.name, srcpgh.version); - } - catch (std::runtime_error const&) - { - } - } + const std::vector source_paragraphs = Paragraphs::load_all_ports(paths.ports); + const std::map src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs); std::string packages_list;