git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/4] config API: don't use vreportf(), make it static in usage.c

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 6, 2021, 21:26 UTC
Message-ID
<xmqqfsr5e87e.fsf@gitster.g>
In-Reply-To
<patch-4.4-e0e6427cbd3-20211206T165221Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 8 quoted lines
> In preceding commits the rest of the vreportf() users outside of
> usage.c have been migrated to die_message(), leaving only the
> git_die_config() function added in 5a80e97c827 (config: add
> `git_die_config()` to the config-set API, 2014-08-07).
>
> Let's have its callers call error() themselves if they want to emit a
> message, which is exactly what git_die_config() was doing for them
> before emitting its own die() message.

I do not quite get this. If git_die_config() has been showing the message for them, and if the existing callers can just use error(), why not git_die_config() call error() on behalf of these callers?

Show 15 quoted lines
> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> index 2b2e28bad79..4e2432bb491 100644
> --- a/builtin/fast-import.c
> +++ b/builtin/fast-import.c
> @@ -3456,9 +3456,10 @@ static void git_pack_config(void)
>  	}
>  	if (!git_config_get_int("pack.indexversion", &indexversion_value)) {
>  		pack_idx_opts.version = indexversion_value;
> -		if (pack_idx_opts.version > 2)
> -			git_die_config("pack.indexversion",
> -					"bad pack.indexversion=%"PRIu32, pack_idx_opts.version);
> +		if (pack_idx_opts.version > 2) {
> +			error("bad pack.indexversion=%"PRIu32, pack_idx_opts.version);
> +			git_die_config("pack.indexversion");
> +		}

This is exactly what triggered the question above, and the pattern repeats elsewhere, too.

Show 17 quoted lines
> @@ -2550,18 +2552,12 @@ void git_die_config_linenr(const char *key, const char *filename, int linenr)
>  		    key, filename, linenr);
>  }
>  
> -NORETURN __attribute__((format(printf, 2, 3)))
> -void git_die_config(const char *key, const char *err, ...)
> +NORETURN
> +void git_die_config(const char *key)
>  {
>  	const struct string_list *values;
>  	struct key_value_info *kv_info;
>  
> -	if (err) {
> -		va_list params;
> -		va_start(params, err);
> -		vreportf("error: ", err, params);
> -		va_end(params);

I get that we do not want to expose vreportf() to this caller, and I agree with the goal, but wouldn't it be the matter of calling get_error_routine() and calling it with err and params here, instead of losing the whole block? Is that insufficient to avoid toucing all the callers?

Show 9 quoted lines
> diff --git a/git-compat-util.h b/git-compat-util.h
> index c6c6f7d6b51..bdb3977b9ec 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -474,7 +474,6 @@ static inline int git_has_dir_sep(const char *path)
>  struct strbuf;
>  
>  /* General helper functions */
> -void vreportf(const char *prefix, const char *err, va_list params);
Good.
Show 10 quoted lines
> diff --git a/usage.c b/usage.c
> index 3d09e8eea48..9943dd8742e 100644
> --- a/usage.c
> +++ b/usage.c
> @@ -6,7 +6,7 @@
>  #include "git-compat-util.h"
>  #include "cache.h"
>  
> -void vreportf(const char *prefix, const char *err, va_list params)
> +static void vreportf(const char *prefix, const char *err, va_list params)
Good, too.
Thanks.
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 8 of 22 in “usage API: Add and use die_message()”
  1. 0/4 usage API: Add and use die_message()Ævar Arnfjörð Bjarmason, Dec 6, 2021
  2. 2/4 usage.c API users: use die_message() where appropriateÆvar Arnfjörð Bjarmason, Dec 6, 2021
  3. Junio C HamanoDec 6, 2021
  4. 1/4 usage.c: add a die_message() routineÆvar Arnfjörð Bjarmason, Dec 6, 2021
  5. Junio C HamanoDec 6, 2021
  6. Junio C HamanoDec 6, 2021
  7. 4/4 config API: don't use vreportf(), make it static in usage.cÆvar Arnfjörð Bjarmason, Dec 6, 2021
  8. Junio C HamanoDec 6, 2021
  9. Ævar Arnfjörð BjarmasonDec 7, 2021
  10. 3/4 usage.c + gc: add and use a die_message_errno()Ævar Arnfjörð Bjarmason, Dec 6, 2021
  11. Junio C HamanoDec 6, 2021
  12. 0/6 usage API: Add and use die_message()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  13. 1/6 usage.c: add a die_message() routineÆvar Arnfjörð Bjarmason, Dec 7, 2021
  14. 2/6 usage.c API users: use die_message() for "fatal :" + exit 128Ævar Arnfjörð Bjarmason, Dec 7, 2021
  15. 3/6 usage.c API users: use die_message() for error() + exit 128Ævar Arnfjörð Bjarmason, Dec 7, 2021
  16. 4/6 gc: return from cmd_gc(), don't call exit()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  17. 5/6 usage.c + gc: add and use a die_message_errno()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  18. 6/6 config API: use get_error_routine(), not vreportf()Ævar Arnfjörð Bjarmason, Dec 7, 2021
  19. Junio C HamanoDec 7, 2021
  20. Jonathan TanDec 22, 2021
  21. Junio C HamanoDec 22, 2021
  22. Ævar Arnfjörð BjarmasonDec 24, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.