mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
scripted-diff: move settings to common namespace
-BEGIN VERIFY SCRIPT- sed -i 's/namespace\ util/namespace\ common/g' src/common/settings.cpp src/common/settings.h sed -i 's/util\:\:GetSetting/common\:\:GetSetting/g' $( git grep -l 'util\:\:GetSetting') sed -i 's/util\:\:Setting/common\:\:Setting/g' $( git grep -l 'util\:\:Setting') sed -i 's/util\:\:FindKey/common\:\:FindKey/g' $( git grep -l 'util\:\:FindKey') sed -i 's/util\:\:ReadSettings/common\:\:ReadSettings/g' $( git grep -l 'util\:\:ReadSettings') sed -i 's/util\:\:WriteSettings/common\:\:WriteSettings/g' $( git grep -l 'util\:\:WriteSettings') -END VERIFY SCRIPT-
This commit is contained in:
@@ -104,7 +104,7 @@ KeyInfo InterpretKey(std::string key)
|
||||
* @return parsed settings value if it is valid, otherwise nullopt accompanied
|
||||
* by a descriptive error string
|
||||
*/
|
||||
std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
|
||||
std::optional<common::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
|
||||
unsigned int flags, std::string& error)
|
||||
{
|
||||
// Return negated settings as false values.
|
||||
@@ -238,15 +238,15 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<util::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
|
||||
std::optional<common::SettingsValue> value = InterpretValue(keyinfo, val ? &*val : nullptr, *flags, error);
|
||||
if (!value) return false;
|
||||
|
||||
m_settings.command_line_options[keyinfo.name].push_back(*value);
|
||||
}
|
||||
|
||||
// we do not allow -includeconf from command line, only -noincludeconf
|
||||
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
|
||||
const util::SettingsSpan values{*includes};
|
||||
if (auto* includes = common::FindKey(m_settings.command_line_options, "includeconf")) {
|
||||
const common::SettingsSpan values{*includes};
|
||||
// Range may be empty if -noincludeconf was passed
|
||||
if (!values.empty()) {
|
||||
error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write();
|
||||
@@ -361,7 +361,7 @@ std::optional<const ArgsManager::Command> ArgsManager::GetCommand() const
|
||||
std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
for (const util::SettingsValue& value : GetSettingsList(strArg)) {
|
||||
for (const common::SettingsValue& value : GetSettingsList(strArg)) {
|
||||
result.push_back(value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str());
|
||||
}
|
||||
return result;
|
||||
@@ -408,7 +408,7 @@ bool ArgsManager::ReadSettingsFile(std::vector<std::string>* errors)
|
||||
LOCK(cs_args);
|
||||
m_settings.rw_settings.clear();
|
||||
std::vector<std::string> read_errors;
|
||||
if (!util::ReadSettings(path, m_settings.rw_settings, read_errors)) {
|
||||
if (!common::ReadSettings(path, m_settings.rw_settings, read_errors)) {
|
||||
SaveErrors(read_errors, errors);
|
||||
return false;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backu
|
||||
|
||||
LOCK(cs_args);
|
||||
std::vector<std::string> write_errors;
|
||||
if (!util::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
|
||||
if (!common::WriteSettings(path_tmp, m_settings.rw_settings, write_errors)) {
|
||||
SaveErrors(write_errors, errors);
|
||||
return false;
|
||||
}
|
||||
@@ -441,10 +441,10 @@ bool ArgsManager::WriteSettingsFile(std::vector<std::string>* errors, bool backu
|
||||
return true;
|
||||
}
|
||||
|
||||
util::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
|
||||
common::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
return util::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
|
||||
return common::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name),
|
||||
/*ignore_nonpersistent=*/true, /*get_chain_type=*/false);
|
||||
}
|
||||
|
||||
@@ -460,11 +460,11 @@ std::string ArgsManager::GetArg(const std::string& strArg, const std::string& st
|
||||
|
||||
std::optional<std::string> ArgsManager::GetArg(const std::string& strArg) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
const common::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToString(value);
|
||||
}
|
||||
|
||||
std::optional<std::string> SettingToString(const util::SettingsValue& value)
|
||||
std::optional<std::string> SettingToString(const common::SettingsValue& value)
|
||||
{
|
||||
if (value.isNull()) return std::nullopt;
|
||||
if (value.isFalse()) return "0";
|
||||
@@ -473,7 +473,7 @@ std::optional<std::string> SettingToString(const util::SettingsValue& value)
|
||||
return value.get_str();
|
||||
}
|
||||
|
||||
std::string SettingToString(const util::SettingsValue& value, const std::string& strDefault)
|
||||
std::string SettingToString(const common::SettingsValue& value, const std::string& strDefault)
|
||||
{
|
||||
return SettingToString(value).value_or(strDefault);
|
||||
}
|
||||
@@ -485,11 +485,11 @@ int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) cons
|
||||
|
||||
std::optional<int64_t> ArgsManager::GetIntArg(const std::string& strArg) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
const common::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToInt(value);
|
||||
}
|
||||
|
||||
std::optional<int64_t> SettingToInt(const util::SettingsValue& value)
|
||||
std::optional<int64_t> SettingToInt(const common::SettingsValue& value)
|
||||
{
|
||||
if (value.isNull()) return std::nullopt;
|
||||
if (value.isFalse()) return 0;
|
||||
@@ -498,7 +498,7 @@ std::optional<int64_t> SettingToInt(const util::SettingsValue& value)
|
||||
return LocaleIndependentAtoi<int64_t>(value.get_str());
|
||||
}
|
||||
|
||||
int64_t SettingToInt(const util::SettingsValue& value, int64_t nDefault)
|
||||
int64_t SettingToInt(const common::SettingsValue& value, int64_t nDefault)
|
||||
{
|
||||
return SettingToInt(value).value_or(nDefault);
|
||||
}
|
||||
@@ -510,18 +510,18 @@ bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const
|
||||
|
||||
std::optional<bool> ArgsManager::GetBoolArg(const std::string& strArg) const
|
||||
{
|
||||
const util::SettingsValue value = GetSetting(strArg);
|
||||
const common::SettingsValue value = GetSetting(strArg);
|
||||
return SettingToBool(value);
|
||||
}
|
||||
|
||||
std::optional<bool> SettingToBool(const util::SettingsValue& value)
|
||||
std::optional<bool> SettingToBool(const common::SettingsValue& value)
|
||||
{
|
||||
if (value.isNull()) return std::nullopt;
|
||||
if (value.isBool()) return value.get_bool();
|
||||
return InterpretBool(value.get_str());
|
||||
}
|
||||
|
||||
bool SettingToBool(const util::SettingsValue& value, bool fDefault)
|
||||
bool SettingToBool(const common::SettingsValue& value, bool fDefault)
|
||||
{
|
||||
return SettingToBool(value).value_or(fDefault);
|
||||
}
|
||||
@@ -738,7 +738,7 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
|
||||
{
|
||||
auto get_net = [&](const std::string& arg) {
|
||||
LOCK(cs_args);
|
||||
util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
|
||||
common::SettingsValue value = common::GetSetting(m_settings, /* section= */ "", SettingName(arg),
|
||||
/* ignore_default_section_config= */ false,
|
||||
/*ignore_nonpersistent=*/false,
|
||||
/* get_chain_type= */ true);
|
||||
@@ -769,24 +769,24 @@ bool ArgsManager::UseDefaultSection(const std::string& arg) const
|
||||
return m_network == ChainTypeToString(ChainType::MAIN) || m_network_only_args.count(arg) == 0;
|
||||
}
|
||||
|
||||
util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
|
||||
common::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
return util::GetSetting(
|
||||
return common::GetSetting(
|
||||
m_settings, m_network, SettingName(arg), !UseDefaultSection(arg),
|
||||
/*ignore_nonpersistent=*/false, /*get_chain_type=*/false);
|
||||
}
|
||||
|
||||
std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
|
||||
std::vector<common::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
return util::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
|
||||
return common::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));
|
||||
}
|
||||
|
||||
void ArgsManager::logArgsPrefix(
|
||||
const std::string& prefix,
|
||||
const std::string& section,
|
||||
const std::map<std::string, std::vector<util::SettingsValue>>& args) const
|
||||
const std::map<std::string, std::vector<common::SettingsValue>>& args) const
|
||||
{
|
||||
std::string section_str = section.empty() ? "" : "[" + section + "] ";
|
||||
for (const auto& arg : args) {
|
||||
|
||||
@@ -75,7 +75,7 @@ struct KeyInfo {
|
||||
|
||||
KeyInfo InterpretKey(std::string key);
|
||||
|
||||
std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
|
||||
std::optional<common::SettingsValue> InterpretValue(const KeyInfo& key, const std::string* value,
|
||||
unsigned int flags, std::string& error);
|
||||
|
||||
struct SectionInfo {
|
||||
@@ -84,14 +84,14 @@ struct SectionInfo {
|
||||
int m_line;
|
||||
};
|
||||
|
||||
std::string SettingToString(const util::SettingsValue&, const std::string&);
|
||||
std::optional<std::string> SettingToString(const util::SettingsValue&);
|
||||
std::string SettingToString(const common::SettingsValue&, const std::string&);
|
||||
std::optional<std::string> SettingToString(const common::SettingsValue&);
|
||||
|
||||
int64_t SettingToInt(const util::SettingsValue&, int64_t);
|
||||
std::optional<int64_t> SettingToInt(const util::SettingsValue&);
|
||||
int64_t SettingToInt(const common::SettingsValue&, int64_t);
|
||||
std::optional<int64_t> SettingToInt(const common::SettingsValue&);
|
||||
|
||||
bool SettingToBool(const util::SettingsValue&, bool);
|
||||
std::optional<bool> SettingToBool(const util::SettingsValue&);
|
||||
bool SettingToBool(const common::SettingsValue&, bool);
|
||||
std::optional<bool> SettingToBool(const common::SettingsValue&);
|
||||
|
||||
class ArgsManager
|
||||
{
|
||||
@@ -130,7 +130,7 @@ protected:
|
||||
};
|
||||
|
||||
mutable RecursiveMutex cs_args;
|
||||
util::Settings m_settings GUARDED_BY(cs_args);
|
||||
common::Settings m_settings GUARDED_BY(cs_args);
|
||||
std::vector<std::string> m_command GUARDED_BY(cs_args);
|
||||
std::string m_network GUARDED_BY(cs_args);
|
||||
std::set<std::string> m_network_only_args GUARDED_BY(cs_args);
|
||||
@@ -159,12 +159,12 @@ protected:
|
||||
* false if "-nosetting" argument was passed, and a string if a "-setting=value"
|
||||
* argument was passed.
|
||||
*/
|
||||
util::SettingsValue GetSetting(const std::string& arg) const;
|
||||
common::SettingsValue GetSetting(const std::string& arg) const;
|
||||
|
||||
/**
|
||||
* Get list of setting values.
|
||||
*/
|
||||
std::vector<util::SettingsValue> GetSettingsList(const std::string& arg) const;
|
||||
std::vector<common::SettingsValue> GetSettingsList(const std::string& arg) const;
|
||||
|
||||
ArgsManager();
|
||||
~ArgsManager();
|
||||
@@ -394,7 +394,7 @@ protected:
|
||||
* Get current setting from config file or read/write settings file,
|
||||
* ignoring nonpersistent command line or forced settings values.
|
||||
*/
|
||||
util::SettingsValue GetPersistentSetting(const std::string& name) const;
|
||||
common::SettingsValue GetPersistentSetting(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Access settings with lock held.
|
||||
@@ -433,7 +433,7 @@ private:
|
||||
void logArgsPrefix(
|
||||
const std::string& prefix,
|
||||
const std::string& section,
|
||||
const std::map<std::string, std::vector<util::SettingsValue>>& args) const;
|
||||
const std::map<std::string, std::vector<common::SettingsValue>>& args) const;
|
||||
};
|
||||
|
||||
extern ArgsManager gArgs;
|
||||
|
||||
@@ -98,7 +98,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
|
||||
std::optional<unsigned int> flags = GetArgFlags('-' + key.name);
|
||||
if (!IsConfSupported(key, error)) return false;
|
||||
if (flags) {
|
||||
std::optional<util::SettingsValue> value = InterpretValue(key, &option.second, *flags, error);
|
||||
std::optional<common::SettingsValue> value = InterpretValue(key, &option.second, *flags, error);
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
@@ -142,9 +142,9 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
||||
bool use_conf_file{true};
|
||||
{
|
||||
LOCK(cs_args);
|
||||
if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {
|
||||
if (auto* includes = common::FindKey(m_settings.command_line_options, "includeconf")) {
|
||||
// ParseParameters() fails if a non-negated -includeconf is passed on the command-line
|
||||
assert(util::SettingsSpan(*includes).last_negated());
|
||||
assert(common::SettingsSpan(*includes).last_negated());
|
||||
use_conf_file = false;
|
||||
}
|
||||
}
|
||||
@@ -155,9 +155,9 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
||||
auto add_includes = [&](const std::string& network, size_t skip = 0) {
|
||||
size_t num_values = 0;
|
||||
LOCK(cs_args);
|
||||
if (auto* section = util::FindKey(m_settings.ro_config, network)) {
|
||||
if (auto* values = util::FindKey(*section, "includeconf")) {
|
||||
for (size_t i = std::max(skip, util::SettingsSpan(*values).negated()); i < values->size(); ++i) {
|
||||
if (auto* section = common::FindKey(m_settings.ro_config, network)) {
|
||||
if (auto* values = common::FindKey(*section, "includeconf")) {
|
||||
for (size_t i = std::max(skip, common::SettingsSpan(*values).negated()); i < values->size(); ++i) {
|
||||
conf_file_names.push_back((*values)[i].get_str());
|
||||
}
|
||||
num_values = values->size();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace util {
|
||||
namespace common {
|
||||
namespace {
|
||||
|
||||
enum class Source {
|
||||
@@ -258,4 +258,4 @@ size_t SettingsSpan::negated() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace common
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
class UniValue;
|
||||
|
||||
namespace util {
|
||||
namespace common {
|
||||
|
||||
//! Settings value type (string/integer/boolean/null variant).
|
||||
//!
|
||||
@@ -110,6 +110,6 @@ auto FindKey(Map&& map, Key&& key) -> decltype(&map.at(key))
|
||||
return it == map.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace common
|
||||
|
||||
#endif // BITCOIN_COMMON_SETTINGS_H
|
||||
|
||||
Reference in New Issue
Block a user