Skip to content

Commit 16cfe1c

Browse files
committed
add committer option
1 parent a509df8 commit 16cfe1c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/subcommand/log_subcommand.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ log_subcommand::log_subcommand(const libgit2_object&, CLI::App& app)
1919
{
2020
auto *sub = app.add_subcommand("log", "Shows commit logs");
2121

22-
sub->add_flag("-n,--max-count", m_max_count_flag, "Limit the output to <number> commits.");
22+
sub->add_flag("--format", m_format_flag, "Pretty-print the contents of the commit logs in a given format, where <format> can be one of full and fuller");
23+
// sub->add_flag("-n,--max-count", m_max_count_flag, "Limit the output to <number> commits.");
2324
// sub->add_flag("--oneline", m_oneline_flag, "This is a shorthand for --pretty=oneline --abbrev-commit used together.");
2425

2526
sub->callback([this]() { this->run(); });
@@ -51,7 +52,7 @@ void print_time(git_time intime, const char *prefix)
5152
printf("%s%s %c%02d%02d\n", prefix, out, sign, hours, minutes);
5253
}
5354

54-
void print_commit(const commit_wrapper& commit)
55+
void print_commit(const commit_wrapper& commit, std::string m_format_flag)
5556
{
5657
// TODO: put in commit_wrapper ?
5758
char buf[GIT_OID_SHA1_HEXSIZE + 1];
@@ -61,10 +62,24 @@ void print_commit(const commit_wrapper& commit)
6162
// TODO end
6263

6364
signature_wrapper author = signature_wrapper::get_commit_author(commit);
65+
signature_wrapper committer = signature_wrapper::get_commit_committer(commit);
6466

65-
std::cout << "commit " << buf << std::endl;
67+
std::cout << "\033[0;33m" << "commit " << buf << "\033[0m" << std::endl;
6668
std::cout << "Author:\t" << author.name() << " " << author.email() << std::endl;
67-
print_time(author.when(), "Date:\t");
69+
if (m_format_flag=="full")
70+
{
71+
std::cout << "Commit:\t" << committer.name() << " " << committer.email() << std::endl;
72+
}
73+
else if (m_format_flag=="fuller")
74+
{
75+
print_time(author.when(), "AuthorDate:\t");
76+
std::cout << "Commit:\t" << committer.name() << " " << committer.email() << std::endl;
77+
print_time(committer.when(), "CommitDate:\t");
78+
}
79+
else
80+
{
81+
print_time(author.when(), "Date:\t");
82+
}
6883
std::cout << git_commit_message(commit) << "\n" << std::endl;
6984
}
7085

@@ -83,6 +98,6 @@ void log_subcommand::run()
8398
while (!git_revwalk_next(&commit_oid, walker))
8499
{
85100
commit_wrapper commit = repo.find_commit(commit_oid);
86-
print_commit(commit);
101+
print_commit(commit, m_format_flag);
87102
}
88103
}

src/subcommand/log_subcommand.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class log_subcommand
1313
void run();
1414

1515
private:
16-
int m_max_count_flag;
16+
std::string m_format_flag;
17+
// int m_max_count_flag;
1718
// bool m_oneline_flag = false;
1819
};

0 commit comments

Comments
 (0)