-
-
Save jamesob/778eb138a8fe41148f173c791727dcb8 to your computer and use it in GitHub Desktop.
$ diff --color=never /home/james/.ackr/15934.ryanofsky.merge_settings_one_place/3.083c954/base.diff /home/james/.ackr/15934.ryanofsky.merge_settings_one_place/2.202e198/base.diff | sed -r "s/[[:cntrl:]]\[[0-9]{1,3}m//g" | xclip -in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2c2 | |
< index ff4f071a3c..a14e44d2c0 100644[m | |
--- | |
> index 82cc19d57c..ad6bf4e080 100644[m | |
5c5 | |
< @@ -219,6 +219,7 @@[m [mBITCOIN_CORE_H = \[m | |
--- | |
> @@ -215,6 +215,7 @@[m [mBITCOIN_CORE_H = \[m | |
13c13 | |
< @@ -513,6 +514,7 @@[m [mlibbitcoin_util_a_SOURCES = \[m | |
--- | |
> @@ -507,6 +508,7 @@[m [mlibbitcoin_util_a_SOURCES = \[m | |
22c22 | |
< index 6d2b546a28..dd1ade5496 100644[m | |
--- | |
> index 019e832cc6..b60f85da2f 100644[m | |
25c25 | |
< @@ -152,6 +152,7 @@[m [mBITCOIN_TESTS =\[m | |
--- | |
> @@ -141,6 +141,7 @@[m [mBITCOIN_TESTS =\[m | |
35c35 | |
< index 0000000000..b0ee76ea6b[m | |
--- | |
> index 0000000000..920d5021be[m | |
44a45 | |
> +[m#include <test/setup_common.h>[m | |
46d46 | |
< +[m#include <test/util/setup_common.h>[m | |
203c203 | |
< index daf6d951bc..b9fcd97a8f 100644[m | |
--- | |
> index 569ce53092..ba9d732cba 100644[m | |
279c279 | |
< @@ -298,6 +299,7 @@[m [mBOOST_AUTO_TEST_CASE(util_GetBoolArg)[m | |
--- | |
> @@ -244,6 +245,7 @@[m [mBOOST_AUTO_TEST_CASE(util_GetBoolArg)[m | |
287c287 | |
< @@ -306,8 +308,8 @@[m [mBOOST_AUTO_TEST_CASE(util_GetBoolArg)[m | |
--- | |
> @@ -252,8 +254,8 @@[m [mBOOST_AUTO_TEST_CASE(util_GetBoolArg)[m | |
298c298 | |
< @@ -403,6 +405,7 @@[m [mBOOST_AUTO_TEST_CASE(util_ReadConfigStream)[m | |
--- | |
> @@ -349,6 +351,7 @@[m [mBOOST_AUTO_TEST_CASE(util_ReadConfigStream)[m | |
306c306 | |
< @@ -419,22 +422,25 @@[m [mBOOST_AUTO_TEST_CASE(util_ReadConfigStream)[m | |
--- | |
> @@ -365,22 +368,25 @@[m [mBOOST_AUTO_TEST_CASE(util_ReadConfigStream)[m | |
347c347 | |
< @@ -573,24 +579,25 @@[m [mBOOST_AUTO_TEST_CASE(util_ReadConfigStream)[m | |
--- | |
> @@ -519,24 +525,25 @@[m [mBOOST_AUTO_TEST_CASE(util_ReadConfigStream)[m | |
388c388 | |
< index 0000000000..af75fef310[m | |
--- | |
> index 0000000000..06536d2ee1[m | |
391c391 | |
< @@ -0,0 +1,169 @@[m | |
--- | |
> @@ -0,0 +1,163 @@[m | |
403,407c403,411 | |
< +[menum class Source {[m | |
< +[m FORCED,[m | |
< +[m COMMAND_LINE,[m | |
< +[m CONFIG_FILE_NETWORK_SECTION,[m | |
< +[m CONFIG_FILE_DEFAULT_SECTION[m | |
--- | |
> +[mstruct Source {[m | |
> +[m SettingsSpan span;[m | |
> +[m bool forced = false;[m | |
> +[m bool config_file = false;[m | |
> +[m bool config_file_default_section = false;[m | |
> +[m | |
> +[m explicit Source(SettingsSpan span) : span(span) {}[m | |
> +[m Source& SetForced() noexcept { forced = true; return *this; }[m | |
> +[m Source& SetConfigFile(bool default_section) noexcept { config_file = true; config_file_default_section = default_section; return *this; }[m | |
410,414d413 | |
< +[m//! Merge settings from multiple sources in precedence order:[m | |
< +[m//! Forced config > command line > config file network-specific section > config file default section[m | |
< +[m//![m | |
< +[m//! This function is provided with a callback function fn that contains[m | |
< +[m//! specific logic for how to merge the sources.[m | |
418d416 | |
< +[m // Merge in the forced settings[m | |
420c418 | |
< +[m fn(SettingsSpan(*value), Source::FORCED);[m | |
--- | |
> +[m fn(Source(SettingsSpan(*value)).SetForced());[m | |
422d419 | |
< +[m // Merge in the command-line options[m | |
424c421 | |
< +[m fn(SettingsSpan(*values), Source::COMMAND_LINE);[m | |
--- | |
> +[m fn(Source(SettingsSpan(*values)));[m | |
426d422 | |
< +[m // Merge in the network-specific section of the config file[m | |
430c426 | |
< +[m fn(SettingsSpan(*values), Source::CONFIG_FILE_NETWORK_SECTION);[m | |
--- | |
> +[m fn(Source(SettingsSpan(*values)).SetConfigFile(/* default_section= */ false));[m | |
434d429 | |
< +[m // Merge in the default section of the config file[m | |
437c432 | |
< +[m fn(SettingsSpan(*values), Source::CONFIG_FILE_DEFAULT_SECTION);[m | |
--- | |
> +[m fn(Source(SettingsSpan(*values)).SetConfigFile(/* default_section= */ true));[m | |
450c445 | |
< +[m MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) {[m | |
--- | |
> +[m MergeSettings(settings, section, name, [&](Source source) {[m | |
452,455c447,450 | |
< +[m // setting even if non-negated setting would be ignored. A negated[m | |
< +[m // value in the default section is applied to network specific options,[m | |
< +[m // even though normal non-negated values there would be ignored.[m | |
< +[m const bool never_ignore_negated_setting = span.last_negated();[m | |
--- | |
> +[m // setting in otherwise ignored sections. A negated value in the[m | |
> +[m // default section is applied to network specific options, even though[m | |
> +[m // non-negated values there would be ignored.[m | |
> +[m const bool never_ignore_negated_setting = source.span.last_negated();[m | |
460,462c455,456 | |
< +[m // the config file the precedence is reversed for all settings except[m | |
< +[m // chain name settings.[m | |
< +[m const bool reverse_precedence = (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) && !get_chain_name;[m | |
--- | |
> +[m // the config file the precedence is reversed for most settings.[m | |
> +[m const bool reverse_precedence = source.config_file && !get_chain_name;[m | |
472c466 | |
< +[m if (ignore_default_section_config && source == Source::CONFIG_FILE_DEFAULT_SECTION && !never_ignore_negated_setting) return;[m | |
--- | |
> +[m if (ignore_default_section_config && source.config_file_default_section && !never_ignore_negated_setting) return;[m | |
475c469 | |
< +[m if (skip_negated_command_line && span.last_negated()) return;[m | |
--- | |
> +[m if (skip_negated_command_line && source.span.last_negated()) return;[m | |
480,482c474,476 | |
< +[m if (!span.empty()) {[m | |
< +[m result = reverse_precedence ? span.begin()[0] : span.end()[-1];[m | |
< +[m } else if (span.last_negated()) {[m | |
--- | |
> +[m if (!source.span.empty()) {[m | |
> +[m result = reverse_precedence ? source.span.begin()[0] : source.span.end()[-1];[m | |
> +[m } else if (source.span.last_negated()) {[m | |
497c491 | |
< +[m MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) {[m | |
--- | |
> +[m MergeSettings(settings, section, name, [&](Source source) {[m | |
500,505c494,499 | |
< +[m // command line will ignore earlier settings on the command line and[m | |
< +[m // ignore settings in the config file, unless the negated command line[m | |
< +[m // value is followed by non-negated value, in which case config file[m | |
< +[m // settings will be brought back from the dead (but earlier command[m | |
< +[m // line settings will still be ignored).[m | |
< +[m const bool add_zombie_config_values = (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) && !prev_negated_empty;[m | |
--- | |
> +[m // command line will discard earlier settings on the command line and[m | |
> +[m // settings in the config file, unless the negated command line value is[m | |
> +[m // followed by non-negated value, in which case config file settings[m | |
> +[m // will be brought back from the dead (but earlier command line settings[m | |
> +[m // will still be discarded).[m | |
> +[m const bool add_zombie_config_values = source.config_file && !prev_negated_empty;[m | |
508c502 | |
< +[m if (ignore_default_section_config && source == Source::CONFIG_FILE_DEFAULT_SECTION) return;[m | |
--- | |
> +[m if (ignore_default_section_config && source.config_file_default_section) return;[m | |
513c507 | |
< +[m for (const auto& value : span) {[m | |
--- | |
> +[m for (const auto& value : source.span) {[m | |
524c518 | |
< +[m result_complete |= span.negated() > 0 || source == Source::FORCED;[m | |
--- | |
> +[m result_complete |= source.span.negated() > 0 || source.forced;[m | |
527c521 | |
< +[m prev_negated_empty |= span.last_negated() && result.empty();[m | |
--- | |
> +[m prev_negated_empty |= source.span.last_negated() && result.empty();[m | |
536,538c530,532 | |
< +[m MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) {[m | |
< +[m if (span.empty()) return;[m | |
< +[m else if (source == Source::CONFIG_FILE_DEFAULT_SECTION) has_default_section_setting = true;[m | |
--- | |
> +[m MergeSettings(settings, section, name, [&](Source source) {[m | |
> +[m if (source.span.empty()) return;[m | |
> +[m else if (source.config_file_default_section) has_default_section_setting = true;[m | |
655c649 | |
< index 7da408eda5..2a2ae6fdf5 100644[m | |
--- | |
> index 7da408eda5..8bcb13b742 100644[m | |
795c789 | |
< @@ -282,34 +204,39 @@[m [mpublic:[m | |
--- | |
> @@ -282,34 +204,38 @@[m [mpublic:[m | |
806d799 | |
< +[m // Split section name from key name for keys like "testnet.foo" or "regtest.bar"[m | |
858c851 | |
< @@ -331,22 +258,9 @@[m [mconst std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const[m | |
--- | |
> @@ -331,22 +257,9 @@[m [mconst std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const[m | |
884c877 | |
< @@ -375,7 +289,7 @@[m [mvoid ArgsManager::SelectConfigNetwork(const std::string& network)[m | |
--- | |
> @@ -375,7 +288,7 @@[m [mvoid ArgsManager::SelectConfigNetwork(const std::string& network)[m | |
893c886 | |
< @@ -408,49 +322,44 @@[m [mbool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin[m | |
--- | |
> @@ -408,49 +321,43 @@[m [mbool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin[m | |
897d889 | |
< +[m // Transform -foo to foo[m | |
963c955 | |
< @@ -460,69 +369,42 @@[m [munsigned int ArgsManager::FlagsOfKnownArg(const std::string& key) const[m | |
--- | |
> @@ -460,69 +367,42 @@[m [munsigned int ArgsManager::FlagsOfKnownArg(const std::string& key) const[m | |
1046c1038 | |
< @@ -544,7 +426,7 @@[m [mbool ArgsManager::SoftSetBoolArg(const std::string& strArg, bool fValue)[m | |
--- | |
> @@ -544,7 +424,7 @@[m [mbool ArgsManager::SoftSetBoolArg(const std::string& strArg, bool fValue)[m | |
1055c1047 | |
< @@ -860,12 +742,15 @@[m [mbool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file[m | |
--- | |
> @@ -860,12 +740,15 @@[m [mbool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file[m | |
1074c1066 | |
< @@ -882,7 +767,7 @@[m [mbool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)[m | |
--- | |
> @@ -882,7 +765,7 @@[m [mbool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)[m | |
1083,1092c1075,1076 | |
< @@ -894,58 +779,64 @@[m [mbool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)[m | |
< if (!ReadConfigStream(stream, confPath, error, ignore_invalid_keys)) {[m | |
< return false;[m | |
< }[m | |
< - // if there is an -includeconf in the override args, but it is empty, that means the user[m | |
< - // passed '-noincludeconf' on the command line, in which case we should not include anything[m | |
< - bool emptyIncludeConf;[m | |
< +[m // `-includeconf` cannot be included in the command line arguments except[m | |
< +[m // as `-noincludeconf` (which indicates that no conf file should be used).[m | |
< +[m bool use_conf_file{true};[m | |
--- | |
> @@ -899,25 +782,31 @@[m [mbool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)[m | |
> bool emptyIncludeConf;[m | |
1096,1100c1080,1081 | |
< +[m if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) {[m | |
< +[m // ParseParameters() fails if a non-negated -includeconf is passed on the command-line[m | |
< +[m assert(util::SettingsSpan(*includes).last_negated());[m | |
< +[m use_conf_file = false;[m | |
< +[m }[m | |
--- | |
> +[m const std::vector<util::SettingsValue>* const includes = util::FindKey(m_settings.command_line_options, "includeconf");[m | |
> +[m emptyIncludeConf = !(includes && util::SettingsSpan(*includes).last_negated());[m | |
1102,1103c1083 | |
< - if (emptyIncludeConf) {[m | |
< +[m if (use_conf_file) {[m | |
--- | |
> if (emptyIncludeConf) {[m | |
1112c1092 | |
< +[m std::vector<std::string> conf_file_names;[m | |
--- | |
> +[m std::vector<std::string> includeconf;[m | |
1123,1127d1102 | |
< -[m | |
< - for (const std::string& to_include : includeconf) {[m | |
< - fsbridge::ifstream include_config(GetConfigFile(to_include));[m | |
< - if (include_config.good()) {[m | |
< - if (!ReadConfigStream(include_config, to_include, error, ignore_invalid_keys)) {[m | |
1131c1106 | |
< +[m conf_file_names.push_back((*values)[i].get_str());[m | |
--- | |
> +[m includeconf.push_back((*values)[i].get_str());[m | |
1143,1156c1118,1121 | |
< +[m | |
< +[m for (const std::string& conf_file_name : conf_file_names) {[m | |
< +[m fsbridge::ifstream conf_file_stream(GetConfigFile(conf_file_name));[m | |
< +[m if (conf_file_stream.good()) {[m | |
< +[m if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) {[m | |
< return false;[m | |
< }[m | |
< - LogPrintf("Included configuration file %s\n", to_include);[m | |
< +[m LogPrintf("Included configuration file %s\n", conf_file_name);[m | |
< } else {[m | |
< - error = "Failed to include configuration file " + to_include;[m | |
< +[m error = "Failed to include configuration file " + conf_file_name;[m | |
< return false;[m | |
< }[m | |
--- | |
> [m | |
> for (const std::string& to_include : includeconf) {[m | |
> fsbridge::ifstream include_config(GetConfigFile(to_include));[m | |
> @@ -933,15 +822,14 @@[m [mbool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)[m | |
1161c1126,1129 | |
< - {[m | |
--- | |
> +[m includeconf.clear();[m | |
> +[m add_includes(chain_id, /* skip= */ chain_includes);[m | |
> +[m add_includes({}, /* skip= */ default_includes);[m | |
> {[m | |
1164,1166c1132,1134 | |
< - std::string chain_id_final = GetChainName();[m | |
< - if (chain_id_final != chain_id) {[m | |
< - // Also warn about recursive includeconf for the chain that was specified in one of the includeconfs[m | |
--- | |
> std::string chain_id_final = GetChainName();[m | |
> if (chain_id_final != chain_id) {[m | |
> // Also warn about recursive includeconf for the chain that was specified in one of the includeconfs[m | |
1169,1181c1137,1138 | |
< - }[m | |
< +[m conf_file_names.clear();[m | |
< +[m add_includes(chain_id, /* skip= */ chain_includes);[m | |
< +[m add_includes({}, /* skip= */ default_includes);[m | |
< +[m std::string chain_id_final = GetChainName();[m | |
< +[m if (chain_id_final != chain_id) {[m | |
< +[m // Also warn about recursive includeconf for the chain that was specified in one of the includeconfs[m | |
< +[m add_includes(chain_id_final);[m | |
< }[m | |
< - for (const std::string& to_include : includeconf) {[m | |
< - tfm::format(std::cerr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", to_include);[m | |
< +[m for (const std::string& conf_file_name : conf_file_names) {[m | |
< +[m tfm::format(std::cerr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", conf_file_name);[m | |
--- | |
> +[m add_includes(chain_id_final);[m | |
> }[m | |
1183,1185c1140,1141 | |
< }[m | |
< }[m | |
< @@ -961,9 +852,16 @@[m [mbool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)[m | |
--- | |
> for (const std::string& to_include : includeconf) {[m | |
> @@ -961,9 +849,16 @@[m [mbool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)[m | |
1206c1162 | |
< index 7452f186e6..e0b6371dc9 100644[m | |
--- | |
> index 908a3c407d..774491516a 100644[m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment