diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-06-13 13:30:13 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-06-13 13:30:13 +0200 |
commit | ef9182151e4a222a65ef55bc4ef06a25ecb2d895 (patch) | |
tree | 863a8b86da704664874ef5618988d3b38390f193 /src/buildtool/file_system/file_root.hpp | |
parent | 454cfcf66efc6ff5f42253431c6033e1e21044cf (diff) | |
download | justbuild-ef9182151e4a222a65ef55bc4ef06a25ecb2d895.tar.gz |
FileRoot: support content description
For some file roots, in particular git trees, we can give a complete
selfcontained description of the content without accessing any
external resources. For those, add a method to return such a complete
description that will be used to compute the keys of content-defined
repositories.
Diffstat (limited to 'src/buildtool/file_system/file_root.hpp')
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index 66ceb68a..747ca896 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -11,6 +11,7 @@ #include <variant> #include "gsl-lite/gsl-lite.hpp" +#include "nlohmann/json.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -82,6 +83,8 @@ class FileRoot { using root_t = std::variant<fs_root_t, git_root_t>; public: + static constexpr auto kGitTreeMarker = "git tree"; + class DirectoryEntries { friend class FileRoot; @@ -252,6 +255,22 @@ class FileRoot { return std::nullopt; } + // Return a complete description of the content of this root, if that can be + // done without any file-system access. + [[nodiscard]] auto ContentDescription() const noexcept + -> std::optional<nlohmann::json> { + try { + if (std::holds_alternative<git_root_t>(root_)) { + nlohmann::json j; + j.push_back(kGitTreeMarker); + j.push_back(std::get<git_root_t>(root_).tree->Hash()); + return j; + } + } catch (...) { + } + return std::nullopt; + } + // Indicates that subsequent calls to `Exists()`, `IsFile()`, // `IsDirectory()`, and `FileType()` on contents of the same directory will // be served without any additional file system lookups. |