From df2a05e8546281135c6ea12430734d74371bcf46 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 17:35:33 -0800 Subject: Introduce Command namespace. Refactoring --- toolsrc/src/commands_portsdiff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 46c6c90c7..4794dee2b 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -10,7 +10,7 @@ #include "SourceParagraph.h" #include "vcpkg_Environment.h" -namespace vcpkg +namespace vcpkg::Commands { static void do_print_name_and_version(const std::vector& ports_to_print, const std::map& names_and_versions) { @@ -99,7 +99,7 @@ namespace vcpkg void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", create_example_string("portsdiff mybranchname")); + static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", Commands::Helpers::create_example_string("portsdiff mybranchname")); args.check_min_arg_count(1, example); args.check_max_arg_count(2, example); -- cgit v1.2.3 From cc8851144a871931b93d84bd962364159ad1c424 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Thu, 12 Jan 2017 22:03:57 -0800 Subject: Reorganize commands, each in its own namespace Additionally, functions related to a command can now live in the same namespace --- toolsrc/src/commands_portsdiff.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 4794dee2b..1665d7c47 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -10,7 +10,7 @@ #include "SourceParagraph.h" #include "vcpkg_Environment.h" -namespace vcpkg::Commands +namespace vcpkg::Commands::PortsDiff { static void do_print_name_and_version(const std::vector& ports_to_print, const std::map& names_and_versions) { @@ -97,9 +97,9 @@ namespace vcpkg::Commands Checks::check_exit(output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", Strings::utf16_to_utf8(git_commit_id)); } - void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) { - static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", Commands::Helpers::create_example_string("portsdiff mybranchname")); + static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", Commands::Help::create_example_string("portsdiff mybranchname")); args.check_min_arg_count(1, example); args.check_max_arg_count(2, example); -- cgit v1.2.3 From 050e4a0f7a8156bd862f95c06ea298ab6697e147 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 27 Jan 2017 12:49:09 -0800 Subject: Introduce precompiled headers --- toolsrc/src/commands_portsdiff.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 1665d7c47..e75633b3c 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -1,11 +1,7 @@ +#include "pch.h" #include "vcpkg_Commands.h" #include "vcpkg_System.h" -#include -#include #include "vcpkg_Maps.h" -#include -#include -#include #include "Paragraphs.h" #include "SourceParagraph.h" #include "vcpkg_Environment.h" -- cgit v1.2.3 From 4e44b8533d1df94dd2405674086377d06b3690a7 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 17 Feb 2017 15:46:35 -0800 Subject: `portsdiff`: Check for --options --- toolsrc/src/commands_portsdiff.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index e75633b3c..119997485 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -98,6 +98,7 @@ namespace vcpkg::Commands::PortsDiff static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", Commands::Help::create_example_string("portsdiff mybranchname")); args.check_min_arg_count(1, example); args.check_max_arg_count(2, example); + args.check_and_get_optional_command_arguments({}); Environment::ensure_git_on_path(paths); const std::wstring git_commit_id_for_previous_snapshot = Strings::utf8_to_utf16(args.command_arguments.at(0)); -- cgit v1.2.3 From 00737588cc6155776734c5a5261c9b08f9446eb4 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 27 Feb 2017 15:40:06 -0800 Subject: Use load_all_ports() in `portsdiff` --- toolsrc/src/commands_portsdiff.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 119997485..2edb3fb3f 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -2,9 +2,9 @@ #include "vcpkg_Commands.h" #include "vcpkg_System.h" #include "vcpkg_Maps.h" -#include "Paragraphs.h" #include "SourceParagraph.h" #include "vcpkg_Environment.h" +#include "vcpkglib.h" namespace vcpkg::Commands::PortsDiff { @@ -40,25 +40,14 @@ namespace vcpkg::Commands::PortsDiff } } - static std::map read_all_ports(const fs::path& ports_folder_path) + static std::map read_port_names_and_versions(const fs::path& ports_folder_path) { std::map names_and_versions; - for (auto it = fs::directory_iterator(ports_folder_path); it != fs::directory_iterator(); ++it) + std::vector ports = load_all_ports(ports_folder_path); + for (SourceParagraph& port : ports) { - const fs::path& path = it->path(); - - try - { - auto pghs = Paragraphs::get_paragraphs(path / "CONTROL"); - if (pghs.empty()) - continue; - auto srcpgh = SourceParagraph(pghs[0]); - names_and_versions.emplace(srcpgh.name, srcpgh.version); - } - catch (std::runtime_error const&) - { - } + names_and_versions.emplace(std::move(port.name), std::move(port.version)); } return names_and_versions; @@ -79,7 +68,7 @@ namespace vcpkg::Commands::PortsDiff checkout_this_dir, L".vcpkg-root"); System::cmd_execute(cmd); - std::map names_and_versions = read_all_ports(temp_checkout_path / ports_dir_name_as_string); + std::map names_and_versions = read_port_names_and_versions(temp_checkout_path / ports_dir_name_as_string); fs::remove_all(temp_checkout_path); return names_and_versions; } -- cgit v1.2.3 From c0ae9fee7e30cdd4898df22aecf5412b2d8f8ee6 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 27 Feb 2017 15:45:56 -0800 Subject: Move some functions from vcpkglib.h to Paragraphs.h --- toolsrc/src/commands_portsdiff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 2edb3fb3f..a927f145d 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Maps.h" #include "SourceParagraph.h" #include "vcpkg_Environment.h" -#include "vcpkglib.h" +#include "PostBuildLint_BuildInfo.h" namespace vcpkg::Commands::PortsDiff { @@ -44,7 +44,7 @@ namespace vcpkg::Commands::PortsDiff { std::map names_and_versions; - std::vector ports = load_all_ports(ports_folder_path); + 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)); -- cgit v1.2.3 From b7bd8c3251dcb9ecf3f6c0201c2a513596ab09b1 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 27 Feb 2017 15:52:57 -0800 Subject: Fix #include of Paragraph.h --- toolsrc/src/commands_portsdiff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index a927f145d..06a1f6c60 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -4,7 +4,7 @@ #include "vcpkg_Maps.h" #include "SourceParagraph.h" #include "vcpkg_Environment.h" -#include "PostBuildLint_BuildInfo.h" +#include "Paragraphs.h" namespace vcpkg::Commands::PortsDiff { -- cgit v1.2.3 From 54859c0f1f201dfcc78e783c77c3b477d0c86c92 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 27 Feb 2017 16:14:36 -0800 Subject: Introduce extract_port_names_and_versions() --- toolsrc/src/commands_portsdiff.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') 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; } -- cgit v1.2.3 From 2d3fa9d7f4f101be62e5ff54885982e8f49ac099 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 27 Feb 2017 17:53:24 -0800 Subject: Remove unnecessary branch --- toolsrc/src/commands_portsdiff.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index ff17a7086..400689b47 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -26,11 +26,6 @@ namespace vcpkg::Commands::PortsDiff { for (const std::string& name : ports_to_print) { - if (name == "") - { - continue; - } - const std::string& previous_version = previous_names_and_versions.at(name); const std::string& current_version = current_names_and_versions.at(name); std::cout << std::left -- cgit v1.2.3 From f81fc894124bbeb709799f6117c01654be8df07f Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 10 Mar 2017 15:31:45 -0800 Subject: Use System::println() instead of std::cout --- toolsrc/src/commands_portsdiff.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 400689b47..25559c2ca 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -13,10 +13,7 @@ namespace vcpkg::Commands::PortsDiff for (const std::string& name : ports_to_print) { const std::string& version = names_and_versions.at(name); - std::cout << std::left - << std::setw(20) << name << ' ' - << std::setw(16) << version << ' ' - << '\n'; + System::println("%-20s %-16s", name, version); } } @@ -28,10 +25,7 @@ namespace vcpkg::Commands::PortsDiff { const std::string& previous_version = previous_names_and_versions.at(name); const std::string& current_version = current_names_and_versions.at(name); - std::cout << std::left - << std::setw(20) << name << ' ' - << std::setw(16) << previous_version << " -> " << current_version - << '\n'; + System::println("%-20s %-16s -> %s", name, previous_version, current_version); } } -- cgit v1.2.3 From 0b30bc7243b7caf3cfce9130f3862607efe715bd Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 10 Mar 2017 16:34:24 -0800 Subject: `portsdiff`: Use paths.get_git_exe(); --- toolsrc/src/commands_portsdiff.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 25559c2ca..065a35345 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -31,18 +31,21 @@ namespace vcpkg::Commands::PortsDiff static std::map 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"; const std::wstring ports_dir_name_as_string = paths.ports.filename().native(); const fs::path temp_checkout_path = paths.root / Strings::wformat(L"%s-%s", ports_dir_name_as_string, git_commit_id); fs::create_directory(temp_checkout_path); const std::wstring checkout_this_dir = Strings::wformat(LR"(.\%s)", ports_dir_name_as_string); // Must be relative to the root of the repository - const std::wstring cmd = Strings::wformat(LR"(git --git-dir="%s" --work-tree="%s" checkout %s -f -q -- %s %s & git reset >NUL)", + const std::wstring cmd = Strings::wformat(LR"("%s" --git-dir="%s" --work-tree="%s" checkout %s -f -q -- %s %s & "%s" reset >NUL)", + git_exe.native(), dot_git_dir.native(), temp_checkout_path.native(), git_commit_id, checkout_this_dir, - L".vcpkg-root"); + L".vcpkg-root", + git_exe.native()); System::cmd_execute(cmd); 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); @@ -50,11 +53,11 @@ namespace vcpkg::Commands::PortsDiff return names_and_versions; } - static void check_commit_exists(const std::wstring& git_commit_id) + static void check_commit_exists(const fs::path& git_exe, const std::wstring& git_commit_id) { static const std::string VALID_COMMIT_OUTPUT = "commit\n"; - const std::wstring cmd = Strings::wformat(LR"(git cat-file -t %s 2>NUL)", git_commit_id); + const std::wstring cmd = Strings::wformat(LR"("%s" cat-file -t %s 2>NUL)", git_exe.native(), git_commit_id); const System::exit_code_and_output output = System::cmd_execute_and_capture_output(cmd); Checks::check_exit(output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", Strings::utf16_to_utf8(git_commit_id)); } @@ -66,12 +69,13 @@ namespace vcpkg::Commands::PortsDiff args.check_max_arg_count(2, example); args.check_and_get_optional_command_arguments({}); - Environment::ensure_git_on_path(paths); + const fs::path& git_exe = paths.get_git_exe(); + const std::wstring git_commit_id_for_previous_snapshot = Strings::utf8_to_utf16(args.command_arguments.at(0)); const std::wstring git_commit_id_for_current_snapshot = args.command_arguments.size() < 2 ? L"HEAD" : Strings::utf8_to_utf16(args.command_arguments.at(1)); - check_commit_exists(git_commit_id_for_current_snapshot); - check_commit_exists(git_commit_id_for_previous_snapshot); + 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 current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot); const std::map previous_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_previous_snapshot); -- cgit v1.2.3 From ea52c29e9af701c4a2e070f836bb1ffb7e092760 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 10 Mar 2017 17:03:47 -0800 Subject: Use System::cmd_execute_clean() for `build`, `create`, `portsdiff` --- toolsrc/src/commands_portsdiff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src/commands_portsdiff.cpp') diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp index 065a35345..4d5a589f6 100644 --- a/toolsrc/src/commands_portsdiff.cpp +++ b/toolsrc/src/commands_portsdiff.cpp @@ -46,7 +46,7 @@ namespace vcpkg::Commands::PortsDiff checkout_this_dir, L".vcpkg-root", git_exe.native()); - System::cmd_execute(cmd); + System::cmd_execute_clean(cmd); 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); -- cgit v1.2.3