diff options
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg/commands.cpp | 1 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.porthistory.cpp | 91 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/help.cpp | 1 |
3 files changed, 93 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg/commands.cpp b/toolsrc/src/vcpkg/commands.cpp index 962dbd48b..1f424a559 100644 --- a/toolsrc/src/vcpkg/commands.cpp +++ b/toolsrc/src/vcpkg/commands.cpp @@ -47,6 +47,7 @@ namespace vcpkg::Commands {"autocomplete", &Autocomplete::perform_and_exit}, {"hash", &Hash::perform_and_exit}, {"fetch", &Fetch::perform_and_exit}, + {"x-history", &PortHistory::perform_and_exit}, {"x-vsinstances", &X_VSInstances::perform_and_exit}, }; return t; diff --git a/toolsrc/src/vcpkg/commands.porthistory.cpp b/toolsrc/src/vcpkg/commands.porthistory.cpp new file mode 100644 index 000000000..44fccbb7f --- /dev/null +++ b/toolsrc/src/vcpkg/commands.porthistory.cpp @@ -0,0 +1,91 @@ +#include "pch.h" + +#include <vcpkg/commands.h> +#include <vcpkg/help.h> + +#include <vcpkg/base/system.print.h> +#include <vcpkg/base/system.process.h> +#include <vcpkg/base/util.h> + +namespace vcpkg::Commands::PortHistory +{ + struct PortControlVersion + { + std::string commit_id; + std::string version; + std::string date; + }; + + static System::ExitCodeAndOutput run_git_command(const VcpkgPaths& paths, const std::string& cmd) + { + const fs::path& git_exe = paths.get_tool_exe(Tools::GIT); + const fs::path dot_git_dir = paths.root / ".git"; + + const std::string full_cmd = + Strings::format(R"("%s" --git-dir="%s" %s)", git_exe.u8string(), dot_git_dir.u8string(), cmd); + + auto output = System::cmd_execute_and_capture_output(full_cmd); + Checks::check_exit(VCPKG_LINE_INFO, output.exit_code == 0, "Failed to run command: %s", full_cmd); + return output; + } + + static std::string get_version_from_commit(const VcpkgPaths& paths, + const std::string& commit_id, + const std::string& port_name) + { + const std::string cmd = Strings::format(R"(show %s:ports/%s/CONTROL)", commit_id, port_name); + auto output = run_git_command(paths, cmd); + + const auto version = Strings::find_at_most_one_enclosed(output.output, "Version: ", "\n"); + Checks::check_exit(VCPKG_LINE_INFO, version.has_value(), "CONTROL file does not have a 'Version' field"); + return version.get()->to_string(); + } + + static std::vector<PortControlVersion> read_versions_from_log(const VcpkgPaths& paths, const std::string& port_name) + { + const std::string cmd = + Strings::format(R"(log --format="%%H %%cd" --date=short --left-only -- ports/%s/.)", port_name); + auto output = run_git_command(paths, cmd); + + auto commits = Util::fmap( + Strings::split(output.output, "\n"), [](const std::string& line) -> auto { + auto parts = Strings::split(line, " "); + return std::make_pair(parts[0], parts[1]); + }); + + std::vector<PortControlVersion> ret; + std::string last_version; + for (auto&& commit_date_pair : commits) + { + const std::string version = get_version_from_commit(paths, commit_date_pair.first, port_name); + if (last_version != version) + { + ret.emplace_back(PortControlVersion{commit_date_pair.first, version, commit_date_pair.second}); + last_version = version; + } + } + return ret; + } + + const CommandStructure COMMAND_STRUCTURE = { + Help::create_example_string("history <port>"), + 1, + 1, + {}, + nullptr, + }; + + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) + { + Util::unused(args.parse_arguments(COMMAND_STRUCTURE)); + + std::string port_name = args.command_arguments.at(0); + std::vector<PortControlVersion> versions = read_versions_from_log(paths, port_name); + System::print2(" version date vcpkg commit\n"); + for (auto&& version : versions) + { + System::printf("%20.20s %s %s\n", version.version, version.date, version.commit_id); + } + Checks::exit_success(VCPKG_LINE_INFO); + } +} diff --git a/toolsrc/src/vcpkg/help.cpp b/toolsrc/src/vcpkg/help.cpp index 9b2751739..1b8e8886e 100644 --- a/toolsrc/src/vcpkg/help.cpp +++ b/toolsrc/src/vcpkg/help.cpp @@ -91,6 +91,7 @@ namespace vcpkg::Help " vcpkg list List installed packages\n" " vcpkg update Display list of packages for updating\n" " vcpkg upgrade Rebuild all outdated packages\n" + " vcpkg history <pkg> Shows the history of CONTROL versions of a package\n" " vcpkg hash <file> [alg] Hash a file by specific algorithm, default SHA512\n" " vcpkg help topics Display the list of help topics\n" " vcpkg help <topic> Display help for a specific topic\n" |
