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

Re: [PATCH/RFC v2 1/2] git_default_config() rewritten using the config-set API

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Aug 13, 2014, 16:16 UTC
Message-ID
<vpqa978qs9f.fsf@anie.imag.fr>
In-Reply-To
<53EB6914.2030807@gmail.com>
Tanay Abhra <tanayabh@gmail.com> writes:
Show 12 quoted lines
> git_default_config() now uses config-set API functions to query for
> values.
>
> Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
> ---
> Sorry, for the short log message, I will explain why.
> The git_default_config() rewrite is 100% complete, the only
> problem remains is the call sites; there are too many of them.
> Some are called from callback functions which pass the remaining
> variables to git_default_config() which they do not have any use for.
> Those call sites can remain as they are, because git_default_config()
> is a single call function now, and is guarded by a sentinel value.

They can remain as they are, but it would also be relatively easy to turn them into non-callback style by doing something like this on each call:

--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -37,7 +37,7 @@ static int commit_tree_config(const char *var, const char *value, void *cb)
                sign_commit = git_config_bool(var, value) ? "" : NULL;
                return 0;
        }
-       return git_default_config(var, value, cb);
+       return 0
 }
 
 int cmd_commit_tree(int argc, const char **argv, const char *prefix)
@@ -49,6 +49,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
        struct strbuf buffer = STRBUF_INIT;
 
        git_config(commit_tree_config, NULL);
+       git_default_config();
 
        if (argc < 2 || !strcmp(argv[1], "-h"))
                usage(commit_tree_usage);

> -int git_default_config(const char *var, const char *value, void *dummy)
> +int git_default_config(const char *unused, const char *unused2, void *dummy)

By having these dummy arguments, you force callers to pass dummy actual
parameters.

Actually, you don't pass anything in PATCH 2, hence the result is not
compilable:

http-fetch.c:70:2: error: too few arguments to function ‘git_default_config’
  git_default_config();
  ^
In file included from http-fetch.c:1:0:
cache.h:1299:12: note: declared here
 extern int git_default_config(const char *, const char *, void *);

After your patch, there are two things git_default_config do:

1) normal callers want to call git_default_config();

2) callback-style callers want to write
   return git_default_config(var, value, cb);

I think this deserves two functions, calling each others:

/* For 1) */
void git_load_default_config(void)
{
	do the actual stuff
}

/* For 2) */
int git_default_config(const char *unused, const char *unused2, void *dummy)
{
	if (default_config_loaded)
		return;
	git_load_default_config(NULL, NULL, NULL);
	default_config_loaded = 1;
	return 0;
}

In an ideal world, git_default_config would disappear after the rewrite
is completed. In practice, it may stay if needed, it doesn't harm
anyone.

PATCH 2 would turn git_config(git_default_config, NULL); into
git_load_default_config().

> @@ -2082,6 +1977,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
>
>  	/* Invalidate the config cache */
>  	git_config_clear();
> +	default_config_loaded = 0;

What about the other callsite in setup.c? We may have left the
configuration half-loaded, and if anyone calls git_load_default_config()
again after that, we do want to reload it, don't we?

Which leads to another question: why not put this default_config_loaded
= 0; inside git_config_clear(), to avoid forgetting?

> index 1d9b6e7..0db595f 100644
> --- a/ident.c
> +++ b/ident.c
> @@ -392,29 +392,26 @@ int author_ident_sufficiently_given(void)
>  	return ident_is_sufficient(author_ident_explicitly_given);
>  }
>
> -int git_ident_config(const char *var, const char *value, void *data)
> +void git_ident_config(void)
>  {
> -	if (!strcmp(var, "user.name")) {
> +	const char *value = NULL;
> +
> +	if (!git_config_get_value("user.name", &value)) {
>  		if (!value)
> -			return config_error_nonbool(var);
> +			git_die_config("user.name", "Missing value for 'user.name'");

I'd rather have git_config_get_string() and a free() afterwards to avoid
duplicating this "Missing value for 'user.name'" (which should be _()-ed
if it stays).

> -
> -	if (!strcmp(var, "user.email")) {
> +	if (!git_config_get_value("user.email", &value)) {
>  		if (!value)
> -			return config_error_nonbool(var);
> +			git_die_config("user.email", "Missing value for 'user.email'");

Likewise.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 19 in “fast-import.c: replace `git_config()` with `git_config_get_*()` family”
  1. 1/4 fast-import.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Aug 13, 2014
  2. 2/4 ll-merge.c: refactor `read_merge_config()` to use `git_config_string()`Tanay Abhra, Aug 13, 2014
  3. Matthieu MoyAug 13, 2014
  4. 2/4 ll-merge.c: refactor `read_merge_config()` to use `git_config_string()`Tanay Abhra, Aug 13, 2014
  5. Matthieu MoyAug 13, 2014
  6. Junio C HamanoAug 13, 2014
  7. 3/4 merge-recursive.c: replace `git_config()` with `git_config_get_int()`Tanay Abhra, Aug 13, 2014
  8. Matthieu MoyAug 13, 2014
  9. 4/4 builtin/apply.c: replace `git_config()` with `git_config_get_string_const()`Tanay Abhra, Aug 13, 2014
  10. Matthieu MoyAug 13, 2014
  11. Tanay AbhraAug 13, 2014
  12. 1/5 fast-import.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Aug 13, 2014
  13. Matthieu MoyAug 13, 2014
  14. 1/2 git_default_config() rewritten using the config-set APITanay Abhra, Aug 13, 2014
  15. 2/2 use the new git_default_config()Tanay Abhra, Aug 13, 2014
  16. Matthieu MoyAug 13, 2014
  17. Junio C HamanoAug 13, 2014
  18. Matthieu MoyAug 13, 2014
  19. Junio C HamanoAug 13, 2014

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.