#include
#include
#include
#include
#include
#include
#include "log_subcommand.hpp"
#include "../wrapper/repository_wrapper.hpp"
#include "../wrapper/commit_wrapper.hpp"
log_subcommand::log_subcommand(const libgit2_object&, CLI::App& app)
{
auto *sub = app.add_subcommand("log", "Shows commit logs");
sub->add_flag("--format", m_format_flag, "Pretty-print the contents of the commit logs in a given format, where can be one of full and fuller");
sub->add_option("-n,--max-count", m_max_count_flag, "Limit the output to commits.");
// sub->add_flag("--oneline", m_oneline_flag, "This is a shorthand for --pretty=oneline --abbrev-commit used together.");
sub->callback([this]() { this->run(); });
};
void print_time(git_time intime, std::string prefix)
{
char sign, out[32];
struct tm *intm;
int offset, hours, minutes;
time_t t;
offset = intime.offset;
if (offset < 0) {
sign = '-';
offset = -offset;
}
else
{
sign = '+';
}
hours = offset / 60;
minutes = offset % 60;
t = (time_t)intime.time + (intime.offset * 60);
intm = gmtime(&t);
strftime(out, sizeof(out), "%a %b %e %T %Y", intm);
std::cout << prefix << out << " " << sign << std::format("{:02d}", hours) << std::format("{:02d}", minutes) <<:endl void print_commit commit_wrapper commit std::string m_format_flag buf="commit.commit_oid_tostr();" signature_wrapper author="signature_wrapper::get_commit_author(commit);" committer="signature_wrapper::get_commit_committer(commit);" stream_colour_fn colour="termcolor::yellow;" std::cout termcolor::reset std::endl if author.name author.email print_time committer.name committer.email else git_commit_message log_subcommand::run auto directory="get_current_git_path();" repo="repository_wrapper::open(directory);" branch_name="repo.head().short_name();" git_revwalk walker git_revwalk_new git_revwalk_push_head std::size_t i="0;" git_oid commit_oid while git_revwalk_free>