From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
To: Tanay Abhra <tanayabh@gmail.com>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>
Subject: Re: [PATCH/RFC v2 1/2] git_default_config() rewritten using the config-set API
Date: Wed, 13 Aug 2014 18:16:44 +0200 [thread overview]
Message-ID: <vpqa978qs9f.fsf@anie.imag.fr> (raw)
In-Reply-To: <53EB6914.2030807@gmail.com> (Tanay Abhra's message of "Wed, 13 Aug 2014 19:03:08 +0530")
Tanay Abhra <tanayabh@gmail.com> writes:
> 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/
next prev parent reply other threads:[~2014-08-13 16:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-13 8:21 [PATCH 1/4] fast-import.c: replace `git_config()` with `git_config_get_*()` family Tanay Abhra
2014-08-13 8:22 ` [PATCH 2/4] ll-merge.c: refactor `read_merge_config()` to use `git_config_string()` Tanay Abhra
2014-08-13 11:32 ` Matthieu Moy
2014-08-13 12:43 ` [PATCH v2 " Tanay Abhra
2014-08-13 13:07 ` Matthieu Moy
2014-08-13 17:07 ` Junio C Hamano
2014-08-13 8:22 ` [PATCH 3/4] merge-recursive.c: replace `git_config()` with `git_config_get_int()` Tanay Abhra
2014-08-13 11:34 ` Matthieu Moy
2014-08-13 8:22 ` [PATCH 4/4] builtin/apply.c: replace `git_config()` with `git_config_get_string_const()` Tanay Abhra
2014-08-13 11:24 ` [PATCH 1/4] fast-import.c: replace `git_config()` with `git_config_get_*()` family Matthieu Moy
2014-08-13 12:11 ` Tanay Abhra
2014-08-13 12:22 ` [PATCH v2 1/5] " Tanay Abhra
2014-08-13 13:10 ` Matthieu Moy
2014-08-13 13:33 ` [PATCH/RFC v2 1/2] git_default_config() rewritten using the config-set API Tanay Abhra
2014-08-13 13:39 ` [PATCH/RFC v2 2/2] use the new git_default_config() Tanay Abhra
2014-08-13 16:00 ` [PATCH/RFC v2 1/2] git_default_config() rewritten using the config-set API Matthieu Moy
2014-08-13 17:18 ` Junio C Hamano
2014-08-13 16:16 ` Matthieu Moy [this message]
2014-08-13 17:14 ` [PATCH 1/4] fast-import.c: replace `git_config()` with `git_config_get_*()` family Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=vpqa978qs9f.fsf@anie.imag.fr \
--to=matthieu.moy@grenoble-inp.fr \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=tanayabh@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.