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
Next Next commit
commit_wrapper now built from reposiroty_wrapper
  • Loading branch information
JohanMabille committed Jul 21, 2025
commit 4f7ffc500be6be77bed08ffaceefbb58660ecbc2
12 changes: 7 additions & 5 deletions src/wrapper/commit_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#include "../utils/git_exception.hpp"
#include "../wrapper/commit_wrapper.hpp"
#include "../wrapper/repository_wrapper.hpp"

commit_wrapper::commit_wrapper(git_commit* commit)
: base_type(commit)
{
}

commit_wrapper::~commit_wrapper()
{
git_commit_free(p_resource);
p_resource = nullptr;
}


commit_wrapper commit_wrapper::from_reference_name(const repository_wrapper& repo, const std::string& ref_name)
/*commit_wrapper commit_wrapper::from_reference_name(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;
}
}*/
13 changes: 5 additions & 8 deletions src/wrapper/commit_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#pragma once

#include <string>

#include <git2.h>

#include "../wrapper/wrapper_base.hpp"

class repository_wrapper;

class commit_wrapper : public wrapper_base<git_commit>
{
public:

using base_type = wrapper_base<git_commit>;

~commit_wrapper();

commit_wrapper(commit_wrapper&&) noexcept = default;
commit_wrapper& operator=(commit_wrapper&&) noexcept = default;

static commit_wrapper
from_reference_name(const repository_wrapper& repo, const std::string& ref_name = "HEAD");

private:

commit_wrapper() = default;
commit_wrapper(git_commit* commit);

friend class repository_wrapper;
};
17 changes: 16 additions & 1 deletion src/wrapper/repository_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ index_wrapper repository_wrapper::make_index()

branch_wrapper repository_wrapper::create_branch(const std::string& name, bool force)
{
return create_branch(name, commit_wrapper::from_reference_name(*this), force);
return create_branch(name, find_commit(), force);
}

branch_wrapper repository_wrapper::create_branch(const std::string& name, const commit_wrapper& commit, bool force)
Expand All @@ -59,3 +59,18 @@ branch_iterator repository_wrapper::iterate_branches(git_branch_t type) const
throwIfError(git_branch_iterator_new(&iter, *this, type));
return branch_iterator(iter);
}


commit_wrapper repository_wrapper::find_commit(const std::string& ref_name) const
{
git_oid oid_parent_commit;
throwIfError(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.c_str()));
return find_commit(oid_parent_commit);
}

commit_wrapper repository_wrapper::find_commit(const git_oid& id) const
{
git_commit* commit;
throwIfError(git_commit_lookup(&commit, *this, &id));
return commit_wrapper(commit);
}
5 changes: 5 additions & 0 deletions src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class repository_wrapper : public wrapper_base<git_repository>

branch_iterator iterate_branches(git_branch_t type) const;

// Commits

commit_wrapper find_commit(const std::string& ref_name = "HEAD") const;
commit_wrapper find_commit(const git_oid& id) const;

private:

repository_wrapper() = default;
Expand Down
1 change: 1 addition & 0 deletions src/wrapper/wrapper_base.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <utility>

template <class T>
class wrapper_base
Expand Down