From 689ef502f5b0655c9923ed77da2ae3504630f473 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 20 May 2020 22:27:37 +0100 Subject: refactor(3p/nix): Apply clang-tidy's readability-* fixes This applies the readability fixes listed here: https://clang.llvm.org/extra/clang-tidy/checks/list.html --- third_party/nix/src/nix-store/graphml.cc | 2 +- third_party/nix/src/nix-store/nix-store.cc | 80 ++++++++++++++++-------------- 2 files changed, 44 insertions(+), 38 deletions(-) (limited to 'third_party/nix/src/nix-store') diff --git a/third_party/nix/src/nix-store/graphml.cc b/third_party/nix/src/nix-store/graphml.cc index 07116cda93..6510b32881 100644 --- a/third_party/nix/src/nix-store/graphml.cc +++ b/third_party/nix/src/nix-store/graphml.cc @@ -58,7 +58,7 @@ void printGraphML(ref store, const PathSet& roots) { workList.erase(path); ret = doneSet.insert(path); - if (ret.second == false) { + if (!ret.second) { continue; } diff --git a/third_party/nix/src/nix-store/nix-store.cc b/third_party/nix/src/nix-store/nix-store.cc index c6028ea3e7..802ebd4207 100644 --- a/third_party/nix/src/nix-store/nix-store.cc +++ b/third_party/nix/src/nix-store/nix-store.cc @@ -49,7 +49,7 @@ static Path useDeriver(Path path) { return path; } Path drvPath = store->queryPathInfo(path)->deriver; - if (drvPath == "") { + if (drvPath.empty()) { throw Error(format("deriver of path '%1%' is not known") % path); } return drvPath; @@ -85,7 +85,7 @@ static PathSet realisePath(Path path, bool build = true) { } Path outPath = i->second.path; if (store2) { - if (gcRoot == "") { + if (gcRoot.empty()) { printGCWarning(); } else { Path rootName = gcRoot; @@ -103,27 +103,25 @@ static PathSet realisePath(Path path, bool build = true) { return outputs; } - else { - if (build) { - store->ensurePath(path); - } else if (!store->isValidPath(path)) { - throw Error(format("path '%1%' does not exist and cannot be created") % - path); - } - if (store2) { - if (gcRoot == "") { - printGCWarning(); - } else { - Path rootName = gcRoot; - rootNr++; - if (rootNr > 1) { - rootName += "-" + std::to_string(rootNr); - } - path = store2->addPermRoot(path, rootName, indirectRoot); + if (build) { + store->ensurePath(path); + } else if (!store->isValidPath(path)) { + throw Error(format("path '%1%' does not exist and cannot be created") % + path); + } + if (store2) { + if (gcRoot.empty()) { + printGCWarning(); + } else { + Path rootName = gcRoot; + rootNr++; + if (rootNr > 1) { + rootName += "-" + std::to_string(rootNr); } + path = store2->addPermRoot(path, rootName, indirectRoot); } - return {path}; } + return {path}; } /* Realise the given paths. */ @@ -153,8 +151,11 @@ static void opRealise(Strings opFlags, Strings opArgs) { store->followLinksToStorePath(p.first), p.second)); } - unsigned long long downloadSize, narSize; - PathSet willBuild, willSubstitute, unknown; + unsigned long long downloadSize; + unsigned long long narSize; + PathSet willBuild; + PathSet willSubstitute; + PathSet unknown; store->queryMissing(PathSet(paths.begin(), paths.end()), willBuild, willSubstitute, unknown, downloadSize, narSize); @@ -267,9 +268,8 @@ static PathSet maybeUseOutputs(const Path& storePath, bool useOutput, outputs.insert(i.second.path); } return outputs; - } else { - return {storePath}; } + return {storePath}; } /* Some code to print a tree representation of a derivation dependency @@ -348,7 +348,7 @@ static void opQuery(Strings opFlags, Strings opArgs) { } else if (i == "--deriver" || i == "-d") { query = qDeriver; } else if (i == "--binding" || i == "-b") { - if (opArgs.size() == 0) { + if (opArgs.empty()) { throw UsageError("expected binding name"); } bindingName = opArgs.front(); @@ -437,7 +437,8 @@ static void opQuery(Strings opFlags, Strings opArgs) { for (auto& i : opArgs) { Path deriver = store->queryPathInfo(store->followLinksToStorePath(i))->deriver; - cout << format("%1%\n") % (deriver == "" ? "unknown-deriver" : deriver); + cout << format("%1%\n") % + (deriver.empty() ? "unknown-deriver" : deriver); } break; @@ -608,7 +609,7 @@ static void registerValidity(bool reregister, bool hashGiven, while (true) { ValidPathInfo info = decodeValidPathInfo(cin, hashGiven); - if (info.path == "") { + if (info.path.empty()) { break; } if (!store->isValidPath(info.path) || reregister) { @@ -947,7 +948,7 @@ static void opServe(Strings opFlags, Strings opArgs) { } if (GET_PROTOCOL_MINOR(clientVersion) >= 3) { settings.buildRepeat = readInt(in); - settings.enforceDeterminism = readInt(in); + settings.enforceDeterminism = readInt(in) != 0u; settings.runDiffHook = true; } settings.printRepeatedBuilds = false; @@ -963,8 +964,8 @@ static void opServe(Strings opFlags, Strings opArgs) { switch (cmd) { case cmdQueryValidPaths: { - bool lock = readInt(in); - bool substitute = readInt(in); + bool lock = readInt(in) != 0u; + bool substitute = readInt(in) != 0u; auto paths = readStorePaths(*store, in); if (lock && writeAllowed) { for (auto& path : paths) { @@ -983,8 +984,11 @@ static void opServe(Strings opFlags, Strings opArgs) { paths2.insert(path); } } - unsigned long long downloadSize, narSize; - PathSet willBuild, willSubstitute, unknown; + unsigned long long downloadSize; + unsigned long long narSize; + PathSet willBuild; + PathSet willSubstitute; + PathSet unknown; store->queryMissing(PathSet(paths2.begin(), paths2.end()), willBuild, willSubstitute, unknown, downloadSize, narSize); /* FIXME: should use ensurePath(), but it only @@ -1080,7 +1084,8 @@ static void opServe(Strings opFlags, Strings opArgs) { out << status.status << status.errorMsg; if (GET_PROTOCOL_MINOR(clientVersion) >= 3) { - out << status.timesBuilt << status.isNonDeterministic + out << status.timesBuilt + << static_cast(status.isNonDeterministic) << status.startTime << status.stopTime; } @@ -1088,7 +1093,7 @@ static void opServe(Strings opFlags, Strings opArgs) { } case cmdQueryClosure: { - bool includeOutputs = readInt(in); + bool includeOutputs = readInt(in) != 0u; PathSet closure; store->computeFSClosure(readStorePaths(*store, in), closure, false, includeOutputs); @@ -1184,7 +1189,8 @@ static void opVersion(Strings opFlags, Strings opArgs) { list. */ static int _main(int argc, char** argv) { { - Strings opFlags, opArgs; + Strings opFlags; + Strings opArgs; Operation op = nullptr; parseCmdLine(argc, argv, @@ -1260,7 +1266,7 @@ static int _main(int argc, char** argv) { opArgs.push_back(*arg); } - if (oldOp && oldOp != op) { + if ((oldOp != nullptr) && oldOp != op) { throw UsageError("only one operation may be specified"); } @@ -1269,7 +1275,7 @@ static int _main(int argc, char** argv) { initPlugins(); - if (!op) { + if (op == nullptr) { throw UsageError("no operation specified"); } -- cgit 1.4.1