Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlen Choo <chooglen@google.com>2023-06-26 20:41:37 +0300
committerJunio C Hamano <gitster@pobox.com>2023-06-26 22:07:47 +0300
commita53f43f9005e8a6fd4c5a6733c69b46199c7bb75 (patch)
treec2b07d968adb0648ba644369890fa3c7dd11a0b5 /config.c
parentfb7d80edcae482f4fa5d4be0227dc3054734e5f3 (diff)
config: don't BUG when both kvi and source are set
When iterating through config, we read config source metadata from global values - either a "struct config_source + enum config_scope" or a "struct key_value_info", using the current_config* functions. Prior to the series starting from 0c60285147 (config.c: create config_reader and the_reader, 2023-03-28), we weren't very picky about which values we should read in which situation; we did note that both groups of values generally shouldn't be set together, but if both were set, current_config* preferentially reads key_value_info. When that series added more structure, we enforced that either the former (when parsing a config source) can be set, or the latter (when iterating a config set), but *never* both at the same time. See 9828453ff0 (config.c: remove current_config_kvi, 2023-03-28) and 5cdf18e7cd (config.c: remove current_parsing_scope, 2023-03-28). That was a good simplifying constraint that helped us reason about the global state, but it turns out that there is at least one situation where we need both to be set at the same time: in a blobless partial clone where .gitmodules is missing. "git fetch" in such a repo will start a config parse over .gitmodules (setting the config_source), and Git will attempt to lazy-fetch it from the promisor remote. However, when we try to read the promisor configuration, we start iterating a config set (setting the key_value_info), and we BUG() out because that's not allowed any more. Teaching config_reader to gracefully handle this is somewhat complicated, but fortunately, there are proposed changes to the config.c machinery to get rid of this global state, and make the BUG() obsolete [1]. We should rely on that as the eventual solution, and avoid doing yet another refactor in the meantime. Therefore, fix the bug by removing the BUG() check. We're reverting to an older, less safe state, but that's generally okay since key_value_info is always preferentially read, so we'd always read the correct values when we iterate a config set in the middle of a config parse (like we are here). The reverse would be wrong, but extremely unlikely to happen since very few callers parse config without going through a config set. [1] https://lore.kernel.org/git/pull.1497.v3.git.git.1687290231.gitgitgadget@gmail.com Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c6
1 files changed, 0 insertions, 6 deletions
diff --git a/config.c b/config.c
index b79baf83e3..7bd4b5b940 100644
--- a/config.c
+++ b/config.c
@@ -106,8 +106,6 @@ static struct config_reader the_reader;
static inline void config_reader_push_source(struct config_reader *reader,
struct config_source *top)
{
- if (reader->config_kvi)
- BUG("source should not be set while iterating a config set");
top->prev = reader->source;
reader->source = top;
}
@@ -125,16 +123,12 @@ static inline struct config_source *config_reader_pop_source(struct config_reade
static inline void config_reader_set_kvi(struct config_reader *reader,
struct key_value_info *kvi)
{
- if (kvi && (reader->source || reader->parsing_scope))
- BUG("kvi should not be set while parsing a config source");
reader->config_kvi = kvi;
}
static inline void config_reader_set_scope(struct config_reader *reader,
enum config_scope scope)
{
- if (scope && reader->config_kvi)
- BUG("scope should only be set when iterating through a config source");
reader->parsing_scope = scope;
}