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 | fc1e1e45838080f4471059c4005a4d31848538e3 | 
| parent | fba7c8793dbe2129753c41bc22592bae14cad7ce | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Mon, 6 Jan 2025 12:18:01 +0100 | 
Object and buf classes
| M | CMakeLists.txt | | | +++ - | 
| A | include/git2wrap/buf.hpp | | | +++++++++++++++++++++++++++ | 
| A | include/git2wrap/object.hpp | | | ++++++++++++++++++++++++++++++++++++++++++ | 
| A | source/buf.cpp | | | +++++++++++ | 
| A | source/object.cpp | | | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 
5 files changed, 143 insertions(+), 1 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              git2wrap
              VERSION 0.1.5
              VERSION 0.1.6
              DESCRIPTION "C++ 20 wrapper for libgit2"
              HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
              LANGUAGES CXX
        
        
          @@ -18,7 +18,9 @@ 
          include(cmake/variables.cmake)
        
        
          add_library(
              git2wrap_git2wrap
              source/branch.cpp
              source/buf.cpp
              source/libgit2.cpp
              source/object.cpp
              source/reference.cpp
              source/repository.cpp
          )
        
        diff --git a/ include/git2wrap/buf.hpp b/ include/git2wrap/buf.hpp
@@ -0,0 +1,27 @@
#pragma once
          #include <git2.h>
          #include "git2wrap/git2wrap_export.hpp"
          namespace git2wrap
          {
          class GIT2WRAP_EXPORT buf
          {
          public:
            buf() = default;
            buf(const buf&) = default;
            buf(buf&&) = default;
            buf& operator=(const buf&) = default;
            buf& operator=(buf&&) = default;
            ~buf();
            git_buf* get() { return &m_buf; }
            const git_buf* get() const { return &m_buf; }
          private:
            git_buf m_buf = {nullptr, 0, 0};
          };
          }  // namespace git2wrap
        
        diff --git a/ include/git2wrap/object.hpp b/ include/git2wrap/object.hpp
@@ -0,0 +1,42 @@
#pragma once
          #include <functional>
          #include <memory>
          #include <git2.h>
          #include "git2wrap/buf.hpp"
          #include "git2wrap/repository.hpp"
          #include "git2wrap/git2wrap_export.hpp"
          namespace git2wrap
          {
          using oid = git_oid;
          class GIT2WRAP_EXPORT object
          {
          public:
            using object_t = git_object_t;
            explicit object(git_object* obj);
            git_object* get() { return m_obj.get(); }
            const git_object* get() const { return m_obj.get(); }
            object clone();
            const oid* get_id() const;
            buf get_id_short() const;
            object_t get_type() const;
            repository get_owner() const;
            static const char *type2string(object_t type);
            static git_object_t string2type(const char *str); 
          private:
            using delete_f = std::function<void(git_object*)>;
            std::unique_ptr<git_object, delete_f> m_obj;
          };
          }  // namespace git2wrap
        
        diff --git a/ source/buf.cpp b/ source/buf.cpp
@@ -0,0 +1,11 @@
#include "git2wrap/buf.hpp"
          namespace git2wrap
          {
          buf::~buf()
          {
            git_buf_dispose(get());
          }
          }  // namespace git2wrap
        
        diff --git a/ source/object.cpp b/ source/object.cpp
@@ -0,0 +1,60 @@
#include "git2wrap/object.hpp"
          #include "git2wrap/error.hpp"
          namespace git2wrap
          {
          object::object(git_object* obj)
              : m_obj(obj, git_object_free)
          {
          }
          const oid* object::get_id() const
          {
            return git_object_id(m_obj.get());
          }
          object object::clone()
          {
            git_object* obj = nullptr;
            if (auto err = git_object_dup(&obj, get())) {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
            return object(obj);
          }
          buf object::get_id_short() const
          {
            buf bufr;
            if (auto err = git_object_short_id(bufr.get(), get())) {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
            return bufr;
          }
          object::object_t object::get_type() const
          {
            return git_object_type(get());
          }
          repository object::get_owner() const
          {
            return repository(git_object_owner(get()));
          }
          const char* object::type2string(object_t type)
          {
            return git_object_type2string(type);
          }
          object::object_t object::string2type(const char* str)
          {
            return git_object_string2type(str);
          }
          }  // namespace git2wrap