forked from lix-project/lix
Move Explicit
This commit is contained in:
parent
dc7d1322ef
commit
9d5e9ef0da
|
@ -34,7 +34,8 @@ LockedNode::LockedNode(const nlohmann::json & json)
|
|||
, isFlake(json.find("flake") != json.end() ? (bool) json["flake"] : true)
|
||||
{
|
||||
if (!lockedRef.input.isImmutable())
|
||||
throw Error("lockfile contains mutable lock '%s'", attrsToJson(lockedRef.input.toAttrs()));
|
||||
throw Error("lockfile contains mutable lock '%s'",
|
||||
fetchers::attrsToJson(lockedRef.input.toAttrs()));
|
||||
}
|
||||
|
||||
StorePath LockedNode::computeStorePath(Store & store) const
|
||||
|
|
|
@ -43,7 +43,8 @@ void emitTreeAttrs(
|
|||
}
|
||||
|
||||
if (input.getType() == "git")
|
||||
mkBool(*state.allocAttr(v, state.symbols.create("submodules")), maybeGetBoolAttr(input.attrs, "submodules").value_or(false));
|
||||
mkBool(*state.allocAttr(v, state.symbols.create("submodules")),
|
||||
fetchers::maybeGetBoolAttr(input.attrs, "submodules").value_or(false));
|
||||
|
||||
if (auto revCount = input.getRevCount())
|
||||
mkInt(*state.allocAttr(v, state.symbols.create("revCount")), *revCount);
|
||||
|
@ -101,7 +102,7 @@ static void fetchTree(
|
|||
else if (attr.value->type == tString)
|
||||
addURI(state, attrs, attr.name, attr.value->string.s);
|
||||
else if (attr.value->type == tBool)
|
||||
attrs.emplace(attr.name, fetchers::Explicit<bool>{attr.value->boolean});
|
||||
attrs.emplace(attr.name, Explicit<bool>{attr.value->boolean});
|
||||
else if (attr.value->type == tInt)
|
||||
attrs.emplace(attr.name, attr.value->integer);
|
||||
else
|
||||
|
|
|
@ -8,18 +8,6 @@
|
|||
|
||||
namespace nix::fetchers {
|
||||
|
||||
/* Wrap bools to prevent string literals (i.e. 'char *') from being
|
||||
cast to a bool in Attr. */
|
||||
template<typename T>
|
||||
struct Explicit {
|
||||
T t;
|
||||
|
||||
bool operator ==(const Explicit<T> & other) const
|
||||
{
|
||||
return t == other.t;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::variant<std::string, uint64_t, Explicit<bool>> Attr;
|
||||
typedef std::map<std::string, Attr> Attrs;
|
||||
|
||||
|
|
|
@ -34,4 +34,16 @@ struct OnStartup
|
|||
OnStartup(T && t) { t(); }
|
||||
};
|
||||
|
||||
/* Wrap bools to prevent string literals (i.e. 'char *') from being
|
||||
cast to a bool in Attr. */
|
||||
template<typename T>
|
||||
struct Explicit {
|
||||
T t;
|
||||
|
||||
bool operator ==(const Explicit<T> & other) const
|
||||
{
|
||||
return t == other.t;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -82,11 +82,11 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
|
|||
if (flake.description)
|
||||
j["description"] = *flake.description;
|
||||
j["originalUrl"] = flake.originalRef.to_string();
|
||||
j["original"] = attrsToJson(flake.originalRef.toAttrs());
|
||||
j["original"] = fetchers::attrsToJson(flake.originalRef.toAttrs());
|
||||
j["resolvedUrl"] = flake.resolvedRef.to_string();
|
||||
j["resolved"] = attrsToJson(flake.resolvedRef.toAttrs());
|
||||
j["resolved"] = fetchers::attrsToJson(flake.resolvedRef.toAttrs());
|
||||
j["url"] = flake.lockedRef.to_string(); // FIXME: rename to lockedUrl
|
||||
j["locked"] = attrsToJson(flake.lockedRef.toAttrs());
|
||||
j["locked"] = fetchers::attrsToJson(flake.lockedRef.toAttrs());
|
||||
if (auto rev = flake.lockedRef.input.getRev())
|
||||
j["revision"] = rev->to_string(Base16, false);
|
||||
if (auto revCount = flake.lockedRef.input.getRevCount())
|
||||
|
|
Loading…
Reference in a new issue