aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/content-address.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-07-05 18:53:44 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-07-07 07:30:01 -0400
commit903700c5e168e2ab5bd6bee5e09b5908cb2908d6 (patch)
treea9b92b2a5e04cfae03a02b5d92aaa2719d8d30b8 /src/libstore/content-address.hh
parent6db66ebfc55769edd0c6bc70fcbd76246d4d26e0 (diff)
Simplify `ContentAddress`
Whereas `ContentAddressWithReferences` is a sum type complex because different varieties support different notions of reference, and `ContentAddressMethod` is a nested enum to support that, `ContentAddress` can be a simple pair of a method and hash. `ContentAddress` does not need to be a sum type on the outside because the choice of method doesn't effect what type of hashes we can use. Co-Authored-By: Cale Gibbard <cgibbard@gmail.com>
Diffstat (limited to 'src/libstore/content-address.hh')
-rw-r--r--src/libstore/content-address.hh91
1 files changed, 30 insertions, 61 deletions
diff --git a/src/libstore/content-address.hh b/src/libstore/content-address.hh
index e1e80448b..01b771e52 100644
--- a/src/libstore/content-address.hh
+++ b/src/libstore/content-address.hh
@@ -114,37 +114,6 @@ struct ContentAddressMethod
*/
/**
- * Somewhat obscure, used by \ref Derivation derivations and
- * `builtins.toFile` currently.
- */
-struct TextHash {
- /**
- * Hash of the contents of the text/file.
- */
- Hash hash;
-
- GENERATE_CMP(TextHash, me->hash);
-};
-
-/**
- * Used by most store objects that are content-addressed.
- */
-struct FixedOutputHash {
- /**
- * How the file system objects are serialized
- */
- FileIngestionMethod method;
- /**
- * Hash of that serialization
- */
- Hash hash;
-
- std::string printMethodAlgo() const;
-
- GENERATE_CMP(FixedOutputHash, me->method, me->hash);
-};
-
-/**
* We've accumulated several types of content-addressed paths over the
* years; fixed-output derivations support multiple hash algorithms and
* serialisation methods (flat file vs NAR). Thus, ‘ca’ has one of the
@@ -158,19 +127,17 @@ struct FixedOutputHash {
*/
struct ContentAddress
{
- typedef std::variant<
- TextHash,
- FixedOutputHash
- > Raw;
-
- Raw raw;
+ /**
+ * How the file system objects are serialized
+ */
+ ContentAddressMethod method;
- GENERATE_CMP(ContentAddress, me->raw);
+ /**
+ * Hash of that serialization
+ */
+ Hash hash;
- /* The moral equivalent of `using Raw::Raw;` */
- ContentAddress(auto &&... arg)
- : raw(std::forward<decltype(arg)>(arg)...)
- { }
+ GENERATE_CMP(ContentAddress, me->method, me->hash);
/**
* Compute the content-addressability assertion
@@ -183,20 +150,6 @@ struct ContentAddress
static std::optional<ContentAddress> parseOpt(std::string_view rawCaOpt);
- /**
- * Create a `ContentAddress` from 2 parts:
- *
- * @param method Way ingesting the file system data.
- *
- * @param hash Hash of ingested file system data.
- */
- static ContentAddress fromParts(
- ContentAddressMethod method, Hash hash) noexcept;
-
- ContentAddressMethod getMethod() const;
-
- const Hash & getHash() const;
-
std::string printMethodAlgo() const;
};
@@ -219,7 +172,8 @@ std::string renderContentAddress(std::optional<ContentAddress> ca);
* References to other store objects are tracked with store paths, self
* references however are tracked with a boolean.
*/
-struct StoreReferences {
+struct StoreReferences
+{
/**
* References to other store objects
*/
@@ -246,8 +200,13 @@ struct StoreReferences {
};
// This matches the additional info that we need for makeTextPath
-struct TextInfo {
- TextHash hash;
+struct TextInfo
+{
+ /**
+ * Hash of the contents of the text/file.
+ */
+ Hash hash;
+
/**
* References to other store objects only; self references
* disallowed
@@ -257,8 +216,18 @@ struct TextInfo {
GENERATE_CMP(TextInfo, me->hash, me->references);
};
-struct FixedOutputInfo {
- FixedOutputHash hash;
+struct FixedOutputInfo
+{
+ /**
+ * How the file system objects are serialized
+ */
+ FileIngestionMethod method;
+
+ /**
+ * Hash of that serialization
+ */
+ Hash hash;
+
/**
* References to other store objects or this one.
*/