File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,51 @@ std::string get_current_git_path()
2323// sub->add_option("directory", directory, "info about directory arg")
2424// ->check(CLI::ExistingDirectory | CLI::NonexistentPath)
2525// ->default_val(std::filesystem::current_path());
26+
27+ git_strarray_wrapper::git_strarray_wrapper (std::vector<std::string> patterns)
28+ : m_patterns(std::move(patterns))
29+ {
30+ init_str_array ();
31+ }
32+
33+ git_strarray_wrapper::git_strarray_wrapper (git_strarray_wrapper&& rhs)
34+ : m_patterns(std::move(rhs.m_patterns))
35+ {
36+ init_str_array ();
37+ rhs.reset_str_array ();
38+ }
39+
40+ git_strarray_wrapper& git_strarray_wrapper::operator =(git_strarray_wrapper&& rhs)
41+ {
42+ using std::swap;
43+ swap (m_patterns, rhs.m_patterns );
44+ swap (m_array.strings , rhs.m_array .strings );
45+ swap (m_array.count , rhs.m_array .count );
46+ return *this ;
47+ }
48+
49+ git_strarray_wrapper::~git_strarray_wrapper ()
50+ {
51+ reset_str_array ();
52+ }
53+
54+ git_strarray_wrapper::operator git_strarray*()
55+ {
56+ return &m_array;
57+ }
58+
59+ void git_strarray_wrapper::reset_str_array ()
60+ {
61+ delete[] m_array.strings ;
62+ m_array={nullptr , 0 };
63+ }
64+
65+ void git_strarray_wrapper::init_str_array ()
66+ {
67+ m_array.strings = new char *[m_patterns.size ()];
68+ m_array.count = m_patterns.size ();
69+ for (size_t i=0 ; i<m_patterns.size (); ++i)
70+ {
71+ m_array.strings [i] = const_cast <char *>(m_patterns[i].c_str ());
72+ }
73+ }
Original file line number Diff line number Diff line change 22
33#include < string>
44#include < utility>
5+ #include < vector>
6+
7+ #include < git2.h>
58
69class noncopyable_nonmovable
710{
@@ -57,3 +60,30 @@ class libgit2_object : private noncopyable_nonmovable
5760};
5861
5962std::string get_current_git_path ();
63+
64+ class git_strarray_wrapper
65+ {
66+ public:
67+ git_strarray_wrapper ()
68+ : m_patterns{}
69+ , m_array{nullptr , 0 }
70+ {}
71+ git_strarray_wrapper (std::vector<std::string> patterns);
72+
73+ git_strarray_wrapper (const git_strarray_wrapper&) = delete ;
74+ git_strarray_wrapper& operator =(const git_strarray_wrapper&) = delete ;
75+
76+ git_strarray_wrapper (git_strarray_wrapper&& rhs);
77+ git_strarray_wrapper& operator =(git_strarray_wrapper&&);
78+
79+ ~git_strarray_wrapper ();
80+
81+ operator git_strarray*();
82+
83+ private:
84+ std::vector<std::string> m_patterns;
85+ git_strarray m_array;
86+
87+ void reset_str_array ();
88+ void init_str_array ();
89+ };
You can’t perform that action at this time.
0 commit comments