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

@ -9,19 +9,18 @@ CanonPath CanonPath::root = CanonPath("/");
static std::string absPathPure(std::string_view path)
{
return canonPathInner<UnixPathTrait>(path, [](auto &, auto &){});
return canonPathInner<UnixPathTrait>(path, [](auto &, auto &) {});
}
CanonPath::CanonPath(std::string_view raw)
: path(absPathPure(concatStrings("/", raw)))
{ }
{
}
CanonPath::CanonPath(std::string_view raw, const CanonPath & root)
: path(absPathPure(
raw.size() > 0 && raw[0] == '/'
? raw
: concatStrings(root.abs(), "/", raw)))
{ }
: path(absPathPure(raw.size() > 0 && raw[0] == '/' ? raw : concatStrings(root.abs(), "/", raw)))
{
}
CanonPath::CanonPath(const std::vector<std::string> & elems)
: path("/")
@ -32,7 +31,8 @@ CanonPath::CanonPath(const std::vector<std::string> & elems)
std::optional<CanonPath> CanonPath::parent() const
{
if (isRoot()) return std::nullopt;
if (isRoot())
return std::nullopt;
return CanonPath(unchecked_t(), path.substr(0, std::max((size_t) 1, path.rfind('/'))));
}
@ -45,30 +45,31 @@ void CanonPath::pop()
bool CanonPath::isWithin(const CanonPath & parent) const
{
return !(
path.size() < parent.path.size()
|| path.substr(0, parent.path.size()) != parent.path
|| (parent.path.size() > 1 && path.size() > parent.path.size()
&& path[parent.path.size()] != '/'));
path.size() < parent.path.size() || path.substr(0, parent.path.size()) != parent.path
|| (parent.path.size() > 1 && path.size() > parent.path.size() && path[parent.path.size()] != '/'));
}
CanonPath CanonPath::removePrefix(const CanonPath & prefix) const
{
assert(isWithin(prefix));
if (prefix.isRoot()) return *this;
if (path.size() == prefix.path.size()) return root;
if (prefix.isRoot())
return *this;
if (path.size() == prefix.path.size())
return root;
return CanonPath(unchecked_t(), path.substr(prefix.path.size()));
}
void CanonPath::extend(const CanonPath & x)
{
if (x.isRoot()) return;
if (x.isRoot())
return;
if (isRoot())
path += x.rel();
else
path += x.abs();
}
CanonPath CanonPath::operator / (const CanonPath & x) const
CanonPath CanonPath::operator/(const CanonPath & x) const
{
auto res = *this;
res.extend(x);
@ -79,11 +80,12 @@ void CanonPath::push(std::string_view c)
{
assert(c.find('/') == c.npos);
assert(c != "." && c != "..");
if (!isRoot()) path += '/';
if (!isRoot())
path += '/';
path += c;
}
CanonPath CanonPath::operator / (std::string_view c) const
CanonPath CanonPath::operator/(std::string_view c) const
{
auto res = *this;
res.push(c);
@ -111,7 +113,7 @@ bool CanonPath::isAllowed(const std::set<CanonPath> & allowed) const
return false;
}
std::ostream & operator << (std::ostream & stream, const CanonPath & path)
std::ostream & operator<<(std::ostream & stream, const CanonPath & path)
{
stream << path.abs();
return stream;
@ -122,7 +124,8 @@ std::string CanonPath::makeRelative(const CanonPath & path) const
auto p1 = begin();
auto p2 = path.begin();
for (; p1 != end() && p2 != path.end() && *p1 == *p2; ++p1, ++p2) ;
for (; p1 != end() && p2 != path.end() && *p1 == *p2; ++p1, ++p2)
;
if (p1 == end() && p2 == path.end())
return ".";
@ -132,15 +135,17 @@ std::string CanonPath::makeRelative(const CanonPath & path) const
std::string res;
while (p1 != end()) {
++p1;
if (!res.empty()) res += '/';
if (!res.empty())
res += '/';
res += "..";
}
if (p2 != path.end()) {
if (!res.empty()) res += '/';
if (!res.empty())
res += '/';
res += p2.remaining;
}
return res;
}
}
}
} // namespace nix