Re: [PATCH v9 1/2] add `config_set` API for caching config-like files

2014-07-15 Thread Junio C Hamano
Tanay Abhra tanay...@gmail.com writes:

 diff --git a/config.c b/config.c
 index ba882a1..89e2d67 100644
 --- a/config.c
 +++ b/config.c
 ...
 +const struct string_list *git_configset_get_value_multi(struct config_set 
 *cs, const char *key)
 +{
 + struct config_set_element *e = configset_find_element(cs, key);
 + return e ? e-value_list : NULL;
 +}

Somehow I find the placement of this function out of place.  Didn't
you get the same impression while proofreading the entire file after
you are done writing this patch?

The right place for it would probably be immediately before
git_configset_get_value(), I would think.

 +int git_configset_add_file(struct config_set *cs, const char *filename)
 +{
 + int ret = 0;
 + ret = git_config_from_file(config_hash_callback, filename, cs);
 + if (!ret)
 + return 0;
 + else {
 + git_configset_clear(cs);
 + return -1;
 + }
 +}

If I add contents from file A successfully and then attempt to
further add contents from file B which fails, I would lose
contents I read from A?

It would not be worth trying to make it transactional (i.e. making
sure cs contains what was there before the config-from-file was
called if it failed), so in such a case we may end up seeing a
mixture of full contents from A and partial contents from B, which
is just as useless as a cleared configset, so it is not wrong to
clear it per-se.  An alternative might be to return without
clearing, as we are leaving the configset in a useless state either
way and give the caller a choice between clearing it and continue,
and dying without even spending unnecessary cycles to clear.  That
might be more consistent with what git_config_check_init() does,
where you die without bothering to clear what was half-read into the
configset.

Whatever behaviour is chosen in the error codepath, it needs to be
documented.

Thanks.
--
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


Re: [PATCH v9 1/2] add `config_set` API for caching config-like files

2014-07-15 Thread Tanay Abhra


On 7/15/2014 9:16 PM, Junio C Hamano wrote:
 Tanay Abhra tanay...@gmail.com writes:
 
 diff --git a/config.c b/config.c
 index ba882a1..89e2d67 100644
 --- a/config.c
 +++ b/config.c
 ...
 +const struct string_list *git_configset_get_value_multi(struct config_set 
 *cs, const char *key)
 +{
 +struct config_set_element *e = configset_find_element(cs, key);
 +return e ? e-value_list : NULL;
 +}
 
 Somehow I find the placement of this function out of place.  Didn't
 you get the same impression while proofreading the entire file after
 you are done writing this patch?
 
 The right place for it would probably be immediately before
 git_configset_get_value(), I would think.


Noted. My fault, will correct in the reroll.

 +int git_configset_add_file(struct config_set *cs, const char *filename)
 +{
 +int ret = 0;
 +ret = git_config_from_file(config_hash_callback, filename, cs);
 +if (!ret)
 +return 0;
 +else {
 +git_configset_clear(cs);
 +return -1;
 +}
 +}
 
 If I add contents from file A successfully and then attempt to
 further add contents from file B which fails, I would lose
 contents I read from A?
 
 It would not be worth trying to make it transactional (i.e. making
 sure cs contains what was there before the config-from-file was
 called if it failed), so in such a case we may end up seeing a
 mixture of full contents from A and partial contents from B, which
 is just as useless as a cleared configset, so it is not wrong to
 clear it per-se.  An alternative might be to return without
 clearing, as we are leaving the configset in a useless state either
 way and give the caller a choice between clearing it and continue,
 and dying without even spending unnecessary cycles to clear.  That
 might be more consistent with what git_config_check_init() does,
 where you die without bothering to clear what was half-read into the
 configset.
 
 Whatever behaviour is chosen in the error codepath, it needs to be
 documented.


Since syntactical errors in reading the file will cause a die when we
use either `git_config_from_file` or `git_config`, I don't think
incomplete parsing would trigger the error path, as it will die before
reaching there.

So, the best way would be just to return without clearing and let the
user take the decision if he wants to go on with the incomplete
config_set or clear it when he sees that configset_add_file() failed.

Die in git_config_check_init() is never triggered expect in rare race
conditions like between access_or_die() and git_config_from_file() in

if (git_config_system()  !access_or_die(git_etc_gitconfig(), R_OK, 
0)) {
ret += git_config_from_file(fn, git_etc_gitconfig(),
data);
found += 1;
}
which I think would never happen in reality, dunno. I think I will take
out the die() in git_config_check_init(). Thus, the behavior of both
functions git_config_check_init()  git_configset_add_file will be consistent.

Thanks.


--
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