From d2022189a16addf9a67ab70989ae38f90e85e07c Mon Sep 17 00:00:00 2001 From: AGawas Date: Fri, 8 Aug 2025 11:47:47 -0400 Subject: [PATCH] Inline printHash16or32 and remove redundant helper (#13716) Fixes ##13692 --------- Co-authored-by: John Ericson Co-authored-by: Sergei Zimmerman --- src/libutil/hash.cc | 6 ------ src/libutil/include/nix/util/hash.hh | 5 ----- src/nix/prefetch.cc | 4 +++- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index fe7e9ab3b..e469957a0 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -60,12 +60,6 @@ std::strong_ordering Hash::operator<=>(const Hash & h) const noexcept return std::strong_ordering::equivalent; } -std::string printHash16or32(const Hash & hash) -{ - assert(static_cast(hash.algo)); - return hash.to_string(hash.algo == HashAlgorithm::MD5 ? HashFormat::Base16 : HashFormat::Nix32, false); -} - std::string Hash::to_string(HashFormat hashFormat, bool includeAlgo) const { std::string s; diff --git a/src/libutil/include/nix/util/hash.hh b/src/libutil/include/nix/util/hash.hh index f5c01d2e1..f4d137bd0 100644 --- a/src/libutil/include/nix/util/hash.hh +++ b/src/libutil/include/nix/util/hash.hh @@ -133,11 +133,6 @@ public: */ Hash newHashAllowEmpty(std::string_view hashStr, std::optional ha); -/** - * Print a hash in base-16 if it's MD5, or base-32 otherwise. - */ -std::string printHash16or32(const Hash & hash); - /** * Compute the hash of the given string. */ diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index 1423ce517..b651a4c97 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -247,7 +247,9 @@ static int main_nix_prefetch_url(int argc, char ** argv) if (!printPath) printInfo("path is '%s'", store->printStorePath(storePath)); - logger->cout(printHash16or32(hash)); + assert(static_cast(hash.algo)); + logger->cout(hash.to_string(hash.algo == HashAlgorithm::MD5 ? HashFormat::Base16 : HashFormat::Nix32, false)); + if (printPath) logger->cout(store->printStorePath(storePath));