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 | 680484e2c68408ac14dc11665b10a9e3eb8d4ceb | 
| parent | 186542f37a081940bca0185ca52f699adcafb821 | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Tue, 7 Jan 2025 20:08:50 +0100 | 
Add most of getters for commit
| M | CMakeLists.txt | | | ++ - | 
| M | include/git2wrap/commit.hpp | | | +++++++++++++ - | 
| M | include/git2wrap/object.hpp | | | -- | 
| A | include/git2wrap/signature.hpp | | | +++++++++++++++++++++++++++++++++++++++++++ | 
| M | include/git2wrap/types.hpp | | | ++++++ | 
| M | source/commit.cpp | | | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 
| A | source/signature.cpp | | | ++++++++++++++++ | 
7 files changed, 156 insertions(+), 4 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              git2wrap
              VERSION 0.1.8
              VERSION 0.1.9
              DESCRIPTION "C++ 20 wrapper for libgit2"
              HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
              LANGUAGES CXX
        
        
          @@ -25,6 +25,7 @@ 
          add_library(
        
        
              source/reference.cpp
              source/repository.cpp
              source/revwalk.cpp
              source/signature.cpp
          )
          add_library(git2wrap::git2wrap ALIAS git2wrap_git2wrap)
          diff --git a/ include/git2wrap/commit.hpp b/ include/git2wrap/commit.hpp
          @@ -17,8 +17,20 @@ 
          public:
        
        
            operator bool() const { return m_commit != nullptr; }  // NOLINT
            commitPtr get() const { return m_commit; }
            const git_oid* get_id() const;
            const oid* get_id() const;
            const char* get_summary() const;
            const char* get_message_encoding() const;
            const char* get_message() const;
            const char* get_message_raw() const;
            const char* get_body() const;
            time_t get_time() const;
            int get_time_offset() const;
            const_signature get_signature() const;
            const_signature get_author() const;
            const char* get_raw_header() const;
            unsigned get_parentcount() const;
            commit get_parent(unsigned n = 0) const;
            buf get_header_field(const char *field) const;
          private:
            commitPtr m_commit;
        
        diff --git a/ include/git2wrap/object.hpp b/ include/git2wrap/object.hpp
@@ -9,8 +9,6 @@
namespace git2wrap
          {
          using oid = git_oid;
          class GIT2WRAP_EXPORT object
          {
          public:
        
        diff --git a/ include/git2wrap/signature.hpp b/ include/git2wrap/signature.hpp
@@ -0,0 +1,43 @@
#pragma once
          #include <git2.h>
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/types.hpp"
          namespace git2wrap
          {
          class GIT2WRAP_EXPORT signature
          {
          public:
            explicit signature(git_signature* sig);
            operator bool() const { return m_sig != nullptr; }  // NOLINT
            signaturePtr get() const { return m_sig; }
            const char* get_email() const { return m_sig->email; }
            const char* get_name() const { return m_sig->name; }
            time get_time() const { return m_sig->when; }
          private:
            signaturePtr m_sig;
          };
          class GIT2WRAP_EXPORT const_signature
          {
          public:
            explicit const_signature(const git_signature* sig);
            operator bool() const { return m_sig != nullptr; }  // NOLINT
            const git_signature* get() const { return m_sig; }
            const char* get_email() const { return m_sig->email; }
            const char* get_name() const { return m_sig->name; }
            time get_time() const { return m_sig->when; }
          private:
            const git_signature* m_sig;
          };
          }  // namespace git2wrap
        
        diff --git a/ include/git2wrap/types.hpp b/ include/git2wrap/types.hpp
@@ -13,6 +13,7 @@
namespace git2wrap
          {
          class const_signature;
          class branch;
          class buf;
          class libgit2;
        
        
          @@ -23,5 +24,10 @@ 
          CLASS(object)
        
        
          CLASS(reference)
          CLASS(repository)
          CLASS(revwalk)
          CLASS(signature)
          using oid = git_oid;
          using time_t = git_time_t;
          using time = git_time;
          }  // namespace git2wrap
        
        diff --git a/ source/commit.cpp b/ source/commit.cpp
@@ -1,5 +1,9 @@
#include "git2wrap/commit.hpp"
          #include "git2wrap/buf.hpp"
          #include "git2wrap/error.hpp"
          #include "git2wrap/signature.hpp"
          namespace git2wrap
          {
          
          @@ -19,4 +23,76 @@ 
          const char* commit::get_summary() const
        
        
            return git_commit_summary(m_commit.get());
          }
          const char* commit::get_message_encoding() const
          {
            return git_commit_message_encoding(m_commit.get());
          }
          const char* commit::get_message() const
          {
            return git_commit_message(m_commit.get());
          }
          const char* commit::get_message_raw() const
          {
            return git_commit_message_raw(m_commit.get());
          }
          const char* commit::get_body() const
          {
            return git_commit_body(m_commit.get());
          }
          time_t commit::get_time() const
          {
            return git_commit_time(m_commit.get());
          }
          int commit::get_time_offset() const
          {
            return git_commit_time_offset(m_commit.get());
          }
          const_signature commit::get_signature() const
          {
            return const_signature(git_commit_committer(m_commit.get()));
          }
          const_signature commit::get_author() const
          {
            return const_signature(git_commit_author(m_commit.get()));
          }
          const char* commit::get_raw_header() const
          {
            return git_commit_raw_header(m_commit.get());
          }
          unsigned commit::get_parentcount() const
          {
            return git_commit_parentcount(m_commit.get());
          }
          commit commit::get_parent(unsigned n) const
          {
            git_commit* cmt = nullptr;
            if (auto err = git_commit_parent(&cmt, m_commit.get(), n)) {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
            return {cmt, m_repo};
          }
          buf commit::get_header_field(const char* field) const
          {
            buf bufr;
            if (auto err = git_commit_header_field(bufr.get(), m_commit.get(), field)) {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
            return bufr;
          }
          }  // namespace git2wrap
        
        diff --git a/ source/signature.cpp b/ source/signature.cpp
@@ -0,0 +1,16 @@
#include "git2wrap/signature.hpp"
          namespace git2wrap
          {
          signature::signature(git_signature* sig)
              : m_sig(sig, git_signature_free)
          {
          }
          const_signature::const_signature(const git_signature* sig)
              : m_sig(sig)
          {
          }
          }  // namespace git2wrap