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

commit 09cdcdc2204d679e304b7416dd178d0736fa8016
parent e00ca71bdad927e3dc219c982454f6b3c574a3f2
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Sat, 10 May 2025 16:57:04 +0200

Add branch and repostiory flags

Diffstat:
M include/git2wrap/branch.hpp | ++++++
M include/git2wrap/object.hpp | +
M include/git2wrap/repository.hpp | +++++++++++++++++++ --
M include/git2wrap/types.hpp | -
M source/repository.cpp | ++++++++ -----

5 files changed, 34 insertions(+), 8 deletions(-)


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

@@ -1,5 +1,7 @@

#pragma once

#include <based/enum/enum_flag.hpp>
#include <based/types/types.hpp>
#include <git2.h>

#include "git2wrap/git2wrap_export.hpp"

@@ -17,6 +19,8 @@ public:

);
branch(reference ref, git_branch_t type);

BASED_DECLARE_ENUM_FLAG(flags_list, based::u8, local, remote, all)

operator bool() const { return m_ref; } // NOLINT
[[nodiscard]] branch dup() const;

@@ -31,6 +35,8 @@ private:

std::string m_name;
};

BASED_DEFINE_ENUM_FLAG_CLASS(branch, flags_list, based::u8, local, remote, all)

class branch_iterator
{
public:

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

@@ -1,5 +1,6 @@

#pragma once

#include <based/enum/enum.hpp>
#include <git2.h>

#include "git2wrap/buf.hpp"

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

@@ -1,5 +1,7 @@

#pragma once

#include <based/enum/enum_flag.hpp>
#include <based/types/types.hpp>
#include <git2.h>

#include "git2wrap/blob.hpp"

@@ -20,6 +22,10 @@ public:

using init_options = git_repository_init_options;
using clone_options = git_clone_options;

BASED_DECLARE_ENUM_FLAG(
flags_open, based::u8, no_search, cross_fs, bare, no_dotgit, from_env
)

explicit repository(git_repository* repo);
explicit repository(repositoryPtr repo);
repository(const char* path, unsigned is_bare);

@@ -35,7 +41,7 @@ public:


static repository open(const char* path);
static repository open(
const char* path, unsigned flags, const char* ceiling_dirs
const char* path, flags_open::type flags, const char* ceiling_dirs
);

object revparse(const char* spec) const;

@@ -43,7 +49,7 @@ public:

[[nodiscard]] blob blob_lookup(const oid& objid) const;
[[nodiscard]] tag tag_lookup(const oid& objid) const;

[[nodiscard]] branch_iterator branch_begin(git_branch_t list_flags) const;
[[nodiscard]] branch_iterator branch_begin(branch::flags_list::type flags) const;
[[nodiscard]] branch_iterator branch_end() const;

void tag_foreach(tag_foreach_cb callback, void* payload) const;

@@ -52,4 +58,15 @@ private:

repositoryPtr m_repo;
};

BASED_DEFINE_ENUM_FLAG_CLASS(
repository,
flags_open,
based::u8,
no_search,
cross_fs,
bare,
no_dotgit,
from_env
)

} // namespace git2wrap

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

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

#include <functional>
#include <memory>

#include <based/enum/enum.hpp>
#include <git2.h>

// NOLINTBEGIN

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

@@ -64,13 +64,14 @@ repository repository::open(const char* path)

}

repository repository::open(
const char* path, unsigned flags, const char* ceiling_dirs
const char* path, flags_open::type flags, const char* ceiling_dirs
)
{
git_repository* repo = nullptr;

const auto err =
error_code_t(git_repository_open_ext(&repo, path, flags, ceiling_dirs));
const auto err = error_code_t(
git_repository_open_ext(&repo, path, flags.value, ceiling_dirs)
);

if (err == error_code_t::ok) {
return repository(repo);

@@ -145,11 +146,13 @@ branch_iterator repository::branch_end() const // NOLINT

return branch_iterator();
}

branch_iterator repository::branch_begin(git_branch_t list_flags) const
branch_iterator repository::branch_begin(branch::flags_list::type flags) const
{
git_branch_iterator* iter = nullptr;

if (git_branch_iterator_new(&iter, m_repo.get(), list_flags) != 0) {
if (git_branch_iterator_new(&iter, m_repo.get(), git_branch_t(flags.value))
!= 0)
{
throw error<error_code_t::error>();
}