From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
To: Tanay Abhra <tanayabh@gmail.com>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v5 1/2] add `config_set` API for caching config-like files
Date: Sun, 06 Jul 2014 19:45:09 +0200 [thread overview]
Message-ID: <vpqa98m8jq2.fsf@anie.imag.fr> (raw)
In-Reply-To: <1404631162-18556-2-git-send-email-tanayabh@gmail.com> (Tanay Abhra's message of "Sun, 6 Jul 2014 00:19:21 -0700")
Tanay Abhra <tanayabh@gmail.com> writes:
> Add a default `config_set`, `the_config_set` to cache all key-value pairs
> read from usual config files (repo specific .git/config, user wide
> ~/.gitconfig and the global /etc/gitconfig). `the_config_set` uses a
> single hashmap populated using `git_config()`.
"uses a single hashmap" is no longer relevant. Any config_set use a
single hashmap.
(The "populated using git_config()" part is still relevant OTOH)
> +`void git_configset_init(struct config_set *cs)`::
> +
> + Initializes the member variables of config_set `cs`.
I'd say just "initializes the config_set `cs`".
> +/*
> + * Default config_set that contains key-value pairs from the usual set of config
> + * config files (i.e repo specific .git/config, user wide ~/.gitconfig and the
> + * global /etc/gitconfig)
To be technically correct, "user wide ~/.gitconfig, XDG config file and
the global ...".
> +static int add_configset_hash(const char *filename, struct config_set *cs)
> +{
> + int ret = 0;
> + if (!cs->hash_initialized)
> + config_hash_init(&cs->config_hash);
> + cs->hash_initialized = 1;
That would seem more natural to me to have a function config_set_init
instead of config_hash_init, that would set hash_initialized.
config_hash_init is currently a one-liner, so there's no risk of making
it too complex.
> +static int config_hash_add_value(const char *key, const char *value, struct hashmap *config_hash)
> +{
> + struct config_hash_entry *e;
> + e = config_hash_find_entry(key, config_hash);
> +
> + if (!e) {
> + e = xmalloc(sizeof(*e));
> + hashmap_entry_init(e, strhash(key));
Nitpick: you're hashing the same string twice. Once for
config_hash_find_entry, and another here. It would be slightly faster to
allow config_hash_find_entry to return the hashcode (as a by-address
parameter).
But you may want to keep the code as it is for simplicity.
It took me some time to understand why you normalize in
config_hash_find_entry and not here. My understanding is that
config_hash_find_entry is used to query the hashmap from the user API
(so you need normalization), but this particular codepath receives
normalized keys (the comment right below states that for values).
It's probably worth a comment here and/or in config_hash_find_entry.
> + }
> + /*
> + * Since the values are being fed by git_config*() callback mechanism, they
> + * are already normalized. So simply add them without any further munging.
> + */
> + string_list_append_nodup(&e->value_list, value ? xstrdup(value) : NULL);
> +
> + return 0;
> +}
[...]
> +int git_configset_add_file(struct config_set *cs, const char *filename)
> +{
> + return add_configset_hash(filename, cs);
> +}
Why have two functions doing the same, with arguments in different
orders?
I guess it's just historical, and you can keep only one.
> +void git_configset_clear(struct config_set *cs)
> +{
> + struct config_hash_entry *entry;
> + struct hashmap_iter iter;
> + if (!cs->hash_initialized)
> + return;
> +
> + hashmap_iter_init( &cs->config_hash, &iter);
No space after (.
> +int git_config_get_string(const char *key, const char **dest)
> +{
> + git_config_check_init();
> + return git_configset_get_string(&the_config_set, key, dest);
> +}
> +
> +int git_config_get_int(const char *key, int *dest)
> +{
> + git_config_check_init();
> + return git_configset_get_int(&the_config_set, key, dest);
> +}
Reading this list, I initially thought it might be worth factoring this
in a macro. But the list isn't that long, and contains several
special-cases (3 parameters instead of 2). So, don't bother.
OK, we're getting close. v6 should be really good :-).
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
next prev parent reply other threads:[~2014-07-06 17:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-06 7:19 [PATCH v5 0/3] git config cache & special querying api utilizing the cache Tanay Abhra
2014-07-06 7:19 ` [PATCH v5 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-06 11:15 ` Ramsay Jones
2014-07-06 17:45 ` Matthieu Moy [this message]
2014-07-06 7:19 ` [PATCH v5 2/2] test-config: Add tests for the config_set API Tanay Abhra
2014-07-06 18:33 ` Matthieu Moy
2014-07-06 19:57 ` Matthieu Moy
2014-07-06 23:24 ` Ramkumar Ramachandra
2014-07-07 7:11 ` Matthieu Moy
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=vpqa98m8jq2.fsf@anie.imag.fr \
--to=matthieu.moy@grenoble-inp.fr \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
--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.