This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrevwalk.cpp
More file actions
109 lines (86 loc) · 2.68 KB
/
Copy pathrevwalk.cpp
File metadata and controls
109 lines (86 loc) · 2.68 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <cppgit2/repository.hpp>
using namespace cppgit2;
#include <functional>
revwalk::revwalk()
: done_(false), c_ptr_(nullptr), owner_(ownership::libgit2) {}
// Construct from libgit2 C ptr
revwalk::revwalk(git_revwalk *c_ptr, ownership owner)
: done_(false), c_ptr_(c_ptr), owner_(owner) {}
// Cleanup revwalk
revwalk::~revwalk() {
if (c_ptr_ && owner_ == ownership::user)
git_revwalk_free(c_ptr_);
}
void revwalk::add_hide_callback(std::function<int(const oid &)> callback) {
struct visitor_wrapper {
std::function<int(const oid &)> fn;
};
visitor_wrapper wrapper;
wrapper.fn = callback;
auto callback_c = [](const git_oid *commit_id, void *payload) {
auto wrapper = reinterpret_cast<visitor_wrapper *>(payload);
return wrapper->fn(oid(commit_id));
};
if (git_revwalk_add_hide_cb(c_ptr_, callback_c, (void *)(&wrapper)))
throw git_exception();
}
bool revwalk::done() const { return done_; }
void revwalk::hide(const oid &commit_id) {
if (git_revwalk_hide(c_ptr_, commit_id.c_ptr()))
throw git_exception();
}
void revwalk::hide_glob(const std::string &glob) {
if (git_revwalk_hide_glob(c_ptr_, glob.c_str()))
throw git_exception();
}
void revwalk::hide_head() {
if (git_revwalk_hide_head(c_ptr_))
throw git_exception();
}
void revwalk::hide_reference(const std::string &ref) {
if (git_revwalk_hide_ref(c_ptr_, ref.c_str()))
throw git_exception();
}
oid revwalk::next() {
oid result;
if (git_revwalk_next(result.c_ptr(), c_ptr_) == GIT_ITEROVER)
done_ = true;
return result;
}
void revwalk::push(const oid &id) {
if (git_revwalk_push(c_ptr_, id.c_ptr()))
throw git_exception();
}
void revwalk::push_glob(const std::string &glob) {
if (git_revwalk_push_glob(c_ptr_, glob.c_str()))
throw git_exception();
}
void revwalk::push_head() {
if (git_revwalk_push_head(c_ptr_))
throw git_exception();
}
void revwalk::push_range(const std::string &range) {
if (git_revwalk_push_range(c_ptr_, range.c_str()))
throw git_exception();
}
void revwalk::push_reference(const std::string &ref) {
if (git_revwalk_push_ref(c_ptr_, ref.c_str()))
throw git_exception();
}
cppgit2::repository revwalk::repository() {
return cppgit2::repository(git_revwalk_repository(c_ptr_));
}
void revwalk::reset() {
done_ = false;
if (git_revwalk_reset(c_ptr_))
throw git_exception();
}
void revwalk::set_sorting_mode(revwalk::sort sorting_mode) {
if (git_revwalk_sorting(c_ptr_, static_cast<unsigned int>(sorting_mode)))
throw git_exception();
}
void revwalk::simplify_first_parent() {
if (git_revwalk_simplify_first_parent(c_ptr_))
throw git_exception();
}
const git_revwalk *revwalk::c_ptr() const { return c_ptr_; }