diff options
author | Kane York <kanepyork@gmail.com> | 2020-07-25T04·09-0700 |
---|---|---|
committer | kanepyork <rikingcoding@gmail.com> | 2020-07-27T21·16+0000 |
commit | ef54f5da9fa30b5c302f2a49595ee5d041f9706a (patch) | |
tree | 8d1da709a2e2d3b135d1e84eda9c402bde467726 /third_party/nix/src/libexpr/primops/fetchGit.cc | |
parent | 69f402563a14d4b668980e4228d033d80e3bb05d (diff) |
fix(3p/nix): apply all clang-tidy fixes r/1495
Change-Id: I265e763393422ee1881653527c91024458060825 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1432 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'third_party/nix/src/libexpr/primops/fetchGit.cc')
-rw-r--r-- | third_party/nix/src/libexpr/primops/fetchGit.cc | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc index 7262a291559f..839094b72b53 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -30,8 +30,9 @@ std::regex revRegex("^[0-9a-fA-F]{40}$"); GitInfo exportGit(ref<Store> store, const std::string& uri, std::optional<std::string> ref, std::string rev, const std::string& name) { - if (evalSettings.pureEval && rev == "") + if (evalSettings.pureEval && rev == "") { throw Error("in pure evaluation mode, 'fetchGit' requires a Git revision"); + } if (!ref && rev == "" && absl::StartsWith(uri, "/") && pathExists(uri + "/.git")) { @@ -90,8 +91,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri, ref = "HEAD"s; } - if (rev != "" && !std::regex_match(rev, revRegex)) + if (rev != "" && !std::regex_match(rev, revRegex)) { throw Error("invalid Git revision '%s'", rev); + } deletePath(getCacheDir() + "/nix/git"); @@ -104,12 +106,13 @@ GitInfo exportGit(ref<Store> store, const std::string& uri, } Path localRefFile; - if (ref->compare(0, 5, "refs/") == 0) + if (ref->compare(0, 5, "refs/") == 0) { localRefFile = cacheDir + "/" + *ref; - else + } else { localRefFile = cacheDir + "/refs/heads/" + *ref; + } - bool doFetch; + bool doFetch = 0; time_t now = time(0); /* If a rev was specified, we need to fetch if it's not in the repo. */ @@ -127,9 +130,10 @@ GitInfo exportGit(ref<Store> store, const std::string& uri, } else { /* If the local ref is older than ‘tarball-ttl’ seconds, do a git fetch to update the local ref to the remote ref. */ - struct stat st; + struct stat st {}; doFetch = stat(localRefFile.c_str(), &st) != 0 || - (uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now; + static_cast<uint64_t>(st.st_mtime) + settings.tarballTtl <= + static_cast<uint64_t>(now); } if (doFetch) { DLOG(INFO) << "fetching Git repository '" << uri << "'"; @@ -225,22 +229,24 @@ static void prim_fetchGit(EvalState& state, const Pos& pos, Value** args, for (auto& attr_iter : *args[0]->attrs) { auto& attr = attr_iter.second; std::string n(attr.name); - if (n == "url") + if (n == "url") { url = state.coerceToString(*attr.pos, *attr.value, context, false, false); - else if (n == "ref") + } else if (n == "ref") { ref = state.forceStringNoCtx(*attr.value, *attr.pos); - else if (n == "rev") + } else if (n == "rev") { rev = state.forceStringNoCtx(*attr.value, *attr.pos); - else if (n == "name") + } else if (n == "name") { name = state.forceStringNoCtx(*attr.value, *attr.pos); - else + } else { throw EvalError("unsupported argument '%s' to 'fetchGit', at %s", attr.name, *attr.pos); + } } - if (url.empty()) + if (url.empty()) { throw EvalError(format("'url' argument required, at %1%") % pos); + } } else { url = state.coerceToString(pos, *args[0], context, false, false); |