Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
content-address.hh
Go to the documentation of this file.
1#pragma once
3
4#include <variant>
5#include "lix/libutil/hash.hh"
9
10namespace nix {
11
12/*
13 * Content addressing method
14 */
15
16/* We only have one way to hash text with references, so this is a single-value
17 type, mainly useful with std::variant.
18*/
19
32struct TextIngestionMethod : std::monostate { };
33
38enum struct FileIngestionMethod : uint8_t {
42 Flat = false,
47 Recursive = true
48};
49
54std::string makeFileIngestionPrefix(FileIngestionMethod m);
55
65{
66 typedef std::variant<
69 > Raw;
70
71 Raw raw;
72
74
76
85 static ContentAddressMethod parsePrefix(std::string_view & m);
86
92 std::string renderPrefix() const;
93
97 static std::pair<ContentAddressMethod, HashType> parse(std::string_view rawCaMethod);
98
105 std::string render(HashType ht) const;
106};
107
108
109/*
110 * Mini content address
111 */
112
126{
131
136
137 GENERATE_CMP(ContentAddress, me->method, me->hash);
138
144 std::string render() const;
145
146 static ContentAddress parse(std::string_view rawCa);
147
148 static std::optional<ContentAddress> parseOpt(std::string_view rawCaOpt);
149
150 std::string printMethodAlgo() const;
151};
152
157std::string renderContentAddress(std::optional<ContentAddress> ca);
158
159
160/*
161 * Full content address
162 *
163 * See the schema for store paths in store-api.cc
164 */
165
173{
177 StorePathSet others;
178
182 bool self = false;
183
188 bool empty() const;
189
194 size_t size() const;
195
196 GENERATE_CMP(StoreReferences, me->self, me->others);
197};
198
199// This matches the additional info that we need for makeTextPath
201{
206
211 StorePathSet references;
212
213 GENERATE_CMP(TextInfo, me->hash, me->references);
214};
215
235
242{
243 typedef std::variant<
244 TextInfo,
246 > Raw;
247
248 Raw raw;
249
251
253
259
272 static std::optional<ContentAddressWithReferences> fromPartsOpt(
273 ContentAddressMethod method, Hash hash, StoreReferences refs);
274
275 ContentAddressMethod getMethod() const;
276
277 Hash getHash() const;
278};
279
280}
#define GENERATE_CMP(args...)
Definition comparator.hh:65
FileIngestionMethod
Definition content-address.hh:38
@ Recursive
Definition content-address.hh:47
@ Flat
Definition content-address.hh:42
Definition content-address.hh:65
std::string render(HashType ht) const
Definition content-address.cc:42
std::string renderPrefix() const
Definition content-address.cc:20
static ContentAddressMethod parsePrefix(std::string_view &m)
Definition content-address.cc:31
static std::pair< ContentAddressMethod, HashType > parse(std::string_view rawCaMethod)
Definition content-address.cc:125
Definition content-address.hh:242
static std::optional< ContentAddressWithReferences > fromPartsOpt(ContentAddressMethod method, Hash hash, StoreReferences refs)
Definition content-address.cc:180
static ContentAddressWithReferences withoutRefs(const ContentAddress &)
Definition content-address.cc:161
Definition content-address.hh:126
Hash hash
Definition content-address.hh:135
ContentAddressMethod method
Definition content-address.hh:130
std::string render() const
Definition content-address.cc:54
Definition content-address.hh:217
FileIngestionMethod method
Definition content-address.hh:221
StoreReferences references
Definition content-address.hh:231
Hash hash
Definition content-address.hh:226
Definition hash.hh:41
Definition content-address.hh:173
bool empty() const
Definition content-address.cc:151
StorePathSet others
Definition content-address.hh:177
bool self
Definition content-address.hh:182
size_t size() const
Definition content-address.cc:156
Definition content-address.hh:201
Hash hash
Definition content-address.hh:205
StorePathSet references
Definition content-address.hh:211
Definition content-address.hh:32
#define MAKE_WRAPPER_CONSTRUCTOR(CLASS_NAME)
Definition variant-wrapper.hh:27