diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-02-27 16:14:36 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-02-27 16:14:36 -0800 |
| commit | 54859c0f1f201dfcc78e783c77c3b477d0c86c92 (patch) | |
| tree | 6723e6c34f27ed98c41fd14fce4275de92f473ea | |
| parent | b7bd8c3251dcb9ecf3f6c0201c2a513596ab09b1 (diff) | |
| download | vcpkg-54859c0f1f201dfcc78e783c77c3b477d0c86c92.tar.gz vcpkg-54859c0f1f201dfcc78e783c77c3b477d0c86c92.zip | |
Introduce extract_port_names_and_versions()
| -rw-r--r-- | toolsrc/include/Paragraphs.h | 4 | ||||
| -rw-r--r-- | toolsrc/src/Paragraphs.cpp | 11 | ||||
| -rw-r--r-- | toolsrc/src/commands_portsdiff.cpp | 16 | ||||
| -rw-r--r-- | 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 <unordered_map> +#include <map> #include "expected.h" #include "BinaryParagraph.h" #include "vcpkg_paths.h" @@ -16,4 +16,6 @@ namespace vcpkg::Paragraphs expected<BinaryParagraph> try_load_cached_package(const vcpkg_paths& paths, const package_spec& spec); std::vector<SourceParagraph> load_all_ports(const fs::path& ports_dir); + + std::map<std::string, std::string> extract_port_names_and_versions(const std::vector<SourceParagraph>& 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<std::string, std::string> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs) + { + std::map<std::string, std::string> 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<std::string, std::string> read_port_names_and_versions(const fs::path& ports_folder_path) - { - std::map<std::string, std::string> names_and_versions; - - std::vector<SourceParagraph> 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<std::string, std::string> 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<std::string, std::string> names_and_versions = read_port_names_and_versions(temp_checkout_path / ports_dir_name_as_string); + const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(temp_checkout_path / ports_dir_name_as_string); + const std::map<std::string, std::string> 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<std::string, std::string> 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<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; |
