All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tanay Abhra <tanayabh@gmail.com>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>
Subject: Re: [PATCH v4 3/6] rewrite git_config() to use the config-set API
Date: Tue, 29 Jul 2014 19:02:48 +0530	[thread overview]
Message-ID: <53D7A280.6080201@gmail.com> (raw)
In-Reply-To: <vpqlhrc8hif.fsf@anie.imag.fr>



On 7/29/2014 6:10 PM, Matthieu Moy wrote:
> Tanay Abhra <tanayabh@gmail.com> writes:
> 
> configset_iter unconditionnally returns 0 (or it dies). Since it is more
> or less the equivalent of the old git_config(), I understand why we
> never encounter the situation where git_config() would return -1 (syntax
> error, weird permission issue => cannot happen when reading from
> memory).
> 
> But then, do we really want this return value, and not just return void?
>

Sounds sane to me.

>> +static void git_config_check_init(void);
>> +
>> +int git_config(config_fn_t fn, void *data)
>> +{
>> +	git_config_check_init();
>> +	return configset_iter(&the_config_set, fn, data);
>> +}
> 
> Here too, git_config now unconditionnally returns 0.
> 
> Most callers of git_config already ignore the return value. Actually,
> there's only one exception in branch.c, but git still compiles with
> this:
>

branch.c is in my git_config() rewrite patch so it should not be a problem
in the future even if it was the case.

> 
> So, I think it's time to make it official that git_config() does not
> return an error code, and make it return void. I would do that in a
> patch before the git_config() -> git_config_raw() rewrite.
> 
> My preference would be to get the return value from
> git_config_with_options and die() if it's negative, but I can also live

Doesn't git_config_with_options() only return positive values, we checked it
pretty intensively last time.

> with a solution where the return value from git_config_with_options() is
> ignored. It's the same discussion we already had about the call to
> git_config() in git_config_check_init() actually, but I now think a
> die() statement should be within git_config(), not after, so that every
> callers benefit from it.

The above patch works like that, doesn't it?

> 
> In any case, doing this in a separate patch means the commit message
> (and possibly a comment next to the git_config() call) should explain
> the situation clearly and justify the choice.
>

The choice being not to return a error code for git_config()?
I am pretty much confused by now.

> The current situation looks like someone tried to get good error
> recovery, but the error code is lost in the way between
> git_config_with_options() and the caller of git_config(), without a
> clear justification of why an error code was once returned, nor a
> justification of why it was later ignored.
> 
> So, in summary, my advice (but not the only option) would be: take my
> patch above, add a die() statement and a comment, write a good commit

Where can the die() statement be inserted? Again, I am confused.
Only thing which sounds reasonable to me is to rewrite existing git_config()
as void first. Other than that, it went over my head.

> message and insert this before this patch.
> 
>>  static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)
>>  {
>>  	struct config_set_element k;
>> @@ -1268,6 +1296,7 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
>>  {
>>  	struct config_set_element *e;
>>  	struct string_list_item *si;
>> +	struct configset_list_item *l_item;
>>  	struct key_value_info *kv_info = xmalloc(sizeof(*kv_info));
>>  
>>  	e = configset_find_element(cs, key);
>> @@ -1283,6 +1312,12 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
>>  		hashmap_add(&cs->config_hash, e);
>>  	}
>>  	si = string_list_append_nodup(&e->value_list, value ? xstrdup(value) : NULL);
>> +
>> +	ALLOC_GROW(cs->list.items, cs->list.nr + 1, cs->list.alloc);
>> +	l_item = &cs->list.items[cs->list.nr++];
>> +	l_item->e = e;
>> +	l_item->value_index = e->value_list.nr - 1;
> 
> I would spell this
> 
> 	l_item = &cs->list.items[cs->list.nr];
> 	l_item->e = e;
> 	l_item->value_index = e->value_list.nr;
> 	cs->list.nr++;
> 
> to avoid having to wonder why the "- 1" is needed. But I'm OK with the
> current code.
> 

Yup, you are right. Thanks.

  reply	other threads:[~2014-07-29 13:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 11:28 [PATCH v4 0/6] Rewrite `git_config()` using config-set API Tanay Abhra
2014-07-29 11:28 ` [PATCH v4 1/6] config.c: fix accuracy of line number in errors Tanay Abhra
2014-07-29 11:28 ` [PATCH v4 2/6] add line number and file name info to `config_set` Tanay Abhra
2014-07-29 11:28 ` [PATCH v4 3/6] rewrite git_config() to use the config-set API Tanay Abhra
2014-07-29 11:35   ` Tanay Abhra
2014-07-29 12:38     ` Matthieu Moy
2014-07-29 12:40   ` Matthieu Moy
2014-07-29 13:32     ` Tanay Abhra [this message]
2014-07-29 14:03       ` Matthieu Moy
2014-07-29 17:49         ` Tanay Abhra
2014-07-29 11:28 ` [PATCH v4 4/6] add a test for semantic errors in config files Tanay Abhra
2014-07-29 11:28 ` [PATCH v4 5/6] config: add `git_die_config()` to the config-set API Tanay Abhra
2014-07-29 11:28 ` [PATCH v4 6/6] add tests for `git_config_get_string_const()` 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=53D7A280.6080201@gmail.com \
    --to=tanayabh@gmail.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    /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.