diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/file_system/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 19 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 2 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS index 32dd96db..349c6d03 100644 --- a/src/buildtool/file_system/TARGETS +++ b/src/buildtool/file_system/TARGETS @@ -64,6 +64,7 @@ , ["src/buildtool/common", "artifact_description"] , ["src/buildtool/compatibility", "compatibility"] , ["@", "gsl-lite", "", "gsl-lite"] + , ["@", "json", "", "json"] ] , "stage": ["src", "buildtool", "file_system"] } 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. diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 435e8219..b41d7a11 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -462,7 +462,7 @@ auto ParseRoot(std::string const& repo, auto path = std::filesystem::path{root[1]}; return {FileRoot{path}, std::move(path)}; } - if (root[0] == "git tree") { + if (root[0] == FileRoot::kGitTreeMarker) { if (root.size() != 3 or (not root[1].is_string()) or (not root[2].is_string())) { Logger::Log(LogLevel::Error, |