File tree Expand file tree Collapse file tree 10 files changed +96
-43
lines changed Expand file tree Collapse file tree 10 files changed +96
-43
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ set(GIT2CPP_SRC
49
49
${GIT2CPP_SOURCE_DIR} /utils/common.hpp
50
50
${GIT2CPP_SOURCE_DIR} /utils/git_exception.cpp
51
51
${GIT2CPP_SOURCE_DIR} /utils/git_exception.hpp
52
+ ${GIT2CPP_SOURCE_DIR} /wrapper/commit_wrapper.cpp
53
+ ${GIT2CPP_SOURCE_DIR} /wrapper/commit_wrapper.hpp
52
54
${GIT2CPP_SOURCE_DIR} /wrapper/index_wrapper.cpp
53
55
${GIT2CPP_SOURCE_DIR} /wrapper/index_wrapper.hpp
54
56
${GIT2CPP_SOURCE_DIR} /wrapper/refs_wrapper.cpp
@@ -57,6 +59,7 @@ set(GIT2CPP_SRC
57
59
${GIT2CPP_SOURCE_DIR} /wrapper/repository_wrapper.hpp
58
60
${GIT2CPP_SOURCE_DIR} /wrapper/status_wrapper.cpp
59
61
${GIT2CPP_SOURCE_DIR} /wrapper/status_wrapper.hpp
62
+ ${GIT2CPP_SOURCE_DIR} /wrapper/wrapper_base.hpp
60
63
${GIT2CPP_SOURCE_DIR} /main.cpp
61
64
${GIT2CPP_SOURCE_DIR} /version.hpp
62
65
)
Original file line number Diff line number Diff line change @@ -19,38 +19,6 @@ class noncopyable_nonmovable
19
19
~noncopyable_nonmovable () = default ;
20
20
};
21
21
22
- template <class T >
23
- class wrapper_base
24
- {
25
- public:
26
- using resource_type = T;
27
-
28
- wrapper_base (const wrapper_base&) = delete ;
29
- wrapper_base& operator =(const wrapper_base&) = delete ;
30
-
31
- wrapper_base (wrapper_base&& rhs)
32
- : p_resource(rhs.p_resource)
33
- {
34
- rhs.p_resource = nullptr ;
35
- }
36
- wrapper_base& operator =(wrapper_base&& rhs)
37
- {
38
- std::swap (p_resource, rhs.p_resource );
39
- return *this ;
40
- }
41
-
42
- operator resource_type*() const noexcept
43
- {
44
- return p_resource;
45
- }
46
-
47
- protected:
48
- // Allocation and deletion of p_resource must be handled by inheriting class.
49
- wrapper_base () = default ;
50
- ~wrapper_base () = default ;
51
- resource_type* p_resource = nullptr ;
52
- };
53
-
54
22
class libgit2_object : private noncopyable_nonmovable
55
23
{
56
24
public:
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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&&) noexcept = default ;
17
+ commit_wrapper& operator =(commit_wrapper&&) noexcept = 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
+ };
Original file line number Diff line number Diff line change 1
1
#include " index_wrapper.hpp"
2
+ #include " ../utils/common.hpp"
2
3
#include " ../utils/git_exception.hpp"
3
4
#include " ../wrapper/repository_wrapper.hpp"
4
5
Original file line number Diff line number Diff line change 5
5
6
6
#include < git2.h>
7
7
8
- #include " ../utils/common .hpp"
8
+ #include " ../wrapper/wrapper_base .hpp"
9
9
10
10
class repository_wrapper ;
11
11
@@ -15,8 +15,8 @@ class index_wrapper : public wrapper_base<git_index>
15
15
16
16
~index_wrapper ();
17
17
18
- index_wrapper (index_wrapper&&) = default ;
19
- index_wrapper& operator =(index_wrapper&&) = default ;
18
+ index_wrapper (index_wrapper&&) noexcept = default ;
19
+ index_wrapper& operator =(index_wrapper&&) noexcept = default ;
20
20
21
21
static index_wrapper init (repository_wrapper& rw);
22
22
Original file line number Diff line number Diff line change 1
1
#pragma once
2
2
3
- // #include <string>
3
+ #include < string>
4
4
5
5
#include < git2.h>
6
6
7
7
#include " ../wrapper/repository_wrapper.hpp"
8
+ #include " ../wrapper/wrapper_base.hpp"
8
9
9
10
class reference_wrapper : public wrapper_base <git_reference>
10
11
{
11
12
public:
12
13
13
14
~reference_wrapper ();
14
15
15
- reference_wrapper (reference_wrapper&&) = default ;
16
- reference_wrapper& operator =(reference_wrapper&&) = default ;
16
+ reference_wrapper (reference_wrapper&&) noexcept = default ;
17
+ reference_wrapper& operator =(reference_wrapper&&) noexcept = default ;
17
18
18
19
static std::string get_ref_name (const repository_wrapper& repo);
19
20
Original file line number Diff line number Diff line change 4
4
5
5
#include < git2.h>
6
6
7
- #include " ../utils/common.hpp"
8
7
#include " ../wrapper/index_wrapper.hpp"
8
+ #include " ../wrapper/wrapper_base.hpp"
9
9
10
10
class repository_wrapper : public wrapper_base <git_repository>
11
11
{
12
12
public:
13
13
14
14
~repository_wrapper ();
15
15
16
- repository_wrapper (repository_wrapper&&) = default ;
17
- repository_wrapper& operator =(repository_wrapper&&) = default ;
16
+ repository_wrapper (repository_wrapper&&) noexcept = default ;
17
+ repository_wrapper& operator =(repository_wrapper&&) noexcept = default ;
18
18
19
19
static repository_wrapper init (const std::string& directory, bool bare);
20
20
static repository_wrapper open (const std::string& directory);
Original file line number Diff line number Diff line change 6
6
#include < git2.h>
7
7
8
8
#include " ../wrapper/repository_wrapper.hpp"
9
+ #include " ../wrapper/wrapper_base.hpp"
9
10
10
11
class status_list_wrapper : public wrapper_base <git_status_list>
11
12
{
@@ -14,8 +15,8 @@ class status_list_wrapper : public wrapper_base<git_status_list>
14
15
15
16
~status_list_wrapper ();
16
17
17
- status_list_wrapper (status_list_wrapper&&) = default ;
18
- status_list_wrapper& operator =(status_list_wrapper&&) = default ;
18
+ status_list_wrapper (status_list_wrapper&&) noexcept = default ;
19
+ status_list_wrapper& operator =(status_list_wrapper&&) noexcept = default ;
19
20
20
21
static status_list_wrapper status_list (const repository_wrapper& wrapper);
21
22
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+
4
+ template <class T >
5
+ class wrapper_base
6
+ {
7
+ public:
8
+ using resource_type = T;
9
+
10
+ wrapper_base (const wrapper_base&) = delete ;
11
+ wrapper_base& operator =(const wrapper_base&) = delete ;
12
+
13
+ wrapper_base (wrapper_base&& rhs) noexcept
14
+ : p_resource(rhs.p_resource)
15
+ {
16
+ rhs.p_resource = nullptr ;
17
+ }
18
+ wrapper_base& operator =(wrapper_base&& rhs) noexcept
19
+ {
20
+ std::swap (p_resource, rhs.p_resource );
21
+ return *this ;
22
+ }
23
+
24
+ operator resource_type*() const noexcept
25
+ {
26
+ return p_resource;
27
+ }
28
+
29
+ protected:
30
+ // Allocation and deletion of p_resource must be handled by inheriting class.
31
+ wrapper_base () = default ;
32
+ ~wrapper_base () = default ;
33
+
34
+ resource_type* p_resource = nullptr ;
35
+ };
You can’t perform that action at this time.
0 commit comments