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

Re: [PATCH v4] merge-recursive: check GIT_MERGE_VERBOSITY only once

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 31, 2017, 02:26 UTC
Message-ID
<xmqq37603vek.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqd1543xfc.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 10 quoted lines
> That holds true for the code before or after this patch equally.  In
> other words, that sounds like a justification for rejecting this
> patch (i.e. explanation of why this change is not needed).
>
> If we are worried about another thread calling these functions after
> the time we call getenv() and before the time we pass the result to
> strtol(), then I do not think this patch gives a better protection
> against such race, so I do not think that is why you are doing this.
>
> So... why do we want to do this change?  I am puzzled.

For the sake of fairness, I would say that the resulting code may be easier to follow and has one less instance of a constant string that the compiler cannot statically check if we made a typo. That's the only benefit in this patch as far as I can see.

The original makes a call to see if the result is NULL, and then makes the same call, expecting that we get the same result (not just that it is not NULL, but it is the same verbosity request the end user made via the environment as the one we checked earlier), and I can understand that it feels a bit redundant and ugly.

Show 32 quoted lines
>> Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com>
>> Reviewed-by: Stefan Beller <sbeller@google.com>
>> ---
>> Added 'reviewed-by' field.
>>  merge-recursive.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/merge-recursive.c b/merge-recursive.c
>> index 1494ffdb8..60084e3a0 100644
>> --- a/merge-recursive.c
>> +++ b/merge-recursive.c
>> @@ -2163,6 +2163,7 @@ static void merge_recursive_config(struct merge_options *o)
>>  
>>  void init_merge_options(struct merge_options *o)
>>  {
>> +	const char *merge_verbosity;
>>  	memset(o, 0, sizeof(struct merge_options));
>>  	o->verbosity = 2;
>>  	o->buffer_output = 1;
>> @@ -2171,9 +2172,9 @@ void init_merge_options(struct merge_options *o)
>>  	o->renormalize = 0;
>>  	o->detect_rename = 1;
>>  	merge_recursive_config(o);
>> -	if (getenv("GIT_MERGE_VERBOSITY"))
>> -		o->verbosity =
>> -			strtol(getenv("GIT_MERGE_VERBOSITY"), NULL, 10);
>> +	merge_verbosity = getenv("GIT_MERGE_VERBOSITY");
>> +	if (merge_verbosity)
>> +		o->verbosity = strtol(merge_verbosity, NULL, 10);
>>  	if (o->verbosity >= 5)
>>  		o->buffer_output = 0;
>>  	strbuf_init(&o->obuf, 0);
Previous: Junio C HamanoNext: Andrey Okoshkin
Message 16 of 22 in “merge-recursive: check GIT_MERGE_VERBOSITY only once”
  1. merge-recursive: check GIT_MERGE_VERBOSITY only onceAndrey Okoshkin, Oct 24, 2017
  2. Stefan BellerOct 24, 2017
  3. Eric SunshineOct 24, 2017
  4. Martin ÅgrenOct 24, 2017
  5. Jeff KingOct 24, 2017
  6. Junio C HamanoOct 25, 2017
  7. Eric SunshineOct 25, 2017
  8. Jeff KingOct 25, 2017
  9. merge-recursive: check GIT_MERGE_VERBOSITY only onceAndrey Okoshkin, Oct 25, 2017
  10. Eric SunshineOct 25, 2017
  11. Andrey OkoshkinOct 25, 2017
  12. Andrey OkoshkinOct 25, 2017
  13. Stefan BellerOct 27, 2017
  14. merge-recursive: check GIT_MERGE_VERBOSITY only onceAndrey Okoshkin, Oct 30, 2017
  15. Junio C HamanoOct 31, 2017
  16. Junio C HamanoOct 31, 2017
  17. Andrey OkoshkinOct 31, 2017
  18. Junio C HamanoOct 31, 2017
  19. merge-recursive: check GIT_MERGE_VERBOSITY only onceAndrey Okoshkin, Oct 31, 2017
  20. Andrey OkoshkinOct 25, 2017
  21. Andrey OkoshkinOct 25, 2017
  22. Andrey OkoshkinOct 25, 2017

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.