git2wrapC++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 (1193B)
1 #include "git2wrap/revwalk.hpp" 2 3 #include "git2wrap/error.hpp" 4 #include "git2wrap/repository.hpp" 5 6 namespace git2wrap 7 { 8 9 revwalk::revwalk(repositoryPtr repo) 10 : m_repo(std::move(repo)) 11 { 12 git_revwalk* rwalk = nullptr; 13 14 if (git_revwalk_new(&rwalk, m_repo.get()) != 0) { 15 throw error<error_code_t::ERROR>(); 16 } 17 18 m_revwalk = {rwalk, git_revwalk_free}; 19 } 20 21 void revwalk::push(const oid& objid) 22 { 23 if (git_revwalk_push(m_revwalk.get(), objid.ptr()) != 0) { 24 throw error<error_code_t::ERROR>(); 25 } 26 } 27 28 void revwalk::push_glob(const char* glob) 29 { 30 if (git_revwalk_push_glob(m_revwalk.get(), glob) != 0) { 31 throw error<error_code_t::ERROR>(); 32 } 33 } 34 35 void revwalk::push_head() 36 { 37 if (git_revwalk_push_head(m_revwalk.get()) != 0) { 38 throw error<error_code_t::ERROR>(); 39 } 40 } 41 42 commit revwalk::next() 43 { 44 static git_oid objid; 45 46 switch (git_revwalk_next(&objid, m_revwalk.get())) { 47 case error_code_t::OK: 48 return repository(m_repo).commit_lookup(oid(&objid)); 49 case error_code_t::ITEROVER: 50 break; 51 } 52 53 return {}; 54 } 55 56 void revwalk::reset() 57 { 58 if (git_revwalk_reset(m_revwalk.get()) != 0) { 59 throw error<error_code_t::ERROR>(); 60 } 61 } 62 63 } // namespace git2wrap