Skip to content

snake_case everywhere #23

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

Merged
merged 1 commit into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

int main(int argc, char** argv)
{
int exitCode = 0;
int exit_code = 0;
try
{
const libgit2_object lg2_obj;
Expand All @@ -38,17 +38,17 @@ int main(int argc, char** argv)
catch (const CLI::Error& e)
{
std::cerr << e.what() << std::endl;
exitCode = 1;
exit_code = 1;
}
catch (const GitException& e)
catch (const git_exception& e)
{
std::cerr << e.what() << std::endl;
exitCode = e.errorCode();
exit_code = e.error_code();
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
exitCode = 1;
exit_code = 1;
}

return exitCode;
return exit_code;
}
2 changes: 1 addition & 1 deletion src/subcommand/checkout_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void checkout_subcommand::checkout_tree
)
{
auto target_commit = repo.find_commit(target_annotated_commit.oid());
throwIfError(git_checkout_tree(repo, target_commit, &options));
throw_if_error(git_checkout_tree(repo, target_commit, &options));
}

void checkout_subcommand::update_head
Expand Down
19 changes: 10 additions & 9 deletions src/utils/git_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

#include "git_exception.hpp"

void throwIfError(int exitCode)
void throw_if_error(int exit_code)
{
if (exitCode < 0) {
throw GitException(git_error_last()->message, exitCode);
if (exit_code < 0)
{
throw git_exception("error: " + std::string(git_error_last()->message), exit_code);
}
}


GitException::GitException(const std::string& message, int errorCode)
: _message(message), _errorCode(errorCode)
git_exception::git_exception(const std::string& message, int error_code)
: m_message(message), m_error_code(error_code)
{}

int GitException::errorCode() const
int git_exception::error_code() const
{
return _errorCode;
return m_error_code;
}

const char* GitException::what() const noexcept
const char* git_exception::what() const noexcept
{
return _message.c_str();
return m_message.c_str();
}
12 changes: 6 additions & 6 deletions src/utils/git_exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
#include <exception>
#include <string>

void throwIfError(int exitCode);
void throw_if_error(int exit_code);

class GitException : public std::exception
class git_exception : public std::exception
{
public:
GitException(const std::string& message, int errorCode);
git_exception(const std::string& message, int error_code);

int errorCode() const;
int error_code() const;

const char* what() const noexcept override;

private:
std::string _message;
int _errorCode;
std::string m_message;
int m_error_code;
};
4 changes: 2 additions & 2 deletions src/wrapper/branch_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ branch_wrapper::~branch_wrapper()
std::string_view branch_wrapper::name() const
{
const char* out = nullptr;
throwIfError(git_branch_name(&out, *this));
throw_if_error(git_branch_name(&out, *this));
return std::string_view(out);
}

Expand All @@ -31,7 +31,7 @@ std::string_view branch_wrapper::reference_name() const

void delete_branch(branch_wrapper&& branch)
{
throwIfError(git_branch_delete(branch));
throw_if_error(git_branch_delete(branch));
}

branch_iterator::branch_iterator(git_branch_iterator* iter)
Expand Down
6 changes: 3 additions & 3 deletions src/wrapper/index_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ index_wrapper::~index_wrapper()
index_wrapper index_wrapper::init(repository_wrapper& rw)
{
index_wrapper index;
throwIfError(git_repository_index(&(index.p_resource), rw));
throw_if_error(git_repository_index(&(index.p_resource), rw));
return index;
}

Expand All @@ -31,6 +31,6 @@ void index_wrapper::add_all()
void index_wrapper::add_impl(std::vector<std::string> patterns)
{
git_strarray_wrapper array{patterns};
throwIfError(git_index_add_all(*this, array, 0, NULL, NULL));
throwIfError(git_index_write(*this));
throw_if_error(git_index_add_all(*this, array, 0, NULL, NULL));
throw_if_error(git_index_write(*this));
}
26 changes: 13 additions & 13 deletions src/wrapper/repository_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ repository_wrapper::~repository_wrapper()
repository_wrapper repository_wrapper::open(std::string_view directory)
{
repository_wrapper rw;
throwIfError(git_repository_open(&(rw.p_resource), directory.data()));
throw_if_error(git_repository_open(&(rw.p_resource), directory.data()));
return rw;
}

repository_wrapper repository_wrapper::init(std::string_view directory, bool bare)
{
repository_wrapper rw;
throwIfError(git_repository_init(&(rw.p_resource), directory.data(), bare));
throw_if_error(git_repository_init(&(rw.p_resource), directory.data(), bare));
return rw;
}

Expand All @@ -29,14 +29,14 @@ git_repository_state_t repository_wrapper::state() const
reference_wrapper repository_wrapper::head() const
{
git_reference* ref;
throwIfError(git_repository_head(&ref, *this));
throw_if_error(git_repository_head(&ref, *this));
return reference_wrapper(ref);
}

reference_wrapper repository_wrapper::find_reference(std::string_view ref_name) const
{
git_reference* ref;
throwIfError(git_reference_lookup(&ref, *this, ref_name.data()));
throw_if_error(git_reference_lookup(&ref, *this, ref_name.data()));
return reference_wrapper(ref);
}

Expand All @@ -61,49 +61,49 @@ branch_wrapper repository_wrapper::create_branch(std::string_view name, bool for
branch_wrapper repository_wrapper::create_branch(std::string_view name, const commit_wrapper& commit, bool force)
{
git_reference* branch = nullptr;
throwIfError(git_branch_create(&branch, *this, name.data(), commit, force));
throw_if_error(git_branch_create(&branch, *this, name.data(), commit, force));
return branch_wrapper(branch);
}

branch_wrapper repository_wrapper::create_branch(std::string_view name, const annotated_commit_wrapper& commit, bool force)
{
git_reference* branch = nullptr;
throwIfError(git_branch_create_from_annotated(&branch, *this, name.data(), commit, force));
throw_if_error(git_branch_create_from_annotated(&branch, *this, name.data(), commit, force));
return branch_wrapper(branch);
}

branch_wrapper repository_wrapper::find_branch(std::string_view name) const
{
git_reference* branch = nullptr;
throwIfError(git_branch_lookup(&branch, *this, name.data(), GIT_BRANCH_LOCAL));
throw_if_error(git_branch_lookup(&branch, *this, name.data(), GIT_BRANCH_LOCAL));
return branch_wrapper(branch);
}

branch_iterator repository_wrapper::iterate_branches(git_branch_t type) const
{
git_branch_iterator* iter = nullptr;
throwIfError(git_branch_iterator_new(&iter, *this, type));
throw_if_error(git_branch_iterator_new(&iter, *this, type));
return branch_iterator(iter);
}

commit_wrapper repository_wrapper::find_commit(std::string_view ref_name) const
{
git_oid oid_parent_commit;
throwIfError(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.data()));
throw_if_error(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.data()));
return find_commit(oid_parent_commit);
}

commit_wrapper repository_wrapper::find_commit(const git_oid& id) const
{
git_commit* commit;
throwIfError(git_commit_lookup(&commit, *this, &id));
throw_if_error(git_commit_lookup(&commit, *this, &id));
return commit_wrapper(commit);
}

annotated_commit_wrapper repository_wrapper::find_annotated_commit(const git_oid& id) const
{
git_annotated_commit* commit;
throwIfError(git_annotated_commit_lookup(&commit, *this, &id));
throw_if_error(git_annotated_commit_lookup(&commit, *this, &id));
return annotated_commit_wrapper(commit);
}

Expand All @@ -116,10 +116,10 @@ std::optional<object_wrapper> repository_wrapper::revparse_single(std::string_vi

void repository_wrapper::set_head(std::string_view ref_name)
{
throwIfError(git_repository_set_head(*this, ref_name.data()));
throw_if_error(git_repository_set_head(*this, ref_name.data()));
}

void repository_wrapper::set_head_detached(const annotated_commit_wrapper& commit)
{
throwIfError(git_repository_set_head_detached_from_annotated(*this, commit));
throw_if_error(git_repository_set_head_detached_from_annotated(*this, commit));
}
2 changes: 1 addition & 1 deletion src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ template <std::convertible_to<git_reference*> T>
annotated_commit_wrapper repository_wrapper::find_annotated_commit(const T& wrapper) const
{
git_annotated_commit* commit;
throwIfError(git_annotated_commit_from_ref(&commit, *this, wrapper));
throw_if_error(git_annotated_commit_from_ref(&commit, *this, wrapper));
return annotated_commit_wrapper(commit);
}
2 changes: 1 addition & 1 deletion src/wrapper/status_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ status_list_wrapper::~status_list_wrapper()
status_list_wrapper status_list_wrapper::status_list(const repository_wrapper& rw)
{
status_list_wrapper res;
throwIfError(git_status_list_new(&(res.p_resource), rw, nullptr));
throw_if_error(git_status_list_new(&(res.p_resource), rw, nullptr));

std::size_t status_list_size = git_status_list_entrycount(res.p_resource);
for (std::size_t i = 0; i < status_list_size; ++i)
Expand Down