From b00660a429e79d9df0d447e3e9fbb9bf9f932d3c Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 21 Sep 2023 15:15:22 +0200 Subject: just serve: Implement service to get Git tree of an archive content Also adds missing TARGETS file in serve_api folder and ensures code comments are consistent with the proto file. --- .../serve_api/serve_service/source_tree.hpp | 57 +++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'src/buildtool/serve_api/serve_service/source_tree.hpp') diff --git a/src/buildtool/serve_api/serve_service/source_tree.hpp b/src/buildtool/serve_api/serve_service/source_tree.hpp index a74de455..030d33ee 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.hpp +++ b/src/buildtool/serve_api/serve_service/source_tree.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -27,22 +28,38 @@ #include "src/buildtool/execution_api/common/create_execution_api.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_api/remote/config.hpp" +#include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" +#include "src/buildtool/file_system/symlinks_map/resolve_symlinks_map.hpp" #include "src/buildtool/logging/logger.hpp" class SourceTreeService final : public justbuild::just_serve::SourceTree::Service { public: + using ServeCommitTreeResponse = + ::justbuild::just_serve::ServeCommitTreeResponse; + using ServeArchiveTreeResponse = + ::justbuild::just_serve::ServeArchiveTreeResponse; + // Retrieve the Git-subtree identifier from a given Git commit. // // There are no method-specific errors. auto ServeCommitTree( ::grpc::ServerContext* context, const ::justbuild::just_serve::ServeCommitTreeRequest* request, - ::justbuild::just_serve::ServeCommitTreeResponse* response) - -> ::grpc::Status override; + ServeCommitTreeResponse* response) -> ::grpc::Status override; + + // Retrieve the Git-subtree identifier for the tree obtained + // by unpacking an archive with a given blob identifier. + // + // There are no method-specific errors. + auto ServeArchiveTree( + ::grpc::ServerContext* context, + const ::justbuild::just_serve::ServeArchiveTreeRequest* request, + ServeArchiveTreeResponse* response) -> ::grpc::Status override; private: + mutable std::shared_mutex mutex_; std::shared_ptr logger_{std::make_shared("serve-service")}; // remote execution endpoint @@ -51,12 +68,48 @@ class SourceTreeService final // local api gsl::not_null const local_api_{ CreateExecutionApi(std::nullopt)}; + // symlinks resolver map + ResolveSymlinksMap resolve_symlinks_map_{CreateResolveSymlinksMap()}; [[nodiscard]] static auto GetSubtreeFromCommit( std::filesystem::path const& repo_path, std::string const& commit, std::string const& subdir, std::shared_ptr const& logger) -> std::optional; + + [[nodiscard]] static auto GetSubtreeFromTree( + std::filesystem::path const& repo_path, + std::string const& tree_id, + std::string const& subdir, + std::shared_ptr const& logger) -> std::optional; + + [[nodiscard]] static auto GetBlobFromRepo( + std::filesystem::path const& repo_path, + std::string const& blob_id, + std::shared_ptr const& logger) -> std::optional; + + [[nodiscard]] auto SyncArchive(std::string const& tree_id, + std::filesystem::path const& repo_path, + bool sync_tree, + ServeArchiveTreeResponse* response) + -> ::grpc::Status; + + [[nodiscard]] auto ResolveContentTree( + std::string const& tree_id, + std::filesystem::path const& repo_path, + std::optional const& resolve_special, + bool sync_tree, + ServeArchiveTreeResponse* response) -> ::grpc::Status; + + [[nodiscard]] auto ImportToGit( + std::filesystem::path const& unpack_path, + std::filesystem::path const& archive_tree_id_file, + std::string const& content, + std::string const& archive_type, + std::string const& subdir, + std::optional const& resolve_special, + bool sync_tree, + ServeArchiveTreeResponse* response) -> ::grpc::Status; }; #endif // INCLUDED_SRC_BUILDTOOL_SERVE_API_SERVE_SERVICE_SOURCE_TREE_HPP -- cgit v1.2.3