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
Prev Previous commit
Next Next commit
Replaced std::string with std::string_view
  • Loading branch information
JohanMabille committed Jul 21, 2025
commit 854f9267e3392e11ff5be29d81bb91159b182d1f
22 changes: 11 additions & 11 deletions src/wrapper/repository_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ repository_wrapper::~repository_wrapper()
p_resource=nullptr;
}

repository_wrapper repository_wrapper::open(const std::string& directory)
repository_wrapper repository_wrapper::open(std::string_view directory)
{
repository_wrapper rw;
throwIfError(git_repository_open(&(rw.p_resource), directory.c_str()));
throwIfError(git_repository_open(&(rw.p_resource), directory.data()));
return rw;
}

repository_wrapper repository_wrapper::init(const std::string& directory, bool bare)
repository_wrapper repository_wrapper::init(std::string_view directory, bool bare)
{
repository_wrapper rw;
throwIfError(git_repository_init(&(rw.p_resource), directory.c_str(), bare));
throwIfError(git_repository_init(&(rw.p_resource), directory.data(), bare));
return rw;
}

Expand All @@ -34,22 +34,22 @@ index_wrapper repository_wrapper::make_index()
return index;
}

branch_wrapper repository_wrapper::create_branch(const std::string& name, bool force)
branch_wrapper repository_wrapper::create_branch(std::string_view name, bool force)
{
return create_branch(name, find_commit(), force);
}

branch_wrapper repository_wrapper::create_branch(const std::string& name, const commit_wrapper& commit, bool force)
branch_wrapper repository_wrapper::create_branch(std::string_view name, const commit_wrapper& commit, bool force)
{
git_reference* branch = nullptr;
throwIfError(git_branch_create(&branch, *this, name.c_str(), commit, force));
throwIfError(git_branch_create(&branch, *this, name.data(), commit, force));
return branch_wrapper(branch);
}

branch_wrapper repository_wrapper::find_branch(const std::string& name)
branch_wrapper repository_wrapper::find_branch(std::string_view name)
{
git_reference* branch = nullptr;
throwIfError(git_branch_lookup(&branch, *this, name.c_str(), GIT_BRANCH_LOCAL));
throwIfError(git_branch_lookup(&branch, *this, name.data(), GIT_BRANCH_LOCAL));
return branch_wrapper(branch);
}

Expand All @@ -61,10 +61,10 @@ branch_iterator repository_wrapper::iterate_branches(git_branch_t type) const
}


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

Expand Down
14 changes: 7 additions & 7 deletions src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string>
#include <string_view>

#include <git2.h>

Expand All @@ -19,23 +19,23 @@ class repository_wrapper : public wrapper_base<git_repository>
repository_wrapper(repository_wrapper&&) noexcept = default;
repository_wrapper& operator=(repository_wrapper&&) noexcept = default;

static repository_wrapper init(const std::string& directory, bool bare);
static repository_wrapper open(const std::string& directory);
static repository_wrapper init(std::string_view directory, bool bare);
static repository_wrapper open(std::string_view directory);

reference_wrapper head() const;

index_wrapper make_index();

branch_wrapper create_branch(const std::string& name, bool force);
branch_wrapper create_branch(const std::string& name, const commit_wrapper& commit, bool force);
branch_wrapper create_branch(std::string_view name, bool force);
branch_wrapper create_branch(std::string_view name, const commit_wrapper& commit, bool force);

branch_wrapper find_branch(const std::string& name);
branch_wrapper find_branch(std::string_view name);

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(std::string_view ref_name = "HEAD") const;
commit_wrapper find_commit(const git_oid& id) const;

private:
Expand Down