1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 14:51:16 +02:00

treewide: hash type -> hash algorithm

"hash type" -> "hash algorithm" in all comments, documentation, and
messages.

ht -> ha, [Hh]ashType -> [HhashAlgo] for all local variables and
function arguments. No API change is made.

Continuation of 5334c9c792 and 837b889c41.
This commit is contained in:
Yueh-Shun Li 2024-02-26 02:04:20 +08:00
parent d83008c3a7
commit fd47f76da9
8 changed files with 17 additions and 17 deletions

View file

@ -111,10 +111,10 @@ static std::pair<ContentAddressMethod, HashAlgorithm> parseContentAddressMethodP
} }
auto parseHashAlgorithm_ = [&](){ auto parseHashAlgorithm_ = [&](){
auto hashTypeRaw = splitPrefixTo(rest, ':'); auto hashAlgoRaw = splitPrefixTo(rest, ':');
if (!hashTypeRaw) if (!hashAlgoRaw)
throw UsageError("content address hash must be in form '<algo>:<hash>', but found: %s", wholeInput); throw UsageError("content address hash must be in form '<algo>:<hash>', but found: %s", wholeInput);
HashAlgorithm hashAlgo = parseHashAlgo(*hashTypeRaw); HashAlgorithm hashAlgo = parseHashAlgo(*hashAlgoRaw);
return hashAlgo; return hashAlgo;
}; };

View file

@ -91,17 +91,17 @@ struct ContentAddressMethod
std::string_view renderPrefix() const; std::string_view renderPrefix() const;
/** /**
* Parse a content addressing method and hash type. * Parse a content addressing method and hash algorithm.
*/ */
static std::pair<ContentAddressMethod, HashAlgorithm> parseWithAlgo(std::string_view rawCaMethod); static std::pair<ContentAddressMethod, HashAlgorithm> parseWithAlgo(std::string_view rawCaMethod);
/** /**
* Render a content addressing method and hash type in a * Render a content addressing method and hash algorithm in a
* nicer way, prefixing both cases. * nicer way, prefixing both cases.
* *
* The rough inverse of `parse()`. * The rough inverse of `parse()`.
*/ */
std::string renderWithAlgo(HashAlgorithm ht) const; std::string renderWithAlgo(HashAlgorithm ha) const;
/** /**
* Get the underlying way to content-address file system objects. * Get the underlying way to content-address file system objects.
@ -127,7 +127,7 @@ struct ContentAddressMethod
* text:sha256:<sha256 hash of file contents> * text:sha256:<sha256 hash of file contents>
* *
* - `FixedIngestionMethod`: * - `FixedIngestionMethod`:
* fixed:<r?>:<hash type>:<hash of file contents> * fixed:<r?>:<hash algorithm>:<hash of file contents>
*/ */
struct ContentAddress struct ContentAddress
{ {

View file

@ -701,7 +701,7 @@ DerivationType BasicDerivation::type() const
floatingHashAlgo = dof.hashAlgo; floatingHashAlgo = dof.hashAlgo;
} else { } else {
if (*floatingHashAlgo != dof.hashAlgo) if (*floatingHashAlgo != dof.hashAlgo)
throw Error("all floating outputs must use the same hash type"); throw Error("all floating outputs must use the same hash algorithm");
} }
}, },
[&](const DerivationOutput::Deferred &) { [&](const DerivationOutput::Deferred &) {

View file

@ -1094,8 +1094,8 @@ public:
this, {}, "hashed-mirrors", this, {}, "hashed-mirrors",
R"( R"(
A list of web servers used by `builtins.fetchurl` to obtain files by A list of web servers used by `builtins.fetchurl` to obtain files by
hash. Given a hash type *ht* and a base-16 hash *h*, Nix will try to hash. Given a hash algorithm *ha* and a base-16 hash *h*, Nix will try to
download the file from *hashed-mirror*/*ht*/*h*. This allows files to download the file from *hashed-mirror*/*ha*/*h*. This allows files to
be downloaded even if they have disappeared from their original URI. be downloaded even if they have disappeared from their original URI.
For example, given an example mirror `http://tarballs.nixos.org/`, For example, given an example mirror `http://tarballs.nixos.org/`,
when building the derivation when building the derivation

View file

@ -63,10 +63,10 @@ void restorePath(
HashResult hashPath( HashResult hashPath(
SourceAccessor & accessor, const CanonPath & path, SourceAccessor & accessor, const CanonPath & path,
FileIngestionMethod method, HashAlgorithm ht, FileIngestionMethod method, HashAlgorithm ha,
PathFilter & filter) PathFilter & filter)
{ {
HashSink sink { ht }; HashSink sink { ha };
dumpPath(accessor, path, sink, method, filter); dumpPath(accessor, path, sink, method, filter);
return sink.finish(); return sink.finish();
} }

View file

@ -63,11 +63,11 @@ void restorePath(
* Compute the hash of the given file system object according to the * Compute the hash of the given file system object according to the
* given method. * given method.
* *
* The hash is defined as (essentially) hashString(ht, dumpPath(path)). * The hash is defined as (essentially) hashString(ha, dumpPath(path)).
*/ */
HashResult hashPath( HashResult hashPath(
SourceAccessor & accessor, const CanonPath & path, SourceAccessor & accessor, const CanonPath & path,
FileIngestionMethod method, HashAlgorithm ht, FileIngestionMethod method, HashAlgorithm ha,
PathFilter & filter = defaultPathFilter); PathFilter & filter = defaultPathFilter);
} }

View file

@ -274,7 +274,7 @@ Hash newHashAllowEmpty(std::string_view hashStr, std::optional<HashAlgorithm> ha
{ {
if (hashStr.empty()) { if (hashStr.empty()) {
if (!ha) if (!ha)
throw BadHash("empty hash requires explicit hash type"); throw BadHash("empty hash requires explicit hash algorithm");
Hash h(*ha); Hash h(*ha);
warn("found empty hash, assuming '%s'", h.to_string(HashFormat::SRI, true)); warn("found empty hash, assuming '%s'", h.to_string(HashFormat::SRI, true));
return h; return h;

View file

@ -58,7 +58,7 @@ struct Hash
* Parse the hash from a string representation in the format * Parse the hash from a string representation in the format
* "[<type>:]<base16|base32|base64>" or "<type>-<base64>" (a * "[<type>:]<base16|base32|base64>" or "<type>-<base64>" (a
* Subresource Integrity hash expression). If the 'type' argument * Subresource Integrity hash expression). If the 'type' argument
* is not present, then the hash type must be specified in the * is not present, then the hash algorithm must be specified in the
* string. * string.
*/ */
static Hash parseAny(std::string_view s, std::optional<HashAlgorithm> optAlgo); static Hash parseAny(std::string_view s, std::optional<HashAlgorithm> optAlgo);
@ -200,7 +200,7 @@ std::optional<HashFormat> parseHashFormatOpt(std::string_view hashFormatName);
std::string_view printHashFormat(HashFormat hashFormat); std::string_view printHashFormat(HashFormat hashFormat);
/** /**
* Parse a string representing a hash type. * Parse a string representing a hash algorithm.
*/ */
HashAlgorithm parseHashAlgo(std::string_view s); HashAlgorithm parseHashAlgo(std::string_view s);