Skip to content

Commit 8afb85d

Browse files
committed
Skeleton for commit_wrapper
1 parent 390a21c commit 8afb85d

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ set(GIT2CPP_SRC
4949
${GIT2CPP_SOURCE_DIR}/utils/common.hpp
5050
${GIT2CPP_SOURCE_DIR}/utils/git_exception.cpp
5151
${GIT2CPP_SOURCE_DIR}/utils/git_exception.hpp
52+
${GIT2CPP_SOURCE_DIR}/wrapper/commit_wrapper.cpp
53+
${GIT2CPP_SOURCE_DIR}/wrapper/commit_wrapper.hpp
5254
${GIT2CPP_SOURCE_DIR}/wrapper/index_wrapper.cpp
5355
${GIT2CPP_SOURCE_DIR}/wrapper/index_wrapper.hpp
5456
${GIT2CPP_SOURCE_DIR}/wrapper/refs_wrapper.cpp

src/wrapper/commit_wrapper.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "commit_wrapper.hpp"
2+
#include "../utils/git_exception.hpp"
3+
4+
commit_wrapper::~commit_wrapper()
5+
{
6+
git_commit_free(p_resource);
7+
p_resource = nullptr;
8+
}
9+
10+
11+
commit_wrapper commit_wrapper::last_commit(const repository_wrapper& repo, const std::string& ref_name)
12+
{
13+
git_oid oid_parent_commit;
14+
throwIfError(git_reference_name_to_id(&oid_parent_commit, repo, ref_name.c_str()));
15+
16+
commit_wrapper cw;
17+
throwIfError(git_commit_lookup(&(cw.p_resource), repo, &oid_parent_commit));
18+
return cw;
19+
}

src/wrapper/commit_wrapper.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
#include <git2.h>
6+
7+
#include "../wrapper/repository_wrapper.hpp"
8+
#include "../wrapper/wrapper_base.hpp"
9+
10+
class commit_wrapper : public wrapper_base<git_commit>
11+
{
12+
public:
13+
14+
~commit_wrapper();
15+
16+
commit_wrapper(commit_wrapper&&) = default;
17+
commit_wrapper& operator=(commit_wrapper&&) = default;
18+
19+
static commit_wrapper
20+
last_commit(const repository_wrapper& repo, const std::string& ref_name = "HEAD");
21+
22+
private:
23+
24+
commit_wrapper() = default;
25+
};

src/wrapper/index_wrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "index_wrapper.hpp"
2+
#include "../utils/common.hpp"
23
#include "../utils/git_exception.hpp"
34
#include "../wrapper/repository_wrapper.hpp"
45

src/wrapper/index_wrapper.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <git2.h>
77

8-
#include "../utils/common.hpp"
98
#include "../wrapper/wrapper_base.hpp"
109

1110
class repository_wrapper;

src/wrapper/repository_wrapper.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <git2.h>
66

7-
#include "../utils/common.hpp"
87
#include "../wrapper/index_wrapper.hpp"
98
#include "../wrapper/wrapper_base.hpp"
109

0 commit comments

Comments
 (0)