From f56805ddde51ffcfdd6123300b6c049764a86980 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 2 Oct 2024 12:27:42 +0200 Subject: Replace manual new allocations for git_strarray with std::vectors ...and remove unused code from git_utils --- src/buildtool/file_system/git_repo.hpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/buildtool/file_system/git_repo.hpp') 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; - /// \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 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 entries_; + std::vector entry_pointers_; + }; }; #endif // INCLUDED_SRC_BUILDTOOL_FILE_SYSTEM_GIT_REPO_HPP -- cgit v1.2.3