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 |

tree.cpp (3007B)


1 #include "git2wrap/tree.hpp" 2 3 #include "git2wrap/error.hpp" 4 #include "git2wrap/object.hpp" 5 #include "git2wrap/types.hpp" 6 7 namespace git2wrap 8 { 9 10 tree::tree(git_tree* tre, repositoryPtr repo) 11 : m_tree(tre, git_tree_free) 12 , m_repo(std::move(repo)) 13 { 14 } 15 16 tree tree::dup() const 17 { 18 git_tree* tre = nullptr; 19 git_tree_dup(&tre, m_tree.get()); 20 return {tre, m_repo}; 21 } 22 23 oid tree::get_id() const 24 { 25 return oid(git_tree_id(m_tree.get())); 26 } 27 28 repositoryPtr tree::get_owner() const 29 { 30 return m_repo; 31 } 32 33 size_t tree::get_entrycount() const 34 { 35 return git_tree_entrycount(m_tree.get()); 36 } 37 38 tree_entry tree::get_entry(const char* name) const 39 { 40 return {git_tree_entry_byname(m_tree.get(), name), m_repo}; 41 } 42 43 tree_entry tree::get_entry(size_t idx) const 44 { 45 return {git_tree_entry_byindex(m_tree.get(), idx), m_repo}; 46 } 47 48 tree_entry tree::get_entry(const oid& objid) const 49 { 50 return {git_tree_entry_byid(m_tree.get(), objid.ptr()), m_repo}; 51 } 52 53 tree_entry tree::get_entry_path(const char* path) const 54 { 55 git_tree_entry* entry = nullptr; 56 57 switch (git_tree_entry_bypath(&entry, m_tree.get(), path)) { 58 case error_code_t::OK: 59 break; 60 case error_code_t::ENOTFOUND: 61 throw error<error_code_t::ENOTFOUND>(); 62 default: 63 // should not happen 64 throw error<error_code_t::ERROR>(); 65 } 66 67 return {entry, m_repo}; 68 } 69 70 tree_entry::tree_entry(const git_tree_entry* entry, repositoryPtr repo) 71 : m_entry(const_cast<git_tree_entry*>(entry), empty_lambda) // NOLINT 72 , m_repo(std::move(repo)) 73 { 74 } 75 76 tree_entry::tree_entry(git_tree_entry* entry, repositoryPtr repo) 77 : m_entry(entry, git_tree_entry_free) 78 , m_repo(std::move(repo)) 79 { 80 } 81 82 tree_entry tree_entry::dup() const 83 { 84 git_tree_entry* entry = nullptr; 85 86 if (git_tree_entry_dup(&entry, m_entry.get()) != 0) { 87 throw error<error_code_t::ERROR>(); 88 } 89 90 return {entry, m_repo}; 91 } 92 93 object tree_entry::to_object() const 94 { 95 git_object* obj = nullptr; 96 97 if (git_tree_entry_to_object(&obj, m_repo.get(), m_entry.get()) != 0) { 98 throw error<error_code_t::ERROR>(); 99 } 100 101 return {obj, m_repo}; 102 } 103 104 tree tree_entry::to_tree() const 105 { 106 git_object* obj = nullptr; 107 108 if (git_tree_entry_to_object(&obj, m_repo.get(), m_entry.get()) != 0) { 109 throw error<error_code_t::ERROR>(); 110 } 111 112 return {reinterpret_cast<git_tree*>(obj), m_repo}; // NOLINT 113 } 114 115 const char* tree_entry::get_name() const 116 { 117 return git_tree_entry_name(m_entry.get()); 118 } 119 120 oid tree_entry::get_id() const 121 { 122 return oid(git_tree_entry_id(m_entry.get())); 123 } 124 125 repositoryPtr tree_entry::get_owner() const 126 { 127 return m_repo; 128 } 129 130 object_t tree_entry::get_type() const 131 { 132 return git_tree_entry_type(m_entry.get()); 133 } 134 135 filemode_t tree_entry::get_filemode() const 136 { 137 return git_tree_entry_filemode(m_entry.get()); 138 } 139 140 filemode_t tree_entry::get_filemode_raw() const 141 { 142 return git_tree_entry_filemode_raw(m_entry.get()); 143 } 144 145 auto tree_entry::operator<=>(const tree_entry& rhs) 146 { 147 return git_tree_entry_cmp(m_entry.get(), rhs.m_entry.get()); 148 } 149 150 } // namespace git2wrap