-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[x-history] Prints CONTROL version history of a port 👻 #7377
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d9019f
[port-history] Print port CONTROL version history
vicroms 2488963
Add commands.porthistory.cpp to VS project
vicroms f198539
Get most recent commit for each version
vicroms f4f5e24
Apply clang-format
vicroms 8e3e470
Fix output format
vicroms ce24101
Merge branch 'master' of https://github.com/Microsoft/vcpkg into pr/p…
vicroms b5dbceb
Rename command to x-history
vicroms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! @vicroms It seems that
history
here should also be changed tox-history
?