-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrefs_wrapper.hpp
More file actions
62 lines (47 loc) · 1.42 KB
/
refs_wrapper.hpp
File metadata and controls
62 lines (47 loc) · 1.42 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
#pragma once
#include <concepts>
#include <string>
#include <git2.h>
#include "../utils/git_exception.hpp"
#include "../wrapper/object_wrapper.hpp"
#include "../wrapper/wrapper_base.hpp"
class reference_wrapper : public wrapper_base<git_reference>
{
public:
using base_type = wrapper_base<git_reference>;
~reference_wrapper();
reference_wrapper(reference_wrapper&&) noexcept = default;
reference_wrapper& operator=(reference_wrapper&&) noexcept = default;
std::string short_name() const;
bool is_remote() const;
const git_oid* target() const;
reference_wrapper write_new_ref(const git_oid target_oid);
template <class W>
W peel() const;
private:
reference_wrapper(git_reference* ref);
friend class repository_wrapper;
};
class commit_wrapper;
class object_wrapper;
// TODO: add constraints on W
// For now it accepts commit_wrapper and object_wrapper only
template <class W>
W reference_wrapper::peel() const
{
constexpr git_object_t obj_type = []
{
if constexpr (std::same_as<W, commit_wrapper>)
{
return GIT_OBJECT_COMMIT;
}
else // Default case
{
return GIT_OBJECT_ANY;
}
}();
using resource_type = typename W::resource_type;
git_object* resource = nullptr;
throw_if_error(git_reference_peel(&resource, this->p_resource, obj_type));
return W(reinterpret_cast<resource_type*>(resource));
}