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, 07:20 UTC
Message-ID
<xmqqwp3byeai.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<ecb12f21-f26f-6905-1fdc-60d7c282cfe3@samsung.com>
Andrey Okoshkin <a.okoshkin@samsung.com> writes:
Show 19 quoted lines
> I think, the main benefits are:
> * Code is more readable, no duplicated calls with the same constant string
> argument.
> * Code is potentially safer, the second getenv() call may return another
> pointer value which could be NULL (and yes, this is an arguable point as it
> can be done only artificially).
>
>> 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.
>
> Yes, you absolutely right.

I am absolutely right when I say your "code is potentially safer" is total BS. The result from first getenv() call may be pointing at an invalid piece of memory by the time it is used, if you are in a situation in which not having the second getenv() matters (i.e. somebody else is also mucking with getenv() at the same time).

So please update the log message so that the patch is not sold on that basis.

Thanks.
Previous: Andrey OkoshkinNext: Andrey Okoshkin
Message 18 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.