| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #include "commit_wrapper.hpp" | ||
| #include "../utils/git_exception.hpp" | ||
|
|
||
| commit_wrapper::~commit_wrapper() | ||
| { | ||
| git_commit_free(p_resource); | ||
| p_resource = nullptr; | ||
| } | ||
|
|
||
|
|
||
| commit_wrapper commit_wrapper::last_commit(const repository_wrapper& repo, const std::string& ref_name) | ||
| { | ||
| git_oid oid_parent_commit; | ||
| throwIfError(git_reference_name_to_id(&oid_parent_commit, repo, ref_name.c_str())); | ||
|
|
||
| commit_wrapper cw; | ||
| throwIfError(git_commit_lookup(&(cw.p_resource), repo, &oid_parent_commit)); | ||
| return cw; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include <git2.h> | ||
|
|
||
| #include "../wrapper/repository_wrapper.hpp" | ||
| #include "../wrapper/wrapper_base.hpp" | ||
|
|
||
| class commit_wrapper : public wrapper_base<git_commit> | ||
| { | ||
| public: | ||
|
|
||
| ~commit_wrapper(); | ||
|
|
||
| commit_wrapper(commit_wrapper&&) noexcept = default; | ||
| commit_wrapper& operator=(commit_wrapper&&) noexcept = default; | ||
|
|
||
| static commit_wrapper | ||
| last_commit(const repository_wrapper& repo, const std::string& ref_name = "HEAD"); | ||
|
|
||
| private: | ||
|
|
||
| commit_wrapper() = default; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #pragma once | ||
|
|
||
|
|
||
| template <class T> | ||
| class wrapper_base | ||
| { | ||
| public: | ||
| using resource_type = T; | ||
|
|
||
| wrapper_base(const wrapper_base&) = delete; | ||
| wrapper_base& operator=(const wrapper_base&) = delete; | ||
|
|
||
| wrapper_base(wrapper_base&& rhs) noexcept | ||
| : p_resource(rhs.p_resource) | ||
| { | ||
| rhs.p_resource = nullptr; | ||
| } | ||
| wrapper_base& operator=(wrapper_base&& rhs) noexcept | ||
| { | ||
| std::swap(p_resource, rhs.p_resource); | ||
| return *this; | ||
| } | ||
|
|
||
| operator resource_type*() const noexcept | ||
| { | ||
| return p_resource; | ||
| } | ||
|
|
||
| protected: | ||
| // Allocation and deletion of p_resource must be handled by inheriting class. | ||
| wrapper_base() = default; | ||
| ~wrapper_base() = default; | ||
|
|
||
| resource_type* p_resource = nullptr; | ||
| }; |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality[nitpick] This call relies on the implicit conversion from repository_wrapper to git_repository*. For readability and to avoid confusion, consider providing an explicit accessor (e.g. repo.get()) or using static_cast<git_repository*>(repo).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis implicit conversion is done on purpose.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.