Skip to content

Commit 4f7ffc5

Browse files
committed
commit_wrapper now built from reposiroty_wrapper
1 parent 171dc28 commit 4f7ffc5

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

src/wrapper/commit_wrapper.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
#include "../utils/git_exception.hpp"
21
#include "../wrapper/commit_wrapper.hpp"
3-
#include "../wrapper/repository_wrapper.hpp"
2+
3+
commit_wrapper::commit_wrapper(git_commit* commit)
4+
: base_type(commit)
5+
{
6+
}
47

58
commit_wrapper::~commit_wrapper()
69
{
710
git_commit_free(p_resource);
811
p_resource = nullptr;
912
}
1013

11-
12-
commit_wrapper commit_wrapper::from_reference_name(const repository_wrapper& repo, const std::string& ref_name)
14+
/*commit_wrapper commit_wrapper::from_reference_name(const repository_wrapper& repo, const std::string& ref_name)
1315
{
1416
git_oid oid_parent_commit;
1517
throwIfError(git_reference_name_to_id(&oid_parent_commit, repo, ref_name.c_str()));
1618
1719
commit_wrapper cw;
1820
throwIfError(git_commit_lookup(&(cw.p_resource), repo, &oid_parent_commit));
1921
return cw;
20-
}
22+
}*/

src/wrapper/commit_wrapper.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
#pragma once
22

3-
#include <string>
4-
53
#include <git2.h>
64

75
#include "../wrapper/wrapper_base.hpp"
86

9-
class repository_wrapper;
10-
117
class commit_wrapper : public wrapper_base<git_commit>
128
{
139
public:
1410

11+
using base_type = wrapper_base<git_commit>;
12+
1513
~commit_wrapper();
1614

1715
commit_wrapper(commit_wrapper&&) noexcept = default;
1816
commit_wrapper& operator=(commit_wrapper&&) noexcept = default;
1917

20-
static commit_wrapper
21-
from_reference_name(const repository_wrapper& repo, const std::string& ref_name = "HEAD");
22-
2318
private:
2419

25-
commit_wrapper() = default;
20+
commit_wrapper(git_commit* commit);
21+
22+
friend class repository_wrapper;
2623
};

src/wrapper/repository_wrapper.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ index_wrapper repository_wrapper::make_index()
3636

3737
branch_wrapper repository_wrapper::create_branch(const std::string& name, bool force)
3838
{
39-
return create_branch(name, commit_wrapper::from_reference_name(*this), force);
39+
return create_branch(name, find_commit(), force);
4040
}
4141

4242
branch_wrapper repository_wrapper::create_branch(const std::string& name, const commit_wrapper& commit, bool force)
@@ -59,3 +59,18 @@ branch_iterator repository_wrapper::iterate_branches(git_branch_t type) const
5959
throwIfError(git_branch_iterator_new(&iter, *this, type));
6060
return branch_iterator(iter);
6161
}
62+
63+
64+
commit_wrapper repository_wrapper::find_commit(const std::string& ref_name) const
65+
{
66+
git_oid oid_parent_commit;
67+
throwIfError(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.c_str()));
68+
return find_commit(oid_parent_commit);
69+
}
70+
71+
commit_wrapper repository_wrapper::find_commit(const git_oid& id) const
72+
{
73+
git_commit* commit;
74+
throwIfError(git_commit_lookup(&commit, *this, &id));
75+
return commit_wrapper(commit);
76+
}

src/wrapper/repository_wrapper.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class repository_wrapper : public wrapper_base<git_repository>
3333

3434
branch_iterator iterate_branches(git_branch_t type) const;
3535

36+
// Commits
37+
38+
commit_wrapper find_commit(const std::string& ref_name = "HEAD") const;
39+
commit_wrapper find_commit(const git_oid& id) const;
40+
3641
private:
3742

3843
repository_wrapper() = default;

src/wrapper/wrapper_base.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <utility>
34

45
template <class T>
56
class wrapper_base

0 commit comments

Comments
 (0)