Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/wrapper/commit_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ class commit_wrapper : public wrapper_base<git_commit>
commit_wrapper(git_commit* commit);

friend class repository_wrapper;
friend class reference_wrapper;
};
1 change: 1 addition & 0 deletions src/wrapper/object_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ class object_wrapper : public wrapper_base<git_object>
object_wrapper(git_object* obj);

friend class repository_wrapper;
friend class reference_wrapper;
};
30 changes: 30 additions & 0 deletions src/wrapper/refs_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <concepts>
#include <string>

#include <git2.h>
Expand All @@ -20,9 +21,38 @@ class reference_wrapper : public wrapper_base<git_reference>
std::string short_name() const;
bool is_remote() const;

template <class W>
W peel() const;

private:

reference_wrapper(git_reference* ref);

friend class repository_wrapper;
};

class commit_wrapper;
class object_wrapper;

// TODO: add constraints on W
// For now it accepts commit_wrapper and object_wrapper only
template <class W>
W reference_wrapper::peel() const
{
constexpr git_object_t obj_type = []
{
if constexpr (std::same_as<W, commit_wrapper>)
{
return GIT_OBJECT_COMMIT;
}
else // Default case
{
return GIT_OBJECT_ANY;
}
}();

using resource_type = typename W::resoure_type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a missing "c" in the second "resource_type"

git_object* resource = nullptr;
throw_if_error(git_reference_peel(&resource, this->p_resource, obj_type));
return W(reinterpret_cast<resource_type*>(resource));
}