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 | 757c9bead268038fdc1920919318a0cb3796b690 |
parent | b94d3e9d439f83ee05a7b7a35980d1f0f4c8c969 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Fri, 10 Jan 2025 15:21:11 +0100 |
Tag class
Diffstat:M | CMakeLists.txt | | | ++- |
M | include/git2wrap/repository.hpp | | | +++++- |
A | include/git2wrap/tag.hpp | | | +++++++++++++++++++++++++++++++++ |
M | include/git2wrap/types.hpp | | | +++ |
M | source/repository.cpp | | | ++++++++++++++++++++++- |
A | source/tag.cpp | | | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 files changed, 125 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)
project(
git2wrap
VERSION 0.1.12
VERSION 0.1.13
DESCRIPTION "C++ 20 wrapper for libgit2"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
LANGUAGES CXX
@@ -26,6 +26,7 @@ add_library(
source/repository.cpp
source/revwalk.cpp
source/signature.cpp
source/tag.cpp
source/tree.cpp
)
add_library(git2wrap::git2wrap ALIAS git2wrap_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/tag.hpp"
#include "git2wrap/types.hpp"
namespace git2wrap
@@ -36,11 +37,14 @@ public:
const char* ceiling_dirs);
object revparse(const char* spec) const;
commit commit_lookup(const git_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;
void tag_foreach(tag_foreach_cb callback, void* payload) const;
private:
repositoryPtr m_repo;
};
diff --git a/include/git2wrap/tag.hpp b/include/git2wrap/tag.hpp
@@ -0,0 +1,33 @@
#pragma once
#include <git2.h>
#include "git2wrap/git2wrap_export.hpp"
#include "git2wrap/signature.hpp"
#include "git2wrap/types.hpp"
namespace git2wrap
{
class GIT2WRAP_EXPORT tag
{
public:
tag(git_tag* tagg, repositoryPtr repo);
operator bool() const { return m_tag != nullptr; } // NOLINT
tag dup() const;
const oid* get_id() const;
repositoryPtr get_owner() const;
const oid* get_target_id() const;
object_t get_target_type() const;
const char* get_name() const;
signature get_tagger() const;
const char* get_message() const;
private:
tagUPtr m_tag;
repositoryPtr m_repo;
};
} // namespace git2wrap
diff --git a/include/git2wrap/types.hpp b/include/git2wrap/types.hpp
@@ -27,6 +27,7 @@ CLASS(reference)
CLASS(repository)
CLASS(revwalk)
CLASS(signature)
CLASS(tag)
CLASS(tree)
CLASS(tree_entry)
@@ -36,6 +37,8 @@ using time = git_time;
using object_t = git_object_t;
using filemode_t = git_filemode_t;
using tag_foreach_cb = git_tag_foreach_cb;
static const struct empty_lambda_t // static and const applies to the object!
{
template<typename... T>
diff --git a/source/repository.cpp b/source/repository.cpp
@@ -1,6 +1,8 @@
#include "git2wrap/repository.hpp"
#include "git2wrap/commit.hpp"
#include "git2wrap/error.hpp"
#include "git2wrap/tag.hpp"
namespace git2wrap
{
@@ -85,9 +87,10 @@ object repository::revparse(const char* spec) const
return {obj, m_repo};
}
commit repository::commit_lookup(const git_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)) {
throw error(err, git_error_last(), __FILE__, __LINE__);
}
@@ -95,6 +98,17 @@ commit repository::commit_lookup(const git_oid* objid) const
return {commit, m_repo};
}
tag repository::tag_lookup(const oid* objid) const
{
git_tag* tagg = nullptr;
if (auto err = git_tag_lookup(&tagg, m_repo.get(), objid)) {
throw error(err, git_error_last(), __FILE__, __LINE__);
}
return {tagg, m_repo};
}
branch_iterator repository::branch_end() const // NOLINT
{
return branch_iterator();
@@ -111,4 +125,11 @@ branch_iterator repository::branch_begin(git_branch_t list_flags) const
return branch_iterator(iter);
}
void repository::tag_foreach(git_tag_foreach_cb callback, void* payload) const
{
if (auto err = git_tag_foreach(m_repo.get(), callback, payload)) {
throw error(err, git_error_last(), __FILE__, __LINE__);
}
}
} // namespace git2wrap
diff --git a/source/tag.cpp b/source/tag.cpp
@@ -0,0 +1,60 @@
#include "git2wrap/tag.hpp"
#include "git2wrap/error.hpp"
namespace git2wrap
{
tag::tag(git_tag* tagg, repositoryPtr repo)
: m_tag(tagg, git_tag_free)
, m_repo(std::move(repo))
{
}
tag tag::dup() const
{
git_tag* tagg = nullptr;
if (auto err = git_tag_dup(&tagg, m_tag.get())) {
throw error(err, git_error_last(), __FILE__, __LINE__);
}
return {tagg, m_repo};
}
const oid* tag::get_id() const
{
return git_tag_id(m_tag.get());
}
repositoryPtr tag::get_owner() const
{
return m_repo;
}
const oid* tag::get_target_id() const
{
return git_tag_target_id(m_tag.get());
}
object_t tag::get_target_type() const
{
return git_tag_target_type(m_tag.get());
}
const char* tag::get_name() const
{
return git_tag_name(m_tag.get());
}
signature tag::get_tagger() const
{
return signature(git_tag_tagger(m_tag.get()));
}
const char* tag::get_message() const
{
return git_tag_message(m_tag.get());
}
} // namespace git2wrap