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.cc46
1 files changed, 35 insertions, 11 deletions
diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc
index cf32ccdc4..64daea0d4 100644
--- a/src/libstore/content-address.cc
+++ b/src/libstore/content-address.cc
@@ -9,7 +9,8 @@ std::string FixedOutputHash::printMethodAlgo() const
return makeFileIngestionPrefix(method) + printHashType(hash.type);
}
-std::string makeFileIngestionPrefix(const FileIngestionMethod m)
+
+std::string makeFileIngestionPrefix(FileIngestionMethod m)
{
switch (m) {
case FileIngestionMethod::Flat:
@@ -21,21 +22,17 @@ std::string makeFileIngestionPrefix(const FileIngestionMethod m)
}
}
-std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash)
-{
- return "fixed:"
- + makeFileIngestionPrefix(method)
- + hash.to_string(Base32, true);
-}
-
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);
}
@@ -144,7 +141,34 @@ Hash getContentAddressHash(const ContentAddress & ca)
},
[](const FixedOutputHash & fsh) {
return fsh.hash;
- }
+ },
+ }, ca);
+}
+
+bool StoreReferences::empty() const
+{
+ return !self && others.empty();
+}
+
+size_t StoreReferences::size() const
+{
+ return (self ? 1 : 0) + others.size();
+}
+
+ContentAddressWithReferences caWithoutRefs(const ContentAddress & ca) {
+ return std::visit(overloaded {
+ [&](const TextHash & h) -> ContentAddressWithReferences {
+ return TextInfo {
+ .hash = h,
+ .references = {},
+ };
+ },
+ [&](const FixedOutputHash & h) -> ContentAddressWithReferences {
+ return FixedOutputInfo {
+ .hash = h,
+ .references = {},
+ };
+ },
}, ca);
}