mirror of
https://github.com/NixOS/nix
synced 2025-07-05 16:31:47 +02:00
Cleanup ContentAddressMethod
to match docs
The old `std::variant` is bad because we aren't adding a new case to `FileIngestionMethod` so much as we are defining a separate concept --- store object content addressing rather than file system object content addressing. As such, it is more correct to just create a fresh enumeration. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
64e599ebe1
commit
b51e161af5
25 changed files with 275 additions and 203 deletions
|
@ -48,15 +48,21 @@ std::optional<ContentAddressWithReferences> ValidPathInfo::contentAddressWithRef
|
|||
if (! ca)
|
||||
return std::nullopt;
|
||||
|
||||
return std::visit(overloaded {
|
||||
[&](const TextIngestionMethod &) -> ContentAddressWithReferences {
|
||||
switch (ca->method.raw) {
|
||||
case ContentAddressMethod::Raw::Text:
|
||||
{
|
||||
assert(references.count(path) == 0);
|
||||
return TextInfo {
|
||||
.hash = ca->hash,
|
||||
.references = references,
|
||||
};
|
||||
},
|
||||
[&](const FileIngestionMethod & m2) -> ContentAddressWithReferences {
|
||||
}
|
||||
|
||||
case ContentAddressMethod::Raw::Flat:
|
||||
case ContentAddressMethod::Raw::NixArchive:
|
||||
case ContentAddressMethod::Raw::Git:
|
||||
default:
|
||||
{
|
||||
auto refs = references;
|
||||
bool hasSelfReference = false;
|
||||
if (refs.count(path)) {
|
||||
|
@ -64,15 +70,15 @@ std::optional<ContentAddressWithReferences> ValidPathInfo::contentAddressWithRef
|
|||
refs.erase(path);
|
||||
}
|
||||
return FixedOutputInfo {
|
||||
.method = m2,
|
||||
.method = ca->method.getFileIngestionMethod(),
|
||||
.hash = ca->hash,
|
||||
.references = {
|
||||
.others = std::move(refs),
|
||||
.self = hasSelfReference,
|
||||
},
|
||||
};
|
||||
},
|
||||
}, ca->method.raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidPathInfo::isContentAddressed(const Store & store) const
|
||||
|
@ -127,22 +133,18 @@ ValidPathInfo::ValidPathInfo(
|
|||
: UnkeyedValidPathInfo(narHash)
|
||||
, path(store.makeFixedOutputPathFromCA(name, ca))
|
||||
{
|
||||
this->ca = ContentAddress {
|
||||
.method = ca.getMethod(),
|
||||
.hash = ca.getHash(),
|
||||
};
|
||||
std::visit(overloaded {
|
||||
[this](TextInfo && ti) {
|
||||
this->references = std::move(ti.references);
|
||||
this->ca = ContentAddress {
|
||||
.method = TextIngestionMethod {},
|
||||
.hash = std::move(ti.hash),
|
||||
};
|
||||
},
|
||||
[this](FixedOutputInfo && foi) {
|
||||
this->references = std::move(foi.references.others);
|
||||
if (foi.references.self)
|
||||
this->references.insert(path);
|
||||
this->ca = ContentAddress {
|
||||
.method = std::move(foi.method),
|
||||
.hash = std::move(foi.hash),
|
||||
};
|
||||
},
|
||||
}, std::move(ca).raw);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue