From: Ramsay Jones <ramsay@ramsay1•demon.co.uk>
To: Tanay Abhra <tanayabh@gmail•com>, git@vger•kernel.org
Cc: Ramkumar Ramachandra <artagnon@gmail•com>,
Matthieu Moy <Matthieu.Moy@grenoble-inp•fr>,
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 12:15:51 +0100 [thread overview]
Message-ID: <53B92FE7.6010707@ramsay1.demon.co.uk> (raw)
In-Reply-To: <1404631162-18556-2-git-send-email-tanayabh@gmail.com>
On 06/07/14 08:19, Tanay Abhra wrote:
> Currently `git_config()` uses a callback mechanism and file rereads for
> config values. Due to this approach, it is not uncommon for the config
> files to be parsed several times during the run of a git program, with
> different callbacks picking out different variables useful to themselves.
>
> Add a `config_set`, that can be used to construct an in-memory cache for
> config-like files that the caller specifies (i.e., files like `.gitmodules`,
> `~/.gitconfig` etc.). Add two external functions `git_configset_get_value`
> and `git_configset_get_value_multi` for querying from the config sets.
> `git_configset_get_value` follows `last one wins` semantic (i.e. if there
> are multiple matches for the queried key in the files of the configset the
> value returned will be the last entry in `value_list`).
> `git_configset_get_value_multi` returns a list of values sorted in order of
> increasing priority (i.e. last match will be at the end of the list). Add
> type specific query functions like `git_configset_get_bool` and similar.
>
> 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()`.
>
> Add two external functions `git_config_get_value` and
> `git_config_get_value_multi` for querying in a non-callback manner from
> `the_config_set`. Also, add type specific query functions that are
> implemented as a thin wrapper around the `config_set` API.
>
> Signed-off-by: Tanay Abhra <tanayabh@gmail•com>
> ---
> Documentation/technical/api-config.txt | 134 +++++++++++++++
> Makefile | 1 +
> cache.h | 34 ++++
> config-hash.c | 297 +++++++++++++++++++++++++++++++++
> config.c | 3 +
> 5 files changed, 469 insertions(+)
> create mode 100644 config-hash.c
>
> diff --git a/Documentation/technical/api-config.txt b/Documentation/technical/api-config.txt
> index 230b3a0..bdf86d0 100644
> --- a/Documentation/technical/api-config.txt
> +++ b/Documentation/technical/api-config.txt
> @@ -77,6 +77,81 @@ To read a specific file in git-config format, use
> `git_config_from_file`. This takes the same callback and data parameters
> as `git_config`.
>
> +Querying For Specific Variables
> +-------------------------------
> +
> +For programs wanting to query for specific variables in a non-callback
> +manner, the config API provides two functions `git_config_get_value`
> +and `git_config_get_value_multi`. They both read values from an internal
> +cache generated previously from reading the config files.
> +
> +`int git_config_get_value(const char *key, const char **value)`::
> +
> + Finds the highest-priority value for the configuration variable `key`,
> + stores the pointer to it in `value` and returns 0. When the
> + configuration variable `key` is not found, returns 1 without touching
> + `value`. The caller should not free or modify `value`, as it is owned
> + by the cache.
> +
> +`const struct string_list *git_config_get_value_multi(const char *key)`::
> +
> + Finds and returns the value list, sorted in order of increasing priority
> + for the configuration variable `key`. When the configuration variable
> + `key` is not found, returns NULL. The caller should not free or modify
> + the returned pointer, as it is owned by the cache.
> +
> +`void git_config_clear(void)`::
> +
> + Resets and invalidate the config cache.
> +
> +The config API also provides type specific API functions which do conversion
> +as well as retrieval for the queried variable, including:
> +
> +`int git_config_get_int(const char *key, int *dest)`::
> +
> + Finds and parses the value to an integer for the configuration variable
> + `key`. Dies on error; otherwise, stores pointer to the parsed integer in
... stores the value of the parsed integer in `dest` ...
> + `dest` and returns 0. When the configuration variable `key` is not found,
> + returns 1 without touching `dest`.
> +
> +`int git_config_get_ulong(const char *key, unsigned long *dest)`::
> +
> + Similar to `git_config_get_int` but for unsigned longs.
> +
> +`int git_config_get_int(const char *key, int *dest)`::
-----------------------^^^
git_config_get_bool
> +
> + Finds and parses the value into a boolean value, for the configuration
> + variable `key`respecting keywords like "true" and "false". Integer
> + values are converted into true/false values (when they are non-zero or
> + zero, respectively). Other values cause a die(). If parsing is successful,
> + stores the pointer to the parsed result in `dest` and returns 0. When the
... stores the value of the parsed result in `dest` ...
> + configuration variable `key` is not found, returns 1 without touching
> + `dest`.
> +
> +`int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest)`::
> +
> + Similar to `git_config_get_bool`, except that integers are copied as-is,
> + and `is_bool` flag is unset.
> +
> +`int git_config_get_maybe_bool(const char *key, int *dest)`::
> +
> + Similar to `git_config_get_bool`, except that it returns -1 on error
> + rather than dying.
> +
> +`int git_config_get_string(const char *key, const char **dest)`::
> +
> + Allocates and copies the retrieved string into the `dest` parameter for
> + the configuration variable `key`; if NULL string is given, prints an
> + error message and returns -1. When the configuration variable `key` is
> + not found, returns 1 without touching `dest`.
> +
> +`int git_config_get_pathname(const char *key, const char **dest)`::
> +
> + Similar to `git_config_get_string`, but expands `~` or `~user` into
> + the user's home directory when found at the beginning of the path.
> +
> +See test-config.c for usage examples.
> +
Sorry, I didn't have time to do more than squint at the code, but at first
glance it looks good.
ATB,
Ramsay Jones
next prev parent reply other threads:[~2014-07-06 11:16 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 [this message]
2014-07-06 17:45 ` Matthieu Moy
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=53B92FE7.6010707@ramsay1.demon.co.uk \
--to=ramsay@ramsay1$(echo .)demon.co.uk \
--cc=Matthieu.Moy@grenoble-inp$(echo .)fr \
--cc=artagnon@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=sunshine@sunshineco$(echo .)com \
--cc=tanayabh@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox