aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Romero <romerosanchezv@gmail.com>2019-09-06 11:35:56 -0700
committerGitHub <noreply@github.com>2019-09-06 11:35:56 -0700
commit84ba23ad3300a86e00841c5e26cbf753f6e89f3f (patch)
tree789b5892900ad7b47806b2af0077762f52cc6d20
parent33f15e40e858dcabddd1f1cc1b67368778516fbf (diff)
downloadvcpkg-84ba23ad3300a86e00841c5e26cbf753f6e89f3f.tar.gz
vcpkg-84ba23ad3300a86e00841c5e26cbf753f6e89f3f.zip
[x-history] Prints CONTROL version history of a port 👻 (#7377)
* [port-history] Print port CONTROL version history * Add commands.porthistory.cpp to VS project * Get most recent commit for each version * Apply clang-format * Fix output format * Rename command to x-history
-rw-r--r--toolsrc/include/vcpkg/commands.h5
-rw-r--r--toolsrc/src/vcpkg/commands.cpp1
-rw-r--r--toolsrc/src/vcpkg/commands.porthistory.cpp91
-rw-r--r--toolsrc/src/vcpkg/help.cpp1
-rw-r--r--toolsrc/vcpkglib/vcpkglib.vcxproj1
-rw-r--r--toolsrc/vcpkglib/vcpkglib.vcxproj.filters3
6 files changed, 102 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg/commands.h b/toolsrc/include/vcpkg/commands.h
index 8a502122e..e73077e1d 100644
--- a/toolsrc/include/vcpkg/commands.h
+++ b/toolsrc/include/vcpkg/commands.h
@@ -100,6 +100,11 @@ namespace vcpkg::Commands
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
}
+ namespace PortHistory
+ {
+ void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
+ }
+
namespace Autocomplete
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
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"
diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj
index 568d316c6..ebbac85a6 100644
--- a/toolsrc/vcpkglib/vcpkglib.vcxproj
+++ b/toolsrc/vcpkglib/vcpkglib.vcxproj
@@ -238,6 +238,7 @@
<ClCompile Include="..\src\vcpkg\commands.integrate.cpp" />
<ClCompile Include="..\src\vcpkg\commands.list.cpp" />
<ClCompile Include="..\src\vcpkg\commands.owns.cpp" />
+ <ClCompile Include="..\src\vcpkg\commands.porthistory.cpp" />
<ClCompile Include="..\src\vcpkg\commands.portsdiff.cpp" />
<ClCompile Include="..\src\vcpkg\commands.search.cpp" />
<ClCompile Include="..\src\vcpkg\commands.upgrade.cpp" />
diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
index 1074a5116..beefedd78 100644
--- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
+++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
@@ -219,6 +219,9 @@
<ClCompile Include="..\src\vcpkg\base\system.print.cpp">
<Filter>Source Files\vcpkg\base</Filter>
</ClCompile>
+ <ClCompile Include="..\src\vcpkg\commands.porthistory.cpp">
+ <Filter>Source Files\vcpkg</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\pch.h">