mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
Merge pull request #4198 from mkenigs/capitalize-JSON
Capitalize JSON for consistency
This commit is contained in:
commit
662e67f8de
11 changed files with 37 additions and 37 deletions
|
@ -35,7 +35,7 @@ LockedNode::LockedNode(const nlohmann::json & json)
|
||||||
{
|
{
|
||||||
if (!lockedRef.input.isImmutable())
|
if (!lockedRef.input.isImmutable())
|
||||||
throw Error("lockfile contains mutable lock '%s'",
|
throw Error("lockfile contains mutable lock '%s'",
|
||||||
fetchers::attrsToJson(lockedRef.input.toAttrs()));
|
fetchers::attrsToJSON(lockedRef.input.toAttrs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
StorePath LockedNode::computeStorePath(Store & store) const
|
StorePath LockedNode::computeStorePath(Store & store) const
|
||||||
|
@ -111,7 +111,7 @@ LockFile::LockFile(const nlohmann::json & json, const Path & path)
|
||||||
// a bit since we don't need to worry about cycles.
|
// a bit since we don't need to worry about cycles.
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json LockFile::toJson() const
|
nlohmann::json LockFile::toJSON() const
|
||||||
{
|
{
|
||||||
nlohmann::json nodes;
|
nlohmann::json nodes;
|
||||||
std::unordered_map<std::shared_ptr<const Node>, std::string> nodeKeys;
|
std::unordered_map<std::shared_ptr<const Node>, std::string> nodeKeys;
|
||||||
|
@ -155,8 +155,8 @@ nlohmann::json LockFile::toJson() const
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto lockedNode = std::dynamic_pointer_cast<const LockedNode>(node)) {
|
if (auto lockedNode = std::dynamic_pointer_cast<const LockedNode>(node)) {
|
||||||
n["original"] = fetchers::attrsToJson(lockedNode->originalRef.toAttrs());
|
n["original"] = fetchers::attrsToJSON(lockedNode->originalRef.toAttrs());
|
||||||
n["locked"] = fetchers::attrsToJson(lockedNode->lockedRef.toAttrs());
|
n["locked"] = fetchers::attrsToJSON(lockedNode->lockedRef.toAttrs());
|
||||||
if (!lockedNode->isFlake) n["flake"] = false;
|
if (!lockedNode->isFlake) n["flake"] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ nlohmann::json LockFile::toJson() const
|
||||||
|
|
||||||
std::string LockFile::to_string() const
|
std::string LockFile::to_string() const
|
||||||
{
|
{
|
||||||
return toJson().dump(2);
|
return toJSON().dump(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
LockFile LockFile::read(const Path & path)
|
LockFile LockFile::read(const Path & path)
|
||||||
|
@ -186,7 +186,7 @@ LockFile LockFile::read(const Path & path)
|
||||||
|
|
||||||
std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile)
|
std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile)
|
||||||
{
|
{
|
||||||
stream << lockFile.toJson().dump(2);
|
stream << lockFile.toJSON().dump(2);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ bool LockFile::isImmutable() const
|
||||||
bool LockFile::operator ==(const LockFile & other) const
|
bool LockFile::operator ==(const LockFile & other) const
|
||||||
{
|
{
|
||||||
// FIXME: slow
|
// FIXME: slow
|
||||||
return toJson() == other.toJson();
|
return toJSON() == other.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
InputPath parseInputPath(std::string_view s)
|
InputPath parseInputPath(std::string_view s)
|
||||||
|
|
|
@ -52,7 +52,7 @@ struct LockFile
|
||||||
LockFile() {};
|
LockFile() {};
|
||||||
LockFile(const nlohmann::json & json, const Path & path);
|
LockFile(const nlohmann::json & json, const Path & path);
|
||||||
|
|
||||||
nlohmann::json toJson() const;
|
nlohmann::json toJSON() const;
|
||||||
|
|
||||||
std::string to_string() const;
|
std::string to_string() const;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ Attrs jsonToAttrs(const nlohmann::json & json)
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json attrsToJson(const Attrs & attrs)
|
nlohmann::json attrsToJSON(const Attrs & attrs)
|
||||||
{
|
{
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
for (auto & attr : attrs) {
|
for (auto & attr : attrs) {
|
||||||
|
@ -44,7 +44,7 @@ std::optional<std::string> maybeGetStrAttr(const Attrs & attrs, const std::strin
|
||||||
if (i == attrs.end()) return {};
|
if (i == attrs.end()) return {};
|
||||||
if (auto v = std::get_if<std::string>(&i->second))
|
if (auto v = std::get_if<std::string>(&i->second))
|
||||||
return *v;
|
return *v;
|
||||||
throw Error("input attribute '%s' is not a string %s", name, attrsToJson(attrs).dump());
|
throw Error("input attribute '%s' is not a string %s", name, attrsToJSON(attrs).dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getStrAttr(const Attrs & attrs, const std::string & name)
|
std::string getStrAttr(const Attrs & attrs, const std::string & name)
|
||||||
|
|
|
@ -13,7 +13,7 @@ typedef std::map<std::string, Attr> Attrs;
|
||||||
|
|
||||||
Attrs jsonToAttrs(const nlohmann::json & json);
|
Attrs jsonToAttrs(const nlohmann::json & json);
|
||||||
|
|
||||||
nlohmann::json attrsToJson(const Attrs & attrs);
|
nlohmann::json attrsToJSON(const Attrs & attrs);
|
||||||
|
|
||||||
std::optional<std::string> maybeGetStrAttr(const Attrs & attrs, const std::string & name);
|
std::optional<std::string> maybeGetStrAttr(const Attrs & attrs, const std::string & name);
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ struct CacheImpl : Cache
|
||||||
bool immutable) override
|
bool immutable) override
|
||||||
{
|
{
|
||||||
_state.lock()->add.use()
|
_state.lock()->add.use()
|
||||||
(attrsToJson(inAttrs).dump())
|
(attrsToJSON(inAttrs).dump())
|
||||||
(attrsToJson(infoAttrs).dump())
|
(attrsToJSON(infoAttrs).dump())
|
||||||
(store->printStorePath(storePath))
|
(store->printStorePath(storePath))
|
||||||
(immutable)
|
(immutable)
|
||||||
(time(0)).exec();
|
(time(0)).exec();
|
||||||
|
@ -70,7 +70,7 @@ struct CacheImpl : Cache
|
||||||
if (!res->expired)
|
if (!res->expired)
|
||||||
return std::make_pair(std::move(res->infoAttrs), std::move(res->storePath));
|
return std::make_pair(std::move(res->infoAttrs), std::move(res->storePath));
|
||||||
debug("ignoring expired cache entry '%s'",
|
debug("ignoring expired cache entry '%s'",
|
||||||
attrsToJson(inAttrs).dump());
|
attrsToJSON(inAttrs).dump());
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -81,15 +81,15 @@ struct CacheImpl : Cache
|
||||||
{
|
{
|
||||||
auto state(_state.lock());
|
auto state(_state.lock());
|
||||||
|
|
||||||
auto inAttrsJson = attrsToJson(inAttrs).dump();
|
auto inAttrsJSON = attrsToJSON(inAttrs).dump();
|
||||||
|
|
||||||
auto stmt(state->lookup.use()(inAttrsJson));
|
auto stmt(state->lookup.use()(inAttrsJSON));
|
||||||
if (!stmt.next()) {
|
if (!stmt.next()) {
|
||||||
debug("did not find cache entry for '%s'", inAttrsJson);
|
debug("did not find cache entry for '%s'", inAttrsJSON);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto infoJson = stmt.getStr(0);
|
auto infoJSON = stmt.getStr(0);
|
||||||
auto storePath = store->parseStorePath(stmt.getStr(1));
|
auto storePath = store->parseStorePath(stmt.getStr(1));
|
||||||
auto immutable = stmt.getInt(2) != 0;
|
auto immutable = stmt.getInt(2) != 0;
|
||||||
auto timestamp = stmt.getInt(3);
|
auto timestamp = stmt.getInt(3);
|
||||||
|
@ -97,16 +97,16 @@ struct CacheImpl : Cache
|
||||||
store->addTempRoot(storePath);
|
store->addTempRoot(storePath);
|
||||||
if (!store->isValidPath(storePath)) {
|
if (!store->isValidPath(storePath)) {
|
||||||
// FIXME: we could try to substitute 'storePath'.
|
// FIXME: we could try to substitute 'storePath'.
|
||||||
debug("ignoring disappeared cache entry '%s'", inAttrsJson);
|
debug("ignoring disappeared cache entry '%s'", inAttrsJSON);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("using cache entry '%s' -> '%s', '%s'",
|
debug("using cache entry '%s' -> '%s', '%s'",
|
||||||
inAttrsJson, infoJson, store->printStorePath(storePath));
|
inAttrsJSON, infoJSON, store->printStorePath(storePath));
|
||||||
|
|
||||||
return Result {
|
return Result {
|
||||||
.expired = !immutable && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)),
|
.expired = !immutable && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)),
|
||||||
.infoAttrs = jsonToAttrs(nlohmann::json::parse(infoJson)),
|
.infoAttrs = jsonToAttrs(nlohmann::json::parse(infoJSON)),
|
||||||
.storePath = std::move(storePath)
|
.storePath = std::move(storePath)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ Input Input::fromAttrs(Attrs && attrs)
|
||||||
ParsedURL Input::toURL() const
|
ParsedURL Input::toURL() const
|
||||||
{
|
{
|
||||||
if (!scheme)
|
if (!scheme)
|
||||||
throw Error("cannot show unsupported input '%s'", attrsToJson(attrs));
|
throw Error("cannot show unsupported input '%s'", attrsToJSON(attrs));
|
||||||
return scheme->toURL(*this);
|
return scheme->toURL(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ bool Input::contains(const Input & other) const
|
||||||
std::pair<Tree, Input> Input::fetch(ref<Store> store) const
|
std::pair<Tree, Input> Input::fetch(ref<Store> store) const
|
||||||
{
|
{
|
||||||
if (!scheme)
|
if (!scheme)
|
||||||
throw Error("cannot fetch unsupported input '%s'", attrsToJson(toAttrs()));
|
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
|
||||||
|
|
||||||
/* The tree may already be in the Nix store, or it could be
|
/* The tree may already be in the Nix store, or it could be
|
||||||
substituted (which is often faster than fetching from the
|
substituted (which is often faster than fetching from the
|
||||||
|
@ -247,7 +247,7 @@ std::optional<time_t> Input::getLastModified() const
|
||||||
|
|
||||||
ParsedURL InputScheme::toURL(const Input & input)
|
ParsedURL InputScheme::toURL(const Input & input)
|
||||||
{
|
{
|
||||||
throw Error("don't know how to convert input '%s' to a URL", attrsToJson(input.attrs));
|
throw Error("don't know how to convert input '%s' to a URL", attrsToJSON(input.attrs));
|
||||||
}
|
}
|
||||||
|
|
||||||
Input InputScheme::applyOverrides(
|
Input InputScheme::applyOverrides(
|
||||||
|
|
|
@ -60,10 +60,10 @@ void Registry::write(const Path & path)
|
||||||
nlohmann::json arr;
|
nlohmann::json arr;
|
||||||
for (auto & entry : entries) {
|
for (auto & entry : entries) {
|
||||||
nlohmann::json obj;
|
nlohmann::json obj;
|
||||||
obj["from"] = attrsToJson(entry.from.toAttrs());
|
obj["from"] = attrsToJSON(entry.from.toAttrs());
|
||||||
obj["to"] = attrsToJson(entry.to.toAttrs());
|
obj["to"] = attrsToJSON(entry.to.toAttrs());
|
||||||
if (!entry.extraAttrs.empty())
|
if (!entry.extraAttrs.empty())
|
||||||
obj["to"].update(attrsToJson(entry.extraAttrs));
|
obj["to"].update(attrsToJSON(entry.extraAttrs));
|
||||||
if (entry.exact)
|
if (entry.exact)
|
||||||
obj["exact"] = true;
|
obj["exact"] = true;
|
||||||
arr.emplace_back(std::move(obj));
|
arr.emplace_back(std::move(obj));
|
||||||
|
|
|
@ -12,7 +12,7 @@ LogFormat parseLogFormat(const std::string & logFormatStr) {
|
||||||
else if (logFormatStr == "raw-with-logs")
|
else if (logFormatStr == "raw-with-logs")
|
||||||
return LogFormat::rawWithLogs;
|
return LogFormat::rawWithLogs;
|
||||||
else if (logFormatStr == "internal-json")
|
else if (logFormatStr == "internal-json")
|
||||||
return LogFormat::internalJson;
|
return LogFormat::internalJSON;
|
||||||
else if (logFormatStr == "bar")
|
else if (logFormatStr == "bar")
|
||||||
return LogFormat::bar;
|
return LogFormat::bar;
|
||||||
else if (logFormatStr == "bar-with-logs")
|
else if (logFormatStr == "bar-with-logs")
|
||||||
|
@ -26,7 +26,7 @@ Logger * makeDefaultLogger() {
|
||||||
return makeSimpleLogger(false);
|
return makeSimpleLogger(false);
|
||||||
case LogFormat::rawWithLogs:
|
case LogFormat::rawWithLogs:
|
||||||
return makeSimpleLogger(true);
|
return makeSimpleLogger(true);
|
||||||
case LogFormat::internalJson:
|
case LogFormat::internalJSON:
|
||||||
return makeJSONLogger(*makeSimpleLogger(true));
|
return makeJSONLogger(*makeSimpleLogger(true));
|
||||||
case LogFormat::bar:
|
case LogFormat::bar:
|
||||||
return makeProgressBar();
|
return makeProgressBar();
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace nix {
|
||||||
enum class LogFormat {
|
enum class LogFormat {
|
||||||
raw,
|
raw,
|
||||||
rawWithLogs,
|
rawWithLogs,
|
||||||
internalJson,
|
internalJSON,
|
||||||
bar,
|
bar,
|
||||||
barWithLogs,
|
barWithLogs,
|
||||||
};
|
};
|
||||||
|
|
|
@ -306,7 +306,7 @@ bool handleJSONLogMessage(const std::string & msg,
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
logError({
|
logError({
|
||||||
.name = "Json log message",
|
.name = "JSON log message",
|
||||||
.hint = hintfmt("bad log message from builder: %s", e.what())
|
.hint = hintfmt("bad log message from builder: %s", e.what())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,17 +76,17 @@ static void printFlakeInfo(const Store & store, const Flake & flake)
|
||||||
std::put_time(std::localtime(&*lastModified), "%F %T"));
|
std::put_time(std::localtime(&*lastModified), "%F %T"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
|
static nlohmann::json flakeToJSON(const Store & store, const Flake & flake)
|
||||||
{
|
{
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
if (flake.description)
|
if (flake.description)
|
||||||
j["description"] = *flake.description;
|
j["description"] = *flake.description;
|
||||||
j["originalUrl"] = flake.originalRef.to_string();
|
j["originalUrl"] = flake.originalRef.to_string();
|
||||||
j["original"] = fetchers::attrsToJson(flake.originalRef.toAttrs());
|
j["original"] = fetchers::attrsToJSON(flake.originalRef.toAttrs());
|
||||||
j["resolvedUrl"] = flake.resolvedRef.to_string();
|
j["resolvedUrl"] = flake.resolvedRef.to_string();
|
||||||
j["resolved"] = fetchers::attrsToJson(flake.resolvedRef.toAttrs());
|
j["resolved"] = fetchers::attrsToJSON(flake.resolvedRef.toAttrs());
|
||||||
j["url"] = flake.lockedRef.to_string(); // FIXME: rename to lockedUrl
|
j["url"] = flake.lockedRef.to_string(); // FIXME: rename to lockedUrl
|
||||||
j["locked"] = fetchers::attrsToJson(flake.lockedRef.toAttrs());
|
j["locked"] = fetchers::attrsToJSON(flake.lockedRef.toAttrs());
|
||||||
if (auto rev = flake.lockedRef.input.getRev())
|
if (auto rev = flake.lockedRef.input.getRev())
|
||||||
j["revision"] = rev->to_string(Base16, false);
|
j["revision"] = rev->to_string(Base16, false);
|
||||||
if (auto revCount = flake.lockedRef.input.getRevCount())
|
if (auto revCount = flake.lockedRef.input.getRevCount())
|
||||||
|
@ -139,7 +139,7 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON
|
||||||
auto flake = getFlake();
|
auto flake = getFlake();
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
auto json = flakeToJson(*store, flake);
|
auto json = flakeToJSON(*store, flake);
|
||||||
logger->cout("%s", json.dump());
|
logger->cout("%s", json.dump());
|
||||||
} else
|
} else
|
||||||
printFlakeInfo(*store, flake);
|
printFlakeInfo(*store, flake);
|
||||||
|
@ -158,7 +158,7 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON
|
||||||
auto flake = lockFlake();
|
auto flake = lockFlake();
|
||||||
|
|
||||||
if (json)
|
if (json)
|
||||||
logger->cout("%s", flake.lockFile.toJson());
|
logger->cout("%s", flake.lockFile.toJSON());
|
||||||
else {
|
else {
|
||||||
logger->cout("%s", flake.flake.lockedRef);
|
logger->cout("%s", flake.flake.lockedRef);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue