Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
usage API: add "core.usageAddSource" config to add <file>:<line>
Optionally extend the support that BUG() has had for emitting line numbers to the {usage,fatal,error,warning}{,_errno}() functions. Before we'd unconditionally get error messages like: $ git -c core.x=y config --get --bool core.x fatal: bad boolean config value 'y' for 'core.x' Which can be changed with core.usageAddSource=true to include the file and line numbers: $ git -c core.usageAddSource=true -c core.x=y config --get --bool core.x fatal: config.c:1241: bad boolean config value 'y' for 'core.x' As the added documentation notes this is primarily intended to be useful to developers of git itself, but is being exposed as a user setting to e.g. help file better bug reports. This also adds a "GIT_TEST_USAGE_ADD_SOURCE" setting intended to run the test suite in this mode. Currently it has a lot of failures. Most of those are rather trivial, and can be "fixed" by pointing GIT_TEST_CMP to a "diff -u" that does a s/^(usage|fatal|error|warning): [^:]+:[0-9]+/$1/g on its input files, and likewise for a "grep" wrapper that does the same. Even if we can't run the tests in this mode yet I'd like to have this for ad-hoc debugging, and to make it easier to work towards running the tests in this mode. If we can turn this on permanently it'll be much easier to read test output, as we won't need to worry about the indirection of looking up where an error might have been emitted, which can be especially painful when the message being emitted isn't unique within git.git. This new code needs to be guarded by the "dying" variable for the reasons explained in 2d3c02f (die(): stop hiding errors due to overzealous recursion guard, 2017-06-21), and for those same reasons it's racy under multi-threading. Here the worst case is that incrementing the variable will run away from us, and we won't get our desired <file>:<line> number. That's OK in this case, those cases should be isolated to the config code (if we can't parse the config), memory allocation etc, but we'll get it right in the common cases. Using GIT_TEST_USAGE_ADD_SOURCE should be immune from any racyness, as it only needs a getenv() and git_parse_maybe_bool(), which won't die. Add a repo_cfg_bool_env() wrapper to repo-settings.c for GIT_TEST_USAGE_ADD_SOURCE, in 3050b6d (repo-settings.c: simplify the setup, 2021-09-21) I indicated that the GIT_TEST_MULTI_PACK_INDEX env variable/config pair in that file has odd semantics, but users of repo_cfg_bool_env() have straightforward and expected semantics. If the environment variable is set (true or false) we'll use it, otherwise we'll use the config, and finally fall back on the default (of "false", in this case). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Loading branch information