version_t -> VersionT

This commit is contained in:
Alexander Karatarakis 2017-04-03 16:13:46 -07:00
parent 5b0d9f3ee0
commit b766a005b7
13 changed files with 120 additions and 72 deletions

View File

@ -5,7 +5,7 @@
#include "vcpkg_expected.h"
#include "BinaryParagraph.h"
#include "vcpkg_paths.h"
#include "version_t.h"
#include "VersionT.h"
namespace vcpkg::Paragraphs
{
@ -22,5 +22,5 @@ namespace vcpkg::Paragraphs
std::vector<SourceParagraph> load_all_ports(const fs::path& ports_dir);
std::map<std::string, version_t> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs);
std::map<std::string, VersionT> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs);
}

View File

@ -0,0 +1,20 @@
#include "pch.h"
#include "Version.h"
#include "vcpkg_Strings.h"
namespace vcpkg
{
Version::Version() : value("0.0.0") {}
Version::Version(const std::string& value) : value(value) {}
bool operator==(const Version& left, const Version& right) { return left.value == right.value; }
bool operator!=(const Version& left, const Version& right) { return left.value != right.value; }
std::string to_printf_arg(const Version& version) { return version.value; }
version_diff_t::version_diff_t() : left(), right() {}
version_diff_t::version_diff_t(const Version& left, const Version& right) : left(left), right(right) {}
std::string version_diff_t::toString() const
{
return Strings::format("%s -> %s", left.value, right.value);
}
}

28
toolsrc/include/Version.h Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include <string>
namespace vcpkg
{
struct Version
{
Version();
Version(const std::string& value);
std::string value;
};
bool operator ==(const Version& left, const Version& right);
bool operator !=(const Version& left, const Version& right);
std::string to_printf_arg(const Version& version);
struct version_diff_t
{
Version left;
Version right;
version_diff_t();
version_diff_t(const Version& left, const Version& right);
std::string toString() const;
};
}

View File

@ -0,0 +1,20 @@
#include "pch.h"
#include "VersionT.h"
#include "vcpkg_Strings.h"
namespace vcpkg
{
VersionT::VersionT() : value("0.0.0") {}
VersionT::VersionT(const std::string& value) : value(value) {}
bool operator==(const VersionT& left, const VersionT& right) { return left.value == right.value; }
bool operator!=(const VersionT& left, const VersionT& right) { return left.value != right.value; }
std::string to_printf_arg(const VersionT& version) { return version.value; }
version_diff_t::version_diff_t() : left(), right() {}
version_diff_t::version_diff_t(const VersionT& left, const VersionT& right) : left(left), right(right) {}
std::string version_diff_t::toString() const
{
return Strings::format("%s -> %s", left.value, right.value);
}
}

View File

@ -0,0 +1,28 @@
#pragma once
#include <string>
namespace vcpkg
{
struct VersionT
{
VersionT();
VersionT(const std::string& value);
std::string value;
};
bool operator ==(const VersionT& left, const VersionT& right);
bool operator !=(const VersionT& left, const VersionT& right);
std::string to_printf_arg(const VersionT& version);
struct version_diff_t
{
VersionT left;
VersionT right;
version_diff_t();
version_diff_t(const VersionT& left, const VersionT& right);
std::string toString() const;
};
}

View File

@ -4,7 +4,7 @@
#include "vcpkg_paths.h"
#include "StatusParagraphs.h"
#include <array>
#include "version_t.h"
#include "VersionT.h"
namespace vcpkg::Commands
{

View File

@ -1,20 +0,0 @@
#include "pch.h"
#include "version_t.h"
#include "vcpkg_Strings.h"
namespace vcpkg
{
version_t::version_t() : value("0.0.0") {}
version_t::version_t(const std::string& value) : value(value) {}
bool operator==(const version_t& left, const version_t& right) { return left.value == right.value; }
bool operator!=(const version_t& left, const version_t& right) { return left.value != right.value; }
std::string to_printf_arg(const version_t& version) { return version.value; }
version_diff_t::version_diff_t() : left(), right() {}
version_diff_t::version_diff_t(const version_t& left, const version_t& right) : left(left), right(right) {}
std::string version_diff_t::toString() const
{
return Strings::format("%s -> %s", left.value, right.value);
}
}

View File

@ -1,28 +0,0 @@
#pragma once
#include <string>
namespace vcpkg
{
struct version_t
{
version_t();
version_t(const std::string& value);
std::string value;
};
bool operator ==(const version_t& left, const version_t& right);
bool operator !=(const version_t& left, const version_t& right);
std::string to_printf_arg(const version_t& version);
struct version_diff_t
{
version_t left;
version_t right;
version_diff_t();
version_diff_t(const version_t& left, const version_t& right);
std::string toString() const;
};
}

View File

@ -250,9 +250,9 @@ namespace vcpkg::Paragraphs
return output;
}
std::map<std::string, version_t> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs)
std::map<std::string, VersionT> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs)
{
std::map<std::string, version_t> names_and_versions;
std::map<std::string, VersionT> names_and_versions;
for (const SourceParagraph& port : source_paragraphs)
{
names_and_versions.emplace(port.name, port.version);

View File

@ -39,14 +39,14 @@ namespace vcpkg::Commands::PortsDiff
};
static std::vector<updated_port> find_updated_ports(const std::vector<std::string>& ports,
const std::map<std::string, version_t>& previous_names_and_versions,
const std::map<std::string, version_t>& current_names_and_versions)
const std::map<std::string, VersionT>& previous_names_and_versions,
const std::map<std::string, VersionT>& current_names_and_versions)
{
std::vector<updated_port> output;
for (const std::string& name : ports)
{
const version_t& previous_version = previous_names_and_versions.at(name);
const version_t& current_version = current_names_and_versions.at(name);
const VersionT& previous_version = previous_names_and_versions.at(name);
const VersionT& current_version = current_names_and_versions.at(name);
if (previous_version == current_version)
{
continue;
@ -58,16 +58,16 @@ namespace vcpkg::Commands::PortsDiff
return output;
}
static void do_print_name_and_version(const std::vector<std::string>& ports_to_print, const std::map<std::string, version_t>& names_and_versions)
static void do_print_name_and_version(const std::vector<std::string>& ports_to_print, const std::map<std::string, VersionT>& names_and_versions)
{
for (const std::string& name : ports_to_print)
{
const version_t& version = names_and_versions.at(name);
const VersionT& version = names_and_versions.at(name);
System::println("%-20s %-16s", name, version);
}
}
static std::map<std::string, version_t> read_ports_from_commit(const vcpkg_paths& paths, const std::wstring& git_commit_id)
static std::map<std::string, VersionT> read_ports_from_commit(const vcpkg_paths& paths, const std::wstring& git_commit_id)
{
const fs::path& git_exe = paths.get_git_exe();
const fs::path dot_git_dir = paths.root / ".git";
@ -86,7 +86,7 @@ namespace vcpkg::Commands::PortsDiff
git_exe.native());
System::cmd_execute_clean(cmd);
const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(temp_checkout_path / ports_dir_name_as_string);
const std::map<std::string, version_t> names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
const std::map<std::string, VersionT> names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
fs::remove_all(temp_checkout_path);
return names_and_versions;
}
@ -115,8 +115,8 @@ namespace vcpkg::Commands::PortsDiff
check_commit_exists(git_exe, git_commit_id_for_current_snapshot);
check_commit_exists(git_exe, git_commit_id_for_previous_snapshot);
const std::map<std::string, version_t> current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot);
const std::map<std::string, version_t> previous_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_previous_snapshot);
const std::map<std::string, VersionT> current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot);
const std::map<std::string, VersionT> previous_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_previous_snapshot);
// Already sorted, so set_difference can work on std::vector too
std::vector<std::string> current_ports = Maps::extract_keys(current_names_and_versions);

View File

@ -15,7 +15,7 @@ namespace vcpkg::Commands::Update
std::vector<OutdatedPackage> find_outdated_packages(const vcpkg_paths& paths, const StatusParagraphs& status_db)
{
const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.ports);
const std::map<std::string, version_t> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
const std::map<std::string, VersionT> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
const std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
std::vector<OutdatedPackage> output;

View File

@ -179,10 +179,10 @@
<ClInclude Include="..\include\vcpkg_Strings.h" />
<ClInclude Include="..\include\vcpkg_System.h" />
<ClInclude Include="..\include\vcpkg_Util.h" />
<ClInclude Include="..\include\version_t.h" />
<ClInclude Include="..\include\VersionT.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\include\version_t.cpp" />
<ClCompile Include="..\include\VersionT.cpp" />
<ClCompile Include="..\src\BinaryParagraph.cpp" />
<ClCompile Include="..\src\commands_ci.cpp" />
<ClCompile Include="..\src\commands_env.cpp" />

View File

@ -159,9 +159,6 @@
<ClCompile Include="..\src\LineInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\include\version_t.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\commands_env.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -180,6 +177,9 @@
<ClCompile Include="..\src\VcpkgCmdArguments.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\include\VersionT.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\SourceParagraph.h">
@ -287,9 +287,6 @@
<ClInclude Include="..\include\vcpkg_expected.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\version_t.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\vcpkg_Util.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -314,5 +311,8 @@
<ClInclude Include="..\include\VcpkgCmdArguments.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\VersionT.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>