git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tanay Abhra <tanayabh@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
	Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: Re: [PATCH v9 1/2] add `config_set` API for caching config-like files
Date: Tue, 15 Jul 2014 21:52:18 +0530	[thread overview]
Message-ID: <53C5553A.2090700@gmail.com> (raw)
In-Reply-To: <xmqqoawqwrov.fsf@gitster.dls.corp.google.com>



On 7/15/2014 9:16 PM, Junio C Hamano wrote:
> Tanay Abhra <tanayabh@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.

  reply	other threads:[~2014-07-15 16:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-15 14:29 [PATCH v9 0/3] git config cache & special querying api utilizing the cache Tanay Abhra
2014-07-15 14:29 ` [PATCH v9 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-15 15:46   ` Junio C Hamano
2014-07-15 16:22     ` Tanay Abhra [this message]
2014-07-16 11:41     ` [PATCH v9r1 " Tanay Abhra
2014-07-15 14:29 ` [PATCH v9 2/2] test-config: add tests for the config_set API Tanay Abhra
2014-07-15 15:57   ` Junio C Hamano
2014-07-15 17:07     ` Tanay Abhra
2014-07-15 18:26       ` Junio C Hamano
2014-07-16 11:44     ` [PATCH v9r1 " Tanay Abhra
2014-07-16 11:49       ` Matthieu Moy
2014-07-16 12:22         ` [PATCH v9r2 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-16 16:06           ` Matthieu Moy
2014-07-16 16:09             ` [PATCH 1/3] fixup for patch 2: minor style fix Matthieu Moy
2014-07-16 16:09               ` [PATCH 2/3] fixup for patch 2: actually check the return value Matthieu Moy
2014-07-16 16:55                 ` Tanay Abhra
2014-07-16 17:10                   ` Matthieu Moy
2014-07-16 16:09               ` [PATCH 3/3] fixup for patch 1: typo Matthieu Moy
2014-07-16 16:44             ` [PATCH v9r2 1/2] add `config_set` API for caching config-like files Tanay Abhra
2014-07-16 17:06               ` Matthieu Moy
     [not found]                 ` <53C6C2BD.3030703@gmail.com>
2014-07-17 10:01                   ` Matthieu Moy
2014-07-17 11:06                     ` Tanay Abhra
2014-07-17 11:34                       ` Matthieu Moy
2014-07-17 11:13                     ` Matthieu Moy
2014-07-17 17:12                       ` Junio C Hamano
2014-07-16 12:22         ` [PATCH v9r2 2/2] test-config: add tests for the config_set API Tanay Abhra

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=53C5553A.2090700@gmail.com \
    --to=tanayabh@gmail.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=Matthieu.Moy@imag.fr \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).