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

diff.cpp (1400B)


0 #include "git2wrap/diff.hpp"
2 #include "git2wrap/error.hpp"
4 namespace git2wrap
5 {
7 diff::diff(git_diff* dif, repositoryPtr repo)
8 : m_diff(dif, git_diff_free)
9 , m_repo(std::move(repo))
10 {
11 }
13 int diff::foreach(
14 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
19 ) const
20 {
21 return git_diff_foreach(
22 m_diff.get(), file_cb, binary_cb, hunk_cb, line_cb, payload
23 );
24 }
26 diff diff::tree_to_tree(
27 const tree& old, const tree& crnt, const git_diff_options* opts
28 )
29 {
30 git_diff* dif = nullptr;
32 if (git_diff_tree_to_tree(
33 &dif, crnt.get_owner().get(), old.ptr(), crnt.ptr(), opts
34 )
35 != 0)
36 {
37 throw error<error_code_t::error>();
38 }
40 return {dif, old.get_owner()};
41 }
43 diff_stats::diff_stats(git_diff_stats* stats)
44 : m_stats(stats, git_diff_stats_free)
45 {
46 }
48 diff_stats diff::get_stats() const
49 {
50 git_diff_stats* stats = nullptr;
52 if (git_diff_get_stats(&stats, m_diff.get()) != 0) {
53 throw error<error_code_t::error>();
54 }
56 return diff_stats(stats);
57 }
59 size_t diff_stats::get_files_changed() const
60 {
61 return git_diff_stats_files_changed(m_stats.get());
62 }
64 size_t diff_stats::get_insertions() const
65 {
66 return git_diff_stats_insertions(m_stats.get());
67 }
69 size_t diff_stats::get_deletions() const
70 {
71 return git_diff_stats_deletions(m_stats.get());
72 }
74 } // namespace git2wrap