Re: [PATCH v3 04/12] config.c: pass ctx in configsets
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 20, 2023, 21:19 UTC
- Message-ID
- <xmqqa5wtltlm.fsf@gitster.g>
- In-Reply-To
- <c5051ddc10dfa9665fbcbed30875369c4e972d17.1687290233.git.gitgitgadget@gmail.com>
"Glen Choo via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 18 quoted lines
> static int config_read_push_default(const char *key, const char *value,
> - const struct config_context *ctx UNUSED, void *cb)
> + const struct config_context *ctx, void *cb)
> {
> + const struct key_value_info *kvi = ctx->kvi;
> +
> struct push_default_info* info = cb;
> if (strcmp(key, "remote.pushdefault") ||
> !value || strcmp(value, info->old_name))
> return 0;
>
> - info->scope = current_config_scope();
> + info->scope = kvi->scope;
> strbuf_reset(&info->origin);
> - strbuf_addstr(&info->origin, current_config_name());
> - info->linenr = current_config_line();
> + strbuf_addstr(&info->origin, config_origin_type_name(kvi->origin_type));
> + info->linenr = kvi->linenr;Yay!
It is very pleasing to see these current_*() functions made unnecessary. This step only allows us to remove the _line() but not yet _scope(), but as long as we lose them at the end, going one step at a time is perfectly fine and readable.
Show 9 quoted lines
> +const char *current_config_origin_type(void)
> +{
> + enum config_origin_type type = CONFIG_ORIGIN_UNKNOWN;
> +
> + if (reader_origin_type(&the_reader, &type))
> + BUG("current_config_origin_type called outside config callback");
> +
> + return config_origin_type_name(type);
> +}We still rely on the fact that the_reader is a global singleton, but that is of course OK in this early part of the series.
Looking nice.