Tanay Abhra writes:
> git_default_config() now uses config-set API functions to query for
> values.
>
> Signed-off-by: Tanay Abhra
> ---
> 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/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html