git2wrapC++20 wrapper for libgit2 | 
          
| git clone git://git.dimitrijedobrota.com/git2wrap.git | 
| Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | 
| commit | e1fdadc52dbd8abfaa899c4e0fdd3cae5ac127d3 | 
| parent | e90c59a6bf9993cfd82cabfa6b76c1fe94a96a45 | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Sun, 12 Jan 2025 17:44:35 +0100 | 
Diff class
| M | CMakeLists.txt | | | + - | 
| A | include/git2wrap/diff.hpp | | | ++++++++++++++++++++++++++++++++ | 
| M | include/git2wrap/types.hpp | | | ++++++ | 
| A | source/diff.cpp | | | +++++++++++++++++++++++++++++++++++++++ | 
4 files changed, 78 insertions(+), 1 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              git2wrap
              VERSION 0.1.14
              VERSION 0.1.15
              DESCRIPTION "C++ 20 wrapper for libgit2"
              HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
              LANGUAGES CXX
        
        diff --git a/ include/git2wrap/diff.hpp b/ include/git2wrap/diff.hpp
@@ -0,0 +1,32 @@
#pragma once
          #include <git2.h>
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/tree.hpp"
          #include "git2wrap/types.hpp"
          namespace git2wrap
          {
          class GIT2WRAP_EXPORT diff
          {
          public:
            diff(git_diff* dif, repositoryPtr repo);
            int foreach(diff_file_cb file_cb,
                        diff_binary_cb binary_cb,
                        diff_hunk_cb hunk_cb,
                        diff_line_cb line_cb,
                        void* payload) const;
            static diff tree_to_tree(const tree& old,
                                     const tree& crnt,
                                     const git_diff_options* opts);
          private:
            diffUPtr m_diff;
            repositoryPtr m_repo;
          };
          }  // namespace git2wrap
        
        diff --git a/ include/git2wrap/types.hpp b/ include/git2wrap/types.hpp
          @@ -38,6 +38,12 @@ 
          using time = git_time;
        
        
          using object_t = git_object_t;
          using filemode_t = git_filemode_t;
          using diff_options = git_diff_options;
          using diff_binary_cb = git_diff_binary_cb;
          using diff_file_cb = git_diff_file_cb;
          using diff_hunk_cb = git_diff_hunk_cb;
          using diff_line_cb = git_diff_line_cb;
          using tag_foreach_cb = git_tag_foreach_cb;
          static const struct empty_lambda_t  // static and const applies to the object!
        
        diff --git a/ source/diff.cpp b/ source/diff.cpp
@@ -0,0 +1,39 @@
#include "git2wrap/diff.hpp"
          #include "git2wrap/error.hpp"
          namespace git2wrap
          {
          diff::diff(git_diff* dif, repositoryPtr repo)
              : m_diff(dif, git_diff_free)
              , m_repo(std::move(repo))
          {
          }
          int diff::foreach(diff_file_cb file_cb,
                            diff_binary_cb binary_cb,
                            diff_hunk_cb hunk_cb,
                            diff_line_cb line_cb,
                            void* payload) const
          {
            return git_diff_foreach(
                m_diff.get(), file_cb, binary_cb, hunk_cb, line_cb, payload);
          }
          diff diff::tree_to_tree(const tree& old,
                                  const tree& crnt,
                                  const git_diff_options* opts)
          {
            git_diff* dif = nullptr;
            if (auto err = git_diff_tree_to_tree(
                    &dif, old.get_owner().get(), old.ptr(), crnt.ptr(), opts))
            {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
            return {dif, old.get_owner()};
          }
          }  // namespace git2wrap