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 | e90c59a6bf9993cfd82cabfa6b76c1fe94a96a45 | 
| parent | 757c9bead268038fdc1920919318a0cb3796b690 | 
| author | Dimitrije Dobrota < mail@dimitrijedobrota.com > | 
| date | Sat, 11 Jan 2025 17:38:24 +0100 | 
Oid class
| M | CMakeLists.txt | | | +++ - | 
| M | include/git2wrap/commit.hpp | | | ++ - | 
| M | include/git2wrap/object.hpp | | | ++ - | 
| A | include/git2wrap/oid.hpp | | | +++++++++++++++++++++++++ | 
| M | include/git2wrap/repository.hpp | | | +++ -- | 
| M | include/git2wrap/revwalk.hpp | | | ++ - | 
| M | include/git2wrap/tag.hpp | | | +++ -- | 
| M | include/git2wrap/tree.hpp | | | +++++ --- | 
| M | include/git2wrap/types.hpp | | | ++ - | 
| M | source/commit.cpp | | | ++ -- | 
| M | source/object.cpp | | | ++ -- | 
| A | source/oid.cpp | | | +++++++++++++++++++++++++ | 
| M | source/repository.cpp | | | ++++ ---- | 
| M | source/revwalk.cpp | | | +++ --- | 
| M | source/tag.cpp | | | ++++ ---- | 
| M | source/tree.cpp | | | ++++++ ------ | 
16 files changed, 93 insertions(+), 33 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
          @@ -4,7 +4,7 @@ 
          include(cmake/prelude.cmake)
        
        
          project(
              git2wrap
              VERSION 0.1.13
              VERSION 0.1.14
              DESCRIPTION "C++ 20 wrapper for libgit2"
              HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
              LANGUAGES CXX
        
        
          @@ -20,8 +20,10 @@ 
          add_library(
        
        
              source/branch.cpp
              source/buf.cpp
              source/commit.cpp
              source/diff.cpp
              source/libgit2.cpp
              source/object.cpp
              source/oid.cpp
              source/reference.cpp
              source/repository.cpp
              source/revwalk.cpp
        
        diff --git a/ include/git2wrap/commit.hpp b/ include/git2wrap/commit.hpp
@@ -5,6 +5,7 @@
#include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/tree.hpp"
          #include "git2wrap/types.hpp"
          #include "git2wrap/oid.hpp"
          namespace git2wrap
          {
        
        
          @@ -18,7 +19,7 @@ 
          public:
        
        
            operator bool() const { return m_commit != nullptr; }  // NOLINT
            commit dup() const;
            const oid* get_id() const;
            oid get_id() const;
            const char* get_summary() const;
            const char* get_message_encoding() const;
            const char* get_message() const;
        
        diff --git a/ include/git2wrap/object.hpp b/ include/git2wrap/object.hpp
@@ -4,6 +4,7 @@
#include "git2wrap/buf.hpp"
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/oid.hpp"
          #include "git2wrap/types.hpp"
          namespace git2wrap
        
        
          @@ -20,7 +21,7 @@ 
          public:
        
        
            operator bool() const { return m_obj != nullptr; }  // NOLINT
            object dup() const;
            const oid* get_id() const;
            oid get_id() const;
            buf get_id_short() const;
            object_t get_type() const;
            repositoryPtr get_owner() const;
        
        diff --git a/ include/git2wrap/oid.hpp b/ include/git2wrap/oid.hpp
@@ -0,0 +1,25 @@
#pragma once
          #include <git2.h>
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/types.hpp"
          namespace git2wrap
          {
          class GIT2WRAP_EXPORT oid
          {
          public:
            explicit oid(const git_oid* objid);
            operator bool() const { return m_oid != nullptr; }  // NOLINT
            git_oid* ptr() const { return m_oid.get(); }
            std::string get_hex_string(size_t n);
          private:
            oidPtr m_oid;
          };
          }  // namespace git2wrap
        
        diff --git a/ include/git2wrap/repository.hpp b/ include/git2wrap/repository.hpp
@@ -6,6 +6,7 @@
#include "git2wrap/commit.hpp"
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/object.hpp"
          #include "git2wrap/oid.hpp"
          #include "git2wrap/tag.hpp"
          #include "git2wrap/types.hpp"
          
          @@ -37,8 +38,8 @@ 
          public:
        
        
                                   const char* ceiling_dirs);
            object revparse(const char* spec) const;
            commit commit_lookup(const oid* objid) const;
            tag tag_lookup(const oid* objid) const;
            commit commit_lookup(const oid& objid) const;
            tag tag_lookup(const oid& objid) const;
            branch_iterator branch_begin(git_branch_t list_flags) const;
            branch_iterator branch_end() const;
        
        diff --git a/ include/git2wrap/revwalk.hpp b/ include/git2wrap/revwalk.hpp
@@ -4,6 +4,7 @@
#include "git2wrap/commit.hpp"
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/oid.hpp"
          #include "git2wrap/types.hpp"
          namespace git2wrap
        
        
          @@ -17,7 +18,7 @@ 
          public:
        
        
            operator bool() const { return m_revwalk != nullptr; }  // NOLINT
            void push(const git_oid* objid);
            void push(const oid& objid);
            void push_glob(const char* glob);
            void push_head();
          diff --git a/ include/git2wrap/tag.hpp b/ include/git2wrap/tag.hpp
@@ -3,6 +3,7 @@
#include <git2.h>
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/oid.hpp"
          #include "git2wrap/signature.hpp"
          #include "git2wrap/types.hpp"
          
          @@ -17,9 +18,9 @@ 
          public:
        
        
            operator bool() const { return m_tag != nullptr; }  // NOLINT
            tag dup() const;
            const oid* get_id() const;
            oid get_id() const;
            repositoryPtr get_owner() const;
            const oid* get_target_id() const;
            oid get_target_id() const;
            object_t get_target_type() const;
            const char* get_name() const;
            signature get_tagger() const;
        
        diff --git a/ include/git2wrap/tree.hpp b/ include/git2wrap/tree.hpp
@@ -3,6 +3,7 @@
#include <git2.h>
          #include "git2wrap/git2wrap_export.hpp"
          #include "git2wrap/oid.hpp"
          #include "git2wrap/types.hpp"
          namespace git2wrap
        
        
          @@ -14,15 +15,16 @@ 
          public:
        
        
            tree(git_tree* tre, repositoryPtr repo);
            operator bool() const { return m_tree != nullptr; }  // NOLINT
            git_tree* ptr() const { return m_tree.get(); }
            tree dup() const;
            const oid* get_id() const;
            oid get_id() const;
            repositoryPtr get_owner() const;
            size_t get_entrycount() const;
            tree_entry get_entry(const char* name) const;
            tree_entry get_entry(size_t idx) const;
            tree_entry get_entry(const oid* objid) const;
            tree_entry get_entry(const oid& objid) const;
            tree_entry get_entry_path(const char* path) const;
          private:
        
        
          @@ -43,7 +45,7 @@ 
          public:
        
        
            tree to_tree() const;
            const char* get_name() const;
            const oid* get_id() const;
            oid get_id() const;
            object_t get_type() const;
            filemode_t get_filemode() const;
            filemode_t get_filemode_raw() const;
        
        diff --git a/ include/git2wrap/types.hpp b/ include/git2wrap/types.hpp
          @@ -22,7 +22,9 @@ 
          class libgit2;
        
        
          CLASS(branch_iterator)
          CLASS(commit)
          CLASS(diff)
          CLASS(object)
          CLASS(oid)
          CLASS(reference)
          CLASS(repository)
          CLASS(revwalk)
        
        
          @@ -31,7 +33,6 @@ 
          CLASS(tag)
        
        
          CLASS(tree)
          CLASS(tree_entry)
          using oid = git_oid;
          using time_t = git_time_t;
          using time = git_time;
          using object_t = git_object_t;
        
        diff --git a/ source/commit.cpp b/ source/commit.cpp
          @@ -24,9 +24,9 @@ 
          commit commit::dup() const
        
        
            return {cmt, m_repo};
          }
          const git_oid* commit::get_id() const
          oid commit::get_id() const
          {
            return git_commit_id(m_commit.get());
            return oid(git_commit_id(m_commit.get()));
          }
          const char* commit::get_summary() const
        
        diff --git a/ source/object.cpp b/ source/object.cpp
          @@ -22,9 +22,9 @@ 
          object object::dup() const
        
        
            return {obj, m_repo};
          }
          const oid* object::get_id() const
          oid object::get_id() const
          {
            return git_object_id(m_obj.get());
            return oid(git_object_id(m_obj.get()));
          }
          buf object::get_id_short() const
        
        diff --git a/ source/oid.cpp b/ source/oid.cpp
@@ -0,0 +1,25 @@
#include "git2wrap/oid.hpp"
          #include "git2wrap/error.hpp"
          namespace git2wrap
          {
          oid::oid(const git_oid* objid)
              : m_oid(const_cast<git_oid*>(objid), empty_lambda)  // NOLINT
          {
          }
          std::string oid::get_hex_string(size_t n)
          {
            std::string str(n, 0);
            char* bfr = const_cast<char*>(str.c_str());  // NOLINT
            if (git_oid_tostr(bfr, n + 1, m_oid.get()) == nullptr) {
              throw error(0, git_error_last(), __FILE__, __LINE__);
            }
            return str;
          }
          }  // namespace git2wrap
        
        diff --git a/ source/repository.cpp b/ source/repository.cpp
          @@ -87,22 +87,22 @@ 
          object repository::revparse(const char* spec) const
        
        
            return {obj, m_repo};
          }
          commit repository::commit_lookup(const oid* objid) const
          commit repository::commit_lookup(const oid& objid) const
          {
            git_commit* commit = nullptr;
            if (auto err = git_commit_lookup(&commit, m_repo.get(), objid)) {
            if (auto err = git_commit_lookup(&commit, m_repo.get(), objid.ptr())) {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
            return {commit, m_repo};
          }
          tag repository::tag_lookup(const oid* objid) const
          tag repository::tag_lookup(const oid& objid) const
          {
            git_tag* tagg = nullptr;
            if (auto err = git_tag_lookup(&tagg, m_repo.get(), objid)) {
            if (auto err = git_tag_lookup(&tagg, m_repo.get(), objid.ptr())) {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
          diff --git a/ source/revwalk.cpp b/ source/revwalk.cpp
          @@ -18,9 +18,9 @@ 
          revwalk::revwalk(repositoryPtr repo)
        
        
            m_revwalk = {rwalk, git_revwalk_free};
          }
          void revwalk::push(const git_oid* objid)
          void revwalk::push(const oid& objid)
          {
            if (auto err = git_revwalk_push(m_revwalk.get(), objid)) {
            if (auto err = git_revwalk_push(m_revwalk.get(), objid.ptr())) {
              throw error(err, git_error_last(), __FILE__, __LINE__);
            }
          }
        
        
          @@ -44,7 +44,7 @@ 
          commit revwalk::next()
        
        
            static git_oid objid;
            if (git_revwalk_next(&objid, m_revwalk.get()) == 0) {
              return repository(m_repo).commit_lookup(&objid);
              return repository(m_repo).commit_lookup(oid(&objid));
            }
            return {};
        
        diff --git a/ source/tag.cpp b/ source/tag.cpp
          @@ -22,9 +22,9 @@ 
          tag tag::dup() const
        
        
            return {tagg, m_repo};
          }
          const oid* tag::get_id() const
          oid tag::get_id() const
          {
            return git_tag_id(m_tag.get());
            return oid(git_tag_id(m_tag.get()));
          }
          repositoryPtr tag::get_owner() const
        
        
          @@ -32,9 +32,9 @@ 
          repositoryPtr tag::get_owner() const
        
        
            return m_repo;
          }
          const oid* tag::get_target_id() const
          oid tag::get_target_id() const
          {
            return git_tag_target_id(m_tag.get());
            return oid(git_tag_target_id(m_tag.get()));
          }
          object_t tag::get_target_type() const
        
        diff --git a/ source/tree.cpp b/ source/tree.cpp
          @@ -24,9 +24,9 @@ 
          tree tree::dup() const
        
        
            return {tre, m_repo};
          }
          const oid* tree::get_id() const
          oid tree::get_id() const
          {
            return git_tree_id(m_tree.get());
            return oid(git_tree_id(m_tree.get()));
          }
          repositoryPtr tree::get_owner() const
        
        
          @@ -49,9 +49,9 @@ 
          tree_entry tree::get_entry(size_t idx) const
        
        
            return {git_tree_entry_byindex(m_tree.get(), idx), m_repo};
          }
          tree_entry tree::get_entry(const oid* objid) const
          tree_entry tree::get_entry(const oid& objid) const
          {
            return {git_tree_entry_byid(m_tree.get(), objid), m_repo};
            return {git_tree_entry_byid(m_tree.get(), objid.ptr()), m_repo};
          }
          tree_entry tree::get_entry_path(const char* path) const
        
        
          @@ -115,9 +115,9 @@ 
          const char* tree_entry::get_name() const
        
        
            return git_tree_entry_name(m_entry.get());
          }
          const oid* tree_entry::get_id() const
          oid tree_entry::get_id() const
          {
            return git_tree_entry_id(m_entry.get());
            return oid(git_tree_entry_id(m_entry.get()));
          }
          object_t tree_entry::get_type() const