Skip to content

Commit

Permalink
assert hash types for Git and Mercurial
Browse files Browse the repository at this point in the history
  • Loading branch information
Uthar committed Apr 12, 2022
1 parent 2c2fd49 commit 2769e43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,16 @@ struct GitInputScheme : InputScheme
if (submodules) cacheType += "-submodules";
if (allRefs) cacheType += "-all-refs";

auto checkHashType = [&](const std::optional<Hash> & hash)
{
if (hash.has_value() && !(hash->type == htSHA1 || hash->type == htSHA256))
throw Error("Hash '%s' is not supported by Git. Supported types are sha1 and sha256.", hash->to_string(Base16, true));
};

auto getLockedAttrs = [&]()
{
checkHashType(input.getRev());

return Attrs({
{"type", cacheType},
{"name", name},
Expand Down
9 changes: 9 additions & 0 deletions src/libfetchers/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,17 @@ struct MercurialInputScheme : InputScheme

if (!input.getRef()) input.attrs.insert_or_assign("ref", "default");

auto checkHashType = [&](const std::optional<Hash> & hash)
{
if (hash.has_value() && hash->type != htSHA1)
throw Error("Hash '%s' is not supported by Mercurial. Only sha1 is supported.", hash->to_string(Base16, true));
};


auto getLockedAttrs = [&]()
{
checkHashType(input.getRev());

return Attrs({
{"type", "hg"},
{"name", name},
Expand Down

0 comments on commit 2769e43

Please sign in to comment.