]> git.ipfire.org Git - thirdparty/git.git/commit - config.h
config: report cached filenames in die_bad_number()
authorGlen Choo <chooglen@google.com>
Tue, 28 Mar 2023 17:51:53 +0000 (17:51 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2023 20:03:27 +0000 (13:03 -0700)
commite2016508e7690cddc789fb28879703082363549d
treec3dbcb4ad2e3ccbf681535de87344c43e7eaec1f
parent5cdf18e7cd6d6e3ce2fb21fef2b5ec84e570abf8
config: report cached filenames in die_bad_number()

If, when parsing numbers from config, die_bad_number() is called, it
reports the filename and config source type if we were parsing a config
file, but not if we were iterating a config_set (it defaults to a less
specific error message). Most call sites don't parse config files
because config is typically read once and cached, so we only report
filename and config source type in "git config --type" (since "git
config" always parses config files).

This could have been fixed when we taught the current_config_*
functions to respect config_set values (0d44a2dacc (config: return
configset value for current_config_ functions, 2016-05-26), but it was
hard to spot then and we might have just missed it (I didn't find
mention of die_bad_number() in the original ML discussion [1].)

Fix this by refactoring the current_config_* functions into variants
that don't BUG() when we aren't reading config, and using the resulting
functions in die_bad_number(). "git config --get[-regexp] --type=int"
cannot use the non-refactored version because it parses the int value
_after_ parsing the config file, which would run into the BUG().

Since the refactored functions aren't public, they use "struct
config_reader".

1. https://lore.kernel.org/git/20160518223712.GA18317@sigill.intra.peff.net/

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
config.h
t/helper/test-config.c
t/t1308-config-set.sh