git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 2/5] notes.c: replace `git_config()` with `git_config_get_value_multi()`

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Jul 31, 2014, 11:38 UTC
Message-ID
<vpqmwbpdagf.fsf@anie.imag.fr>
In-Reply-To
<vpqsiliol1o.fsf@anie.imag.fr>
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 27 quoted lines
> Tanay Abhra <tanayabh@gmail.com> writes:
>
>> On 7/30/2014 7:43 PM, Matthieu Moy wrote:
>>> * if (!values->items[i].string)
>>>           config_error_nonbool(
>>> 
>>>   => This check could be done once and for all in a function, say
>>>   git_config_get_value_multi_nonbool, a trivial wrapper around
>>>   git_config_get_value_multi like
>>> 
>>> const struct string_list *git_configset_get_value_multi_nonbool(struct config_set *cs, const char *key)
>>> {
>>> 	struct string_list l = git_configset_get_value_multi(cs, key);
>>>         // possibly if(l) depending on the point above.
>>> 	for (i = 0; i < values->nr; i++) {
>>> 		if (!values->items[i].string)
>>> 			git_config_die(key);
>>> 	}
>>> 	return l;
>>> }
>>>
>>
>> Not worth it, most the multi value calls do not die on a nonbool.
>
> Can you cite some multi-value variables that can be nonbool? I can't
> find many multi-valued variables, and I can't find any which would allow
> bool and nonbool.

Thinking a bit more about it: we actually need more than your patch and my code example above to give accurate error messages. Your code gives no error message, and mine uses git_config_die(key); which gives the line of the _last_ entry, but not necessarily the right line.

The right line number should be extracted from the info field of the string_list. It's not completely trivial, hence I'd rather have a helper doing it well in config.c than letting callers re-do the check and possibly give wrong line in their error message as I did in my first attempt.

I think you can introduce a helper git_config_die_linenr(key, linenr) that displays the right error message. Then git_config_die becomes a wrapper around it that does the lookup to find linenr from the hash.

You already have a duplicate piece of code in your other series:
			if (!kv_info->linenr)
				die("unable to parse '%s' from command-line config", entry->key);
			else
				die("bad config variable '%s' at file line %d in %s",
					entry->key,
					kv_info->linenr,
					kv_info->filename);
That would be the content of git_config_die_linenr().
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Matthieu MoyNext: Tanay Abhra
Message 7 of 16 in “git_config callers rewritten with the new config cache API”
  1. 0/5 git_config callers rewritten with the new config cache APITanay Abhra, Jul 30, 2014
  2. 1/5 pager.c: replace `git_config()` with `git_config_get_value()`Tanay Abhra, Jul 30, 2014
  3. 2/5 notes.c: replace `git_config()` with `git_config_get_value_multi()`Tanay Abhra, Jul 30, 2014
  4. Matthieu MoyJul 30, 2014
  5. Tanay AbhraJul 30, 2014
  6. Matthieu MoyJul 30, 2014
  7. Matthieu MoyJul 31, 2014
  8. Tanay AbhraJul 31, 2014
  9. 3/5 imap-send.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Jul 30, 2014
  10. 4/5 branch.c: replace `git_config()` with `git_config_get_string()Tanay Abhra, Jul 30, 2014
  11. Matthieu MoyJul 30, 2014
  12. 5/5 alias.c: replace `git_config()` with `git_config_get_string()`Tanay Abhra, Jul 30, 2014
  13. Matthieu MoyJul 30, 2014
  14. Tanay AbhraJul 30, 2014
  15. Matthieu MoyJul 30, 2014
  16. Ramsay JonesJul 31, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.