diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-20T21·27+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-20T21·27+0100 |
commit | 689ef502f5b0655c9923ed77da2ae3504630f473 (patch) | |
tree | 3e331c153646f136875f047cc3b9f0aad8c86341 /third_party/nix/src/nix | |
parent | d331d3a0b5c497a46e2636f308234be66566c04c (diff) |
refactor(3p/nix): Apply clang-tidy's readability-* fixes r/788
This applies the readability fixes listed here: https://clang.llvm.org/extra/clang-tidy/checks/list.html
Diffstat (limited to 'third_party/nix/src/nix')
-rw-r--r-- | third_party/nix/src/nix/build.cc | 4 | ||||
-rw-r--r-- | third_party/nix/src/nix/command.cc | 5 | ||||
-rw-r--r-- | third_party/nix/src/nix/doctor.cc | 8 | ||||
-rw-r--r-- | third_party/nix/src/nix/installables.cc | 17 | ||||
-rw-r--r-- | third_party/nix/src/nix/log.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/nix/main.cc | 6 | ||||
-rw-r--r-- | third_party/nix/src/nix/path-info.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/nix/repl.cc | 60 | ||||
-rw-r--r-- | third_party/nix/src/nix/run.cc | 8 | ||||
-rw-r--r-- | third_party/nix/src/nix/search.cc | 15 | ||||
-rw-r--r-- | third_party/nix/src/nix/show-derivation.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/nix/sigs.cc | 4 | ||||
-rw-r--r-- | third_party/nix/src/nix/upgrade-nix.cc | 6 | ||||
-rw-r--r-- | third_party/nix/src/nix/verify.cc | 7 | ||||
-rw-r--r-- | third_party/nix/src/nix/why-depends.cc | 6 |
15 files changed, 79 insertions, 73 deletions
diff --git a/third_party/nix/src/nix/build.cc b/third_party/nix/src/nix/build.cc index 0738821a8938..9ab2d27e0fc9 100644 --- a/third_party/nix/src/nix/build.cc +++ b/third_party/nix/src/nix/build.cc @@ -47,11 +47,11 @@ struct CmdBuild : MixDryRun, InstallablesCommand { for (size_t i = 0; i < buildables.size(); ++i) { auto& b(buildables[i]); - if (outLink != "") { + if (!outLink.empty()) { for (auto& output : b.outputs) { if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) { std::string symlink = outLink; - if (i) { + if (i != 0u) { symlink += fmt("-%d", i); } if (output.first != "out") { diff --git a/third_party/nix/src/nix/command.cc b/third_party/nix/src/nix/command.cc index b0efcb823dd6..439f22dc3b67 100644 --- a/third_party/nix/src/nix/command.cc +++ b/third_party/nix/src/nix/command.cc @@ -80,9 +80,8 @@ bool MultiCommand::processFlag(Strings::iterator& pos, Strings::iterator end) { bool MultiCommand::processArgs(const Strings& args, bool finish) { if (command) { return command->processArgs(args, finish); - } else { - return Args::processArgs(args, finish); } + return Args::processArgs(args, finish); } StoreCommand::StoreCommand() = default; @@ -119,7 +118,7 @@ void StorePathsCommand::run(ref<Store> store) { Paths storePaths; if (all) { - if (installables.size()) { + if (!installables.empty() != 0u) { throw UsageError("'--all' does not expect arguments"); } for (auto& p : store->queryAllValidPaths()) { diff --git a/third_party/nix/src/nix/doctor.cc b/third_party/nix/src/nix/doctor.cc index 44ce2d92921d..95bf8a922e26 100644 --- a/third_party/nix/src/nix/doctor.cc +++ b/third_party/nix/src/nix/doctor.cc @@ -7,7 +7,7 @@ using namespace nix; std::string formatProtocol(unsigned int proto) { - if (proto) { + if (proto != 0u) { auto major = GET_PROTOCOL_MAJOR(proto) >> 8; auto minor = GET_PROTOCOL_MINOR(proto); return (format("%1%.%2%") % major % minor).str(); @@ -41,7 +41,7 @@ struct CmdDoctor : StoreCommand { } } - bool checkNixInPath() { + static bool checkNixInPath() { PathSet dirs; for (auto& dir : tokenizeString<Strings>(getEnv("PATH"), ":")) { @@ -64,7 +64,7 @@ struct CmdDoctor : StoreCommand { return true; } - bool checkProfileRoots(ref<Store> store) { + static bool checkProfileRoots(ref<Store> store) { PathSet dirs; for (auto& dir : tokenizeString<Strings>(getEnv("PATH"), ":")) { @@ -106,7 +106,7 @@ struct CmdDoctor : StoreCommand { return true; } - bool checkStoreProtocol(unsigned int storeProto) { + static bool checkStoreProtocol(unsigned int storeProto) { unsigned int clientProto = GET_PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == GET_PROTOCOL_MAJOR(storeProto) ? SERVE_PROTOCOL_VERSION diff --git a/third_party/nix/src/nix/installables.cc b/third_party/nix/src/nix/installables.cc index 06419f1f122d..f6cba6d3b636 100644 --- a/third_party/nix/src/nix/installables.cc +++ b/third_party/nix/src/nix/installables.cc @@ -23,7 +23,7 @@ SourceExprCommand::SourceExprCommand() { } Value* SourceExprCommand::getSourceExpr(EvalState& state) { - if (vSourceExpr) { + if (vSourceExpr != nullptr) { return vSourceExpr; } @@ -31,7 +31,7 @@ Value* SourceExprCommand::getSourceExpr(EvalState& state) { vSourceExpr = state.allocValue(); - if (file != "") { + if (!file.empty()) { state.evalFile(lookupFileArg(state, file), *vSourceExpr); } else { @@ -46,7 +46,7 @@ Value* SourceExprCommand::getSourceExpr(EvalState& state) { std::unordered_set<std::string> seen; auto addEntry = [&](const std::string& name) { - if (name == "") { + if (name.empty()) { return; } if (!seen.insert(name).second) { @@ -135,7 +135,7 @@ struct InstallableValue : Installable { drvPaths.insert(b.drvPath); auto outputName = drv.queryOutputName(); - if (outputName == "") { + if (outputName.empty()) { throw Error("derivation '%s' lacks an 'outputName' attribute", b.drvPath); } @@ -153,9 +153,8 @@ struct InstallableValue : Installable { b.outputs.insert(b2.outputs.begin(), b2.outputs.end()); } return {b}; - } else { - return res; } + return res; } }; @@ -204,7 +203,7 @@ static std::vector<std::shared_ptr<Installable>> parseInstallables( std::vector<std::shared_ptr<Installable>> result; if (ss.empty() && useDefaultInstallables) { - if (cmd.file == "") { + if (cmd.file.empty()) { cmd.file = "."; } ss = {""}; @@ -222,7 +221,7 @@ static std::vector<std::shared_ptr<Installable>> parseInstallables( } } - else if (s == "" || std::regex_match(s, attrPathRegex)) { + else if (s.empty() || std::regex_match(s, attrPathRegex)) { result.push_back(std::make_shared<InstallableAttrPath>(cmd, s)); } else { @@ -254,7 +253,7 @@ Buildables build(ref<Store> store, RealiseMode mode, for (auto& i : installables) { for (auto& b : i->toBuildables()) { - if (b.drvPath != "") { + if (!b.drvPath.empty()) { StringSet outputNames; for (auto& output : b.outputs) { outputNames.insert(output.first); diff --git a/third_party/nix/src/nix/log.cc b/third_party/nix/src/nix/log.cc index 86f133e94a7a..63d3554cc2fb 100644 --- a/third_party/nix/src/nix/log.cc +++ b/third_party/nix/src/nix/log.cc @@ -40,7 +40,7 @@ struct CmdLog : InstallableCommand { RunPager pager; for (auto& sub : subs) { - auto log = b.drvPath != "" ? sub->getBuildLog(b.drvPath) : nullptr; + auto log = !b.drvPath.empty() ? sub->getBuildLog(b.drvPath) : nullptr; for (auto& output : b.outputs) { if (log) { break; diff --git a/third_party/nix/src/nix/main.cc b/third_party/nix/src/nix/main.cc index 54285bfa9313..11ba3f8410c4 100644 --- a/third_party/nix/src/nix/main.cc +++ b/third_party/nix/src/nix/main.cc @@ -27,14 +27,14 @@ namespace nix { static bool haveInternet() { struct ifaddrs* addrs; - if (getifaddrs(&addrs)) { + if (getifaddrs(&addrs) != 0) { return true; } Finally free([&]() { freeifaddrs(addrs); }); - for (auto i = addrs; i; i = i->ifa_next) { - if (!i->ifa_addr) { + for (auto i = addrs; i != nullptr; i = i->ifa_next) { + if (i->ifa_addr == nullptr) { continue; } if (i->ifa_addr->sa_family == AF_INET) { diff --git a/third_party/nix/src/nix/path-info.cc b/third_party/nix/src/nix/path-info.cc index b871c45f1c16..e94dcc962831 100644 --- a/third_party/nix/src/nix/path-info.cc +++ b/third_party/nix/src/nix/path-info.cc @@ -113,7 +113,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON { if (info->ultimate) { ss.push_back("ultimate"); } - if (info->ca != "") { + if (!info->ca.empty()) { ss.push_back("ca:" + info->ca); } for (auto& sig : info->sigs) { diff --git a/third_party/nix/src/nix/repl.cc b/third_party/nix/src/nix/repl.cc index 9567ad4315db..81e940dd3aaf 100644 --- a/third_party/nix/src/nix/repl.cc +++ b/third_party/nix/src/nix/repl.cc @@ -62,7 +62,7 @@ struct NixRepl { ~NixRepl(); void mainLoop(const std::vector<std::string>& files); StringSet completePrefix(string prefix); - bool getLine(string& input, const std::string& prompt); + static bool getLine(string& input, const std::string& prompt); Path getDerivationPath(Value& v); bool processLine(string line); void loadFile(const Path& path); @@ -145,11 +145,12 @@ static char* completionCallback(char* s, int* match) { if (possible.size() == 1) { *match = 1; auto* res = strdup(possible.begin()->c_str() + strlen(s)); - if (!res) { + if (res == nullptr) { throw Error("allocation failure"); } return res; - } else if (possible.size() > 1) { + } + if (possible.size() > 1) { auto checkAllHaveSameAt = [&](size_t pos) { auto& first = *possible.begin(); for (auto& p : possible) { @@ -167,7 +168,7 @@ static char* completionCallback(char* s, int* match) { if (len > 0) { *match = 1; auto* res = strdup(std::string(*possible.begin(), start, len).c_str()); - if (!res) { + if (res == nullptr) { throw Error("allocation failure"); } return res; @@ -266,10 +267,9 @@ void NixRepl::mainLoop(const std::vector<std::string>& files) { // For parse errors on incomplete input, we continue waiting for the // next line of input without clearing the input so far. continue; - } else { - LOG(ERROR) << error << (settings.showTrace ? e.prefix() : "") - << e.msg(); } + LOG(ERROR) << error << (settings.showTrace ? e.prefix() : "") << e.msg(); + } catch (Error& e) { LOG(ERROR) << error << (settings.showTrace ? e.prefix() : "") << e.msg(); } catch (Interrupted& e) { @@ -284,29 +284,31 @@ void NixRepl::mainLoop(const std::vector<std::string>& files) { } bool NixRepl::getLine(string& input, const std::string& prompt) { - struct sigaction act, old; - sigset_t savedSignalMask, set; + struct sigaction act; + struct sigaction old; + sigset_t savedSignalMask; + sigset_t set; auto setupSignals = [&]() { act.sa_handler = sigintHandler; sigfillset(&act.sa_mask); act.sa_flags = 0; - if (sigaction(SIGINT, &act, &old)) { + if (sigaction(SIGINT, &act, &old) != 0) { throw SysError("installing handler for SIGINT"); } sigemptyset(&set); sigaddset(&set, SIGINT); - if (sigprocmask(SIG_UNBLOCK, &set, &savedSignalMask)) { + if (sigprocmask(SIG_UNBLOCK, &set, &savedSignalMask) != 0) { throw SysError("unblocking SIGINT"); } }; auto restoreSignals = [&]() { - if (sigprocmask(SIG_SETMASK, &savedSignalMask, nullptr)) { + if (sigprocmask(SIG_SETMASK, &savedSignalMask, nullptr) != 0) { throw SysError("restoring signals"); } - if (sigaction(SIGINT, &old, nullptr)) { + if (sigaction(SIGINT, &old, nullptr) != 0) { throw SysError("restoring handler for SIGINT"); } }; @@ -316,13 +318,13 @@ bool NixRepl::getLine(string& input, const std::string& prompt) { Finally doFree([&]() { free(s); }); restoreSignals(); - if (g_signal_received) { + if (g_signal_received != 0) { g_signal_received = 0; input.clear(); return true; } - if (!s) { + if (s == nullptr) { return false; } input += s; @@ -334,7 +336,8 @@ StringSet NixRepl::completePrefix(string prefix) { StringSet completions; size_t start = prefix.find_last_of(" \n\r\t(){}[]"); - std::string prev, cur; + std::string prev; + std::string cur; if (start == std::string::npos) { prev = ""; cur = prefix; @@ -343,13 +346,14 @@ StringSet NixRepl::completePrefix(string prefix) { cur = std::string(prefix, start + 1); } - size_t slash, dot; + size_t slash; + size_t dot; if ((slash = cur.rfind('/')) != string::npos) { try { auto dir = std::string(cur, 0, slash); auto prefix2 = std::string(cur, slash + 1); - for (auto& entry : readDirectory(dir == "" ? "/" : dir)) { + for (auto& entry : readDirectory(dir.empty() ? "/" : dir)) { if (entry.name[0] != '.' && hasPrefix(entry.name, prefix2)) { completions.insert(prev + dir + "/" + entry.name); } @@ -418,7 +422,7 @@ static int runProgram(const string& program, const Strings& args) { } bool isVarName(const string& s) { - if (s.size() == 0) { + if (s.empty()) { return false; } char c = s[0]; @@ -441,18 +445,19 @@ Path NixRepl::getDerivationPath(Value& v) { "expression does not evaluate to a derivation, so I can't build it"); } Path drvPath = drvInfo->queryDrvPath(); - if (drvPath == "" || !state.store->isValidPath(drvPath)) { + if (drvPath.empty() || !state.store->isValidPath(drvPath)) { throw Error("expression did not evaluate to a valid derivation"); } return drvPath; } bool NixRepl::processLine(string line) { - if (line == "") { + if (line.empty()) { return true; } - string command, arg; + string command; + string arg; if (line[0] == ':') { size_t p = line.find_first_of(" \n\r\t"); @@ -505,7 +510,9 @@ bool NixRepl::processLine(string line) { std::cout << showType(v) << std::endl; } else if (command == ":u") { - Value v, f, result; + Value v; + Value f; + Value result; evalString(arg, v); evalString( "drv: (import <nixpkgs> {}).runCommand \"shell\" { buildInputs = [ drv " @@ -553,7 +560,7 @@ bool NixRepl::processLine(string line) { else if (command == ":q" || command == ":quit") { return false; - } else if (command != "") { + } else if (!command.empty()) { throw Error(format("unknown command '%1%'") % command); } else { @@ -580,7 +587,8 @@ bool NixRepl::processLine(string line) { void NixRepl::loadFile(const Path& path) { loadedFiles.remove(path); loadedFiles.push_back(path); - Value v, v2; + Value v; + Value v2; state.evalFile(lookupFileArg(state, path), v); state.autoCallFunction(*autoArgs, v, v2); addAttrsToScope(v2); @@ -652,7 +660,7 @@ std::ostream& NixRepl::printValue(std::ostream& str, Value& v, std::ostream& printStringValue(std::ostream& str, const char* string) { str << "\""; - for (const char* i = string; *i; i++) { + for (const char* i = string; *i != 0; i++) { if (*i == '\"' || *i == '\\') { str << "\\" << *i; } else if (*i == '\n') { diff --git a/third_party/nix/src/nix/run.cc b/third_party/nix/src/nix/run.cc index 5459c38952d4..9827360f0aa9 100644 --- a/third_party/nix/src/nix/run.cc +++ b/third_party/nix/src/nix/run.cc @@ -96,7 +96,7 @@ struct CmdRun : InstallablesCommand { std::map<std::string, std::string> kept; for (auto& var : keep) { auto s = getenv(var.c_str()); - if (s) { + if (s != nullptr) { kept[var] = s; } } @@ -133,9 +133,7 @@ struct CmdRun : InstallablesCommand { continue; } - if (true) { - unixPath.push_front(path + "/bin"); - } + { unixPath.push_front(path + "/bin"); } auto propPath = path + "/nix-support/propagated-user-env-packages"; if (accessor->stat(propPath).type == FSAccessor::tRegular) { @@ -249,7 +247,7 @@ void chrootHelper(int argc, char** argv) { } char* cwd = getcwd(nullptr, 0); - if (!cwd) { + if (cwd == nullptr) { throw SysError("getting current directory"); } Finally freeCwd([&]() { free(cwd); }); diff --git a/third_party/nix/src/nix/search.cc b/third_party/nix/src/nix/search.cc index 78a1f21bc1e2..5f6def220291 100644 --- a/third_party/nix/src/nix/search.cc +++ b/third_party/nix/src/nix/search.cc @@ -160,11 +160,11 @@ struct CmdSearch : SourceExprCommand, MixJSON { } } - if (cache) { + if (cache != nullptr) { cache->attr("type", "derivation"); cache->attr("name", drv.queryName()); cache->attr("system", drv.querySystem()); - if (description != "") { + if (!description.empty()) { auto meta(cache->object("meta")); meta.attr("description", description); } @@ -190,11 +190,12 @@ struct CmdSearch : SourceExprCommand, MixJSON { for (auto& i : *v->attrs) { auto cache2 = - cache ? std::make_unique<JSONObject>(cache->object(i.name)) - : nullptr; + cache != nullptr + ? std::make_unique<JSONObject>(cache->object(i.name)) + : nullptr; doExpr(i.value, - attrPath == "" ? (std::string)i.name - : attrPath + "." + (std::string)i.name, + attrPath.empty() ? (std::string)i.name + : attrPath + "." + (std::string)i.name, toplevel2 || fromCache, cache2 ? cache2.get() : nullptr); } } @@ -256,7 +257,7 @@ struct CmdSearch : SourceExprCommand, MixJSON { } } - if (results.size() == 0) { + if (results.empty()) { throw Error("no results for the given search term(s)!"); } diff --git a/third_party/nix/src/nix/show-derivation.cc b/third_party/nix/src/nix/show-derivation.cc index 4a604c2c224c..b821a9ee1205 100644 --- a/third_party/nix/src/nix/show-derivation.cc +++ b/third_party/nix/src/nix/show-derivation.cc @@ -63,7 +63,7 @@ struct CmdShowDerivation : InstallablesCommand { for (auto& output : drv.outputs) { auto outputObj(outputsObj.object(output.first)); outputObj.attr("path", output.second.path); - if (output.second.hash != "") { + if (!output.second.hash.empty()) { outputObj.attr("hashAlgo", output.second.hashAlgo); outputObj.attr("hash", output.second.hash); } diff --git a/third_party/nix/src/nix/sigs.cc b/third_party/nix/src/nix/sigs.cc index eb99fc8ee581..420296a8023f 100644 --- a/third_party/nix/src/nix/sigs.cc +++ b/third_party/nix/src/nix/sigs.cc @@ -71,7 +71,7 @@ struct CmdCopySigs : StorePathsCommand { } for (auto& sig : info2->sigs) { - if (!info->sigs.count(sig)) { + if (info->sigs.count(sig) == 0u) { newSigs.insert(sig); } } @@ -132,7 +132,7 @@ struct CmdSignPaths : StorePathsCommand { info2.sign(secretKey); assert(!info2.sigs.empty()); - if (!info->sigs.count(*info2.sigs.begin())) { + if (info->sigs.count(*info2.sigs.begin()) == 0u) { store->addSignatures(storePath, info2.sigs); added++; } diff --git a/third_party/nix/src/nix/upgrade-nix.cc b/third_party/nix/src/nix/upgrade-nix.cc index dd11da0087c7..b225aac2d725 100644 --- a/third_party/nix/src/nix/upgrade-nix.cc +++ b/third_party/nix/src/nix/upgrade-nix.cc @@ -52,7 +52,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand { void run(ref<Store> store) override { evalSettings.pureEval = true; - if (profileDir == "") { + if (profileDir.empty()) { profileDir = getProfileDir(store); } @@ -97,7 +97,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand { } /* Return the profile in which Nix is installed. */ - Path getProfileDir(ref<Store> store) { + static Path getProfileDir(ref<Store> store) { Path where; for (auto& dir : tokenizeString<Strings>(getEnv("PATH"), ":")) { @@ -107,7 +107,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand { } } - if (where == "") { + if (where.empty()) { throw Error( "couldn't figure out how Nix is installed, so I can't upgrade it"); } diff --git a/third_party/nix/src/nix/verify.cc b/third_party/nix/src/nix/verify.cc index 6b74761ba75a..63dd181e074c 100644 --- a/third_party/nix/src/nix/verify.cc +++ b/third_party/nix/src/nix/verify.cc @@ -94,7 +94,7 @@ struct CmdVerify : StorePathsCommand { if (!noTrust) { bool good = false; - if (info->ultimate && !sigsNeeded) { + if (info->ultimate && (sigsNeeded == 0u)) { good = true; } else { @@ -104,7 +104,7 @@ struct CmdVerify : StorePathsCommand { auto doSigs = [&](StringSet sigs) { for (auto sig : sigs) { - if (sigsSeen.count(sig)) { + if (sigsSeen.count(sig) != 0u) { continue; } sigsSeen.insert(sig); @@ -162,7 +162,8 @@ struct CmdVerify : StorePathsCommand { pool.process(); - throw Exit((corrupted ? 1 : 0) | (untrusted ? 2 : 0) | (failed ? 4 : 0)); + throw Exit((corrupted != 0u ? 1 : 0) | (untrusted != 0u ? 2 : 0) | + (failed != 0u ? 4 : 0)); } }; diff --git a/third_party/nix/src/nix/why-depends.cc b/third_party/nix/src/nix/why-depends.cc index baf27a69514a..bbbfd1fe0182 100644 --- a/third_party/nix/src/nix/why-depends.cc +++ b/third_party/nix/src/nix/why-depends.cc @@ -18,7 +18,7 @@ static std::string hilite(const std::string& s, size_t pos, size_t len, static std::string filterPrintable(const std::string& s) { std::string res; for (char c : s) { - res += isprint(c) ? c : '.'; + res += isprint(c) != 0 ? c : '.'; } return res; } @@ -70,7 +70,7 @@ struct CmdWhyDepends : SourceExprCommand { PathSet closure; store->computeFSClosure({packagePath}, closure, false, false); - if (!closure.count(dependencyPath)) { + if (closure.count(dependencyPath) == 0u) { LOG(WARNING) << "'" << package->what() << "' does not depend on '" << dependency->what() << "'"; return; @@ -146,7 +146,7 @@ struct CmdWhyDepends : SourceExprCommand { assert(node.dist != inf); std::cout << fmt("%s%s%s%s" ANSI_NORMAL "\n", firstPad, node.visited ? "\e[38;5;244m" : "", - firstPad != "" ? "=> " : "", node.path); + !firstPad.empty() ? "=> " : "", node.path); if (node.path == dependencyPath && !all && packagePath != dependencyPath) { |