From d8c10028d96d49b2c783fe279daa91402e8a91da Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 22 Sep 2021 14:15:35 +0200 Subject: Make setDefault() typed --- src/libutil/config.cc | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/libutil/config.cc') diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 2a5f913e6..c247c7dae 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -177,11 +177,6 @@ AbstractSetting::AbstractSetting( { } -void AbstractSetting::setDefault(const std::string & str) -{ - if (!overridden) set(str); -} - nlohmann::json AbstractSetting::toJSON() { return nlohmann::json(toJSONObject()); -- cgit v1.2.3 From af99941279b80c962ec9cae3e5fa32976a3f5744 Mon Sep 17 00:00:00 2001 From: regnat Date: Mon, 25 Oct 2021 15:53:01 +0200 Subject: Make experimental-features a proper type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than having them plain strings scattered through the whole codebase, create an enum containing all the known experimental features. This means that - Nix can now `warn` when an unkwown experimental feature is passed (making it much nicer to spot typos and spot deprecated features) - It’s now easy to remove a feature altogether (once the feature isn’t experimental anymore or is dropped) by just removing the field for the enum and letting the compiler point us to all the now invalid usages of it. --- src/libutil/config.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/libutil/config.cc') diff --git a/src/libutil/config.cc b/src/libutil/config.cc index c247c7dae..026db6574 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -1,6 +1,7 @@ #include "config.hh" #include "args.hh" #include "abstract-setting-to-json.hh" +#include "experimental-features.hh" #include @@ -313,6 +314,31 @@ template<> std::string BaseSetting::to_string() const return concatStringsSep(" ", value); } +template<> void BaseSetting>::set(const std::string & str, bool append) +{ + if (!append) value.clear(); + for (auto & s : tokenizeString(str)) { + auto thisXpFeature = parseExperimentalFeature(s); + if (thisXpFeature) + value.insert(thisXpFeature.value()); + else + warn("Unknown experimental feature %s", s); + } +} + +template<> bool BaseSetting>::isAppendable() +{ + return true; +} + +template<> std::string BaseSetting>::to_string() const +{ + StringSet stringifiedXpFeatures; + for (auto & feature : value) + stringifiedXpFeatures.insert(std::string(showExperimentalFeature(feature))); + return concatStringsSep(" ", stringifiedXpFeatures); +} + template<> void BaseSetting::set(const std::string & str, bool append) { if (!append) value.clear(); @@ -348,6 +374,7 @@ template class BaseSetting; template class BaseSetting; template class BaseSetting; template class BaseSetting; +template class BaseSetting>; void PathSetting::set(const std::string & str, bool append) { -- cgit v1.2.3 From 13a7a24ba5213a536911320c0ee69faf26bc3f53 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 27 Oct 2021 13:01:56 +0200 Subject: Style --- src/libutil/config.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libutil/config.cc') diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 026db6574..92ab265d3 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -322,7 +322,7 @@ template<> void BaseSetting>::set(const std::strin if (thisXpFeature) value.insert(thisXpFeature.value()); else - warn("Unknown experimental feature %s", s); + warn("unknown experimental feature '%s'", s); } } -- cgit v1.2.3 From 1ac2664472d0135503e54f0d924a802023855003 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 21 Feb 2022 16:32:34 +0100 Subject: Remove std::vector alias --- src/libutil/config.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libutil/config.cc') diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 92ab265d3..8e05f1765 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -90,7 +90,7 @@ void AbstractConfig::applyConfig(const std::string & contents, const std::string if (hash != string::npos) line = string(line, 0, hash); - vector tokens = tokenizeString >(line); + auto tokens = tokenizeString>(line); if (tokens.empty()) continue; if (tokens.size() < 2) @@ -122,7 +122,7 @@ void AbstractConfig::applyConfig(const std::string & contents, const std::string string name = tokens[0]; - vector::iterator i = tokens.begin(); + auto i = tokens.begin(); advance(i, 2); set(name, concatStringsSep(" ", Strings(i, tokens.end()))); // FIXME: slow -- cgit v1.2.3 From df552ff53e68dff8ca360adbdbea214ece1d08ee Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 25 Feb 2022 16:00:00 +0100 Subject: Remove std::string alias (for real this time) Also use std::string_view in a few more places. --- src/libutil/config.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/libutil/config.cc') diff --git a/src/libutil/config.cc b/src/libutil/config.cc index 8e05f1765..9bb412b4f 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -81,16 +81,16 @@ void AbstractConfig::applyConfig(const std::string & contents, const std::string unsigned int pos = 0; while (pos < contents.size()) { - string line; + std::string line; while (pos < contents.size() && contents[pos] != '\n') line += contents[pos++]; pos++; - string::size_type hash = line.find('#'); - if (hash != string::npos) - line = string(line, 0, hash); + auto hash = line.find('#'); + if (hash != std::string::npos) + line = std::string(line, 0, hash); - auto tokens = tokenizeString>(line); + auto tokens = tokenizeString>(line); if (tokens.empty()) continue; if (tokens.size() < 2) @@ -120,7 +120,7 @@ void AbstractConfig::applyConfig(const std::string & contents, const std::string if (tokens[1] != "=") throw UsageError("illegal configuration line '%1%' in '%2%'", line, path); - string name = tokens[0]; + std::string name = tokens[0]; auto i = tokens.begin(); advance(i, 2); @@ -132,7 +132,7 @@ void AbstractConfig::applyConfig(const std::string & contents, const std::string void AbstractConfig::applyConfigFile(const Path & path) { try { - string contents = readFile(path); + std::string contents = readFile(path); applyConfig(contents, path); } catch (SysError &) { } } -- cgit v1.2.3