Skip to content

Commit

Permalink
libfetchers: Rename immutable -> locked
Browse files Browse the repository at this point in the history
This is more consistent with flake terminology.
  • Loading branch information
edolstra committed Feb 24, 2022
1 parent 3317866 commit 8518ceb
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 50 deletions.
8 changes: 4 additions & 4 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ LockedFlake lockFlake(
this input. */
debug("creating new input '%s'", inputPathS);

if (!lockFlags.allowMutable && !input.ref->input.isImmutable())
if (!lockFlags.allowMutable && !input.ref->input.isLocked())
throw Error("cannot update flake input '%s' in pure mode", inputPathS);

if (input.isFlake) {
Expand Down Expand Up @@ -650,7 +650,7 @@ LockedFlake lockFlake(
now. Corner case: we could have reverted from a
dirty to a clean tree! */
if (flake.lockedRef.input == prevLockedRef.input
&& !flake.lockedRef.input.isImmutable())
&& !flake.lockedRef.input.isLocked())
throw Error("'%s' did not change after I updated its 'flake.lock' file; is 'flake.lock' under version control?", flake.originalRef);
}
} else
Expand Down Expand Up @@ -709,8 +709,8 @@ static void prim_getFlake(EvalState & state, const Pos & pos, Value * * args, Va

string flakeRefS(state.forceStringNoCtx(*args[0], pos));
auto flakeRef = parseFlakeRef(flakeRefS, {}, true);
if (evalSettings.pureEval && !flakeRef.input.isImmutable())
throw Error("cannot call 'getFlake' on mutable flake reference '%s', at %s (use --impure to override)", flakeRefS, pos);
if (evalSettings.pureEval && !flakeRef.input.isLocked())
throw Error("cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)", flakeRefS, pos);

callFlake(state,
lockFlake(state, flakeRef,
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/flake/lockfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LockedNode::LockedNode(const nlohmann::json & json)
, originalRef(getFlakeRef(json, "original", nullptr))
, isFlake(json.find("flake") != json.end() ? (bool) json["flake"] : true)
{
if (!lockedRef.input.isImmutable())
if (!lockedRef.input.isLocked())
throw Error("lockfile contains mutable lock '%s'",
fetchers::attrsToJSON(lockedRef.input.toAttrs()));
}
Expand Down Expand Up @@ -220,7 +220,7 @@ bool LockFile::isImmutable() const
for (auto & i : nodes) {
if (i == root) continue;
auto lockedNode = std::dynamic_pointer_cast<const LockedNode>(i);
if (lockedNode && !lockedNode->lockedRef.input.isImmutable()) return false;
if (lockedNode && !lockedNode->lockedRef.input.isLocked()) return false;
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions src/libexpr/primops/fetchTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void emitTreeAttrs(
bool emptyRevFallback,
bool forceDirty)
{
assert(input.isImmutable());
assert(input.isLocked());

auto attrs = state.buildBindings(8);

Expand Down Expand Up @@ -166,8 +166,8 @@ static void fetchTree(
if (!evalSettings.pureEval && !input.isDirect())
input = lookupInRegistries(state.store, input).first;

if (evalSettings.pureEval && !input.isImmutable())
throw Error("in pure evaluation mode, 'fetchTree' requires an immutable input, at %s", pos);
if (evalSettings.pureEval && !input.isLocked())
throw Error("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", pos);

auto [tree, input2] = input.fetch(state.store);

Expand Down
8 changes: 4 additions & 4 deletions src/libfetchers/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ struct CacheImpl : Cache
const Attrs & inAttrs,
const Attrs & infoAttrs,
const StorePath & storePath,
bool immutable) override
bool locked) override
{
_state.lock()->add.use()
(attrsToJSON(inAttrs).dump())
(attrsToJSON(infoAttrs).dump())
(store->printStorePath(storePath))
(immutable)
(locked)
(time(0)).exec();
}

Expand Down Expand Up @@ -91,7 +91,7 @@ struct CacheImpl : Cache

auto infoJSON = stmt.getStr(0);
auto storePath = store->parseStorePath(stmt.getStr(1));
auto immutable = stmt.getInt(2) != 0;
auto locked = stmt.getInt(2) != 0;
auto timestamp = stmt.getInt(3);

store->addTempRoot(storePath);
Expand All @@ -105,7 +105,7 @@ struct CacheImpl : Cache
inAttrsJSON, infoJSON, store->printStorePath(storePath));

return Result {
.expired = !immutable && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)),
.expired = !locked && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)),
.infoAttrs = jsonToAttrs(nlohmann::json::parse(infoJSON)),
.storePath = std::move(storePath)
};
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/cache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Cache
const Attrs & inAttrs,
const Attrs & infoAttrs,
const StorePath & storePath,
bool immutable) = 0;
bool locked) = 0;

virtual std::optional<std::pair<Attrs, StorePath>> lookup(
ref<Store> store,
Expand Down
8 changes: 4 additions & 4 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ static void fixupInput(Input & input)
input.getType();
input.getRef();
if (input.getRev())
input.immutable = true;
input.locked = true;
input.getRevCount();
input.getLastModified();
if (input.getNarHash())
input.immutable = true;
input.locked = true;
}

Input Input::fromURL(const ParsedURL & url)
Expand Down Expand Up @@ -165,7 +165,7 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const
input.to_string(), *prevRevCount);
}

input.immutable = true;
input.locked = true;

assert(input.hasAllInfo());

Expand Down Expand Up @@ -209,7 +209,7 @@ StorePath Input::computeStorePath(Store & store) const
{
auto narHash = getNarHash();
if (!narHash)
throw Error("cannot compute store path for mutable input '%s'", to_string());
throw Error("cannot compute store path for unlocked input '%s'", to_string());
return store.makeFixedOutputPath(FileIngestionMethod::Recursive, *narHash, getName());
}

Expand Down
12 changes: 7 additions & 5 deletions src/libfetchers/fetchers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct Input

std::shared_ptr<InputScheme> scheme; // note: can be null
Attrs attrs;
bool immutable = false;
bool locked = false;
bool direct = true;

/* path of the parent of this input, used for relative path resolution */
Expand All @@ -59,16 +59,18 @@ public:
one that goes through a registry. */
bool isDirect() const { return direct; }

/* Check whether this is an "immutable" input, that is,
/* Check whether this is a "locked" input, that is,
one that contains a commit hash or content hash. */
bool isImmutable() const { return immutable; }
bool isLocked() const { return locked; }

bool hasAllInfo() const;

bool operator ==(const Input & other) const;

bool contains(const Input & other) const;

/* Fetch the input into the Nix store, returning the location in
the Nix store and the locked input. */
std::pair<Tree, Input> fetch(ref<Store> store) const;

Input applyOverrides(
Expand Down Expand Up @@ -146,14 +148,14 @@ DownloadFileResult downloadFile(
ref<Store> store,
const std::string & url,
const std::string & name,
bool immutable,
bool locked,
const Headers & headers = {});

std::pair<Tree, time_t> downloadTarball(
ref<Store> store,
const std::string & url,
const std::string & name,
bool immutable,
bool locked,
const Headers & headers = {});

}
14 changes: 7 additions & 7 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ struct GitInputScheme : InputScheme
if (submodules) cacheType += "-submodules";
if (allRefs) cacheType += "-all-refs";

auto getImmutableAttrs = [&]()
auto getLockedAttrs = [&]()
{
return Attrs({
{"type", cacheType},
Expand All @@ -208,7 +208,7 @@ struct GitInputScheme : InputScheme
};

if (input.getRev()) {
if (auto res = getCache()->lookup(store, getImmutableAttrs()))
if (auto res = getCache()->lookup(store, getLockedAttrs()))
return makeResult(res->first, std::move(res->second));
}

Expand Down Expand Up @@ -288,7 +288,7 @@ struct GitInputScheme : InputScheme

if (!input.getRef()) input.attrs.insert_or_assign("ref", isLocal ? readHead(actualUrl) : "master");

Attrs mutableAttrs({
Attrs unlockedAttrs({
{"type", cacheType},
{"name", name},
{"url", actualUrl},
Expand All @@ -307,7 +307,7 @@ struct GitInputScheme : InputScheme

} else {

if (auto res = getCache()->lookup(store, mutableAttrs)) {
if (auto res = getCache()->lookup(store, unlockedAttrs)) {
auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), htSHA1);
if (!input.getRev() || input.getRev() == rev2) {
input.attrs.insert_or_assign("rev", rev2.gitRev());
Expand Down Expand Up @@ -404,7 +404,7 @@ struct GitInputScheme : InputScheme

/* Now that we know the ref, check again whether we have it in
the store. */
if (auto res = getCache()->lookup(store, getImmutableAttrs()))
if (auto res = getCache()->lookup(store, getLockedAttrs()))
return makeResult(res->first, std::move(res->second));

Path tmpDir = createTempDir();
Expand Down Expand Up @@ -476,14 +476,14 @@ struct GitInputScheme : InputScheme
if (!_input.getRev())
getCache()->add(
store,
mutableAttrs,
unlockedAttrs,
infoAttrs,
storePath,
false);

getCache()->add(
store,
getImmutableAttrs(),
getLockedAttrs(),
infoAttrs,
storePath,
true);
Expand Down
6 changes: 3 additions & 3 deletions src/libfetchers/github.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ struct GitArchiveInputScheme : InputScheme
input.attrs.erase("ref");
input.attrs.insert_or_assign("rev", rev->gitRev());

Attrs immutableAttrs({
Attrs lockedAttrs({
{"type", "git-tarball"},
{"rev", rev->gitRev()},
});

if (auto res = getCache()->lookup(store, immutableAttrs)) {
if (auto res = getCache()->lookup(store, lockedAttrs)) {
input.attrs.insert_or_assign("lastModified", getIntAttr(res->first, "lastModified"));
return {std::move(res->second), input};
}
Expand All @@ -211,7 +211,7 @@ struct GitArchiveInputScheme : InputScheme

getCache()->add(
store,
immutableAttrs,
lockedAttrs,
{
{"rev", rev->gitRev()},
{"lastModified", uint64_t(lastModified)}
Expand Down
14 changes: 7 additions & 7 deletions src/libfetchers/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct MercurialInputScheme : InputScheme

if (!input.getRef()) input.attrs.insert_or_assign("ref", "default");

auto getImmutableAttrs = [&]()
auto getLockedAttrs = [&]()
{
return Attrs({
{"type", "hg"},
Expand All @@ -218,20 +218,20 @@ struct MercurialInputScheme : InputScheme
};

if (input.getRev()) {
if (auto res = getCache()->lookup(store, getImmutableAttrs()))
if (auto res = getCache()->lookup(store, getLockedAttrs()))
return makeResult(res->first, std::move(res->second));
}

auto revOrRef = input.getRev() ? input.getRev()->gitRev() : *input.getRef();

Attrs mutableAttrs({
Attrs unlockedAttrs({
{"type", "hg"},
{"name", name},
{"url", actualUrl},
{"ref", *input.getRef()},
});

if (auto res = getCache()->lookup(store, mutableAttrs)) {
if (auto res = getCache()->lookup(store, unlockedAttrs)) {
auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), htSHA1);
if (!input.getRev() || input.getRev() == rev2) {
input.attrs.insert_or_assign("rev", rev2.gitRev());
Expand Down Expand Up @@ -277,7 +277,7 @@ struct MercurialInputScheme : InputScheme
auto revCount = std::stoull(tokens[1]);
input.attrs.insert_or_assign("ref", tokens[2]);

if (auto res = getCache()->lookup(store, getImmutableAttrs()))
if (auto res = getCache()->lookup(store, getLockedAttrs()))
return makeResult(res->first, std::move(res->second));

Path tmpDir = createTempDir();
Expand All @@ -297,14 +297,14 @@ struct MercurialInputScheme : InputScheme
if (!_input.getRev())
getCache()->add(
store,
mutableAttrs,
unlockedAttrs,
infoAttrs,
storePath,
false);

getCache()->add(
store,
getImmutableAttrs(),
getLockedAttrs(),
infoAttrs,
storePath,
true);
Expand Down
14 changes: 7 additions & 7 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DownloadFileResult downloadFile(
ref<Store> store,
const std::string & url,
const std::string & name,
bool immutable,
bool locked,
const Headers & headers)
{
// FIXME: check store
Expand Down Expand Up @@ -88,7 +88,7 @@ DownloadFileResult downloadFile(
inAttrs,
infoAttrs,
*storePath,
immutable);
locked);

if (url != res.effectiveUri)
getCache()->add(
Expand All @@ -100,7 +100,7 @@ DownloadFileResult downloadFile(
},
infoAttrs,
*storePath,
immutable);
locked);

return {
.storePath = std::move(*storePath),
Expand All @@ -113,7 +113,7 @@ std::pair<Tree, time_t> downloadTarball(
ref<Store> store,
const std::string & url,
const std::string & name,
bool immutable,
bool locked,
const Headers & headers)
{
Attrs inAttrs({
Expand All @@ -130,7 +130,7 @@ std::pair<Tree, time_t> downloadTarball(
getIntAttr(cached->infoAttrs, "lastModified")
};

auto res = downloadFile(store, url, name, immutable, headers);
auto res = downloadFile(store, url, name, locked, headers);

std::optional<StorePath> unpackedStorePath;
time_t lastModified;
Expand Down Expand Up @@ -160,7 +160,7 @@ std::pair<Tree, time_t> downloadTarball(
inAttrs,
infoAttrs,
*unpackedStorePath,
immutable);
locked);

return {
Tree { .actualPath = store->toRealPath(*unpackedStorePath), .storePath = std::move(*unpackedStorePath) },
Expand Down Expand Up @@ -202,7 +202,7 @@ struct TarballInputScheme : InputScheme

Input input;
input.attrs = attrs;
//input.immutable = (bool) maybeGetStrAttr(input.attrs, "hash");
//input.locked = (bool) maybeGetStrAttr(input.attrs, "hash");
return input;
}

Expand Down
Loading

0 comments on commit 8518ceb

Please sign in to comment.