From 964cd5b4c3beb0dee3a05e96fd17a000ec0ccd5d Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Tue, 22 Jul 2025 21:23:34 +0200 Subject: [PATCH] snake_case everywhere --- src/main.cpp | 12 ++++++------ src/subcommand/checkout_subcommand.cpp | 2 +- src/utils/git_exception.cpp | 19 ++++++++++--------- src/utils/git_exception.hpp | 12 ++++++------ src/wrapper/branch_wrapper.cpp | 4 ++-- src/wrapper/index_wrapper.cpp | 6 +++--- src/wrapper/repository_wrapper.cpp | 26 +++++++++++++------------- src/wrapper/repository_wrapper.hpp | 2 +- src/wrapper/status_wrapper.cpp | 2 +- 9 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 55e8a24..afc3821 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,7 @@ int main(int argc, char** argv) { - int exitCode = 0; + int exit_code = 0; try { const libgit2_object lg2_obj; @@ -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; } diff --git a/src/subcommand/checkout_subcommand.cpp b/src/subcommand/checkout_subcommand.cpp index 67b8644..09491b8 100644 --- a/src/subcommand/checkout_subcommand.cpp +++ b/src/subcommand/checkout_subcommand.cpp @@ -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 diff --git a/src/utils/git_exception.cpp b/src/utils/git_exception.cpp index d8357f9..7be528f 100644 --- a/src/utils/git_exception.cpp +++ b/src/utils/git_exception.cpp @@ -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(); } diff --git a/src/utils/git_exception.hpp b/src/utils/git_exception.hpp index fdff3a1..673949d 100644 --- a/src/utils/git_exception.hpp +++ b/src/utils/git_exception.hpp @@ -3,18 +3,18 @@ #include #include -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; }; diff --git a/src/wrapper/branch_wrapper.cpp b/src/wrapper/branch_wrapper.cpp index bc0af64..b4fc906 100644 --- a/src/wrapper/branch_wrapper.cpp +++ b/src/wrapper/branch_wrapper.cpp @@ -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); } @@ -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) diff --git a/src/wrapper/index_wrapper.cpp b/src/wrapper/index_wrapper.cpp index 4baff3f..81b1c26 100644 --- a/src/wrapper/index_wrapper.cpp +++ b/src/wrapper/index_wrapper.cpp @@ -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; } @@ -31,6 +31,6 @@ void index_wrapper::add_all() void index_wrapper::add_impl(std::vector 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)); } diff --git a/src/wrapper/repository_wrapper.cpp b/src/wrapper/repository_wrapper.cpp index 9c9a0e0..8029d05 100644 --- a/src/wrapper/repository_wrapper.cpp +++ b/src/wrapper/repository_wrapper.cpp @@ -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; } @@ -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); } @@ -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); } @@ -116,10 +116,10 @@ std::optional 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)); } diff --git a/src/wrapper/repository_wrapper.hpp b/src/wrapper/repository_wrapper.hpp index a33c4a3..e2b9c60 100644 --- a/src/wrapper/repository_wrapper.hpp +++ b/src/wrapper/repository_wrapper.hpp @@ -72,6 +72,6 @@ template 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); } diff --git a/src/wrapper/status_wrapper.cpp b/src/wrapper/status_wrapper.cpp index 4f7a981..a1962d8 100644 --- a/src/wrapper/status_wrapper.cpp +++ b/src/wrapper/status_wrapper.cpp @@ -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)