1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 20:16:03 +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.

Co-authored-by: Graham Christensen <graham@grahamc.com>
This commit is contained in:
Sergei Zimmerman 2025-07-18 22:25:33 +03:00
parent 9b8b5d8560
commit 95d9c13716
No known key found for this signature in database
585 changed files with 23297 additions and 23164 deletions

View file

@ -2,15 +2,13 @@
namespace nix {
MemorySourceAccessor::File *
MemorySourceAccessor::open(const CanonPath & path, std::optional<File> create)
MemorySourceAccessor::File * MemorySourceAccessor::open(const CanonPath & path, std::optional<File> create)
{
File * cur = &root;
bool newF = false;
for (std::string_view name : path)
{
for (std::string_view name : path) {
auto * curDirP = std::get_if<File::Directory>(&cur->raw);
if (!curDirP)
return nullptr;
@ -22,16 +20,19 @@ MemorySourceAccessor::open(const CanonPath & path, std::optional<File> create)
return nullptr;
else {
newF = true;
i = curDir.contents.insert(i, {
std::string { name },
File::Directory {},
});
i = curDir.contents.insert(
i,
{
std::string{name},
File::Directory{},
});
}
}
cur = &i->second;
}
if (newF && create) *cur = std::move(*create);
if (newF && create)
*cur = std::move(*create);
return cur;
}
@ -54,32 +55,33 @@ bool MemorySourceAccessor::pathExists(const CanonPath & path)
MemorySourceAccessor::Stat MemorySourceAccessor::File::lstat() const
{
return std::visit(overloaded {
[](const Regular & r) {
return Stat {
.type = tRegular,
.fileSize = r.contents.size(),
.isExecutable = r.executable,
};
return std::visit(
overloaded{
[](const Regular & r) {
return Stat{
.type = tRegular,
.fileSize = r.contents.size(),
.isExecutable = r.executable,
};
},
[](const Directory &) {
return Stat{
.type = tDirectory,
};
},
[](const Symlink &) {
return Stat{
.type = tSymlink,
};
},
},
[](const Directory &) {
return Stat {
.type = tDirectory,
};
},
[](const Symlink &) {
return Stat {
.type = tSymlink,
};
},
}, this->raw);
this->raw);
}
std::optional<MemorySourceAccessor::Stat>
MemorySourceAccessor::maybeLstat(const CanonPath & path)
std::optional<MemorySourceAccessor::Stat> MemorySourceAccessor::maybeLstat(const CanonPath & path)
{
const auto * f = open(path, std::nullopt);
return f ? std::optional { f->lstat() } : std::nullopt;
return f ? std::optional{f->lstat()} : std::nullopt;
}
MemorySourceAccessor::DirEntries MemorySourceAccessor::readDirectory(const CanonPath & path)
@ -110,7 +112,7 @@ std::string MemorySourceAccessor::readLink(const CanonPath & path)
SourcePath MemorySourceAccessor::addFile(CanonPath path, std::string && contents)
{
auto * f = open(path, File { File::Regular {} });
auto * f = open(path, File{File::Regular{}});
if (!f)
throw Error("file '%s' cannot be made because some parent file is not a directory", path);
if (auto * r = std::get_if<File::Regular>(&f->raw))
@ -121,12 +123,11 @@ SourcePath MemorySourceAccessor::addFile(CanonPath path, std::string && contents
return SourcePath{ref(shared_from_this()), path};
}
using File = MemorySourceAccessor::File;
void MemorySink::createDirectory(const CanonPath & path)
{
auto * f = dst.open(path, File { File::Directory { } });
auto * f = dst.open(path, File{File::Directory{}});
if (!f)
throw Error("file '%s' cannot be made because some parent file is not a directory", path);
@ -134,25 +135,27 @@ void MemorySink::createDirectory(const CanonPath & path)
throw Error("file '%s' is not a directory", path);
};
struct CreateMemoryRegularFile : CreateRegularFileSink {
struct CreateMemoryRegularFile : CreateRegularFileSink
{
File::Regular & regularFile;
CreateMemoryRegularFile(File::Regular & r)
: regularFile(r)
{ }
{
}
void operator () (std::string_view data) override;
void operator()(std::string_view data) override;
void isExecutable() override;
void preallocateContents(uint64_t size) override;
};
void MemorySink::createRegularFile(const CanonPath & path, std::function<void(CreateRegularFileSink &)> func)
{
auto * f = dst.open(path, File { File::Regular {} });
auto * f = dst.open(path, File{File::Regular{}});
if (!f)
throw Error("file '%s' cannot be made because some parent file is not a directory", path);
if (auto * rp = std::get_if<File::Regular>(&f->raw)) {
CreateMemoryRegularFile crf { *rp };
CreateMemoryRegularFile crf{*rp};
func(crf);
} else
throw Error("file '%s' is not a regular file", path);
@ -168,14 +171,14 @@ void CreateMemoryRegularFile::preallocateContents(uint64_t len)
regularFile.contents.reserve(len);
}
void CreateMemoryRegularFile::operator () (std::string_view data)
void CreateMemoryRegularFile::operator()(std::string_view data)
{
regularFile.contents += data;
}
void MemorySink::createSymlink(const CanonPath & path, const std::string & target)
{
auto * f = dst.open(path, File { File::Symlink { } });
auto * f = dst.open(path, File{File::Symlink{}});
if (!f)
throw Error("file '%s' cannot be made because some parent file is not a directory", path);
if (auto * s = std::get_if<File::Symlink>(&f->raw))
@ -194,4 +197,4 @@ ref<SourceAccessor> makeEmptySourceAccessor()
return empty;
}
}
} // namespace nix