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 e00ca71bdad927e3dc219c982454f6b3c574a3f2
parent 4be48e2371d482745760af7e3ff3a55e35beb0f1
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Sat, 10 May 2025 16:24:13 +0200

Add enum_flags to diff_options and as object_t

Diffstat:
M include/git2wrap/diff.hpp | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ---
M include/git2wrap/object.hpp | +++++++++++ ---
M include/git2wrap/tag.hpp | ++ -
M include/git2wrap/tree.hpp | ++ -
M include/git2wrap/types.hpp | + -
M source/object.cpp | +++ ---
M source/tag.cpp | ++ --
M source/tree.cpp | ++ --

8 files changed, 102 insertions(+), 15 deletions(-)


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

@@ -40,18 +40,95 @@ private:

class GIT2WRAP_EXPORT diff_options
{
public:
explicit diff_options(unsigned int version)
explicit diff_options()
{
git_diff_options_init(&m_options, version);
git_diff_options_init(&m_options, GIT_DIFF_OPTIONS_VERSION);
}

operator auto() { return &m_options; } // NOLINT(*explicit*)
operator auto() const { return &m_options; } // NOLINT(*explicit*)

BASED_DECLARE_ENUM_FLAG(
flag,
based::u32,
normal,
reverse,
include_ignored,
recurse_ignored_dirs,
include_untracked,
recurse_untracked_dirs,
include_unmodified,
include_typechange,
include_typechange_trees,
ignore_filemode,
ignore_submodules,
ignore_case,
include_casechange,
disable_pathspec_match,
skip_binary_check,
enable_fast_untracked_dirs,
update_index,
include_unreadable,
include_unreadable_as_untracked,
indent_heuristic,
ignore_blank_lines,
force_text,
force_binary,
ignore_whitespace,
ignore_whitespace_change,
ignore_whitespace_eol,
show_untracked_content,
show_unmodified,
flag_unused,
patience,
minimal,
show_binary
)

auto flags() { return based::enum_flag_wrapper<flag::type>(m_options.flags); }

private:
git_diff_options m_options = {};
};

BASED_DEFINE_ENUM_FLAG_CLASS(
diff_options,
flag,
based::u32,
normal,
reverse,
include_ignored,
recurse_ignored_dirs,
include_untracked,
recurse_untracked_dirs,
include_unmodified,
include_typechange,
include_typechange_trees,
ignore_filemode,
ignore_submodules,
ignore_case,
include_casechange,
disable_pathspec_match,
skip_binary_check,
enable_fast_untracked_dirs,
update_index,
include_unreadable,
include_unreadable_as_untracked,
indent_heuristic,
ignore_blank_lines,
force_text,
force_binary,
ignore_whitespace,
ignore_whitespace_change,
ignore_whitespace_eol,
show_untracked_content,
show_unmodified,
flag_unused,
patience,
minimal,
show_binary
)

class GIT2WRAP_EXPORT diff_stats
{
public:

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

@@ -13,25 +13,33 @@ namespace git2wrap

class GIT2WRAP_EXPORT object
{
public:
using object_t = git_object_t;

object(git_object* obj, repositoryPtr repo);
object() = default;

operator bool() const { return m_obj != nullptr; } // NOLINT
[[nodiscard]] object dup() const;

BASED_DECLARE_ENUM(
object_type, int, -2, any, invalid, commit, unused, tree, blob, tag
)

using object_t = object_type::type;

[[nodiscard]] oid get_id() const;
[[nodiscard]] buf get_id_short() const;
[[nodiscard]] object_t get_type() const;
[[nodiscard]] repositoryPtr get_owner() const;

static const char* type2string(object_t type);
static git_object_t string2type(const char* str);
static object_t string2type(const char* str);

private:
objectUPtr m_obj;
repositoryPtr m_repo;
};

BASED_DEFINE_ENUM_CLASS(
object, object_type, int, -2, any, invalid, commit, unused, tree, blob, tag
)

} // namespace git2wrap

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/object.hpp"
#include "git2wrap/oid.hpp"
#include "git2wrap/signature.hpp"
#include "git2wrap/types.hpp"

@@ -21,7 +22,7 @@ public:

[[nodiscard]] oid get_id() const;
[[nodiscard]] repositoryPtr get_owner() const;
[[nodiscard]] oid get_target_id() const;
[[nodiscard]] object_t get_target_type() const;
[[nodiscard]] object::object_t get_target_type() const;
[[nodiscard]] const char* get_name() const;
[[nodiscard]] signature get_tagger() const;
[[nodiscard]] const char* get_message() 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/object.hpp"
#include "git2wrap/oid.hpp"
#include "git2wrap/types.hpp"

@@ -47,7 +48,7 @@ public:

[[nodiscard]] const char* get_name() const;
[[nodiscard]] repositoryPtr get_owner() const;
[[nodiscard]] oid get_id() const;
[[nodiscard]] object_t get_type() const;
[[nodiscard]] object::object_t get_type() const;
[[nodiscard]] filemode_t get_filemode() const;
[[nodiscard]] filemode_t get_filemode_raw() const;

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

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

#include <functional>
#include <memory>

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

// NOLINTBEGIN

@@ -37,7 +38,6 @@ CLASS(tree_entry)


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;

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

@@ -36,7 +36,7 @@ buf object::get_id_short() const


object::object_t object::get_type() const
{
return git_object_type(m_obj.get());
return object_t::get(git_object_type(m_obj.get()));
}

repositoryPtr object::get_owner() const

@@ -46,12 +46,12 @@ repositoryPtr object::get_owner() const


const char* object::type2string(object_t type)
{
return git_object_type2string(type);
return git_object_type2string(git_object_t(type.value));
}

object::object_t object::string2type(const char* str)
{
return git_object_string2type(str);
return object_t::get(git_object_string2type(str));
}

} // namespace git2wrap

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

@@ -33,9 +33,9 @@ oid tag::get_target_id() const

return oid(git_tag_target_id(m_tag.get()));
}

object_t tag::get_target_type() const
object::object_t tag::get_target_type() const
{
return git_tag_target_type(m_tag.get());
return object::object_t::get(git_tag_target_type(m_tag.get()));
}

const char* tag::get_name() const

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

@@ -129,9 +129,9 @@ repositoryPtr tree_entry::get_owner() const

return m_repo;
}

object_t tree_entry::get_type() const
object::object_t tree_entry::get_type() const
{
return git_tree_entry_type(m_entry.get());
return object::object_t::get(git_tree_entry_type(m_entry.get()));
}

filemode_t tree_entry::get_filemode() const