Skip to content

Commit 40aac5e

Browse files
committed
address review cooment
1 parent 87be596 commit 40aac5e

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/subcommand/log_subcommand.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ void log_subcommand::print_commit(repository_wrapper& repo, const commit_wrapper
230230

231231
std::string message = commit.message();
232232
while (!message.empty() && message.back() == '\n')
233+
{
233234
message.pop_back();
235+
}
234236

235237
if (oneline)
236238
{

src/subcommand/revparse_subcommand.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ revparse_subcommand::revparse_subcommand(const libgit2_object&, CLI::App& app)
88

99
auto* bare_opt = sub->add_flag("--is-bare-repository", m_is_bare_repository_flag, "When the repository is bare print \"true\", otherwise \"false\".");
1010
auto* shallow_opt = sub->add_flag("--is-shallow-repository", m_is_shallow_repository_flag, "When the repository is shallow print \"true\", otherwise \"false\".");
11+
auto* rev_opt = sub->add_option("<rev>", m_revisions, "Revision(s) to parse (e.g. HEAD, main, HEAD~1, dae86e, ...)");
1112

12-
sub->add_option("<rev>", m_revisions, "Revision(s) to parse (e.g. HEAD, main, HEAD~1, dae86e, ...)");
13-
14-
sub->parse_complete_callback([this, sub, bare_opt, shallow_opt]() {
13+
sub->parse_complete_callback([this, sub, bare_opt, shallow_opt, rev_opt]() {
1514
for (CLI::Option* opt : sub->parse_order())
1615
{
1716
if (opt == bare_opt)
@@ -22,6 +21,10 @@ revparse_subcommand::revparse_subcommand(const libgit2_object&, CLI::App& app)
2221
{
2322
m_queries_in_order.push_back("is_shallow");
2423
}
24+
else if (opt == rev_opt)
25+
{
26+
m_queries_in_order.push_back("is_rev");
27+
}
2528
}
2629
});
2730

@@ -45,27 +48,26 @@ void revparse_subcommand::run()
4548
{
4649
std::cout << std::boolalpha << repo.is_shallow() << std::endl;
4750
}
48-
}
49-
return;
50-
}
51+
if (q == "is_rev")
52+
{
53+
for (const auto& rev : m_revisions)
54+
{
55+
auto obj = repo.revparse_single(rev.c_str());
5156

52-
if (!m_revisions.empty())
53-
{
54-
for (const auto& rev : m_revisions)
55-
{
56-
auto obj = repo.revparse_single(rev.c_str());
57+
if (!obj.has_value())
58+
{
59+
throw git_exception("bad revision '" + rev + "'", git2cpp_error_code::BAD_ARGUMENT);
60+
}
5761

58-
if (!obj.has_value())
59-
{
60-
throw git_exception("bad revision '" + rev + "'", git2cpp_error_code::BAD_ARGUMENT);
61-
return;
62+
auto oid = obj.value().oid();
63+
std::cout << git_oid_tostr_s(&oid) << std::endl;
64+
}
6265
}
63-
64-
auto oid = obj.value().oid();
65-
std::cout << git_oid_tostr_s(&oid) << std::endl;
6666
}
67-
return;
6867
}
69-
70-
std::cout << "revparse only supports --is-bare-repository, --is-shallow-repository and parsing revisions for now" << std::endl;
68+
else
69+
{
70+
std::cout << "revparse only supports --is-bare-repository, --is-shallow-repository and parsing revisions for now" << std::endl;
71+
}
72+
return;
7173
}

0 commit comments

Comments
 (0)