-
Notifications
You must be signed in to change notification settings - Fork 2
/
LibGitInitializer.cpp
74 lines (59 loc) · 1.45 KB
/
LibGitInitializer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "LibGitInitializer.h"
#include <git2.h>
#include "LibGitException.h"
using LibGitInitializer = Git::LibGitInitializer;
using LibGitException = Git::LibGitException;
int LibGitInitializer::numOfLibGitInitializers = 0;
void LibGitInitializer::checkLibGitError(int errorCode) const
{
if(0 != errorCode)
{
//std::cout << giterr_last()->message;
if(giterr_last())
{
throw LibGitException(*giterr_last(), errorCode);
}
else
{
if(GIT_EUSER == errorCode)
{
throw LibGitException("User interruption", errorCode);
}
else
{
throw LibGitException("Unknown", errorCode);
}
}
}
}
LibGitInitializer::LibGitInitializer()
{
init();
}
LibGitInitializer::LibGitInitializer(const LibGitInitializer& toCopy)
{
(void) toCopy;
init();
}
LibGitInitializer& LibGitInitializer::operator=(const LibGitInitializer& toAssign)
{
(void) toAssign;
init();
return *this;
}
LibGitInitializer::~LibGitInitializer()
{
--LibGitInitializer::numOfLibGitInitializers;
if(0 == LibGitInitializer::numOfLibGitInitializers)
{
git_libgit2_shutdown();
}
}
/*private*/ void LibGitInitializer::init() const
{
if(0 == LibGitInitializer::numOfLibGitInitializers)
{
git_libgit2_init();
}
++LibGitInitializer::numOfLibGitInitializers;
}