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:
parent
241420a788
commit
143bd60136
18 changed files with 56 additions and 50 deletions
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue