1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 15:32:43 +01:00

libutil: Make HashResult a proper struct

This resolves an existing TODO and makes the
code slightly more readable.
This commit is contained in:
Sergei Zimmerman 2025-08-08 02:02:30 +03:00
parent 241420a788
commit 143bd60136
No known key found for this signature in database
18 changed files with 56 additions and 50 deletions

View file

@ -101,7 +101,7 @@ hashPath(const SourcePath & path, FileIngestionMethod method, HashAlgorithm ht,
case FileIngestionMethod::Flat:
case FileIngestionMethod::NixArchive: {
auto res = hashPath(path, (FileSerialisationMethod) method, ht, filter);
return {res.first, {res.second}};
return {res.hash, res.numBytesDigested};
}
case FileIngestionMethod::Git:
return {git::dumpHash(ht, path, filter).hash, std::nullopt};

View file

@ -329,7 +329,7 @@ TreeEntry dumpHash(HashAlgorithm ha, const SourcePath & path, PathFilter & filte
hook = [&](const SourcePath & path) -> TreeEntry {
auto hashSink = HashSink(ha);
auto mode = dump(path, hashSink, hook, filter);
auto hash = hashSink.finish().first;
auto hash = hashSink.finish().hash;
return {
.mode = mode,
.hash = hash,

View file

@ -338,7 +338,7 @@ Hash hashFile(HashAlgorithm ha, const Path & path)
{
HashSink sink(ha);
readFile(path, sink);
return sink.finish().first;
return sink.finish().hash;
}
HashSink::HashSink(HashAlgorithm ha)

View file

@ -153,10 +153,12 @@ Hash hashFile(HashAlgorithm ha, const Path & path);
/**
* The final hash and the number of bytes digested.
*
* @todo Convert to proper struct
*/
typedef std::pair<Hash, uint64_t> HashResult;
struct HashResult
{
Hash hash;
uint64_t numBytesDigested;
};
/**
* Compress a hash to the specified number of bytes by cyclically

View file

@ -120,7 +120,7 @@ HashResult HashModuloSink::finish()
hashSink(fmt("|%d", pos));
auto h = hashSink.finish();
return {h.first, rewritingSink.pos};
return {.hash = h.hash, .numBytesDigested = rewritingSink.pos};
}
} // namespace nix

View file

@ -65,7 +65,7 @@ Hash SourceAccessor::hashPath(const CanonPath & path, PathFilter & filter, HashA
{
HashSink sink(ha);
dumpPath(path, sink, filter);
return sink.finish().first;
return sink.finish().hash;
}
SourceAccessor::Stat SourceAccessor::lstat(const CanonPath & path)