summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-12-04 12:31:15 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-12-04 18:03:44 +0100
commitf2c7776e00d6a0ed9f601fbfbf082cab0393d640 (patch)
treeffc286fb7eff4e00b434eabdc57f9608ed4e475d
parentee5dac3d832d4951fc0141aaf9b642e499d8189d (diff)
downloadjustbuild-f2c7776e00d6a0ed9f601fbfbf082cab0393d640.tar.gz
rehash_utils: add a class for the rehash function
... to allow a more specific signature when passing around the rehash function.
-rw-r--r--src/buildtool/execution_api/utils/rehash_utils.cpp10
-rw-r--r--src/buildtool/execution_api/utils/rehash_utils.hpp19
2 files changed, 29 insertions, 0 deletions
diff --git a/src/buildtool/execution_api/utils/rehash_utils.cpp b/src/buildtool/execution_api/utils/rehash_utils.cpp
index 43a6e682..ec4edf99 100644
--- a/src/buildtool/execution_api/utils/rehash_utils.cpp
+++ b/src/buildtool/execution_api/utils/rehash_utils.cpp
@@ -297,4 +297,14 @@ auto RehashGitDigest(std::vector<Artifact::ObjectInfo> const& digests,
/*from_git=*/true);
}
+auto Rehasher::Rehash(Artifact::ObjectInfo const& info) const
+ -> expected<Artifact::ObjectInfo, std::string> {
+ auto rehashed = RehashUtils::RehashDigest(
+ std::vector<Artifact::ObjectInfo>{info}, source_, target_, apis_);
+ if (not rehashed) {
+ return unexpected<std::string>(rehashed.error());
+ }
+ return rehashed.value()[0];
+}
+
} // namespace RehashUtils
diff --git a/src/buildtool/execution_api/utils/rehash_utils.hpp b/src/buildtool/execution_api/utils/rehash_utils.hpp
index e4a09ca9..f21d5e41 100644
--- a/src/buildtool/execution_api/utils/rehash_utils.hpp
+++ b/src/buildtool/execution_api/utils/rehash_utils.hpp
@@ -17,6 +17,7 @@
#include <optional>
#include <string>
+#include <utility>
#include <vector>
#include "gsl/gsl"
@@ -77,6 +78,24 @@ namespace RehashUtils {
RepositoryConfig const& repo_config)
-> expected<std::vector<Artifact::ObjectInfo>, std::string>;
+class Rehasher {
+ public:
+ Rehasher(StorageConfig source_config,
+ StorageConfig target_config,
+ std::optional<gsl::not_null<ApiBundle const*>> apis)
+ : source_{std::move(source_config)},
+ target_{std::move(target_config)},
+ apis_{std::move(apis)} {}
+
+ [[nodiscard]] auto Rehash(Artifact::ObjectInfo const& info) const
+ -> expected<Artifact::ObjectInfo, std::string>;
+
+ private:
+ StorageConfig const source_;
+ StorageConfig const target_;
+ std::optional<gsl::not_null<ApiBundle const*>> const apis_;
+};
+
} // namespace RehashUtils
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_UTILS_REHASH_UTILS_HPP