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

@ -3,28 +3,25 @@
#include <regex>
namespace nix {
struct Regex
{
std::regex regex;
};
DrvName::DrvName()
{
name = "";
}
/* Parse a derivation name. The `name' part of a derivation name is
everything up to but not including the first dash *not* followed by
a letter. The `version' part is the rest (excluding the separating
dash). E.g., `apache-httpd-2.0.48' is parsed to (`apache-httpd',
'2.0.48'). */
DrvName::DrvName(std::string_view s) : hits(0)
DrvName::DrvName(std::string_view s)
: hits(0)
{
name = fullName = std::string(s);
for (unsigned int i = 0; i < s.size(); ++i) {
@ -37,10 +34,7 @@ DrvName::DrvName(std::string_view s) : hits(0)
}
}
DrvName::~DrvName()
{ }
DrvName::~DrvName() {}
bool DrvName::matches(const DrvName & n)
{
@ -49,27 +43,30 @@ bool DrvName::matches(const DrvName & n)
regex = std::make_unique<Regex>();
regex->regex = std::regex(name, std::regex::extended);
}
if (!std::regex_match(n.name, regex->regex)) return false;
if (!std::regex_match(n.name, regex->regex))
return false;
}
if (version != "" && version != n.version) return false;
if (version != "" && version != n.version)
return false;
return true;
}
std::string_view nextComponent(std::string_view::const_iterator & p,
const std::string_view::const_iterator end)
std::string_view nextComponent(std::string_view::const_iterator & p, const std::string_view::const_iterator end)
{
/* Skip any dots and dashes (component separators). */
while (p != end && (*p == '.' || *p == '-')) ++p;
while (p != end && (*p == '.' || *p == '-'))
++p;
if (p == end) return "";
if (p == end)
return "";
/* If the first character is a digit, consume the longest sequence
of digits. Otherwise, consume the longest sequence of
non-digit, non-separator characters. */
auto s = p;
if (isdigit(*p))
while (p != end && isdigit(*p)) p++;
while (p != end && isdigit(*p))
p++;
else
while (p != end && (!isdigit(*p) && *p != '.' && *p != '-'))
p++;
@ -77,23 +74,28 @@ std::string_view nextComponent(std::string_view::const_iterator & p,
return {s, size_t(p - s)};
}
static bool componentsLT(const std::string_view c1, const std::string_view c2)
{
auto n1 = string2Int<int>(c1);
auto n2 = string2Int<int>(c2);
if (n1 && n2) return *n1 < *n2;
else if (c1 == "" && n2) return true;
else if (c1 == "pre" && c2 != "pre") return true;
else if (c2 == "pre") return false;
if (n1 && n2)
return *n1 < *n2;
else if (c1 == "" && n2)
return true;
else if (c1 == "pre" && c2 != "pre")
return true;
else if (c2 == "pre")
return false;
/* Assume that `2.3a' < `2.3.1'. */
else if (n2) return true;
else if (n1) return false;
else return c1 < c2;
else if (n2)
return true;
else if (n1)
return false;
else
return c1 < c2;
}
std::strong_ordering compareVersions(const std::string_view v1, const std::string_view v2)
{
auto p1 = v1.begin();
@ -102,14 +104,15 @@ std::strong_ordering compareVersions(const std::string_view v1, const std::strin
while (p1 != v1.end() || p2 != v2.end()) {
auto c1 = nextComponent(p1, v1.end());
auto c2 = nextComponent(p2, v2.end());
if (componentsLT(c1, c2)) return std::strong_ordering::less;
else if (componentsLT(c2, c1)) return std::strong_ordering::greater;
if (componentsLT(c1, c2))
return std::strong_ordering::less;
else if (componentsLT(c2, c1))
return std::strong_ordering::greater;
}
return std::strong_ordering::equal;
}
DrvNames drvNamesFromArgs(const Strings & opArgs)
{
DrvNames result;
@ -118,5 +121,4 @@ DrvNames drvNamesFromArgs(const Strings & opArgs)
return result;
}
}
} // namespace nix