Introduce extract_port_names_and_versions()

This commit is contained in:
Alexander Karatarakis 2017-02-27 16:14:36 -08:00
parent b7bd8c3251
commit 54859c0f1f
4 changed files with 18 additions and 34 deletions

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;