From 06d7b4aebd9e4a1a87f77fe59a8c08392318be5d Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 24 May 2020 01:36:11 +0100 Subject: refactor(3p/nix/libutil): Replace chomp() with absl::strings --- third_party/nix/src/libexpr/primops/fetchGit.cc | 8 ++++++-- third_party/nix/src/libexpr/primops/fetchMercurial.cc | 4 +++- 2 files changed, 9 insertions(+), 3 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 67641258d518..c45090707749 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -76,7 +77,8 @@ GitInfo exportGit(ref store, const std::string& uri, } // clean working tree, but no ref or rev specified. Use 'HEAD'. - rev = chomp(runProgram("git", true, {"-C", uri, "rev-parse", "HEAD"})); + rev = absl::StripTrailingAsciiWhitespace( + runProgram("git", true, {"-C", uri, "rev-parse", "HEAD"})); ref = "HEAD"s; } @@ -145,7 +147,9 @@ GitInfo exportGit(ref store, const std::string& uri, // FIXME: check whether rev is an ancestor of ref. GitInfo gitInfo; - gitInfo.rev = rev != "" ? rev : chomp(readFile(localRefFile)); + gitInfo.rev = + rev != "" ? rev + : absl::StripTrailingAsciiWhitespace(readFile(localRefFile)); gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); DLOG(INFO) << "using revision " << gitInfo.rev << " of repo '" << uri << "'"; diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc index 9223f1c3ca99..69ece06eacb9 100644 --- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc +++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -43,7 +44,8 @@ HgInfo exportMercurial(ref store, const std::string& uri, HgInfo hgInfo; hgInfo.rev = "0000000000000000000000000000000000000000"; - hgInfo.branch = chomp(runProgram("hg", true, {"branch", "-R", uri})); + hgInfo.branch = absl::StripTrailingAsciiWhitespace( + runProgram("hg", true, {"branch", "-R", uri})); auto files = tokenizeString>( runProgram("hg", true, -- cgit 1.4.1