Skip to content

Commit 854f926

Browse files
committed
Replaced std::string with std::string_view
1 parent 4f7ffc5 commit 854f926

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/wrapper/repository_wrapper.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ repository_wrapper::~repository_wrapper()
77
p_resource=nullptr;
88
}
99

10-
repository_wrapper repository_wrapper::open(const std::string& directory)
10+
repository_wrapper repository_wrapper::open(std::string_view directory)
1111
{
1212
repository_wrapper rw;
13-
throwIfError(git_repository_open(&(rw.p_resource), directory.c_str()));
13+
throwIfError(git_repository_open(&(rw.p_resource), directory.data()));
1414
return rw;
1515
}
1616

17-
repository_wrapper repository_wrapper::init(const std::string& directory, bool bare)
17+
repository_wrapper repository_wrapper::init(std::string_view directory, bool bare)
1818
{
1919
repository_wrapper rw;
20-
throwIfError(git_repository_init(&(rw.p_resource), directory.c_str(), bare));
20+
throwIfError(git_repository_init(&(rw.p_resource), directory.data(), bare));
2121
return rw;
2222
}
2323

@@ -34,22 +34,22 @@ index_wrapper repository_wrapper::make_index()
3434
return index;
3535
}
3636

37-
branch_wrapper repository_wrapper::create_branch(const std::string& name, bool force)
37+
branch_wrapper repository_wrapper::create_branch(std::string_view name, bool force)
3838
{
3939
return create_branch(name, find_commit(), force);
4040
}
4141

42-
branch_wrapper repository_wrapper::create_branch(const std::string& name, const commit_wrapper& commit, bool force)
42+
branch_wrapper repository_wrapper::create_branch(std::string_view name, const commit_wrapper& commit, bool force)
4343
{
4444
git_reference* branch = nullptr;
45-
throwIfError(git_branch_create(&branch, *this, name.c_str(), commit, force));
45+
throwIfError(git_branch_create(&branch, *this, name.data(), commit, force));
4646
return branch_wrapper(branch);
4747
}
4848

49-
branch_wrapper repository_wrapper::find_branch(const std::string& name)
49+
branch_wrapper repository_wrapper::find_branch(std::string_view name)
5050
{
5151
git_reference* branch = nullptr;
52-
throwIfError(git_branch_lookup(&branch, *this, name.c_str(), GIT_BRANCH_LOCAL));
52+
throwIfError(git_branch_lookup(&branch, *this, name.data(), GIT_BRANCH_LOCAL));
5353
return branch_wrapper(branch);
5454
}
5555

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

6363

64-
commit_wrapper repository_wrapper::find_commit(const std::string& ref_name) const
64+
commit_wrapper repository_wrapper::find_commit(std::string_view ref_name) const
6565
{
6666
git_oid oid_parent_commit;
67-
throwIfError(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.c_str()));
67+
throwIfError(git_reference_name_to_id(&oid_parent_commit, *this, ref_name.data()));
6868
return find_commit(oid_parent_commit);
6969
}
7070

src/wrapper/repository_wrapper.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <string>
3+
#include <string_view>
44

55
#include <git2.h>
66

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

22-
static repository_wrapper init(const std::string& directory, bool bare);
23-
static repository_wrapper open(const std::string& directory);
22+
static repository_wrapper init(std::string_view directory, bool bare);
23+
static repository_wrapper open(std::string_view directory);
2424

2525
reference_wrapper head() const;
2626

2727
index_wrapper make_index();
2828

29-
branch_wrapper create_branch(const std::string& name, bool force);
30-
branch_wrapper create_branch(const std::string& name, const commit_wrapper& commit, bool force);
29+
branch_wrapper create_branch(std::string_view name, bool force);
30+
branch_wrapper create_branch(std::string_view name, const commit_wrapper& commit, bool force);
3131

32-
branch_wrapper find_branch(const std::string& name);
32+
branch_wrapper find_branch(std::string_view name);
3333

3434
branch_iterator iterate_branches(git_branch_t type) const;
3535

3636
// Commits
3737

38-
commit_wrapper find_commit(const std::string& ref_name = "HEAD") const;
38+
commit_wrapper find_commit(std::string_view ref_name = "HEAD") const;
3939
commit_wrapper find_commit(const git_oid& id) const;
4040

4141
private:

0 commit comments

Comments
 (0)