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
add git_strarray wrapper
  • Loading branch information
SandrineP committed Jul 16, 2025
commit 9e04c96990c1b4d3d0b46f3657141b7a914be2d7
11 changes: 11 additions & 0 deletions src/utils/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ std::string get_current_git_path()
// sub->add_option("directory", directory, "info about directory arg")
// ->check(CLI::ExistingDirectory | CLI::NonexistentPath)
// ->default_val(std::filesystem::current_path());

git_strarray git_strarray_wrapper::init_str_array()
{
git_strarray_wrapper aw;
git_strarray array{new char*[aw.m_patterns.size()], aw.m_patterns.size()};
for (size_t i=0; i<aw.m_patterns.size(); ++i)
{
array.strings[i] = const_cast<char*>(aw.m_patterns[i].c_str());
}
Comment thread
JohanMabille marked this conversation as resolved.
return array;
}
42 changes: 42 additions & 0 deletions src/utils/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <string>
#include <utility>
#include <vector>

#include <git2.h>

class noncopyable_nonmovable
{
Expand Down Expand Up @@ -57,3 +60,42 @@ class libgit2_object : private noncopyable_nonmovable
};

std::string get_current_git_path();

class git_strarray_wrapper
{
public:
git_strarray_wrapper()
: m_patterns{}
, m_array{nullptr, 0}
{}
git_strarray_wrapper(std::vector<std::string> m_patterns)
: m_patterns(std::move(m_patterns))
{
init_str_array();
}

git_strarray_wrapper(const git_strarray_wrapper&) = delete;
git_strarray_wrapper& operator=(const git_strarray_wrapper&) = delete;

git_strarray_wrapper(git_strarray_wrapper&& rhs)
: m_patterns(std::move(rhs.m_patterns))
{
init_str_array();
}

~git_strarray_wrapper()
{
delete[] m_array.strings;
}

operator git_strarray*()
{
return &m_array;
}

static git_strarray init_str_array();

protected:
std::vector<std::string> m_patterns;
git_strarray m_array;
};