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

Re: [PATCH v2] help.c: configurable suggestions

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 17, 2020, 21:25 UTC
Message-ID
<xmqq4kln65gh.fsf@gitster.c.googlers.com>
In-Reply-To
<20201117152535.9795-1-sir@cmpwn.com>
Drew DeVault <sir@cmpwn.com> writes:
> -	if (!strcmp(var, "help.autocorrect"))
> -		autocorrect = git_config_int(var,value);
> +	if (!strcasecmp(var, "help.autocorrect")) {

This is an unwarranted change. The first part and the last part of a configuration variable name are downcased before the config callback functions are called, so strcmp() is sufficient.

> +		if (!value)
> +			return config_error_nonbool(var);
This is to protect us against
	[help]
		autocorrect

(i.e. "true" expressed without "= true"), which is not strictly needed when the only thing we do with value is git_config_int() because it knows how to handle value==NULL case. But it starts to matter when parsing variables with more elaborate shape, like "int or some known token".

And because we want to keep the promise "if you write negative value, it means immediate" we made to our users, we can instead make this variable "number or 'never'". To do so, keep that "barf if NULL" check above, and then add something like:

		if (!strcmp(value, "never"))
			autocorrect = AUTOCORRECT_NEVER;
		else {
			int v = git_config_int(var, value);
                        autocorrect = (v < 0) 
				? AUTOCORRECT_IMMEDIATELY : v;
		}

The configuration the end user has may say '-2', but that is different from 'never', so instead of leaving a negative value as is, like this code below does ...

> +		autocorrect = git_config_int(var, value);

... we normalize any negative value the user gave us to AUTOCORRECT_IMMEDIATELY. That way, we can keep configuration the user has working the same way as before, while allowing a new value 'never' to have a new meaning.

We might want to further make the variable "number, 'never' or 'immediate'" for consistency, with an eye on the possibility that we might eventually want to deprecate the "negative means immediate".

To do so, we could do:
		if (!strcmp(value, "never")) {
			autocorrect = AUTOCORRECT_NEVER;
		} else if (!strcmp(value, "immediate")) {
			autocorrect = AUTOCORRECT_IMMEDIATELY;
		} else {
			int v = git_config_int(var, value);
                        autocorrect = (v < 0) 
				? AUTOCORRECT_IMMEDIATELY : v;
		}
instead.
Previous: Drew DeVault
Message 4 of 4 in “help.c: configurable suggestions”
  1. help.c: configurable suggestionsDrew DeVault, Nov 17, 2020
  2. Junio C HamanoNov 17, 2020
  3. Drew DeVaultNov 17, 2020
  4. Junio C HamanoNov 17, 2020

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.