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 | e61c8b837306b18bb2c2cd61861dbbac50ddc5fa |
parent | 49a2ec4865bc1f3d1c5578f94cf5bb3a3a8fd295 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Wed, 15 Jan 2025 22:17:45 +0100 |
Blob class
Diffstat:M | CMakeLists.txt | | | ++- |
A | include/git2wrap/blob.hpp | | | +++++++++++++++++++++++++++++++ |
M | include/git2wrap/diff.hpp | | | +++--- |
M | include/git2wrap/repository.hpp | | | ++ |
M | include/git2wrap/tree.hpp | | | + |
M | include/git2wrap/types.hpp | | | +++ |
A | source/blob.cpp | | | ++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | source/diff.cpp | | | +++--- |
M | source/repository.cpp | | | +++++++++++ |
M | source/tree.cpp | | | +++++ |
10 files changed, 111 insertions(+), 7 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)
project(
git2wrap
VERSION 0.1.16
VERSION 0.1.17
DESCRIPTION "C++ 20 wrapper for libgit2"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
LANGUAGES CXX
@@ -17,6 +17,7 @@ include(cmake/variables.cmake)
add_library(
git2wrap_git2wrap
source/blob.cpp
source/branch.cpp
source/buf.cpp
source/commit.cpp
diff --git a/include/git2wrap/blob.hpp b/include/git2wrap/blob.hpp
@@ -0,0 +1,31 @@
#pragma once
#include <git2.h>
#include "git2wrap/git2wrap_export.hpp"
#include "git2wrap/types.hpp"
#include "git2wrap/oid.hpp"
namespace git2wrap
{
class GIT2WRAP_EXPORT blob
{
public:
blob(git_blob* blb, repositoryPtr repo);
operator bool() const { return m_blob != nullptr; } // NOLINT
blob dup() const;
oid get_id() const;
repositoryPtr get_owner() const;
const void* get_rawcontent() const;
object_size_t get_rawsize() const;
bool is_binary() const;
private:
blobUPtr m_blob;
repositoryPtr m_repo;
};
} // namespace git2wrap
diff --git a/include/git2wrap/diff.hpp b/include/git2wrap/diff.hpp
@@ -38,9 +38,9 @@ class GIT2WRAP_EXPORT diff_stats
public:
explicit diff_stats(git_diff_stats* stats);
size_t files_changed() const;
size_t insertions() const;
size_t deletions() const;
size_t get_files_changed() const;
size_t get_insertions() const;
size_t get_deletions() const;
private:
diff_statsUPtr m_stats;
diff --git a/include/git2wrap/repository.hpp b/include/git2wrap/repository.hpp
@@ -2,6 +2,7 @@
#include <git2.h>
#include "git2wrap/blob.hpp"
#include "git2wrap/branch.hpp"
#include "git2wrap/commit.hpp"
#include "git2wrap/git2wrap_export.hpp"
@@ -39,6 +40,7 @@ public:
object revparse(const char* spec) const;
commit commit_lookup(const oid& objid) const;
blob blob_lookup(const oid& objid) const;
tag tag_lookup(const oid& objid) const;
branch_iterator branch_begin(git_branch_t list_flags) const;
diff --git a/include/git2wrap/tree.hpp b/include/git2wrap/tree.hpp
@@ -45,6 +45,7 @@ public:
tree to_tree() const;
const char* get_name() const;
repositoryPtr get_owner() const;
oid get_id() const;
object_t get_type() const;
filemode_t get_filemode() const;
diff --git a/include/git2wrap/types.hpp b/include/git2wrap/types.hpp
@@ -20,6 +20,7 @@ class branch;
class buf;
class libgit2;
CLASS(blob)
CLASS(branch_iterator)
CLASS(commit)
CLASS(diff)
@@ -38,6 +39,8 @@ using time_t = git_time_t;
using time = git_time;
using object_t = git_object_t;
using filemode_t = git_filemode_t;
using off_t = git_off_t;
using object_size_t = git_object_size_t;
using diff_options = git_diff_options;
diff --git a/source/blob.cpp b/source/blob.cpp
@@ -0,0 +1,50 @@
#include "git2wrap/blob.hpp"
#include "git2wrap/error.hpp"
namespace git2wrap
{
blob::blob(git_blob* blb, repositoryPtr repo)
: m_blob(blb, git_blob_free)
, m_repo(std::move(repo))
{
}
blob blob::dup() const
{
git_blob* blb = nullptr;
if (auto err = git_blob_dup(&blb, m_blob.get())) {
throw error(err, git_error_last(), __FILE__, __LINE__);
}
return {blb, m_repo};
}
oid blob::get_id() const
{
return oid(git_blob_id(m_blob.get()));
}
repositoryPtr blob::get_owner() const
{
return m_repo;
}
const void* blob::get_rawcontent() const
{
return git_blob_rawcontent(m_blob.get());
}
object_size_t blob::get_rawsize() const
{
return git_blob_rawsize(m_blob.get());
}
bool blob::is_binary() const
{
return git_blob_is_binary(m_blob.get()) == 1;
}
} // namespace git2wrap
diff --git a/source/diff.cpp b/source/diff.cpp
@@ -52,17 +52,17 @@ diff_stats diff::get_stats() const
return diff_stats(stats);
}
size_t diff_stats::files_changed() const
size_t diff_stats::get_files_changed() const
{
return git_diff_stats_files_changed(m_stats.get());
}
size_t diff_stats::insertions() const
size_t diff_stats::get_insertions() const
{
return git_diff_stats_insertions(m_stats.get());
}
size_t diff_stats::deletions() const
size_t diff_stats::get_deletions() const
{
return git_diff_stats_deletions(m_stats.get());
}
diff --git a/source/repository.cpp b/source/repository.cpp
@@ -98,6 +98,17 @@ commit repository::commit_lookup(const oid& objid) const
return {commit, m_repo};
}
blob repository::blob_lookup(const oid& objid) const
{
git_blob* blob = nullptr;
if (auto err = git_blob_lookup(&blob, m_repo.get(), objid.ptr())) {
throw error(err, git_error_last(), __FILE__, __LINE__);
}
return {blob, m_repo};
}
tag repository::tag_lookup(const oid& objid) const
{
git_tag* tagg = nullptr;
diff --git a/source/tree.cpp b/source/tree.cpp
@@ -120,6 +120,11 @@ oid tree_entry::get_id() const
return oid(git_tree_entry_id(m_entry.get()));
}
repositoryPtr tree_entry::get_owner() const
{
return m_repo;
}
object_t tree_entry::get_type() const
{
return git_tree_entry_type(m_entry.get());