From b99b368d17f2e806a61f7abb83c6d3a9e4bbdc38 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 25 May 2020 02:19:01 +0100 Subject: refactor(3p/nix/libutil): Replace hasPrefix/Suffix with Abseil Uses the equivalent absl::StartsWith and absl::EndsWith functions instead. --- third_party/nix/src/libexpr/primops/fetchGit.cc | 8 +++++--- third_party/nix/src/libexpr/primops/fetchMercurial.cc | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'third_party/nix/src/libexpr/primops') diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc index c45090707749..99f1c3c4ba0c 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -31,7 +32,8 @@ GitInfo exportGit(ref store, const std::string& uri, if (evalSettings.pureEval && rev == "") throw Error("in pure evaluation mode, 'fetchGit' requires a Git revision"); - if (!ref && rev == "" && hasPrefix(uri, "/") && pathExists(uri + "/.git")) { + if (!ref && rev == "" && absl::StartsWith(uri, "/") && + pathExists(uri + "/.git")) { bool clean = true; try { @@ -56,7 +58,7 @@ GitInfo exportGit(ref store, const std::string& uri, runProgram("git", true, {"-C", uri, "ls-files", "-z"}), "\0"s); PathFilter filter = [&](const Path& p) -> bool { - assert(hasPrefix(p, uri)); + assert(absl::StartsWith(p, uri)); std::string file(p, uri.size() + 1); auto st = lstat(p); @@ -64,7 +66,7 @@ GitInfo exportGit(ref store, const std::string& uri, if (S_ISDIR(st.st_mode)) { auto prefix = file + "/"; auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); + return i != files.end() && absl::StartsWith(*i, prefix); } return files.count(file); diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc index 69ece06eacb9..b6d4a5e1c8bc 100644 --- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc +++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -31,7 +32,7 @@ HgInfo exportMercurial(ref store, const std::string& uri, "in pure evaluation mode, 'fetchMercurial' requires a Mercurial " "revision"); - if (rev == "" && hasPrefix(uri, "/") && pathExists(uri + "/.hg")) { + if (rev == "" && absl::StartsWith(uri, "/") && pathExists(uri + "/.hg")) { bool clean = runProgram("hg", true, {"status", "-R", uri, "--modified", "--added", "--removed"}) == ""; @@ -54,7 +55,7 @@ HgInfo exportMercurial(ref store, const std::string& uri, "\0"s); PathFilter filter = [&](const Path& p) -> bool { - assert(hasPrefix(p, uri)); + assert(absl::StartsWith(p, uri)); std::string file(p, uri.size() + 1); auto st = lstat(p); @@ -62,7 +63,7 @@ HgInfo exportMercurial(ref store, const std::string& uri, if (S_ISDIR(st.st_mode)) { auto prefix = file + "/"; auto i = files.lower_bound(prefix); - return i != files.end() && hasPrefix(*i, prefix); + return i != files.end() && absl::StartsWith(*i, prefix); } return files.count(file); -- cgit 1.4.1