forked from lix-project/lix
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).
This commit is contained in:
parent
f01e33f283
commit
2c2fd4946f
|
@ -238,9 +238,18 @@ std::optional<std::string> Input::getRef() const
|
||||||
|
|
||||||
std::optional<Hash> Input::getRev() const
|
std::optional<Hash> Input::getRev() const
|
||||||
{
|
{
|
||||||
if (auto s = maybeGetStrAttr(attrs, "rev"))
|
std::optional<Hash> hash = {};
|
||||||
return Hash::parseAny(*s, htSHA1);
|
|
||||||
return {};
|
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
|
std::optional<uint64_t> Input::getRevCount() const
|
||||||
|
|
|
@ -155,7 +155,7 @@ static std::pair<std::optional<HashType>, bool> getParsedTypeAndSRI(std::string_
|
||||||
{
|
{
|
||||||
bool isSRI = false;
|
bool isSRI = false;
|
||||||
|
|
||||||
// Parse the has type before the separater, if there was one.
|
// Parse the hash type before the separator, if there was one.
|
||||||
std::optional<HashType> optParsedType;
|
std::optional<HashType> optParsedType;
|
||||||
{
|
{
|
||||||
auto hashRaw = splitPrefixTo(rest, ':');
|
auto hashRaw = splitPrefixTo(rest, ':');
|
||||||
|
|
|
@ -93,13 +93,11 @@ public:
|
||||||
|
|
||||||
std::string gitRev() const
|
std::string gitRev() const
|
||||||
{
|
{
|
||||||
assert(type == htSHA1);
|
|
||||||
return to_string(Base16, false);
|
return to_string(Base16, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string gitShortRev() const
|
std::string gitShortRev() const
|
||||||
{
|
{
|
||||||
assert(type == htSHA1);
|
|
||||||
return std::string(to_string(Base16, false), 0, 7);
|
return std::string(to_string(Base16, false), 0, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue