mirror of
https://github.com/NixOS/nix.git
synced 2025-12-02 23:20:59 +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:
parent
41bf87ec70
commit
e4f62e4608
587 changed files with 23258 additions and 23135 deletions
|
|
@ -12,7 +12,9 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
|
|||
unsigned line = 1;
|
||||
|
||||
auto corrupt = [&](const char * reason) {
|
||||
return Error("NAR info file '%1%' is corrupt: %2%", whence,
|
||||
return Error(
|
||||
"NAR info file '%1%' is corrupt: %2%",
|
||||
whence,
|
||||
std::string(reason) + (line > 0 ? " at line " + std::to_string(line) : ""));
|
||||
};
|
||||
|
||||
|
|
@ -31,20 +33,21 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
|
|||
while (pos < s.size()) {
|
||||
|
||||
size_t colon = s.find(':', pos);
|
||||
if (colon == s.npos) throw corrupt("expecting ':'");
|
||||
if (colon == s.npos)
|
||||
throw corrupt("expecting ':'");
|
||||
|
||||
std::string name(s, pos, colon - pos);
|
||||
|
||||
size_t eol = s.find('\n', colon + 2);
|
||||
if (eol == s.npos) throw corrupt("expecting '\\n'");
|
||||
if (eol == s.npos)
|
||||
throw corrupt("expecting '\\n'");
|
||||
|
||||
std::string value(s, colon + 2, eol - colon - 2);
|
||||
|
||||
if (name == "StorePath") {
|
||||
path = store.parseStorePath(value);
|
||||
havePath = true;
|
||||
}
|
||||
else if (name == "URL")
|
||||
} else if (name == "URL")
|
||||
url = value;
|
||||
else if (name == "Compression")
|
||||
compression = value;
|
||||
|
|
@ -52,32 +55,31 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
|
|||
fileHash = parseHashField(value);
|
||||
else if (name == "FileSize") {
|
||||
auto n = string2Int<decltype(fileSize)>(value);
|
||||
if (!n) throw corrupt("invalid FileSize");
|
||||
if (!n)
|
||||
throw corrupt("invalid FileSize");
|
||||
fileSize = *n;
|
||||
}
|
||||
else if (name == "NarHash") {
|
||||
} else if (name == "NarHash") {
|
||||
narHash = parseHashField(value);
|
||||
haveNarHash = true;
|
||||
}
|
||||
else if (name == "NarSize") {
|
||||
} else if (name == "NarSize") {
|
||||
auto n = string2Int<decltype(narSize)>(value);
|
||||
if (!n) throw corrupt("invalid NarSize");
|
||||
if (!n)
|
||||
throw corrupt("invalid NarSize");
|
||||
narSize = *n;
|
||||
}
|
||||
else if (name == "References") {
|
||||
} else if (name == "References") {
|
||||
auto refs = tokenizeString<Strings>(value, " ");
|
||||
if (!references.empty()) throw corrupt("extra References");
|
||||
if (!references.empty())
|
||||
throw corrupt("extra References");
|
||||
for (auto & r : refs)
|
||||
references.insert(StorePath(r));
|
||||
}
|
||||
else if (name == "Deriver") {
|
||||
} else if (name == "Deriver") {
|
||||
if (value != "unknown-deriver")
|
||||
deriver = StorePath(value);
|
||||
}
|
||||
else if (name == "Sig")
|
||||
} else if (name == "Sig")
|
||||
sigs.insert(value);
|
||||
else if (name == "CA") {
|
||||
if (ca) throw corrupt("extra CA");
|
||||
if (ca)
|
||||
throw corrupt("extra CA");
|
||||
// FIXME: allow blank ca or require skipping field?
|
||||
ca = ContentAddress::parseOpt(value);
|
||||
}
|
||||
|
|
@ -86,16 +88,17 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
|
|||
line += 1;
|
||||
}
|
||||
|
||||
if (compression == "") compression = "bzip2";
|
||||
if (compression == "")
|
||||
compression = "bzip2";
|
||||
|
||||
if (!havePath || !haveNarHash || url.empty() || narSize == 0) {
|
||||
line = 0; // don't include line information in the error
|
||||
throw corrupt(
|
||||
!havePath ? "StorePath missing" :
|
||||
!haveNarHash ? "NarHash missing" :
|
||||
url.empty() ? "URL missing" :
|
||||
narSize == 0 ? "NarSize missing or zero"
|
||||
: "?");
|
||||
!havePath ? "StorePath missing"
|
||||
: !haveNarHash ? "NarHash missing"
|
||||
: url.empty() ? "URL missing"
|
||||
: narSize == 0 ? "NarSize missing or zero"
|
||||
: "?");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,10 +130,7 @@ std::string NarInfo::to_string(const Store & store) const
|
|||
return res;
|
||||
}
|
||||
|
||||
nlohmann::json NarInfo::toJSON(
|
||||
const Store & store,
|
||||
bool includeImpureInfo,
|
||||
HashFormat hashFormat) const
|
||||
nlohmann::json NarInfo::toJSON(const Store & store, bool includeImpureInfo, HashFormat hashFormat) const
|
||||
{
|
||||
using nlohmann::json;
|
||||
|
||||
|
|
@ -150,19 +150,14 @@ nlohmann::json NarInfo::toJSON(
|
|||
return jsonObject;
|
||||
}
|
||||
|
||||
NarInfo NarInfo::fromJSON(
|
||||
const Store & store,
|
||||
const StorePath & path,
|
||||
const nlohmann::json & json)
|
||||
NarInfo NarInfo::fromJSON(const Store & store, const StorePath & path, const nlohmann::json & json)
|
||||
{
|
||||
using nlohmann::detail::value_t;
|
||||
|
||||
NarInfo res {
|
||||
ValidPathInfo {
|
||||
path,
|
||||
UnkeyedValidPathInfo::fromJSON(store, json),
|
||||
}
|
||||
};
|
||||
NarInfo res{ValidPathInfo{
|
||||
path,
|
||||
UnkeyedValidPathInfo::fromJSON(store, json),
|
||||
}};
|
||||
|
||||
if (json.contains("url"))
|
||||
res.url = getString(valueAt(json, "url"));
|
||||
|
|
@ -171,9 +166,7 @@ NarInfo NarInfo::fromJSON(
|
|||
res.compression = getString(valueAt(json, "compression"));
|
||||
|
||||
if (json.contains("downloadHash"))
|
||||
res.fileHash = Hash::parseAny(
|
||||
getString(valueAt(json, "downloadHash")),
|
||||
std::nullopt);
|
||||
res.fileHash = Hash::parseAny(getString(valueAt(json, "downloadHash")), std::nullopt);
|
||||
|
||||
if (json.contains("downloadSize"))
|
||||
res.fileSize = getUnsigned(valueAt(json, "downloadSize"));
|
||||
|
|
@ -181,4 +174,4 @@ NarInfo NarInfo::fromJSON(
|
|||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue