git2wrap

C++20 wrapper for libgit2
git clone git://git.dimitrijedobrota.com/git2wrap.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |

commite052d852bf784d2e9c13a4ea88aee1f02497c693
parent7758d84d392c0d1dbfaa2fd3da18f0f44d583179
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateWed, 8 Jan 2025 20:52:34 +0100

Improve branch by using reference directly

Diffstat:
MCMakeLists.txt|+-
Minclude/git2wrap/branch.hpp|+++++++----
Minclude/git2wrap/reference.hpp|+++-
Msource/branch.cpp|+++++++++++++-

4 files changed, 24 insertions(+), 7 deletions(-)


diff --git a/CMakeLists.txt b/CMakeLists.txt

@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)

project(
git2wrap
VERSION 0.1.10
VERSION 0.1.11
DESCRIPTION "C++ 20 wrapper for libgit2"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/git2wrap.git"
LANGUAGES CXX

diff --git a/include/git2wrap/branch.hpp b/include/git2wrap/branch.hpp

@@ -3,6 +3,7 @@

#include <git2.h>
#include "git2wrap/git2wrap_export.hpp"
#include "git2wrap/reference.hpp"
#include "git2wrap/types.hpp"
namespace git2wrap

@@ -13,16 +14,18 @@ class GIT2WRAP_EXPORT branch

public:
explicit branch(git_reference* ref = nullptr,
git_branch_t type = git_branch_t(0));
explicit branch(referencePtr ref, git_branch_t type = git_branch_t(0));
branch(reference ref, git_branch_t type);
operator bool() const { return m_ref; } // NOLINT
branch dup() const;
operator bool() const { return m_ref != nullptr; } // NOLINT
git_branch_t get_type() const { return m_type; }
const std::string& get_name();
private:
referenceUPtr m_ref;
git_branch_t m_type = {};
reference m_ref;
git_branch_t m_type;
std::string m_name;
};

diff --git a/include/git2wrap/reference.hpp b/include/git2wrap/reference.hpp

@@ -13,9 +13,11 @@ class GIT2WRAP_EXPORT reference

public:
explicit reference(git_reference* ref = nullptr);
operator bool() const { return m_ref != nullptr; } // NOLINT
operator bool() const { return m_ref != nullptr; } // NOLINT
reference dup() const;
git_reference* get() const { return m_ref.get(); }
friend bool operator==(const reference& lhs, const reference& rhs);
friend bool operator!=(const reference& lhs, const reference& rhs);

diff --git a/source/branch.cpp b/source/branch.cpp

@@ -4,12 +4,24 @@

namespace git2wrap
{
branch::branch(git_reference* ref, git_branch_t type)
: m_ref(ref, git_reference_free)
: m_ref(ref)
, m_type(type)
{
}
branch::branch(reference ref, git_branch_t type)
: m_ref(std::move(ref))
, m_type(type)
{
}
branch branch::dup() const
{
return {m_ref.dup(), m_type};
}
const std::string& branch::get_name()
{
if (!m_name.empty()) {