Skip to content

Commit 0c96016

Browse files
authored
snake_case everywhere (#23)
1 parent e43841f commit 0c96016

File tree

9 files changed

+43
-42
lines changed

9 files changed

+43
-42
lines changed

src/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
int main(int argc, char** argv)
1414
{
15-
int exitCode = 0;
15+
int exit_code = 0;
1616
try
1717
{
1818
const libgit2_object lg2_obj;
@@ -43,17 +43,17 @@ int main(int argc, char** argv)
4343
catch (const CLI::Error& e)
4444
{
4545
std::cerr << e.what() << std::endl;
46-
exitCode = 1;
46+
exit_code = 1;
4747
}
48-
catch (const GitException& e)
48+
catch (const git_exception& e)
4949
{
5050
std::cerr << e.what() << std::endl;
51-
exitCode = e.errorCode();
51+
exit_code = e.error_code();
5252
}
5353
catch (std::exception& e) {
5454
std::cerr << e.what() << std::endl;
55-
exitCode = 1;
55+
exit_code = 1;
5656
}
5757

58-
return exitCode;
58+
return exit_code;
5959
}

src/subcommand/checkout_subcommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void checkout_subcommand::checkout_tree
9696
)
9797
{
9898
auto target_commit = repo.find_commit(target_annotated_commit.oid());
99-
throwIfError(git_checkout_tree(repo, target_commit, &options));
99+
throw_if_error(git_checkout_tree(repo, target_commit, &options));
100100
}
101101

102102
void checkout_subcommand::update_head

src/utils/git_exception.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
#include "git_exception.hpp"
44

5-
void throwIfError(int exitCode)
5+
void throw_if_error(int exit_code)
66
{
7-
if (exitCode < 0) {
8-
throw GitException(git_error_last()->message, exitCode);
7+
if (exit_code < 0)
8+
{
9+
throw git_exception("error: " + std::string(git_error_last()->message), exit_code);
910
}
1011
}
1112

1213

13-
GitException::GitException(const std::string& message, int errorCode)
14-
: _message(message), _errorCode(errorCode)
14+
git_exception::git_exception(const std::string& message, int error_code)
15+
: m_message(message), m_error_code(error_code)
1516
{}
1617

17-
int GitException::errorCode() const
18+
int git_exception::error_code() const
1819
{
19-
return _errorCode;
20+
return m_error_code;
2021
}
2122

22-
const char* GitException::what() const noexcept
23+
const char* git_exception::what() const noexcept
2324
{
24-
return _message.c_str();
25+
return m_message.c_str();
2526
}

src/utils/git_exception.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
#include <exception>
44
#include <string>
55

6-
void throwIfError(int exitCode);
6+
void throw_if_error(int exit_code);
77

8-
class GitException : public std::exception
8+
class git_exception : public std::exception
99
{
1010
public:
11-
GitException(const std::string& message, int errorCode);
11+
git_exception(const std::string& message, int error_code);
1212

13-
int errorCode() const;
13+
int error_code() const;
1414

1515
const char* what() const noexcept override;
1616

1717
private:
18-
std::string _message;
19-
int _errorCode;
18+
std::string m_message;
19+
int m_error_code;
2020
};

src/wrapper/branch_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ branch_wrapper::~branch_wrapper()
1919
std::string_view branch_wrapper::name() const
2020
{
2121
const char* out = nullptr;
22-
throwIfError(git_branch_name(&out, *this));
22+
throw_if_error(git_branch_name(&out, *this));
2323
return std::string_view(out);
2424
}
2525

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

3232
void delete_branch(branch_wrapper&& branch)
3333
{
34-
throwIfError(git_branch_delete(branch));
34+
throw_if_error(git_branch_delete(branch));
3535
}
3636

3737
branch_iterator::branch_iterator(git_branch_iterator* iter)

src/wrapper/index_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ index_wrapper::~index_wrapper()
1414
index_wrapper index_wrapper::init(repository_wrapper& rw)
1515
{
1616
index_wrapper index;
17-
throwIfError(git_repository_index(&(index.p_resource), rw));
17+
throw_if_error(git_repository_index(&(index.p_resource), rw));
1818
return index;
1919
}
2020

@@ -31,6 +31,6 @@ void index_wrapper::add_all()
3131
void index_wrapper::add_impl(std::vector<std::string> patterns)
3232
{
3333
git_strarray_wrapper array{patterns};
34-
throwIfError(git_index_add_all(*this, array, 0, NULL, NULL));
35-
throwIfError(git_index_write(*this));
34+
throw_if_error(git_index_add_all(*this, array, 0, NULL, NULL));
35+
throw_if_error(git_index_write(*this));
3636
}

src/wrapper/repository_wrapper.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ repository_wrapper::~repository_wrapper()
1010
repository_wrapper repository_wrapper::open(std::string_view directory)
1111
{
1212
repository_wrapper rw;
13-
throwIfError(git_repository_open(&(rw.p_resource), directory.data()));
13+
throw_if_error(git_repository_open(&(rw.p_resource), directory.data()));
1414
return rw;
1515
}
1616

1717
repository_wrapper repository_wrapper::init(std::string_view directory, bool bare)
1818
{
1919
repository_wrapper rw;
20-
throwIfError(git_repository_init(&(rw.p_resource), directory.data(), bare));
20+
throw_if_error(git_repository_init(&(rw.p_resource), directory.data(), bare));
2121
return rw;
2222
}
2323

@@ -29,14 +29,14 @@ git_repository_state_t repository_wrapper::state() const
2929
reference_wrapper repository_wrapper::head() const
3030
{
3131
git_reference* ref;
32-
throwIfError(git_repository_head(&ref, *this));
32+
throw_if_error(git_repository_head(&ref, *this));
3333
return reference_wrapper(ref);
3434
}
3535

3636
reference_wrapper repository_wrapper::find_reference(std::string_view ref_name) const
3737
{
3838
git_reference* ref;
39-
throwIfError(git_reference_lookup(&ref, *this, ref_name.data()));
39+
throw_if_error(git_reference_lookup(&ref, *this, ref_name.data()));
4040
return reference_wrapper(ref);
4141
}
4242

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

6868
branch_wrapper repository_wrapper::create_branch(std::string_view name, const annotated_commit_wrapper& commit, bool force)
6969
{
7070
git_reference* branch = nullptr;
71-
throwIfError(git_branch_create_from_annotated(&branch, *this, name.data(), commit, force));
71+
throw_if_error(git_branch_create_from_annotated(&branch, *this, name.data(), commit, force));
7272
return branch_wrapper(branch);
7373
}
7474

7575
branch_wrapper repository_wrapper::find_branch(std::string_view name) const
7676
{
7777
git_reference* branch = nullptr;
78-
throwIfError(git_branch_lookup(&branch, *this, name.data(), GIT_BRANCH_LOCAL));
78+
throw_if_error(git_branch_lookup(&branch, *this, name.data(), GIT_BRANCH_LOCAL));
7979
return branch_wrapper(branch);
8080
}
8181

8282
branch_iterator repository_wrapper::iterate_branches(git_branch_t type) const
8383
{
8484
git_branch_iterator* iter = nullptr;
85-
throwIfError(git_branch_iterator_new(&iter, *this, type));
85+
throw_if_error(git_branch_iterator_new(&iter, *this, type));
8686
return branch_iterator(iter);
8787
}
8888

8989
commit_wrapper repository_wrapper::find_commit(std::string_view ref_name) const
9090
{
9191
git_oid oid_parent_commit;
92-
throwIfError(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.data()));
92+
throw_if_error(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.data()));
9393
return find_commit(oid_parent_commit);
9494
}
9595

9696
commit_wrapper repository_wrapper::find_commit(const git_oid& id) const
9797
{
9898
git_commit* commit;
99-
throwIfError(git_commit_lookup(&commit, *this, &id));
99+
throw_if_error(git_commit_lookup(&commit, *this, &id));
100100
return commit_wrapper(commit);
101101
}
102102

103103
annotated_commit_wrapper repository_wrapper::find_annotated_commit(const git_oid& id) const
104104
{
105105
git_annotated_commit* commit;
106-
throwIfError(git_annotated_commit_lookup(&commit, *this, &id));
106+
throw_if_error(git_annotated_commit_lookup(&commit, *this, &id));
107107
return annotated_commit_wrapper(commit);
108108
}
109109

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

117117
void repository_wrapper::set_head(std::string_view ref_name)
118118
{
119-
throwIfError(git_repository_set_head(*this, ref_name.data()));
119+
throw_if_error(git_repository_set_head(*this, ref_name.data()));
120120
}
121121

122122
void repository_wrapper::set_head_detached(const annotated_commit_wrapper& commit)
123123
{
124-
throwIfError(git_repository_set_head_detached_from_annotated(*this, commit));
124+
throw_if_error(git_repository_set_head_detached_from_annotated(*this, commit));
125125
}

src/wrapper/repository_wrapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ template <std::convertible_to<git_reference*> T>
7272
annotated_commit_wrapper repository_wrapper::find_annotated_commit(const T& wrapper) const
7373
{
7474
git_annotated_commit* commit;
75-
throwIfError(git_annotated_commit_from_ref(&commit, *this, wrapper));
75+
throw_if_error(git_annotated_commit_from_ref(&commit, *this, wrapper));
7676
return annotated_commit_wrapper(commit);
7777
}

src/wrapper/status_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ status_list_wrapper::~status_list_wrapper()
1010
status_list_wrapper status_list_wrapper::status_list(const repository_wrapper& rw)
1111
{
1212
status_list_wrapper res;
13-
throwIfError(git_status_list_new(&(res.p_resource), rw, nullptr));
13+
throw_if_error(git_status_list_new(&(res.p_resource), rw, nullptr));
1414

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

0 commit comments

Comments
 (0)