From c0422f390f9f30b7cc470a814e209bedc7e87f1a Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 14 Jul 2022 17:56:02 +0200 Subject: BazelMsgFactory: Support dumping Git tree to string --- .../execution_api/bazel_msg/bazel_msg_factory.cpp | 23 ++++++++++++++++++++++ .../execution_api/bazel_msg/bazel_msg_factory.hpp | 5 +++++ 2 files changed, 28 insertions(+) (limited to 'src') diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp index ead45f6e..8d4d06c7 100644 --- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp +++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp @@ -680,3 +680,26 @@ auto BazelMsgFactory::DirectoryToString(bazel_re::Directory const& dir) noexcept return std::nullopt; } } + +auto BazelMsgFactory::GitTreeToString( + GitCAS::tree_entries_t const& entries) noexcept + -> std::optional { + auto json = nlohmann::json::object(); + try { + if (not BazelMsgFactory::ReadObjectInfosFromGitTree( + entries, [&json](auto path, auto info) { + json[path.string()] = info.ToString(/*size_unknown=*/true); + return true; + })) { + Logger::Log(LogLevel::Error, + "reading object infos from Directory failed"); + return std::nullopt; + } + return json.dump(2) + "\n"; + } catch (std::exception const& ex) { + Logger::Log(LogLevel::Error, + "dumping Directory to string failed with:\n{}", + ex.what()); + return std::nullopt; + } +} diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp index 5044a646..06d981eb 100644 --- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp +++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp @@ -113,6 +113,11 @@ class BazelMsgFactory { [[nodiscard]] static auto DirectoryToString( bazel_re::Directory const& dir) noexcept -> std::optional; + /// \brief Create descriptive string from Git tree entries. + [[nodiscard]] static auto GitTreeToString( + GitCAS::tree_entries_t const& entries) noexcept + -> std::optional; + /// \brief Create message vector from std::map. /// \param[in] input map /// \tparam T protobuf message type. It must be a name-value -- cgit v1.2.3