git2wrapC++20 wrapper for libgit2 |
git clone git://git.dimitrijedobrota.com/git2wrap.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | |
diff.cpp (1482B)
1 #include "git2wrap/diff.hpp" 2 3 #include "git2wrap/error.hpp" 4 5 namespace git2wrap 6 { 7 8 diff::diff(git_diff* dif, repositoryPtr repo) 9 : m_diff(dif, git_diff_free) 10 , m_repo(std::move(repo)) 11 { 12 } 13 14 int diff::foreach(diff_file_cb file_cb, 15 diff_binary_cb binary_cb, 16 diff_hunk_cb hunk_cb, 17 diff_line_cb line_cb, 18 void* payload) const 19 { 20 return git_diff_foreach( 21 m_diff.get(), file_cb, binary_cb, hunk_cb, line_cb, payload); 22 } 23 24 diff diff::tree_to_tree(const tree& old, 25 const tree& crnt, 26 const git_diff_options* opts) 27 { 28 git_diff* dif = nullptr; 29 30 if (git_diff_tree_to_tree( 31 &dif, crnt.get_owner().get(), old.ptr(), crnt.ptr(), opts) 32 != 0) 33 { 34 throw error<error_code_t::ERROR>(); 35 } 36 37 return {dif, old.get_owner()}; 38 } 39 40 diff_stats::diff_stats(git_diff_stats* stats) 41 : m_stats(stats, git_diff_stats_free) 42 { 43 } 44 45 diff_stats diff::get_stats() const 46 { 47 git_diff_stats* stats = nullptr; 48 49 if (git_diff_get_stats(&stats, m_diff.get()) != 0) { 50 throw error<error_code_t::ERROR>(); 51 } 52 53 return diff_stats(stats); 54 } 55 56 size_t diff_stats::get_files_changed() const 57 { 58 return git_diff_stats_files_changed(m_stats.get()); 59 } 60 61 size_t diff_stats::get_insertions() const 62 { 63 return git_diff_stats_insertions(m_stats.get()); 64 } 65 66 size_t diff_stats::get_deletions() const 67 { 68 return git_diff_stats_deletions(m_stats.get()); 69 } 70 71 } // namespace git2wrap