File tree Expand file tree Collapse file tree 5 files changed +73
-30
lines changed Expand file tree Collapse file tree 5 files changed +73
-30
lines changed Original file line number Diff line number Diff line change 1
- #ifndef CPPGIT_GIT_HPP
2
- #define CPPGIT_GIT_HPP
1
+ #ifndef CPPGIT_GIT2API_HPP
2
+ #define CPPGIT_GIT2API_HPP
3
3
4
4
#include < tuple>
5
-
5
+ # include < atomic >
6
6
namespace cppgit {
7
7
// =====================================================================================
8
8
// Class: Git
9
9
// Description:
10
10
// =====================================================================================
11
- class Git {
11
+ class Git2API {
12
12
public:
13
13
// ==================== LIFECYCLE =======================================
14
- Git ();
15
- ~Git ();
14
+ Git2API ();
15
+ Git2API (const Git2API &);
16
+ Git2API (Git2API &&) = delete ;
17
+ Git2API &operator =(const Git2API &) = default ;
18
+ Git2API &operator =(Git2API &&) = delete ;
19
+ virtual ~Git2API ();
16
20
// ==================== ACCESSORS =======================================
21
+ [[nodiscard]] static int counter () noexcept ;
17
22
[[nodiscard]] static std::tuple<int , int , int > version ();
18
23
// ==================== MUTATORS =======================================
19
24
// ==================== OPERATORS =======================================
@@ -23,7 +28,8 @@ class Git {
23
28
private:
24
29
// ==================== METHODS =======================================
25
30
// ==================== DATA MEMBERS =======================================
26
- }; // ----- end of class Git -----
31
+ inline static std::atomic<int > m_init_counter{0 };
32
+ }; // ----- end of class Git2API -----
27
33
} // namespace cppgit
28
34
29
35
#endif
Original file line number Diff line number Diff line change 1
1
#ifndef CPPGIT_HPP
2
2
#define CPPGIT_HPP
3
3
4
+ #include " cppgit/git2api.hpp"
4
5
#include < tuple>
5
6
6
7
namespace cppgit {
@@ -9,7 +10,7 @@ namespace cppgit {
9
10
// Description:
10
11
//
11
12
// =====================================================================================
12
- class Repository {
13
+ class Repository : private Git2API {
13
14
public:
14
15
// ==================== LIFECYCLE =======================================
15
16
Repository ();
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ #include " cppgit/git2api.hpp"
2
+ #include " cppgit/exception.hpp"
3
+ #include < git2.h>
4
+
5
+ namespace cppgit {
6
+
7
+ Git2API::Git2API () {
8
+ if (++m_init_counter == 1 ) {
9
+ git_libgit2_init ();
10
+ }
11
+ }
12
+
13
+ Git2API::Git2API (const Git2API&) {
14
+ ++m_init_counter;
15
+ }
16
+
17
+
18
+ Git2API::~Git2API () {
19
+ if (--m_init_counter == 0 ){
20
+ git_libgit2_shutdown ();
21
+ }
22
+ }
23
+
24
+ int Git2API::counter () noexcept {
25
+ return Git2API::m_init_counter;
26
+ }
27
+ std::tuple<int , int , int > Git2API::version () {
28
+ int major = 0 , minor = 0 , revision = 0 ;
29
+ if (git_libgit2_version (&major, &minor, &revision) != 0 ) {
30
+ //
31
+ throw Exception ();
32
+ }
33
+ return {major, minor, revision};
34
+ }
35
+
36
+ } // namespace cppgit
Original file line number Diff line number Diff line change 1
1
2
+ #include " cppgit/git2api.hpp"
2
3
#include " cppgit/version.hpp"
3
4
#include < doctest/doctest.h>
4
5
#include < iostream>
5
6
#include < string>
6
7
7
- TEST_CASE (" Greeter version" ) {
8
+ class Object : private cppgit ::Git2API {
9
+
10
+ };
11
+
12
+ TEST_CASE (" Version" ) {
8
13
static_assert (std::string_view (CPPGIT_VERSION) == std::string_view (" 1.0.0" ));
9
14
CHECK (std::string (CPPGIT_VERSION) == std::string (" 1.0.0" ));
10
15
}
16
+
17
+ TEST_CASE (" Initialization Test" ) {
18
+ {
19
+ const cppgit::Git2API git_obj1;
20
+ {
21
+ const cppgit::Git2API git_obj2;
22
+ const Object git_obj3;
23
+ CHECK (cppgit::Git2API::counter () == 3 );
24
+ }
25
+ CHECK (cppgit::Git2API::counter () == 1 );
26
+ const cppgit::Git2API git_obj2;
27
+ CHECK (cppgit::Git2API::counter () == 2 );
28
+ }
29
+ CHECK (cppgit::Git2API::counter () == 0 );
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments