Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address review comment
  • Loading branch information
SandrineP committed Mar 11, 2026
commit b66f83d11368f5f011396fd1895459461f98d123
40 changes: 18 additions & 22 deletions src/subcommand/revparse_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,29 @@ void revparse_subcommand::run()
auto repo = repository_wrapper::open(directory);

size_t i = 0;
if (!m_queries_in_order.empty())
for (const auto& q : m_queries_in_order)
{
for (const auto& q : m_queries_in_order)
if (q == "is_bare")
{
if (q == "is_bare")
{
std::cout << std::boolalpha << repo.is_bare() << std::endl;
}
else if (q == "is_shallow")
std::cout << std::boolalpha << repo.is_bare() << std::endl;
}
else if (q == "is_shallow")
{
std::cout << std::boolalpha << repo.is_shallow() << std::endl;
}
else if (q == "is_rev")
{
const auto& rev = m_revisions[i];
auto obj = repo.revparse_single(rev.c_str());

if (!obj.has_value())
{
std::cout << std::boolalpha << repo.is_shallow() << std::endl;
throw git_exception("bad revision '" + rev + "'", git2cpp_error_code::BAD_ARGUMENT);
}
else if (q == "is_rev")
{
const auto& rev = m_revisions[i];
auto obj = repo.revparse_single(rev.c_str());

if (!obj.has_value())
{
throw git_exception("bad revision '" + rev + "'", git2cpp_error_code::BAD_ARGUMENT);
}

auto oid = obj.value().oid();
std::cout << git_oid_tostr_s(&oid) << std::endl;
i += 1;
}
auto oid = obj.value().oid();
std::cout << git_oid_tostr_s(&oid) << std::endl;
i += 1;
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using else here would avoid the need for the previous return statement

return;
}
Loading