forked from olipfei/cbvcs
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgit_libgit2_wrapper.h
More file actions
73 lines (66 loc) · 2.01 KB
/
git_libgit2_wrapper.h
File metadata and controls
73 lines (66 loc) · 2.01 KB
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
#ifndef GIT_LIBGIT2_WRAPPER_H_INCLUDED
#define GIT_LIBGIT2_WRAPPER_H_INCLUDED
#include <git2.h>
class GitRepo
{
public:
git_repository* m_repo{nullptr};
GitRepo(const wxString& workDir)
{
int error = git_repository_open(&m_repo, workDir.ToUTF8().data());
if (0 != error)
{
const git_error* e = git_error_last();
fprintf(stderr, "LibGit2::%s:%d git_repository_open failed : %d/%d: %s\n", __FUNCTION__, __LINE__, error, e->klass, e->message);
}
}
~GitRepo()
{
if (m_repo)
{
git_repository_free(m_repo);
}
}
};
class GitRepoIndex
{
public:
git_index* m_idx{nullptr};
GitRepo m_gitRepo;
GitRepoIndex(const wxString& workDir) : m_gitRepo(workDir)
{
if (m_gitRepo.m_repo)
{
int error = git_repository_index(&m_idx, m_gitRepo.m_repo);
if (0 != error)
{
const git_error* e = git_error_last();
fprintf(stderr, "LibGit2::%s:%d git_repository_index failed : %d/%d: %s\n", __FUNCTION__, __LINE__, error, e->klass, e->message);
}
error = git_index_read(m_idx, true);
if (0 != error)
{
const git_error* e = git_error_last();
fprintf(stderr, "LibGit2::%s:%d git_index_read failed : %d/%d: %s\n", __FUNCTION__, __LINE__, error, e->klass, e->message);
}
}
else
{
fprintf(stderr, "LibGit2::%s:%d gitRepo.m_repo not available\n", __FUNCTION__, __LINE__);
}
}
~GitRepoIndex()
{
if (m_idx)
{
int error = git_index_write(m_idx);
if (0 != error)
{
const git_error* e = git_error_last();
fprintf(stderr, "LibGit2::%s:%d git_index_read failed : %d/%d: %s\n", __FUNCTION__, __LINE__, error, e->klass, e->message);
}
git_index_free(m_idx);
}
}
};
#endif // GIT_LIBGIT2_WRAPPER_H_INCLUDED