1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-30 14:10:59 +01:00

Apply clang-format universally.

* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
This commit is contained in:
Graham Christensen 2025-07-18 12:47:27 -04:00
parent 41bf87ec70
commit e4f62e4608
587 changed files with 23258 additions and 23135 deletions

View file

@ -14,7 +14,7 @@ std::optional<StructuredAttrs> StructuredAttrs::tryParse(const StringPairs & env
auto jsonAttr = env.find("__json");
if (jsonAttr != env.end()) {
try {
return StructuredAttrs {
return StructuredAttrs{
.structuredAttrs = nlohmann::json::parse(jsonAttr->second),
};
} catch (std::exception & e) {
@ -36,9 +36,7 @@ static std::regex shVarName("[A-Za-z_][A-Za-z0-9_]*");
* mechanism to allow this to evolve again and get back in sync, but for
* now we must not change - not even extend - the behavior.
*/
static nlohmann::json pathInfoToJSON(
Store & store,
const StorePathSet & storePaths)
static nlohmann::json pathInfoToJSON(Store & store, const StorePathSet & storePaths)
{
using nlohmann::json;
@ -100,8 +98,7 @@ nlohmann::json StructuredAttrs::prepareStructuredAttrs(
StorePathSet storePaths;
for (auto & p : inputPaths)
storePaths.insert(store.toStorePath(p).first);
json[key] = pathInfoToJSON(store,
store.exportReferences(storePaths, storePaths));
json[key] = pathInfoToJSON(store, store.exportReferences(storePaths, storePaths));
}
return json;
@ -133,7 +130,8 @@ std::string StructuredAttrs::writeShell(const nlohmann::json & json)
for (auto & [key, value] : json.items()) {
if (!std::regex_match(key, shVarName)) continue;
if (!std::regex_match(key, shVarName))
continue;
auto s = handleSimpleType(value);
if (s)
@ -145,8 +143,12 @@ std::string StructuredAttrs::writeShell(const nlohmann::json & json)
for (auto & value2 : value) {
auto s3 = handleSimpleType(value2);
if (!s3) { good = false; break; }
s2 += *s3; s2 += ' ';
if (!s3) {
good = false;
break;
}
s2 += *s3;
s2 += ' ';
}
if (good)
@ -159,7 +161,10 @@ std::string StructuredAttrs::writeShell(const nlohmann::json & json)
for (auto & [key2, value2] : value.items()) {
auto s3 = handleSimpleType(value2);
if (!s3) { good = false; break; }
if (!s3) {
good = false;
break;
}
s2 += fmt("[%s]=%s ", escapeShellArgAlways(key2), *s3);
}
@ -170,4 +175,4 @@ std::string StructuredAttrs::writeShell(const nlohmann::json & json)
return jsonSh;
}
}
} // namespace nix