aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/content-address.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/content-address.cc')
-rw-r--r--src/libstore/content-address.cc24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc
index 90a3ad1f5..d68c60f4f 100644
--- a/src/libstore/content-address.cc
+++ b/src/libstore/content-address.cc
@@ -9,6 +9,7 @@ std::string FixedOutputHash::printMethodAlgo() const
return makeFileIngestionPrefix(method) + printHashType(hash.type);
}
+
std::string makeFileIngestionPrefix(const FileIngestionMethod m)
{
switch (m) {
@@ -16,9 +17,8 @@ std::string makeFileIngestionPrefix(const FileIngestionMethod m)
return "";
case FileIngestionMethod::Recursive:
return "r:";
- default:
- throw Error("impossible, caught both cases");
}
+ assert(false);
}
std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash)
@@ -32,10 +32,13 @@ std::string renderContentAddress(ContentAddress ca)
{
return std::visit(overloaded {
[](TextHash th) {
- return "text:" + th.hash.to_string(Base32, true);
+ return "text:"
+ + th.hash.to_string(Base32, true);
},
[](FixedOutputHash fsh) {
- return makeFixedOutputCA(fsh.method, fsh.hash);
+ return "fixed:"
+ + makeFileIngestionPrefix(fsh.method)
+ + fsh.hash.to_string(Base32, true);
}
}, ca);
}
@@ -142,7 +145,18 @@ Hash getContentAddressHash(const ContentAddress & ca)
},
[](FixedOutputHash fsh) {
return fsh.hash;
- }
+ },
+ }, ca);
+}
+
+ContentAddressWithReferences caWithoutRefs(const ContentAddress & ca) {
+ return std::visit(overloaded {
+ [&](TextHash h) -> ContentAddressWithReferences {
+ return TextInfo { h, {}};
+ },
+ [&](FixedOutputHash h) -> ContentAddressWithReferences {
+ return FixedOutputInfo { h, {}};
+ },
}, ca);
}