Debian Codegraph @

plugins/vcs/Commit.h

raw
1 #pragma once
2
3 #include "Repository.h"
4 #include "GitException.h"
5 #include "Tree.h"
6 #include <git2.h>
7
8 namespace vcs
9 {
10
11 namespace git
12 {
13
14 class Commit final
15 {
16 private:
17 git_commit* _commit;
18
19 public:
20 using Ptr = std::shared_ptr<Commit>;
21
22 Commit(git_commit* commit) :
23 _commit(commit)
24 {}
25
26 ~Commit()
27 {
28 git_commit_free(_commit);
29 }
30
31 const git_oid* getOid() const
32 {
33 return git_commit_id(_commit);
34 }
35
36 std::shared_ptr<Tree> getTree()
37 {
38 git_tree* tree;
39 auto error = git_commit_tree(&tree, _commit);
40 GitException::ThrowOnError(error);
41
42 return std::make_shared<Tree>(tree);
43 }
44
45 static Ptr LookupFromOid(git_repository* repository, git_oid* oid)
46 {
47 git_commit* commit;
48
49 auto error = git_commit_lookup(&commit, repository, oid);
50 GitException::ThrowOnError(error);
51
52 return std::make_shared<Commit>(commit);
53 }
54
55 const git_commit* _get()
56 {
57 return _commit;
58 }
59 };
60
61 }
62
63 }