forked from QuantStack/git2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_wrapper.cpp
More file actions
43 lines (36 loc) · 1 KB
/
commit_wrapper.cpp
File metadata and controls
43 lines (36 loc) · 1 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
#include "../wrapper/commit_wrapper.hpp"
commit_wrapper::commit_wrapper(git_commit* commit)
: base_type(commit)
{
}
commit_wrapper::~commit_wrapper()
{
git_commit_free(p_resource);
p_resource = nullptr;
}
commit_wrapper::operator git_object*() const noexcept
{
return reinterpret_cast<git_object*>(p_resource);
}
const git_oid& commit_wrapper::oid() const
{
return *git_commit_id(p_resource);
}
std::string commit_wrapper::commit_oid_tostr() const
{
char buf[GIT_OID_SHA1_HEXSIZE + 1];
return git_oid_tostr(buf, sizeof(buf), &this->oid());
}
commit_list_wrapper commit_wrapper::get_parents_list() const
{
size_t parent_count = git_commit_parentcount(*this);
std::vector<commit_wrapper> parents_list;
parents_list.reserve(parent_count);
for (size_t i=0; i < parent_count; ++i)
{
git_commit* parent;
git_commit_parent(&parent, *this, i);
parents_list.push_back(commit_wrapper(parent));
}
return commit_list_wrapper(std::move(parents_list));
}