All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tanay Abhra <tanayabh@gmail.com>
To: "Torsten Bögershausen" <tboegi@web.de>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [RFC/PATCH 1/2] config: Add cache for config value querying
Date: Tue, 27 May 2014 06:54:38 -0700	[thread overview]
Message-ID: <5384991E.10409@gmail.com> (raw)
In-Reply-To: <53839DEE.9090504@web.de>

Hi,

On 05/26/2014 01:02 PM, Torsten Bögershausen wrote:
>> Add an internal cache with the all variable value pairs read from the usual
> "cache": The word "cache" is in Git often used for "index" 
Okay, point noted. I thought about choosing between "hashmap" and "cache" and chose
the later.
> "variable value" can be written as "key value"

I  had used the term "variable" to be consistent with the documentation
(api-config.txt). But I think "key" is much clearer.

> "usual": I don't think we handle "unusual" config files,
> (so can we drop the word usual ?)

Okay, noted.

> I think the (important) first line can be written like this:
> 
>> Add a hash table with the all key-value pairs read from the
> or
>> Add a hash table to cache all key-value pairs read from the
> 
>> config files(repo specific .git/config, user wide ~/.gitconfig and the global
>> /etc/gitconfig). Also, add two external functions `git_config_get_string` and
> Can we drop "Also" ?
>> @@ -37,6 +39,102 @@ static struct config_source *cf;
>>  
>>  static int zlib_compression_seen;
>>  
>> +struct hashmap config_cache;
>> +
>> +struct config_cache_node {
>> +	struct hashmap_entry ent;
>> +	struct strbuf key;
> Do we need a whole strbuf for the key?
> Or could a "char *key" work as well? 
> (and/or could it be "const char *key" ?

To maintain consistency with config.c. config.c uses strbuf for both key and value
throughout. I found the reason by git-blaming config.c. Key length is flexible so it
would be better to use a api construct such as strbuf for it.

>> +	struct string_list *value_list ;
> 
> 
> 
>> +static struct string_list *config_cache_get_value(const char *key)
>> +{
>> +	struct config_cache_node *e = config_cache_find_entry(key);
> why "e" ? Will "node" be easier to read ? Or entry ? 

Noted. Entry is much better.

>> +static void config_cache_set_value(const char *key, const char *value)
>> +{
>> +	struct config_cache_node *e;
>> +
>> +	if (!value)
>> +		return;
> Hm, either NULL could mean "unset==remove" the value, (but we don't do that, do we?
> 
> Or it could mean a programming or runtime error?, Should there be a warning ?

Nope. It is just a check to not save blank values for a key in the hashmap. Removal
functionality will come later. NULL==remove is implemented in
git_config_set_multivar_in_file(). We are not reading key value pairs from that, just
from git_config().
>> +
>> +	e = config_cache_find_entry(key);
>> +	if (!e) {
>> +		e = malloc(sizeof(*e));
>> +		hashmap_entry_init(e, strihash(key));
>> +		strbuf_init(&(e->key), 1024);
>> +		strbuf_addstr(&(e->key),key);
>> +		e->value_list = malloc(sizeof(struct string_list));
>> +		e->value_list->strdup_strings = 1;
>> +		e->value_list->nr = 0;
>> +		e->value_list->alloc = 0;
>> +		e->value_list->items = NULL;
>> +		e->value_list->cmp = NULL;
> When malloc() is replaced by xcalloc()  the x = NULL and y = 0 can go away,
> and the code is shorter and easier to read.

Much better, thanks.

>> +extern const char *git_config_get_string(const char *name)
>> +{
>> +	struct string_list *values;
>> +	int num_values;
>> +	char *result;
>> +	values = config_cache_get_value(name);
>> +	if (!values)
>> +		return NULL;
>> +	num_values = values->nr;
>> +	result = values->items[num_values-1].string ;
> We could get rid of the variable  "int num_values" by simply writing
> result = values->items[values->nr-1].string;
> 

Noted.


Cheers,
Tanay Abhra.

  reply	other threads:[~2014-05-27 13:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-26 17:33 [RFC/PATCH 0/2] Git config cache & special querying api utilizing the cache Tanay Abhra
2014-05-26 17:33 ` [RFC/PATCH 1/2] config: Add cache for config value querying Tanay Abhra
2014-05-26 20:02   ` Torsten Bögershausen
2014-05-27 13:54     ` Tanay Abhra [this message]
2014-05-28  9:31   ` Eric Sunshine
2014-05-26 17:33 ` [RFC/PATCH 2/2] config: Add new query functions to the api Tanay Abhra
2014-05-28  9:43   ` Eric Sunshine

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=5384991E.10409@gmail.com \
    --to=tanayabh@gmail.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=tboegi@web.de \
    /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.