diff options
author | Kasper Gałkowski <kpg@posteo.net> | 2022-04-06 19:28:12 +0200 |
---|---|---|
committer | Kasper Gałkowski <kpg@posteo.net> | 2022-04-07 19:49:47 +0200 |
commit | 2c2fd4946f96e6839ecbfb4cf61318d8910e7e8f (patch) | |
tree | 63d3aada6e7f9af6dcbd7d934904d9801465c240 /src/libfetchers/fetchers.cc | |
parent | f01e33f283f4ff4e04ccdd4c3692c631cb7290b9 (diff) |
don't assume that rev is a SHA1 hash
This was a problem when writing a fetcher that uses e.g. sha256 hashes
for revisions. This doesn't actually do anything new, but allows for
creating such fetchers in the future (perhaps when support for Git's
SHA256 object format gains more popularity).
Diffstat (limited to 'src/libfetchers/fetchers.cc')
-rw-r--r-- | src/libfetchers/fetchers.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 976f40d3b..6957d2da4 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -238,9 +238,18 @@ std::optional<std::string> Input::getRef() const std::optional<Hash> Input::getRev() const { - if (auto s = maybeGetStrAttr(attrs, "rev")) - return Hash::parseAny(*s, htSHA1); - return {}; + std::optional<Hash> hash = {}; + + if (auto s = maybeGetStrAttr(attrs, "rev")) { + try { + hash = Hash::parseAnyPrefixed(*s); + } catch (BadHash &e) { + // Default to sha1 for backwards compatibility with existing flakes + hash = Hash::parseAny(*s, htSHA1); + } + } + + return hash; } std::optional<uint64_t> Input::getRevCount() const |