Skip to content

Commit

Permalink
Add Hash::dummy to signal default value
Browse files Browse the repository at this point in the history
We did this in the same spirit of the dummy value that's present in
libstore/path.hh
  • Loading branch information
meditans committed Aug 5, 2020
1 parent 1d71028 commit 1ad6394
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct LegacySSHStore : public Store

if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 4) {
auto s = readString(conn->from);
info->narHash = s.empty() ? Hash(htSHA256) : Hash::parseAnyPrefixed(s);
info->narHash = s.empty() ? Hash::dummy : Hash::parseAnyPrefixed(s);
info->ca = parseContentAddressOpt(readString(conn->from));
info->sigs = readStrings<StringSet>(conn->from);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/path-info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ struct ValidPathInfo

ValidPathInfo(const ValidPathInfo & other) = default;

ValidPathInfo(StorePath && path) : path(std::move(path)), narHash(Hash(htSHA256)) { };
ValidPathInfo(const StorePath & path) : path(path), narHash(Hash(htSHA256)) { };
ValidPathInfo(StorePath && path) : path(std::move(path)), narHash(Hash::dummy) { };
ValidPathInfo(const StorePath & path) : path(path), narHash(Hash::dummy) { };

virtual ~ValidPathInfo() { }
};
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ std::string Hash::to_string(Base base, bool includeType) const
return s;
}

Hash Hash::dummy(htSHA256);

Hash Hash::parseSRI(std::string_view original) {
auto rest = original;

Expand Down
2 changes: 2 additions & 0 deletions src/libutil/hash.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public:
assert(type == htSHA1);
return std::string(to_string(Base16, false), 0, 7);
}

static Hash dummy;
};

/* Helper that defaults empty hashes to the 0 hash. */
Expand Down

0 comments on commit 1ad6394

Please sign in to comment.