aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/outputs-spec.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-12 20:20:27 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-12 20:20:27 -0500
commit31875bcfb7ccbbf6e88c2cc62714a2a3794994ec (patch)
treeb3750a8c2f786afa433c0d41071478fe2a80ecc7 /src/libstore/outputs-spec.cc
parent0faf5326bd333eeef126730683dc02009a06402f (diff)
Split `OutputsSpec::merge` into `OuputsSpec::{union_, isSubsetOf}`
Additionally get rid of the evil time we made an empty `OutputSpec::Names()`.
Diffstat (limited to 'src/libstore/outputs-spec.cc')
-rw-r--r--src/libstore/outputs-spec.cc46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/libstore/outputs-spec.cc b/src/libstore/outputs-spec.cc
index 8e6e40c2b..d0f39a854 100644
--- a/src/libstore/outputs-spec.cc
+++ b/src/libstore/outputs-spec.cc
@@ -96,24 +96,20 @@ std::string ExtendedOutputsSpec::to_string() const
}
-bool OutputsSpec::merge(const OutputsSpec & that)
+OutputsSpec OutputsSpec::union_(const OutputsSpec & that) const
{
return std::visit(overloaded {
- [&](OutputsSpec::All &) {
- /* If we already refer to all outputs, there is nothing to do. */
- return false;
+ [&](const OutputsSpec::All &) -> OutputsSpec {
+ return OutputsSpec::All { };
},
- [&](OutputsSpec::Names & theseNames) {
+ [&](const OutputsSpec::Names & theseNames) -> OutputsSpec {
return std::visit(overloaded {
- [&](const OutputsSpec::All &) {
- *this = OutputsSpec::All {};
- return true;
+ [&](const OutputsSpec::All &) -> OutputsSpec {
+ return OutputsSpec::All {};
},
- [&](const OutputsSpec::Names & thoseNames) {
- bool ret = false;
- for (auto & i : thoseNames)
- if (theseNames.insert(i).second)
- ret = true;
+ [&](const OutputsSpec::Names & thoseNames) -> OutputsSpec {
+ OutputsSpec::Names ret = theseNames;
+ ret.insert(thoseNames.begin(), thoseNames.end());
return ret;
},
}, that.raw());
@@ -121,6 +117,30 @@ bool OutputsSpec::merge(const OutputsSpec & that)
}, raw());
}
+
+bool OutputsSpec::isSubsetOf(const OutputsSpec & that) const
+{
+ return std::visit(overloaded {
+ [&](const OutputsSpec::All &) {
+ return true;
+ },
+ [&](const OutputsSpec::Names & thoseNames) {
+ return std::visit(overloaded {
+ [&](const OutputsSpec::All &) {
+ return false;
+ },
+ [&](const OutputsSpec::Names & theseNames) {
+ bool ret = true;
+ for (auto & o : theseNames)
+ if (thoseNames.count(o) == 0)
+ ret = false;
+ return ret;
+ },
+ }, raw());
+ },
+ }, that.raw());
+}
+
}
namespace nlohmann {