diff options
author | eldritch horrors <pennae@lix.systems> | 2024-05-01 20:10:00 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-07-06 12:36:37 +0200 |
commit | 5af76dee371ea5fa1eb72141370fdf18851d67c7 (patch) | |
tree | a51cc0348910a8fce0df02c132efe9a438ddd911 /src/nix/hash.cc | |
parent | 4162a66cee97ec16c88d991ef9a6d9baa3740053 (diff) |
libutil: turn HashModuloSink into a free function
Change-Id: I5878007502fa68c2816a0f4c61f7d0e60bdde702
Diffstat (limited to 'src/nix/hash.cc')
-rw-r--r-- | src/nix/hash.cc | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/nix/hash.cc b/src/nix/hash.cc index d9079d551..12b66a83c 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -76,23 +76,19 @@ struct CmdHashBase : Command void run() override { for (auto path : paths) { - - std::unique_ptr<AbstractHashSink> hashSink; - if (modulus) - hashSink = std::make_unique<HashModuloSink>(ht, *modulus); - else - hashSink = std::make_unique<HashSink>(ht); - - switch (mode) { - case FileIngestionMethod::Flat: - *hashSink << readFileSource(path); - break; - case FileIngestionMethod::Recursive: - *hashSink << dumpPath(path); - break; - } - - Hash h = hashSink->finish().first; + auto source = [&] () -> GeneratorSource { + switch (mode) { + case FileIngestionMethod::Flat: + return GeneratorSource(readFileSource(path)); + case FileIngestionMethod::Recursive: + return GeneratorSource(dumpPath(path)); + } + assert(false); + }(); + + Hash h = modulus + ? computeHashModulo(ht, *modulus, source).first + : hashSource(ht, source).first; if (truncate && h.hashSize > 20) h = compressHash(h, 20); logger->cout(h.to_string(base, base == SRI)); } |