diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-19T21·02+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-19T21·02+0100 |
commit | 88f337588c9f1a41ac67b3afb8d43f124b4d153b (patch) | |
tree | 1e7ee739c979f5a54a1c23fcb1a6adf49652a7e5 /third_party/nix | |
parent | 39087321811e81e26a1a47d6967df1088dcf0e95 (diff) |
refactor(3p/nix): Make all single-argument constructors explicit r/778
Implicit constructors can be confusing, especially in a codebase that is already as unintentionally obfuscated as this one. https://google.github.io/styleguide/cppguide.html#Explicit_Constructors
Diffstat (limited to 'third_party/nix')
-rw-r--r-- | third_party/nix/src/libstore/build.cc | 22 | ||||
-rw-r--r-- | third_party/nix/src/libstore/export-import.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libstore/gc.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libstore/local-fs-store.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libstore/misc.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libstore/nar-accessor.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libstore/optimise-store.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libstore/remote-store.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libutil/compression.cc | 12 | ||||
-rw-r--r-- | third_party/nix/src/nix-daemon/nix-daemon.cc | 6 | ||||
-rw-r--r-- | third_party/nix/src/nix/hash.cc | 4 | ||||
-rw-r--r-- | third_party/nix/src/nix/installables.cc | 4 |
12 files changed, 31 insertions, 31 deletions
diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc index b1f63a4fac76..3349e1e8c8e9 100644 --- a/third_party/nix/src/libstore/build.cc +++ b/third_party/nix/src/libstore/build.cc @@ -133,7 +133,7 @@ class Goal : public std::enable_shared_from_this<Goal> { /* Whether the goal is finished. */ ExitCode exitCode; - Goal(Worker& worker) : worker(worker) { + explicit Goal(Worker& worker) : worker(worker) { nrFailed = nrNoSubstituters = nrIncompleteClosure = 0; exitCode = ecBusy; } @@ -264,7 +264,7 @@ class Worker { it answers with "decline-permanently", we don't try again. */ bool tryBuildHook = true; - Worker(LocalStore& store); + explicit Worker(LocalStore& store); ~Worker(); /* Make a goal (with caching). */ @@ -823,7 +823,7 @@ class DerivationGoal : public Goal { struct ChrootPath { Path source; bool optional; - ChrootPath(Path source = "", bool optional = false) + explicit ChrootPath(Path source = "", bool optional = false) : source(source), optional(optional) {} }; typedef map<Path, ChrootPath> @@ -2037,12 +2037,12 @@ void DerivationGoal::startBuilder() { } size_t p = i.find('='); if (p == string::npos) { - dirsInChroot[i] = {i, optional}; + dirsInChroot[i] = ChrootPath(i, optional); } else { - dirsInChroot[string(i, 0, p)] = {string(i, p + 1), optional}; + dirsInChroot[string(i, 0, p)] = ChrootPath(string(i, p + 1), optional); } } - dirsInChroot[tmpDirInSandbox] = tmpDir; + dirsInChroot[tmpDirInSandbox] = ChrootPath(tmpDir); /* Add the closure of store paths to the chroot. */ PathSet closure; @@ -2058,7 +2058,7 @@ void DerivationGoal::startBuilder() { } } for (auto& i : closure) { - dirsInChroot[i] = i; + dirsInChroot[i] = ChrootPath(i); } PathSet allowedPaths = settings.allowedImpureHostPrefixes; @@ -2088,7 +2088,7 @@ void DerivationGoal::startBuilder() { drvPath % i); } - dirsInChroot[i] = i; + dirsInChroot[i] = ChrootPath(i); } #if __linux__ @@ -2170,7 +2170,7 @@ void DerivationGoal::startBuilder() { throw SysError(format("getting attributes of path '%1%'") % i); } if (S_ISDIR(st.st_mode)) { - dirsInChroot[i] = r; + dirsInChroot[i] = ChrootPath(r); } else { Path p = chrootRootDir + i; DLOG(INFO) << "linking '" << p << "' to '" << r << "'"; @@ -2264,9 +2264,9 @@ void DerivationGoal::startBuilder() { } else { auto p = line.find('='); if (p == string::npos) { - dirsInChroot[line] = line; + dirsInChroot[line] = ChrootPath(line); } else { - dirsInChroot[string(line, 0, p)] = string(line, p + 1); + dirsInChroot[string(line, 0, p)] = ChrootPath(string(line, p + 1)); } } } diff --git a/third_party/nix/src/libstore/export-import.cc b/third_party/nix/src/libstore/export-import.cc index 6a1862492d1f..d50638d5b0f7 100644 --- a/third_party/nix/src/libstore/export-import.cc +++ b/third_party/nix/src/libstore/export-import.cc @@ -9,7 +9,7 @@ namespace nix { struct HashAndWriteSink : Sink { Sink& writeSink; HashSink hashSink; - HashAndWriteSink(Sink& writeSink) + explicit HashAndWriteSink(Sink& writeSink) : writeSink(writeSink), hashSink(htSHA256) {} virtual void operator()(const unsigned char* data, size_t len) { writeSink(data, len); diff --git a/third_party/nix/src/libstore/gc.cc b/third_party/nix/src/libstore/gc.cc index 3e79e6c336aa..2241c58c419c 100644 --- a/third_party/nix/src/libstore/gc.cc +++ b/third_party/nix/src/libstore/gc.cc @@ -505,7 +505,7 @@ struct LocalStore::GCState { unsigned long long bytesInvalidated; bool moveToTrash = true; bool shouldDelete; - GCState(GCResults& results_) : results(results_), bytesInvalidated(0) {} + explicit GCState(GCResults& results_) : results(results_), bytesInvalidated(0) {} }; bool LocalStore::isActiveTempFile(const GCState& state, const Path& path, diff --git a/third_party/nix/src/libstore/local-fs-store.cc b/third_party/nix/src/libstore/local-fs-store.cc index bc282eac96b9..f3ac5b3663ff 100644 --- a/third_party/nix/src/libstore/local-fs-store.cc +++ b/third_party/nix/src/libstore/local-fs-store.cc @@ -12,7 +12,7 @@ LocalFSStore::LocalFSStore(const Params& params) : Store(params) {} struct LocalStoreAccessor : public FSAccessor { ref<LocalFSStore> store; - LocalStoreAccessor(ref<LocalFSStore> store) : store(store) {} + explicit LocalStoreAccessor(ref<LocalFSStore> store) : store(store) {} Path toRealPath(const Path& path) { Path storePath = store->toStorePath(path); diff --git a/third_party/nix/src/libstore/misc.cc b/third_party/nix/src/libstore/misc.cc index a82fc1251c56..0ef0e559876d 100644 --- a/third_party/nix/src/libstore/misc.cc +++ b/third_party/nix/src/libstore/misc.cc @@ -151,7 +151,7 @@ void Store::queryMissing(const PathSet& targets, PathSet& willBuild_, size_t left; bool done = false; PathSet outPaths; - DrvState(size_t left) : left(left) {} + explicit DrvState(size_t left) : left(left) {} }; Sync<State> state_(State{PathSet(), unknown_, willSubstitute_, willBuild_, diff --git a/third_party/nix/src/libstore/nar-accessor.cc b/third_party/nix/src/libstore/nar-accessor.cc index 8be22ada2e36..ffbf7c1a89d5 100644 --- a/third_party/nix/src/libstore/nar-accessor.cc +++ b/third_party/nix/src/libstore/nar-accessor.cc @@ -93,7 +93,7 @@ struct NarAccessor : public FSAccessor { } }; - NarAccessor(ref<const std::string> nar) : nar(nar) { + explicit NarAccessor(ref<const std::string> nar) : nar(nar) { NarIndexer indexer(*this, *nar); parseDump(indexer, indexer); } diff --git a/third_party/nix/src/libstore/optimise-store.cc b/third_party/nix/src/libstore/optimise-store.cc index 8c0f24d382bd..7febe1b145f7 100644 --- a/third_party/nix/src/libstore/optimise-store.cc +++ b/third_party/nix/src/libstore/optimise-store.cc @@ -27,7 +27,7 @@ static void makeWritable(const Path& path) { struct MakeReadOnly { Path path; - MakeReadOnly(const Path& path) : path(path) {} + explicit MakeReadOnly(const Path& path) : path(path) {} ~MakeReadOnly() { try { /* This will make the path read-only. */ diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc index b0025df98f5b..e1fcb749a3fe 100644 --- a/third_party/nix/src/libstore/remote-store.cc +++ b/third_party/nix/src/libstore/remote-store.cc @@ -215,7 +215,7 @@ struct ConnectionHandle { Pool<RemoteStore::Connection>::Handle handle; bool daemonException = false; - ConnectionHandle(Pool<RemoteStore::Connection>::Handle&& handle) + explicit ConnectionHandle(Pool<RemoteStore::Connection>::Handle&& handle) : handle(std::move(handle)) {} ConnectionHandle(ConnectionHandle&& h) : handle(std::move(h.handle)) {} diff --git a/third_party/nix/src/libutil/compression.cc b/third_party/nix/src/libutil/compression.cc index e13ffcec74d8..93e2360bd58c 100644 --- a/third_party/nix/src/libutil/compression.cc +++ b/third_party/nix/src/libutil/compression.cc @@ -34,7 +34,7 @@ struct ChunkedCompressionSink : CompressionSink { struct NoneSink : CompressionSink { Sink& nextSink; - NoneSink(Sink& nextSink) : nextSink(nextSink) {} + explicit NoneSink(Sink& nextSink) : nextSink(nextSink) {} void finish() override { flush(); } void write(const unsigned char* data, size_t len) override { nextSink(data, len); @@ -47,7 +47,7 @@ struct XzDecompressionSink : CompressionSink { lzma_stream strm = LZMA_STREAM_INIT; bool finished = false; - XzDecompressionSink(Sink& nextSink) : nextSink(nextSink) { + explicit XzDecompressionSink(Sink& nextSink) : nextSink(nextSink) { lzma_ret ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED); if (ret != LZMA_OK) { throw CompressionError("unable to initialise lzma decoder"); @@ -92,7 +92,7 @@ struct BzipDecompressionSink : ChunkedCompressionSink { bz_stream strm; bool finished = false; - BzipDecompressionSink(Sink& nextSink) : nextSink(nextSink) { + explicit BzipDecompressionSink(Sink& nextSink) : nextSink(nextSink) { memset(&strm, 0, sizeof(strm)); int ret = BZ2_bzDecompressInit(&strm, 0, 0); if (ret != BZ_OK) { @@ -140,7 +140,7 @@ struct BrotliDecompressionSink : ChunkedCompressionSink { BrotliDecoderState* state; bool finished = false; - BrotliDecompressionSink(Sink& nextSink) : nextSink(nextSink) { + explicit BrotliDecompressionSink(Sink& nextSink) : nextSink(nextSink) { state = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr); if (!state) { throw CompressionError("unable to initialize brotli decoder"); @@ -284,7 +284,7 @@ struct BzipCompressionSink : ChunkedCompressionSink { bz_stream strm; bool finished = false; - BzipCompressionSink(Sink& nextSink) : nextSink(nextSink) { + explicit BzipCompressionSink(Sink& nextSink) : nextSink(nextSink) { memset(&strm, 0, sizeof(strm)); int ret = BZ2_bzCompressInit(&strm, 9, 0, 30); if (ret != BZ_OK) { @@ -333,7 +333,7 @@ struct BrotliCompressionSink : ChunkedCompressionSink { BrotliEncoderState* state; bool finished = false; - BrotliCompressionSink(Sink& nextSink) : nextSink(nextSink) { + explicit BrotliCompressionSink(Sink& nextSink) : nextSink(nextSink) { state = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr); if (!state) { throw CompressionError("unable to initialise brotli encoder"); diff --git a/third_party/nix/src/nix-daemon/nix-daemon.cc b/third_party/nix/src/nix-daemon/nix-daemon.cc index 4f71a0c36fe2..0e5d7ac8baa6 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon.cc @@ -74,7 +74,7 @@ struct TunnelLogger { unsigned int clientVersion; - TunnelLogger(unsigned int clientVersion) : clientVersion(clientVersion) {} + explicit TunnelLogger(unsigned int clientVersion) : clientVersion(clientVersion) {} void enqueueMsg(const std::string& s) { auto state(state_.lock()); @@ -150,7 +150,7 @@ struct TunnelLogger { struct TunnelSink : Sink { Sink& to; - TunnelSink(Sink& to) : to(to) {} + explicit TunnelSink(Sink& to) : to(to) {} virtual void operator()(const unsigned char* data, size_t len) { to << STDERR_WRITE; writeString(data, len, to); @@ -159,7 +159,7 @@ struct TunnelSink : Sink { struct TunnelSource : BufferedSource { Source& from; - TunnelSource(Source& from) : from(from) {} + explicit TunnelSource(Source& from) : from(from) {} protected: size_t readUnbuffered(unsigned char* data, size_t len) override { diff --git a/third_party/nix/src/nix/hash.cc b/third_party/nix/src/nix/hash.cc index 39780532f842..da4b64fe757c 100644 --- a/third_party/nix/src/nix/hash.cc +++ b/third_party/nix/src/nix/hash.cc @@ -14,7 +14,7 @@ struct CmdHash : Command { HashType ht = htSHA256; std::vector<std::string> paths; - CmdHash(Mode mode) : mode(mode) { + explicit CmdHash(Mode mode) : mode(mode) { mkFlag(0, "sri", "print hash in SRI format", &base, SRI); mkFlag(0, "base64", "print hash in base-64", &base, Base64); mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base32); @@ -52,7 +52,7 @@ struct CmdToBase : Command { HashType ht = htUnknown; std::vector<std::string> args; - CmdToBase(Base base) : base(base) { + explicit CmdToBase(Base base) : base(base) { mkFlag().longName("type").mkHashTypeFlag(&ht); expectArgs("strings", &args); } diff --git a/third_party/nix/src/nix/installables.cc b/third_party/nix/src/nix/installables.cc index 8a7de8655bef..2d896e3bb9bb 100644 --- a/third_party/nix/src/nix/installables.cc +++ b/third_party/nix/src/nix/installables.cc @@ -100,7 +100,7 @@ Buildable Installable::toBuildable() { struct InstallableStorePath : Installable { Path storePath; - InstallableStorePath(const Path& storePath) : storePath(storePath) {} + explicit InstallableStorePath(const Path& storePath) : storePath(storePath) {} std::string what() override { return storePath; } @@ -112,7 +112,7 @@ struct InstallableStorePath : Installable { struct InstallableValue : Installable { SourceExprCommand& cmd; - InstallableValue(SourceExprCommand& cmd) : cmd(cmd) {} + explicit InstallableValue(SourceExprCommand& cmd) : cmd(cmd) {} Buildables toBuildables() override { auto state = cmd.getEvalState(); |