git2wrap

C++20 wrapper for libgit2
git clone git://git.dimitrijedobrota.com/git2wrap.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

revwalk.cpp (1279B)


0 #include "git2wrap/revwalk.hpp"
2 #include "git2wrap/error.hpp"
3 #include "git2wrap/repository.hpp"
5 namespace git2wrap
6 {
8 revwalk::revwalk(repositoryPtr repo)
9 : m_repo(std::move(repo))
10 {
11 git_revwalk* rwalk = nullptr;
13 if (git_revwalk_new(&rwalk, m_repo.get()) != 0) {
14 throw error<error_code_t::error>();
15 }
17 m_revwalk = {rwalk, git_revwalk_free};
18 }
20 void revwalk::push(const oid& objid)
21 {
22 if (git_revwalk_push(m_revwalk.get(), objid.ptr()) != 0) {
23 throw error<error_code_t::error>();
24 }
25 }
27 void revwalk::push_glob(const char* glob)
28 {
29 if (git_revwalk_push_glob(m_revwalk.get(), glob) != 0) {
30 throw error<error_code_t::error>();
31 }
32 }
34 void revwalk::push_head()
35 {
36 if (git_revwalk_push_head(m_revwalk.get()) != 0) {
37 throw error<error_code_t::error>();
38 }
39 }
41 commit revwalk::next()
42 {
43 static git_oid objid;
45 const auto err = error_code_t(git_revwalk_next(&objid, m_revwalk.get()));
46 if (err == error_code_t::ok) {
47 return repository(m_repo).commit_lookup(oid(&objid));
48 }
50 if (err == error_code_t::iterover) {
51 return {};
52 }
54 // should not happen
55 throw error<error_code_t::error>();
56 }
58 void revwalk::reset()
59 {
60 if (git_revwalk_reset(m_revwalk.get()) != 0) {
61 throw error<error_code_t::error>();
62 }
63 }
65 } // namespace git2wrap