From cf86a37f1963ffdaab349627f71009103152f816 Mon Sep 17 00:00:00 2001 From: Thomas1664 <46387399+Thomas1664@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:25:10 +0000 Subject: [PATCH 1/2] Remove command `x-history` --- include/vcpkg/base/messages.h | 3 +- include/vcpkg/commands.porthistory.h | 13 -- src/vcpkg/base/messages.cpp | 1 - src/vcpkg/commands.cpp | 3 - src/vcpkg/commands.porthistory.cpp | 219 --------------------------- src/vcpkg/vcpkgcmdarguments.cpp | 1 - 6 files changed, 1 insertion(+), 239 deletions(-) delete mode 100644 include/vcpkg/commands.porthistory.h delete mode 100644 src/vcpkg/commands.porthistory.cpp diff --git a/include/vcpkg/base/messages.h b/include/vcpkg/base/messages.h index 52e75f2455..d9909be6c6 100644 --- a/include/vcpkg/base/messages.h +++ b/include/vcpkg/base/messages.h @@ -979,7 +979,6 @@ namespace vcpkg "", "Formats all vcpkg.json files. Run this before committing to vcpkg."); DECLARE_MESSAGE(HelpHashCommand, (), "", "Hash a file by specific algorithm, default SHA512."); - DECLARE_MESSAGE(HelpHistoryCommand, (), "", "(Experimental) Show the history of versions of a package."); DECLARE_MESSAGE(HelpInitializeRegistryCommand, (), "", "Initializes a registry in the directory ."); DECLARE_MESSAGE(HelpInstallCommand, (), "", "Install a package."); DECLARE_MESSAGE(HelpListCommand, (), "", "List installed packages."); @@ -1592,4 +1591,4 @@ namespace vcpkg "WarningMessage in code instead."); DECLARE_MESSAGE(WarningsTreatedAsErrors, (), "", "previous warnings being interpreted as errors"); DECLARE_MESSAGE(WhileLookingForSpec, (msg::spec), "", "while looking for {spec}:"); -} \ No newline at end of file +} diff --git a/include/vcpkg/commands.porthistory.h b/include/vcpkg/commands.porthistory.h deleted file mode 100644 index 3ca5325320..0000000000 --- a/include/vcpkg/commands.porthistory.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -namespace vcpkg::Commands::PortHistory -{ - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths); - - struct PortHistoryCommand : PathsCommand - { - virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override; - }; -} diff --git a/src/vcpkg/base/messages.cpp b/src/vcpkg/base/messages.cpp index 582615da8b..61be127e51 100644 --- a/src/vcpkg/base/messages.cpp +++ b/src/vcpkg/base/messages.cpp @@ -587,7 +587,6 @@ namespace vcpkg REGISTER_MESSAGE(HelpExportCommand); REGISTER_MESSAGE(HelpFormatManifestCommand); REGISTER_MESSAGE(HelpHashCommand); - REGISTER_MESSAGE(HelpHistoryCommand); REGISTER_MESSAGE(HelpInitializeRegistryCommand); REGISTER_MESSAGE(HelpInstallCommand); REGISTER_MESSAGE(HelpListCommand); diff --git a/src/vcpkg/commands.cpp b/src/vcpkg/commands.cpp index 268dc7058e..66be8f04fb 100644 --- a/src/vcpkg/commands.cpp +++ b/src/vcpkg/commands.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -101,7 +100,6 @@ namespace vcpkg::Commands static const List::ListCommand list{}; static const NewCommand new_{}; static const Owns::OwnsCommand owns{}; - static const PortHistory::PortHistoryCommand porthistory{}; static const PortsDiff::PortsDiffCommand portsdiff{}; static const RegenerateCommand regenerate{}; static const SearchCommand search{}; @@ -136,7 +134,6 @@ namespace vcpkg::Commands {"x-add-version", &add_version}, {"x-ci-clean", &ciclean}, {"x-ci-verify-versions", &ci_verify_versions}, - {"x-history", &porthistory}, {"x-package-info", &info}, {"x-regenerate", ®enerate}, {"x-vsinstances", &vsinstances}, diff --git a/src/vcpkg/commands.porthistory.cpp b/src/vcpkg/commands.porthistory.cpp deleted file mode 100644 index 5c0965e4cb..0000000000 --- a/src/vcpkg/commands.porthistory.cpp +++ /dev/null @@ -1,219 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace vcpkg::Commands::PortHistory -{ - namespace - { - struct HistoryVersion - { - std::string port_name; - std::string git_tree; - std::string commit_id; - std::string commit_date; - std::string version_string; - std::string version; - int port_version; - VersionScheme scheme; - }; - - ExpectedL run_git_command(const VcpkgPaths& paths, const Command& cmd) - { - auto full_cmd = paths.git_cmd_builder(paths.root / ".git", paths.root).raw_arg(cmd.command_line()); - return flatten_out(cmd_execute_and_capture_output(full_cmd), Tools::GIT); - } - - vcpkg::Optional get_version_from_text(const std::string& text, - const std::string& git_tree, - const std::string& commit_id, - const std::string& commit_date, - const std::string& port_name, - bool is_manifest) - { - auto res = Paragraphs::try_load_port_text( - text, Strings::concat(commit_id, ":", port_name), is_manifest, stdout_sink); - if (const auto& maybe_scf = res.get()) - { - if (const auto& scf = maybe_scf->get()) - { - auto version = scf->core_paragraph->raw_version; - auto port_version = scf->core_paragraph->port_version; - auto scheme = scf->core_paragraph->version_scheme; - return HistoryVersion{ - port_name, - git_tree, - commit_id, - commit_date, - Strings::concat(version, "#", port_version), - version, - port_version, - scheme, - }; - } - } - - return nullopt; - } - - vcpkg::Optional get_version_from_commit(const VcpkgPaths& paths, - const std::string& commit_id, - const std::string& commit_date, - const std::string& port_name) - { - auto rev_parse_cmd = Command("rev-parse").string_arg(Strings::concat(commit_id, ":ports/", port_name)); - auto maybe_rev_parse_output = run_git_command(paths, rev_parse_cmd); - if (auto rev_parse_output = maybe_rev_parse_output.get()) - { - // Remove newline character - const auto git_tree = Strings::trim(std::move(*rev_parse_output)); - - // Do we have a manifest file? - auto manifest_cmd = Command("show").string_arg(Strings::concat(git_tree, ":vcpkg.json")); - auto maybe_manifest_output = run_git_command(paths, manifest_cmd); - if (auto manifest_output = maybe_manifest_output.get()) - { - return get_version_from_text(*manifest_output, git_tree, commit_id, commit_date, port_name, true); - } - - auto cmd = Command("show").string_arg(Strings::concat(git_tree, ":CONTROL")); - auto maybe_control_output = run_git_command(paths, cmd); - if (auto control_output = maybe_control_output.get()) - { - return get_version_from_text(*control_output, git_tree, commit_id, commit_date, port_name, false); - } - } - - return nullopt; - } - - std::vector read_versions_from_log(const VcpkgPaths& paths, const std::string& port_name) - { - // log --format="%H %cd" --date=short --left-only -- ports/{port_name}/. - Command builder; - builder.string_arg("log"); - builder.string_arg("--format=%H %cd"); - builder.string_arg("--date=short"); - builder.string_arg("--left-only"); - builder.string_arg("--"); // Begin pathspec - builder.string_arg(Strings::format("ports/%s/.", port_name)); - std::vector ret; - const auto maybe_output = run_git_command(paths, builder); - if (auto output = maybe_output.get()) - { - auto commits = Util::fmap( - Strings::split(*output, '\n'), [](const std::string& line) -> auto{ - auto parts = Strings::split(line, ' '); - return std::make_pair(parts[0], parts[1]); - }); - - std::string last_version; - for (auto&& commit_date_pair : commits) - { - auto maybe_version = - get_version_from_commit(paths, commit_date_pair.first, commit_date_pair.second, port_name); - if (maybe_version.has_value()) - { - const auto version = maybe_version.value_or_exit(VCPKG_LINE_INFO); - - // Keep latest port with the current version string - if (last_version != version.version_string) - { - last_version = version.version_string; - ret.emplace_back(version); - } - } - } - } - - return ret; - } - } - - static constexpr StringLiteral OPTION_OUTPUT_FILE = "output"; - - static const CommandSetting HISTORY_SETTINGS[] = { - {OPTION_OUTPUT_FILE, "Write output to a file"}, - }; - - const CommandStructure COMMAND_STRUCTURE = { - create_example_string("history "), - 1, - 1, - {{}, {HISTORY_SETTINGS}, {}}, - nullptr, - }; - - static Optional maybe_lookup(std::map> const& m, StringView key) - { - const auto it = m.find(key); - if (it != m.end()) return it->second; - return nullopt; - } - - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) - { - const ParsedArguments parsed_args = args.parse_arguments(COMMAND_STRUCTURE); - auto maybe_output_file = maybe_lookup(parsed_args.settings, OPTION_OUTPUT_FILE); - - std::string port_name = args.command_arguments.at(0); - std::vector versions = read_versions_from_log(paths, port_name); - - if (args.output_json()) - { - Json::Array versions_json; - for (auto&& version : versions) - { - Json::Object object; - object.insert("git-tree", Json::Value::string(version.git_tree)); - - serialize_schemed_version(object, version.scheme, version.version, version.port_version, true); - versions_json.push_back(std::move(object)); - } - - Json::Object root; - root.insert("versions", versions_json); - - auto json_string = Json::stringify(root); - if (maybe_output_file.has_value()) - { - auto output_file_path = maybe_output_file.value_or_exit(VCPKG_LINE_INFO); - auto& fs = paths.get_filesystem(); - fs.write_contents(output_file_path, json_string, VCPKG_LINE_INFO); - } - else - { - vcpkg::printf("%s\n", json_string); - } - } - else - { - if (maybe_output_file.has_value()) - { - vcpkg::printf(Color::warning, "Warning: Option `--$s` requires `--x-json` switch.", OPTION_OUTPUT_FILE); - } - - print2(" version date vcpkg commit\n"); - for (auto&& version : versions) - { - vcpkg::printf("%20.20s %s %s\n", version.version_string, version.commit_date, version.commit_id); - } - } - Checks::exit_success(VCPKG_LINE_INFO); - } - - void PortHistoryCommand::perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const - { - PortHistory::perform_and_exit(args, paths); - } -} diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 614c46ae26..f07ca1e2f6 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -571,7 +571,6 @@ namespace vcpkg table.format("vcpkg update", msg::format(msgHelpUpdateCommand)); table.format("vcpkg remove --outdated", msg::format(msgHelpRemoveOutdatedCommand)); table.format("vcpkg upgrade", msg::format(msgHelpUpgradeCommand)); - table.format("vcpkg x-history ", msg::format(msgHelpHistoryCommand)); table.format("vcpkg hash [alg]", msg::format(msgHelpHashCommand)); table.format("vcpkg help topics", msg::format(msgHelpTopicsCommand)); table.format("vcpkg help ", msg::format(msgHelpTopicCommand)); From 5fd3a075ff54c35e04aa0a1218bc221d23fcb756 Mon Sep 17 00:00:00 2001 From: Thomas1664 <46387399+Thomas1664@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:35:38 +0000 Subject: [PATCH 2/2] regenerate messages --- locales/messages.en.json | 1 - locales/messages.json | 1 - 2 files changed, 2 deletions(-) diff --git a/locales/messages.en.json b/locales/messages.en.json index fd00824674..516e9bdf84 100644 --- a/locales/messages.en.json +++ b/locales/messages.en.json @@ -186,7 +186,6 @@ "HelpExportCommand": "Exports a package.", "HelpFormatManifestCommand": "Formats all vcpkg.json files. Run this before committing to vcpkg.", "HelpHashCommand": "Hash a file by specific algorithm, default SHA512.", - "HelpHistoryCommand": "(Experimental) Show the history of versions of a package.", "HelpInitializeRegistryCommand": "Initializes a registry in the directory .", "HelpInstallCommand": "Install a package.", "HelpListCommand": "List installed packages.", diff --git a/locales/messages.json b/locales/messages.json index 0562f8b649..2f9b26d7a4 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -316,7 +316,6 @@ "HelpExportCommand": "Exports a package.", "HelpFormatManifestCommand": "Formats all vcpkg.json files. Run this before committing to vcpkg.", "HelpHashCommand": "Hash a file by specific algorithm, default SHA512.", - "HelpHistoryCommand": "(Experimental) Show the history of versions of a package.", "HelpInitializeRegistryCommand": "Initializes a registry in the directory .", "HelpInstallCommand": "Install a package.", "HelpListCommand": "List installed packages.",