-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbranch_wrapper.cpp
More file actions
62 lines (52 loc) · 1.23 KB
/
branch_wrapper.cpp
File metadata and controls
62 lines (52 loc) · 1.23 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
#include "../wrapper/branch_wrapper.hpp"
#include <iostream>
#include "../utils/git_exception.hpp"
#include "../wrapper/commit_wrapper.hpp"
#include "../wrapper/repository_wrapper.hpp"
branch_wrapper::branch_wrapper(git_reference* ref)
: base_type(ref)
{
}
branch_wrapper::~branch_wrapper()
{
git_reference_free(p_resource);
p_resource = nullptr;
}
std::string_view branch_wrapper::name() const
{
const char* out = nullptr;
throw_if_error(git_branch_name(&out, *this));
return std::string_view(out);
}
std::string_view branch_wrapper::reference_name() const
{
const char* out = git_reference_name(*this);
return out ? out : std::string_view();
}
void delete_branch(branch_wrapper&& branch)
{
throw_if_error(git_branch_delete(branch));
}
branch_iterator::branch_iterator(git_branch_iterator* iter)
: base_type(iter)
{
}
branch_iterator::~branch_iterator()
{
git_branch_iterator_free(p_resource);
p_resource = nullptr;
}
std::optional<branch_wrapper> branch_iterator::next()
{
git_reference* ref = nullptr;
git_branch_t type;
int res = git_branch_next(&ref, &type, p_resource);
if (res == 0)
{
return branch_wrapper(ref);
}
else
{
return std::nullopt;
}
}