forked from lix-project/lix
Cleanup
This commit is contained in:
parent
b270869466
commit
958ec5de56
|
@ -22,7 +22,7 @@ static FlakeRef maybeLookupFlake(
|
||||||
const FlakeRef & flakeRef,
|
const FlakeRef & flakeRef,
|
||||||
bool allowLookup)
|
bool allowLookup)
|
||||||
{
|
{
|
||||||
if (!flakeRef.isDirect()) {
|
if (!flakeRef.input->isDirect()) {
|
||||||
if (allowLookup)
|
if (allowLookup)
|
||||||
return flakeRef.resolve(state.store);
|
return flakeRef.resolve(state.store);
|
||||||
else
|
else
|
||||||
|
@ -150,9 +150,7 @@ static Flake getFlake(EvalState & state, const FlakeRef & originalRef,
|
||||||
maybeLookupFlake(state,
|
maybeLookupFlake(state,
|
||||||
lookupInFlakeCache(flakeCache, originalRef), allowLookup));
|
lookupInFlakeCache(flakeCache, originalRef), allowLookup));
|
||||||
|
|
||||||
auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store);
|
auto [sourceInfo, lockedRef] = flakeRef.fetchTree(state.store);
|
||||||
|
|
||||||
FlakeRef lockedRef(resolvedInput, flakeRef.subdir);
|
|
||||||
|
|
||||||
debug("got flake source '%s' from '%s'",
|
debug("got flake source '%s' from '%s'",
|
||||||
state.store->printStorePath(sourceInfo.storePath), lockedRef);
|
state.store->printStorePath(sourceInfo.storePath), lockedRef);
|
||||||
|
@ -257,9 +255,7 @@ static std::pair<fetchers::Tree, FlakeRef> getNonFlake(
|
||||||
maybeLookupFlake(state,
|
maybeLookupFlake(state,
|
||||||
lookupInFlakeCache(flakeCache, originalRef), allowLookup));
|
lookupInFlakeCache(flakeCache, originalRef), allowLookup));
|
||||||
|
|
||||||
auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store);
|
auto [sourceInfo, lockedRef] = flakeRef.fetchTree(state.store);
|
||||||
|
|
||||||
FlakeRef lockedRef(resolvedInput, flakeRef.subdir);
|
|
||||||
|
|
||||||
debug("got non-flake source '%s' from '%s'",
|
debug("got non-flake source '%s' from '%s'",
|
||||||
state.store->printStorePath(sourceInfo.storePath), lockedRef);
|
state.store->printStorePath(sourceInfo.storePath), lockedRef);
|
||||||
|
@ -470,7 +466,7 @@ LockedFlake lockFlake(
|
||||||
/* We need to update/create a new lock file
|
/* We need to update/create a new lock file
|
||||||
entry. So fetch the flake/non-flake. */
|
entry. So fetch the flake/non-flake. */
|
||||||
|
|
||||||
if (!lockFlags.allowMutable && !input.ref.isImmutable())
|
if (!lockFlags.allowMutable && !input.ref.input->isImmutable())
|
||||||
throw Error("cannot update flake input '%s' in pure mode", inputPathS);
|
throw Error("cannot update flake input '%s' in pure mode", inputPathS);
|
||||||
|
|
||||||
if (input.isFlake) {
|
if (input.isFlake) {
|
||||||
|
|
|
@ -27,16 +27,6 @@ fetchers::Input::Attrs FlakeRef::toAttrs() const
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FlakeRef::isDirect() const
|
|
||||||
{
|
|
||||||
return input->isDirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FlakeRef::isImmutable() const
|
|
||||||
{
|
|
||||||
return input->isImmutable();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef)
|
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef)
|
||||||
{
|
{
|
||||||
str << flakeRef.to_string();
|
str << flakeRef.to_string();
|
||||||
|
@ -182,4 +172,10 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Input::Attrs & attrs)
|
||||||
fetchers::maybeGetStrAttr(attrs, "subdir").value_or(""));
|
fetchers::maybeGetStrAttr(attrs, "subdir").value_or(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<fetchers::Tree, FlakeRef> FlakeRef::fetchTree(ref<Store> store) const
|
||||||
|
{
|
||||||
|
auto [tree, lockedInput] = input->fetchTree(store);
|
||||||
|
return {std::move(tree), FlakeRef(lockedInput, subdir)};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,11 @@ struct FlakeRef
|
||||||
|
|
||||||
fetchers::Input::Attrs toAttrs() const;
|
fetchers::Input::Attrs toAttrs() const;
|
||||||
|
|
||||||
/* Check whether this is a "direct" flake reference, that is, not
|
|
||||||
a flake ID, which requires a lookup in the flake registry. */
|
|
||||||
bool isDirect() const;
|
|
||||||
|
|
||||||
/* Check whether this is an "immutable" flake reference, that is,
|
|
||||||
one that contains a commit hash or content hash. */
|
|
||||||
bool isImmutable() const;
|
|
||||||
|
|
||||||
FlakeRef resolve(ref<Store> store) const;
|
FlakeRef resolve(ref<Store> store) const;
|
||||||
|
|
||||||
static FlakeRef fromAttrs(const fetchers::Input::Attrs & attrs);
|
static FlakeRef fromAttrs(const fetchers::Input::Attrs & attrs);
|
||||||
|
|
||||||
|
std::pair<fetchers::Tree, FlakeRef> fetchTree(ref<Store> store) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
|
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
|
||||||
|
|
|
@ -84,7 +84,7 @@ LockedInput::LockedInput(const nlohmann::json & json)
|
||||||
, originalRef(getFlakeRef(json, "originalUrl", "originalUri", "original"))
|
, originalRef(getFlakeRef(json, "originalUrl", "originalUri", "original"))
|
||||||
, info(parseTreeInfo(json))
|
, info(parseTreeInfo(json))
|
||||||
{
|
{
|
||||||
if (!lockedRef.isImmutable())
|
if (!lockedRef.input->isImmutable())
|
||||||
throw Error("lockfile contains mutable flakeref '%s'", lockedRef);
|
throw Error("lockfile contains mutable flakeref '%s'", lockedRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ nlohmann::json LockedInputs::toJson() const
|
||||||
bool LockedInputs::isImmutable() const
|
bool LockedInputs::isImmutable() const
|
||||||
{
|
{
|
||||||
for (auto & i : inputs)
|
for (auto & i : inputs)
|
||||||
if (!i.second.lockedRef.isImmutable() || !i.second.isImmutable()) return false;
|
if (!i.second.lockedRef.input->isImmutable() || !i.second.isImmutable()) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,12 @@ struct Input : std::enable_shared_from_this<Input>
|
||||||
|
|
||||||
virtual bool operator ==(const Input & other) const { return false; }
|
virtual bool operator ==(const Input & other) const { return false; }
|
||||||
|
|
||||||
|
/* Check whether this is a "direct" input, that is, not
|
||||||
|
one that goes through a registry. */
|
||||||
virtual bool isDirect() const { return true; }
|
virtual bool isDirect() const { return true; }
|
||||||
|
|
||||||
|
/* Check whether this is an "immutable" input, that is,
|
||||||
|
one that contains a commit hash or content hash. */
|
||||||
virtual bool isImmutable() const { return (bool) narHash; }
|
virtual bool isImmutable() const { return (bool) narHash; }
|
||||||
|
|
||||||
virtual bool contains(const Input & other) const { return false; }
|
virtual bool contains(const Input & other) const { return false; }
|
||||||
|
|
|
@ -330,7 +330,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
|
||||||
for (size_t i = 0; i < manifest.elements.size(); ++i) {
|
for (size_t i = 0; i < manifest.elements.size(); ++i) {
|
||||||
auto & element(manifest.elements[i]);
|
auto & element(manifest.elements[i]);
|
||||||
if (element.source
|
if (element.source
|
||||||
&& !element.source->originalRef.isImmutable()
|
&& !element.source->originalRef.input->isImmutable()
|
||||||
&& matches(*store, element, i, matchers))
|
&& matches(*store, element, i, matchers))
|
||||||
{
|
{
|
||||||
Activity act(*logger, lvlChatty, actUnknown,
|
Activity act(*logger, lvlChatty, actUnknown,
|
||||||
|
|
Loading…
Reference in a new issue