diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-03-24 14:26:13 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-03-24 14:34:47 +0100 |
commit | 0a10854f857e519d1455ff0f0be1f8401c40a11c (patch) | |
tree | 64cd9b1c0727eb0642574e4535c5ba61af497c3a /src/libutil | |
parent | c85097da7c1ef06e2f1912c922110ff358de3aa2 (diff) |
Misc changes from the flakes branch
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/hash.hh | 12 | ||||
-rw-r--r-- | src/libutil/util.hh | 5 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index ffa43ecf5..ea9fca3e7 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -80,6 +80,18 @@ struct Hash or base-64. By default, this is prefixed by the hash type (e.g. "sha256:"). */ std::string to_string(Base base = Base32, bool includeType = true) const; + + std::string gitRev() const + { + assert(type == htSHA1); + return to_string(Base16, false); + } + + std::string gitShortRev() const + { + assert(type == htSHA1); + return std::string(to_string(Base16, false), 0, 7); + } }; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index acef682cd..7c3a30242 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -476,10 +476,11 @@ string base64Decode(const string & s); /* Get a value for the specified key from an associate container, or a default value if the key doesn't exist. */ template <class T> -std::optional<std::string> get(const T & map, const std::string & key) +std::optional<typename T::mapped_type> get(const T & map, const typename T::key_type & key) { auto i = map.find(key); - return i == map.end() ? std::optional<std::string>() : i->second; + if (i == map.end()) return {}; + return std::optional<typename T::mapped_type>(i->second); } |