diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-01-31 19:16:40 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-01-31 19:16:40 +0100 |
commit | 8414685c0f0c0d744c70d438894e4ecd7a078808 (patch) | |
tree | 3c7ca4bf6116f0d7dc863f4737518213767e7455 /src/libexpr/flake/flakeref.cc | |
parent | dbefe9e6b8e4db54be0bd63d3318019d0e3043ac (diff) |
Change lock file format to use an attribute representation of flake refs rather than URLs
Diffstat (limited to 'src/libexpr/flake/flakeref.cc')
-rw-r--r-- | src/libexpr/flake/flakeref.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 7b840bce5..194332674 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -14,12 +14,19 @@ const static std::string subDirElemRegex = "(?:[a-zA-Z0-9_-]+[a-zA-Z0-9._-]*)"; const static std::string subDirRegex = subDirElemRegex + "(?:/" + subDirElemRegex + ")*"; #endif - std::string FlakeRef::to_string() const { return input->to_string(); } +fetchers::Input::Attrs FlakeRef::toAttrs() const +{ + auto attrs = input->toAttrs(); + if (subdir != "") + attrs.emplace("subdir", subdir); + return attrs; +} + bool FlakeRef::isDirect() const { return input->isDirect(); @@ -36,7 +43,7 @@ std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef) return str; } -bool FlakeRef::operator==(const FlakeRef & other) const +bool FlakeRef::operator ==(const FlakeRef & other) const { return *input == *other.input && subdir == other.subdir; } @@ -166,4 +173,13 @@ std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment( } } +FlakeRef FlakeRef::fromAttrs(const fetchers::Input::Attrs & attrs) +{ + auto attrs2(attrs); + attrs2.erase("subdir"); + return FlakeRef( + fetchers::inputFromAttrs(attrs2), + fetchers::maybeGetStrAttr(attrs, "subdir").value_or("")); +} + } |