diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-02 12:27:42 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-07 13:37:39 +0200 |
commit | f56805ddde51ffcfdd6123300b6c049764a86980 (patch) | |
tree | 0b18734f5a60bddec7bb44c32b4027529de056e8 /src/buildtool/file_system/git_repo.hpp | |
parent | e2555394980ab4d1d8b938fec0ad8d246d7745b4 (diff) | |
download | justbuild-f56805ddde51ffcfdd6123300b6c049764a86980.tar.gz |
Replace manual new allocations for git_strarray with std::vectors
...and remove unused code from git_utils
Diffstat (limited to 'src/buildtool/file_system/git_repo.hpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index 03ce92d8..942e97b7 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -33,6 +33,7 @@ extern "C" { struct git_repository; struct git_config; +struct git_strarray; } /// \brief Git repository logic. @@ -378,13 +379,19 @@ class GitRepo { std::filesystem::path const& dir, anon_logger_ptr const& logger) noexcept -> std::optional<std::string>; - /// \brief Helper function to allocate and populate the char** pointer of a - /// git_strarray from a vector of standard strings. User MUST use - /// git_strarray_dispose to deallocate the inner pointer when the strarray - /// is not needed anymore! - static void PopulateStrarray( - git_strarray* array, - std::vector<std::string> const& string_list) noexcept; + class GitStrArray final { + public: + void AddEntry(std::string entry) { + char* const entry_ptr = + entries_.emplace_back(std::move(entry)).data(); + entry_pointers_.push_back(entry_ptr); + } + [[nodiscard]] auto Get() & noexcept -> git_strarray; + + private: + std::vector<std::string> entries_; + std::vector<char*> entry_pointers_; + }; }; #endif // INCLUDED_SRC_BUILDTOOL_FILE_SYSTEM_GIT_REPO_HPP |